@aws-mdaa/dataops-job-l3-construct 1.4.0 → 1.5.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.
Files changed (24) hide show
  1. package/.jsii +98 -112
  2. package/lib/dataops-job-l3-construct.d.ts +30 -240
  3. package/lib/dataops-job-l3-construct.js +23 -23
  4. package/node_modules/@aws-mdaa/s3-bucketpolicy-helper/.npmignore +34 -0
  5. package/node_modules/@aws-mdaa/s3-bucketpolicy-helper/jest.config.js +5 -0
  6. package/node_modules/@aws-mdaa/s3-bucketpolicy-helper/lib/index.ts +241 -0
  7. package/node_modules/@aws-mdaa/s3-bucketpolicy-helper/package.json +9 -7
  8. package/node_modules/@aws-mdaa/s3-bucketpolicy-helper/test/bucketpolicy-helper.test.d.ts +5 -0
  9. package/node_modules/@aws-mdaa/s3-bucketpolicy-helper/test/bucketpolicy-helper.test.js +200 -0
  10. package/node_modules/@aws-mdaa/s3-bucketpolicy-helper/test/bucketpolicy-helper.test.ts +215 -0
  11. package/node_modules/@aws-mdaa/s3-bucketpolicy-helper/tsconfig.json +40 -0
  12. package/node_modules/@aws-mdaa/s3-bucketpolicy-helper/tsconfig.tsbuildinfo +1 -0
  13. package/node_modules/@aws-mdaa/s3-bucketpolicy-helper/typedoc.json +7 -0
  14. package/node_modules/@aws-mdaa/s3-inventory-helper/.npmignore +34 -0
  15. package/node_modules/@aws-mdaa/s3-inventory-helper/jest.config.js +5 -0
  16. package/node_modules/@aws-mdaa/s3-inventory-helper/lib/index.d.ts +2 -20
  17. package/node_modules/@aws-mdaa/s3-inventory-helper/lib/index.js +2 -11
  18. package/node_modules/@aws-mdaa/s3-inventory-helper/lib/index.ts +241 -0
  19. package/node_modules/@aws-mdaa/s3-inventory-helper/package.json +8 -6
  20. package/node_modules/@aws-mdaa/s3-inventory-helper/test/TODO +0 -0
  21. package/node_modules/@aws-mdaa/s3-inventory-helper/tsconfig.json +40 -0
  22. package/node_modules/@aws-mdaa/s3-inventory-helper/tsconfig.tsbuildinfo +1 -0
  23. package/node_modules/@aws-mdaa/s3-inventory-helper/typedoc.json +7 -0
  24. package/package.json +24 -22
