feat: service accounts with scoped virtual key self-provisioning#134
Merged
farovictor merged 1 commit intomainfrom Apr 6, 2026
Merged
feat: service accounts with scoped virtual key self-provisioning#134farovictor merged 1 commit intomainfrom
farovictor merged 1 commit intomainfrom
Conversation
Adds a machine identity layer so CI/CD pipelines and automated services
can request short-lived virtual keys without a full user account.
- pkg/serviceaccounts: ServiceAccount model, MemoryStore, SQLStore
- allowed_services: empty = allow all; non-empty = restrict to list
- NOTE: flat v1 design — org-scoping deferred, see pkg/serviceaccounts/serviceaccount.go
- POST /v1/serviceaccounts — create (auto-generates ID + api_key)
- GET /v1/serviceaccounts — list (requires user auth)
- DELETE /v1/serviceaccounts/{id} — delete (requires user auth)
- POST /v1/service-token (X-Service-Key header) — returns a scoped virtual key
- defaults: ttl=3600s, rate_limit=60rpm, scope=write, source=sa
- keys.SourceServiceAccount constant added
- migration 011_create_service_accounts.sql
- 12 tests covering CRUD + token happy/error paths
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
ServiceAccountentity — separate fromUser, no management accessPOST /v1/service-token(auth viaX-Service-Key) issues a short-lived virtual key without needing a user sessionPOST/GET /v1/serviceaccounts,DELETE /v1/serviceaccounts/{id}allowed_servicesfield: empty = allow any registered service, non-empty = restrict to listed service IDssource: "sa"for traceability in usage logs011_create_service_accounts.sqlDesign note
This is a flat v1 implementation — service accounts are global to the Bifrost instance. Org-scoped service accounts are documented as a future concern in
pkg/serviceaccounts/serviceaccount.go.Usage (CI/CD pipeline example)
Test plan
TestCreateServiceAccount_OK— generates ID + api_key automaticallyTestCreateServiceAccount_MissingName— 400TestCreateServiceAccount_Duplicate— 409TestListServiceAccounts— returns all accountsTestDeleteServiceAccount_OK— 204TestDeleteServiceAccount_NotFound— 404TestServiceToken_OK— returns key with correct sourceTestServiceToken_MissingServiceKey— 401TestServiceToken_InvalidServiceKey— 401TestServiceToken_ServiceNotAllowed— 403TestServiceToken_ServiceNotFound— 404TestServiceToken_EmptyAllowedServicesAllowsAny— 200🤖 Generated with Claude Code