Skip to content

Commit

Permalink
extend semgrep rule to ensure error is handled
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross committed Jan 6, 2023
1 parent cfc05e1 commit b21ebf8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
6 changes: 5 additions & 1 deletion .semgrep/rpc_endpoint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ rules:
# TODO: add authorization steps as well.
- pattern-not-inside: |
...
... := $A.$B.Authenticate($A.ctx, args)
authErr := $A.$B.Authenticate($A.ctx, args)
...
if authErr != nil {
return authErr
}
...
- metavariable-pattern:
metavariable: $METHOD
Expand Down
6 changes: 3 additions & 3 deletions nomad/acl_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -1997,9 +1997,9 @@ func (a *ACL) GetAuthMethods(
// once other Workload Identity work is solidified
func (a *ACL) WhoAmI(args *structs.GenericRequest, reply *structs.ACLWhoAmIResponse) error {

err := a.srv.Authenticate(a.ctx, args)
if err != nil {
return err
authErr := a.srv.Authenticate(a.ctx, args)
if authErr != nil {
return authErr
}

if done, err := a.srv.forward("ACL.WhoAmI", args, args, reply); done {
Expand Down
8 changes: 4 additions & 4 deletions nomad/eval_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ func (e *Eval) GetEval(args *structs.EvalSpecificRequest,
func (e *Eval) Dequeue(args *structs.EvalDequeueRequest,
reply *structs.EvalDequeueResponse) error {

err := e.srv.Authenticate(e.ctx, args)
if err != nil {
return err
authErr := e.srv.Authenticate(e.ctx, args)
if authErr != nil {
return authErr
}

// Ensure the connection was initiated by another server if TLS is used.
err = validateTLSCertificateLevel(e.srv, e.ctx, tlsCertificateLevelServer)
err := validateTLSCertificateLevel(e.srv, e.ctx, tlsCertificateLevelServer)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions nomad/variables_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (sv *Variables) Apply(args *structs.VariablesApplyRequest, reply *structs.V
return err
}
if authErr != nil {
return structs.ErrPermissionDenied
return authErr
}

defer metrics.MeasureSince([]string{
Expand Down Expand Up @@ -230,7 +230,7 @@ func (sv *Variables) Read(args *structs.VariablesReadRequest, reply *structs.Var
return err
}
if authErr != nil {
return structs.ErrPermissionDenied
return authErr
}

defer metrics.MeasureSince([]string{"nomad", "variables", "read"}, time.Now())
Expand Down Expand Up @@ -280,7 +280,7 @@ func (sv *Variables) List(
return err
}
if authErr != nil {
return structs.ErrPermissionDenied
return authErr
}

defer metrics.MeasureSince([]string{"nomad", "variables", "list"}, time.Now())
Expand Down

0 comments on commit b21ebf8

Please sign in to comment.