Skip to content

Commit

Permalink
Optional client secret for some providers (#178)
Browse files Browse the repository at this point in the history
Some providers, like google, request a client secret for the device
authentication. Make it optional, so that the admin can set it if
required in the generic broker.

There is no integration tests for now that could make use of it, but all
existing tests are passing. I have also tested manually with google and
msentraid.

UDENG-4954
  • Loading branch information
didrocks authored Nov 12, 2024
2 parents ed309a2 + d2cc671 commit 14fad3f
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions conf/broker.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[oidc]
issuer = https://<ISSUER_URL>
client_id = <CLIENT_ID>
# Client secret is needed for some specific auth flows depending on the provider.
# Only enable it if this is needed for your particular configuration.
# client_secret = <CLIENT_SECRET>

[users]
# The directory where the home directory will be created for new users.
Expand Down
8 changes: 5 additions & 3 deletions internal/broker/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type Config struct {

type userConfig struct {
clientID string
clientSecret string
issuerURL string
homeBaseDir string
allowedSSHSuffixes []string
Expand Down Expand Up @@ -213,9 +214,10 @@ func (b *Broker) connectToProvider(ctx context.Context) (authCfg authConfig, err
}

oauthCfg := oauth2.Config{
ClientID: b.oidcCfg.ClientID,
Endpoint: provider.Endpoint(),
Scopes: append(consts.DefaultScopes, b.providerInfo.AdditionalScopes()...),
ClientID: b.oidcCfg.ClientID,
ClientSecret: b.cfg.clientSecret,
Endpoint: provider.Endpoint(),
Scopes: append(consts.DefaultScopes, b.providerInfo.AdditionalScopes()...),
}

return authConfig{provider: provider, oauth: oauthCfg}, nil
Expand Down
3 changes: 3 additions & 0 deletions internal/broker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const (
issuerKey = "issuer"
// clientIDKey is the key in the config file for the client ID.
clientIDKey = "client_id"
// clientSecret is the optional client secret for this client.
clientSecret = "client_secret"

// usersSection is the section name in the config file for the users and broker specific configuration.
usersSection = "users"
Expand Down Expand Up @@ -50,6 +52,7 @@ func parseConfigFile(cfgPath string) (userConfig, error) {
if oidc != nil {
cfg.issuerURL = oidc.Key(issuerKey).String()
cfg.clientID = oidc.Key(clientIDKey).String()
cfg.clientSecret = oidc.Key(clientSecret).String()
}

users := iniCfg.Section(usersSection)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
clientID=<CLIENT_ID
clientSecret=
issuerURL=https://ISSUER_URL>
homeBaseDir=
allowedSSHSuffixes=[]
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
clientID=client_id
clientSecret=
issuerURL=https://issuer.url.com
homeBaseDir=
allowedSSHSuffixes=[]
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
clientID=client_id
clientSecret=
issuerURL=https://issuer.url.com
homeBaseDir=/home
allowedSSHSuffixes=[]

0 comments on commit 14fad3f

Please sign in to comment.