Skip to content

Commit

Permalink
Complain if the env set in SecretEnv cannot be found
Browse files Browse the repository at this point in the history
Signed-off-by: Sandro <[email protected]>
  • Loading branch information
SuperSandro2000 committed Jan 2, 2024
1 parent e41a28b commit 39ecb13
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions cmd/dex/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ func (p *password) UnmarshalJSON(b []byte) error {
})
if len(data.Hash) == 0 && len(data.HashFromEnv) > 0 {
data.Hash = os.Getenv(data.HashFromEnv)
if data.Hash == "" {
return fmt.Errorf("invalid config: could not find HashFromEnv %q", data.HashFromEnv)
}
}
if len(data.Hash) == 0 {
return fmt.Errorf("no password hash provided")
Expand Down
12 changes: 10 additions & 2 deletions cmd/dex/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,11 @@ func runServe(options serveOptions) error {
if client.ID != "" {
return fmt.Errorf("invalid config: ID and IDEnv fields are exclusive for client %q", client.ID)
}
c.StaticClients[i].ID = os.Getenv(client.IDEnv)
id := os.Getenv(client.IDEnv)
if id == "" {
return fmt.Errorf("invalid config: could not find IDEnv %q", id)
}
c.StaticClients[i].ID = id
}
if client.Secret == "" && client.SecretEnv == "" && !client.Public {
return fmt.Errorf("invalid config: Secret or SecretEnv field is required for client %q", client.ID)
Expand All @@ -197,7 +201,11 @@ func runServe(options serveOptions) error {
if client.Secret != "" {
return fmt.Errorf("invalid config: Secret and SecretEnv fields are exclusive for client %q", client.ID)
}
c.StaticClients[i].Secret = os.Getenv(client.SecretEnv)
secret := os.Getenv(client.SecretEnv)
if secret == "" {
return fmt.Errorf("invalid config: could not find SecretEnv %q", client.SecretEnv)
}
c.StaticClients[i].Secret = secret
}
logger.Infof("config static client: %s", client.Name)
}
Expand Down

0 comments on commit 39ecb13

Please sign in to comment.