Skip to content

fix(dashboard): role script deletes legacy policy versions and the hand-added inline policies (#1376) - #1379

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/1376-dashboard-role-script-cleanup
Oct 28, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/1376-dashboard-role-script-cleanup

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #1376

What changed

lambda/dashboard-api/scripts/setup-dashboard-lambda-role.sh:

  1. Legacy managed policy. When SpawnDashboardLambdaPolicy (managed) has AttachmentCount 0, the script deletes every non-default version (list-policy-versions --query 'Versions[?!IsDefaultVersion].VersionId' + delete-policy-version) and then runs delete-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.
  2. Hand-added inline policies. DynamoDBStreamsAccess, SlackSecretsAccess and SporeSlackWorkspaceAccess are removed by exact name. Each is removed only if it passes every check below:
    • it is in list-role-policies;
    • every statement is a plain Allow (no Deny, NotAction or NotResource);
    • every action is one that the script's own policies grant for the same purpose:
      • streams: DescribeStream, GetRecords, GetShardIterator, ListStreams (statements ProcessorStreams and ProcessorListStreams);
      • Slack secret: GetSecretValue, and only when the script wrote SpawnDashboardLambdaPolicySlack this run;
      • workspaces: GetItem, PutItem, Scan, UpdateItem (statement SlackWorkspaces).
        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/iamcoverage TestEveryPrincipalCallIsGranted passes for dashboard-api, dashboard-websocket, dashboard-websocket-processor and cost-history-collector against this script's heredocs alone, with no hand-added policy involved.
  • The spore-bot-workspaces calls in slack_oauth.go and slack_token.go are GetItem, PutItem, Scan and UpdateItem (no index and no Query), and SlackWorkspaces grants exactly those on the table.
  • Stream reads are made by the event source mapping, so iamcoverage does not see them. setup-event-source-mappings.sh maps exactly spawn-sweep-orchestration and spawn-autoscale-groups-production, and ProcessorStreams covers both tables' /stream/*.
  • slack_secrets.go calls GetSecretValue only when SLACK_SECRETS_ARN is set. The script reads that same ARN and grants it.
  • Not verifiable offline: whether the live secret uses a customer-managed KMS key (then kms:Decrypt is needed), and whether the live documents scope to other resources. The action check catches the first case: SlackSecretsAccess would 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 aws on PATH. The fake records every call. Its delete-policy fails with DeleteConflict while any non-default version remains, as in production.

  • TestRoleScriptDeletesEveryNonDefaultVersionBeforeThePolicy: v5–v8 are each deleted before delete-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, SomeoneElsesPolicy and the near-miss DynamoDBStreamsAccessV2. Exactly the three are deleted, each with its document printed. An uncovered kms:Decrypt keeps SlackSecretsAccess, 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:

  • no version deletes: the script exits 254 (DeleteConflict);
  • versions deleted after delete-policy: "ran after delete-policy";
  • != absent guard: deletions with AttachmentCount 1 and 3;
  • no action check: kms and no-Slack subtests fail;
  • Slack covered unconditionally: no-Slack subtest fails;
  • delete-role-policy dropped: all-covered subtest fails;
  • name filter replaced by "all inline names" together with the action check removed: all 8 policies deleted, so the test fails.

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 check and make 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-infra in 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's get-role-policy output for the three documents: look for actions or resources the new policies don't cover, and confirm SLACK_SECRETS_ARN resolves, otherwise SlackSecretsAccess is kept.

@scttfrdmn
scttfrdmn merged commit 17f5463 into main Oct 28, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1376-dashboard-role-script-cleanup branch October 28, 2026 17:54
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.

setup-dashboard-lambda-role.sh can't delete the legacy managed policy (multiple versions); the role keeps three now-redundant hand-added inline policies

1 participant