Skip to content

Commit

Permalink
Merge pull request #62 from aws4embeddedlinux/pipeline-policy-options
Browse files Browse the repository at this point in the history
Add Pipeline Project IAM Statement Props
  • Loading branch information
nateglims committed Jan 8, 2024
2 parents 15aa7c5 + bf2c3e0 commit c71ab4b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
32 changes: 20 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,26 @@ source repos, etc.

1. Create a _Secret_ in Secrets Manager and add your secret value.
1. Grant access permissions to the CodeBuild pipeline project.
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".
1. In the IAM console page, add a new policy, replacing \<Secret ARN\> with the ARN of the secret created.
```json
{
"Version": "2012-10-17",
"Statement": [ {
"Effect": "Allow",
"Action": "secretsmanager:GetSecretValue",
"Resource": "<Secret ARN>"
} ]
}
```
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.
11. Add this policy statement to the `buildPolicyAdditions` props for the `EmbeddedLinuxPipelineStack`. e.g.
```typescript
import * as iam from "aws-cdk-lib/aws-iam";


const pipeline = new EmbeddedLinuxPipelineStack(app, "MyPokyPipeline", {
imageRepo: buildImageRepo.repository,
imageTag: ImageKind.Ubuntu22_04,
vpc: vpc.vpc,
buildPolicyAdditions: [
iam.PolicyStatement.fromJson({
Effect: "Allow",
Action: "secretsmanager:GetSecretValue",
Resource:
"arn:aws:secretsmanager:us-west-2:123456789012:secret:my-secret-??????",
}),
],
});
```

The secret can then be used in the CodeBuild Project by adding it to the BuildSpec. See
the [CodeBuild Documentation](https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html) for more details.
Expand Down
6 changes: 6 additions & 0 deletions lib/embedded-linux-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export interface EmbeddedLinuxPipelineProps extends cdk.StackProps {
readonly projectKind?: ProjectKind;
/** A name for the layer-repo that is created. Default is 'layer-repo' */
readonly layerRepoName?: string;
/** Additional policy statements to add to the build project. */
readonly buildPolicyAdditions?: iam.PolicyStatement[];
}

/**
Expand Down Expand Up @@ -199,6 +201,10 @@ export class EmbeddedLinuxPipelineStack extends cdk.Stack {
},
});

if (props.buildPolicyAdditions) {
props.buildPolicyAdditions.map(p => project.addToRolePolicy(p))
}

if (props.projectKind && props.projectKind == ProjectKind.PokyAmi) {
outputBucket.grantReadWrite(project);
project.addToRolePolicy(this.addVMExportPolicy());
Expand Down

0 comments on commit c71ab4b

Please sign in to comment.