forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(iam): customer managed policies (aws#3578)
* Support creation of customer managed policies * Make ManagedPolicy changes pass build * Add tests and make policy stuff work with users, groups and roles * fix call to generatePolicyName from ManagedPolicy after merge from master * Fix implementation of ManagedPolicy and add integ test * Revert test.role.ts to its original form * Remove unnecessary Lazy.stringValue * Allow adding parameters to previously unused constructor * Fix policy naming * Fix tests
- Loading branch information
1 parent
ba2a4df
commit 4681d01
Showing
10 changed files
with
807 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
change-return-type:@aws-cdk/core.Fn.getAtt | ||
new-argument:@aws-cdk/aws-iam.ManagedPolicy.<initializer> | ||
new-argument:@aws-cdk/aws-iam.ManagedPolicy.<initializer> |
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
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
66 changes: 66 additions & 0 deletions
66
packages/@aws-cdk/aws-iam/test/integ.managed-policy.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,66 @@ | ||
{ | ||
"Resources": { | ||
"MyUserDC45028B": { | ||
"Type": "AWS::IAM::User", | ||
"Properties": { | ||
"ManagedPolicyArns": [ | ||
{ | ||
"Ref": "TwoManagedPolicy7E701864" | ||
}, | ||
{ | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"arn:", | ||
{ | ||
"Ref": "AWS::Partition" | ||
}, | ||
":iam::aws:policy/SecurityAudit" | ||
] | ||
] | ||
} | ||
] | ||
} | ||
}, | ||
"OneManagedPolicy77F9185F": { | ||
"Type": "AWS::IAM::ManagedPolicy", | ||
"Properties": { | ||
"PolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "sqs:SendMessage", | ||
"Effect": "Allow", | ||
"Resource": "*" | ||
} | ||
], | ||
"Version": "2012-10-17" | ||
}, | ||
"Description": "My Policy", | ||
"ManagedPolicyName": "Default", | ||
"Path": "/some/path/", | ||
"Users": [ | ||
{ | ||
"Ref": "MyUserDC45028B" | ||
} | ||
] | ||
} | ||
}, | ||
"TwoManagedPolicy7E701864": { | ||
"Type": "AWS::IAM::ManagedPolicy", | ||
"Properties": { | ||
"PolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "lambda:InvokeFunction", | ||
"Effect": "Allow", | ||
"Resource": "*" | ||
} | ||
], | ||
"Version": "2012-10-17" | ||
}, | ||
"Description": "", | ||
"Path": "/" | ||
} | ||
} | ||
} | ||
} |
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, Stack } from "@aws-cdk/core"; | ||
import { ManagedPolicy, PolicyStatement } from "../lib"; | ||
import { User } from "../lib/user"; | ||
|
||
const app = new App(); | ||
|
||
const stack = new Stack(app, 'aws-cdk-iam-managed-policy'); | ||
|
||
const user = new User(stack, 'MyUser'); | ||
|
||
const policy = new ManagedPolicy(stack, 'OneManagedPolicy', { | ||
managedPolicyName: 'Default', | ||
description: 'My Policy', | ||
path: '/some/path/', | ||
}); | ||
policy.addStatements(new PolicyStatement({ resources: ['*'], actions: ['sqs:SendMessage'] })); | ||
policy.attachToUser(user); | ||
|
||
const policy2 = new ManagedPolicy(stack, 'TwoManagedPolicy'); | ||
policy2.addStatements(new PolicyStatement({ resources: ['*'], actions: ['lambda:InvokeFunction'] })); | ||
user.addManagedPolicy(policy2); | ||
|
||
const policy3 = ManagedPolicy.fromAwsManagedPolicyName('SecurityAudit'); | ||
user.addManagedPolicy(policy3); | ||
|
||
app.synth(); |
Oops, something went wrong.