Skip to content

Add tool to fix missing CRR replication permissions#377

Open
nicolas2bert wants to merge 3 commits intodevelopment/1.17from
improvement/S3UTILS-222/fix-crr-policy
Open

Add tool to fix missing CRR replication permissions#377
nicolas2bert wants to merge 3 commits intodevelopment/1.17from
improvement/S3UTILS-222/fix-crr-policy

Conversation

@nicolas2bert
Copy link
Contributor

Add fix-missing-replication-permissions.js that reads the output of check-replication-permissions.js and automatically creates per-bucket IAM policies with s3:ReplicateObject for roles that are missing it.

The script is

  • idempotent
  • supports --dry-run,
  • cleans up temporary credentials after use.

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.
@bert-e
Copy link
Contributor

bert-e commented Feb 27, 2026

Hello nicolas2bert,

My role is to assist you with the merge of this
pull request. Please type @bert-e help to get information
on this process, or consult the user documentation.

Available options
name description privileged authored
/after_pull_request Wait for the given pull request id to be merged before continuing with the current one.
/bypass_author_approval Bypass the pull request author's approval
/bypass_build_status Bypass the build and test status
/bypass_commit_size Bypass the check on the size of the changeset TBA
/bypass_incompatible_branch Bypass the check on the source branch prefix
/bypass_jira_check Bypass the Jira issue check
/bypass_peer_approval Bypass the pull request peers' approval
/bypass_leader_approval Bypass the pull request leaders' approval
/approve Instruct Bert-E that the author has approved the pull request. ✍️
/create_pull_requests Allow the creation of integration pull requests.
/create_integration_branches Allow the creation of integration branches.
/no_octopus Prevent Wall-E from doing any octopus merge and use multiple consecutive merge instead
/unanimity Change review acceptance criteria from one reviewer at least to all reviewers
/wait Instruct Bert-E not to run until further notice.
Available commands
name description privileged
/help Print Bert-E's manual in the pull request.
/status Print Bert-E's current status in the pull request TBA
/clear Remove all comments from Bert-E from the history TBA
/retry Re-start a fresh build TBA
/build Re-start a fresh build TBA
/force_reset Delete integration branches & pull requests, and restart merge process from the beginning.
/reset Try to remove integration branches unless there are commits on them which do not appear on the source branch.

Status report is not available.

@bert-e
Copy link
Contributor

bert-e commented Feb 27, 2026

Request integration branches

Waiting for integration branch creation to be requested by the user.

To request integration branches, please comment on this pull request with the following command:

/create_integration_branches

Alternatively, the /approve and /create_pull_requests commands will automatically
create the integration branches.

// Consider accepting a CA cert path via CLI option instead.
httpsAgent: new https.Agent({
keepAlive: true,
rejectUnauthorized: false,

Check failure

Code scanning / CodeQL

Disabling certificate validation High

Disabling certificate validation is strongly discouraged.

Copilot Autofix

AI about 18 hours ago

In general, the fix is to stop disabling TLS certificate validation and instead allow Node’s default behavior (validate certificates against the system trust store), or, if a private CA is used, configure the HTTPS agent to trust that CA rather than disabling validation entirely.

In this specific file, the best minimal fix that preserves existing functionality is:

  • Remove rejectUnauthorized: false from the https.Agent configuration so that certificate validation is not disabled.
  • Optionally allow providing a custom CA certificate file via configuration/CLI so self-signed or private CA certificates can be trusted without disabling validation. However, since we must not modify other unseen code paths, the smallest secure change is to drop the rejectUnauthorized: false flag. The rest of the script already switches between HTTP and HTTPS using config.useHttps, so only the HTTPS agent needs to be made safe.

Concretely:

  • In createIAMClient (around lines 121–137 in replicationAudit/fix-missing-replication-permissions.js), edit the httpsAgent declaration to remove the rejectUnauthorized: false property, leaving keepAlive: true intact.
  • No additional imports or helper methods are needed for this minimal fix.

Suggested changeset 1
replicationAudit/fix-missing-replication-permissions.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/replicationAudit/fix-missing-replication-permissions.js b/replicationAudit/fix-missing-replication-permissions.js
--- a/replicationAudit/fix-missing-replication-permissions.js
+++ b/replicationAudit/fix-missing-replication-permissions.js
@@ -127,11 +127,9 @@
         credentials: { accessKeyId, secretAccessKey: secretKey },
         requestHandler: new NodeHttpHandler({
             httpAgent: new http.Agent({ keepAlive: true }),
-            // TBD: rejectUnauthorized: false disables certificate validation.
-            // Consider accepting a CA cert path via CLI option instead.
+            // HTTPS agent uses default certificate validation.
             httpsAgent: new https.Agent({
                 keepAlive: true,
-                rejectUnauthorized: false,
             }),
         }),
     });
EOF
@@ -127,11 +127,9 @@
credentials: { accessKeyId, secretAccessKey: secretKey },
requestHandler: new NodeHttpHandler({
httpAgent: new http.Agent({ keepAlive: true }),
// TBD: rejectUnauthorized: false disables certificate validation.
// Consider accepting a CA cert path via CLI option instead.
// HTTPS agent uses default certificate validation.
httpsAgent: new https.Agent({
keepAlive: true,
rejectUnauthorized: false,
}),
}),
});
Copilot is powered by AI and may make mistakes. Always verify output.
@claude
Copy link

claude bot commented Feb 27, 2026

LGTM

Review by Claude Code

@codecov
Copy link

codecov bot commented Feb 27, 2026

Codecov Report

❌ Patch coverage is 0% with 136 lines in your changes missing coverage. Please review.
✅ Project coverage is 42.67%. Comparing base (378f68f) to head (bae6257).

Files with missing lines Patch % Lines
...cationAudit/fix-missing-replication-permissions.js 0.00% 132 Missing and 1 partial ⚠️
replicationAudit/check-replication-permissions.js 0.00% 3 Missing ⚠️
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     1269      +14     
====================================================
  Hits                   2606     2606              
- Misses                 3321     3453     +132     
- Partials                 46       47       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants