Default-deny access control with group flags and access enumeration
Some checks failed
Some checks failed
Replaces the implicit "empty allowed_groups means public" rule with explicit default-deny across both OIDC and ForwardAuth. Adds two boolean flags on Group — auto_assign (Keycloak-style auto-join on user create) and admin (members can reach the admin panel) — and drops the users.admin column entirely. Adds "Users with access" and "Accessible applications" panels with via-group badges on the application/user show pages. BEHAVIOR CHANGE: a ForwardAuth app with no allowed_groups previously bypassed authentication entirely; it now returns 403 like any other unauthorized request. The data migration seeds an "everyone" group and attaches it to all previously group-less apps to preserve behavior on existing installs. An "admins" group is seeded and backfilled from any user with the old admin column. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -42,7 +42,18 @@ class User < ApplicationRecord
|
||||
enum :status, {active: 0, disabled: 1, pending_invitation: 2}
|
||||
|
||||
# Scopes
|
||||
scope :admins, -> { where(admin: true) }
|
||||
scope :admins, -> { joins(:groups).where(groups: {admin: true}).distinct }
|
||||
|
||||
# Set true on a user (or on the user_params) to skip the auto-assign callback
|
||||
# for that record. Used by the admin invite form (opt-out checkbox) and by
|
||||
# tests that want a clean slate.
|
||||
attr_accessor :skip_auto_assign
|
||||
|
||||
after_create :add_to_auto_assign_groups, unless: :skip_auto_assign
|
||||
|
||||
def admin?
|
||||
groups.any?(&:admin?)
|
||||
end
|
||||
|
||||
# TOTP methods
|
||||
def totp_enabled?
|
||||
@@ -222,6 +233,10 @@ class User < ApplicationRecord
|
||||
|
||||
private
|
||||
|
||||
def add_to_auto_assign_groups
|
||||
Group.auto_assign.each { |g| groups << g }
|
||||
end
|
||||
|
||||
def no_reserved_claim_names
|
||||
return if custom_claims.blank?
|
||||
|
||||
|
||||
Reference in New Issue
Block a user