Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions packages/@aws-cdk/cloudformation-diff/lib/iam/iam-changes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,15 @@ export class IamChanges {
break;
case PropertyScrutinyType.InlineResourcePolicy:
// Any PolicyDocument on a resource (including AssumeRolePolicyDocument)
this.statements.addOld(...this.readResourceStatements(propertyChange.oldValue, propertyChange.resourceLogicalId));
this.statements.addNew(...this.readResourceStatements(propertyChange.newValue, propertyChange.resourceLogicalId));
// Special-case AWS::SSO::PermissionSet as a pseudo-principal in the IAM statement changes output.
if (propertyChange.resourceType === 'AWS::SSO::PermissionSet') {
this.statements.addOld(...this.readPermissionSetInlinePolicy(propertyChange.oldValue, propertyChange.resourceLogicalId));
this.statements.addNew(...this.readPermissionSetInlinePolicy(propertyChange.newValue, propertyChange.resourceLogicalId));
} else {
// Existing behaviour for all other resources
this.statements.addOld(...this.readResourceStatements(propertyChange.oldValue, propertyChange.resourceLogicalId));
this.statements.addNew(...this.readResourceStatements(propertyChange.newValue, propertyChange.resourceLogicalId));
}
break;
case PropertyScrutinyType.ManagedPolicies:
// Just a list of managed policies
Expand Down Expand Up @@ -413,6 +420,27 @@ export class IamChanges {
})];
}

private readPermissionSetInlinePolicy(policy: any, logicalId: string): Statement[] {
if (policy === undefined) {
return [];
}

// For PermissionSet inline policies:
// - Resource: still defaulted to the PermissionSet ARN when wildcarded
// - Principal: a pseudo-principal that identifies the PermissionSet
const appliesToResource = '${' + logicalId + '.Arn}';
const appliesToPrincipal = 'AWS:${' + logicalId + '}';

const statements = parseStatements(renderIntrinsics(policy.Statement));

// Keeping the existing behaviour for Resource…
defaultResource(appliesToResource, statements);
// …and additionally injecting a pseudo-principal for readability
defaultPrincipal(appliesToPrincipal, statements);

return statements;
}

private readResourceStatements(policy: any, logicalId: string): Statement[] {
if (policy === undefined) {
return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ test('can summarize negative ssoPermissionSet changes with PermissionsBoundary.C
'${MySsoPermissionSet.Arn}',
'Allow',
'iam:CreateServiceLinkedRole',
'',
'AWS:${MySsoPermissionSet}',
'',
].map(s => chalk.red(s)),
],
Expand Down Expand Up @@ -609,7 +609,7 @@ test('can summarize ssoPermissionSet changes with PermissionsBoundary.CustomerMa
'${MySsoPermissionSet.Arn}',
'Allow',
'iam:CreateServiceLinkedRole',
'',
'AWS:${MySsoPermissionSet}',
'',
].map(s => chalk.green(s)),
],
Expand Down
Loading