@byaga/cdk-patterns 0.5.0 → 0.6.1

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.
package/lib/Role.d.ts ADDED
@@ -0,0 +1,139 @@
1
+ import { IPrincipal, Role as CdkRole } from "aws-cdk-lib/aws-iam";
2
+ import { Duration } from "aws-cdk-lib";
3
+ import { IDeployStack } from "./IDeployStack";
4
+ import { IManagedPolicy } from "aws-cdk-lib/aws-iam/lib/managed-policy";
5
+ import { PolicyDocument } from "aws-cdk-lib/aws-iam/lib/policy-document";
6
+ interface IRoleProps {
7
+ identityPool: string;
8
+ amr: string;
9
+ /**
10
+ * The IAM principal (i.e. `new ServicePrincipal('sns.amazonaws.com')`) which can assume this role.
11
+ *
12
+ * You can later modify the assume role policy document by accessing it via
13
+ * the `assumeRolePolicy` property.
14
+ *
15
+ * @stability stable
16
+ */
17
+ assumedBy?: IPrincipal;
18
+ /**
19
+ * (deprecated) ID that the role assumer needs to provide when assuming this role.
20
+ *
21
+ * If the configured and provided external IDs do not match, the
22
+ * AssumeRole operation will fail.
23
+ *
24
+ * @default No external ID required
25
+ * @deprecated see {@link externalIds}
26
+ */
27
+ readonly externalId?: string;
28
+ /**
29
+ * List of IDs that the role assumer needs to provide one of when assuming this role.
30
+ *
31
+ * If the configured and provided external IDs do not match, the
32
+ * AssumeRole operation will fail.
33
+ *
34
+ * @default No external ID required
35
+ * @stability stable
36
+ */
37
+ readonly externalIds?: string[];
38
+ /**
39
+ * A list of managed policies associated with this role.
40
+ *
41
+ * You can add managed policies later using
42
+ * `addManagedPolicy(ManagedPolicy.fromAwsManagedPolicyName(policyName))`.
43
+ *
44
+ * @default - No managed policies.
45
+ * @stability stable
46
+ */
47
+ readonly managedPolicies?: IManagedPolicy[];
48
+ /**
49
+ * A list of named policies to inline into this role.
50
+ *
51
+ * These policies will be
52
+ * created with the role, whereas those added by ``addToPolicy`` are added
53
+ * using a separate CloudFormation resource (allowing a way around circular
54
+ * dependencies that could otherwise be introduced).
55
+ *
56
+ * @default - No policy is inlined in the Role resource.
57
+ * @stability stable
58
+ */
59
+ readonly inlinePolicies?: {
60
+ [name: string]: PolicyDocument;
61
+ };
62
+ /**
63
+ * The path associated with this role.
64
+ *
65
+ * For information about IAM paths, see
66
+ * Friendly Names and Paths in IAM User Guide.
67
+ *
68
+ * @default /
69
+ * @stability stable
70
+ */
71
+ readonly path?: string;
72
+ /**
73
+ * AWS supports permissions boundaries for IAM entities (users or roles).
74
+ *
75
+ * A permissions boundary is an advanced feature for using a managed policy
76
+ * to set the maximum permissions that an identity-based policy can grant to
77
+ * an IAM entity. An entity's permissions boundary allows it to perform only
78
+ * the actions that are allowed by both its identity-based policies and its
79
+ * permissions boundaries.
80
+ *
81
+ * @default - No permissions boundary.
82
+ * @stability stable
83
+ * @link https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_boundaries.html
84
+ */
85
+ readonly permissionsBoundary?: IManagedPolicy;
86
+ /**
87
+ * A name for the IAM role.
88
+ *
89
+ * For valid values, see the RoleName parameter for
90
+ * the CreateRole action in the IAM API Reference.
91
+ *
92
+ * IMPORTANT: If you specify a name, you cannot perform updates that require
93
+ * replacement of this resource. You can perform updates that require no or
94
+ * some interruption. If you must replace the resource, specify a new name.
95
+ *
96
+ * If you specify a name, you must specify the CAPABILITY_NAMED_IAM value to
97
+ * acknowledge your template's capabilities. For more information, see
98
+ * Acknowledging IAM Resources in AWS CloudFormation Templates.
99
+ *
100
+ * @default - AWS CloudFormation generates a unique physical ID and uses that ID
101
+ * for the role name.
102
+ * @stability stable
103
+ */
104
+ readonly roleName?: string;
105
+ /**
106
+ * The maximum session duration that you want to set for the specified role.
107
+ *
108
+ * This setting can have a value from 1 hour (3600sec) to 12 (43200sec) hours.
109
+ *
110
+ * Anyone who assumes the role from the AWS CLI or API can use the
111
+ * DurationSeconds API parameter or the duration-seconds CLI parameter to
112
+ * request a longer session. The MaxSessionDuration setting determines the
113
+ * maximum duration that can be requested using the DurationSeconds
114
+ * parameter.
115
+ *
116
+ * If users don't specify a value for the DurationSeconds parameter, their
117
+ * security credentials are valid for one hour by default. This applies when
118
+ * you use the AssumeRole* API operations or the assume-role* CLI operations
119
+ * but does not apply when you use those operations to create a console URL.
120
+ *
121
+ * @default Duration.hours(1)
122
+ * @stability stable
123
+ * @link https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use.html
124
+ */
125
+ readonly maxSessionDuration?: Duration;
126
+ /**
127
+ * A description of the role.
128
+ *
129
+ * It can be up to 1000 characters long.
130
+ *
131
+ * @default - No description.
132
+ * @stability stable
133
+ */
134
+ readonly description?: string;
135
+ }
136
+ export declare class Role extends CdkRole {
137
+ constructor(stack: IDeployStack, id: string, props: IRoleProps);
138
+ }
139
+ export {};
package/lib/Role.js ADDED
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Role = void 0;
4
+ const aws_iam_1 = require("aws-cdk-lib/aws-iam");
5
+ const aws_cdk_lib_1 = require("aws-cdk-lib");
6
+ class Role extends aws_iam_1.Role {
7
+ constructor(stack, id, props) {
8
+ console.log('Defining Role', stack.genId(id));
9
+ if (!props.assumedBy) {
10
+ props.assumedBy = new aws_iam_1.FederatedPrincipal('cognito-identity.amazonaws.com', {
11
+ StringEquals: {
12
+ 'cognito-identity.amazonaws.com:aud': props.identityPool
13
+ },
14
+ "ForAnyValue:StringLike": {
15
+ 'cognito-identity.amazonaws.com:amr': props.amr
16
+ }
17
+ }, 'sts:AssumeRoleWithWebIdentity');
18
+ }
19
+ super(stack, stack.genId(id), {
20
+ ...props,
21
+ roleName: stack.genName(props.roleName || id),
22
+ assumedBy: props.assumedBy
23
+ });
24
+ new aws_cdk_lib_1.CfnOutput(stack, stack.genId(id, 'arn-output'), {
25
+ value: this.roleArn,
26
+ exportName: stack.genName(id, 'arn')
27
+ });
28
+ }
29
+ }
30
+ exports.Role = Role;
package/lib/index.d.ts CHANGED
@@ -3,3 +3,4 @@ export { IDeployStack } from "./IDeployStack";
3
3
  export { IDomainConfig } from "./IDomainConfig";
