mirror of
https://github.com/kemko/nomad.git
synced 2026-01-05 18:05:42 +03:00
job endpoint: reorder check for disabled job registrations (#18523)
When job registrations are disabled, there's no reason to do the potentially expensive job mutation and admission hooks. Move the ACL resolution and this check before those hooks.
This commit is contained in:
@@ -102,6 +102,15 @@ func (j *Job) Register(args *structs.JobRegisterRequest, reply *structs.JobRegis
|
||||
}
|
||||
defer metrics.MeasureSince([]string{"nomad", "job", "register"}, time.Now())
|
||||
|
||||
aclObj, err := j.srv.ResolveACL(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if ok, err := registrationsAreAllowed(aclObj, j.srv.State()); !ok || err != nil {
|
||||
j.logger.Warn("job registration is currently disabled for non-management ACL")
|
||||
return structs.ErrJobRegistrationDisabled
|
||||
}
|
||||
|
||||
// Validate the arguments
|
||||
if args.Job == nil {
|
||||
return fmt.Errorf("missing job for registration")
|
||||
@@ -136,10 +145,7 @@ func (j *Job) Register(args *structs.JobRegisterRequest, reply *structs.JobRegis
|
||||
reply.Warnings = helper.MergeMultierrorWarnings(warnings...)
|
||||
|
||||
// Check job submission permissions
|
||||
aclObj, err := j.srv.ResolveACL(args)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if aclObj != nil {
|
||||
if aclObj != nil {
|
||||
if !aclObj.AllowNsOp(args.RequestNamespace(), acl.NamespaceCapabilitySubmitJob) {
|
||||
return structs.ErrPermissionDenied
|
||||
}
|
||||
@@ -198,11 +204,6 @@ func (j *Job) Register(args *structs.JobRegisterRequest, reply *structs.JobRegis
|
||||
}
|
||||
}
|
||||
|
||||
if ok, err := registrationsAreAllowed(aclObj, j.srv.State()); !ok || err != nil {
|
||||
j.logger.Warn("job registration is currently disabled for non-management ACL")
|
||||
return structs.ErrJobRegistrationDisabled
|
||||
}
|
||||
|
||||
// Lookup the job
|
||||
snap, err := j.srv.State().Snapshot()
|
||||
if err != nil {
|
||||
|
||||
@@ -2416,7 +2416,7 @@ func TestJobRegister_ACL_RejectedBySchedulerConfig(t *testing.T) {
|
||||
name: "reject enabled, without a token",
|
||||
token: "",
|
||||
rejectEnabled: true,
|
||||
errExpected: structs.ErrPermissionDenied.Error(),
|
||||
errExpected: structs.ErrJobRegistrationDisabled.Error(),
|
||||
},
|
||||
{
|
||||
name: "reject enabled, with a management token",
|
||||
|
||||
Reference in New Issue
Block a user