-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
45 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import * as cdk from 'aws-cdk-lib' | ||
import {AppStack} from '../lib/app-stack' | ||
import {DeploymentStack} from '../lib/deployment-stack'; | ||
|
||
const app = new cdk.App() | ||
new AppStack(app, 'GitHubActionsAccessTokens') | ||
const appStack = new AppStack(app, 'GitHubActionsAccessTokens') | ||
// new DeploymentStack(app, appStack.stackName + '-Deployment') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
server/deployments/aws/infrastructure/lib/deployment-stack.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import {Stack, StackProps} from 'aws-cdk-lib'; | ||
import {Construct} from 'constructs'; | ||
import {OpenIdConnectPrincipal, OpenIdConnectProvider, Role} from 'aws-cdk-lib/aws-iam'; | ||
|
||
export class DeploymentStack extends Stack { | ||
constructor(scope: Construct, id: string, props?: StackProps) { | ||
super(scope, id, props) | ||
|
||
const githubOidcProvider = OpenIdConnectProvider.fromOpenIdConnectProviderArn( | ||
this, "GithubOpenIdConnectProvider", | ||
`arn:aws:iam::${this.account}:oidc-provider/token.actions.githubusercontent.com`); | ||
|
||
new Role(this, 'DeploymentRole', { | ||
roleName: this.stackName, | ||
managedPolicies: [ | ||
{managedPolicyArn: 'arn:aws:iam::aws:policy/AdministratorAccess'}, | ||
], | ||
assumedBy: new OpenIdConnectPrincipal(githubOidcProvider, { | ||
'StringEquals': { | ||
// Official AWS GitHub Action https://github.com/aws-actions/configure-aws-credentials set audience to `sts.amazonaws.com` by default | ||
// https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services#adding-the-identity-provider-to-aws' | ||
[`${githubOidcProvider.openIdConnectProviderIssuer}:aud`]: 'sts.amazonaws.com', | ||
}, | ||
'ForAnyValue:StringLike': { | ||
[`${githubOidcProvider.openIdConnectProviderIssuer}:sub`]: ['repo:JH-JDS/actions--access-token:ref:refs/heads/main'], | ||
} | ||
}), | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters