admin → RBAC group migration: grant-based access replaces role check
All checks were successful
CI/CD / detect-changes (pull_request) Successful in 19s
CI/CD / test-frontend (pull_request) Has been skipped
CI/CD / test-go-pg (pull_request) Successful in 2m14s
CI/CD / test-sqlite (pull_request) Successful in 2m56s
CI/CD / build-and-deploy (pull_request) Successful in 1m21s

surface.admin.access permission + seeded Admins system group replaces
hardcoded role == "admin" middleware checks. Admin bypass removed from
RequirePermission — all permissions flow through group membership.
Bootstrap, seed, OIDC, and admin handlers sync group membership on
role changes. Demotion/deletion safeguards use group member count.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-26 16:14:46 +00:00
parent b9180d4184
commit 316c9cbfa7
15 changed files with 208 additions and 50 deletions

View File

@@ -171,6 +171,9 @@ func (p *OIDCProvider) Authenticate(c *gin.Context, stores store.Stores) (*Resul
user.Role = role
}
// Sync Admins group membership with resolved role
SyncAdminsGroupMembership(ctx, stores, user.ID, role)
// Sync groups
p.syncGroups(ctx, user.ID, claims, stores)
@@ -474,6 +477,9 @@ func (p *OIDCProvider) autoProvision(
log.Printf("[auth/oidc] auto-provisioned user %s (sub=%s, email=%s)", user.ID, sub, email)
// Sync Admins group membership with resolved role
SyncAdminsGroupMembership(ctx, stores, user.ID, role)
// Auto-add to default team
if p.cfg.DefaultTeam != "" {
if err := stores.Teams.AddMember(ctx, p.cfg.DefaultTeam, user.ID, "member"); err != nil {

View File

@@ -8,23 +8,30 @@ import (
)
// EveryoneGroupID is the stable ID of the implicit "Everyone" group seeded in
// migration 020. Every authenticated user receives its permissions without an
// migration 002. Every authenticated user receives its permissions without an
// explicit membership row.
const EveryoneGroupID = "00000000-0000-0000-0000-000000000001"
// AdminsGroupID is the stable ID of the "Admins" system group seeded in
// migration 002. Members receive surface.admin.access and all platform
// permissions. Replaces the legacy users.role = 'admin' check.
const AdminsGroupID = "00000000-0000-0000-0000-000000000002"
// Permission constants — domain.action convention.
const (
PermExtensionUse = "extension.use" // use installed extensions
PermExtensionInstall = "extension.install" // install/manage extension packages
PermWorkflowCreate = "workflow.create" // create workflow definitions
PermWorkflowSubmit = "workflow.submit" // submit to public workflows
PermAdminView = "admin.view" // read-only admin panel access
PermTokenUnlimited = "token.unlimited" // bypass token budgets
PermSurfaceAdminAccess = "surface.admin.access" // full admin panel access (replaces role check)
PermExtensionUse = "extension.use" // use installed extensions
PermExtensionInstall = "extension.install" // install/manage extension packages
PermWorkflowCreate = "workflow.create" // create workflow definitions
PermWorkflowSubmit = "workflow.submit" // submit to public workflows
PermAdminView = "admin.view" // read-only admin panel access
PermTokenUnlimited = "token.unlimited" // bypass token budgets
)
// AllPermissions is the complete set of valid permission strings.
// Used for validation in handlers and rendering checkboxes in admin UI.
var AllPermissions = []string{
PermSurfaceAdminAccess,
PermExtensionUse,
PermExtensionInstall,
PermWorkflowCreate,
@@ -37,7 +44,7 @@ var AllPermissions = []string{
// ResolvePermissions returns the effective permission set for a user.
// Always includes the Everyone group regardless of membership.
// Callers should short-circuit for role=admin before calling this.
// Includes both implicit Everyone group and explicit group memberships.
func ResolvePermissions(ctx context.Context, stores store.Stores, userID string) (map[string]bool, error) {
perms := make(map[string]bool)
@@ -62,6 +69,17 @@ func ResolvePermissions(ctx context.Context, stores store.Stores, userID string)
return perms, nil
}
// SyncAdminsGroupMembership adds or removes a user from the Admins group
// based on their role. Called by auth providers and admin handlers when
// a user's role changes so that permissions stay in sync.
func SyncAdminsGroupMembership(ctx context.Context, stores store.Stores, userID, role string) {
if role == "admin" {
_ = stores.Groups.AddMember(ctx, AdminsGroupID, userID, userID)
} else {
_ = stores.Groups.RemoveMember(ctx, AdminsGroupID, userID)
}
}
// ── Token Budget ────────────────────────────
// TokenBudget holds the resolved ceiling for a user and the time window it covers.