fix(fly): require SPRITES_TOKEN on the fly target - #682
Open
kylemclaren wants to merge 1 commit into
Open
Conversation
deploy/core/fly.toml sets SANDBOX_BACKEND = "sprites", which makes SPRITES_TOKEN a required core secret at config load. The CLI never saw that value: the secret gate resolves SANDBOX_BACKEND from env.core and then from TARGET_ENV_DEFAULTS, and the fly entry declared only HARNESS. setup never prompted for the token, check never listed it, secrets push never delivered it, and up deployed a core that crash-looped to its restart limit with "missing or insecure required core secrets: SPRITES_TOKEN". Declare SANDBOX_BACKEND in FLY_TEMPLATE_ENV_DEFAULTS so the constant matches the template it mirrors, and share one resolver between the fly and aws defaults so an explicit sandbox.backend overrides both. The existing sync test only walked the constant and asserted fly.toml agreed, so a missing entry was invisible. The new test walks the other direction over every template env that gates a secret. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RvEqtztffzduM5H7Hrt9JJ
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.
The problem
A new
flydeployment does not start. The core application stops immediately after each start. It writes this error:The core application makes 10 attempts to start. Then Fly stops the machine. The other four services do not deploy, because the core deploys first.
I found this problem when I deployed to Fly for the first time.
The cause
The file
deploy/core/fly.tomlsetsSANDBOX_BACKEND = "sprites". The filesrc/deployment/secret-schema.tsmakesSPRITES_TOKENa necessary secret whenSANDBOX_BACKENDhas the valuesprites. Thus the core application needsSPRITES_TOKENwhen it starts.The CLI does not know this. The secret gate in
cli/src/secrets.tslooks for the value ofSANDBOX_BACKENDin two places:env.corein the fileqm.config.jsonc.TARGET_ENV_DEFAULTS.The
flyentry inTARGET_ENV_DEFAULTSdeclares onlyHARNESS. It does not declareSANDBOX_BACKEND. A scaffolded configuration does not setSANDBOX_BACKENDinenv.core. Thus the CLI does not find the value.The result is four failures:
qm setupdoes not ask the operator for the token.qm checkdoes not show the token in the list of necessary secrets.qm secrets pushdoes not send the token to the core application.qm updeploys a core application that cannot start.The
flytarget permits only thespritessandbox backend. You can see this incli/src/providers.ts. Thus eachflydeployment needs this secret.Why the tests did not find the problem
The test
FLY_TEMPLATE_ENV_DEFAULTS stays in sync with deploy/core/fly.tomlexamines one direction only. It reads each entry in the constant. Then it makes sure thatdeploy/core/fly.tomlsets that entry to the same value. It does not read the entries indeploy/core/fly.toml. Thus an entry that the constant does not declare stays hidden.The test
the sprites token is a catalog secret when the sandbox backend is spritesuses theawstarget only. No test used theflytarget.The correction
The correction has two parts:
SANDBOX_BACKEND: "sprites"toFLY_TEMPLATE_ENV_DEFAULTS. The constant now agrees with the template that it mirrors.flydefaults and theawsdefaults. Before this change, only theawsbranch let an explicitsandbox.backendreplace the default. The two branches now behave in the same way.The new tests
I added two tests to
cli/test/secrets.test.ts:flytarget needsSPRITES_TOKEN. It uses three configurations: nosandboxblock, asandboxblock with an app, and asandboxblock with an explicit backend.deploy/core/fly.toml. It finds each variable that controls a secret. For each of these variables, the test makes sure thatFLY_TEMPLATE_ENV_DEFAULTSdeclares the variable with the same value. This test looks in the direction that the older test does not examine. It prevents this class of problem in the future.Both new tests fail before the correction. Both new tests pass after the correction.
The effect on operators
SPRITES_TOKENbecomes a necessary secret for eachflydeployment.qm setupasks for the token.qm checkshows the token.qm secrets pushsends the token to the core application.A
flydeployment that operates correctly today already has this secret in its core application. Such a deployment does not change.The tests that I ran
I ran the CLI test suite before the change and after the change:
The same three tests fail in both conditions. These three tests fail because of my environment, not because of this change. Two of them (
init refuses to generate keys into an absent but Git-tracked .envandinit refuses a present tracked .env before writing the scaffold) depend on the Git state of the checkout. One of them (the packed npm artifact creates and operates a standalone deployment repository) runsnpm pack, which my sandbox restricts.I updated four test fixtures for the
flytarget. These fixtures now supplySPRITES_TOKEN. The fixtures were correct to fail: they described a deployment that could not start.npm run typecheckandeslintshow no errors for the changed files.What I did not do
I did not add the token to
qm doctoras a live check. The Sprites API can show if a token is correct. A subsequent change can add this check.A related note
I used the Sprites API to make sure that a token was correct before I put it in the deployment:
An organization token for Fly does not operate here. The token must come from
sprite login. The referencecli/templates/deployment/references/fly.mddoes not tell the operator this. The same reference tells the operator to prove the agent computer withfly machine exec. This instruction is correct for Fly Machines. It is not correct for sandboxes that run on Sprites. These two items are documentation problems. I did not correct them in this change.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.