@kensio/yulin 1.20.15 → 1.20.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/README.md +13 -0
  2. package/dist/sdk/module/sim-sdk-module-client-interceptor.d.ts +5 -0
  3. package/dist/sdk/module/sim-sdk-module-client-interceptor.js +14 -0
  4. package/dist/sdk/module/sim-sdk-static-client-factory.d.ts +26 -0
  5. package/dist/sdk/module/sim-sdk-static-client-factory.js +59 -0
  6. package/dist/sdk/send-patch.d.ts +8 -0
  7. package/dist/sdk/send-patch.js +11 -0
  8. package/dist/service/aws/caller/sim-aws-caller-resolver.d.ts +28 -6
  9. package/dist/service/aws/caller/sim-aws-caller-resolver.js +18 -11
  10. package/dist/service/aws/caller/sim-aws-caller.d.ts +9 -0
  11. package/dist/service/aws/caller/sim-aws-resolved-caller.d.ts +19 -0
  12. package/dist/service/aws/caller/sim-aws-resolved-caller.js +26 -0
  13. package/dist/service/aws/factory/sim-aws-account-region-service-builder.d.ts +6 -0
  14. package/dist/service/aws/factory/sim-aws-account-region-service-builder.js +3 -0
  15. package/dist/service/aws/factory/sim-aws-account-service-cache.d.ts +6 -0
  16. package/dist/service/aws/factory/sim-aws-account-service-cache.js +5 -0
  17. package/dist/service/aws/factory/sim-aws-service-factory.d.ts +5 -0
  18. package/dist/service/aws/factory/sim-aws-service-factory.js +6 -0
  19. package/dist/service/aws/sim-aws-properties.d.ts +15 -0
  20. package/dist/service/aws/sim-aws.js +2 -1
  21. package/dist/service/iam/authorize/context/sim-iam-auth-z-caller-context-builder.d.ts +30 -7
  22. package/dist/service/iam/authorize/context/sim-iam-auth-z-caller-context-builder.js +20 -11
  23. package/dist/service/iam/authorize/context/sim-iam-auth-z-context-builder.d.ts +2 -1
  24. package/dist/service/iam/authorize/context/sim-iam-auth-z-context-builder.js +5 -1
  25. package/dist/service/iam/authorize/match/sim-iam-policy-principal-matcher.d.ts +10 -0
  26. package/dist/service/iam/authorize/match/sim-iam-policy-principal-matcher.js +15 -3
  27. package/dist/service/iam/authorize/sim-iam-account-auth-z.d.ts +11 -4
  28. package/dist/service/iam/authorize/sim-iam-account-auth-z.js +5 -3
  29. package/dist/service/iam/authorize/sim-iam-authorizer.d.ts +2 -1
  30. package/dist/service/iam/authorize/sim-iam-authorizer.js +1 -0
  31. package/dist/service/iam/role/sim-iam-role-with-policy.factory.d.ts +9 -0
  32. package/dist/service/iam/role/sim-iam-role-with-policy.factory.js +4 -2
  33. package/dist/service/iam/sim-iam-account-parts.d.ts +8 -0
  34. package/dist/service/iam/sim-iam-account-parts.js +1 -0
  35. package/dist/service/sts/auth-z/assume-role-auth-z-coordinator.d.ts +9 -2
  36. package/dist/service/sts/auth-z/assume-role-auth-z-coordinator.js +2 -2
  37. package/dist/service/sts/auth-z/assume-role-source-account-auth-z.d.ts +10 -4
  38. package/dist/service/sts/auth-z/assume-role-source-account-auth-z.js +8 -7
  39. package/dist/service/sts/auth-z/assume-role-target-auth-z.d.ts +2 -2
  40. package/dist/service/sts/auth-z/assume-role-trust-policy-authorizer.d.ts +6 -2
  41. package/dist/service/sts/auth-z/assume-role-trust-policy-authorizer.js +14 -11
  42. package/dist/service/sts/command/assume-role/assume-role.handler.d.ts +5 -1
  43. package/dist/service/sts/command/assume-role/assume-role.handler.js +5 -2
  44. package/dist/service/sts/command/get-caller-identity/get-caller-identity.handler.d.ts +5 -1
  45. package/dist/service/sts/command/get-caller-identity/get-caller-identity.handler.js +4 -1
  46. package/dist/service/sts/service-role/sim-service-role.js +5 -1
  47. package/dist/service/sts/sim-sts.d.ts +9 -1
  48. package/dist/service/sts/sim-sts.js +4 -0
  49. package/docs/README.md +54 -0
  50. package/docs/ai-skill/README.md +69 -0
  51. package/docs/cli/README.md +284 -0
  52. package/docs/factories/README.md +140 -0
  53. package/docs/lint/README.md +176 -0
  54. package/docs/non-aws-dependencies/README.md +261 -0
  55. package/docs/sdk/README.md +272 -0
  56. package/docs/serve/README.md +1126 -0
  57. package/docs/services/acm/README.md +823 -0
  58. package/docs/services/apigateway/README.md +1919 -0
  59. package/docs/services/apigatewayv2/README.md +2678 -0
  60. package/docs/services/athena/README.md +1044 -0
  61. package/docs/services/bedrock/README.md +350 -0
  62. package/docs/services/cloudformation/README.md +3440 -0
  63. package/docs/services/cloudfront/README.md +2874 -0
  64. package/docs/services/cloudwatch/README.md +420 -0
  65. package/docs/services/cognito/README.md +4923 -0
  66. package/docs/services/dynamodb/README.md +3784 -0
  67. package/docs/services/ecr/README.md +302 -0
  68. package/docs/services/ecs/README.md +2010 -0
  69. package/docs/services/elbv2/README.md +1897 -0
  70. package/docs/services/eventbridge/README.md +1110 -0
  71. package/docs/services/firehose/README.md +805 -0
  72. package/docs/services/glue/README.md +501 -0
  73. package/docs/services/iam/README.md +1283 -0
  74. package/docs/services/kinesis/README.md +454 -0
  75. package/docs/services/kms/README.md +659 -0
  76. package/docs/services/lambda/README.md +3645 -0
  77. package/docs/services/logs/README.md +868 -0
  78. package/docs/services/organizations/README.md +574 -0
  79. package/docs/services/personalize/README.md +835 -0
  80. package/docs/services/rekognition/README.md +1070 -0
  81. package/docs/services/route53/README.md +1783 -0
  82. package/docs/services/s3/README.md +3024 -0
  83. package/docs/services/scheduler/README.md +806 -0
  84. package/docs/services/secretsmanager/README.md +667 -0
  85. package/docs/services/ses/README.md +1011 -0
  86. package/docs/services/sns/README.md +1904 -0
  87. package/docs/services/sqs/README.md +1185 -0
  88. package/docs/services/ssm/README.md +1072 -0
  89. package/docs/services/stepfunctions/README.md +1332 -0
  90. package/docs/services/sts/README.md +245 -0
  91. package/docs/services/wafv2/README.md +1378 -0
  92. package/docs/terraform/README.md +248 -0
  93. package/docs/time/README.md +284 -0
  94. package/llms.txt +59 -0
  95. package/package.json +7 -4
