Skip to content

Commit

Permalink
cdk cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hans-m-song committed May 5, 2024
1 parent c548c6c commit f9b060e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 28 deletions.
12 changes: 0 additions & 12 deletions aws/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,27 +77,15 @@ new ECRPublicStack(app, "ECRPublic", {
repositories: Object.values(ECR),
});

new GithubActionsOIDCProviderStack(app, "GithubActionsOIDCProvider", {
env: { region: Region.Sydney },
});

new HostedZoneUpdateStack(app, "HostedZoneUpdateStack", {
env: { region: Region.Sydney },
hostedZones: Object.values(hostedZones),
});

new ManagedPolicyStack(app, "ManagedPolicy", {
env: { region: Region.Sydney },
});

new NewRelicIntegrationStack(app, "NewRelicIntegration", {
env: { region: Region.Sydney },
});

new TerraformBackendStack(app, "TerraformBackend", {
env: { region: Region.Sydney },
});

for (const child of app.node.children) {
(child as Stack).tag();
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,10 @@ export class GithubActionsOIDCProviderStack extends Stack {
role(
id: string,
claims: GithubActionsSubjectClaims[],
parameterName?: string,
opts?: { parameterName?: string; roleName?: string },
) {
const role = new GithubActionsRole(this, id, { claims });
const { parameterName, roleName } = opts ?? {};
const role = new GithubActionsRole(this, id, { roleName, claims });

this.output(`${id}ARN`, role.roleArn);

Expand Down
21 changes: 9 additions & 12 deletions aws/lib/constructs/iam/GithubActionsRole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export interface GithubActionsSubjectClaims {
ref?: string;
pr?: boolean;
};
workflowRef?: string;
actor?: string;
}

Expand Down Expand Up @@ -49,24 +48,22 @@ export class GithubActionsFederatedPrincipal extends FederatedPrincipal {

private static formatClaims(claims: GithubActionsSubjectClaims): string[] {
const contexts = [];
const { env, ref, pr } = claims.context;
const repo = `repo:${claims.repo}`;
const actor = `actor:${claims.actor ?? "*"}`;

if (pr) {
contexts.push("pull_request");
if (claims.context.pr) {
contexts.push(`${repo}:pull_request:${actor}`);
}

if (ref) {
contexts.push(`ref:refs/heads/${ref}`);
if (claims.context.ref) {
contexts.push(`${repo}:ref:refs/heads/${claims.context.ref}:${actor}`);
}

if (env) {
contexts.push(`environment:${env}`);
if (claims.context.env) {
contexts.push(`${repo}:environment:${claims.context.env}:${actor}`);
}

const repo = `repo:${claims.repo}`;
const actor = `actor:${claims.actor ?? "*"}`;

return contexts.map((context) => [repo, context, actor].join(":"));
return contexts;
}
}

Expand Down
5 changes: 3 additions & 2 deletions aws/templates/TerraformInfrastructure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Resources:
DeployPolicy:
Type: AWS::IAM::ManagedPolicy
Properties:
ManagedPolicyName: terraform-deploy-policy
Description: Permissions to access Terraform state resources
Path: /
Roles:
Expand Down Expand Up @@ -138,7 +139,7 @@ Resources:
- Fn::GetAtt: StateLockTable.Arn
- Effect: Allow
Action:
- "*"
- '*'
Resource:
- Fn::Sub: arn:${AWS::Partition}:acm:*:${AWS::AccountId}:certificate/*
- Fn::Sub: arn:${AWS::Partition}:iam::${AWS::AccountId}:oidc-provider/*
Expand All @@ -158,4 +159,4 @@ Resources:
- route53:ListTagsForResources
- ssm:DescribeParameters
Resource:
- "*"
- '*'

0 comments on commit f9b060e

Please sign in to comment.