@proofgate-cdk/extractor 0.0.0-stage → 1.1.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/LICENSE +201 -0
- package/README.md +8 -2
- package/dist/index.d.ts +6 -0
- package/dist/index.js +277 -0
- package/dist/index.js.map +1 -0
- package/dist/managed-policies.d.ts +6 -0
- package/dist/managed-policies.js +80 -0
- package/dist/managed-policies.js.map +1 -0
- package/dist/resolve.d.ts +14 -0
- package/dist/resolve.js +113 -0
- package/dist/resolve.js.map +1 -0
- package/package.json +48 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 ProofGate contributors
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @proofgate-cdk/extractor
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
合成済みCloudFormationから、ProofGateが対応するIAMロール、Trust Policy、インラインポリシーをFail Closedで抽出します。
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pnpm add @proofgate-cdk/extractor
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
未対応のCondition、NotAction、NotResource、Managed Policy、解決不能な式は安全とみなさず、`UnsupportedFinding`として返します。通常は`@proofgate-cdk/cdk-plugin`から間接的に利用します。
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { parseManagedPolicies } from "./managed-policies.js";
|
|
2
|
+
import { resolveResources, resolveValue } from "./resolve.js";
|
|
3
|
+
/** IAMポリシー変数の構文(`${`から`}`まで)です。 */
|
|
4
|
+
const POLICY_VARIABLE = /\$\{[^}]*\}/;
|
|
5
|
+
// unknownのまま受け取ったJSONを、必要な形へ段階的に絞り込みます。
|
|
6
|
+
const object = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7
|
+
const strings = (value) => typeof value === "string"
|
|
8
|
+
? [value]
|
|
9
|
+
: Array.isArray(value) && value.every((entry) => typeof entry === "string")
|
|
10
|
+
? value
|
|
11
|
+
: undefined;
|
|
12
|
+
/**
|
|
13
|
+
* 通常のIAM Policy Statementを、文字列だけで構成された決定的なモデルへ変換します。
|
|
14
|
+
*/
|
|
15
|
+
function parseStatements(document, path, unsupported, context) {
|
|
16
|
+
if (!object(document) || !Array.isArray(document.Statement)) {
|
|
17
|
+
unsupported.push({ sourcePath: path, reason: "PolicyDocument.Statement must be an array" });
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
return document.Statement.flatMap((raw, index) => {
|
|
21
|
+
const sourcePath = `${path}.Statement[${index}]`;
|
|
22
|
+
if (!object(raw)) {
|
|
23
|
+
unsupported.push({ sourcePath, reason: "Statement must be an object" });
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
// 否定形式やConditionは意味を過小評価する危険があるため、初期版では必ず拒否します。
|
|
27
|
+
for (const key of ["NotAction", "NotResource", "Condition"]) {
|
|
28
|
+
if (key in raw)
|
|
29
|
+
unsupported.push({ sourcePath: `${sourcePath}.${key}`, reason: `${key} is not supported` });
|
|
30
|
+
}
|
|
31
|
+
const actions = strings(raw.Action);
|
|
32
|
+
// Resourceは、リテラルに加えて、Fn::Join・Ref・Fn::GetAtt(R1)も読みます。Actionはリテラルのままです。
|
|
33
|
+
const resources = resolveResources(raw.Resource, context);
|
|
34
|
+
if (!actions || !resources) {
|
|
35
|
+
unsupported.push({
|
|
36
|
+
sourcePath,
|
|
37
|
+
reason: "Action and Resource must be literal strings or arrays of strings",
|
|
38
|
+
});
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
if (raw.Effect !== "Allow" && raw.Effect !== "Deny") {
|
|
42
|
+
unsupported.push({
|
|
43
|
+
sourcePath: `${sourcePath}.Effect`,
|
|
44
|
+
reason: "Effect must be Allow or Deny",
|
|
45
|
+
});
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
48
|
+
// IAMポリシー変数(`${aws:username}`など)は評価せず、未対応として拒否します。
|
|
49
|
+
// 実行時に展開されるため、リテラル文字列として扱うと権限を過小評価する危険があるためです。
|
|
50
|
+
// CloudFormationのintrinsicで既に未対応になったResourceは、上のfindingだけを維持します。
|
|
51
|
+
// 変数の位置は、テンプレートの要素の添字で報告します(解決した候補の添字ではありません。R1でパーティションが複数の候補になるためです)。
|
|
52
|
+
// The position is the index of the template entry, not of the resolved alternatives (R1 expands partitions).
|
|
53
|
+
const entries = Array.isArray(raw.Resource) ? raw.Resource : [raw.Resource];
|
|
54
|
+
const variableFindings = entries.flatMap((entry, index) => (resolveValue(entry, context) ?? []).some((resource) => POLICY_VARIABLE.test(resource))
|
|
55
|
+
? [
|
|
56
|
+
{
|
|
57
|
+
sourcePath: `${sourcePath}.Resource${Array.isArray(raw.Resource) ? `[${index}]` : ""}`,
|
|
58
|
+
reason: "IAM policy variables in Resource are not supported",
|
|
59
|
+
},
|
|
60
|
+
]
|
|
61
|
+
: []);
|
|
62
|
+
if (variableFindings.length > 0) {
|
|
63
|
+
unsupported.push(...variableFindings);
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
return [{ effect: raw.Effect, actions, resources, sourcePath }];
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Trust Policyから、ロールを引き受けられるAWSサービスだけを抽出します。
|
|
71
|
+
*/
|
|
72
|
+
function parseTrustServices(document, path, unsupported) {
|
|
73
|
+
if (!object(document) || !Array.isArray(document.Statement)) {
|
|
74
|
+
unsupported.push({
|
|
75
|
+
sourcePath: path,
|
|
76
|
+
reason: "AssumeRolePolicyDocument.Statement must be an array",
|
|
77
|
+
});
|
|
78
|
+
return [];
|
|
79
|
+
}
|
|
80
|
+
const services = [];
|
|
81
|
+
document.Statement.forEach((raw, index) => {
|
|
82
|
+
const sourcePath = `${path}.Statement[${index}]`;
|
|
83
|
+
if (!object(raw)) {
|
|
84
|
+
unsupported.push({ sourcePath, reason: "Trust statement must be an object" });
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
for (const key of ["NotAction", "NotPrincipal", "Condition"]) {
|
|
88
|
+
// Allowの信頼Statementに付いたオブジェクトのConditionは、無いものとして読みます(R3)。
|
|
89
|
+
// Conditionは引き受けられる主体を狭めるだけなので、無視すると指摘が増える側です。
|
|
90
|
+
// An object Condition on an Allow trust statement is read as absent: it can only narrow who may
|
|
91
|
+
// assume the role, so ignoring it only adds findings. Deny, and a Condition that is not an object, stay unsupported.
|
|
92
|
+
if (key === "Condition" && raw.Effect === "Allow" && object(raw.Condition))
|
|
93
|
+
continue;
|
|
94
|
+
if (key in raw)
|
|
95
|
+
unsupported.push({
|
|
96
|
+
sourcePath: `${sourcePath}.${key}`,
|
|
97
|
+
reason: `${key} is not supported in trust policies`,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
const actions = strings(raw.Action);
|
|
101
|
+
if (!actions) {
|
|
102
|
+
unsupported.push({
|
|
103
|
+
sourcePath: `${sourcePath}.Action`,
|
|
104
|
+
reason: "Trust policy Action must contain literal strings",
|
|
105
|
+
});
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (raw.Effect !== "Allow" && raw.Effect !== "Deny") {
|
|
109
|
+
unsupported.push({
|
|
110
|
+
sourcePath: `${sourcePath}.Effect`,
|
|
111
|
+
reason: "Trust policy Effect must be Allow or Deny",
|
|
112
|
+
});
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
// Allowされたsts:AssumeRoleだけが、サービスによる引き受け経路を作ります。
|
|
116
|
+
if (raw.Effect !== "Allow" ||
|
|
117
|
+
!actions.some((action) => ["*", "sts:*", "sts:assumerole"].includes(action.toLowerCase())))
|
|
118
|
+
return;
|
|
119
|
+
if (raw.Principal === "*") {
|
|
120
|
+
services.push("*");
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (!object(raw.Principal)) {
|
|
124
|
+
unsupported.push({
|
|
125
|
+
sourcePath: `${sourcePath}.Principal`,
|
|
126
|
+
reason: "Trust policy Principal must be a literal object or *",
|
|
127
|
+
});
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
for (const [principalType, values] of Object.entries(raw.Principal)) {
|
|
131
|
+
const parsed = strings(values);
|
|
132
|
+
if (!parsed) {
|
|
133
|
+
unsupported.push({
|
|
134
|
+
sourcePath: `${sourcePath}.Principal.${principalType}`,
|
|
135
|
+
reason: "Trust principals must contain literal strings",
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
else if (principalType === "Service") {
|
|
139
|
+
services.push(...parsed.map((service) => service.toLowerCase()));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
return [...new Set(services)].sort();
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* 1つのCloudFormationテンプレートを正規化します。
|
|
147
|
+
* 未対応構文があれば部分的なモデルを返さず、呼び出し側がFail Closedにできるようにします。
|
|
148
|
+
*/
|
|
149
|
+
export function extractStack(template) {
|
|
150
|
+
const unsupported = [];
|
|
151
|
+
if (!object(template) || !object(template.Resources)) {
|
|
152
|
+
return {
|
|
153
|
+
unsupported: [
|
|
154
|
+
{ sourcePath: "Resources", reason: "CloudFormation Resources object is required" },
|
|
155
|
+
],
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
const context = { resources: template.Resources };
|
|
159
|
+
const roles = new Map();
|
|
160
|
+
// 第1段階: AWS::IAM::Role本体とロール内インラインポリシーを収集します。
|
|
161
|
+
for (const [logicalId, rawResource] of Object.entries(template.Resources)) {
|
|
162
|
+
if (object(rawResource) && rawResource.Type === "AWS::IAM::ManagedPolicy") {
|
|
163
|
+
unsupported.push({
|
|
164
|
+
sourcePath: `Resources.${logicalId}`,
|
|
165
|
+
reason: "AWS::IAM::ManagedPolicy is not supported in the first vertical slice",
|
|
166
|
+
});
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
if (object(rawResource) &&
|
|
170
|
+
typeof rawResource.Type === "string" &&
|
|
171
|
+
rawResource.Type.startsWith("AWS::IAM::") &&
|
|
172
|
+
!["AWS::IAM::Role", "AWS::IAM::Policy"].includes(rawResource.Type)) {
|
|
173
|
+
unsupported.push({
|
|
174
|
+
sourcePath: `Resources.${logicalId}`,
|
|
175
|
+
reason: `${rawResource.Type} is not supported in the first vertical slice`,
|
|
176
|
+
});
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
if (!object(rawResource) ||
|
|
180
|
+
rawResource.Type !== "AWS::IAM::Role" ||
|
|
181
|
+
!object(rawResource.Properties))
|
|
182
|
+
continue;
|
|
183
|
+
const statements = [];
|
|
184
|
+
const trustPath = `Resources.${logicalId}.Properties.AssumeRolePolicyDocument`;
|
|
185
|
+
const trustServices = parseTrustServices(rawResource.Properties.AssumeRolePolicyDocument, trustPath, unsupported);
|
|
186
|
+
const policies = rawResource.Properties.Policies;
|
|
187
|
+
if (policies !== undefined) {
|
|
188
|
+
if (!Array.isArray(policies)) {
|
|
189
|
+
unsupported.push({
|
|
190
|
+
sourcePath: `Resources.${logicalId}.Properties.Policies`,
|
|
191
|
+
reason: "Policies must be an array",
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
policies.forEach((policy, index) => {
|
|
196
|
+
const path = `Resources.${logicalId}.Properties.Policies[${index}].PolicyDocument`;
|
|
197
|
+
if (!object(policy))
|
|
198
|
+
unsupported.push({ sourcePath: path, reason: "Inline policy must be an object" });
|
|
199
|
+
else
|
|
200
|
+
statements.push(...parseStatements(policy.PolicyDocument, path, unsupported, context));
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (rawResource.Properties.ManagedPolicyArns !== undefined) {
|
|
205
|
+
statements.push(...parseManagedPolicies(rawResource.Properties.ManagedPolicyArns, `Resources.${logicalId}.Properties.ManagedPolicyArns`, unsupported));
|
|
206
|
+
}
|
|
207
|
+
if (rawResource.Properties.RoleName !== undefined &&
|
|
208
|
+
typeof rawResource.Properties.RoleName !== "string") {
|
|
209
|
+
unsupported.push({
|
|
210
|
+
sourcePath: `Resources.${logicalId}.Properties.RoleName`,
|
|
211
|
+
reason: "RoleName must be a literal string when present",
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
if (rawResource.Properties.Path !== undefined && rawResource.Properties.Path !== "/") {
|
|
215
|
+
unsupported.push({
|
|
216
|
+
sourcePath: `Resources.${logicalId}.Properties.Path`,
|
|
217
|
+
reason: "Non-default IAM role paths are not supported in the first vertical slice",
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
const roleName = typeof rawResource.Properties.RoleName === "string"
|
|
221
|
+
? rawResource.Properties.RoleName
|
|
222
|
+
: undefined;
|
|
223
|
+
roles.set(logicalId, { logicalId, roleName, trustServices, statements });
|
|
224
|
+
}
|
|
225
|
+
// 第2段階: 独立したAWS::IAM::Policyを、Refで指定されたローカルロールへ結合します。
|
|
226
|
+
for (const [logicalId, rawResource] of Object.entries(template.Resources)) {
|
|
227
|
+
if (!object(rawResource) ||
|
|
228
|
+
rawResource.Type !== "AWS::IAM::Policy" ||
|
|
229
|
+
!object(rawResource.Properties))
|
|
230
|
+
continue;
|
|
231
|
+
const path = `Resources.${logicalId}.Properties.PolicyDocument`;
|
|
232
|
+
const statements = parseStatements(rawResource.Properties.PolicyDocument, path, unsupported, context);
|
|
233
|
+
const roleRefs = rawResource.Properties.Roles;
|
|
234
|
+
if (!Array.isArray(roleRefs)) {
|
|
235
|
+
unsupported.push({
|
|
236
|
+
sourcePath: `Resources.${logicalId}.Properties.Roles`,
|
|
237
|
+
reason: "Policy Roles must be an array",
|
|
238
|
+
});
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
for (const [index, roleRef] of roleRefs.entries()) {
|
|
242
|
+
if (!object(roleRef) || typeof roleRef.Ref !== "string" || !roles.has(roleRef.Ref)) {
|
|
243
|
+
unsupported.push({
|
|
244
|
+
sourcePath: `Resources.${logicalId}.Properties.Roles[${index}]`,
|
|
245
|
+
reason: "Only local role Ref targets are supported",
|
|
246
|
+
});
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
const role = roles.get(roleRef.Ref);
|
|
250
|
+
if (!role)
|
|
251
|
+
continue;
|
|
252
|
+
roles.set(role.logicalId, { ...role, statements: [...role.statements, ...statements] });
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
// 検査対象が空のときに定理が自明に成立する「空虚な証明」を防ぎます。
|
|
256
|
+
if (roles.size === 0)
|
|
257
|
+
unsupported.push({
|
|
258
|
+
sourcePath: "Resources",
|
|
259
|
+
reason: "No IAM roles were found; refusing a vacuous proof",
|
|
260
|
+
});
|
|
261
|
+
if ([...roles.values()].every((role) => role.statements.length === 0)) {
|
|
262
|
+
unsupported.push({
|
|
263
|
+
sourcePath: "Resources",
|
|
264
|
+
reason: "No supported IAM policy statements were found; refusing a vacuous proof",
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
return unsupported.length > 0
|
|
268
|
+
? { unsupported }
|
|
269
|
+
: {
|
|
270
|
+
model: {
|
|
271
|
+
version: "1",
|
|
272
|
+
roles: [...roles.values()].sort((a, b) => a.logicalId.localeCompare(b.logicalId)),
|
|
273
|
+
},
|
|
274
|
+
unsupported,
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAA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AAE;QACjB,CAAC,CAAC;YACE,KAAK,EAAE;gBACL,OAAO,EAAE,GAAG;gBACZ,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;aAClF;YACD,WAAW;SACZ,CAAC;AACR,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { StatementModel, UnsupportedFinding } from "@proofgate-cdk/model";
|
|
2
|
+
/**
|
|
3
|
+
* ロールのManagedPolicyArnsを、Statementへ展開します。
|
|
4
|
+
* 1つでも表にない要素があれば、元の理由でunsupportedとして記録し、空配列を返します(部分的な結果は返しません)。
|
|
5
|
+
*/
|
|
6
|
+
export declare function parseManagedPolicies(value: unknown, path: string, unsupported: UnsupportedFinding[]): StatementModel[];
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AWS管理ポリシーの表です(spec proofgate-cdk-construct-support, R2)。
|
|
3
|
+
* 表に載せるのは、AWSのドキュメントで内容を確認したポリシーだけです。表にないポリシーは未対応(PG-IAM-003)です。
|
|
4
|
+
* Managed policies that were checked against the AWS documentation. Any other managed policy stays unsupported.
|
|
5
|
+
*
|
|
6
|
+
* AWSLambdaBasicExecutionRole: policy version v1, ARN arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole.
|
|
7
|
+
* The only statement is Allow of logs:CreateLogGroup, logs:CreateLogStream, and logs:PutLogEvents on "*".
|
|
8
|
+
* Source: https://docs.aws.amazon.com/aws-managed-policy/latest/reference/AWSLambdaBasicExecutionRole.html
|
|
9
|
+
* Checked on 2026-11-19. AWS can publish a new default version later; this is a trust assumption (docs/ASSUMPTIONS.md).
|
|
10
|
+
*/
|
|
11
|
+
const MANAGED_POLICIES = {
|
|
12
|
+
"service-role/AWSLambdaBasicExecutionRole": {
|
|
13
|
+
actions: ["logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents"],
|
|
14
|
+
resources: ["*"],
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
const UNSUPPORTED_REASON = "Managed policies are not supported in the first vertical slice";
|
|
18
|
+
const ARN_PREFIX = "arn:aws:iam::aws:policy/";
|
|
19
|
+
const PARTITION_WILDCARD_PREFIX = "arn:*:iam::aws:policy/";
|
|
20
|
+
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21
|
+
/**
|
|
22
|
+
* ManagedPolicyArnsの1要素を、ポリシー名(表のキー)にします。読めなければundefinedです。
|
|
23
|
+
* 対応する形は2つだけです。リテラルのARN(パーティションはaws)と、
|
|
24
|
+
* CDKが作る`Fn::Join ["", ["arn:", {Ref: AWS::Partition}, ":iam::aws:policy/<name>"]]`です。
|
|
25
|
+
*/
|
|
26
|
+
function policyNameOf(entry) {
|
|
27
|
+
let text;
|
|
28
|
+
if (typeof entry === "string") {
|
|
29
|
+
text = entry;
|
|
30
|
+
}
|
|
31
|
+
else if (isObject(entry) && Object.keys(entry).length === 1) {
|
|
32
|
+
const join = entry["Fn::Join"];
|
|
33
|
+
if (Array.isArray(join) && join.length === 2 && join[0] === "" && Array.isArray(join[1])) {
|
|
34
|
+
const parts = join[1].map((part) => {
|
|
35
|
+
if (typeof part === "string")
|
|
36
|
+
return part;
|
|
37
|
+
const ref = isObject(part) && Object.keys(part).length === 1 ? part.Ref : undefined;
|
|
38
|
+
// パーティションは1つの実値より大きい`*`として読みます。それ以外のRefは読みません。
|
|
39
|
+
return ref === "AWS::Partition" ? "*" : undefined;
|
|
40
|
+
});
|
|
41
|
+
if (parts.every((part) => part !== undefined))
|
|
42
|
+
text = parts.join("");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (text === undefined)
|
|
46
|
+
return undefined;
|
|
47
|
+
const prefix = [ARN_PREFIX, PARTITION_WILDCARD_PREFIX].find((candidate) => text.startsWith(candidate));
|
|
48
|
+
if (prefix === undefined)
|
|
49
|
+
return undefined;
|
|
50
|
+
// 文字列のARNに*を書いた場合(arn:*:...)は、パーティションの`*`として読まれないよう、Joinの結果だけを許します。
|
|
51
|
+
if (prefix === PARTITION_WILDCARD_PREFIX && typeof entry === "string")
|
|
52
|
+
return undefined;
|
|
53
|
+
const name = text.slice(prefix.length);
|
|
54
|
+
return Object.hasOwn(MANAGED_POLICIES, name) ? name : undefined;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* ロールのManagedPolicyArnsを、Statementへ展開します。
|
|
58
|
+
* 1つでも表にない要素があれば、元の理由でunsupportedとして記録し、空配列を返します(部分的な結果は返しません)。
|
|
59
|
+
*/
|
|
60
|
+
export function parseManagedPolicies(value, path, unsupported) {
|
|
61
|
+
const names = Array.isArray(value) ? value.map(policyNameOf) : undefined;
|
|
62
|
+
if (names === undefined || names.some((name) => name === undefined)) {
|
|
63
|
+
unsupported.push({ sourcePath: path, reason: UNSUPPORTED_REASON });
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
return names.flatMap((name, index) => {
|
|
67
|
+
const policy = MANAGED_POLICIES[name];
|
|
68
|
+
return policy === undefined
|
|
69
|
+
? []
|
|
70
|
+
: [
|
|
71
|
+
{
|
|
72
|
+
effect: "Allow",
|
|
73
|
+
actions: [...policy.actions],
|
|
74
|
+
resources: [...policy.resources],
|
|
75
|
+
sourcePath: `${path}[${index}]`,
|
|
76
|
+
},
|
|
77
|
+
];
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=managed-policies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"managed-policies.js","sourceRoot":"","sources":["../src/managed-policies.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,MAAM,gBAAgB,GAElB;IACF,0CAA0C,EAAE;QAC1C,OAAO,EAAE,CAAC,qBAAqB,EAAE,sBAAsB,EAAE,mBAAm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AAC,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,kBAAkB,EAAE,CAAC,CAAC;QACnE,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QACnC,MAAM,MAAM,GAAG,gBAAgB,CAAC,IAAc,CAAC,CAAC;QAChD,OAAO,MAAM,KAAK,SAAS;YACzB,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC;gBACE;oBACE,MAAM,EAAE,OAAgB;oBACxB,OAAO,EAAE,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC;oBAC5B,SAAS,EAAE,CAAC,GAAG,MAAM,CAAC,SAAS,CAAC;oBAChC,UAAU,EAAE,GAAG,IAAI,IAAI,KAAK,GAAG;iBAChC;aACF,CAAC;IACR,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** リゾルバが参照する、テンプレートの`Resources`です。 */
|
|
2
|
+
export interface ResolveContext {
|
|
3
|
+
readonly resources: Readonly<Record<string, unknown>>;
|
|
4
|
+
}
|
|
5
|
+
/** 値の候補の集合です。実際の値は、このどれか1つです。 */
|
|
6
|
+
type Alternatives = readonly string[];
|
|
7
|
+
/** 値を、候補の文字列の集合にします。読めなければundefinedです。 */
|
|
8
|
+
export declare function resolveValue(value: unknown, context: ResolveContext): Alternatives | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* `Resource`の値(文字列、intrinsic、またはそれらの配列)を、文字列の配列にします。
|
|
11
|
+
* 候補が複数ある要素は、すべての候補を並べます(Allowでは、どれか1つに当たれば当たるため、和集合で正確です)。
|
|
12
|
+
*/
|
|
13
|
+
export declare function resolveResources(value: unknown, context: ResolveContext): string[] | undefined;
|
|
14
|
+
export {};
|
package/dist/resolve.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2
|
+
/** 名前のないバケットとロールの、不透明な名前の接頭辞です。S3のバケット名として不可能な`_`で始めます。 */
|
|
3
|
+
const GENERATED_PREFIX = "_generated_";
|
|
4
|
+
/** ARNのパーティションの候補です(AWS公式ドキュメントのsupported partitions)。 */
|
|
5
|
+
const PARTITIONS = ["aws", "aws-cn", "aws-us-gov"];
|
|
6
|
+
/** 1つの値の候補数の上限です。超えたら未対応にします(組み合わせの爆発を防ぎます)。 */
|
|
7
|
+
const MAX_ALTERNATIVES = 64;
|
|
8
|
+
/** `Ref`が`*`になる疑似パラメータです。実際の値は1つなので、`*`はそれより大きい集合です。 */
|
|
9
|
+
const WILDCARD_PSEUDO_PARAMETERS = new Set(["AWS::Region", "AWS::AccountId", "AWS::URLSuffix"]);
|
|
10
|
+
const resourceOf = (context, id) => {
|
|
11
|
+
const resource = Object.hasOwn(context.resources, id) ? context.resources[id] : undefined;
|
|
12
|
+
return isObject(resource) ? resource : undefined;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* バケットまたはロールの名前です。リテラルの名前はそのまま、名前がなければ不透明な名前、
|
|
16
|
+
* 名前がintrinsicなどで読めなければundefinedです。
|
|
17
|
+
*/
|
|
18
|
+
function physicalName(resource, logicalId, property) {
|
|
19
|
+
const properties = resource.Properties;
|
|
20
|
+
const name = isObject(properties) ? properties[property] : undefined;
|
|
21
|
+
if (name === undefined)
|
|
22
|
+
return `${GENERATED_PREFIX}${logicalId}`;
|
|
23
|
+
return typeof name === "string" && name.length > 0 ? name : undefined;
|
|
24
|
+
}
|
|
25
|
+
const one = (value) => value === undefined ? undefined : [value];
|
|
26
|
+
function resolveRef(target, context) {
|
|
27
|
+
if (typeof target !== "string")
|
|
28
|
+
return undefined;
|
|
29
|
+
if (target === "AWS::Partition")
|
|
30
|
+
return PARTITIONS;
|
|
31
|
+
if (target.startsWith("AWS::"))
|
|
32
|
+
return WILDCARD_PSEUDO_PARAMETERS.has(target) ? ["*"] : undefined;
|
|
33
|
+
const resource = resourceOf(context, target);
|
|
34
|
+
if (resource === undefined)
|
|
35
|
+
return undefined; // パラメータや、テンプレートにない名前
|
|
36
|
+
if (resource.Type === "AWS::S3::Bucket")
|
|
37
|
+
return one(physicalName(resource, target, "BucketName"));
|
|
38
|
+
if (resource.Type === "AWS::IAM::Role")
|
|
39
|
+
return one(physicalName(resource, target, "RoleName"));
|
|
40
|
+
return ["*"]; // ほかのリソースの物理IDは未知ですが、必ず存在します。
|
|
41
|
+
}
|
|
42
|
+
function resolveGetAtt(target, context) {
|
|
43
|
+
if (!Array.isArray(target) || target.length !== 2)
|
|
44
|
+
return undefined;
|
|
45
|
+
const [id, attribute] = target;
|
|
46
|
+
if (typeof id !== "string" || typeof attribute !== "string")
|
|
47
|
+
return undefined;
|
|
48
|
+
const resource = resourceOf(context, id);
|
|
49
|
+
if (resource === undefined)
|
|
50
|
+
return undefined;
|
|
51
|
+
if (resource.Type === "AWS::S3::Bucket") {
|
|
52
|
+
// この型はよく知っているので、知らない属性は推測せず未対応にします。
|
|
53
|
+
const name = attribute === "Arn" ? physicalName(resource, id, "BucketName") : undefined;
|
|
54
|
+
return name === undefined ? undefined : PARTITIONS.map((p) => `arn:${p}:s3:::${name}`);
|
|
55
|
+
}
|
|
56
|
+
if (resource.Type === "AWS::IAM::Role") {
|
|
57
|
+
const name = attribute === "Arn" ? physicalName(resource, id, "RoleName") : undefined;
|
|
58
|
+
return name === undefined ? undefined : PARTITIONS.map((p) => `arn:${p}:iam::*:role/${name}`);
|
|
59
|
+
}
|
|
60
|
+
return ["*"];
|
|
61
|
+
}
|
|
62
|
+
/** 値を、候補の文字列の集合にします。読めなければundefinedです。 */
|
|
63
|
+
export function resolveValue(value, context) {
|
|
64
|
+
if (typeof value === "string")
|
|
65
|
+
return [value];
|
|
66
|
+
if (!isObject(value))
|
|
67
|
+
return undefined;
|
|
68
|
+
const keys = Object.keys(value);
|
|
69
|
+
if (keys.length !== 1)
|
|
70
|
+
return undefined;
|
|
71
|
+
if ("Ref" in value)
|
|
72
|
+
return resolveRef(value.Ref, context);
|
|
73
|
+
if ("Fn::GetAtt" in value)
|
|
74
|
+
return resolveGetAtt(value["Fn::GetAtt"], context);
|
|
75
|
+
if ("Fn::Join" in value) {
|
|
76
|
+
const join = value["Fn::Join"];
|
|
77
|
+
if (!Array.isArray(join) || join.length !== 2)
|
|
78
|
+
return undefined;
|
|
79
|
+
const [separator, parts] = join;
|
|
80
|
+
if (typeof separator !== "string" || !Array.isArray(parts))
|
|
81
|
+
return undefined;
|
|
82
|
+
let combined = [];
|
|
83
|
+
for (const [index, part] of parts.entries()) {
|
|
84
|
+
const resolved = resolveValue(part, context);
|
|
85
|
+
if (resolved === undefined)
|
|
86
|
+
return undefined;
|
|
87
|
+
combined =
|
|
88
|
+
index === 0
|
|
89
|
+
? [...resolved]
|
|
90
|
+
: combined.flatMap((left) => resolved.map((right) => `${left}${separator}${right}`));
|
|
91
|
+
if (combined.length > MAX_ALTERNATIVES)
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
return [...new Set(combined)];
|
|
95
|
+
}
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* `Resource`の値(文字列、intrinsic、またはそれらの配列)を、文字列の配列にします。
|
|
100
|
+
* 候補が複数ある要素は、すべての候補を並べます(Allowでは、どれか1つに当たれば当たるため、和集合で正確です)。
|
|
101
|
+
*/
|
|
102
|
+
export function resolveResources(value, context) {
|
|
103
|
+
const entries = Array.isArray(value) ? value : [value];
|
|
104
|
+
const resolved = [];
|
|
105
|
+
for (const entry of entries) {
|
|
106
|
+
const alternatives = resolveValue(entry, context);
|
|
107
|
+
if (alternatives === undefined)
|
|
108
|
+
return undefined;
|
|
109
|
+
resolved.push(...alternatives);
|
|
110
|
+
}
|
|
111
|
+
return [...new Set(resolved)];
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=resolve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resol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G,SAAS,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC;YACzF,IAAI,QAAQ,CAAC,MAAM,GAAG,gBAAgB;gBAAE,OAAO,SAAS,CAAC;QAC3D,CAAC;QACD,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;IAChC,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAc,EAAE,OAAuB;IACtE,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IACvD,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,MAAM,YAAY,GAAG,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAClD,IAAI,YAAY,KAAK,SAAS;YAAE,OAAO,SAAS,CAAC;QACjD,QAAQ,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,CAAC;IACjC,CAAC;IACD,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;AAChC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proofgate-cdk/extractor",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.1.1",
|
|
4
|
+
"description": "Fail-closed CloudFormation IAM extractor for ProofGate.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=26"
|
|
23
|
+
},
|
|
24
|
+
"license": "Apache-2.0",
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/mashharuki/proofgate.git",
|
|
28
|
+
"directory": "packages/extractor"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://github.com/mashharuki/proofgate#readme",
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/mashharuki/proofgate/issues"
|
|
33
|
+
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"aws",
|
|
36
|
+
"cloudformation",
|
|
37
|
+
"iam",
|
|
38
|
+
"cdk",
|
|
39
|
+
"security"
|
|
40
|
+
],
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@proofgate-cdk/model": "^1.1.1"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsc -p tsconfig.json",
|
|
49
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
50
|
+
}
|
|
6
51
|
}
|