feat(control-plane): wire real injectSecrets/revokeSecrets against the main app's token broker - #8081
Merged
Merged
Conversation
…e main app's token broker (#8066) Closes the gap #7852's control-plane wiring left open: provisionTenant already captured provisionDatabase's real connection details (#7653) into its own result, but discarded them before calling injectSecrets. TenantProvisioningRequest now carries an optional `database` field, attached by provisionTenant right after provisionDatabase resolves and before injectSecrets runs. Adds secret-driver.ts: a real injectSecrets/revokeSecrets implementation calling the main app's own /v1/internal/orb/enrollments (issue, #8064's tenant_db_credential secret type) and its new revoke route -- the same two-step HTTP pattern self-hosted containers already use for their own GitHub-token exchange, just from a different physical caller. Stores the WHOLE DatabaseConnectionDetails object (JSON-encoded), not just the bare connectionString. Scope is deliberately narrow: this only stores/revokes custody of the credential in the broker, not delivery into a running container's environment (separate, not-yet-built infrastructure). injectSecrets now returns an opaque `secretRef` (the broker's enrollId) instead of void; provisionTenant threads it into its own result, http-app.ts persists it on the tenant registry record (product-agnostic, unlike amsSchedule/orbInstallationId), and DELETE /v1/tenants/:name reads it back to pass into deprovisionTenant's new optional secretRef parameter, so revokeSecrets knows what to revoke on teardown. Idempotent: a request with no secretRef never calls the broker at all. withRealSecretDriver (driver-factory.ts) composes the real driver in when MAIN_APP_BASE_URL/INTERNAL_JOB_TOKEN are both configured, mirroring withRealDatabaseDriver/withRealContainerDriver's existing composition shape. The GitHub-token type's existing behavior, and every other driver step, are completely unchanged. This is the last piece of #7852 (itself split from #7180's provisioning core) -- #8064 shipped the broker-side secret type + revoke path this calls. Closes #8066
Contributor
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8081 +/- ##
==========================================
- Coverage 91.99% 91.47% -0.52%
==========================================
Files 752 753 +1
Lines 76979 77157 +178
Branches 23315 23330 +15
==========================================
- Hits 70820 70583 -237
- Misses 5053 5515 +462
+ Partials 1106 1059 -47
Flags with carried forward coverage won't be shown. Click here to find out more.
|
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.
Summary
Implements #8066, the last piece of #7852 (itself split from #7180's provisioning core). #8064 (already merged) shipped the broker-side
tenant_db_credentialsecret type + revoke path this calls.provisionTenantalready capturedprovisionDatabase's real connection details (Real Postgres/Hyperdrive driver for control-plane's provisionDatabase/deprovisionDatabase #7653) into its own result, but discarded them before callinginjectSecrets(flagged in that function's own header comment).TenantProvisioningRequestnow carries an optionaldatabasefield, attached right afterprovisionDatabaseresolves and beforeinjectSecretsruns.secret-driver.ts: a realinjectSecrets/revokeSecretsimplementation calling the main app'sPOST /v1/internal/orb/enrollments(issue,tenant_db_credential) and its new revoke route — the same two-step HTTP pattern self-hosted containers already use for their own GitHub-token exchange, just from a different physical caller (control-plane's Worker has no D1 binding and no Worker-to-Worker service-binding precedent exists in this repo). Stores the wholeDatabaseConnectionDetailsobject (JSON-encoded), not just the bareconnectionString.injectSecretsnow returns an opaquesecretRef(the broker'senrollId) instead ofvoid.provisionTenantthreads it into its own result;http-app.tspersists it on the tenant registry record (product-agnostic, unlikeamsSchedule/orbInstallationId— either product can have a real secret driver configured);DELETE /v1/tenants/:namereads it back and passes it intodeprovisionTenant's new optionalsecretRefparameter sorevokeSecretsknows what to revoke on teardown. Idempotent: a request with nosecretRefnever calls the broker at all.withRealSecretDriver(driver-factory.ts) composes the real driver in whenMAIN_APP_BASE_URL/INTERNAL_JOB_TOKENare both configured, mirroringwithRealDatabaseDriver/withRealContainerDriver's existing composition shape.Test plan
npm run build(typecheck) cleannpm run cf:typecheckcleannpm run cf:typegen— regeneratedworker-configuration.d.tsfor the newMAIN_APP_BASE_URLvar, committednpm run test:node— 179/179 passingnode ../scripts/control-plane-coverage.mjs— every touched file 100%/100%/100%/100%; only gap is the pre-existing, untouchedsettlement-backend-driver.tsnpx wrangler deploy --dry-runclean, both container images build, all bindings (including the newMAIN_APP_BASE_URLvar) resolvenpm audit --audit-level=moderate— pre-existing findings only, no dependency changes in this PRCloses #8066