@constructive-io/static-site-deploy 0.2.0 → 0.3.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/README.md +1 -1
- package/deploy.js +1 -1
- package/esm/deploy.js +1 -1
- package/package.json +1 -1
- package/provision.sh +11 -4
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ pnpm exec static-site-deploy setup --site OWNER/REPO --provision --reviewer LOGI
|
|
|
37
37
|
|
|
38
38
|
Replace the placeholders. `--dry-run` prints a fresh-setup plan and does not change AWS, GitHub, or stored values. Remove it to apply; with inputs supplied through variables, `--provision --yes` also supports unattended provisioning. Use a separate role for each site. Sites in the same AWS account reuse the GitHub OIDC provider, not the role or credentials. Do not share or store AWS access keys in GitHub or in appstash.
|
|
39
39
|
|
|
40
|
-
Provisioning creates or reuses the IAM provider, sets an exact AWS audience and subject for the repository's `production` environment and `refs/heads/main` (or `--branch`), and restricts permissions to the selected S3 bucket and CloudFront distribution. It sets the GitHub repository-wide OIDC template to `["repo","context","ref"]`; check for other OIDC integrations before applying. It sets `production` environment variables for the deployment targets, region, homepage, and role ARN. It never dispatches a deployment.
|
|
40
|
+
Provisioning creates or reuses the IAM provider, sets an exact AWS audience and subject for the repository's `production` environment and `refs/heads/main` (or `--branch`), and restricts permissions to the selected S3 bucket and CloudFront distribution. It sets the GitHub repository-wide OIDC template to `["repo","context","ref"]`; check for other OIDC integrations before applying. Repositories that use immutable OIDC subjects keep them, and the role trusts the subject GitHub reports, such as `repo:OWNER@OWNER-ID/REPO@REPO-ID:environment:production:ref:refs/heads/main`. It sets `production` environment variables for the deployment targets, region, homepage, and role ARN. It never dispatches a deployment.
|
|
41
41
|
|
|
42
42
|
If asked, turn off **Allow administrators to bypass configured protection rules** in the GitHub `production` environment, save, and rerun setup. GitHub's public REST API cannot write this toggle. The environment requires the configured reviewer and permits only the configured branch. If the environment is deleted, revoke AWS role trust until the environment and its protections are restored.
|
|
43
43
|
|
package/deploy.js
CHANGED
|
@@ -90,7 +90,7 @@ function deploy(config, { directory, preserve = markdown, dryRun, trailingSlashA
|
|
|
90
90
|
aws('s3', 'cp', source, s3, '--recursive', '--exclude', '*', ...markdown.flatMap(pattern => ['--include', pattern]), '--content-type', 'text/plain; charset=utf-8');
|
|
91
91
|
for (const [alias, key] of aliases) {
|
|
92
92
|
if (alias.endsWith('/')) {
|
|
93
|
-
aws('s3api', 'copy-object', '--bucket', bucket,
|
|
93
|
+
aws('s3api', 'copy-object', '--bucket', bucket, `--copy-source=${bucket}/${key}`, `--key=${alias}`);
|
|
94
94
|
}
|
|
95
95
|
else {
|
|
96
96
|
aws('s3', 'cp', `${s3}/${key}`, `${s3}/${alias}`);
|
package/esm/deploy.js
CHANGED
|
@@ -87,7 +87,7 @@ export function deploy(config, { directory, preserve = markdown, dryRun, trailin
|
|
|
87
87
|
aws('s3', 'cp', source, s3, '--recursive', '--exclude', '*', ...markdown.flatMap(pattern => ['--include', pattern]), '--content-type', 'text/plain; charset=utf-8');
|
|
88
88
|
for (const [alias, key] of aliases) {
|
|
89
89
|
if (alias.endsWith('/')) {
|
|
90
|
-
aws('s3api', 'copy-object', '--bucket', bucket,
|
|
90
|
+
aws('s3api', 'copy-object', '--bucket', bucket, `--copy-source=${bucket}/${key}`, `--key=${alias}`);
|
|
91
91
|
}
|
|
92
92
|
else {
|
|
93
93
|
aws('s3', 'cp', `${s3}/${key}`, `${s3}/${alias}`);
|
package/package.json
CHANGED
package/provision.sh
CHANGED
|
@@ -92,8 +92,15 @@ subject_template=repos/$repo/actions/oidc/customization/sub
|
|
|
92
92
|
identity=$(read_state "arn:aws:iam::$AWS_ACCOUNT_ID:root" aws sts get-caller-identity --query Arn --output text)
|
|
93
93
|
[[ $identity == arn:aws:*:"$AWS_ACCOUNT_ID":* ]] || fail "AWS credentials do not belong to account $AWS_ACCOUNT_ID in the standard AWS partition."
|
|
94
94
|
template=$(read_state '{"use_immutable_subject":false}' gh api "$subject_template")
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
subject_settings='{"use_default":false,"include_claim_keys":["repo","context","ref"]}'
|
|
96
|
+
subject_repo="repo:$repo"
|
|
97
|
+
if jq -e '.use_immutable_subject == true' <<< "$template" >/dev/null; then
|
|
98
|
+
subject_repo=$(jq -er --arg repo "repo:$repo" '.sub_claim_prefix | select(type == "string"
|
|
99
|
+
and test("^repo:[A-Za-z0-9-]+@[1-9][0-9]*/[A-Za-z0-9_.-]+@[1-9][0-9]*$")
|
|
100
|
+
and (sub("@[0-9]+"; ""; "g") | ascii_downcase) == ($repo | ascii_downcase))' <<< "$template") ||
|
|
101
|
+
fail "GitHub did not return an immutable OIDC subject prefix for $repo."
|
|
102
|
+
subject_settings='{"use_default":false,"include_claim_keys":["repo","context","ref"],"use_immutable_subject":true}'
|
|
103
|
+
fi
|
|
97
104
|
|
|
98
105
|
reviewer=$(read_state 1 gh api "users/$SITE_REVIEWER" --jq .id)
|
|
99
106
|
[[ $reviewer =~ ^[1-9][0-9]*$ ]] || fail "Could not resolve the GitHub reviewer $SITE_REVIEWER."
|
|
@@ -133,7 +140,7 @@ elif ! jq -e --arg aud "$audience" '.ClientIDList | index($aud) != null' <<< "$p
|
|
|
133
140
|
run aws iam add-client-id-to-open-id-connect-provider --open-id-connect-provider-arn "$provider" --client-id "$audience"
|
|
134
141
|
fi
|
|
135
142
|
|
|
136
|
-
trust=$(jq -cn --arg provider "$provider" --arg aud "$audience" --arg sub "
|
|
143
|
+
trust=$(jq -cn --arg provider "$provider" --arg aud "$audience" --arg sub "$subject_repo:environment:production:ref:refs/heads/$SITE_BRANCH" '{
|
|
137
144
|
Version: "2012-10-17", Statement: [{
|
|
138
145
|
Effect: "Allow", Principal: {Federated: $provider}, Action: "sts:AssumeRoleWithWebIdentity",
|
|
139
146
|
Condition: {StringEquals: {"token.actions.githubusercontent.com:aud": $aud, "token.actions.githubusercontent.com:sub": $sub}}
|
|
@@ -162,7 +169,7 @@ else
|
|
|
162
169
|
run aws iam update-assume-role-policy --role-name "$AWS_DEPLOY_ROLE_NAME" --policy-document "$trust"
|
|
163
170
|
fi
|
|
164
171
|
run aws iam put-role-policy --role-name "$AWS_DEPLOY_ROLE_NAME" --policy-name "$policy_name" --policy-document "$permissions"
|
|
165
|
-
write_github PUT "$subject_template"
|
|
172
|
+
write_github PUT "$subject_template" "$subject_settings"
|
|
166
173
|
|
|
167
174
|
for name in AWS_S3_BUCKET AWS_CLOUDFRONT_DISTRIBUTION_ID SITE_URL AWS_REGION; do
|
|
168
175
|
run gh variable set "$name" --repo "$repo" --env production --body "${!name}"
|