Skip to content

Commit

Permalink
feat: allow domain names or IDs in keystone connector
Browse files Browse the repository at this point in the history
OpenStack Keystone allows a user to authenticate against a domain. That
domain can be specified either as the domain ID or the domain name when
authenticating. The domain ID is a UUID or the special "default" domain
ID so key off of that when deciding what to submit to the keystone API.
Collapsed the code to share the domainKeystone struct by utilizing
omitempty to skip unset fields.

Signed-off-by: Doug Goldstein <[email protected]>
  • Loading branch information
cardoe committed Jun 2, 2024
1 parent 0b6a783 commit 926a81c
Show file tree
Hide file tree
Showing 3 changed files with 214 additions and 48 deletions.
36 changes: 24 additions & 12 deletions connector/keystone/keystone.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import (
"log/slog"
"net/http"

"github.com/google/uuid"

"github.com/dexidp/dex/connector"
)

type conn struct {
Domain string
Domain domainKeystone
Host string
AdminUsername string
AdminPassword string
Expand All @@ -29,8 +31,8 @@ type userKeystone struct {
}

type domainKeystone struct {
ID string `json:"id"`
Name string `json:"name"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
}

// Config holds the configuration parameters for Keystone connector.
Expand Down Expand Up @@ -71,13 +73,9 @@ type password struct {
}

type user struct {
Name string `json:"name"`
Domain domain `json:"domain"`
Password string `json:"password"`
}

type domain struct {
ID string `json:"id"`
Name string `json:"name"`
Domain domainKeystone `json:"domain"`
Password string `json:"password"`
}

type token struct {
Expand Down Expand Up @@ -112,8 +110,22 @@ var (

// Open returns an authentication strategy using Keystone.
func (c *Config) Open(id string, logger *slog.Logger) (connector.Connector, error) {
_, err := uuid.Parse(c.Domain)
var domain domainKeystone
// check if the supplied domain is a UUID or the special "default" value
// which is treated as an ID and not a name
if err == nil || c.Domain == "default" {
domain = domainKeystone{
ID: c.Domain,
}
} else {
domain = domainKeystone{
Name: c.Domain,
}
}

return &conn{
Domain: c.Domain,
Domain: domain,
Host: c.Host,
AdminUsername: c.AdminUsername,
AdminPassword: c.AdminPassword,
Expand Down Expand Up @@ -202,7 +214,7 @@ func (p *conn) getTokenResponse(ctx context.Context, username, pass string) (res
Password: password{
User: user{
Name: username,
Domain: domain{ID: p.Domain},
Domain: p.Domain,
Password: pass,
},
},
Expand Down
Loading

0 comments on commit 926a81c

Please sign in to comment.