Merge pull request #6391 from hashicorp/b-ns-job-register-check
nomad: defensive check for namespaces in job registration call
This commit is contained in:
commit
4a93081275
|
@ -905,6 +905,7 @@ func TestFS_Logs_TaskPending(t *testing.T) {
|
||||||
args := &structs.JobRegisterRequest{}
|
args := &structs.JobRegisterRequest{}
|
||||||
args.Job = job
|
args.Job = job
|
||||||
args.WriteRequest.Region = "global"
|
args.WriteRequest.Region = "global"
|
||||||
|
args.Namespace = job.Namespace
|
||||||
var jobResp structs.JobRegisterResponse
|
var jobResp structs.JobRegisterResponse
|
||||||
require.NoError(s.RPC("Job.Register", args, &jobResp))
|
require.NoError(s.RPC("Job.Register", args, &jobResp))
|
||||||
|
|
||||||
|
|
|
@ -88,6 +88,11 @@ func (j *Job) Register(args *structs.JobRegisterRequest, reply *structs.JobRegis
|
||||||
return fmt.Errorf("missing job for registration")
|
return fmt.Errorf("missing job for registration")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// defensive check; http layer and RPC requester should ensure namespaces are set consistently
|
||||||
|
if args.RequestNamespace() != args.Job.Namespace {
|
||||||
|
return fmt.Errorf("mismatched request namespace in request: %q, %q", args.RequestNamespace(), args.Job.Namespace)
|
||||||
|
}
|
||||||
|
|
||||||
// Run admission controllers
|
// Run admission controllers
|
||||||
job, warnings, err := j.admissionControllers(args.Job)
|
job, warnings, err := j.admissionControllers(args.Job)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -343,6 +348,11 @@ func (j *Job) Summary(args *structs.JobSummaryRequest,
|
||||||
func (j *Job) Validate(args *structs.JobValidateRequest, reply *structs.JobValidateResponse) error {
|
func (j *Job) Validate(args *structs.JobValidateRequest, reply *structs.JobValidateResponse) error {
|
||||||
defer metrics.MeasureSince([]string{"nomad", "job", "validate"}, time.Now())
|
defer metrics.MeasureSince([]string{"nomad", "job", "validate"}, time.Now())
|
||||||
|
|
||||||
|
// defensive check; http layer and RPC requester should ensure namespaces are set consistently
|
||||||
|
if args.RequestNamespace() != args.Job.Namespace {
|
||||||
|
return fmt.Errorf("mismatched request namespace in request: %q, %q", args.RequestNamespace(), args.Job.Namespace)
|
||||||
|
}
|
||||||
|
|
||||||
job, mutateWarnings, err := j.admissionMutators(args.Job)
|
job, mutateWarnings, err := j.admissionMutators(args.Job)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -364,7 +364,10 @@ func TestJobEndpoint_Register_ACL(t *testing.T) {
|
||||||
codec := rpcClient(t, s1)
|
codec := rpcClient(t, s1)
|
||||||
req := &structs.JobRegisterRequest{
|
req := &structs.JobRegisterRequest{
|
||||||
Job: tt.Job,
|
Job: tt.Job,
|
||||||
WriteRequest: structs.WriteRequest{Region: "global"},
|
WriteRequest: structs.WriteRequest{
|
||||||
|
Region: "global",
|
||||||
|
Namespace: tt.Job.Namespace,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
req.AuthToken = tt.Token
|
req.AuthToken = tt.Token
|
||||||
|
|
||||||
|
@ -408,7 +411,10 @@ func TestJobEndpoint_Register_InvalidNamespace(t *testing.T) {
|
||||||
job.Namespace = "foo"
|
job.Namespace = "foo"
|
||||||
req := &structs.JobRegisterRequest{
|
req := &structs.JobRegisterRequest{
|
||||||
Job: job,
|
Job: job,
|
||||||
WriteRequest: structs.WriteRequest{Region: "global"},
|
WriteRequest: structs.WriteRequest{
|
||||||
|
Region: "global",
|
||||||
|
Namespace: job.Namespace,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try without a token, expect failure
|
// Try without a token, expect failure
|
||||||
|
|
Loading…
Reference in New Issue