Repository navigation
fix(dashboard): role script deletes legacy policy versions and the hand-added inline policies (#1376) - #1379
Merged
Conversation
…and the hand-added inline policies (#1376)
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.
Fixes #1376
What changed
lambda/dashboard-api/scripts/setup-dashboard-lambda-role.sh:SpawnDashboardLambdaPolicy(managed) hasAttachmentCount0, the script deletes every non-default version (list-policy-versions --query 'Versions[?!IsDefaultVersion].VersionId'+delete-policy-version) and then runsdelete-policy. A failure now stops the script; it used to fall back to "delete it by hand". If the policy is still attached elsewhere, nothing is deleted and the script warns. If the policy is already gone, the script does nothing. Re-running it is safe.DynamoDBStreamsAccess,SlackSecretsAccessandSporeSlackWorkspaceAccessare removed by exact name. Each is removed only if it passes every check below:list-role-policies;DescribeStream,GetRecords,GetShardIterator,ListStreams(statementsProcessorStreamsandProcessorListStreams);GetSecretValue, and only when the script wroteSpawnDashboardLambdaPolicySlackthis run;GetItem,PutItem,Scan,UpdateItem(statementSlackWorkspaces).The document is printed before it is deleted, so it can be restored. If a policy fails a check (for example
kms:Decrypt,dynamodb:*, or any other action), it is kept with a warning. Other inline policies are never touched.Coverage evidence (main as of 5549f3f, independent of #1320)
internal/iamcoverageTestEveryPrincipalCallIsGrantedpasses for dashboard-api, dashboard-websocket, dashboard-websocket-processor and cost-history-collector against this script's heredocs alone, with no hand-added policy involved.spore-bot-workspacescalls inslack_oauth.goandslack_token.goareGetItem,PutItem,ScanandUpdateItem(no index and no Query), andSlackWorkspacesgrants exactly those on the table.setup-event-source-mappings.shmaps exactlyspawn-sweep-orchestrationandspawn-autoscale-groups-production, andProcessorStreamscovers both tables'/stream/*.slack_secrets.gocallsGetSecretValueonly whenSLACK_SECRETS_ARNis set. The script reads that same ARN and grants it.kms:Decryptis needed), and whether the live documents scope to other resources. The action check catches the first case:SlackSecretsAccesswould be kept. Resource scope is not compared, so review the printed documents in the dry run.Gates (
lambda/dashboard-api/setup_role_script_test.go)These tests run the whole script under a fake
awson PATH. The fake records every call. Itsdelete-policyfails with DeleteConflict while any non-default version remains, as in production.TestRoleScriptDeletesEveryNonDefaultVersionBeforeThePolicy: v5–v8 are each deleted beforedelete-policy, and the default (v9) is never deleted.TestRoleScriptDeletesNoLegacyPolicyStillAttachedElsewhere: with AttachmentCount 1, 3 or absent, there is no delete-policy-version, delete-policy or detach call.TestRoleScriptRemovesOnlyTheThreeHandAddedInlinePolicies: the role has the script's own policies, the three hand-added ones,SomeoneElsesPolicyand the near-missDynamoDBStreamsAccessV2. Exactly the three are deleted, each with its document printed. An uncoveredkms:DecryptkeepsSlackSecretsAccess, and so does a run with no Slack grant.Each gate was watched failing against a revert of the script, and the tests compiled throughout:
delete-policy: "ran after delete-policy";!= absentguard: deletions with AttachmentCount 1 and 3;Removing only the name filter does NOT fail the gate. The name-keyed action check also refuses unknown names, so either one alone keeps the outcome.
make checkandmake lint(0 issues, 10 modules) pass,semgrep scan --config=auto --error .finds 0, and shellcheck on the script is clean.Live step needed (not done here)
Re-run
lambda/dashboard-api/scripts/setup-dashboard-lambda-role.sh spore-host-infrain the infra account (966362334030), with a dry run first using the recording shim. The legacy managed policy is already gone (deleted by hand), so the live effect is only the inline-policy removal. Before the real run, check the shim'sget-role-policyoutput for the three documents: look for actions or resources the new policies don't cover, and confirmSLACK_SECRETS_ARNresolves, otherwiseSlackSecretsAccessis kept.