Skip to content

Bot secrets: fail closed on a missing credentials key; app secrets out of Lambda env (#1594, #1591) - #1627

Merged
scttfrdmn merged 1 commit into
mainfrom
hardening/1594-1591-bot-secrets
Nov 14, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
hardening/1594-1591-bot-secrets

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #1594
Fixes #1591

What changes

#1594: workspace-credential sealing fails closed. botsecret.Field.Seal used to store the plaintext, logging once per process, whenever KMS returned NotFound for the default alias alias/spore-bot-secrets. Removing that alias (a tofu seal_workspace_credentials=false flip, an accidental delete, or a self-hosted stack without the key) therefore wrote new bot tokens, refresh tokens and webhook URLs to spore-bot-workspaces in the clear. The case is now an error that names the key, SPORE_BOT_SECRETS_KMS_KEY and the opt-in. Plaintext is stored only when the process sets SPORE_BOT_ALLOW_UNSEALED_CREDENTIALS=1 (exactly 1). Every write that opt-in lets through is logged with the stable marker SPORE_BOT_CREDENTIAL_STORED_UNSEALED, ready for a metric-filter alarm. An explicitly named key that is missing, and every other KMS failure, still refuse regardless of the opt-in. The change is contained in pkg/botsecret. Its writers are spawn notify workspace add and the dashboard's Slack OAuth install and refresh, all behind SPAWN_EXPERIMENTAL_CHAT. Reads of legacy plaintext are unchanged.

#1591: app-level secrets leave the Lambda environment in the self-hosting template deployment/cloudformation/spore-bot.yaml. The template still takes the five NoEcho parameters, but now writes them into one AWS::SecretsManager::Secret, BotAppSecrets. It is a JSON object keyed by the env var names the bot reads: SLACK_SIGNING_SECRET, BOT_OAUTH_SECRET, SPORE_SLACK_CLIENT_SECRET, TEAMS_APP_SECRET, TWILIO_AUTH_TOKEN. The function gets BOT_APP_SECRETS_ARN and secretsmanager:GetSecretValue on that secret only. The bot code lives in spore-host, so the read side is spore-host/spore-host#740 (filed with this PR). The template header says to deploy that bot build first or in the same update. The hosted bot is Tofu-managed and being decommissioned, so #740 also covers its Tofu.

Tests

  • pkg/botsecret: a missing default key fails every field and logs nothing. Only =1 opts in, so true, yes and 1 do not. With the opt-in, every write is stored and logged with the marker, not once. With the opt-in, the other failures still refuse.
  • bot_app_secrets_test.go: the template's function environment holds none of the five names. The one secret's JSON keys are exactly those names, each from a parameter. BOT_APP_SECRETS_ARN is !Ref that secret, and the only secretsmanager: grant is GetSecretValue on it. The test fails against main.
  • cfn-lint is clean. make check is clean apart from the known space-in-path failures. Semgrep is clean on the changed paths.

Deploy steps

Live checks for the owner

  1. aws kms describe-key --key-id alias/spore-bot-secrets --region us-east-1 in 966362334030: the alias exists and the key is Enabled. If it does not exist, any hosted writer now fails, which is intended.
  2. Check that no hosted function's environment sets SPORE_BOT_ALLOW_UNSEALED_CREDENTIALS. List key names only (spawn-dashboard-api, spore-bot).
  3. Optional, for a self-hosted stack: aws cloudformation validate-template on the new template, then deploy into a scratch account with a waitForSSHReady cannot report failure: it returns nothing, so a 120s timeout renders as "✅ Waiting for SSH" and the launch proceeds to SSH-dependent steps #740 bot build. Confirm get-function-configuration lists none of the five names and that a Slack-signed request verifies.

@codecov

codecov Bot commented Nov 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn force-pushed the hardening/1594-1591-bot-secrets branch from c16c99f to 552005f Compare November 14, 2026 20:17
…app secrets out of Lambda env (#1594, #1591)

botsecret.Field.Seal stored the plaintext, logging once per process,
whenever alias/spore-bot-secrets did not exist, so deleting the alias put
every new install's tokens in the table in the clear. That case is now an
error unless SPORE_BOT_ALLOW_UNSEALED_CREDENTIALS=1, and every write the
opt-in lets through is logged with SPORE_BOT_CREDENTIAL_STORED_UNSEALED.

The self-hosting spore-bot template moves the five app-level secrets from
the function environment into one Secrets Manager secret
(BOT_APP_SECRETS_ARN, GetSecretValue on it alone). The bot-side read is
spore-host/spore-host#740.
@scttfrdmn
scttfrdmn force-pushed the hardening/1594-1591-bot-secrets branch from 552005f to 3c76b0a Compare November 14, 2026 21:39
@scttfrdmn
scttfrdmn marked this pull request as ready for review November 14, 2026 21:39
@scttfrdmn
scttfrdmn merged commit ac6896c into main Nov 14, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the hardening/1594-1591-bot-secrets branch November 14, 2026 21:59
@scttfrdmn scttfrdmn mentioned this pull request Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant