chore(rbac): update default behavior for tenant RBAC configuration
Refactor the tenant RBAC configuration to change the default value from false to true, enabling role enforcement by default. This change allows operators to opt into a logging-only rollout window by explicitly setting the configuration to false. Updates include: - Modifications to .env.example and docker-compose.yml to reflect the new default. - Adjustments in rbac.md documentation to clarify the new default behavior and the opt-in process. - Code changes across various files to utilize the new pointer-based configuration for EnableRBAC, ensuring nil safety and clearer intent. No functional changes were introduced; the adjustments primarily enhance clarity and maintainability of the RBAC feature.
This commit is contained in:
@@ -345,7 +345,7 @@ func resolveTenantRole(
|
||||
}
|
||||
|
||||
// 4. 兜底:根据 EnableRBAC 决定 fail-closed 还是 fail-open
|
||||
if cfg != nil && cfg.Tenant != nil && cfg.Tenant.EnableRBAC {
|
||||
if cfg != nil && cfg.Tenant.IsRBACEnforced() {
|
||||
logger.Warnf(ctx,
|
||||
"[auth] resolveTenantRole step4 fail-closed (EnableRBAC=true): user=%s tenant=%d",
|
||||
user.ID, targetTenantID)
|
||||
|
||||
@@ -135,7 +135,7 @@ func (f *fakeMemberService) RemoveMember(ctx context.Context, userID string, ten
|
||||
var _ interfaces.TenantMemberService = (*fakeMemberService)(nil)
|
||||
|
||||
func cfgWithRBAC(enabled bool) *config.Config {
|
||||
return &config.Config{Tenant: &config.TenantConfig{EnableRBAC: enabled}}
|
||||
return &config.Config{Tenant: &config.TenantConfig{EnableRBAC: &enabled}}
|
||||
}
|
||||
|
||||
func TestResolveTenantRole_ActiveMembershipWins(t *testing.T) {
|
||||
|
||||
@@ -207,7 +207,7 @@ func RequireOwnershipOrRole(min types.TenantRole, lookup CreatorLookup, cfg *con
|
||||
// to a warning and ownership lookups are skipped entirely so the dormant
|
||||
// rollout window incurs no per-request DB cost.
|
||||
func rbacEnforcementEnabled(cfg *config.Config) bool {
|
||||
return cfg != nil && cfg.Tenant != nil && cfg.Tenant.EnableRBAC
|
||||
return cfg != nil && cfg.Tenant.IsRBACEnforced()
|
||||
}
|
||||
|
||||
// isCrossTenantSuperuser was moved to access.go (renamed to
|
||||
|
||||
@@ -40,7 +40,7 @@ func rbacTestHarness(role types.TenantRole, userID string, mw gin.HandlerFunc) *
|
||||
}
|
||||
|
||||
func cfgRBAC(enabled bool) *config.Config {
|
||||
return &config.Config{Tenant: &config.TenantConfig{EnableRBAC: enabled}}
|
||||
return &config.Config{Tenant: &config.TenantConfig{EnableRBAC: &enabled}}
|
||||
}
|
||||
|
||||
// cfgRBACWithCrossTenant returns a config with both per-tenant RBAC
|
||||
@@ -49,7 +49,7 @@ func cfgRBAC(enabled bool) *config.Config {
|
||||
// so cross-tenant superuser tests need this rather than plain cfgRBAC.
|
||||
func cfgRBACWithCrossTenant(enabled bool) *config.Config {
|
||||
return &config.Config{Tenant: &config.TenantConfig{
|
||||
EnableRBAC: enabled,
|
||||
EnableRBAC: &enabled,
|
||||
EnableCrossTenantAccess: true,
|
||||
}}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user