Skip to content

Commit

Permalink
vault: Remove legacy token based authentication workflow.
Browse files Browse the repository at this point in the history
The legacy workflow for Vault whereby servers were configured
using a token to provide authentication to the Vault API has now
been removed. This change also removes the workflow where servers
were responsible for deriving Vault tokens for Nomad clients.

The deprecated Vault config options used byi the Nomad agent have
all been removed except for "token" which is still in use by the
Vault Transit keyring implementation.

Job specification authors can no longer use the "vault.policies"
parameter and should instead use "vault.role" when not using the
default workload identity.
  • Loading branch information
jrasell committed Feb 19, 2025
1 parent 32c25d3 commit 13bfcb6
Show file tree
Hide file tree
Showing 66 changed files with 417 additions and 5,911 deletions.
4 changes: 0 additions & 4 deletions api/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,6 @@ type Job struct {
Migrate *MigrateStrategy `hcl:"migrate,block"`
Meta map[string]string `hcl:"meta,block"`
ConsulToken *string `mapstructure:"consul_token" hcl:"consul_token,optional"`
VaultToken *string `mapstructure:"vault_token" hcl:"vault_token,optional"`
UI *JobUIConfig `hcl:"ui,block"`

/* Fields set by server, not sourced from job config file */
Expand Down Expand Up @@ -1179,9 +1178,6 @@ func (j *Job) Canonicalize() {
if j.ConsulNamespace == nil {
j.ConsulNamespace = pointerOf("")
}
if j.VaultToken == nil {
j.VaultToken = pointerOf("")
}
if j.VaultNamespace == nil {
j.VaultNamespace = pointerOf("")
}
Expand Down
8 changes: 0 additions & 8 deletions api/jobs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ func TestJobs_Canonicalize(t *testing.T) {
AllAtOnce: pointerOf(false),
ConsulToken: pointerOf(""),
ConsulNamespace: pointerOf(""),
VaultToken: pointerOf(""),
VaultNamespace: pointerOf(""),
NomadTokenID: pointerOf(""),
Status: pointerOf(""),
Expand Down Expand Up @@ -387,7 +386,6 @@ func TestJobs_Canonicalize(t *testing.T) {
AllAtOnce: pointerOf(false),
ConsulToken: pointerOf(""),
ConsulNamespace: pointerOf(""),
VaultToken: pointerOf(""),
VaultNamespace: pointerOf(""),
NomadTokenID: pointerOf(""),
Status: pointerOf(""),
Expand Down Expand Up @@ -469,7 +467,6 @@ func TestJobs_Canonicalize(t *testing.T) {
AllAtOnce: pointerOf(false),
ConsulToken: pointerOf(""),
ConsulNamespace: pointerOf(""),
VaultToken: pointerOf(""),
VaultNamespace: pointerOf(""),
NomadTokenID: pointerOf(""),
Stop: pointerOf(false),
Expand Down Expand Up @@ -645,7 +642,6 @@ func TestJobs_Canonicalize(t *testing.T) {
AllAtOnce: pointerOf(false),
ConsulToken: pointerOf(""),
ConsulNamespace: pointerOf(""),
VaultToken: pointerOf(""),
VaultNamespace: pointerOf(""),
NomadTokenID: pointerOf(""),
Stop: pointerOf(false),
Expand Down Expand Up @@ -818,7 +814,6 @@ func TestJobs_Canonicalize(t *testing.T) {
AllAtOnce: pointerOf(false),
ConsulToken: pointerOf(""),
ConsulNamespace: pointerOf(""),
VaultToken: pointerOf(""),
VaultNamespace: pointerOf(""),
NomadTokenID: pointerOf(""),
Stop: pointerOf(false),
Expand Down Expand Up @@ -912,7 +907,6 @@ func TestJobs_Canonicalize(t *testing.T) {
AllAtOnce: pointerOf(false),
ConsulToken: pointerOf(""),
ConsulNamespace: pointerOf(""),
VaultToken: pointerOf(""),
VaultNamespace: pointerOf(""),
NomadTokenID: pointerOf(""),
Stop: pointerOf(false),
Expand Down Expand Up @@ -1096,7 +1090,6 @@ func TestJobs_Canonicalize(t *testing.T) {
AllAtOnce: pointerOf(false),
ConsulToken: pointerOf(""),
ConsulNamespace: pointerOf(""),
VaultToken: pointerOf(""),
VaultNamespace: pointerOf(""),
NomadTokenID: pointerOf(""),
Stop: pointerOf(false),
Expand Down Expand Up @@ -1275,7 +1268,6 @@ func TestJobs_Canonicalize(t *testing.T) {
AllAtOnce: pointerOf(false),
ConsulToken: pointerOf(""),
ConsulNamespace: pointerOf(""),
VaultToken: pointerOf(""),
VaultNamespace: pointerOf(""),
NomadTokenID: pointerOf(""),
Stop: pointerOf(false),
Expand Down
11 changes: 5 additions & 6 deletions client/allocrunner/taskrunner/task_runner_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,18 @@ func TestTaskRunner_DisableFileForVaultToken_UpgradePath(t *testing.T) {
"run_for": "0s",
}
task.Vault = &structs.Vault{
Cluster: structs.VaultDefaultCluster,
Policies: []string{"default"},
Cluster: structs.VaultDefaultCluster,
}

// Setup a test Vault client.
token := "1234"
handler := func(*structs.Allocation, []string) (map[string]string, error) {
return map[string]string{task.Name: token}, nil
handler := func(ctx context.Context, req vaultclient.JWTLoginRequest) (string, bool, error) {
return token, true, nil
}
vc, err := vaultclient.NewMockVaultClient(structs.VaultDefaultCluster)
must.NoError(t, err)
vaultClient := vc.(*vaultclient.MockVaultClient)
vaultClient.DeriveTokenFn = handler
vaultClient.SetDeriveTokenWithJWTFn(handler)

conf, cleanup := testTaskRunnerConfig(t, alloc, task.Name, vaultClient)
defer cleanup()
Expand Down Expand Up @@ -75,7 +74,7 @@ func TestTaskRunner_DisableFileForVaultToken_UpgradePath(t *testing.T) {
must.Eq(t, structs.TaskStateDead, finalState.State)
must.False(t, finalState.Failed)

// Verfiry token is in secrets dir.
// Verify token is in secrets dir.
tokenPath = filepath.Join(conf.TaskDir.SecretsDir, vaultTokenFile)
data, err := os.ReadFile(tokenPath)
must.NoError(t, err)
Expand Down
Loading

0 comments on commit 13bfcb6

Please sign in to comment.