fix(cloud-security): use credential report for iam-root-access-keys check#2846
Open
github-actions[bot] wants to merge 1 commit into
Open
fix(cloud-security): use credential report for iam-root-access-keys check#2846github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
…heck The check previously called GetAccountSummary and read AccountAccessKeysPresent, which returns 1 when the root account has *any* access keys — active or inactive. That produced a critical false positive for accounts that only had a disabled root key sitting on them: AWS Console correctly said "Root user has no active access keys" while our scan reported "Root account has active access keys" at critical severity. Switch to GenerateCredentialReport + GetCredentialReport (same source AWS Console's IAM Dashboard recommendation panel uses). Parse the <root_account> row's access_key_1_active / access_key_2_active columns directly so we report exactly what AWS Console reports. - Extract the check into apps/api/src/cloud-security/providers/aws/iam-root-access-keys.ts so it can be unit-tested in isolation. - Drop the old in-adapter implementation and the now-unused GetAccountSummary import. iam.adapter.ts shrinks from 308 → 266 lines. - Add 16 unit tests covering: customer's exact scenario (inactive-only key passes), each active-key column, both active, no root row (safe skip), permission errors (safe skip), and the polling/retry path on CredentialReportNotReadyException. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
iam-root-access-keysCloud Tests check was producing critical false positives. Customer-reported case: AWS account615477685532(Marsello-Prod-01). IAM Dashboard's Security Recommendations panel shows "Root user has no active access keys" ✓ — our scan reports "Root account has active access keys" at critical severity ✗.iam.adapter.ts:checkRootAccessKeyscalledGetAccountSummaryand readAccountAccessKeysPresent. Per the AWS Security blog, that field returns1when root has access keys "even when that access key is not active" — so any leftover disabled root key triggers our critical finding even though AWS Console correctly ignores it.GenerateCredentialReport+GetCredentialReport(same source AWS Console's recommendation panel uses). Parse the<root_account>row'saccess_key_1_active/access_key_2_activecolumns directly. Our finding now matches AWS Console exactly.iam-root-access-keys.ts) so it's unit-testable. Added 16 unit tests covering all branches — there were zero tests for the IAM adapter before.What changed
apps/api/src/cloud-security/providers/aws/iam-root-access-keys.ts—checkRootAccessKeys, plus exported helpersgetCredentialReport(handlesGenerateCredentialReport+ polling with retry onCredentialReportNotReadyException/CredentialReportNotPresentException) andfindRootAccountRow(CSV parser).apps/api/src/cloud-security/providers/aws/iam-root-access-keys.spec.ts— 16 tests.apps/api/src/cloud-security/providers/aws/iam.adapter.ts— drops the broken in-adaptercheckRootAccessKeys(and the now-unusedGetAccountSummaryCommandimport), imports the new helper. File shrinks from 308 → 266 lines (back under the 300-line limit).Why the new approach is correct
The credential report has explicit
access_key_*_activecolumns:true= active key,false= inactive (or no key at that slot). This is exactly what AWS Console'sIAM Dashboard → Security recommendations → Root user has no active access keyschecks. The IAM managed policySecurityAudit(which our auditor role already has) grantsiam:GenerateCredentialReportandiam:GetCredentialReport, so customers don't need to update their IAM role.Failure modes — handled
GenerateCredentialReportis called first; subsequentGetCredentialReportcalls poll for up to ~10 seconds onCredentialReportNotReadyException.[](skip) rather than failing the entire scan.[](skip).Test plan
npx jest src/cloud-security/providers/aws— 22/22 pass (16 new + 6 existing ec2-vpc)tsc --noEmiton the changed files — zero errors. The package-level typecheck shows only pre-existing errors unrelated to this PR (people-invite.service.ts,variables.controller.spec.ts,training-certificate-pdf.service.spec.ts, etc.) plus a worktree-vs-mainbetter-authtype duplication that resolves once merged.iam-root-access-keysflips from failed → passed without IAM changes on the customer's side.Tests added (covering all the relevant branches)
passed=true, info severityaccess_key_1_active=truepassed=false, criticalaccess_key_2_active=truepassed=false, criticalpassed=false, critical<root_account>row in CSV[](skip)AccessDeniedon GetCredentialReport[](skip)nullGenerateCredentialReportfailsWhat did NOT change
SecurityAuditalready grants both credential-report APIs.iam-root-access-keys), severity (criticalwhen failed,infowhen passed), or remediation message.iam.adapter.ts(password policy, MFA, stale keys) — untouched.🤖 Generated with Claude Code
Summary by cubic
Replaced the IAM root access keys check to use the IAM Credential Report so we only flag active root keys and match what the AWS Console shows. This fixes false positives when a root key exists but is disabled.
Bug Fixes
GenerateCredentialReportandGetCredentialReportfrom@aws-sdk/client-iaminstead ofGetAccountSummary.AccountAccessKeysPresent.<root_account>row and evaluateaccess_key_1_active/access_key_2_active.CredentialReportNotReadyException(1s delay, up to 10 tries); safe-skip on permission errors or missing root row.Refactors
apps/api/src/cloud-security/providers/aws/iam-root-access-keys.tswith focused unit tests iniam-root-access-keys.spec.ts.IamAdapterto callcheckRootAccessKeysand removed theGetAccountSummaryusage/import.Written for commit 0c9069e. Summary will update on new commits.