forked from huabeitech/agent-desk
-
Notifications
You must be signed in to change notification settings - Fork 0
feat(auth): redirect-only login mode with break-glass admin allowlist #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,7 @@ package migration | |||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| import ( | ||||||||||||||||||||||||||||||
| "agent-desk/internal/models" | ||||||||||||||||||||||||||||||
| "agent-desk/internal/pkg/config" | ||||||||||||||||||||||||||||||
| "agent-desk/internal/pkg/constants" | ||||||||||||||||||||||||||||||
| "agent-desk/internal/pkg/enums" | ||||||||||||||||||||||||||||||
| "agent-desk/internal/repositories" | ||||||||||||||||||||||||||||||
|
|
@@ -184,6 +185,22 @@ func ensureBootstrapAdmin(tx *gorm.DB, superAdminRole *models.Role) error { | |||||||||||||||||||||||||||||
| return errors.New("super admin role not found") | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // In SSO-only mode (OIDC enabled, password login disabled) a fresh | ||||||||||||||||||||||||||||||
| // deployment must not seed the known default-password account: it would be | ||||||||||||||||||||||||||||||
| // a standing backdoor the moment password login is ever re-enabled. Fresh | ||||||||||||||||||||||||||||||
| // SSO-only deployments bootstrap their first admin through the break-glass | ||||||||||||||||||||||||||||||
| // email allowlist (auth.breakGlassEmails) on first OIDC login instead. | ||||||||||||||||||||||||||||||
| // Deployments that seeded the account before flipping to SSO-only keep it; | ||||||||||||||||||||||||||||||
| // it stays unusable while password login is disabled because the allowlist | ||||||||||||||||||||||||||||||
| // only ever matches an email and this account has none. | ||||||||||||||||||||||||||||||
| cfg := config.Current() | ||||||||||||||||||||||||||||||
| if cfg.OIDC.Enabled && !cfg.Auth.IsPasswordLoginEnabled() { | ||||||||||||||||||||||||||||||
| slog.Info("skipping bootstrap admin seed: SSO-only login mode is active", | ||||||||||||||||||||||||||||||
| "oidc_enabled", true, | ||||||||||||||||||||||||||||||
| "password_login_enabled", false) | ||||||||||||||||||||||||||||||
| return nil | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
Comment on lines
+196
to
+202
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a nil check for
Suggested change
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| username := constants.BootstrapAdminUsername | ||||||||||||||||||||||||||||||
| nickname := constants.BootstrapAdminNickname | ||||||||||||||||||||||||||||||
| password := constants.BootstrapAdminPassword | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| package config | ||
|
|
||
| import ( | ||
| "reflect" | ||
| "testing" | ||
| ) | ||
|
|
||
| func boolPtr(v bool) *bool { | ||
| return &v | ||
| } | ||
|
|
||
| func TestAuthConfigBreakGlassEmailList(t *testing.T) { | ||
| cases := []struct { | ||
| name string | ||
| raw string | ||
| expected []string | ||
| }{ | ||
| {name: "empty", raw: "", expected: []string{}}, | ||
| {name: "blank only", raw: " , ,", expected: []string{}}, | ||
| {name: "trims and lowercases", raw: " Joy@Dos.AI , admin@crove.com ", expected: []string{"joy@dos.ai", "admin@crove.com"}}, | ||
| {name: "single email", raw: "joy@dos.ai", expected: []string{"joy@dos.ai"}}, | ||
| } | ||
|
|
||
| for _, tc := range cases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| cfg := AuthConfig{BreakGlassEmails: tc.raw} | ||
|
|
||
| if got := cfg.BreakGlassEmailList(); !reflect.DeepEqual(got, tc.expected) { | ||
| t.Fatalf("BreakGlassEmailList(%q) = %v, want %v", tc.raw, got, tc.expected) | ||
| } | ||
|
|
||
| if got := cfg.HasBreakGlassEmails(); got != (len(tc.expected) > 0) { | ||
| t.Fatalf("HasBreakGlassEmails(%q) = %v, want %v", tc.raw, got, len(tc.expected) > 0) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestAuthConfigIsBreakGlassEmail(t *testing.T) { | ||
| cfg := AuthConfig{BreakGlassEmails: "Joy@Dos.AI,ops@crove.com"} | ||
|
|
||
| cases := []struct { | ||
| email string | ||
| expected bool | ||
| }{ | ||
| {email: "joy@dos.ai", expected: true}, | ||
| {email: " JOY@DOS.AI ", expected: true}, | ||
| {email: "OPS@crove.com", expected: true}, | ||
| {email: "someone@dos.ai", expected: false}, | ||
| {email: "", expected: false}, | ||
| {email: " ", expected: false}, | ||
| } | ||
|
|
||
| for _, tc := range cases { | ||
| if got := cfg.IsBreakGlassEmail(tc.email); got != tc.expected { | ||
| t.Fatalf("IsBreakGlassEmail(%q) = %v, want %v", tc.email, got, tc.expected) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func TestAuthConfigIsBreakGlassLoginEnabled(t *testing.T) { | ||
| allowlist := "joy@dos.ai" | ||
|
|
||
| // Password login enabled: the door is irrelevant. | ||
| enabled := AuthConfig{PasswordLoginEnabled: boolPtr(true), BreakGlassEmails: allowlist} | ||
| if enabled.IsBreakGlassLoginEnabled() { | ||
| t.Fatal("break-glass must not be armed while password login is enabled") | ||
| } | ||
|
|
||
| // Disabled with no allowlist: nothing is armed. | ||
| disabledNoList := AuthConfig{PasswordLoginEnabled: boolPtr(false)} | ||
| if disabledNoList.IsBreakGlassLoginEnabled() { | ||
| t.Fatal("break-glass must not be armed without an allowlist") | ||
| } | ||
|
|
||
| // Disabled with an allowlist: the break-glass door is armed. | ||
| armed := AuthConfig{PasswordLoginEnabled: boolPtr(false), BreakGlassEmails: allowlist} | ||
| if !armed.IsBreakGlassLoginEnabled() { | ||
| t.Fatal("break-glass must be armed when password login is disabled and an allowlist exists") | ||
| } | ||
|
|
||
| // Default (unset) password login stays enabled. | ||
| defaultCfg := AuthConfig{BreakGlassEmails: allowlist} | ||
| if defaultCfg.IsBreakGlassLoginEnabled() { | ||
| t.Fatal("unset passwordLoginEnabled must keep password login enabled") | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To allow customers (
enums.UserTypeUser) to continue logging in via password when staff password login is disabled, we should remove this handler-level restriction. TheAuthService.Loginmethod will handle the password login restrictions specifically for employees (enums.UserTypeEmployee), making the handler-level check redundant and overly restrictive.// Password login enablement is checked per-user in AuthService.Login to support customer login.