Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auth: use ACLsDisabledACL when ACLs are disabled #18754

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 25 additions & 54 deletions .semgrep/rpc_endpoint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
# SPDX-License-Identifier: BUSL-1.1

rules:
# Check potentially unauthenticated RPC endpoints. Technically more
# authorization (authz) oriented than authn, but before Nomad 1.4/1.5 that
# distinction wasn't as important.
# Check potentially RPC endpoints with missing authentication/authorization.
- id: "rpc-potentially-unauthenticated"
patterns:
- pattern: |
Expand Down Expand Up @@ -40,7 +38,6 @@ rules:
}
...


# Pattern used by endpoints that are used only for client-to-server.
# Authorization can be done after forwarding, but must check the
# AllowClientOp policy
Expand All @@ -56,7 +53,6 @@ rules:
}
...


# Pattern used by endpoints that are used only for client-to-server.
# Authorization can be done after forwarding, but must check the
# AllowClientOp policy. This should not be added to any new endpoints.
Expand All @@ -72,7 +68,8 @@ rules:
}
...

# Pattern used by ACL endpoints that need to interact with the token directly
# Pattern used by ACL endpoints that need to interact with the token
# directly.
- pattern-not-inside: |
authErr := $A.$B.Authenticate($A.ctx, args)
...
Expand All @@ -82,52 +79,7 @@ rules:
...
... := args.GetIdentity().GetACLToken()
...
# Pattern used by endpoints called exclusively between agents
# (server -> server or client -> server)
- pattern-not-inside: |
authErr := $A.$B.Authenticate($A.ctx, args)
...
... := validateTLSCertificateLevel(...)
...
if done, err := $A.$B.forward($METHOD, ...); done {
return err
}
# Pattern used by endpoints that support both normal ACLs and workload
# identity but break authentication and authorization up
# TODO: currently this is just for Variables and should be removed once
# https://github.com/hashicorp/nomad/issues/15875 is complete.
- pattern-not-inside: |
authErr := $A.$B.Authenticate($A.ctx, args)
...
if done, err := $A.$B.forward($METHOD, ...); done {
return err
}
...
... := $T.handleMixedAuthEndpoint(...)
...
# Second pattern used by endpoints that support both normal ACLs and
# workload identity but break authentication and authorization up
# TODO: currently this is just for Variables and should be removed once
# https://github.com/hashicorp/nomad/issues/15875 is complete.
- pattern-not-inside: |
authErr := $A.$B.Authenticate($A.ctx, args)
...
if done, err := $A.$B.forward($METHOD, ...); done {
return err
}
...
... := svePreApply($A, args, args.Var)
...
# Pattern used by some Node endpoints.
- pattern-not-inside: |
authErr := $A.$B.Authenticate($A.ctx, args)
...
if done, err := $A.$B.forward($METHOD, ...); done {
return err
}
...
return $A.deregister(...)
...

- metavariable-pattern:
metavariable: $METHOD
patterns:
Expand All @@ -142,8 +94,6 @@ rules:
- pattern-not: 'structs.ACLOIDCAuthURLRPCMethod'
- pattern-not: 'structs.ACLOIDCCompleteAuthRPCMethod'
- pattern-not: 'structs.ACLLoginRPCMethod'
- pattern-not: '"CSIPlugin.Get"'
- pattern-not: '"CSIPlugin.List"'
- pattern-not: '"Status.Leader"'
- pattern-not: '"Status.Peers"'
- pattern-not: '"Status.Version"'
Expand All @@ -155,3 +105,24 @@ rules:
paths:
include:
- "nomad/*_endpoint.go"


# ACL objects should never be nil-checked in RPC handlers before checking
# authorization, as nil ACLs are always programmer errors.
- id: "rpc-authz-bypass"
patterns:
# Pattern that will accidentally bypass authorization checks.
- pattern: |
...
if aclObj != nil && aclObj.$ACL_CHECK(...) {
...
}
...

message: "RPC method ACL check $ACL_CHECK appears to bypass authorization by first checking for nil ACLs"
languages:
- "go"
severity: "WARNING"
paths:
include:
- "nomad/*_endpoint.go"
Loading