Skip to content

Commit

Permalink
rbac: add method name to :path in headers (#7965)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfawley authored Dec 24, 2024
1 parent e912015 commit e8d5feb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/xds/rbac/rbac_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ func newRPCData(ctx context.Context) (*rpcData, error) {
if !ok {
return nil, errors.New("missing method in incoming context")
}
// gRPC-Go strips :path from the headers given to the application, but RBAC should be
// able to match against it.
md[":path"] = []string{mn}

// The connection is needed in order to find the destination address and
// port of the incoming RPC Call.
Expand Down
24 changes: 24 additions & 0 deletions test/xds/xds_server_rbac_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,30 @@ func (s) TestRBACHTTPFilter(t *testing.T) {
wantStatusEmptyCall: codes.PermissionDenied,
wantStatusUnaryCall: codes.OK,
},
// This test tests an RBAC HTTP Filter which is configured to allow only
// RPC's with certain paths ("UnaryCall") via the ":path" header. Only
// unary calls passing through this RBAC HTTP Filter should proceed as
// normal, and any others should be denied.
{
name: "allow-certain-path-by-header",
rbacCfg: &rpb.RBAC{
Rules: &v3rbacpb.RBAC{
Action: v3rbacpb.RBAC_ALLOW,
Policies: map[string]*v3rbacpb.Policy{
"certain-path": {
Permissions: []*v3rbacpb.Permission{
{Rule: &v3rbacpb.Permission_Header{Header: &v3routepb.HeaderMatcher{Name: ":path", HeaderMatchSpecifier: &v3routepb.HeaderMatcher_ExactMatch{ExactMatch: "/grpc.testing.TestService/UnaryCall"}}}},
},
Principals: []*v3rbacpb.Principal{
{Identifier: &v3rbacpb.Principal_Any{Any: true}},
},
},
},
},
},
wantStatusEmptyCall: codes.PermissionDenied,
wantStatusUnaryCall: codes.OK,
},
// This test that a RBAC Config with nil rules means that every RPC is
// allowed. This maps to the line "If absent, no enforcing RBAC policy
// will be applied" from the RBAC Proto documentation for the Rules
Expand Down

0 comments on commit e8d5feb

Please sign in to comment.