diff --git a/.changelog/22227.txt b/.changelog/22227.txt new file mode 100644 index 000000000000..a5347802c74d --- /dev/null +++ b/.changelog/22227.txt @@ -0,0 +1,3 @@ +```release-note:bug +config: Fixed a panic triggered by registering a job specifying a Vault cluster that has not been configured within the server +``` diff --git a/nomad/job_endpoint_hook_vault_ce_test.go b/nomad/job_endpoint_hook_vault_ce_test.go index bced997d62be..7cd5014dbe43 100644 --- a/nomad/job_endpoint_hook_vault_ce_test.go +++ b/nomad/job_endpoint_hook_vault_ce_test.go @@ -57,4 +57,13 @@ func TestJobEndpointHook_VaultCE(t *testing.T) { warnings, err := hook.Validate(job) must.Len(t, 0, warnings) must.NoError(t, err) + + // Attempt to validate a job which details a Vault cluster name which has + // no configuration mapping within the server config. + mockJob2 := mock.Job() + mockJob2.TaskGroups[0].Tasks[0].Vault = &structs.Vault{Cluster: "does-not-exist"} + + warnings, err = hook.Validate(mockJob2) + must.Nil(t, warnings) + must.EqError(t, err, `Vault "does-not-exist" not enabled but used in the job`) } diff --git a/nomad/structs/config/vault.go b/nomad/structs/config/vault.go index 92f7cacee22f..52f34a0465ed 100644 --- a/nomad/structs/config/vault.go +++ b/nomad/structs/config/vault.go @@ -137,6 +137,9 @@ func DefaultVaultConfig() *VaultConfig { // IsEnabled returns whether the config enables Vault integration func (c *VaultConfig) IsEnabled() bool { + if c == nil { + return false + } return c.Enabled != nil && *c.Enabled }