Skip to content

S3UTILS-222 Tool to update CRR policies#375

Closed
nicolas2bert wants to merge 7 commits intodevelopment/1.17from
improvement/S3UTILS-222/check-replication-permissions
Closed

S3UTILS-222 Tool to update CRR policies#375
nicolas2bert wants to merge 7 commits intodevelopment/1.17from
improvement/S3UTILS-222/check-replication-permissions

Conversation

@nicolas2bert
Copy link
Contributor

No description provided.

@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

Incorrect fix version

The Fix Version/s in issue S3UTILS-222 contains:

  • None

Considering where you are trying to merge, I ignored possible hotfix versions and I expected to find:

  • 1.18.0

Please check the Fix Version/s of S3UTILS-222, or the target
branch of this pull request.

@nicolas2bert nicolas2bert marked this pull request as draft February 27, 2026 11:14
@nicolas2bert nicolas2bert changed the base branch from development/1 to development/1.17 February 27, 2026 11:14
@bert-e
Copy link
Contributor

bert-e commented Feb 27, 2026

Incorrect fix version

The Fix Version/s in issue S3UTILS-222 contains:

  • None

Considering where you are trying to merge, I ignored possible hotfix versions and I expected to find:

  • 1.17.5

  • 1.18.0

Please check the Fix Version/s of S3UTILS-222, or the target
branch of this pull request.

httpAgent: new http.Agent({ keepAlive: true }),
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 1 day ago

In general, the fix is to stop disabling TLS certificate validation and either (a) rely on the default system trust store, or (b) explicitly configure a trusted CA/certificate instead of setting rejectUnauthorized: false. This keeps HTTPS secure while still allowing connections to custom or self‑signed endpoints when configured.

In this file, the single best change is to remove rejectUnauthorized: false from the https.Agent used by NodeHttpHandler inside createIAMClient, and (without altering existing behavior for standard environments) add optional support for a custom CA certificate path passed in through the existing config object. If config.caCertPath is provided, we read that file and pass its contents as the ca option to https.Agent. If it’s not provided, we construct a default agent without rejectUnauthorized: false, so certificate validation uses Node’s default trust store. This keeps existing functionality (HTTPS vs HTTP controlled by config.useHttps, endpoint/port logic unchanged), while making TLS properly validated and still supporting custom CAs when explicitly configured.

Concretely, in replicationAudit/fix-missing-replication-permissions.js:

  • Add a small helper to load an optional CA from a path (using the already‑imported fs) or just inline the fs.readFileSync call when building the agent.
  • Modify the httpsAgent construction in createIAMClient:
    • Remove the rejectUnauthorized: false line.
    • Optionally add ca: fs.readFileSync(config.caCertPath) only if config.caCertPath is set.
      No new imports are needed, since fs, http, and https are already required at the top of the file.
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
@@ -121,18 +121,22 @@
 /** Create an IAM client for a given account */
 function createIAMClient(config, accessKeyId, secretKey) {
     const protocol = config.useHttps ? 'https' : 'http';
+    const httpsAgentOptions = {
+        keepAlive: true,
+    };
+    // If a custom CA certificate path is provided in config, use it to
+    // validate the HTTPS connection instead of disabling verification.
+    if (config.caCertPath) {
+        httpsAgentOptions.ca = fs.readFileSync(config.caCertPath);
+    }
+
     return new IAMClient({
         region: 'us-east-1',
         endpoint: `${protocol}://${config.vaultHost}:${config.iamPort}`,
         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.
-            httpsAgent: new https.Agent({
-                keepAlive: true,
-                rejectUnauthorized: false,
-            }),
+            httpsAgent: new https.Agent(httpsAgentOptions),
         }),
     });
 }
EOF
@@ -121,18 +121,22 @@
/** Create an IAM client for a given account */
function createIAMClient(config, accessKeyId, secretKey) {
const protocol = config.useHttps ? 'https' : 'http';
const httpsAgentOptions = {
keepAlive: true,
};
// If a custom CA certificate path is provided in config, use it to
// validate the HTTPS connection instead of disabling verification.
if (config.caCertPath) {
httpsAgentOptions.ca = fs.readFileSync(config.caCertPath);
}

return new IAMClient({
region: 'us-east-1',
endpoint: `${protocol}://${config.vaultHost}:${config.iamPort}`,
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.
httpsAgent: new https.Agent({
keepAlive: true,
rejectUnauthorized: false,
}),
httpsAgent: new https.Agent(httpsAgentOptions),
}),
});
}
Copilot is powered by AI and may make mistakes. Always verify output.
@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.

