Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: add -jwks-ca-file to Vault/Consul setup commands #20518

Merged
merged 1 commit into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/20518.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
cli: Add `-jwks-ca-file` argument to `setup consul/vault` commands
```
23 changes: 19 additions & 4 deletions command/setup_consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ type SetupConsulCommand struct {
client *api.Client
clientCfg *api.Config

jwksURL string
jwksURL string
jwksCACertPath string

consulEnt bool
destroy bool
Expand Down Expand Up @@ -71,6 +72,10 @@ Setup Consul options:
URL of Nomad's JWKS endpoint contacted by Consul to verify JWT
signatures. Defaults to http://localhost:4646/.well-known/jwks.json.

-jwks-ca-file <path>
Path to a CA certificate file that will be used to validate the
JWKS URL if it uses TLS

-destroy
Removes all configuration components this command created from the
Consul cluster.
Expand All @@ -86,9 +91,10 @@ Setup Consul options:
func (s *SetupConsulCommand) AutocompleteFlags() complete.Flags {
return mergeAutocompleteFlags(s.Meta.AutocompleteFlags(FlagSetClient),
complete.Flags{
"-jwks-url": complete.PredictAnything,
"-destroy": complete.PredictSet("true", "false"),
"-y": complete.PredictSet("true", "false"),
"-jwks-url": complete.PredictAnything,
"-jwks-ca-file": complete.PredictAnything,
"-destroy": complete.PredictSet("true", "false"),
"-y": complete.PredictSet("true", "false"),
})
}

Expand All @@ -110,6 +116,7 @@ func (s *SetupConsulCommand) Run(args []string) int {
flags.BoolVar(&s.destroy, "destroy", false, "")
flags.BoolVar(&s.autoYes, "y", false, "")
flags.StringVar(&s.jwksURL, "jwks-url", "http://localhost:4646/.well-known/jwks.json", "")
flags.StringVar(&s.jwksCACertPath, "jwks-ca-file", "", "")
if err := flags.Parse(args); err != nil {
return 1
}
Expand Down Expand Up @@ -430,6 +437,14 @@ func (s *SetupConsulCommand) renderAuthMethod(name string, desc string) (*api.AC
authConfig["BoundAudiences"] = []string{consulAud}
authConfig["JWTSupportedAlgs"] = []string{"RS256"}

if s.jwksCACertPath != "" {
caCert, err := os.ReadFile(s.jwksCACertPath)
if err != nil {
return nil, fmt.Errorf("could not read -jwks-certfile: %v", err)
}
authConfig["JWKSCACert"] = string(caCert)
}

method := &api.ACLAuthMethod{
Name: name,
Type: "jwt",
Expand Down
23 changes: 19 additions & 4 deletions command/setup_vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ type SetupVaultCommand struct {
vLogical *api.Logical
ns string

jwksURL string
jwksURL string
jwksCACertPath string

destroy bool
autoYes bool
Expand Down Expand Up @@ -82,6 +83,10 @@ Setup Vault options:
URL of Nomad's JWKS endpoint contacted by Vault to verify JWT
signatures. Defaults to http://localhost:4646/.well-known/jwks.json.

-jwks-ca-file <path>
Path to a CA certificate file that will be used to validate the
JWKS URL if it uses TLS

-destroy
Removes all configuration components this command created from the
Vault cluster.
Expand Down Expand Up @@ -112,9 +117,10 @@ Setup Vault options when using -check:
func (s *SetupVaultCommand) AutocompleteFlags() complete.Flags {
return mergeAutocompleteFlags(s.Meta.AutocompleteFlags(FlagSetClient),
complete.Flags{
"-jwks-url": complete.PredictAnything,
"-destroy": complete.PredictSet("true", "false"),
"-y": complete.PredictSet("true", "false"),
"-jwks-url": complete.PredictAnything,
"-jwks-ca-file": complete.PredictAnything,
"-destroy": complete.PredictSet("true", "false"),
"-y": complete.PredictSet("true", "false"),

// Options for -check.
"-check": complete.PredictSet("true", "false"),
Expand Down Expand Up @@ -142,6 +148,7 @@ func (s *SetupVaultCommand) Run(args []string) int {
flags.BoolVar(&s.destroy, "destroy", false, "")
flags.BoolVar(&s.autoYes, "y", false, "")
flags.StringVar(&s.jwksURL, "jwks-url", "http://localhost:4646/.well-known/jwks.json", "")
flags.StringVar(&s.jwksCACertPath, "jwks-ca-file", "", "")

// Options for -check.
flags.BoolVar(&s.check, "check", false, "")
Expand Down Expand Up @@ -485,6 +492,14 @@ func (s *SetupVaultCommand) renderAuthMethod() (map[string]any, error) {
authConfig["jwks_url"] = s.jwksURL
authConfig["default_role"] = vaultRole

if s.jwksCACertPath != "" {
caCert, err := os.ReadFile(s.jwksCACertPath)
if err != nil {
return nil, fmt.Errorf("could not read -jwks-certfile: %v", err)
}
authConfig["jwks_ca_pem"] = string(caCert)
}

return authConfig, nil
}

Expand Down
3 changes: 3 additions & 0 deletions website/content/docs/commands/setup/consul.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ nomad setup consul [options]
- `-jwks-url`: URL of Nomad's JWKS endpoint contacted by Consul to verify JWT
signatures. Defaults to `http://localhost:4646/.well-known/jwks.json`.

- `-jwks-ca-file`: Path to a CA certificate file that will be used to validate
the JWKS URL if it uses TLS.

- `-destroy`: Removes all configuration components this command created from the
Consul cluster.

Expand Down
3 changes: 3 additions & 0 deletions website/content/docs/commands/setup/vault.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ nomad setup vault [options]
- `-jwks-url`: URL of Nomad's JWKS endpoint contacted by Consul to verify JWT
signatures. Defaults to `http://localhost:4646/.well-known/jwks.json`.

- `-jwks-ca-file`: Path to a CA certificate file that will be used to validate
the JWKS URL if it uses TLS.

- `-destroy`: Removes all configuration components this command created from the
Consul cluster.

Expand Down
Loading