-
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(core): CfnJson enables intrinsics in hash keys (#8099)
Rarely there is a need to use a CloudFormation intrinsic in a JSON hash key. This is impossible since intrinsics are not strings. To circumvent that, CfnJson can be used to "delay" the rendition of the object using a simple custom resource which simply parses and reflects the input value as an attribute. Required in order to implement EKS IRSA (#8084) and other federated identity use cases. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Elad Ben-Israel
authored
May 21, 2020
1 parent
3fed84b
commit 195cd40
Showing
14 changed files
with
509 additions
and
5 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
165 changes: 165 additions & 0 deletions
165
packages/@aws-cdk/aws-iam/test/integ.condition-with-ref.expected.json
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,165 @@ | ||
{ | ||
"Parameters": { | ||
"PrincipalTag": { | ||
"Type": "String", | ||
"Default": "developer" | ||
}, | ||
"AssetParameterse02a38b06730095e29b3afe60b65afcdc3a4ad4716c2f21de5fd5dc58e194f57S3BucketEF5DD638": { | ||
"Type": "String", | ||
"Description": "S3 bucket for asset \"e02a38b06730095e29b3afe60b65afcdc3a4ad4716c2f21de5fd5dc58e194f57\"" | ||
}, | ||
"AssetParameterse02a38b06730095e29b3afe60b65afcdc3a4ad4716c2f21de5fd5dc58e194f57S3VersionKey2EA0DB2E": { | ||
"Type": "String", | ||
"Description": "S3 key for asset version \"e02a38b06730095e29b3afe60b65afcdc3a4ad4716c2f21de5fd5dc58e194f57\"" | ||
}, | ||
"AssetParameterse02a38b06730095e29b3afe60b65afcdc3a4ad4716c2f21de5fd5dc58e194f57ArtifactHash95B71D2D": { | ||
"Type": "String", | ||
"Description": "Artifact hash for asset \"e02a38b06730095e29b3afe60b65afcdc3a4ad4716c2f21de5fd5dc58e194f57\"" | ||
} | ||
}, | ||
"Resources": { | ||
"PrincipalTagCondition94CCB594": { | ||
"Type": "Custom::AWSCDKCfnJson", | ||
"Properties": { | ||
"ServiceToken": { | ||
"Fn::GetAtt": [ | ||
"AWSCDKCfnUtilsProviderCustomResourceProviderHandlerCF82AA57", | ||
"Arn" | ||
] | ||
}, | ||
"Value": { | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"{\"aws:PrincipalTag/", | ||
{ | ||
"Ref": "PrincipalTag" | ||
}, | ||
"\":\"true\"}" | ||
] | ||
] | ||
} | ||
}, | ||
"UpdateReplacePolicy": "Delete", | ||
"DeletionPolicy": "Delete" | ||
}, | ||
"AWSCDKCfnUtilsProviderCustomResourceProviderRoleFE0EE867": { | ||
"Type": "AWS::IAM::Role", | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "lambda.amazonaws.com" | ||
} | ||
} | ||
] | ||
}, | ||
"ManagedPolicyArns": [ | ||
{ | ||
"Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" | ||
} | ||
] | ||
} | ||
}, | ||
"AWSCDKCfnUtilsProviderCustomResourceProviderHandlerCF82AA57": { | ||
"Type": "AWS::Lambda::Function", | ||
"Properties": { | ||
"Code": { | ||
"S3Bucket": { | ||
"Ref": "AssetParameterse02a38b06730095e29b3afe60b65afcdc3a4ad4716c2f21de5fd5dc58e194f57S3BucketEF5DD638" | ||
}, | ||
"S3Key": { | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
{ | ||
"Fn::Select": [ | ||
0, | ||
{ | ||
"Fn::Split": [ | ||
"||", | ||
{ | ||
"Ref": "AssetParameterse02a38b06730095e29b3afe60b65afcdc3a4ad4716c2f21de5fd5dc58e194f57S3VersionKey2EA0DB2E" | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"Fn::Select": [ | ||
1, | ||
{ | ||
"Fn::Split": [ | ||
"||", | ||
{ | ||
"Ref": "AssetParameterse02a38b06730095e29b3afe60b65afcdc3a4ad4716c2f21de5fd5dc58e194f57S3VersionKey2EA0DB2E" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
] | ||
} | ||
}, | ||
"Timeout": 900, | ||
"MemorySize": 128, | ||
"Handler": "__entrypoint__.handler", | ||
"Role": { | ||
"Fn::GetAtt": [ | ||
"AWSCDKCfnUtilsProviderCustomResourceProviderRoleFE0EE867", | ||
"Arn" | ||
] | ||
}, | ||
"Runtime": "nodejs12.x" | ||
}, | ||
"DependsOn": [ | ||
"AWSCDKCfnUtilsProviderCustomResourceProviderRoleFE0EE867" | ||
] | ||
}, | ||
"MyRoleF48FFE04": { | ||
"Type": "AWS::IAM::Role", | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Condition": { | ||
"StringEquals": { | ||
"Fn::GetAtt": [ | ||
"PrincipalTagCondition94CCB594", | ||
"Value" | ||
] | ||
} | ||
}, | ||
"Effect": "Allow", | ||
"Principal": { | ||
"AWS": { | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"arn:", | ||
{ | ||
"Ref": "AWS::Partition" | ||
}, | ||
":iam::", | ||
{ | ||
"Ref": "AWS::AccountId" | ||
}, | ||
":root" | ||
] | ||
] | ||
} | ||
} | ||
} | ||
], | ||
"Version": "2012-10-17" | ||
} | ||
} | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
packages/@aws-cdk/aws-iam/test/integ.condition-with-ref.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,26 @@ | ||
import { App, CfnJson, CfnParameter, Construct, Stack } from '@aws-cdk/core'; | ||
import { AccountRootPrincipal, Role } from '../lib'; | ||
|
||
class MyStack extends Stack { | ||
constructor(scope: Construct, id: string) { | ||
super(scope, id); | ||
|
||
const tagName = new CfnParameter(this, 'PrincipalTag', { default: 'developer' }); | ||
|
||
const stringEquals = new CfnJson(this, 'PrincipalTagCondition', { | ||
value: { | ||
[`aws:PrincipalTag/${tagName.valueAsString}`]: 'true', | ||
}, | ||
}); | ||
|
||
const principal = new AccountRootPrincipal().withConditions({ | ||
StringEquals: stringEquals, | ||
}); | ||
|
||
new Role(this, 'MyRole', { assumedBy: principal }); | ||
} | ||
} | ||
|
||
const app = new App(); | ||
new MyStack(app, 'test-condition-with-ref'); | ||
app.synth(); |
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
Oops, something went wrong.