@@ -0,0 +1,215 @@
1
+ /*!
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ import { MdaaTestApp } from '@aws-mdaa/testing';
7
+ import {
8
+ IRestrictBucketToRoles,
9
+ IRestrictObjectPrefixToRoles,
10
+ RestrictBucketToRoles,
11
+ RestrictObjectPrefixToRoles,
12
+ } from '../lib';
13
+ import { Bucket } from 'aws-cdk-lib/aws-s3';
14
+ import { ArnPrincipal } from 'aws-cdk-lib/aws-iam';
15
+
16
+ describe('Test BucketPolicy Helper', () => {
17
+ const testApp = new MdaaTestApp();
18
+ const testBucket = Bucket.fromBucketName(testApp.testStack, 'test-bucket', 'test-bucket');
19
+ describe('RestrictPrefix', () => {
20
+ const baseTestProps: IRestrictObjectPrefixToRoles = {
21
+ s3Bucket: testBucket,
22
+ s3Prefix: 'test-prefix',
23
+ };
24
+ test('Read Role Ids', () => {
25
+ const testProps: IRestrictObjectPrefixToRoles = {
26
+ ...baseTestProps,
27
+ readRoleIds: ['test-role-id-1', 'test-role-id-2'],
28
+ };
29
+ const restriction = new RestrictObjectPrefixToRoles(testProps);
30
+ // console.log( JSON.stringify( restriction.statements()[ 0 ], undefined, 2 ) )
31
+ expect(restriction.statements().length).toBe(1);
32
+ expect(restriction.readStatements().length).toBe(1);
33
+ expect(restriction.readWriteSuperStatements().length).toBe(0);
34
+ expect(restriction.readWriteStatements().length).toBe(0);
35
+ expect(restriction.readStatements()[0].actions).toStrictEqual(['s3:GetObject*']);
36
+ expect(restriction.readStatements()[0].conditions).toStrictEqual({
37
+ StringLike: {
38
+ 'aws:userId': ['test-role-id-1:*', 'test-role-id-2:*'],
39
+ },
40
+ });
41
+ expect(restriction.readStatements()[0].effect).toBe('Allow');
42
+ expect(restriction.readStatements()[0].resources).toStrictEqual([
43
+ 'arn:test-partition:s3:::test-bucket/test-prefix/*',
44
+ ]);
45
+ });
46
+
47
+ test('ReadWrite Role Ids', () => {
48
+ const testProps: IRestrictObjectPrefixToRoles = {
49
+ ...baseTestProps,
50
+ readWriteRoleIds: ['test-role-id-1', 'test-role-id-2'],
51
+ };
52
+ const restriction = new RestrictObjectPrefixToRoles(testProps);
53
+ // console.log( JSON.stringify( restriction.statements()[ 0 ], undefined, 2 ) )
54
+ expect(restriction.statements().length).toBe(1);
55
+ expect(restriction.readWriteStatements().length).toBe(1);
56
+ expect(restriction.readStatements().length).toBe(0);
57
+ expect(restriction.readWriteSuperStatements().length).toBe(0);
58
+ expect(restriction.readWriteStatements()[0].actions).toStrictEqual([
59
+ 's3:GetObject*',
60
+ 's3:PutObject',
61
+ 's3:PutObjectTagging',
62
+ 's3:DeleteObject',
63
+ ]);
64
+ expect(restriction.readWriteStatements()[0].conditions).toStrictEqual({
65
+ StringLike: {
66
+ 'aws:userId': ['test-role-id-1:*', 'test-role-id-2:*'],
67
+ },
68
+ });
69
+ });
70
+
71
+ test('ReadWriteSuper Role Ids', () => {
72
+ const testProps: IRestrictObjectPrefixToRoles = {
73
+ ...baseTestProps,
74
+ readWriteSuperRoleIds: ['test-role-id-1', 'test-role-id-2'],
75
+ };
76
+ const restriction = new RestrictObjectPrefixToRoles(testProps);
77
+ // console.log( JSON.stringify( restriction.statements()[ 0 ], undefined, 2 ) )
78
+ expect(restriction.statements().length).toBe(1);
79
+ expect(restriction.readWriteSuperStatements().length).toBe(1);
80
+ expect(restriction.readStatements().length).toBe(0);
81
+ expect(restriction.readWriteStatements().length).toBe(0);
82
+ expect(restriction.readWriteSuperStatements()[0].actions).toStrictEqual([
83
+ 's3:GetObject*',
84
+ 's3:PutObject',
85
+ 's3:PutObjectTagging',
86
+ 's3:DeleteObject',
87
+ 's3:DeleteObjectVersion',
88
+ ]);
89
+ expect(restriction.readWriteSuperStatements()[0].conditions).toStrictEqual({
90
+ StringLike: {
91
+ 'aws:userId': ['test-role-id-1:*', 'test-role-id-2:*'],
92
+ },
93
+ });
94
+ });
95
+
96
+ test('Read Principals', () => {
97
+ const testProps: IRestrictObjectPrefixToRoles = {
98
+ ...baseTestProps,
99
+ readPrincipals: [new ArnPrincipal('test-role-arn-1')],
100
+ };
101
+ const restriction = new RestrictObjectPrefixToRoles(testProps);
102
+ // console.log( JSON.stringify( restriction.statements()[ 0 ], undefined, 2 ) )
103
+ expect(restriction.statements().length).toBe(1);
104
+ expect(restriction.readStatements().length).toBe(1);
105
+ expect(restriction.readWriteSuperStatements().length).toBe(0);
106
+ expect(restriction.readWriteStatements().length).toBe(0);
107
+ expect(restriction.readStatements()[0].actions).toStrictEqual(['s3:GetObject*']);
108
+ expect(restriction.readStatements()[0].effect).toBe('Allow');
109
+ expect(restriction.readStatements()[0].resources).toStrictEqual([
110
+ 'arn:test-partition:s3:::test-bucket/test-prefix/*',
111
+ ]);
112
+ expect(restriction.readStatements()[0].principals.length).toBe(1);
113
+ expect(JSON.stringify(restriction.readStatements()[0].principals[0])).toStrictEqual(
114
+ JSON.stringify({ AWS: ['test-role-arn-1'] }),
115
+ );
116
+ });
117
+
118
+ test('ReadWrite Principals', () => {
119
+ const testProps: IRestrictObjectPrefixToRoles = {
120
+ ...baseTestProps,
121
+ readWritePrincipals: [new ArnPrincipal('test-role-arn-1')],
122
+ };
123
+ const restriction = new RestrictObjectPrefixToRoles(testProps);
124
+ // console.log( JSON.stringify( restriction.statements()[ 0 ], undefined, 2 ) )
125
+ expect(restriction.statements().length).toBe(1);
126
+ expect(restriction.readWriteStatements().length).toBe(1);
127
+ expect(restriction.readStatements().length).toBe(0);
128
+ expect(restriction.readWriteSuperStatements().length).toBe(0);
129
+ expect(restriction.readWriteStatements()[0].actions).toStrictEqual([
130
+ 's3:GetObject*',
131
+ 's3:PutObject',
132
+ 's3:PutObjectTagging',
133
+ 's3:DeleteObject',
134
+ ]);
135
+ expect(restriction.readWriteStatements()[0].effect).toBe('Allow');
136
+ expect(restriction.readWriteStatements()[0].resources).toStrictEqual([
137
+ 'arn:test-partition:s3:::test-bucket/test-prefix/*',
138
+ ]);
139
+ expect(restriction.readWriteStatements()[0].principals.length).toBe(1);
140
+ expect(JSON.stringify(restriction.readWriteStatements()[0].principals[0])).toStrictEqual(
141
+ JSON.stringify({ AWS: ['test-role-arn-1'] }),
142
+ );
143
+ });
144
+
145
+ test('ReadWriteSuper Principals', () => {
146
+ const testProps: IRestrictObjectPrefixToRoles = {
147
+ ...baseTestProps,
148
+ readWriteSuperPrincipals: [new ArnPrincipal('test-role-arn-1')],
149
+ };
150
+ const restriction = new RestrictObjectPrefixToRoles(testProps);
151
+ // console.log( JSON.stringify( restriction.statements()[ 0 ], undefined, 2 ) )
152
+ expect(restriction.statements().length).toBe(1);
153
+ expect(restriction.readStatements().length).toBe(0);
154
+ expect(restriction.readWriteStatements().length).toBe(0);
155
+ expect(restriction.readWriteSuperStatements().length).toBe(1);
156
+ expect(restriction.readWriteSuperStatements()[0].actions).toStrictEqual([
157
+ 's3:GetObject*',
158
+ 's3:PutObject',
159
+ 's3:PutObjectTagging',
160
+ 's3:DeleteObject',
161
+ 's3:DeleteObjectVersion',
162
+ ]);
163
+ expect(restriction.readWriteSuperStatements()[0].effect).toBe('Allow');
164
+ expect(restriction.readWriteSuperStatements()[0].resources).toStrictEqual([
165
+ 'arn:test-partition:s3:::test-bucket/test-prefix/*',
166
+ ]);
167
+ expect(restriction.readWriteSuperStatements()[0].principals.length).toBe(1);
168
+ expect(JSON.stringify(restriction.readWriteSuperStatements()[0].principals[0])).toStrictEqual(
169
+ JSON.stringify({ AWS: ['test-role-arn-1'] }),
170
+ );
171
+ });
172
+ });
173
+ describe('RestrictBucket', () => {
174
+ const baseTestProps: IRestrictBucketToRoles = {
175
+ s3Bucket: testBucket,
176
+ roleExcludeIds: ['test-role-id-1', 'test-role-id-2'],
177
+ principalExcludes: ['test-arn'],
178
+ prefixExcludes: ['exclude-prefix'],
179
+ prefixIncludes: ['exclude-prefix'],
180
+ };
181
+ test('Base Allow', () => {
182
+ const testProps: IRestrictBucketToRoles = {
183
+ ...baseTestProps,
184
+ };
185
+ const restriction = new RestrictBucketToRoles(testProps);
186
+ console.log(JSON.stringify(restriction.allowStatement, undefined, 2));
187
+ expect(restriction.allowStatement.actions).toStrictEqual(['s3:List*', 's3:GetBucket*']);
188
+ expect(restriction.allowStatement.effect).toBe('Allow');
189
+ expect(restriction.allowStatement.conditions).toStrictEqual({
190
+ StringLike: {
191
+ 'aws:userId': ['test-role-id-1:*', 'test-role-id-2:*'],
192
+ },
193
+ });
194
+ expect(restriction.allowStatement.resources).toStrictEqual([
195
+ 'arn:test-partition:s3:::test-bucket/*',
196
+ 'arn:test-partition:s3:::test-bucket',
197
+ ]);
198
+ });
199
+ test('Base Deny', () => {
200
+ const testProps: IRestrictBucketToRoles = {
201
+ ...baseTestProps,
202
+ };
203
+ const restriction = new RestrictBucketToRoles(testProps);
204
+ console.log(JSON.stringify(restriction.denyStatement, undefined, 2));
205
+ expect(restriction.denyStatement.actions).toStrictEqual(['s3:PutObject*', 's3:GetObject*', 's3:DeleteObject*']);
206
+ expect(restriction.denyStatement.effect).toBe('Deny');
207
+ expect(restriction.denyStatement.conditions).toStrictEqual({
208
+ 'ForAnyValue:StringNotLike': {
209
+ 'aws:userId': ['test-role-id-1:*', 'test-role-id-2:*'],
210
+ 'aws:PrincipalArn': ['test-arn'],
211
+ },
212
+ });
213
+ });
214
+ });
215
+ });
@@ -0,0 +1,40 @@
1
+ {
2
+ "compilerOptions": {
3
+ "declarationMap": false,
4
+ "inlineSourceMap": true,
5
+ "inlineSources": true,
6
+ "alwaysStrict": true,
7
+ "removeComments": false,
8
+ "declaration": true,
9
+ "experimentalDecorators": true,
10
+ "incremental": true,
11
+ "lib": [
12
+ "es2020"
13
+ ],
14
+ "module": "CommonJS",
15
+ "newLine": "lf",
16
+ "noEmitOnError": true,
17
+ "noFallthroughCasesInSwitch": true,
18
+ "noImplicitAny": true,
19
+ "noImplicitReturns": true,
20
+ "noImplicitThis": true,
21
+ "noUnusedLocals": true,
22
+ "noUnusedParameters": true,
23
+ "resolveJsonModule": true,
24
+ "skipLibCheck": true,
25
+ "strict": true,
26
+ "strictNullChecks": true,
27
+ "strictPropertyInitialization": true,
28
+ "stripInternal": false,
29
+ "target": "ES2020",
30
+ "composite": true,
31
+ "tsBuildInfoFile": "tsconfig.tsbuildinfo"
32
+ },
33
+ "include": [
34
+ "**/*.ts"
35
+ ],
36
+ "exclude": [
37
+ "node_modules"
38
+ ],
39
+ "_generated_by_jsii_": "Generated by jsii - safe to delete, and ideally should be in .gitignore"
40
+ }