4
4
  export { IHostedZoneConfig } from "./IHostedZoneConfig";
5
5
  export { IStackArguments } from "./IStackArguments";
6
+ export { Role } from "./Role";
package/lib/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IDeployStack = exports.ApiCertificate = void 0;
3
+ exports.Role = exports.IDeployStack = exports.ApiCertificate = void 0;
4
4
  var ApiCertificate_1 = require("./ApiCertificate");
5
5
  Object.defineProperty(exports, "ApiCertificate", { enumerable: true, get: function () { return ApiCertificate_1.ApiCertificate; } });
6
6
  var IDeployStack_1 = require("./IDeployStack");
7
7
  Object.defineProperty(exports, "IDeployStack", { enumerable: true, get: function () { return IDeployStack_1.IDeployStack; } });
8
+ var Role_1 = require("./Role");
9
+ Object.defineProperty(exports, "Role", { enumerable: true, get: function () { return Role_1.Role; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@byaga/cdk-patterns",
3
- "version": "0.5.0",
3
+ "version": "0.6.1",
4
4
  "description": "Collection of common patterns used when making AWS CloudFormation templates using CDK",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -15,13 +15,12 @@
15
15
  "author": "VeryFineHat",
16
16
  "license": "MIT",
17
17
  "dependencies": {
18
+ "aws-cdk": "^2.92.0",
18
19
  "aws-cdk-lib": "^2.92.0",
19
- "constructs": "^10.2.69",
20
- "fs-extra": "^11.1.1",
21
- "glob": "^10.3.3",
22
- "js-yaml": "^4.1.0"
20
+ "constructs": "^10.2.69"
23
21
  },
24
22
  "devDependencies": {
23
+ "@types/node": "^20.5.0",
25
24
  "typescript": "^5.1.6"
26
25
  }
27
26
  }
package/src/Role.ts ADDED
@@ -0,0 +1,167 @@
1
+ import {FederatedPrincipal, IPrincipal, Role as CdkRole} from "aws-cdk-lib/aws-iam";
2
+ import {CfnOutput, Duration} from "aws-cdk-lib";
3
+ import {IDeployStack} from "./IDeployStack";
4
+ import {IManagedPolicy} from "aws-cdk-lib/aws-iam/lib/managed-policy";
5
+ import {PolicyDocument} from "aws-cdk-lib/aws-iam/lib/policy-document";
6
+
7
+ interface IRoleProps {
8
+ identityPool: string,
9
+ amr: string,
10
+ /**
11
+ * The IAM principal (i.e. `new ServicePrincipal('sns.amazonaws.com')`) which can assume this role.
12
+ *
13
+ * You can later modify the assume role policy document by accessing it via
14
+ * the `assumeRolePolicy` property.
15
+ *
16
+ * @stability stable
17
+ */
18
+ assumedBy?: IPrincipal,
19
+
20
+ /**
21
+ * (deprecated) ID that the role assumer needs to provide when assuming this role.
22
+ *
23
+ * If the configured and provided external IDs do not match, the
24
+ * AssumeRole operation will fail.
25
+ *
26
+ * @default No external ID required
27
+ * @deprecated see {@link externalIds}
28
+ */
29
+ readonly externalId?: string;
30
+ /**
31
+ * List of IDs that the role assumer needs to provide one of when assuming this role.
32
+ *
33
+ * If the configured and provided external IDs do not match, the
34
+ * AssumeRole operation will fail.
35
+ *
36
+ * @default No external ID required
37
+ * @stability stable
38
+ */
39
+ readonly externalIds?: string[];
40
+ /**
41
+ * A list of managed policies associated with this role.
42
+ *
43
+ * You can add managed policies later using
44
+ * `addManagedPolicy(ManagedPolicy.fromAwsManagedPolicyName(policyName))`.
45
+ *
46
+ * @default - No managed policies.
47
+ * @stability stable
48
+ */
49
+ readonly managedPolicies?: IManagedPolicy[];
50
+ /**
51
+ * A list of named policies to inline into this role.
52
+ *
53
+ * These policies will be
54
+ * created with the role, whereas those added by ``addToPolicy`` are added
55
+ * using a separate CloudFormation resource (allowing a way around circular
56
+ * dependencies that could otherwise be introduced).
57
+ *
58
+ * @default - No policy is inlined in the Role resource.
59
+ * @stability stable
60
+ */
61
+ readonly inlinePolicies?: {
62
+ [name: string]: PolicyDocument;
63
+ };
64
+ /**
65
+ * The path associated with this role.
66
+ *
67
+ * For information about IAM paths, see
68
+ * Friendly Names and Paths in IAM User Guide.
69
+ *
70
+ * @default /
71
+ * @stability stable
72
+ */
73
+ readonly path?: string;
74
+ /**
75
+ * AWS supports permissions boundaries for IAM entities (users or roles).
76
+ *
77
+ * A permissions boundary is an advanced feature for using a managed policy
78
+ * to set the maximum permissions that an identity-based policy can grant to
79
+ * an IAM entity. An entity's permissions boundary allows it to perform only
80
+ * the actions that are allowed by both its identity-based policies and its
81
+ * permissions boundaries.
82
+ *
83
+ * @default - No permissions boundary.
84
+ * @stability stable
85
+ * @link https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_boundaries.html
86
+ */
87
+ readonly permissionsBoundary?: IManagedPolicy;
88
+ /**
89
+ * A name for the IAM role.
90
+ *
91
+ * For valid values, see the RoleName parameter for
92
+ * the CreateRole action in the IAM API Reference.
93
+ *
94
+ * IMPORTANT: If you specify a name, you cannot perform updates that require
95
+ * replacement of this resource. You can perform updates that require no or
96
+ * some interruption. If you must replace the resource, specify a new name.
97
+ *
98
+ * If you specify a name, you must specify the CAPABILITY_NAMED_IAM value to
99
+ * acknowledge your template's capabilities. For more information, see
100
+ * Acknowledging IAM Resources in AWS CloudFormation Templates.
101
+ *
102
+ * @default - AWS CloudFormation generates a unique physical ID and uses that ID
103
+ * for the role name.
104
+ * @stability stable
105
+ */
106
+ readonly roleName?: string;
107
+ /**
108
+ * The maximum session duration that you want to set for the specified role.
109
+ *
110
+ * This setting can have a value from 1 hour (3600sec) to 12 (43200sec) hours.
111
+ *
112
+ * Anyone who assumes the role from the AWS CLI or API can use the
113
+ * DurationSeconds API parameter or the duration-seconds CLI parameter to
114
+ * request a longer session. The MaxSessionDuration setting determines the
115
+ * maximum duration that can be requested using the DurationSeconds
116
+ * parameter.
117
+ *
118
+ * If users don't specify a value for the DurationSeconds parameter, their
119
+ * security credentials are valid for one hour by default. This applies when
120
+ * you use the AssumeRole* API operations or the assume-role* CLI operations
121
+ * but does not apply when you use those operations to create a console URL.
122
+ *
123
+ * @default Duration.hours(1)
124
+ * @stability stable
125
+ * @link https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use.html
126
+ */
127
+ readonly maxSessionDuration?: Duration;
128
+ /**
129
+ * A description of the role.
130
+ *
131
+ * It can be up to 1000 characters long.
132
+ *
133
+ * @default - No description.
134
+ * @stability stable
135
+ */
136
+ readonly description?: string;
137
+ }
138
+
139
+ export class Role extends CdkRole {
140
+ constructor(stack: IDeployStack, id: string, props: IRoleProps) {
141
+ console.log('Defining Role', stack.genId(id))
142
+ if (!props.assumedBy) {
143
+ props.assumedBy = new FederatedPrincipal(
144
+ 'cognito-identity.amazonaws.com',
145
+ {
146
+ StringEquals: {
147
+ 'cognito-identity.amazonaws.com:aud': props.identityPool
148
+ },
149
+ "ForAnyValue:StringLike": {
150
+ 'cognito-identity.amazonaws.com:amr': props.amr
151
+ }
152
+ },
153
+ 'sts:AssumeRoleWithWebIdentity'
154
+ )
155
+ }
156
+
157
+ super(stack, stack.genId(id), {
158
+ ...props,
159
+ roleName: stack.genName(props.roleName || id),
160
+ assumedBy: props.assumedBy
161
+ })
162
+ new CfnOutput(stack, stack.genId(id, 'arn-output'), {
163
+ value: this.roleArn,
164
+ exportName: stack.genName(id, 'arn')
165
+ })
166
+ }
167
+ }
package/src/index.ts CHANGED
@@ -3,3 +3,4 @@ export {IDeployStack} from "./IDeployStack";
3
3
  export {IDomainConfig} from "./IDomainConfig";
4
4
  export {IHostedZoneConfig} from "./IHostedZoneConfig";
5
5
  export {IStackArguments} from "./IStackArguments";
6
+ export {Role} from "./Role";