@guardian/cdk 62.3.5 → 62.4.0

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.
@@ -0,0 +1,65 @@
1
+ import { ManagedPolicy, PolicyStatement } from "aws-cdk-lib/aws-iam";
2
+ import type { GuStack } from "../../../../constructs/core";
3
+ import type { GuAllowPolicyProps, GuDenyPolicyProps } from "../../../../constructs/iam";
4
+ export type GuWorkloadPolicyProps = {
5
+ /**
6
+ * List of explicitly allowed permissions given by this policy.
7
+ */
8
+ readonly allow?: GuAllowPolicyProps[];
9
+ /**
10
+ * List of explicitly denied permissions which can be used to fine tune this policy by pruning the allow permissions.
11
+ */
12
+ readonly deny?: GuDenyPolicyProps[];
13
+ /**
14
+ * Initial set of permissions to add to this policy document.
15
+ * You can also use `addPermission(statement)` to add permissions later.
16
+ *
17
+ * @default - No statements.
18
+ */
19
+ readonly statements?: PolicyStatement[];
20
+ /**
21
+ * The unique identifier of the policy, which will be displayed when creating credentials.
22
+ */
23
+ readonly permission: string;
24
+ /**
25
+ * An optional description of the policy which will be displayed if present.
26
+ */
27
+ readonly description?: string;
28
+ };
29
+ /**
30
+ * Creates a structured `AWS::IAM::ManagedPolicy` resource to manage arbitrary permissions on general account
31
+ * resources which can then be used to create limited permission credentials for use with specific activities.
32
+ *
33
+ * The permission scope is not controlled. This class should be used with care to create minimal permissions.
34
+ * To that end, broad ALLOW permissions can pruned with narrower optional DENY permissions.
35
+ *
36
+ * `permission` is prefixed with `/developer-policy/` and postfixed with `/` to construct the path. This will
37
+ * be used for discovery and display. It is restricted to the same character set as AWS `path`.
38
+ *
39
+ * `description` is optionally used to construct the AWS Managed Policy description and used for display.
40
+ *
41
+ * ```yaml
42
+ * TestingECAE2E87:
43
+ * Type: AWS::IAM::ManagedPolicy
44
+ * Properties:
45
+ * Description: This is testing stuff
46
+ * Path: /developer-policy/read-from-mybucket-under-mypath/
47
+ * PolicyDocument:
48
+ * Statement:
49
+ * - Action: s3:GetObject
50
+ * Effect: Allow
51
+ * Resource: arn:aws:s3:::mybucket/mypath
52
+ * - Action: s3:GetObject
53
+ * Effect: Deny
54
+ * Resource: arn:aws:s3:::mybucket/mypath/butnotthispath
55
+ * Version: "2012-10-17"
56
+ * Metadata:
57
+ * aws:cdk:path: janus-resources-for-testing-managed-policy-tagging/justin-testing/Resource* ```
58
+ * ```
59
+ *
60
+ * @experimental
61
+ */
62
+ export declare class GuDeveloperPolicyExperimental extends ManagedPolicy {
63
+ constructor(scope: GuStack, id: string, props: GuWorkloadPolicyProps);
64
+ }
65
+ //# sourceMappingURL=developer-policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"developer-policy.d.ts","sourceRoot":"","sources":["../../../../../src/experimental/constructs/iam/policies/developer-policy.ts"],"names":[],"mappings":"AACA,OAAO,EAAU,aAAa,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC7E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAExF,MAAM,MAAM,qBAAqB,GAAG;IAClC;;OAEG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,kBAAkB,EAAE,CAAC;IACtC;;OAEG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,iBAAiB,EAAE,CAAC;IACpC;;;;;OAKG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,eAAe,EAAE,CAAC;IACxC;;OAEG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B;;OAEG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,qBAAa,6BAA8B,SAAQ,aAAa;gBAClD,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,qBAAqB;CAsErE"}
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GuDeveloperPolicyExperimental = void 0;
4
+ const aws_cdk_lib_1 = require("aws-cdk-lib");
5
+ const aws_iam_1 = require("aws-cdk-lib/aws-iam");
6
+ /**
7
+ * Creates a structured `AWS::IAM::ManagedPolicy` resource to manage arbitrary permissions on general account
8
+ * resources which can then be used to create limited permission credentials for use with specific activities.
9
+ *
10
+ * The permission scope is not controlled. This class should be used with care to create minimal permissions.
11
+ * To that end, broad ALLOW permissions can pruned with narrower optional DENY permissions.
12
+ *
13
+ * `permission` is prefixed with `/developer-policy/` and postfixed with `/` to construct the path. This will
14
+ * be used for discovery and display. It is restricted to the same character set as AWS `path`.
15
+ *
16
+ * `description` is optionally used to construct the AWS Managed Policy description and used for display.
17
+ *
18
+ * ```yaml
19
+ * TestingECAE2E87:
20
+ * Type: AWS::IAM::ManagedPolicy
21
+ * Properties:
22
+ * Description: This is testing stuff
23
+ * Path: /developer-policy/read-from-mybucket-under-mypath/
24
+ * PolicyDocument:
25
+ * Statement:
26
+ * - Action: s3:GetObject
27
+ * Effect: Allow
28
+ * Resource: arn:aws:s3:::mybucket/mypath
29
+ * - Action: s3:GetObject
30
+ * Effect: Deny
31
+ * Resource: arn:aws:s3:::mybucket/mypath/butnotthispath
32
+ * Version: "2012-10-17"
33
+ * Metadata:
34
+ * aws:cdk:path: janus-resources-for-testing-managed-policy-tagging/justin-testing/Resource* ```
35
+ * ```
36
+ *
37
+ * @experimental
38
+ */
39
+ class GuDeveloperPolicyExperimental extends aws_iam_1.ManagedPolicy {
40
+ constructor(scope, id, props) {
41
+ super(scope, id, {
42
+ description: `${props.permission} developer policy`,
43
+ ...props,
44
+ path: `/developer-policy/${props.permission}/`,
45
+ });
46
+ let valid = true;
47
+ const { statements = [] } = props;
48
+ for (const statement of statements) {
49
+ if (statement.effect === aws_iam_1.Effect.ALLOW) {
50
+ for (const action of statement.actions) {
51
+ if (action === "*") {
52
+ const name = statement.actions.join(",");
53
+ aws_cdk_lib_1.Annotations.of(this).addError(`Action of '*' found in ${name} ALLOW permission`);
54
+ valid = false;
55
+ }
56
+ }
57
+ for (const resource of statement.resources) {
58
+ if (resource === "*") {
59
+ const name = statement.actions.join(",");
60
+ aws_cdk_lib_1.Annotations.of(this).addError(`Resource of '*' found in ${name} ALLOW permission`);
61
+ valid = false;
62
+ }
63
+ }
64
+ }
65
+ }
66
+ const { allow = [] } = props;
67
+ for (const allowed of allow) {
68
+ // validity checks
69
+ const name = allowed.policyName ?? allowed.actions.join(",") + " on " + allowed.resources.join(",");
70
+ for (const resource of allowed.resources) {
71
+ if (resource === "*") {
72
+ aws_cdk_lib_1.Annotations.of(this).addError(`Resource of '*' found in ${name} ALLOW permission`);
73
+ valid = false;
74
+ }
75
+ }
76
+ for (const action of allowed.actions) {
77
+ if (action === "*") {
78
+ const name = allowed.policyName ?? allowed.actions.join(",");
79
+ aws_cdk_lib_1.Annotations.of(this).addError(`Action of '*' found in ${name} ALLOW permission`);
80
+ valid = false;
81
+ }
82
+ }
83
+ this.addStatements(new aws_iam_1.PolicyStatement({
84
+ effect: aws_iam_1.Effect.ALLOW,
85
+ resources: allowed.resources,
86
+ actions: allowed.actions,
87
+ }));
88
+ }
89
+ if (!valid) {
90
+ throw new Error("Overly broad permission present, see annotations for details");
91
+ }
92
+ const { deny = [] } = props;
93
+ for (const denied of deny) {
94
+ this.addStatements(new aws_iam_1.PolicyStatement({
95
+ effect: aws_iam_1.Effect.DENY,
96
+ resources: denied.resources,
97
+ actions: denied.actions,
98
+ }));
99
+ }
100
+ }
101
+ }
102
+ exports.GuDeveloperPolicyExperimental = GuDeveloperPolicyExperimental;
103
+ //# sourceMappingURL=developer-policy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"developer-policy.js","sourceRoot":"","sources":["../../../../../src/experimental/constructs/iam/policies/developer-policy.ts"],"names":[],"mappings":";;;AAAA,6CAA0C;AAC1C,iDAA6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AC,IAAI;gBACnB,SAAS,EAAE,MAAM,CAAC,SAAS;gBAC3B,OAAO,EAAE,MAAM,CAAC,OAAO;aACxB,CAAC,CACH,CAAC;SACH;IACH,CAAC;CACF;AAvED,sEAuEC","sourcesContent":["import { Annotations } from \"aws-cdk-lib\";\nimport { Effect, ManagedPolicy, PolicyStatement } from \"aws-cdk-lib/aws-iam\";\nimport type { GuStack } from \"../../../../constructs/core\";\nimport type { GuAllowPolicyProps, GuDenyPolicyProps } from \"../../../../constructs/iam\";\n\nexport type GuWorkloadPolicyProps = {\n /**\n * List of explicitly allowed permissions given by this policy.\n */\n readonly allow?: GuAllowPolicyProps[];\n /**\n * List of explicitly denied permissions which can be used to fine tune this policy by pruning the allow permissions.\n */\n readonly deny?: GuDenyPolicyProps[];\n /**\n * Initial set of permissions to add to this policy document.\n * You can also use `addPermission(statement)` to add permissions later.\n *\n * @default - No statements.\n */\n readonly statements?: PolicyStatement[];\n /**\n * The unique identifier of the policy, which will be displayed when creating credentials.\n */\n readonly permission: string;\n /**\n * An optional description of the policy which will be displayed if present.\n */\n readonly description?: string;\n};\n\n/**\n * Creates a structured `AWS::IAM::ManagedPolicy` resource to manage arbitrary permissions on general account\n * resources which can then be used to create limited permission credentials for use with specific activities.\n *\n * The permission scope is not controlled. This class should be used with care to create minimal permissions.\n * To that end, broad ALLOW permissions can pruned with narrower optional DENY permissions.\n *\n * `permission` is prefixed with `/developer-policy/` and postfixed with `/` to construct the path. This will\n * be used for discovery and display. It is restricted to the same character set as AWS `path`.\n *\n * `description` is optionally used to construct the AWS Managed Policy description and used for display.\n *\n * ```yaml\n * TestingECAE2E87:\n * Type: AWS::IAM::ManagedPolicy\n * Properties:\n * Description: This is testing stuff\n * Path: /developer-policy/read-from-mybucket-under-mypath/\n * PolicyDocument:\n * Statement:\n * - Action: s3:GetObject\n * Effect: Allow\n * Resource: arn:aws:s3:::mybucket/mypath\n * - Action: s3:GetObject\n * Effect: Deny\n * Resource: arn:aws:s3:::mybucket/mypath/butnotthispath\n * Version: \"2012-10-17\"\n * Metadata:\n * aws:cdk:path: janus-resources-for-testing-managed-policy-tagging/justin-testing/Resource* ```\n * ```\n *\n * @experimental\n */\nexport class GuDeveloperPolicyExperimental extends ManagedPolicy {\n constructor(scope: GuStack, id: string, props: GuWorkloadPolicyProps) {\n super(scope, id, {\n description: `${props.permission} developer policy`,\n ...props,\n path: `/developer-policy/${props.permission}/`,\n });\n\n let valid = true;\n\n const { statements = [] } = props;\n for (const statement of statements) {\n if (statement.effect === Effect.ALLOW) {\n for (const action of statement.actions) {\n if (action === \"*\") {\n const name = statement.actions.join(\",\");\n Annotations.of(this).addError(`Action of '*' found in ${name} ALLOW permission`);\n valid = false;\n }\n }\n for (const resource of statement.resources) {\n if (resource === \"*\") {\n const name = statement.actions.join(\",\");\n Annotations.of(this).addError(`Resource of '*' found in ${name} ALLOW permission`);\n valid = false;\n }\n }\n }\n }\n\n const { allow = [] } = props;\n for (const allowed of allow) {\n // validity checks\n const name = allowed.policyName ?? allowed.actions.join(\",\") + \" on \" + allowed.resources.join(\",\");\n for (const resource of allowed.resources) {\n if (resource === \"*\") {\n Annotations.of(this).addError(`Resource of '*' found in ${name} ALLOW permission`);\n valid = false;\n }\n }\n for (const action of allowed.actions) {\n if (action === \"*\") {\n const name = allowed.policyName ?? allowed.actions.join(\",\");\n Annotations.of(this).addError(`Action of '*' found in ${name} ALLOW permission`);\n valid = false;\n }\n }\n this.addStatements(\n new PolicyStatement({\n effect: Effect.ALLOW,\n resources: allowed.resources,\n actions: allowed.actions,\n }),\n );\n }\n\n if (!valid) {\n throw new Error(\"Overly broad permission present, see annotations for details\");\n }\n\n const { deny = [] } = props;\n for (const denied of deny) {\n this.addStatements(\n new PolicyStatement({\n effect: Effect.DENY,\n resources: denied.resources,\n actions: denied.actions,\n }),\n );\n }\n }\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export * from "./developer-policy";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/experimental/constructs/iam/policies/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./developer-policy"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/experimental/constructs/iam/policies/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC","sourcesContent":["export * from \"./developer-policy\";\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@guardian/cdk",
3
3
  "description": "Generic Guardian flavoured AWS CDK components",
4
- "version": "62.3.5",
4
+ "version": "62.4.0",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
7
7
  "files": [
@@ -46,7 +46,7 @@
46
46
  "eslint": "^9.39.2",
47
47
  "eslint-plugin-custom-rules": "file:tools/eslint",
48
48
  "gh-pages": "^6.3.0",
49
- "jest": "^29.7.0",
49
+ "jest": "30.2.0",
50
50
  "prettier": "^3.8.1",
51
51
  "serve": "^14.2.5",
52
52
  "ts-jest": "^29.4.6",