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.
This adds an IRole implementation that ignores all mutating operations. To accommodate this new behavior, add a new method to IIdentity: createAndAttachPolicy, which is meant to replace attachInlinePolicy, which can leave Policy resources unattached, which is illegal in CloudFormation. Fixes aws#2985 Fixes aws#4465
- Loading branch information
Showing
11 changed files
with
245 additions
and
20 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
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Grant } from './grant'; | ||
import { IManagedPolicy } from './managed-policy'; | ||
import { Policy, PolicyProps } from './policy'; | ||
import { PolicyStatement } from './policy-statement'; | ||
import { IPrincipal } from './principals'; | ||
import { IRole } from './role'; | ||
|
||
/** | ||
* An immutable wrapper around an IRole that ignores all mutating operations, | ||
* like attaching policies or adding policy statements. | ||
* Useful in cases where you want to turn off CDK's automatic permissions management, | ||
* and instead have full control over all permissions. | ||
* Note: if you want to ignore all mutations for an externally defined role | ||
* which was imported into the CDK with {@link Role.fromRoleArn}, you don't have to use this class - | ||
* simply pass the property mutable = false when calling {@link Role.fromRoleArn}. | ||
*/ | ||
export class ImmutableRole implements IRole { | ||
public readonly assumeRoleAction = this.role.assumeRoleAction; | ||
public readonly policyFragment = this.role.policyFragment; | ||
public readonly grantPrincipal = this.role.grantPrincipal; | ||
public readonly roleArn = this.role.roleArn; | ||
public readonly roleName = this.role.roleName; | ||
public readonly node = this.role.node; | ||
public readonly stack = this.role.stack; | ||
|
||
constructor(private readonly role: IRole) { | ||
} | ||
|
||
public addPolicy(_id: string, _props?: PolicyProps): Policy | undefined { | ||
return undefined; | ||
} | ||
|
||
public attachInlinePolicy(_policy: Policy): void { | ||
// do nothing | ||
} | ||
|
||
public addManagedPolicy(_policy: IManagedPolicy): void { | ||
// do nothing | ||
} | ||
|
||
public addToPolicy(_statement: PolicyStatement): boolean { | ||
return false; | ||
} | ||
|
||
public grant(grantee: IPrincipal, ...actions: string[]): Grant { | ||
return this.role.grant(grantee, ...actions); | ||
} | ||
|
||
public grantPassRole(grantee: IPrincipal): Grant { | ||
return this.role.grantPassRole(grantee); | ||
} | ||
} |
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
Oops, something went wrong.