Skip to content
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

Allow OIDC as default login #3617

Merged
merged 4 commits into from Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/swagger.yml
Expand Up @@ -591,6 +591,8 @@ components:
enum: [initialized, not_initialized]
oidc_enabled:
type: boolean
oidc_default_login:
type: boolean
AccessKeyCredentials:
type: object
properties:
Expand Down
3 changes: 3 additions & 0 deletions clients/java/api/openapi.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions clients/java/docs/SetupState.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions clients/python/docs/SetupState.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions clients/python/lakefs_client/model/setup_state.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions docs/assets/js/swagger.yml
Expand Up @@ -591,6 +591,8 @@ components:
enum: [initialized, not_initialized]
oidc_enabled:
type: boolean
oidc_default_login:
type: boolean
AccessKeyCredentials:
type: object
properties:
Expand Down
1 change: 1 addition & 0 deletions docs/reference/configuration.md
Expand Up @@ -57,6 +57,7 @@ This reference uses `.` to denote the nesting of values.
* `auth.ldap.default_user_group` `(string : )` - Create all LDAP users in this group. Defaults to `Viewers`.
* `auth.ldap.user_filter` `(string : )` - Additional filter for users.
* `auth.oidc.enabled` `(boolean : false)` - Set to true to enable authentication with an external OIDC provider.
* `auth.oidc.is_default_login` `(boolean : false)` - If true, the lakeFS login page will redirect to the external provider by default.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great way to add a property! I even complained about the added line on swagger.yml (then had to delete that comment when I saw this documentation...).

* `auth.oidc.client_id` `(string : )` - OIDC client ID.
* `auth.oidc.client_secret` `(string : )` - OIDC client secret.
* `auth.oidc.url` `(string : )` - The base URL of your OIDC compatible identity provider.
Expand Down
7 changes: 6 additions & 1 deletion pkg/api/controller.go
Expand Up @@ -3105,7 +3105,12 @@ func (c *Controller) GetSetupState(w http.ResponseWriter, r *http.Request) {
if initialized || c.Config.IsAuthTypeAPI() {
state = setupStateInitialized
}
response := SetupState{State: swag.String(state), OidcEnabled: swag.Bool(c.Config.GetAuthOIDCConfiguration().Enabled)}
oidcConfig := c.Config.GetAuthOIDCConfiguration()
response := SetupState{
State: swag.String(state),
OidcEnabled: swag.Bool(oidcConfig.Enabled),
OidcDefaultLogin: swag.Bool(oidcConfig.IsDefaultLogin),
}
writeResponse(w, http.StatusOK, response)
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/config/template.go
Expand Up @@ -5,7 +5,8 @@ import (
)

type OIDC struct {
Enabled bool `mapstructure:"enabled"`
Enabled bool `mapstructure:"enabled"`
IsDefaultLogin bool `mapstructure:"is_default_login"`

// provider details:
URL string `mapstructure:"url"`
Expand Down
7 changes: 6 additions & 1 deletion webui/src/pages/auth/login.jsx
Expand Up @@ -10,6 +10,8 @@ import {Error} from "../../lib/components/controls"
import {useRouter} from "../../lib/hooks/router";
import {useAPI} from "../../lib/hooks/api";

const OIDC_LOGIN_URL = "/oidc/login?prompt=login";

const LoginForm = ({oidcEnabled}) => {
const router = useRouter();
const [loginError, setLoginError] = useState(null);
Expand Down Expand Up @@ -60,7 +62,7 @@ const LoginForm = ({oidcEnabled}) => {
<Button variant="link" className="text-secondary mt-2" onClick={async ()=> {
document.cookie = 'oidc_auth_session=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
document.cookie = 'internal_auth_session=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
window.location = "/oidc/login?prompt=login";
window.location = OIDC_LOGIN_URL;
}}>Sign in with SSO provider</Button>
: ""
}
Expand All @@ -82,6 +84,9 @@ const LoginPage = () => {
if (!error && response && response.state !== SETUP_STATE_INITIALIZED) {
router.push({pathname: '/setup', query: router.query})
}
if (!error && response && response.oidc_default_login) {
window.location = OIDC_LOGIN_URL;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic here is a bit worrying: it seems like a both ifs could be taken. Now I know that they cannot, but it still looks weird.

What makes it even more confusing is that when oidc_default_login, we do a client-side redirect but also return a <Layout>. AFAIU that React component will never be rendered, so perhaps return after line 88? And then move lines 87..89 about lines 84..86???

I think something like this might be easier (if it is indeed correct, of course!):

Suggested change
if (!error && response && response.state !== SETUP_STATE_INITIALIZED) {
router.push({pathname: '/setup', query: router.query})
}
if (!error && response && response.oidc_default_login) {
window.location = OIDC_LOGIN_URL;
}
if (!error && response && response.oidc_default_login) {
window.location = OIDC_LOGIN_URL;
return null;
}
if (!error && response && response.state !== SETUP_STATE_INITIALIZED) {
router.push({pathname: '/setup', query: router.query})
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

return (
<Layout logged={false}>
<LoginForm oidcEnabled={!error && response && response.oidc_enabled }/>
Expand Down