Support Vault entity aliases (#12449)

Move some common Vault API data struct decoding out of the Vault client
so it can be reused in other situations.

Make Vault job validation its own function so it's easier to expand it.

Rename the `Job.VaultPolicies` method to just `Job.Vault` since it
returns the full Vault block, not just their policies.

Set `ChangeMode` on `Vault.Canonicalize`.

Add some missing tests.

Allows specifying an entity alias that will be used by Nomad when
deriving the task Vault token.

An entity alias assigns an indentity to a token, allowing better control
and management of Vault clients since all tokens with the same indentity
alias will now be considered the same client. This helps track Nomad
activity in Vault's audit logs and better control over Vault billing.

Add support for a new Nomad server configuration to define a default
entity alias to be used when deriving Vault tokens. This default value
will be used if the task doesn't have an entity alias defined.
This commit is contained in:
Luiz Aoqui
2022-04-05 14:18:10 -04:00
committed by GitHub
parent a8d5e5e7a3
commit d412f7b497
33 changed files with 1411 additions and 233 deletions

View File

@@ -1197,6 +1197,7 @@ func ApiTaskToStructsTask(job *structs.Job, group *structs.TaskGroup,
Policies: apiTask.Vault.Policies,
Namespace: *apiTask.Vault.Namespace,
Env: *apiTask.Vault.Env,
EntityAlias: *apiTask.Vault.EntityAlias,
ChangeMode: *apiTask.Vault.ChangeMode,
ChangeSignal: *apiTask.Vault.ChangeSignal,
}

View File

@@ -2721,6 +2721,7 @@ func TestJobs_ApiJobToStructsJob(t *testing.T) {
Env: helper.BoolToPtr(true),
ChangeMode: helper.StringToPtr("c"),
ChangeSignal: helper.StringToPtr("sighup"),
EntityAlias: helper.StringToPtr("valid-alias"),
},
Templates: []*api.Template{
{
@@ -3120,6 +3121,7 @@ func TestJobs_ApiJobToStructsJob(t *testing.T) {
Env: true,
ChangeMode: "c",
ChangeSignal: "sighup",
EntityAlias: "valid-alias",
},
Templates: []*structs.Template{
{