Skip to content

Add an OIDC auto-login option for the web login pages - #2271

Open
huzama wants to merge 1 commit into
drakkan:mainfrom
huzama:oidc-auto-login
Open

Add an OIDC auto-login option for the web login pages#2271
huzama wants to merge 1 commit into
drakkan:mainfrom
huzama:oidc-auto-login

Conversation

@huzama

@huzama huzama commented Jul 23, 2026

Copy link
Copy Markdown

Checklist for Pull Requests


Adds oidc.auto_login, an opt-in setting that sends the WebAdmin and WebClient login pages straight to the OpenID provider instead of rendering the SFTPGo login page.

Why

With OIDC configured, reaching the provider always costs an extra click. Deployments that authenticate only through an identity provider work around this by rewriting the login path at the reverse proxy. That workaround is fragile: the rule is bypassed by any query string, it rewrites the login POST as well, and it traps the logout and OIDC error paths in a redirect loop, because both deliberately return the browser to the login page.

Configuration

"oidc": {
  "auto_login": 3
}
SFTPGO_HTTPD__BINDINGS__0__OIDC__AUTO_LOGIN=3
Value Effect
0 Disabled (default)
1 The WebAdmin UI login page redirects
2 The WebClient UI login page redirects
3 Both

The selected UI needs a usable OIDC setup: role_field or implicit_roles for the WebAdmin UI, and OIDC login not turned off through disabled_login_methods. Invalid combinations are rejected at startup rather than leaving the login page unreachable.

Behaviour

handleClientWebLogin and handleWebAdminLogin call oidcLoginRedirect directly, so this is a single redirect and the existing next validation and PKCE handling are reused unchanged.

The login page is still rendered, without redirecting, in two cases:

  1. A flash message is pending. Authentication errors such as an expired token or a role mismatch stay visible instead of looping back to the provider.
  2. Immediately after an explicit logout. The logout handlers set a short-lived, one-shot HttpOnly cookie that the next render consumes and clears. Without it, logging out would start a new login flow against an identity provider session that normally outlives the SFTPGo one, and the user would be signed straight back in.

The setting only controls presentation. It does not disable password authentication; disabled_login_methods remains the way to enforce OIDC-only access.

Tests

TestOIDCAutoLogin, TestOIDCAutoLoginConfig and TestNoAutoLoginCookie cover both UIs, next propagation, the two suppression paths and the startup validation.

OIDC-only deployments skip the SFTPGo login page by rewriting it at the
reverse proxy, which any query string bypasses and which loops logout and
error redirects back into the provider. Handling it in the login handler
lets the redirect be skipped while a flash message is pending and once
after a logout, so errors stay visible and logging out works.

Disabled by default. See drakkan#1646.
Copilot AI review requested due to automatic review settings July 23, 2026 03:17
@huzama
huzama requested a review from drakkan as a code owner July 23, 2026 03:17
@CLAassistant

CLAassistant commented Jul 23, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds an opt-in OIDC “auto-login” mode that can redirect WebAdmin and/or WebClient login pages directly to the OpenID Provider (instead of rendering the local login page), while preserving existing OIDC redirect/PKCE/next handling and preventing redirect loops after logout or when an auth error must be shown.

Changes:

  • Introduces oidc.auto_login (bitmask 0..3) in config/env and documents it in the sample JSON.
  • Implements conditional login-page redirects for WebAdmin/WebClient, with suppression when a flash error is present or immediately after logout via a short-lived one-shot cookie.
  • Adds startup validation and tests covering redirect behavior, next propagation, suppression paths, and env/config parsing.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
sftpgo.json Adds oidc.auto_login to the sample configuration with default 0.
internal/httpd/server.go Triggers OIDC redirect from login handlers when auto-login is enabled; sets no-auto-login cookie on logout.
internal/httpd/oidc.go Adds AutoLogin field to OIDC configuration with in-code documentation.
internal/httpd/oidc_test.go Adds tests for auto-login config validation, redirect behavior, and no-auto-login cookie semantics.
internal/httpd/httpd.go Adds auto-login enablement checks and startup validation integration.
internal/httpd/auth_utils.go Implements short-lived one-shot no_auto_login cookie helpers.
internal/config/config.go Wires oidc.auto_login default and env var parsing.
internal/config/config_test.go Extends env-binding tests to cover OIDC__AUTO_LOGIN.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/httpd/httpd.go
Comment on lines +819 to +827
func (b *Binding) checkAutoLogin() error {
if b.OIDC.AutoLogin&1 != 0 && !b.isWebAdminAutoLoginEnabled() {
return errors.New("OIDC auto login is enabled for the WebAdmin UI but OIDC login is not available")
}
if b.OIDC.AutoLogin&2 != 0 && !b.isWebClientAutoLoginEnabled() {
return errors.New("OIDC auto login is enabled for the WebClient UI but OIDC login is not available")
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants