Skip to content

Commit

Permalink
fix: make existingGitHubActionsProvider aware of AWS partitions (#868)
Browse files Browse the repository at this point in the history
Replace hard coded 'aws' partition with a reference to the `AWS::Partition` in the current stack. This makes `GitHubActionRole` work for e.g. `aws-cn` too.

There are more work that needs to be done to get full aws-cn support (see #820), but this is a general fix and so could be merged independently.
  • Loading branch information
mbergkvist authored Feb 12, 2024
1 parent 557df69 commit d0e1c52
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion API.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/oidc-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export interface GitHubActionRoleProps {
* You must `cdk deploy` once (with your normal AWS credentials) to have this role created for you.
*
* You can then make note of the role arn in the stack output and send it into the Github Workflow app via
* the `gitHubActionRoleArn` property. The role arn will be `arn:aws:iam::<accountId>:role/GithubActionRole`.
* the `gitHubActionRoleArn` property. The role arn will be `arn:<partition>:iam::<accountId>:role/GithubActionRole`.
*
* @see https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services
*/
Expand All @@ -91,7 +91,7 @@ export class GitHubActionRole extends Construct {
return iam.OpenIdConnectProvider.fromOpenIdConnectProviderArn(
scope,
'GitHubActionProvider',
`arn:aws:iam::${Aws.ACCOUNT_ID}:oidc-provider/token.actions.githubusercontent.com`,
`arn:${Aws.PARTITION}:iam::${Aws.ACCOUNT_ID}:oidc-provider/token.actions.githubusercontent.com`,
);
}

Expand Down Expand Up @@ -174,4 +174,4 @@ function formatRepos(repos: string[]) {
formattedRepos.push(`repo:${repo}:*`);
}
return formattedRepos;
}
}
6 changes: 5 additions & 1 deletion test/oidc-provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ describe('GithubActionRole construct', () => {
'Fn::Join': [
'',
[
'arn:aws:iam::',
'arn:',
{
Ref: 'AWS::Partition',
},
':iam::',
{
Ref: 'AWS::AccountId',
},
Expand Down

0 comments on commit d0e1c52

Please sign in to comment.