feat(provision): service token on product lifecycle calls; stage/prod provision URLs #26

Merged
sharang merged 1 commits from feat/provision-service-token into main 2026-09-12 09:27:41 +00:00
6 changed files with 24 additions and 1 deletions

No files matched your search

+5
View File
@@ -91,4 +91,9 @@ type Adapter interface {
// Health pings the admin endpoint. Used by readyz and the cluster cold-
// start sequence (INFRASTRUCTURE.md §10 scenario F).
Health(ctx context.Context) error
// ServiceToken returns a client_credentials access token of the
// registry's own Keycloak client — the bearer for product lifecycle
// calls (PRODUCT_INTEGRATION_SPEC 2.0 §4.1; products verify aud + azp).
ServiceToken(ctx context.Context) (string, error)
}
+3
View File
@@ -58,6 +58,9 @@ func NewHTTPAdapter(cfg HTTPConfig) *HTTPAdapter {
// ─── auth ────────────────────────────────────────────────────────────────
// ServiceToken exposes the cached client_credentials token (see Adapter).
func (a *HTTPAdapter) ServiceToken(ctx context.Context) (string, error) { return a.token(ctx) }
func (a *HTTPAdapter) token(ctx context.Context) (string, error) {
a.mu.Lock()
defer a.mu.Unlock()
+3
View File
@@ -41,6 +41,9 @@ func (m *Mock) SyncTenantStatus(_ context.Context, slug, status string) error {
func (m *Mock) Health(_ context.Context) error { return nil }
// ServiceToken returns a fixed token so provisioning requests carry a bearer.
func (m *Mock) ServiceToken(_ context.Context) (string, error) { return "mock-service-token", nil }
func (m *Mock) CreateOrgAndInvite(_ context.Context, in InviteInput) (*InviteResult, error) {
m.mu.Lock()
defer m.mu.Unlock()
+8 -1
View File
@@ -370,7 +370,14 @@ func (s *Server) provisionProduct(ctx context.Context, r *http.Request, t *store
"id": t.ID, "name": t.Name, "slug": t.Slug, "plan": t.Plan,
"product": p.Key, "config": tp.Config, "expires_at": tp.ExpiresAt, "contract_version": "2.0",
}
if err := product.ProvisionAt(ctx, url, payload, nil, 10*time.Second); err != nil {
auth := func(ctx context.Context) (string, error) {
tok, err := s.Keycloak.ServiceToken(ctx)
if err != nil || tok == "" {
return "", err
}
return "Bearer " + tok, nil
}
if err := product.ProvisionAt(ctx, url, payload, auth, 10*time.Second); err != nil {
s.emitAudit(ctx, r, store.AuditEvent{
TenantID: t.ID, Action: "product.provision_failed", TargetID: p.Key, TargetType: "product",
Metadata: map[string]interface{}{"url": url, "err": err.Error()},
+1
View File
@@ -0,0 +1 @@
UPDATE products SET provision_urls = '{}'::jsonb WHERE key IN ('pruefwerk', 'firmwerk');
+4
View File
@@ -0,0 +1,4 @@
-- M-MIG-8: the registry provisions tenants at the products' platform endpoints
-- (PRODUCT_INTEGRATION_SPEC 2.0 §4.1) with its own service token.
UPDATE products SET provision_urls = '{"stage": "https://pruefwerk-stage.breakpilot.com/api/v1/platform/tenants/{id}/provision", "prod": "https://pruefwerk.breakpilot.com/api/v1/platform/tenants/{id}/provision"}'::jsonb WHERE key = 'pruefwerk';
UPDATE products SET provision_urls = '{"stage": "https://firmwerk-stage.breakpilot.com/api/v1/platform/tenants/{id}/provision", "prod": "https://firmwerk.breakpilot.com/api/v1/platform/tenants/{id}/provision"}'::jsonb WHERE key = 'firmwerk';