@@ -2,34 +2,43 @@ import { SimAwsCallerResolver, } from "../../../aws/caller/sim-aws-caller-resolv
2
2
  /**
3
3
  * Resolves the caller and any policy sources implied by that caller.
4
4
  *
5
- * The configured default principal represents the simulated account root. It is
6
- * used only when the request omits a caller. An explicit anonymous caller does
7
- * not fall back to root.
5
+ * A request that omits a caller is decided as the simulation's default caller,
6
+ * and as the Account root where the simulation named none. An explicit
7
+ * anonymous caller falls back to neither.
8
8
  */
9
9
  export class SimIamAuthZCallerContextBuilder {
10
10
  callerResolver;
11
- defaultCallerPrincipal;
12
- constructor(defaultCallerPrincipal, credentialIdentityResolver) {
13
- this.defaultCallerPrincipal = defaultCallerPrincipal;
14
- this.callerResolver = new SimAwsCallerResolver(credentialIdentityResolver);
11
+ accountRootPrincipal;
12
+ accountRootArn;
13
+ constructor(properties) {
14
+ const root = properties.accountRootPrincipal;
15
+ this.accountRootPrincipal = root;
16
+ this.accountRootArn = root.kind === "arn" ? root.arn : undefined;
17
+ this.callerResolver = new SimAwsCallerResolver({
18
+ credentialIdentityResolver: properties.credentialIdentityResolver,
19
+ defaultCaller: properties.defaultCaller,
20
+ });
15
21
  }
16
22
  /**
17
23
  * Resolve request caller data and add the simulated root policy when
18
24
  * applicable.
19
25
  */
20
26
  build(caller) {
21
- const resolvedCaller = this.callerResolver.resolve(caller, this.defaultCallerPrincipal);
27
+ const resolvedCaller = this.callerResolver.resolve(caller, this.accountRootPrincipal);
22
28
  return {
23
29
  caller: resolvedCaller,
24
30
  rootPolicySources: this.rootPolicySources(resolvedCaller),
25
31
  };
26
32
  }
27
33
  /**
28
- * Give the configured account-root principal unrestricted identity access.
34
+ * Give the Account's root principal unrestricted identity access.
35
+ *
36
+ * The comparison names the root principal explicitly, so a simulation with a
37
+ * default caller keeps this access on the root where AWS has it.
29
38
  */
30
39
  rootPolicySources(caller) {
31
- const defaultCaller = this.callerResolver.resolve(this.defaultCallerPrincipal, this.defaultCallerPrincipal);
32
- if (defaultCaller.arn === undefined || caller.arn !== defaultCaller.arn) {
40
+ if (this.accountRootArn === undefined ||
41
+ caller.arn !== this.accountRootArn) {
33
42
  return [];
34
43
  }
35
44
  return [
@@ -1,6 +1,6 @@
1
1
  import type { SimArn } from "../../../aws/arn.js";
2
2
  import type { AwsRegionName } from "../../../aws/sim-aws-region.js";
3
- import type { SimAwsCaller, SimAwsPrincipal } from "../../../aws/caller/sim-aws-caller.js";
3
+ import type { SimAwsCaller, SimAwsDefaultCaller, SimAwsPrincipal } from "../../../aws/caller/sim-aws-caller.js";
4
4
  import type { SimAwsAccountId } from "../../../aws/sim-aws-account.js";
5
5
  import type { SimIamAccountResolver } from "../../registry/sim-iam-account-resolver.js";
6
6
  import type { SimIamConditionValue, SimIamPolicy, SimIamPolicyDocument } from "../../policy/sim-iam-policy.js";
@@ -85,6 +85,7 @@ interface SimIamAuthZContextBuilderProperties {
85
85
  readonly roles: ReadonlyMap<SimIamRoleName, SimIamRole>;
86
86
  readonly users: ReadonlyMap<SimIamUsername, SimIamUser>;
87
87
  readonly credentialIdentityResolver: SimAwsCredentialIdentityResolver;
88
+ readonly defaultCaller?: SimAwsDefaultCaller | undefined;
88
89
  /**
89
90
  * Resolves other Accounts' IAM in the same simulation, for the identity side
90
91
  * of a cross-Account request.
@@ -43,7 +43,11 @@ export class SimIamAuthZContextBuilder {
43
43
  derivedConditions = new SimIamDerivedConditions();
44
44
  scpSourceBuilder;
45
45
  constructor(properties) {
46
- this.callerContextBuilder = new SimIamAuthZCallerContextBuilder(makeSimAwsAccountRootPrincipal(properties.accountId), properties.credentialIdentityResolver);
46
+ this.callerContextBuilder = new SimIamAuthZCallerContextBuilder({
47
+ accountRootPrincipal: makeSimAwsAccountRootPrincipal(properties.accountId),
48
+ credentialIdentityResolver: properties.credentialIdentityResolver,
49
+ defaultCaller: properties.defaultCaller,
50
+ });
47
51
  this.identityPolicyCoordinator = new SimIamAuthZIdentityPolicyCoordinator({
48
52
  policies: properties.policies,
49
53
  roles: properties.roles,
@@ -47,8 +47,18 @@ export declare class SimIamPolicyPrincipalMatcher {
47
47
  * The wildcard matches both authenticated and anonymous requests. Other AWS
48
48
  * forms require an ARN-based caller. Account delegation forms compare against
49
49
  * the account ID derived by the caller resolver.
50
+ *
51
+ * A pattern is compared against two ARNs, because an assumed-role session
52
+ * has two. The session ARN is the caller, and the Role behind it is the
53
+ * identity whose policies apply. AWS matches a policy naming either one, and
54
+ * recommends naming the Role. The two ARNs are the same for every caller
55
+ * that is not a session, so one comparison happens in that case.
50
56
  */
51
57
  private awsPatternMatches;
58
+ /**
59
+ * Whether a principal pattern names one of the caller's ARNs.
60
+ */
61
+ private arnMatches;
52
62
  /**
53
63
  * Compare a service principal pattern with the resolved caller.
54
64
  *
@@ -81,6 +81,12 @@ export class SimIamPolicyPrincipalMatcher {
81
81
  * The wildcard matches both authenticated and anonymous requests. Other AWS
82
82
  * forms require an ARN-based caller. Account delegation forms compare against
83
83
  * the account ID derived by the caller resolver.
84
+ *
85
+ * A pattern is compared against two ARNs, because an assumed-role session
86
+ * has two. The session ARN is the caller, and the Role behind it is the
87
+ * identity whose policies apply. AWS matches a policy naming either one, and
88
+ * recommends naming the Role. The two ARNs are the same for every caller
89
+ * that is not a session, so one comparison happens in that case.
84
90
  */
85
91
  awsPatternMatches(pattern) {
86
92
  if (pattern === "*") {
@@ -94,9 +100,15 @@ export class SimIamPolicyPrincipalMatcher {
94
100
  if (delegatedAccountId !== undefined) {
95
101
  return SimIamPrincipalMatch.accountDelegation().when(caller.accountId === delegatedAccountId);
96
102
  }
97
- return SimIamPrincipalMatch.direct().when(simIamWildcardMatch(pattern, caller.arn, {
98
- caseSensitive: true,
99
- }));
103
+ return SimIamPrincipalMatch.direct().when(this.arnMatches(pattern, caller.arn) ||
104
+ this.arnMatches(pattern, caller.identityPolicyArn));
105
+ }
106
+ /**
107
+ * Whether a principal pattern names one of the caller's ARNs.
108
+ */
109
+ arnMatches(pattern, arn) {
110
+ return (arn !== undefined &&
111
+ simIamWildcardMatch(pattern, arn, { caseSensitive: true }));
100
112
  }
101
113
  /**
102
114
  * Compare a service principal pattern with the resolved caller.
@@ -1,7 +1,7 @@
1
1
  import type { SimAwsAccountId } from "../../aws/sim-aws-account.js";
2
2
  import type { SimArn } from "../../aws/arn.js";
3
3
  import type { SimAwsCredentialIdentityResolver } from "../../aws/caller/sim-aws-caller-resolver.js";
4
- import type { SimAwsPrincipal } from "../../aws/caller/sim-aws-caller.js";
4
+ import type { SimAwsDefaultCaller, SimAwsPrincipal } from "../../aws/caller/sim-aws-caller.js";
5
5
  import type { SimIamManagedPolicy } from "../policy/sim-iam-policy.js";
6
6
  import type { SimIamRole, SimIamRoleName } from "../role/sim-iam-role.js";
7
7
  import type { SimIamUser, SimIamUsername } from "../user/sim-iam-user.js";
@@ -17,6 +17,12 @@ interface SimIamAccountAuthZProperties {
17
17
  readonly roles: Map<SimIamRoleName, SimIamRole>;
18
18
  readonly users: Map<SimIamUsername, SimIamUser>;
19
19
  readonly credentialIdentityResolver: SimAwsCredentialIdentityResolver;
20
+ /**
21
+ * The caller this simulation attributes a request naming none to.
22
+ *
23
+ * Left out, such a request is decided as this Account's root principal.
24
+ */
25
+ readonly defaultCaller?: SimAwsDefaultCaller | undefined;
20
26
  /**
21
27
  * Resolves other Accounts' IAM in the same simulation.
22
28
  *
@@ -37,9 +43,10 @@ interface SimIamAccountAuthZProperties {
37
43
  * Evaluates IAM authorization attempts against one simulated Account's IAM
38
44
  * state.
39
45
  *
40
- * If the caller is omitted, authorization defaults to the root principal of
41
- * the owning sim Account. An explicit anonymous caller suppresses that
42
- * fallback and is evaluated without identity policies.
46
+ * If the caller is omitted, authorization defaults to the simulation's default
47
+ * caller, and to the root principal of the owning sim Account where the
48
+ * simulation has none. An explicit anonymous caller suppresses both and is
49
+ * evaluated without identity policies.
43
50
  */
44
51
  export declare class SimIamAccountAuthZ implements SimIamAccountIdentityPolicies {
45
52
  private readonly properties;
@@ -3,9 +3,10 @@ import { SimIamAuthorizer } from "./sim-iam-authorizer.js";
3
3
  * Evaluates IAM authorization attempts against one simulated Account's IAM
4
4
  * state.
5
5
  *
6
- * If the caller is omitted, authorization defaults to the root principal of
7
- * the owning sim Account. An explicit anonymous caller suppresses that
8
- * fallback and is evaluated without identity policies.
6
+ * If the caller is omitted, authorization defaults to the simulation's default
7
+ * caller, and to the root principal of the owning sim Account where the
8
+ * simulation has none. An explicit anonymous caller suppresses both and is
9
+ * evaluated without identity policies.
9
10
  */
10
11
  export class SimIamAccountAuthZ {
11
12
  properties;
@@ -38,6 +39,7 @@ export class SimIamAccountAuthZ {
38
39
  roles: this.properties.roles,
39
40
  users: this.properties.users,
40
41
  credentialIdentityResolver: this.properties.credentialIdentityResolver,
42
+ defaultCaller: this.properties.defaultCaller,
41
43
  iamResolver: this.properties.iamResolver,
42
44
  scpResolver: this.properties.scpResolver,
43
45
  });
@@ -3,7 +3,7 @@ import type { SimIamPolicy } from "../policy/sim-iam-policy.js";
3
3
  import type { SimIamRole, SimIamRoleName } from "../role/sim-iam-role.js";
4
4
  import { type SimIamAuthorizationInput } from "./context/sim-iam-auth-z-context-builder.js";
5
5
  import { SimIamPolicyDecision } from "./sim-iam-decision.js";
6
- import type { SimAwsPrincipal } from "../../aws/caller/sim-aws-caller.js";
6
+ import type { SimAwsDefaultCaller, SimAwsPrincipal } from "../../aws/caller/sim-aws-caller.js";
7
7
  import type { SimIamUser, SimIamUsername } from "../user/sim-iam-user.js";
8
8
  import type { SimAwsCredentialIdentityResolver } from "../../aws/caller/sim-aws-caller-resolver.js";
9
9
  import type { SimAwsAccountId } from "../../aws/sim-aws-account.js";
@@ -17,6 +17,7 @@ interface SimIamAuthorizerProperties {
17
17
  readonly roles: ReadonlyMap<SimIamRoleName, SimIamRole>;
18
18
  readonly users: ReadonlyMap<SimIamUsername, SimIamUser>;
19
19
  readonly credentialIdentityResolver: SimAwsCredentialIdentityResolver;
20
+ readonly defaultCaller?: SimAwsDefaultCaller | undefined;
20
21
  readonly iamResolver?: SimIamAccountResolver | undefined;
21
22
  readonly scpResolver?: SimIamServiceControlPolicyResolver | undefined;
22
23
  }
@@ -17,6 +17,7 @@ export class SimIamAuthorizer {
17
17
  roles: properties.roles,
18
18
  users: properties.users,
19
19
  credentialIdentityResolver: properties.credentialIdentityResolver,
20
+ defaultCaller: properties.defaultCaller,
20
21
  iamResolver: properties.iamResolver,
21
22
  scpResolver: properties.scpResolver,
22
23
  });
@@ -1,5 +1,6 @@
1
1
  import { AsyncMappedFactory } from "@kensio/part-factory";
2
2
  import type { SimAws } from "../../aws/sim-aws.js";
3
+ import type { SimAwsCaller } from "../../aws/caller/sim-aws-caller.js";
3
4
  import type { SimCreateRoleCommandOutput } from "../command/role/create-role/create-role.command.js";
4
5
  /**
5
6
  * What a test asks for when it wants a Role that may do something.
@@ -13,6 +14,14 @@ export interface SimIamRoleWithPolicyInput {
13
14
  readonly policyName: string;
14
15
  readonly actions: readonly string[];
15
16
  readonly resource: string;
17
+ /**
18
+ * The principal creating the Role.
19
+ *
20
+ * A simulation given a default caller attributes these two commands to it,
21
+ * and a Role being created for that caller has no policies to allow them
22
+ * yet. Naming the Account root here is how such a test bootstraps.
23
+ */
24
+ readonly caller?: SimAwsCaller | undefined;
16
25
  }
17
26
  /**
18
27
  * The Role a CreateRole request answers with.
@@ -24,8 +24,10 @@ export const simIamRoleWithPolicyFactory = new AsyncMappedFactory(() => ({
24
24
  policyName: "ApplicationPolicy",
25
25
  actions: [],
26
26
  resource: "*",
27
+ caller: undefined,
27
28
  }), async (input, simAws) => {
28
29
  const simIam = simAws.iam();
30
+ const options = input.caller === undefined ? undefined : { caller: input.caller };
29
31
  const creation = await simIam.createRole({
30
32
  input: {
31
33
  RoleName: input.roleName,
@@ -38,7 +40,7 @@ export const simIamRoleWithPolicyFactory = new AsyncMappedFactory(() => ({
38
40
  },
39
41
  }),
40
42
  },
41
- });
43
+ }, options);
42
44
  await simIam.putRolePolicy({
43
45
  input: {
44
46
  RoleName: input.roleName,
@@ -47,6 +49,6 @@ export const simIamRoleWithPolicyFactory = new AsyncMappedFactory(() => ({
47
49
  Statement: { Action: input.actions, Resource: input.resource },
48
50
  }),
49
51
  },
50
- });
52
+ }, options);
51
53
  return creation.Role;
52
54
  });
@@ -1,6 +1,7 @@
1
1
  import { type BackgroundScheduler } from "../../util/background/background.js";
2
2
  import type { SimAwsAccountId } from "../aws/sim-aws-account.js";
3
3
  import type { SimAwsAccountRegionScope } from "../aws/sim-aws-account-region-scope.js";
4
+ import type { SimAwsDefaultCaller } from "../aws/caller/sim-aws-caller.js";
4
5
  import { SimIamAccountAuthZ } from "./authorize/sim-iam-account-auth-z.js";
5
6
  import type { SimIamInterServiceAuthZ } from "./authorize/sim-iam-inter-service-auth-z.js";
6
7
  import { SimIamCommandHandlers } from "./command/sim-iam-command-handlers.js";
@@ -19,6 +20,13 @@ export interface SimIamProperties {
19
20
  readonly credentialRegistry?: SimIamCredentialRegistry;
20
21
  readonly sessionCredentialGenerator?: SimIamSessionCredentialGenerator;
21
22
  readonly userCredentialGenerator?: SimIamUserCredentialGenerator;
23
+ /**
24
+ * The caller this simulation attributes a request naming none to.
25
+ *
26
+ * A SimAws passes on what it was built with. Left out, such a request is
27
+ * decided as the Account root, which is what a standalone SimIam does.
28
+ */
29
+ readonly defaultCaller?: SimAwsDefaultCaller | undefined;
22
30
  /**
23
31
  * Resolves the IAM of other Accounts in the same simulation.
24
32
  *
@@ -47,6 +47,7 @@ export class SimIamAccountParts {
47
47
  roles: this.roles,
48
48
  users: this.users,
49
49
  credentialIdentityResolver: credentialRegistry,
50
+ defaultCaller: properties.defaultCaller,
50
51
  iamResolver: properties.iamResolver,
51
52
  scpResolver: properties.scpResolver,
52
53
  });
@@ -1,4 +1,4 @@
1
- import type { SimArnPrincipal } from "../../aws/caller/sim-aws-caller.js";
1
+ import type { SimAwsResolvedCaller } from "../../aws/caller/sim-aws-caller-resolver.js";
2
2
  import type { SimAwsAccountId } from "../../aws/sim-aws-account.js";
3
3
  import type { AwsRegionName } from "../../aws/sim-aws-region.js";
4
4
  import type { SimGetRoleCommandOutput } from "../../iam/command/role/get-role/get-role.command.js";
@@ -14,7 +14,14 @@ interface AssumeRoleAuthorizationCoordinatorProperties {
14
14
  interface AssumeRoleAuthorizationInput {
15
15
  readonly roleArn: string;
16
16
  readonly roleArnParts: IamRoleArnParts;
17
- readonly caller: SimArnPrincipal;
17
+ /**
18
+ * The caller as the request boundary resolved it.
19
+ *
20
+ * Both sides of an AssumeRole decision need the identity whose policies
21
+ * apply, which is the Role behind an assumed-role session. Passing the
22
+ * resolved caller whole is what carries it here.
23
+ */
24
+ readonly caller: SimAwsResolvedCaller;
18
25
  readonly conditionContext?: Readonly<Record<string, SimIamConditionValue>> | undefined;
19
26
  }
20
27
  type AssumeRoleAuthorizedRole = SimGetRoleCommandOutput["Role"];
@@ -38,8 +38,8 @@ export class AssumeRoleAuthorizationCoordinator {
38
38
  });
39
39
  this.sourcePrincipalAuthorizer.authorize({
40
40
  roleArn: input.roleArn,
41
- callerPrincipal: input.caller,
42
- identityPolicyAllowRequired: !this.hasDirectSameAccountUserGrant(input.caller, input.roleArnParts.accountId, targetAuthorization.trust.isDirectPrincipalGrant),
41
+ caller: input.caller,
42
+ identityPolicyAllowRequired: !this.hasDirectSameAccountUserGrant(input.caller.principal, input.roleArnParts.accountId, targetAuthorization.trust.isDirectPrincipalGrant),
43
43
  });
44
44
  return targetAuthorization.role;
45
45
  }
@@ -1,7 +1,7 @@
1
1
  import type { SimIamAccountResolver } from "../../iam/registry/sim-iam-account-resolver.js";
2
2
  import type { SimAwsAccountId } from "../../aws/sim-aws-account.js";
3
3
  import type { AwsRegionName } from "../../aws/sim-aws-region.js";
4
- import type { SimAwsPrincipal } from "../../aws/caller/sim-aws-caller.js";
4
+ import type { SimAwsResolvedCaller } from "../../aws/caller/sim-aws-caller-resolver.js";
5
5
  interface AssumeRoleSourceAccountAuthorizerProperties {
6
6
  readonly sourceAccountId: SimAwsAccountId;
7
7
  readonly iamResolver: SimIamAccountResolver;
@@ -12,7 +12,13 @@ interface AssumeRoleSourceAccountAuthorizerProperties {
12
12
  }
13
13
  export interface AssumeRoleSourceAuthorizationInput {
14
14
  readonly roleArn: string;
15
- readonly callerPrincipal?: SimAwsPrincipal | undefined;
15
+ /**
16
+ * The caller as the request boundary resolved it.
17
+ *
18
+ * The identity policies deciding this are the ones held by the Role behind
19
+ * an assumed-role session, so the resolved caller travels here whole.
20
+ */
21
+ readonly caller?: SimAwsResolvedCaller | undefined;
16
22
  /**
17
23
  * Whether the caller must have an identity-policy Allow for sts:AssumeRole.
18
24
  *
@@ -31,8 +37,8 @@ export interface AssumeRoleSourceAuthorizationInput {
31
37
  * trust authorization is a separate responsibility and must be performed even
32
38
  * when the source and target Account are the same.
33
39
  *
34
- * When no caller principal is supplied, Sim IAM applies its normal default
35
- * caller behavior for the source Account.
40
+ * When no caller principal is supplied, sim IAM applies its own default caller
41
+ * behaviour for the source Account.
36
42
  */
37
43
  export declare class AssumeRoleSourcePrincipalAuthorizer {
38
44
  private readonly sourceAccountId;
@@ -1,4 +1,4 @@
1
- import { makeSimAwsAccountRootPrincipal } from "../../aws/caller/sim-aws-account-root-principal.js";
1
+ import { simAwsCallerFor } from "../../aws/caller/sim-aws-resolved-caller.js";
2
2
  import { SimIamAccessDenied } from "../../iam/error/sim-iam.error.js";
3
3
  /**
4
4
  * Authorizes the caller's request to assume a role against IAM in the source
@@ -10,8 +10,8 @@ import { SimIamAccessDenied } from "../../iam/error/sim-iam.error.js";
10
10
  * trust authorization is a separate responsibility and must be performed even
11
11
  * when the source and target Account are the same.
12
12
  *
13
- * When no caller principal is supplied, Sim IAM applies its normal default
14
- * caller behavior for the source Account.
13
+ * When no caller principal is supplied, sim IAM applies its own default caller
14
+ * behaviour for the source Account.
15
15
  */
16
16
  export class AssumeRoleSourcePrincipalAuthorizer {
17
17
  sourceAccountId;
@@ -30,18 +30,19 @@ export class AssumeRoleSourcePrincipalAuthorizer {
30
30
  */
31
31
  authorize(input) {
32
32
  const sourceIam = this.iamResolver.iamForAccount(this.sourceAccountId);
33
- const callerPrincipal = input.callerPrincipal ??
34
- makeSimAwsAccountRootPrincipal(this.sourceAccountId);
33
+ // A request with no caller of its own is left for sim IAM to attribute.
34
+ // The simulation's default caller reaches this decision the way it reaches
35
+ // every other one.
35
36
  const decision = sourceIam.authorize({
36
37
  action: "sts:AssumeRole",
37
38
  resource: input.roleArn,
38
39
  region: this.regionName,
39
- caller: callerPrincipal,
40
+ caller: input.caller === undefined ? undefined : simAwsCallerFor(input.caller),
40
41
  });
41
42
  if (decision.isExplicitDeny ||
42
43
  (decision.isImplicitDeny && Boolean(input.identityPolicyAllowRequired))) {
43
44
  throw new SimIamAccessDenied({
44
- principal: callerPrincipal,
45
+ principal: decision.caller.principal,
45
46
  action: "sts:AssumeRole",
46
47
  resource: input.roleArn,
47
48
  });
@@ -1,4 +1,4 @@
1
- import type { SimAwsPrincipal } from "../../aws/caller/sim-aws-caller.js";
1
+ import type { SimAwsResolvedCaller } from "../../aws/caller/sim-aws-caller-resolver.js";
2
2
  import type { SimAwsAccountId } from "../../aws/sim-aws-account.js";
3
3
  import type { AwsRegionName } from "../../aws/sim-aws-region.js";
4
4
  import type { SimIamAccountResolver } from "../../iam/registry/sim-iam-account-resolver.js";
@@ -17,7 +17,7 @@ type AssumeRoleTargetRole = SimGetRoleCommandOutput["Role"];
17
17
  interface AssumeRoleTargetAuthorizationInput {
18
18
  readonly roleArn: string;
19
19
  readonly target: IamRoleArnParts | SimAwsAccountId;
20
- readonly caller: SimAwsPrincipal;
20
+ readonly caller: SimAwsResolvedCaller;
21
21
  readonly conditionContext?: Readonly<Record<string, SimIamConditionValue>> | undefined;
22
22
  }
23
23
  interface AssumeRoleTargetAuthorization {
@@ -1,4 +1,4 @@
1
- import type { SimAwsPrincipal } from "../../aws/caller/sim-aws-caller.js";
1
+ import type { SimAwsResolvedCaller } from "../../aws/caller/sim-aws-caller-resolver.js";
2
2
  import type { AwsRegionName } from "../../aws/sim-aws-region.js";
3
3
  import type { SimGetRoleCommandOutput } from "../../iam/command/role/get-role/get-role.command.js";
4
4
  import type { SimIamConditionValue } from "../../iam/policy/sim-iam-policy.js";
@@ -14,7 +14,7 @@ interface AssumeRoleTrustPolicyAuthorizationInput {
14
14
  * target Account's service control policies can be conditioned on.
15
15
  */
16
16
  readonly region?: AwsRegionName | undefined;
17
- readonly caller: SimAwsPrincipal;
17
+ readonly caller: SimAwsResolvedCaller;
18
18
  readonly conditionContext?: Readonly<Record<string, SimIamConditionValue>> | undefined;
19
19
  }
20
20
  export interface AssumeRoleTrustPolicyAuthorization {
@@ -46,5 +46,9 @@ export declare class AssumeRoleTrustPolicyAuthorizer {
46
46
  * no trust-policy statement grants access, even if no explicit Deny matched.
47
47
  */
48
48
  authorize(input: AssumeRoleTrustPolicyAuthorizationInput): AssumeRoleTrustPolicyAuthorization;
49
+ /**
50
+ * Refuse the request as the caller that made it.
51
+ */
52
+ private refuse;
49
53
  }
50
54
  export {};
@@ -1,4 +1,5 @@
1
1
  import { jsonParse } from "../../../util/type-guard/json.js";
2
+ import { simAwsCallerFor } from "../../aws/caller/sim-aws-resolved-caller.js";
2
3
  import { SimIamAccessDenied } from "../../iam/error/sim-iam.error.js";
3
4
  import { AssumeRoleTrustGrantClassifier } from "./assume-role-trust-grant-classifier.js";
4
5
  /**
@@ -27,18 +28,14 @@ export class AssumeRoleTrustPolicyAuthorizer {
27
28
  */
28
29
  authorize(input) {
29
30
  if (input.role.AssumeRolePolicyDocument === undefined) {
30
- throw new SimIamAccessDenied({
31
- principal: input.caller,
32
- action: "sts:AssumeRole",
33
- resource: input.roleArn,
34
- });
31
+ this.refuse(input);
35
32
  }
36
33
  const trustPolicy = jsonParse(input.role.AssumeRolePolicyDocument);
37
34
  const decision = input.targetIam.authorize({
38
35
  action: "sts:AssumeRole",
39
36
  resource: input.roleArn,
40
37
  region: input.region,
41
- caller: input.caller,
38
+ caller: simAwsCallerFor(input.caller),
42
39
  conditionContext: input.conditionContext,
43
40
  resourcePolicies: [
44
41
  {
@@ -50,15 +47,21 @@ export class AssumeRoleTrustPolicyAuthorizer {
50
47
  ],
51
48
  });
52
49
  if (decision.isDenied || !decision.isAllowedByTrustPolicy) {
53
- throw new SimIamAccessDenied({
54
- principal: input.caller,
55
- action: "sts:AssumeRole",
56
- resource: input.roleArn,
57
- });
50
+ this.refuse(input);
58
51
  }
59
52
  return {
60
53
  decision,
61
54
  isDirectPrincipalGrant: this.trustGrantClassifier.hasDirectPrincipalGrant(decision.trustAllowStatements),
62
55
  };
63
56
  }
57
+ /**
58
+ * Refuse the request as the caller that made it.
59
+ */
60
+ refuse(input) {
61
+ throw new SimIamAccessDenied({
62
+ principal: input.caller.principal,
63
+ action: "sts:AssumeRole",
64
+ resource: input.roleArn,
65
+ });
66
+ }
64
67
  }
@@ -4,7 +4,7 @@ import type { SimAssumeRoleCommand, SimAssumeRoleCommandOutput } from "./assume-
4
4
  import { type BackgroundScheduler } from "../../../../util/background/background.js";
5
5
  import type { SimAwsAccountId } from "../../../aws/sim-aws-account.js";
6
6
  import type { AwsRegionName } from "../../../aws/sim-aws-region.js";
7
- import type { SimAwsCaller } from "../../../aws/caller/sim-aws-caller.js";
7
+ import type { SimAwsCaller, SimAwsDefaultCaller } from "../../../aws/caller/sim-aws-caller.js";
8
8
  interface AssumeRoleCommandHandlerProperties {
9
9
  readonly sourceAccountId: SimAwsAccountId;
10
10
  /**
@@ -13,6 +13,10 @@ interface AssumeRoleCommandHandlerProperties {
13
13
  readonly regionName: AwsRegionName;
14
14
  readonly iamResolver: SimIamAccountResolver;
15
15
  readonly background?: BackgroundScheduler;
16
+ /**
17
+ * The caller this simulation attributes a request naming none to.
18
+ */
19
+ readonly defaultCaller?: SimAwsDefaultCaller | undefined;
16
20
  }
17
21
  /**
18
22
  * STS AssumeRoleCommand handler.
@@ -16,7 +16,7 @@ import { AssumeRoleAuthorizationCoordinator } from "../../auth-z/assume-role-aut
16
16
  */
17
17
  export class AssumeRoleCommandHandler {
18
18
  background;
19
- callerResolver = new SimAwsCallerResolver();
19
+ callerResolver;
20
20
  requestParser = new SimStsAssumeRoleRequestParser();
21
21
  authorizationCoordinator;
22
22
  sessionCreator;
@@ -25,6 +25,9 @@ export class AssumeRoleCommandHandler {
25
25
  const { sourceAccountId, regionName, iamResolver, background = new BackgroundTasks(), } = properties;
26
26
  this.sourceAccountId = sourceAccountId;
27
27
  this.background = background;
28
+ this.callerResolver = new SimAwsCallerResolver({
29
+ defaultCaller: properties.defaultCaller,
30
+ });
28
31
  this.authorizationCoordinator = new AssumeRoleAuthorizationCoordinator({
29
32
  sourceAccountId,
30
33
  iamResolver,
@@ -56,7 +59,7 @@ export class AssumeRoleCommandHandler {
56
59
  const role = await this.authorizationCoordinator.authorize({
57
60
  roleArn: request.roleArn,
58
61
  roleArnParts: request.roleArnParts,
59
- caller: caller.principal,
62
+ caller,
60
63
  conditionContext: request.conditionContext,
61
64
  });
62
65
  return this.sessionCreator.create({
@@ -1,11 +1,15 @@
1
1
  import type { CommandHandler } from "../../../../command/command-handler.js";
2
- import type { SimAwsCaller } from "../../../aws/caller/sim-aws-caller.js";
2
+ import type { SimAwsCaller, SimAwsDefaultCaller } from "../../../aws/caller/sim-aws-caller.js";
3
3
  import type { SimAwsAccountId } from "../../../aws/sim-aws-account.js";
4
4
  import type { SimIamAccountResolver } from "../../../iam/registry/sim-iam-account-resolver.js";
5
5
  import type { SimGetCallerIdentityCommand, SimGetCallerIdentityCommandOutput } from "./get-caller-identity.command.js";
6
6
  interface GetCallerIdentityCommandHandlerProperties {
7
7
  readonly sourceAccountId: SimAwsAccountId;
8
8
  readonly iamResolver: SimIamAccountResolver;
9
+ /**
10
+ * The caller this simulation attributes a request naming none to.
11
+ */
12
+ readonly defaultCaller?: SimAwsDefaultCaller | undefined;
9
13
  }
10
14
  /**
11
15
  * Simulated STS GetCallerIdentity handler.
@@ -13,12 +13,15 @@ import { simStsCallerUserId } from "./sim-sts-caller-user-id.js";
13
13
  * https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/sts/command/GetCallerIdentityCommand/
14
14
  */
15
15
  export class GetCallerIdentityCommandHandler {
16
- callerResolver = new SimAwsCallerResolver();
16
+ callerResolver;
17
17
  sourceAccountId;
18
18
  iamResolver;
19
19
  constructor(properties) {
20
20
  this.sourceAccountId = properties.sourceAccountId;
21
21
  this.iamResolver = properties.iamResolver;
22
+ this.callerResolver = new SimAwsCallerResolver({
23
+ defaultCaller: properties.defaultCaller,
24
+ });
22
25
  }
23
26
  /**
24
27
  * Report the identity behind this request.
@@ -1,3 +1,4 @@
1
+ import { simAwsResolvedCallerOf } from "../../aws/caller/sim-aws-resolved-caller.js";
1
2
  import { SimIamAccessDenied } from "../../iam/error/sim-iam.error.js";
2
3
  import { AssumeRoleTrustPolicyAuthorizer } from "../auth-z/assume-role-trust-policy-authorizer.js";
3
4
  import { simServiceRoleConditionContext, } from "./sim-service-role-source.js";
@@ -25,7 +26,10 @@ export async function assumeSimServiceRole(assumption) {
25
26
  role,
26
27
  targetIam: iam,
27
28
  region: scope.accountRegionScope.regionName,
28
- caller: { kind: "service", service: servicePrincipal },
29
+ caller: simAwsResolvedCallerOf({
30
+ kind: "service",
31
+ service: servicePrincipal,
32
+ }),
29
33
  conditionContext: simServiceRoleConditionContext(source),
30
34
  });
31
35
  }