Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(codepipeline_actions): Need support for Full Clone for CodeCommit action. (OutputArtifactFormat= CODEBUILD_CLONE_REF) #12236

Closed
2 tasks
pcolazurdo opened this issue Dec 26, 2020 · 4 comments · Fixed by #12558
Assignees
Labels
@aws-cdk/aws-codepipeline-actions effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2

Comments

@pcolazurdo
Copy link

As referenced here this is a Feature Request to allow CodeBuild to access Git metadata in the pipeline build action.

Full Clone is needed in cases where the CodeBuild action needs to access the full Git Repository metadata

Use Case

In my case I'm trying to run the AWS Copilot CLI to build & deploy from CodeBuild once there is an update to the CodeCommit repo. AWS Copilot CLI needs access to the Git Repository directly. This is a supported case as referenced in the link above, but the codepipeline_actions modules seems to have exposed this only for BitBucket sources. It would be nice to extend this to other Sources.

Proposed Solution

My understanding is that exposing the property OutputArtifactFormat similar to what is done here should be enough, but I don't understand the source code enough as to make a proper PR.

Special care has to be considered when defining Role permissions as there are specific requirements for this option to work. This is clearly referenced here

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

@pcolazurdo pcolazurdo added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Dec 26, 2020
@pcolazurdo
Copy link
Author

pcolazurdo commented Dec 26, 2020

Found a temporary solution using an Escape hatch - documenting it for future reference

// CloudFromation Escape Hatch to add OutputArtifactFormat allows support 
// for Full Clone (bug: https://github.com/aws/aws-cdk/issues/12236)

// As additional permissions are needed I need to create a new role and assign it to the action 
// This is temporary as codepipeline_actions.CodeCommitSourceAction doesn't expose the role to add the policy directly
const codeCommitSourceActionRole = new iam.Role(this, 'CodeCommitSourceActionRole', {
  assumedBy: new iam.AccountPrincipal(this.account)
});

codeCommitSourceActionRole.addToPrincipalPolicy (new iam.PolicyStatement({
  effect: iam.Effect.ALLOW, 
  resources: [code.repositoryArn],
  actions: [
    'codecommit:GetBranch',
    'codecommit:GetCommit',
    'codecommit:UploadArchive',
    'codecommit:GetUploadArchiveStatus',
    'codecommit:CancelUploadArchive',
    'codecommit:GitPull',
    'codecommit:GetRepository',
  ]
}));

const codeCommitSourceAction = new codepipeline_actions.CodeCommitSourceAction({
  role: codeCommitSourceActionRole,
  actionName: 'CodeCommit_Source',
  repository: code,
  output: sourceOutput
});

// Also, the codebuild Service Role needs additional permissions
codeBuildServiceRole.addToPrincipalPolicy (new iam.PolicyStatement({
      effect: iam.Effect.ALLOW, 
      resources: [code.repositoryArn],
      actions: [            
        'codecommit:GitPull'
      ]
}));

// This modifies the specific Stage Properties
const cfnPipeline = pipeline.node.defaultChild as codepipeline.CfnPipeline;
cfnPipeline.addPropertyOverride('Stages.0.Actions.0.Configuration.OutputArtifactFormat', 'CODEBUILD_CLONE_REF');

@skinny85 skinny85 self-assigned this Dec 28, 2020
@skinny85 skinny85 added @aws-cdk/aws-codepipeline-actions effort/medium Medium work item – several days of effort p2 and removed needs-triage This issue or PR still needs to be triaged. labels Dec 28, 2020
@MHacker9404
Copy link

something to check in - so I did the hack-around waiting for the PR. Ran into an encryption/decryption error - the pipeline didn't have access to the key used on the S3 bucket. Will this still be an issue with this update?

@skinny85
Copy link
Contributor

something to check in - so I did the hack-around waiting for the PR. Ran into an encryption/decryption error - the pipeline didn't have access to the key used on the S3 bucket. Will this still be an issue with this update?

I've just tried it, and everything worked for me!

Let's get this released - the API looks good, and if there are any remaining permissions issues, we'll handle them as we go 🙂.

@mergify mergify bot closed this as completed in #12558 Jan 21, 2021
mergify bot pushed a commit that referenced this issue Jan 21, 2021
…#12558)

Add `codeBuildCloneOutput` property to the CodeCommit source action.

It automatically adds the `codecommit:GetRepository` permission to the CodeCommitSourceAction role.
It will also add the `codecommit:GitPull` permission to any CodeBuildAction using the artifact from CodeCommitSourceAction as input.

Closes #12236

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

mohanrajendran pushed a commit to mohanrajendran/aws-cdk that referenced this issue Jan 24, 2021
…aws#12558)

Add `codeBuildCloneOutput` property to the CodeCommit source action.

It automatically adds the `codecommit:GetRepository` permission to the CodeCommitSourceAction role.
It will also add the `codecommit:GitPull` permission to any CodeBuildAction using the artifact from CodeCommitSourceAction as input.

Closes aws#12236

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-codepipeline-actions effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants