Set parent project at creation time for imported repos from GitHub The configuration of the Gerrit parent project should be done right at creation time for avoiding to have cached ACLs on the previous project hierarchy. Gerrit does not evict the whole chain of project hierarchy for avoiding expensive cache coherence evaluation. However, the import of a project with the wrong public hierarchy may lead the project to be public right after the import. The cache eviction would then eventually make the repository private, however the exposure to external access for a few minutes represent a security risk and therefore must be avoided at all costs. Move the parent project definition at the GitCloneStep stage so that the right hierarchy is in place at the time of the git fetch from GitHub. Bug: Issue 16727 Change-Id: Id1a6c4809eed43ba618ed13e2c3161a8968dd063
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/CreateProjectStep.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/CreateProjectStep.java index 870a13b..f25e6ee 100644 --- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/CreateProjectStep.java +++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/CreateProjectStep.java
@@ -190,7 +190,6 @@ private void setProjectSettings() { projectConfig.updateProject( b -> { - b.setParent(config.getBaseProject(getRepository().isPrivate())); b.setDescription(description); b.setSubmitType(SubmitType.MERGE_IF_NECESSARY); b.setBooleanConfig(
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/GitCloneStep.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/GitCloneStep.java index 02dfe87..bcd725e 100644 --- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/GitCloneStep.java +++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/GitCloneStep.java
@@ -16,6 +16,7 @@ import com.google.gerrit.entities.Project; import com.google.gerrit.extensions.api.GerritApi; import com.google.gerrit.extensions.api.changes.NotifyHandling; +import com.google.gerrit.extensions.api.projects.ProjectInput; import com.google.gerrit.extensions.events.ProjectDeletedListener; import com.google.gerrit.extensions.registration.DynamicSet; import com.google.gerrit.extensions.restapi.ResourceConflictException; @@ -98,7 +99,10 @@ private void createNewProject() throws GitException { String projectName = organisation + "/" + repository; try (ManualRequestContext requestContext = context.openAs(config.importAccountId)) { - gerritApi.projects().create(projectName).get(); + ProjectInput pi = new ProjectInput(); + pi.name = projectName; + pi.parent = config.getBaseProject(getRepository().isPrivate()); + gerritApi.projects().create(pi).get(); } catch (ResourceConflictException e) { throw new GitDestinationAlreadyExistsException(projectName); } catch (RestApiException e) {