-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ecr): authorization token retrieval grants (#11783)
See README.md ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Niranjan Jayakar
authored
Nov 30, 2020
1 parent
7b8b665
commit c072981
Showing
4 changed files
with
68 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import * as iam from '@aws-cdk/aws-iam'; | ||
|
||
/** | ||
* Authorization token to access ECR repositories via Docker CLI. | ||
*/ | ||
export class AuthorizationToken { | ||
/** | ||
* Grant access to retrieve an authorization token. | ||
*/ | ||
public static grantRead(grantee: iam.IGrantable) { | ||
grantee.grantPrincipal.addToPrincipalPolicy(new iam.PolicyStatement({ | ||
actions: ['ecr:GetAuthorizationToken'], | ||
// GetAuthorizationToken only allows '*'. See https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonelasticcontainerregistry.html#amazonelasticcontainerregistry-actions-as-permissions | ||
resources: ['*'], | ||
})); | ||
} | ||
|
||
private constructor() { | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { expect, haveResourceLike } from '@aws-cdk/assert'; | ||
import * as iam from '@aws-cdk/aws-iam'; | ||
import { Stack } from '@aws-cdk/core'; | ||
import { Test } from 'nodeunit'; | ||
import { AuthorizationToken } from '../lib'; | ||
|
||
export = { | ||
'grant()'(test: Test) { | ||
// GIVEN | ||
const stack = new Stack(); | ||
const user = new iam.User(stack, 'User'); | ||
|
||
// WHEN | ||
AuthorizationToken.grantRead(user); | ||
|
||
// THEN | ||
expect(stack).to(haveResourceLike('AWS::IAM::Policy', { | ||
PolicyDocument: { | ||
Statement: [ | ||
{ | ||
Action: 'ecr:GetAuthorizationToken', | ||
Effect: 'Allow', | ||
Resource: '*', | ||
}, | ||
], | ||
}, | ||
})); | ||
|
||
test.done(); | ||
}, | ||
}; |