Files
Niklas Ye a023274280 Let team owners create service accounts in the web UI
Making a credential for CI meant signing in with curl, minting a personal
API key, finding a user id and then calling the service-accounts API by
hand. Nobody should need that to let a pipeline record a release event.

Team -> Automation lists the team's accounts and lets an owner create one,
add a key (rotation), revoke a key or delete the account. A new key is shown
once, next to the team id, because the next place it goes is a CI secret.
It sits behind the owner check, as the rest of a team's configuration does.

Two routes back it: GET /api/teams/{id}/service-accounts returns the team's
accounts with each key's name, age and last use and never a key value, and
DELETE /api/teams/{id}/service-accounts/{id} removes one, scoped to the
team so another team's account answers 404. Creating an account and minting
or revoking a key reuse the existing routes. Deleting an account keeps its
history: timelines, events and notes keep their rows, shown without a name.

Instance-scoped accounts are still an administrator's API call and are not
offered in the UI, since they reach every team. Nothing in the TUI or the
operator's client uses these routes, so neither needs a change.
2026-11-04 21:44:31 +01:00

42 lines
1.6 KiB
Go

package models
import "time"
// Service account scopes. Instance acts with the same reach system
// administration has over teams: create one, list them, mint a team-scoped
// account against any of them. Team acts as that one team's owner, and
// nothing else.
const (
ServiceAccountScopeInstance = "instance"
ServiceAccountScopeTeam = "team"
)
// ServiceAccount is a non-human credential: not a users row, so it never
// touches OIDC group sync, login, or the is_admin flag, and is never mistaken
// for a human in an audit trail (see api_keys' user_id, which every service
// account key deliberately does not have).
type ServiceAccount struct {
ID int64 `json:"id"`
Name string `json:"name"`
Scope string `json:"scope"`
TeamID *int64 `json:"team_id,omitempty"`
CreatedBy *int64 `json:"created_by,omitempty"`
CreatedAt time.Time `json:"created_at"`
// Keys is filled by the per-team listing only: each key's name, age and
// last use, never its value.
Keys []ServiceAccountKey `json:"keys,omitempty"`
}
// ServiceAccountKey is one bearer credential on a ServiceAccount. Multiple
// keys per account, the same shape as APIKey, are what let rotation mint a
// new one and revoke the old without recreating the account.
type ServiceAccountKey struct {
ID int64 `json:"id"`
ServiceAccountID int64 `json:"service_account_id"`
Name string `json:"name"`
CreatedAt time.Time `json:"created_at"`
LastUsedAt *time.Time `json:"last_used_at,omitempty"`
Key string `json:"key,omitempty"` // populated only on creation, never stored
}