-
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.
fix(iam): no trust policy added for cross-account roles
Trust policies should be added to resources when trying to grant permissions to a principal in a different account. Typically this is a Service Principal, but it could also be an imported Role from a different account (and the same should not be done for a Role in the same account). Our previous API (`addToPolicy` returning `true|false`) was designed for in-account Roles and cross-account ServicePrincipals, but was not rich enough to make the distinction that Roles could be cross-account. Add a function to `IPrincipal` to ask it whether it is in the same or a different account from a given scope, and have `Grant` respect that. Also in this commit: a bugfix for `ImmutableRole` to make it work correctly with `Grant` Also in this commit: `parseArn()` used to behave the same for `parseArn(TOKEN)` and `parseArn("arn:{TOKEN}:svc:1234:...")`. Make it (opportunistically) do the right thing in the latter case, parsing out the concrete components and the TOKEN components separately. This makes it possible to parse out the concrete account number from an ARN that contains tokenized parts we don't care about. Fixes #5740.
- Loading branch information
Showing
14 changed files
with
340 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Token } from '@aws-cdk/core'; | ||
|
||
/** | ||
* Return whether the given accounts are definitely different. | ||
* | ||
* If one or both of them are agnostic, return false (we don't know). | ||
*/ | ||
export function accountsAreDefinitelyDifferent(account1: string | undefined, | ||
account2: string | undefined): boolean { | ||
return !Token.isUnresolved(account1) && !Token.isUnresolved(account2) && account1 !== account2; | ||
} | ||
|
||
/** | ||
* Return whether two accounts are the same account | ||
* | ||
* Returns undefined if one is agnostic and the other one isn't. | ||
*/ | ||
export function sameAccount(account1: string | undefined, account2: string | undefined): boolean | undefined { | ||
// Both agnostic in 99% of cases means they will be deployed to the same environment, | ||
// so treat as the same. | ||
if (Token.isUnresolved(account1) && Token.isUnresolved(account2)) { return true; } | ||
|
||
// One agnostic and the other one not means "shug". | ||
if (Token.isUnresolved(account1) || Token.isUnresolved(account2)) { return undefined; } | ||
return account1 === account2; | ||
} |
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.