Author SHA1 Message Date
Sharang ParnerkarandClaude Fable 5 fa07b3bae0 ci: the image job never ran — fix its condition, tag :latest, deploy for real
ci / shared (pull_request) Failing after 4s
ci / test (pull_request) Successful in 21m22s
ci / image (pull_request) Skipped
Three defects left the deployment frozen on an Aug-06 image while five
RBAC merges landed on main:

1. The job-level `hashFiles('Dockerfile')` condition evaluates BEFORE
   checkout, against an empty workspace — always '', so the job was
   silently skipped on every push to main.
2. Had it run, it pushed only sha-* and env-stage tags; orca deploys
   :latest, which nothing ever updated.
3. The final step ran `orca apply --env=stage` against a stage
   environment this cluster does not have.

Now: condition without hashFiles (the Dockerfile is not optional),
:latest tagged alongside sha-*, and the deploy step replaced with the
HMAC-signed orca webhook the other repos use (registered on the master;
ORCA_WEBHOOK_SECRET set as a repo Actions secret).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-30 23:10:18 +02:00
7 changed files with 61 additions and 201 deletions
+17 -25
View File
@@ -99,33 +99,25 @@ jobs:
# this job silently never ran (deployment sat on an Aug-06 image). # this job silently never ran (deployment sat on an Aug-06 image).
if: github.event_name == 'push' && github.ref == 'refs/heads/main' if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: docker runs-on: docker
# The runner's default job container has no docker CLI, so
# docker/login-action + docker/build-push-action die with "Unable to
# locate executable file: docker". Same pattern as the proven
# breakpilot-compliance build-push-deploy.yml: run in docker:27-cli
# (talks to the runner's daemon) and use plain docker commands.
container: docker:27-cli
steps: steps:
- name: Checkout - uses: actions/checkout@v4
run: |
apk add --no-cache git curl openssl
git clone --depth 1 --branch ${GITHUB_REF_NAME} $(echo ${GITHUB_SERVER_URL} | sed -E "s#^(https?://)#\1ci:${{ secrets.GITHUB_TOKEN }}@#")/${GITHUB_REPOSITORY}.git .
- name: Login - uses: docker/login-action@v3
env: with:
REGISTRY_USER: ${{ secrets.REGISTRY_USER }} registry: repo.breakpilot.com
REGISTRY_PASS: ${{ secrets.REGISTRY_PASS }} username: ${{ secrets.REGISTRY_USER }}
run: echo "$REGISTRY_PASS" | docker login repo.breakpilot.com -u "$REGISTRY_USER" --password-stdin password: ${{ secrets.REGISTRY_PASS }}
- name: Build + push - uses: docker/build-push-action@v6
run: | with:
set -eu push: true
docker build \ tags: |
-t repo.breakpilot.com/breakpilot/tenant-registry:latest \ repo.breakpilot.com/breakpilot/${{ github.event.repository.name }}:sha-${{ github.sha }}
-t repo.breakpilot.com/breakpilot/tenant-registry:sha-${GITHUB_SHA} \ repo.breakpilot.com/breakpilot/${{ github.event.repository.name }}:latest
.
docker push repo.breakpilot.com/breakpilot/tenant-registry:latest - uses: anchore/sbom-action@v0
docker push repo.breakpilot.com/breakpilot/tenant-registry:sha-${GITHUB_SHA} with:
image: repo.breakpilot.com/breakpilot/${{ github.event.repository.name }}:sha-${{ github.sha }}
# Notify orca to pull :latest and recreate the service (same pattern as # Notify orca to pull :latest and recreate the service (same pattern as
# breakpilot-core/build-pitch-deck.yml). The stage-env deploy this used to # breakpilot-core/build-pitch-deck.yml). The stage-env deploy this used to
@@ -135,7 +127,7 @@ jobs:
ORCA_WEBHOOK_SECRET: ${{ secrets.ORCA_WEBHOOK_SECRET }} ORCA_WEBHOOK_SECRET: ${{ secrets.ORCA_WEBHOOK_SECRET }}
ORCA_WEBHOOK_URL: http://46.225.100.82:6880/api/v1/webhooks/github ORCA_WEBHOOK_URL: http://46.225.100.82:6880/api/v1/webhooks/github
run: | run: |
set -eu set -euo pipefail
PAYLOAD="{\"ref\":\"refs/heads/main\",\"repository\":{\"full_name\":\"${GITHUB_REPOSITORY}\"},\"head_commit\":{\"id\":\"${GITHUB_SHA}\",\"message\":\"ci: tenant-registry image build\"}}" PAYLOAD="{\"ref\":\"refs/heads/main\",\"repository\":{\"full_name\":\"${GITHUB_REPOSITORY}\"},\"head_commit\":{\"id\":\"${GITHUB_SHA}\",\"message\":\"ci: tenant-registry image build\"}}"
SIG=$(printf '%s' "$PAYLOAD" | openssl dgst -sha256 -hmac "$ORCA_WEBHOOK_SECRET" -r | awk '{print $1}') SIG=$(printf '%s' "$PAYLOAD" | openssl dgst -sha256 -hmac "$ORCA_WEBHOOK_SECRET" -r | awk '{print $1}')
curl -sSf -k \ curl -sSf -k \
+1 -1
View File
@@ -3,7 +3,7 @@
# /tenant-registry — long-running API server # /tenant-registry — long-running API server
# /migrate — one-shot schema migrator (Orca init container in prod) # /migrate — one-shot schema migrator (Orca init container in prod)
FROM golang:1.25-alpine AS build FROM golang:1.24-alpine AS build
WORKDIR /src WORKDIR /src
COPY go.mod go.sum ./ COPY go.mod go.sum ./
RUN go mod download RUN go mod download
+5 -6
View File
@@ -75,12 +75,11 @@ type Adapter interface {
SyncClaims(ctx context.Context, userID string, c Claims) error SyncClaims(ctx context.Context, userID string, c Claims) error
// Memberships resolves the tenants user userID (the Keycloak user id, // Memberships resolves the tenants user userID (the Keycloak user id,
// i.e. the JWT `sub`) belongs to, as Keycloak records them. Since the // i.e. the JWT `sub`) belongs to, as Keycloak records them. The realm
// realm enabled Organizations (2026-09-01) this is an org-membership // has no Organizations yet, so this reads the user's attribute
// query: one membership per enabled org the user belongs to (alias = // projection — zero or one memberships. When the realm migrates to
// tenant slug, org attribute tenant_id = registry UUID). The legacy // Organizations this becomes an org-membership query and callers keep
// user-attribute projection no longer grants membership on its own. // working unchanged. Returns ErrUserNotFound for an unknown user id.
// Returns ErrUserNotFound for an unknown user id.
Memberships(ctx context.Context, userID string) ([]Claims, error) Memberships(ctx context.Context, userID string) ([]Claims, error)
// Health pings the admin endpoint. Used by readyz and the cluster cold- // Health pings the admin endpoint. Used by readyz and the cluster cold-
-10
View File
@@ -4,7 +4,6 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"errors" "errors"
"io"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"strings" "strings"
@@ -25,7 +24,6 @@ type stubKC struct {
emailCalls atomic.Int32 emailCalls atomic.Int32
healthCalls atomic.Int32 healthCalls atomic.Int32
syncCalls atomic.Int32 syncCalls atomic.Int32
lastOrgBody string
tokenFails atomic.Bool // when true, /token returns 401 once tokenFails atomic.Bool // when true, /token returns 401 once
} }
@@ -55,8 +53,6 @@ func newStubKC(t *testing.T) *stubKC {
mux.HandleFunc("/admin/realms/test-realm/organizations", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/admin/realms/test-realm/organizations", func(w http.ResponseWriter, r *http.Request) {
s.orgCalls.Add(1) s.orgCalls.Add(1)
if r.Method == http.MethodPost { if r.Method == http.MethodPost {
body, _ := io.ReadAll(r.Body)
s.lastOrgBody = string(body)
w.Header().Set("Location", s.srv.URL+"/admin/realms/test-realm/organizations/org-xyz") w.Header().Set("Location", s.srv.URL+"/admin/realms/test-realm/organizations/org-xyz")
w.WriteHeader(http.StatusCreated) w.WriteHeader(http.StatusCreated)
return return
@@ -139,12 +135,6 @@ func TestHTTPAdapter_createOrgAndInvite(t *testing.T) {
t.Errorf("call counts: org=%d user=%d member=%d email=%d", t.Errorf("call counts: org=%d user=%d member=%d email=%d",
s.orgCalls.Load(), s.userCalls.Load(), s.memberCalls.Load(), s.emailCalls.Load()) s.orgCalls.Load(), s.userCalls.Load(), s.memberCalls.Load(), s.emailCalls.Load())
} }
// KC 26 rejects a domainless org; the adapter must send a synthetic
// per-slug domain so onboarding actually provisions.
if !strings.Contains(s.lastOrgBody, `"domains"`) ||
!strings.Contains(s.lastOrgBody, "acme.tenant.breakpilot.com") {
t.Errorf("org create body missing synthetic domain: %s", s.lastOrgBody)
}
} }
func TestHTTPAdapter_emailMissingAdminEmailRejected(t *testing.T) { func TestHTTPAdapter_emailMissingAdminEmailRejected(t *testing.T) {
-15
View File
@@ -13,11 +13,6 @@ import (
// ─── organizations API ─────────────────────────────────────────────────── // ─── organizations API ───────────────────────────────────────────────────
// orgDomainSuffix namespaces the synthetic org domain. The slug is unique in
// the registry, so "<slug>.tenant.breakpilot.com" is unique per organization
// and never a real deliverable mail domain we might clash with.
const orgDomainSuffix = ".tenant.breakpilot.com"
type orgCreate struct { type orgCreate struct {
Name string `json:"name"` Name string `json:"name"`
Alias string `json:"alias"` Alias string `json:"alias"`
@@ -55,16 +50,6 @@ func (a *HTTPAdapter) CreateOrgAndInvite(ctx context.Context, in InviteInput) (*
Name: in.Name, Name: in.Name,
Alias: in.Slug, Alias: in.Slug,
Description: fmt.Sprintf("Auto-provisioned from tenant-registry %s", in.TenantID), Description: fmt.Sprintf("Auto-provisioned from tenant-registry %s", in.TenantID),
// Keycloak 26 rejects an organization with no domain ("You must
// provide at least one domain"). Membership is registry-authoritative
// (model B2), so we do NOT use Keycloak's email-domain auto-join; a
// synthetic per-tenant domain derived from the unique slug satisfies
// the constraint without depending on the customer's real mail domain
// (which may be a shared public domain and would collide across
// tenants). Unverified is fine — verification only gates auto-join.
Domains: []map[string]any{
{"name": in.Slug + orgDomainSuffix, "verified": false},
},
Attributes: map[string][]string{ Attributes: map[string][]string{
"tenant_id": {in.TenantID}, "tenant_id": {in.TenantID},
}, },
+16 -51
View File
@@ -18,33 +18,7 @@ type userRepresentation struct {
Attributes map[string][]string `json:"attributes"` Attributes map[string][]string `json:"attributes"`
} }
// memberOrgRepresentation is the slice of OrganizationRepresentation the // Memberships implements Adapter against GET /admin/realms/{realm}/users/{id}.
// membership query needs: the alias IS the tenant slug and the org
// attribute "tenant_id" carries the registry tenant UUID (both written by
// CreateOrgAndInvite, or provisioned by the realm admin for pre-existing
// tenants).
type memberOrgRepresentation struct {
ID string `json:"id"`
Alias string `json:"alias"`
Enabled bool `json:"enabled"`
Attributes map[string][]string `json:"attributes"`
}
// Memberships implements Adapter with Keycloak Organizations as the
// authoritative membership source (prod shape, realm orgs enabled
// 2026-09-01):
//
// 1. GET /users/{id} — preserves ErrUserNotFound semantics and supplies
// the per-user claim attributes (org_roles / products / plan /
// tenant_status) that SyncClaims maintains.
// 2. GET /organizations/members/{id}/organizations — the memberships.
//
// One Claims entry per ENABLED organization: TenantID = org attribute
// "tenant_id" (registry UUID), TenantSlug = org alias. A disabled org
// grants no membership. A user in no organization has zero memberships —
// the legacy user-attribute tenant projection is NO LONGER consulted for
// membership, so a stale tenant_id/tenant_slug user attribute cannot
// grant access the org model has revoked.
func (a *HTTPAdapter) Memberships(ctx context.Context, userID string) ([]Claims, error) { func (a *HTTPAdapter) Memberships(ctx context.Context, userID string) ([]Claims, error) {
var u userRepresentation var u userRepresentation
resp, err := a.adminCall(ctx, http.MethodGet, "/users/"+userID, nil, &u) resp, err := a.adminCall(ctx, http.MethodGet, "/users/"+userID, nil, &u)
@@ -59,34 +33,25 @@ func (a *HTTPAdapter) Memberships(ctx context.Context, userID string) ([]Claims,
_ = resp.Body.Close() _ = resp.Body.Close()
return nil, fmt.Errorf("keycloak get user: %d", resp.StatusCode) return nil, fmt.Errorf("keycloak get user: %d", resp.StatusCode)
} }
return claimsFromAttributes(u.Attributes), nil
var orgs []memberOrgRepresentation
resp, err = a.adminCall(
ctx, http.MethodGet, "/organizations/members/"+userID+"/organizations", nil, &orgs,
)
if err != nil {
return nil, err
}
if resp.StatusCode/100 != 2 {
_ = resp.Body.Close()
return nil, fmt.Errorf("keycloak member organizations: %d", resp.StatusCode)
} }
claims := []Claims{} // claimsFromAttributes builds the membership list from a user's attribute
for _, org := range orgs { // projection. A user with no tenant_id and no tenant_slug attribute simply
if !org.Enabled { // has no memberships — that is a valid state, not an error.
continue func claimsFromAttributes(attrs map[string][]string) []Claims {
c := Claims{
TenantID: attrValue(attrs, "tenant_id"),
TenantSlug: attrValue(attrs, "tenant_slug"),
OrgRoles: attrValues(attrs, "org_roles"),
Products: attrValues(attrs, "products"),
Plan: attrValue(attrs, "plan"),
TenantStatus: attrValue(attrs, "tenant_status"),
} }
claims = append(claims, Claims{ if c.TenantID == "" && c.TenantSlug == "" {
TenantID: attrValue(org.Attributes, "tenant_id"), return []Claims{}
TenantSlug: org.Alias,
OrgRoles: attrValues(u.Attributes, "org_roles"),
Products: attrValues(u.Attributes, "products"),
Plan: attrValue(u.Attributes, "plan"),
TenantStatus: attrValue(u.Attributes, "tenant_status"),
})
} }
return claims, nil return []Claims{c}
} }
func attrValue(attrs map[string][]string, key string) string { func attrValue(attrs map[string][]string, key string) string {
+21 -92
View File
@@ -9,13 +9,9 @@ import (
"testing" "testing"
) )
// stubUsersKC is a users+organizations KC look-alike; stubKC (client_test.go) // stubUsersKC is a users-endpoint-only KC look-alike; stubKC (client_test.go)
// covers the org-create/invite paths and doesn't register these reads. // covers the org/invite paths and doesn't register GET /users/{id}.
func stubUsersKC( func stubUsersKC(t *testing.T, users map[string]userRepresentation) *httptest.Server {
t *testing.T,
users map[string]userRepresentation,
memberOrgs map[string][]memberOrgRepresentation,
) *httptest.Server {
t.Helper() t.Helper()
mux := http.NewServeMux() mux := http.NewServeMux()
mux.HandleFunc("/realms/test-realm/protocol/openid-connect/token", func(w http.ResponseWriter, _ *http.Request) { mux.HandleFunc("/realms/test-realm/protocol/openid-connect/token", func(w http.ResponseWriter, _ *http.Request) {
@@ -32,14 +28,6 @@ func stubUsersKC(
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(u) _ = json.NewEncoder(w).Encode(u)
}) })
mux.HandleFunc("GET /admin/realms/test-realm/organizations/members/{id}/organizations", func(w http.ResponseWriter, r *http.Request) {
orgs, ok := memberOrgs[r.PathValue("id")]
if !ok {
orgs = []memberOrgRepresentation{}
}
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(orgs)
})
srv := httptest.NewServer(mux) srv := httptest.NewServer(mux)
t.Cleanup(srv.Close) t.Cleanup(srv.Close)
return srv return srv
@@ -52,11 +40,10 @@ func usersAdapter(srv *httptest.Server) *HTTPAdapter {
} }
func TestHTTPAdapter_Memberships(t *testing.T) { func TestHTTPAdapter_Memberships(t *testing.T) {
users := map[string]userRepresentation{ srv := stubUsersKC(t, map[string]userRepresentation{
"u-1": {ID: "u-1", Username: "test@breakpilot.com", Enabled: true, Attributes: map[string][]string{ "u-1": {ID: "u-1", Username: "test@breakpilot.com", Enabled: true, Attributes: map[string][]string{
// legacy projection attrs — MUST NOT grant membership on their own "tenant_id": {"acme-001"},
"tenant_id": {"stale-legacy-001"}, "tenant_slug": {"acme"},
"tenant_slug": {"stale"},
"tenant_status": {"active"}, "tenant_status": {"active"},
"plan": {"Scale"}, "plan": {"Scale"},
"org_roles": {"IT_ADMIN", "FINANCE"}, "org_roles": {"IT_ADMIN", "FINANCE"},
@@ -64,30 +51,10 @@ func TestHTTPAdapter_Memberships(t *testing.T) {
"products": {"compliance##certifai"}, "products": {"compliance##certifai"},
}}, }},
"u-2": {ID: "u-2", Username: "bare@breakpilot.com", Enabled: true}, "u-2": {ID: "u-2", Username: "bare@breakpilot.com", Enabled: true},
"u-3": {ID: "u-3", Username: "multi@breakpilot.com", Enabled: true}, })
"u-4": {ID: "u-4", Username: "attrs-only@breakpilot.com", Enabled: true, Attributes: map[string][]string{
"tenant_id": {"acme-001"},
"tenant_slug": {"acme"},
}},
}
memberOrgs := map[string][]memberOrgRepresentation{
"u-1": {{
ID: "org-1", Alias: "acme", Enabled: true,
Attributes: map[string][]string{"tenant_id": {"2f875d6a-1d94-433a-b2ec-8529451a2d89"}},
}},
"u-3": {
{ID: "org-1", Alias: "acme", Enabled: true,
Attributes: map[string][]string{"tenant_id": {"2f875d6a-1d94-433a-b2ec-8529451a2d89"}}},
{ID: "org-2", Alias: "globex", Enabled: true,
Attributes: map[string][]string{"tenant_id": {"7c3f2b10-0000-4000-8000-000000000042"}}},
{ID: "org-3", Alias: "disabled-co", Enabled: false,
Attributes: map[string][]string{"tenant_id": {"9e9e9e9e-0000-4000-8000-000000000099"}}},
},
}
srv := stubUsersKC(t, users, memberOrgs)
a := usersAdapter(srv) a := usersAdapter(srv)
t.Run("org membership becomes the claim, org attrs are authoritative", func(t *testing.T) { t.Run("attribute projection becomes one membership", func(t *testing.T) {
got, err := a.Memberships(context.Background(), "u-1") got, err := a.Memberships(context.Background(), "u-1")
if err != nil { if err != nil {
t.Fatalf("memberships: %v", err) t.Fatalf("memberships: %v", err)
@@ -96,14 +63,8 @@ func TestHTTPAdapter_Memberships(t *testing.T) {
t.Fatalf("want 1 membership, got %d", len(got)) t.Fatalf("want 1 membership, got %d", len(got))
} }
c := got[0] c := got[0]
// tenant identity comes from the ORG (alias + tenant_id attribute), if c.TenantID != "acme-001" || c.TenantSlug != "acme" || c.Plan != "Scale" || c.TenantStatus != "active" {
// never from the user's legacy projection attributes t.Errorf("scalar claims wrong: %+v", c)
if c.TenantID != "2f875d6a-1d94-433a-b2ec-8529451a2d89" || c.TenantSlug != "acme" {
t.Errorf("org identity wrong: %+v", c)
}
// per-user claim attrs still ride along
if c.Plan != "Scale" || c.TenantStatus != "active" {
t.Errorf("user claim attrs wrong: %+v", c)
} }
if len(c.OrgRoles) != 2 || c.OrgRoles[0] != "IT_ADMIN" || c.OrgRoles[1] != "FINANCE" { if len(c.OrgRoles) != 2 || c.OrgRoles[0] != "IT_ADMIN" || c.OrgRoles[1] != "FINANCE" {
t.Errorf("org_roles wrong: %v", c.OrgRoles) t.Errorf("org_roles wrong: %v", c.OrgRoles)
@@ -113,7 +74,7 @@ func TestHTTPAdapter_Memberships(t *testing.T) {
} }
}) })
t.Run("user in no org has zero memberships", func(t *testing.T) { t.Run("user without tenant attributes has zero memberships", func(t *testing.T) {
got, err := a.Memberships(context.Background(), "u-2") got, err := a.Memberships(context.Background(), "u-2")
if err != nil { if err != nil {
t.Fatalf("memberships: %v", err) t.Fatalf("memberships: %v", err)
@@ -123,29 +84,6 @@ func TestHTTPAdapter_Memberships(t *testing.T) {
} }
}) })
t.Run("legacy tenant attributes alone grant NO membership", func(t *testing.T) {
got, err := a.Memberships(context.Background(), "u-4")
if err != nil {
t.Fatalf("memberships: %v", err)
}
if len(got) != 0 {
t.Fatalf("attribute projection must not grant membership, got %+v", got)
}
})
t.Run("multiple orgs give multiple memberships, disabled org skipped", func(t *testing.T) {
got, err := a.Memberships(context.Background(), "u-3")
if err != nil {
t.Fatalf("memberships: %v", err)
}
if len(got) != 2 {
t.Fatalf("want 2 memberships (disabled org skipped), got %d", len(got))
}
if got[0].TenantSlug != "acme" || got[1].TenantSlug != "globex" {
t.Errorf("slugs wrong: %+v", got)
}
})
t.Run("unknown user is ErrUserNotFound", func(t *testing.T) { t.Run("unknown user is ErrUserNotFound", func(t *testing.T) {
_, err := a.Memberships(context.Background(), "nope") _, err := a.Memberships(context.Background(), "nope")
if !errors.Is(err, ErrUserNotFound) { if !errors.Is(err, ErrUserNotFound) {
@@ -154,24 +92,15 @@ func TestHTTPAdapter_Memberships(t *testing.T) {
}) })
} }
func TestHTTPAdapter_Memberships_OrgQueryFailure(t *testing.T) { func TestMock_Memberships(t *testing.T) {
mux := http.NewServeMux() m := NewMock()
mux.HandleFunc("/realms/test-realm/protocol/openid-connect/token", func(w http.ResponseWriter, _ *http.Request) { if _, err := m.Memberships(context.Background(), "ghost"); !errors.Is(err, ErrUserNotFound) {
w.Header().Set("Content-Type", "application/json") t.Fatalf("want ErrUserNotFound, got %v", err)
_ = json.NewEncoder(w).Encode(map[string]any{"access_token": "t", "expires_in": 60}) }
}) want := Claims{TenantSlug: "acme", OrgRoles: []string{"IT_ADMIN"}}
mux.HandleFunc("GET /admin/realms/test-realm/users/{id}", func(w http.ResponseWriter, _ *http.Request) { m.Claims["u-1"] = want
w.Header().Set("Content-Type", "application/json") got, err := m.Memberships(context.Background(), "u-1")
_ = json.NewEncoder(w).Encode(userRepresentation{ID: "u-1", Enabled: true}) if err != nil || len(got) != 1 || got[0].TenantSlug != "acme" {
}) t.Fatalf("got %+v err %v", got, err)
mux.HandleFunc("GET /admin/realms/test-realm/organizations/members/{id}/organizations", func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
})
srv := httptest.NewServer(mux)
t.Cleanup(srv.Close)
_, err := usersAdapter(srv).Memberships(context.Background(), "u-1")
if err == nil {
t.Fatal("want error when the org query fails, got nil")
} }
} }