config: fix panic in job using Vault cluster not in agent config. (#22227)

This commit is contained in:
James Rasell
2024-05-24 15:13:20 +01:00
committed by GitHub
parent ac8fc25dd8
commit 81d87f1e9f
3 changed files with 15 additions and 0 deletions

3
.changelog/22227.txt Normal file
View File

@@ -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
```

View File

@@ -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`)
}

View File

@@ -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
}