-
-
Notifications
You must be signed in to change notification settings - Fork 15
Add authentication support (local users, SAML SSO, user management UI) #153
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
Open
ViToRiO92
wants to merge
24
commits into
voxpupuli:main
Choose a base branch
from
ViToRiO92:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
194cf1e
Add local user authentication (ADR-001)
ViToRiO92 c56f4e0
go mod tidy
ViToRiO92 6146ee9
Fix import cycle between handler and middleware packages
ViToRiO92 bcb0b81
Add authentication test plan
ViToRiO92 6d5bc25
Add ADR-003: User management UI
ViToRiO92 77c5cb1
tests successfully for adr-001 done
ViToRiO92 dc36a2b
Add user management UI page (ADR-003)
ViToRiO92 12e7905
Implement SAML 2.0 authentication (ADR-002)
ViToRiO92 36f3b09
Fix SAML assertion validation by tracking AuthnRequest ID in cookie
ViToRiO92 876028d
crewjam logging
ViToRiO92 ca8bbfd
Fix login button extending beyond form field width
ViToRiO92 bda6f41
Make SAML user profile read-only in user management UI
ViToRiO92 c7447ec
Document SAML user read-only UI behavior in ADR-002
ViToRiO92 feaf170
Log config file parse errors instead of silently ignoring
ViToRiO92 ad1ff8e
Remove CLAUDE.md from repository
ViToRiO92 9af77ca
Update ADR documents, CONFIGURATION.md, and add screenshots
ViToRiO92 b0958cc
Update ADRs with is_admin authorization model
ViToRiO92 2bf6585
add reader and admin role
ViToRiO92 7513e00
save button visible for admin user
ViToRiO92 c38cbd4
SAML Cookie Missing Secure Flag
ViToRiO92 f58d750
implement adr-004
ViToRiO92 774b664
add security review
ViToRiO92 cfe0c10
add new test result
ViToRiO92 f60e841
updated ADR
ViToRiO92 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| package db | ||
|
|
||
| import ( | ||
| "database/sql" | ||
| "fmt" | ||
| "log" | ||
| "os" | ||
| "path/filepath" | ||
|
|
||
| _ "modernc.org/sqlite" | ||
| ) | ||
|
|
||
| type Database struct { | ||
| db *sql.DB | ||
| } | ||
|
|
||
| func Open(dbPath string) (*Database, error) { | ||
| dir := filepath.Dir(dbPath) | ||
| if err := os.MkdirAll(dir, 0700); err != nil { | ||
| return nil, fmt.Errorf("failed to create database directory: %w", err) | ||
| } | ||
|
|
||
| sqlDB, err := sql.Open("sqlite", dbPath) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to open database: %w", err) | ||
| } | ||
|
|
||
| if _, err := sqlDB.Exec("PRAGMA journal_mode=WAL"); err != nil { | ||
| sqlDB.Close() | ||
| return nil, fmt.Errorf("failed to set journal mode: %w", err) | ||
| } | ||
| if _, err := sqlDB.Exec("PRAGMA foreign_keys=ON"); err != nil { | ||
| sqlDB.Close() | ||
| return nil, fmt.Errorf("failed to enable foreign keys: %w", err) | ||
| } | ||
|
|
||
| d := &Database{db: sqlDB} | ||
| if err := d.migrate(); err != nil { | ||
| sqlDB.Close() | ||
| return nil, fmt.Errorf("failed to run migrations: %w", err) | ||
| } | ||
|
|
||
| log.Printf("Database opened: %s", dbPath) | ||
| return d, nil | ||
| } | ||
|
|
||
| func (d *Database) Close() error { | ||
| return d.db.Close() | ||
| } | ||
|
|
||
| func (d *Database) migrate() error { | ||
| migrations := []string{ | ||
| `CREATE TABLE IF NOT EXISTS users ( | ||
| id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
| username TEXT UNIQUE NOT NULL, | ||
| email TEXT, | ||
| display_name TEXT, | ||
| given_name TEXT, | ||
| surname TEXT, | ||
| password_hash TEXT, | ||
| auth_source TEXT NOT NULL DEFAULT 'local', | ||
| is_admin BOOLEAN NOT NULL DEFAULT FALSE, | ||
| created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP | ||
| )`, | ||
| `CREATE TABLE IF NOT EXISTS refresh_tokens ( | ||
| id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
| user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE, | ||
| token_hash TEXT UNIQUE NOT NULL, | ||
| expires_at DATETIME NOT NULL, | ||
| created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| revoked_at DATETIME | ||
| )`, | ||
| `CREATE INDEX IF NOT EXISTS idx_refresh_tokens_user_id ON refresh_tokens(user_id)`, | ||
| `CREATE INDEX IF NOT EXISTS idx_refresh_tokens_hash ON refresh_tokens(token_hash)`, | ||
| } | ||
|
|
||
| for _, m := range migrations { | ||
| if _, err := d.db.Exec(m); err != nil { | ||
| return fmt.Errorf("migration failed: %w\nSQL: %s", err, m) | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } |
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.
i think if we add this, we should use an ORM to enable other dbms also.