Repository navigation
Opt-in per-account ExternalId + tag-scoped EC2 in bot cross-account role (#374) - #368
Merged
Merged
Conversation
…ount role Adds two default-off parameters to bot-cross-account-role.yaml so each account can harden its spore-bot cross-account role without breaking already-deployed roles (#374): - ExternalId (default ''): when set, the trust policy requires this per-account high-entropy value (returned by `spawn bot register`) instead of the shared "<prefix>-bot". Empty preserves the legacy value the Lambda falls back to. - ScopeStartStopByTag (default 'false'): when 'true', Start/StopInstances are restricted to <prefix>:managed=true instances via an aws:ResourceTag condition; otherwise Resource "*" as before (registry-gated). IAM condition map keys must be literals, so the tag key is selected by TagPrefix (spawn|prism) via an Fn::If. Re-deploying with defaults reproduces current behavior exactly. Removing the code-side static fallback stays gated on customer-role adoption. cfn-lint clean.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
scttfrdmn
added a commit
that referenced
this pull request
Aug 3, 2026
Semgrep's dangerous-exec-command rule is blocking in this repo (#368), and it fires on every `exec.Command` with a non-literal argument — which is all six of them here. Annotated in the repo's existing style rather than widened in .semgrepignore, so each one carries its own reason: - `runQuietly`: the binary is a literal at both call sites ("scp", "ssh") and the args come from scpArgs/SSHExecArgs. No shell is involved, so an argument holding shell metacharacters is one argv element, not a command. - `RunLocal`: running a caller-named binary IS the contract. The path comes from the operator invoking spawn, who already has a local shell. - The four test sites: fixtures. Two of them run a shell deliberately — the forged-readiness-line reproduction needs one, and WrapRemoteCommand produces a shell script by design, so verifying the reap-on-EOF wrapper means running it. Also replaces the test server's `fmt.Fprint(w, body)` with `w.Write`, which is what it should have been: there is nothing to format, and it drops the no-fprintf-to-responsewriter finding rather than suppressing it.
scttfrdmn
added a commit
that referenced
this pull request
Aug 3, 2026
#481) Adds a verb for the shape spawn had no answer to: run a long-lived HTTP service on an instance and get a working local URL for it. `spawn launch` assumes a job that ends; `spawn connect -- cmd` gives no way to learn the port. Neither closes the loop. The seam is one JSON line on the service's stdout: {"event":"ready","addr":"127.0.0.1:54321","provenance":{...}} The service picks its own port (`:0`) and announces what it bound; spawn forwards to that. Nothing guesses a port, and nothing polls one — "is 8080 open yet?" cannot tell *my service starting* from *someone else's already there*. spawn does not name any workload and no workload names spawn. pkg/service is the reusable core (local child, readiness scan, tunnel, remote-over-SSH ladder); cmd/service.go is the verb; docs/service-readiness-contract.md is the public spec. Two hazards drove the design, both covered by tests: - The readiness line is forgeable. `init()` runs before `main`, so a workload can always print a well-formed line of its choosing first — "first match wins" is defeated by construction. Each candidate address is verified before it is trusted. - Verification is an HTTP request, not a TCP connect, because `ssh -L` accepts on the local end whether or not anything listens on the far side. A connect to a forward proves only that ssh is running. Any HTTP status counts, including 401/404 — the question is whether a server is there, not whether the caller is authorized. Lifetime: closing an SSH session does not reliably kill what it started (no TTY, so no SIGHUP), so the remote command is wrapped to TERM→KILL the service on stdin EOF. That is a request, not a guarantee — a partition can strand it. The instance TTL is the guarantee, so the launch path goes through the same mandatory-TTL zombie guard as every other launch, and `--dry-run` quotes the bound (rate × ttl) before spending anything. `--host` attaches to an instance spawn did not launch and promises no teardown. Exposure is loopback-only on both ends. A supplied token goes into the printed URL but never into the loggable address form. Tested at $0 over a local loopback path — the Substrate emulator is control-plane only (instances never boot, no SSH), so the emulator could not keep the first real spawn from being the first test. `service` is declared Tier 2-deferred in the coverage gate for that reason. Semgrep's exec and ResponseWriter findings are triaged inline per the repo's #368 convention, each with its own reason. Closes #409.
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.
Completes the additive half of the cross-account-role hardening in #374.1, on the spawn side (this template is where the customer
SpawnBotCrossAccountrole is defined; the spore-host Makefile references it cross-repo).Both changes are default-off and backward-compatible — re-deploying the stack with defaults reproduces the current behavior byte-for-byte. Each account opts into the hardened posture on its own schedule.
What changed (
deployment/cloudformation/bot-cross-account-role.yaml)ExternalIdparameter (default''): when set, the trust policy requires this per-account high-entropy value — the onespawn bot registernow returns asexternal_id(spore-host #412) — instead of the shared${TagPrefix}-bot. Empty preserves the legacy shared value, which the Lambda still falls back to.ScopeStartStopByTagparameter (default'false'): when'true',ec2:StartInstances/StopInstancesare restricted to${TagPrefix}:managed=trueinstances (the tag spawn applies to every launch) via anaws:ResourceTagcondition; otherwiseResource "*"as before, gated by the spore-bot registryenabledflag.ExternalIdoutput description ("hardcoded in the Lambda").Notes
Conditionmap keys must be literal strings (noFn::Sub), so the tag key is selected byTagPrefix(spawn|prism) with anFn::If.cfn-lintclean.Still gated (not in this PR)
Removing the code-side static
BOT_EXTERNAL_IDfallback (rest-api/spore-bot) stays gated until every customer role has re-deployed with a per-accountExternalId. This PR is the prerequisite that makes that adoption possible.Refs #374.