Skip to content

Commit

Permalink
Implement support for blocking pushes to push redirected repos and co…
Browse files Browse the repository at this point in the history
…mmit cloud refs

Summary:
This is needed for the whatsapp effort.

I ran the Mononoke Git Server integration tests and fixed them but I will let gustavoavena take care of git-push-rebase ones that will be addressed in a follow up diff. Both these diffs need to land together.

Reviewed By: gustavoavena

Differential Revision: D64604922

fbshipit-source-id: beffdd1e98fc028642d4efaaedf60d2aee87fc84
  • Loading branch information
RajivTS authored and facebook-github-bot committed Oct 21, 2024
1 parent 002a8cf commit 761e695
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
16 changes: 16 additions & 0 deletions eden/mononoke/git_server/src/service/bookmark_mover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ use import_tools::bookmark::BookmarkOperationErrorReporting;
use import_tools::git_reader::GitReader;
use import_tools::set_bookmark;
use import_tools::BookmarkOperation;
use mononoke_api::repo::push_redirector_enabled;
use mononoke_api::repo::RepoContextBuilder;
use mononoke_api::BookmarkKey;
use mononoke_api::MononokeError;
use mononoke_types::ChangesetId;
use protocol::bookmarks_provider::wait_for_bookmark_move;
use repo_authorization::AuthorizationContext;
use repo_identity::RepoIdentityRef;

use super::GitMappingsStore;
use super::GitObjectStore;
Expand All @@ -36,6 +38,7 @@ use crate::service::uploader::peel_tag_target;
use crate::util::mononoke_source_of_truth;

const HOOK_WIKI_LINK: &str = "https://fburl.com/wiki/mb4wtk1j";
const COMMIT_CLOUD_REF: &str = "refs/commitcloud/upload";

/// Struct representing a ref update (create, move, delete) operation
pub struct RefUpdateOperation {
Expand Down Expand Up @@ -164,6 +167,19 @@ async fn set_ref_inner(
request_context.repo.clone(),
request_context.mononoke_repos.clone(),
);
// Check if the push is to a commit cloud ref, if yes then reject it with proper message
if ref_update_op.ref_update.ref_name == COMMIT_CLOUD_REF {
return Err(anyhow::anyhow!(
"Commit-cloud upload succeeded. Your commit is now backed up in Mononoke"
));
}
// Check if push redirector is enabled, if it is then reject the push
if push_redirector_enabled(&ctx, repo.clone()).await? {
return Err(anyhow::anyhow!(
"Pushes to repo {} are disallowed because its source of truth has been migrated",
repo.repo_identity().name()
));
}
// Create the repo context which is the pre-requisite for moving bookmarks
let repo_context = RepoContextBuilder::new(ctx.clone(), repo.clone(), repos)
.await
Expand Down
10 changes: 10 additions & 0 deletions eden/mononoke/mononoke_api/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,16 @@ pub struct RepoContextBuilder<R> {
repos: Arc<MononokeRepos<R>>,
}

pub async fn push_redirector_enabled<R: MononokeRepo>(
ctx: &CoreContext,
repo: Arc<R>,
) -> Result<bool> {
let live_commit_sync_config = repo.repo_cross_repo().live_commit_sync_config();
live_commit_sync_config
.push_redirector_enabled_for_public(ctx, repo.repo_identity().id())
.await
}

async fn maybe_push_redirector<'a, R: MononokeRepo>(
ctx: &'a CoreContext,
repo: &'a Arc<R>,
Expand Down

0 comments on commit 761e695

Please sign in to comment.