Add tool to fix missing CRR replication permissions#377
Add tool to fix missing CRR replication permissions#377bert-e merged 7 commits intodevelopment/1.17from
Conversation
Switch from $'...' quoting with \n to <br> for line breaks in comment bodies, except inside fenced code blocks.
…eanup Include ownerDisplayName in check-replication-permissions.js results so the fix script can map accounts without extra API calls. Improve deleteTestAccount to clean up all buckets in the account (not just the initial one) and delete detached policies.
New script reads the output of check-replication-permissions.js and creates per-bucket IAM policies with s3:ReplicateObject, then attaches them to the corresponding roles. Supports --dry-run and is idempotent. Move @aws-sdk/client-iam to production dependencies (required at runtime). Add functional tests covering dry-run, idempotency, multi-bucket, multi-role, multi-account, key cleanup, and input validation.
Hello nicolas2bert,My role is to assist you with the merge of this Available options
Available commands
Status report is not available. |
Request integration branchesWaiting for integration branch creation to be requested by the user. To request integration branches, please comment on this pull request with the following command: Alternatively, the |
|
LGTM |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## development/1.17 #377 +/- ##
====================================================
- Coverage 43.62% 42.67% -0.96%
====================================================
Files 84 85 +1
Lines 5973 6106 +133
Branches 1255 1270 +15
====================================================
Hits 2606 2606
- Misses 3321 3453 +132
- Partials 46 47 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
replicationAudit/README.md
Outdated
| # Step 7 (optional): Fix missing permissions | ||
| # Run from your local machine (requires vaultclient and @aws-sdk/client-iam) | ||
| node replicationAudit/fix-missing-replication-permissions.js \ | ||
| /root/replicationAudit_missing.json <supervisor-ip> admin1.json |
There was a problem hiding this comment.
Move this step before the cleanup step, and run the fix script with ansible:
(previous code was running the nodeJS script from the supervisor, which would fail)
| # Step 7 (optional): Fix missing permissions | |
| # Run from your local machine (requires vaultclient and @aws-sdk/client-iam) | |
| node replicationAudit/fix-missing-replication-permissions.js \ | |
| /root/replicationAudit_missing.json <supervisor-ip> admin1.json | |
| # Step 6 (optional): Fix missing permissions | |
| ansible -i env/$ENV_DIR/inventory runners_s3[0] -m copy \ | |
| -a "src=env/$ENV_DIR/vault/admin-clientprofile/admin1.json dest={{ env_host_logs}}/scality-vault{{ container_name_suffix | default("")}}/logs" | |
| ansible -i env/$ENV_DIR/inventory runners_s3[0] -m shell \ | |
| -a "ctrctl exec scality-vault{{ container_name_suffix | default("")}} \ | |
| node /logs/fix-missing-replication-permissions.js /logs/missing.json 127.0.0.1 /logs/admin1.json" |
replicationAudit/README.md
Outdated
| # Step 6: Clean up remote files | ||
| ansible -i env/$ENV_DIR/inventory runners_s3[0] -m shell \ | ||
| -a 'rm -f {{ env_host_logs}}/scality-vault{{ container_name_suffix | default("")}}/logs/missing.json \ | ||
| {{ env_host_logs}}/scality-vault{{ container_name_suffix | default("")}}/logs/check-replication-permissions.js \ | ||
| {{ env_host_logs}}/scality-vault{{ container_name_suffix | default("")}}/logs/buckets-with-replication.json \ | ||
| /root/list-buckets-with-replication.sh' |
There was a problem hiding this comment.
| # Step 6: Clean up remote files | |
| ansible -i env/$ENV_DIR/inventory runners_s3[0] -m shell \ | |
| -a 'rm -f {{ env_host_logs}}/scality-vault{{ container_name_suffix | default("")}}/logs/missing.json \ | |
| {{ env_host_logs}}/scality-vault{{ container_name_suffix | default("")}}/logs/check-replication-permissions.js \ | |
| {{ env_host_logs}}/scality-vault{{ container_name_suffix | default("")}}/logs/buckets-with-replication.json \ | |
| /root/list-buckets-with-replication.sh' | |
| # Step 7: Clean up remote files | |
| ansible -i env/$ENV_DIR/inventory runners_s3[0] -m shell \ | |
| -a 'rm -f {{ env_host_logs}}/scality-vault{{ container_name_suffix | default("")}}/logs/missing.json \ | |
| {{ env_host_logs}}/scality-vault{{ container_name_suffix | default("")}}/logs/check-replication-permissions.js \ | |
| {{ env_host_logs}}/scality-vault{{ container_name_suffix | default("")}}/logs/buckets-with-replication.json \ | |
| {{ env_host_logs}}/scality-vault{{ container_name_suffix | default("")}}/logs/fix-missing-replication-permissions.js \ | |
| {{ env_host_logs}}/scality-vault{{ container_name_suffix | default("")}}/logs/admin1.json \ | |
| /root/list-buckets-with-replication.sh' |
Switch from @aws-sdk/client-iam v3 to aws-sdk v2 so the fix script can run inside the vault container of older S3C versions (pre-9.5.2) where only v2 is available. Update README workflow to copy and execute the fix script inside the vault container instead of running it externally.
| sslEnabled: config.useHttps, | ||
| httpOptions: { | ||
| agent: config.useHttps | ||
| ? new https.Agent({ keepAlive: true, rejectUnauthorized: false }) |
Check failure
Code scanning / CodeQL
Disabling certificate validation High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 22 days ago
In general, the fix is to stop disabling TLS certificate validation and instead rely on the default behavior (or explicitly set rejectUnauthorized: true). If the environment uses self‑signed or private CA certificates, those should be trusted via the OS/Node trust store or by providing a CA bundle to the HTTPS agent, not by turning validation off.
Concretely for this file, in createIAMClient, we should change the HTTPS agent construction so it no longer sets rejectUnauthorized: false. The safest minimal change that preserves existing behavior (keep‑alive, optional HTTPS) is:
- For HTTPS: use
new https.Agent({ keepAlive: true }), allowing Node’s default certificate validation. - Optionally, if this script must support a custom CA bundle, we could add a
caoption wired from configuration, but the prompt doesn’t show such config, so we’ll keep the change minimal.
Only replicationAudit/fix-missing-replication-permissions.js needs editing. No new imports or helper methods are required; we simply modify the httpOptions.agent initialization lines 130–133.
| @@ -128,7 +128,7 @@ | ||
| sslEnabled: config.useHttps, | ||
| httpOptions: { | ||
| agent: config.useHttps | ||
| ? new https.Agent({ keepAlive: true, rejectUnauthorized: false }) | ||
| ? new https.Agent({ keepAlive: true }) | ||
| : new http.Agent({ keepAlive: true }), | ||
| }, | ||
| }); |
|
LGTM |
replicationAudit/README.md
Outdated
There was a problem hiding this comment.
We need to keep /root/buckets-with-replication.json so that we can re-run checks
| -a "cp /root/buckets-with-replication.json {{ env_host_logs}}/scality-vault{{ container_name_suffix | default("")}}/logs && \ |
replicationAudit/README.md
Outdated
| {{ env_host_logs}}/scality-vault{{ container_name_suffix | default("")}}/logs/buckets-with-replication.json \ | ||
| {{ env_host_logs}}/scality-vault{{ container_name_suffix | default("")}}/logs/replication-fix-results.json \ | ||
| {{ env_host_logs}}/scality-vault{{ container_name_suffix | default("")}}/logs/admin1.json \ | ||
| /root/list-buckets-with-replication.sh' |
There was a problem hiding this comment.
| /root/list-buckets-with-replication.sh' | |
| /root/list-buckets-with-replication.sh /root/buckets-with-replication.json' |
|
LGTM |
…ecks Use cp instead of mv so the bucket list file remains at /root/ on the runner, allowing steps 3-5 to be repeated without re-running the list script.
f7bd3a9 to
1795d54
Compare
|
LGTM |
Add GHSA-j965-2qgj-vjmq to the allow list since aws-sdk v2 is intentionally used as a devDependency for vault container compatibility. Also add /root/buckets-with-replication.json to step 8 cleanup.
|
LGTM |
|
@bert-e approve |
Integration data createdI have created the integration data for the additional destination branches.
The following branches will NOT be impacted:
You can set option The following options are set: approve |
|
LGTM |
Build failedThe build for commit did not succeed in branch improvement/S3UTILS-222/fix-crr-policy The following options are set: approve |
|
I have successfully merged the changeset of this pull request
The following branches have NOT changed:
Please check the status of the associated issue S3UTILS-222. Goodbye nicolas2bert. The following options are set: approve |
Add
fix-missing-replication-permissions.jsthat reads the output ofcheck-replication-permissions.jsand automatically creates per-bucket IAM policies withs3:ReplicateObjectfor roles that are missing it.The script is