-
Notifications
You must be signed in to change notification settings - Fork 1.9k
OIDC Authentication Driver #14406
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
OIDC Authentication Driver #14406
Conversation
361b921
to
c15e09a
Compare
|
AER Report: CI Coreaer_workflow , commit , Clean Go Tidy & Generate , Detect Changes , Scheduled Run Frequency , GolangCI Lint (.) , Core Tests (go_core_tests) , test-scripts , Core Tests (go_core_tests_integration) , Core Tests (go_core_ccip_deployment_tests) , Core Tests (go_core_fuzz) , Core Tests (go_core_race_tests) , lint , SonarQube Scan 1. Duplicate migration version found:go_core_race_testsSource of Error:
Suggested fix: Rename one of the migration files to have a unique version number. 2. Duplicate migration version found:go_core_tests_integrationSource of Error:
Suggested fix: Rename one of the migration files to have a unique version number. 3. Missing go.sum entry: test-scriptsSource of Error:
Suggested fix: Run 4. Duplicate migration version found:go_core_ccip_deployment_testsSource of Error:
Suggested fix: Rename one of the migration files to have a unique version number. 5. GolangCI Lint errors: GolangCI Lint (.)Source of Error:
|
a771d47
to
ce4bdea
Compare
core/sessions/oidcauth/oidc.go
Outdated
RouterRateLimitterPeriod = 1 * time.Minute | ||
RouterRateLimitterLimit = 1000 |
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.
Unused? Otherwise, spelling:
RouterRateLimitterPeriod = 1 * time.Minute | |
RouterRateLimitterLimit = 1000 | |
RouterRateLimiterPeriod = 1 * time.Minute | |
RouterRateLimiterLimit = 1000 |
And could use a https://pkg.go.dev/golang.org/x/time/rate#Limiter which has some helpers for specifying the rate and supports bursts.
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.
Yes, removed 🙂
core/sessions/oidcauth/oidc.go
Outdated
); err != nil { | ||
return clsessions.ErrUserSessionExpired |
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.
Should this confirm sql.ErrNoRows
or something to rule out other kinds of errors?
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.
Yes we should catch that case, updated now to propagate up the error if its not the expected NoRows
core/sessions/oidcauth/oidc.go
Outdated
if err := sqlutil.TransactDataSource(ctx, oi.ds, nil, func(tx sqlutil.DataSource) error { | ||
return tx.GetContext(ctx, &localAdminUser, SQLSelectUserbyEmail, user.Email) | ||
}); err != nil { | ||
oi.lggr.Infof("Can not change password, local user with email not found in users table: %s, err: %v", user.Email, err) | ||
return clsessions.ErrNotSupported | ||
} | ||
|
||
// User is local admin, save new password | ||
hashedPassword, err := utils.HashPassword(newPassword) | ||
if err != nil { | ||
return err | ||
} | ||
if err := sqlutil.TransactDataSource(ctx, oi.ds, nil, func(tx sqlutil.DataSource) error { | ||
sql := "UPDATE users SET hashed_password = $1, updated_at = now() WHERE email = $2 RETURNING *" | ||
return tx.GetContext(ctx, user, sql, hashedPassword, user.Email) | ||
}); err != nil { | ||
oi.lggr.Errorf("unable to set password for user: %s, err: %v", user.Email, err) | ||
return errors.New("unable to save password") | ||
} |
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.
We should be able to skip the transactions in cases with a single statement
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.
Simplified now 🙂
core/sessions/oidcauth/oidc.go
Outdated
const constantTimeEmailLength = 256 | ||
|
||
func constantTimeEmailCompare(left, right string) bool { | ||
length := mathutil.Max(constantTimeEmailLength, len(left), len(right)) |
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.
nit/ this is valid if you want to declare it in the narrowest scope:
const constantTimeEmailLength = 256 | |
func constantTimeEmailCompare(left, right string) bool { | |
length := mathutil.Max(constantTimeEmailLength, len(left), len(right)) | |
func constantTimeEmailCompare(left, right string) bool { | |
const constantTimeEmailLength = 256 | |
length := mathutil.Max(constantTimeEmailLength, len(left), len(right))``` |
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.
Nice, done!
core/sessions/oidcauth/oidc.go
Outdated
// User is local admin, save new password | ||
hashedPassword, err := utils.HashPassword(newPassword) | ||
if err != nil { | ||
return err |
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.
Maybe worth wrapping?
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.
Logged and created new user facing error in the case this is hit
core/sessions/oidcauth/oidc.go
Outdated
) | ||
if err != nil { | ||
oi.lggr.Errorf("unable to create new session in oidc_sessions table %v", err) | ||
return "", fmt.Errorf("error creating local LDAP session: %w", err) |
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.
return "", fmt.Errorf("error creating local LDAP session: %w", err) | |
return "", fmt.Errorf("error creating local OIDC session: %w", err) |
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.
Hehe nice catch
Merged operator-ui with support for optional OIDC login button: https://github.com/smartcontractkit/operator-ui/releases/tag/v0.8.0-371c5cf - release cut |
Documentation PR: smartcontractkit/documentation#2790 |
core/sessions/oidcauth/oidc.go
Outdated
err := sqlutil.TransactDataSource(ctx, oi.ds, nil, func(tx sqlutil.DataSource) error { | ||
return tx.GetContext(ctx, &foundUser, SQLSelectUserbyEmail, email) | ||
}) | ||
|
||
if err != nil { |
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.
err := sqlutil.TransactDataSource(ctx, oi.ds, nil, func(tx sqlutil.DataSource) error { | |
return tx.GetContext(ctx, &foundUser, SQLSelectUserbyEmail, email) | |
}) | |
if err != nil { | |
if err := tx.GetContext(ctx, &foundUser, SQLSelectUserbyEmail, email); err != nil { |
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.
👍
core/sessions/oidcauth/oidc.go
Outdated
if err := sqlutil.TransactDataSource(ctx, oi.ds, nil, func(tx sqlutil.DataSource) error { | ||
sql := "SELECT * FROM users ORDER BY email ASC;" | ||
return tx.SelectContext(ctx, &returnUsers, sql) | ||
}); err != nil { |
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.
if err := sqlutil.TransactDataSource(ctx, oi.ds, nil, func(tx sqlutil.DataSource) error { | |
sql := "SELECT * FROM users ORDER BY email ASC;" | |
return tx.SelectContext(ctx, &returnUsers, sql) | |
}); err != nil { | |
if err := tx.SelectContext(ctx, &returnUsers, "SELECT * FROM users ORDER BY email ASC;"); err != nil { |
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.
👍
|
This PR introduces a new authentication driver for the core node session auth flow for the Operator UI. This extends the options to local auth, LDAP server authentication, and now OIDC auth. This means that SSO sign on and RBAC roles can be managed from a provider/identity server that manages and maps user group membership.
The only required config to support this new authentication method looks as follows:
See Front-end changes
smartcontractkit/operator-ui#104