Skip to content

Commit 0a93ddd

Browse files
authored
Merge pull request #7127 from hashicorp/b-unset-ct
nomad: unset consul token on job register
2 parents 76e1785 + b5b5e50 commit 0a93ddd

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

nomad/job_endpoint.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ func (j *Job) Register(args *structs.JobRegisterRequest, reply *structs.JobRegis
256256
// Clear the Vault token
257257
args.Job.VaultToken = ""
258258

259+
// Clear the Consul token
260+
args.Job.ConsulToken = ""
261+
259262
// Check if the job has changed at all
260263
if existingJob == nil || existingJob.SpecChanged(args.Job) {
261264
// Set the submit time

nomad/job_endpoint_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,15 @@ func TestJobEndpoint_Register_Connect_AllowUnauthenticatedFalse(t *testing.T) {
317317
}
318318
}
319319

320+
noTokenOnJob := func(t *testing.T) {
321+
fsmState := s1.State()
322+
ws := memdb.NewWatchSet()
323+
storedJob, err := fsmState.JobByID(ws, job.Namespace, job.ID)
324+
require.NoError(t, err)
325+
require.NotNil(t, storedJob)
326+
require.Empty(t, storedJob.ConsulToken)
327+
}
328+
320329
// Each variation of the provided Consul operator token
321330
noOpToken := ""
322331
unrecognizedOpToken := uuid.Generate()
@@ -353,6 +362,7 @@ func TestJobEndpoint_Register_Connect_AllowUnauthenticatedFalse(t *testing.T) {
353362
var response structs.JobRegisterResponse
354363
err := msgpackrpc.CallWithCodec(codec, "Job.Register", request, &response)
355364
require.NoError(t, err)
365+
noTokenOnJob(t)
356366
})
357367
}
358368

0 commit comments

Comments
 (0)