return {
inputFile,
vaultHost,
vaultAdminPort: 8600,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vaultAdminPort is hardcoded to 8600, but iamPort is configurable via --iam-port. If someone passes --iam-port 9600, IAM operations go to 9600 while generateAccountAccessKey still targets 8600. Consider reusing iamPort here or adding a --vault-port flag. — Claude Code

@claude
Copy link

claude bot commented Feb 27, 2026

Two issues found:

  1. @aws-sdk/client-iam is in devDependencies but imported by production script fix-missing-replication-permissions.js. Move it to dependencies in package.json.

  2. vaultAdminPort is hardcoded to 8600 while iamPort is configurable via the --iam-port flag. Reuse iamPort for both, or add a separate --vault-port flag.

Review by Claude Code

@nicolas2bert nicolas2bert force-pushed the improvement/S3UTILS-222/check-replication-permissions branch from dd53dc3 to 341df13 Compare February 27, 2026 14:12
@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 (feecad8).

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     #375      +/-   ##
====================================================
- 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.

@nicolas2bert nicolas2bert force-pushed the improvement/S3UTILS-222/check-replication-permissions branch from 341df13 to d329715 Compare February 27, 2026 14:42
…t bodies

The allowed-tools glob pattern Bash(gh pr comment *) fails to match
when the command contains literal newlines from $'...' quoting. Switch
to <br> for line breaks in comment bodies (except inside code blocks
and suggestion blocks) to keep commands on a single line.
@claude
Copy link

claude bot commented Feb 27, 2026

  • Missing process.exit(0) at end of successful main() in fix-missing-replication-permissions.js. The keepAlive HTTP agents will prevent the process from exiting naturally after completion. Add process.exit(0) after the final console.log, or call destroy() on the HTTP agents before returning.

Review by Claude Code

@claude
Copy link

claude bot commented Feb 27, 2026

LGTM

Review by Claude Code

@nicolas2bert
Copy link
Contributor Author

@copilot /review-pr

Copy link

Copilot AI commented Feb 27, 2026

@nicolas2bert I've opened a new pull request, #376, to work on those changes. Once the pull request is ready, I'll request review from you.

@claude
Copy link

claude bot commented Feb 27, 2026

LGTM

Review by Claude Code

Switching from one policy per role (covering multiple buckets) to one
policy per bucket eliminates stale-policy issues on re-runs: since the
policy document is always identical for a given bucket,
EntityAlreadyExists becomes a true no-op with no version management
needed.
@nicolas2bert nicolas2bert force-pushed the improvement/S3UTILS-222/check-replication-permissions branch from c612530 to 4d361a5 Compare February 27, 2026 16:45
@claude
Copy link

claude bot commented Feb 27, 2026

LGTM

Review by Claude Code

- Avoid mutating checkBucketPermissions result object; use spread instead
- Add comment about missing pagination in test cleanup
@claude
Copy link

claude bot commented Feb 27, 2026

LGTM

Well-structured script with proper dry-run support, idempotency handling, and comprehensive functional tests covering multi-bucket, multi-role, and multi-account scenarios. The dependency move of @aws-sdk/client-iam from devDependencies to dependencies is correct since the new production script requires it. Error handling and credential lifecycle management (temp key creation/cleanup with auto-expiry fallback) are solid.

Review by Claude Code


for (let i = 0; i < entries.length; i++) {
const entry = entries[i];
const { accountId, roleName } = parseRoleArn(entry.sourceRole);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parseRoleArn is called outside the try block (which starts at line 250). A malformed sourceRole in any entry will crash the entire script mid-run instead of logging the error and continuing to the next entry. Move it inside the try block so the existing catch handler records the failure in outcome.errors and processes remaining entries.

— Claude Code

@claude
Copy link

claude bot commented Feb 27, 2026

  • parseRoleArn (line 225) is called outside the try block. A malformed sourceRole in any entry crashes the script instead of recording the error and continuing - Move parseRoleArn and the dependent lines inside the existing try block so errors are handled per-entry Review by Claude Code

- Align test input with real check script output: remove
  destinationRole/missingActions, add policies array
- Idempotent test: verify no extra audit-fix policies on the role
- Key cleanup test: snapshot access keys before/after to verify
  temp keys are actually deleted, not just counted
- Clarify TBD comment about idempotency via policy name check
@claude
Copy link

claude bot commented Feb 27, 2026

LGTM

Well-structured addition. The fix script has proper dry-run support, idempotent design (per-bucket policy naming + EntityAlreadyExists handling), credential lifecycle management (temp keys with auto-expiry fallback), and comprehensive functional test coverage across single-bucket, multi-bucket, multi-role, and multi-account scenarios. The check script change to propagate ownerDisplayName is clean, and the S3Setup cleanup improvements (listing all buckets + IAM resources) are necessary for the new test fixtures.

Review by Claude Code

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.

3 participants