-
Notifications
You must be signed in to change notification settings - Fork 4k
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
pipelines : Enable custom role configuration #27605
Comments
Makes sense. But I believe it's still possible to override. Can you share minimal reproducible code snippets with us that provisions the pipeline with all the four roles? |
This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled. |
Hi @pahud , Repository will have following structure Repo
CDK App
CodePipelineStack
Stage
Lambda Stack
release.sh - this will do a mvn release prepare and will do cdk diff and cdk synth
|
Here is the repo with code |
Thank you. Yes unfortunately cdk pipelines does not allow to specify existing roles for all the 4 roles and it's very tricky to override it. I am making it a p1 feature request now. |
Hi @supunasp After some deep diving I was able to print out the role ARNs with CDK in typescript: Given the pipeline as below: const pipeline = new pipelines.CodePipeline(this, 'MyPipeline', {
synth: new pipelines.ShellStep('Synth', {
// Use a connection created using the AWS console to authenticate to GitHub
// Other sources are available.
input: pipelines.CodePipelineSource.connection(repoString, repoBranch, {
connectionArn, // Created using the AWS console * });',
}),
commands: [
'yarn install --frozen-lockfile',
// 'yarn build',
'npx cdk synth',
],
}),
}); When I And I was able to print out the 4 role ARNs with a helper function: pipeline.buildPipeline();
// Pipeline Role
new CfnOutput(this, 'PipelineRoleArn', { value: pipeline.pipeline.role.roleArn });
const stackName = Stack.of(this).stackName;
const _repoString = repoString.replace('/', '_');
// MyPipeline/Pipeline/Source/${_repoString}/CodePipelineActionRole
const codePipelineActionRole = this.findRolebyPath(`${stackName}/Pipeline/Source/${_repoString}/CodePipelineActionRole`, pipeline);
new CfnOutput(this, 'CodePipelineSourceActionRole', { value: codePipelineActionRole.roleArn });
// MyPipeline/Pipeline/Build/Synth/CdkBuildProject/Role
const cdkBuildSynthRole = this.findRolebyPath(`${stackName}/Pipeline/Build/Synth/CdkBuildProject/Role`, pipeline);
new CfnOutput(this, 'CdkBuildSynthRoleArn', { value: cdkBuildSynthRole.roleArn });
// MyPipeline/UpdatePipeline/SelfMutation/Role
const selfMutationRole = this.findRolebyPath(`${stackName}/UpdatePipeline/SelfMutation/Role`, pipeline);
new CfnOutput(this, 'SelfMutationRoleArn', { value: selfMutationRole.roleArn });
// CodeBuildActionRole
const actionRole = pipeline.node.tryFindChild('CodeBuildActionRole') as iam.Role;
new CfnOutput(this, 'CodeBuildActionRoleArn', { value: actionRole.roleArn }); And the helper function as below: private findRolebyPath(path: string, findFrom: Construct): iam.Role {
const split = path.split('/');
let found: Construct = findFrom;
for (var i=1; i<split.length-1; i++) {
console.log('finding ', split[i]);
found = found.node.tryFindChild(split[i]) as Construct;
};
return found.node.tryFindChild(split[split.length-1]) as iam.Role;
} And the output
With that being said, I think it's still possible to override the 5 roles with escape hatches so you can reuse your existing custom roles. I am making it a p2 feature request again as this seems to be a workaround but we still welcome any pull requests to allow custom role definition in the construct props. |
Describe the feature
I have developed a CodePipeline as follows.
But when I deploy the pipeline, cdk will create another 4 roles. Is there a way to stop generating those roles and tell CDK to reuse existing ones provided ?
Use Case
We have around 25+ lambda functions and each of them currently having build job where CodeBuildRole is shared. We will be creating this new pipeline for all of them. Which means there will be around 100+ roles created.
I need to use a pre-existing service role created by our security team instead auto generating ones. Our security team identifies this as another vulnerability.
Proposed Solution
CodePipeline can be configured as this. Solution would be to introduce role instead of rolePolicy in CodeBuildOptions
Other Information
I have tried overriding the roles using CfnResource. (L1 construct). I was able to override some roles. I was not able to override the role to But the roles are still getting generated. I couldn't find a way to stop generating the role.
Acknowledgements
CDK version used
software.amazon.awscdk: aws-cdk-lib: 2.99.1
Environment details (OS name and version, etc.)
AWS Amazon Linux 2 & Java
The text was updated successfully, but these errors were encountered: