Skip to content

Commit 8eb4641

Browse files
committed
Allow disabling local password through broker.conf
1 parent 8304517 commit 8eb4641

3 files changed

Lines changed: 34 additions & 2 deletions

File tree

authd-oidc-brokers/conf/variants/oidc/broker.conf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ client_id = <CLIENT_ID>
2424
## if the identity provider is unreachable (e.g. due to network issues).
2525
#force_provider_authentication = false
2626

27+
## Disable local password authentication, requiring users to always perform
28+
## device authentication with the identity provider.
29+
##
30+
## When enabled:
31+
## - Users will not be able to create or use local passwords
32+
## - Device authentication will be required for every login
33+
## - Local password authentication mode will not be offered
34+
##
35+
## Important: Enabling this option prevents offline login entirely.
36+
## Users must have network connectivity to authenticate.
37+
#disable_local_password = false
38+
2739
[users]
2840
## The directory where the home directories of new users are created.
2941
## Existing users will keep their current home directory.

authd-oidc-brokers/internal/broker/broker.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,11 @@ func (b *Broker) availableAuthModes(session session) (availableModes []string, e
305305
func (b *Broker) authModeIsAvailable(session session, authMode string) bool {
306306
switch authMode {
307307
case authmodes.Password:
308+
if b.cfg.disableLocalPassword {
309+
log.Debugf(context.Background(), "Local password authentication is disabled")
310+
return false
311+
}
312+
308313
if !tokenExists(session) {
309314
log.Debugf(context.Background(), "Token does not exist for user %q, so local password authentication is not available", session.username)
310315
return false
@@ -716,9 +721,14 @@ func (b *Broker) deviceAuth(ctx context.Context, session *session) (string, isAu
716721
// Store the auth info in the session so that we can use it when handling the
717722
// next IsAuthenticated call for the new password mode.
718723
session.authInfo = authInfo
719-
session.nextAuthModes = []string{authmodes.NewPassword}
720724

721-
return AuthNext, nil
725+
// Only require password creation if local password authentication is not disabled
726+
if !b.cfg.disableLocalPassword {
727+
session.nextAuthModes = []string{authmodes.NewPassword}
728+
return AuthNext, nil
729+
}
730+
731+
return b.finishAuth(session, authInfo)
722732
}
723733

724734
func (b *Broker) passwordAuth(ctx context.Context, session *session, secret string) (string, isAuthenticatedDataResponse) {

authd-oidc-brokers/internal/broker/config.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818
const (
1919
// forceProviderAuthenticationKey is the key in the config file for the option to force provider authentication during login.
2020
forceProviderAuthenticationKey = "force_provider_authentication"
21+
// disableLocalPasswordKey is the key in the config file for the option to disable local password authentication.
22+
disableLocalPasswordKey = "disable_local_password"
2123

2224
// oidcSection is the section name in the config file for the OIDC specific configuration.
2325
oidcSection = "oidc"
@@ -80,6 +82,7 @@ type userConfig struct {
8082
issuerURL string
8183

8284
forceProviderAuthentication bool
85+
disableLocalPassword bool
8386
registerDevice bool
8487

8588
allowedUsers map[string]struct{}
@@ -234,6 +237,13 @@ func parseConfig(cfgContent []byte, dropInContent []any, p provider) (userConfig
234237
return userConfig{}, fmt.Errorf("error parsing '%s': %w", forceProviderAuthenticationKey, err)
235238
}
236239
}
240+
241+
if oidc.HasKey(disableLocalPasswordKey) {
242+
cfg.disableLocalPassword, err = oidc.Key(disableLocalPasswordKey).Bool()
243+
if err != nil {
244+
return userConfig{}, fmt.Errorf("error parsing '%s': %w", disableLocalPasswordKey, err)
245+
}
246+
}
237247
}
238248

239249
entraID := iniCfg.Section(entraIDSection)

0 commit comments

Comments
 (0)