cloudmason2 1.6.0 → 1.7.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.
- package/commands/new_app.js +25 -11
- package/package.json +1 -1
package/commands/new_app.js
CHANGED
|
@@ -134,21 +134,27 @@ async function ensureGithubRole(repo, bucket, appPrefix, appName, productId){
|
|
|
134
134
|
|
|
135
135
|
const oidcArn = await ensureOidcProvider(iam, accountId);
|
|
136
136
|
|
|
137
|
+
// Reuse the role if it already exists - the permissions policy below is
|
|
138
|
+
// still re-applied, so re-running new-app refreshes an existing role
|
|
139
|
+
let roleArn = null;
|
|
137
140
|
try {
|
|
138
141
|
const existing = await iam.send(new GetRoleCommand({ RoleName: roleName }));
|
|
139
142
|
console.log(`Role ${roleName} already exists (${existing.Role.Arn})`);
|
|
140
|
-
|
|
143
|
+
roleArn = existing.Role.Arn;
|
|
141
144
|
} catch (e){
|
|
142
145
|
if (!/NoSuchEntity/.test(e)){ throw e }
|
|
143
146
|
}
|
|
144
147
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
148
|
+
if (!roleArn){
|
|
149
|
+
// Trust: only GitHub Actions workflows from this repo
|
|
150
|
+
const trustPolicy = exports.githubTrustPolicy(oidcArn, repo);
|
|
151
|
+
const created = await iam.send(new CreateRoleCommand({
|
|
152
|
+
RoleName: roleName,
|
|
153
|
+
AssumeRolePolicyDocument: JSON.stringify(trustPolicy),
|
|
154
|
+
Description: `Mason CI role for ${appName} (github.com/${repo})`
|
|
155
|
+
}));
|
|
156
|
+
roleArn = created.Role.Arn;
|
|
157
|
+
}
|
|
152
158
|
|
|
153
159
|
// Scoped to the app prefix, product id, and app stack names where the
|
|
154
160
|
// services support it. EC2 build permissions cannot be scoped
|
|
@@ -187,6 +193,14 @@ async function ensureGithubRole(repo, bucket, appPrefix, appName, productId){
|
|
|
187
193
|
Action: ["cloudformation:CreateStack", "cloudformation:UpdateStack", "cloudformation:DescribeStacks"],
|
|
188
194
|
Resource: `arn:aws:cloudformation:*:${accountId}:stack/${appName}-*/*`
|
|
189
195
|
},
|
|
196
|
+
{
|
|
197
|
+
Sid: "ReadTemplateSummary",
|
|
198
|
+
Effect: "Allow",
|
|
199
|
+
// launch calls GetTemplateSummary with a TemplateURL, which IAM
|
|
200
|
+
// evaluates against * rather than a stack ARN
|
|
201
|
+
Action: "cloudformation:GetTemplateSummary",
|
|
202
|
+
Resource: "*"
|
|
203
|
+
},
|
|
190
204
|
{
|
|
191
205
|
Sid: "ReadRoleParam",
|
|
192
206
|
Effect: "Allow",
|
|
@@ -207,9 +221,9 @@ async function ensureGithubRole(repo, bucket, appPrefix, appName, productId){
|
|
|
207
221
|
PolicyDocument: JSON.stringify(policy)
|
|
208
222
|
}));
|
|
209
223
|
|
|
210
|
-
console.log(`
|
|
211
|
-
console.log(`Use in GitHub Actions with: role-to-assume: ${
|
|
212
|
-
return
|
|
224
|
+
console.log(`Configured role ${roleName} (${roleArn})`);
|
|
225
|
+
console.log(`Use in GitHub Actions with: role-to-assume: ${roleArn}`);
|
|
226
|
+
return roleArn;
|
|
213
227
|
}
|
|
214
228
|
|
|
215
229
|
async function ensureOidcProvider(iam, accountId){
|