Skip to content

Commit c71ab4b

Browse files
authored
Merge pull request #62 from aws4embeddedlinux/pipeline-policy-options
Add Pipeline Project IAM Statement Props
2 parents 15aa7c5 + bf2c3e0 commit c71ab4b

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

README.md

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,26 @@ source repos, etc.
7373

7474
1. Create a _Secret_ in Secrets Manager and add your secret value.
7575
1. Grant access permissions to the CodeBuild pipeline project.
76-
1. Find the IAM role for the CodeBuild Project in the CodeBuild console page under the "Build Details". This is also called the "Service Role".
77-
1. In the IAM console page, add a new policy, replacing \<Secret ARN\> with the ARN of the secret created.
78-
```json
79-
{
80-
"Version": "2012-10-17",
81-
"Statement": [ {
82-
"Effect": "Allow",
83-
"Action": "secretsmanager:GetSecretValue",
84-
"Resource": "<Secret ARN>"
85-
} ]
86-
}
87-
```
76+
11. Create a [Policy Statement](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_iam.PolicyStatement.html) which allows `secretsmanager:GetSecretValue` for your secret.
77+
11. Add this policy statement to the `buildPolicyAdditions` props for the `EmbeddedLinuxPipelineStack`. e.g.
78+
```typescript
79+
import * as iam from "aws-cdk-lib/aws-iam";
80+
81+
82+
const pipeline = new EmbeddedLinuxPipelineStack(app, "MyPokyPipeline", {
83+
imageRepo: buildImageRepo.repository,
84+
imageTag: ImageKind.Ubuntu22_04,
85+
vpc: vpc.vpc,
86+
buildPolicyAdditions: [
87+
iam.PolicyStatement.fromJson({
88+
Effect: "Allow",
89+
Action: "secretsmanager:GetSecretValue",
90+
Resource:
91+
"arn:aws:secretsmanager:us-west-2:123456789012:secret:my-secret-??????",
92+
}),
93+
],
94+
});
95+
```
8896

8997
The secret can then be used in the CodeBuild Project by adding it to the BuildSpec. See
9098
the [CodeBuild Documentation](https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html) for more details.

lib/embedded-linux-pipeline.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ export interface EmbeddedLinuxPipelineProps extends cdk.StackProps {
4848
readonly projectKind?: ProjectKind;
4949
/** A name for the layer-repo that is created. Default is 'layer-repo' */
5050
readonly layerRepoName?: string;
51+
/** Additional policy statements to add to the build project. */
52+
readonly buildPolicyAdditions?: iam.PolicyStatement[];
5153
}
5254

5355
/**
@@ -199,6 +201,10 @@ export class EmbeddedLinuxPipelineStack extends cdk.Stack {
199201
},
200202
});
201203

204+
if (props.buildPolicyAdditions) {
205+
props.buildPolicyAdditions.map(p => project.addToRolePolicy(p))
206+
}
207+
202208
if (props.projectKind && props.projectKind == ProjectKind.PokyAmi) {
203209
outputBucket.grantReadWrite(project);
204210
project.addToRolePolicy(this.addVMExportPolicy());

0 commit comments

Comments
 (0)