Skip to content

Commit 6f76801

Browse files
committed
Add comments.
Signed-off-by: xuezhaojun <zxue@redhat.com>
1 parent a5ce47e commit 6f76801

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

pkg/server/grpc/authn/interface.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,20 @@ const (
1111
ContextGroupsKey contextKey = "groups"
1212
)
1313

14-
// Authenticator is the interface to authenticate for grpc server
14+
// Authenticator defines the interface for authenticating gRPC requests.
15+
// Implementations should validate user credentials and return an enriched context
16+
// containing user identity information for downstream processing.
1517
type Authenticator interface {
18+
// Authenticate validates the incoming request context and returns an enriched context
19+
// containing user identity information (user and groups) or an error if authentication fails.
20+
// The returned context should include user identity using newContextWithIdentity function.
1621
Authenticate(ctx context.Context) (context.Context, error)
1722
}
1823

24+
// newContextWithIdentity creates a new context with user identity information.
25+
// It adds the user name and groups to the context using predefined context keys.
26+
// This function is typically used by Authenticator implementations to enrich
27+
// the context with authenticated user information.
1928
func newContextWithIdentity(ctx context.Context, user string, groups []string) context.Context {
2029
ctx = context.WithValue(ctx, ContextUserKey, user)
2130
return context.WithValue(ctx, ContextGroupsKey, groups)

pkg/server/grpc/authz/interface.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,23 @@ import (
66
"google.golang.org/grpc"
77
)
88

9+
// UnaryAuthorizer defines the interface for authorizing unary gRPC requests.
10+
// Implementations should validate whether the authenticated user has permission
11+
// to perform the requested operation based on the context and request.
912
type UnaryAuthorizer interface {
13+
// AuthorizeRequest validates whether the user in the context is authorized
14+
// to perform the operation represented by the request. Returns an error
15+
// if authorization fails, or nil if the request is authorized.
1016
AuthorizeRequest(ctx context.Context, req any) error
1117
}
1218

19+
// StreamAuthorizer defines the interface for authorizing streaming gRPC requests.
20+
// Implementations should validate whether the authenticated user has permission
21+
// to establish and maintain the streaming connection.
1322
type StreamAuthorizer interface {
23+
// AuthorizeStream validates whether the user in the context is authorized
24+
// to establish the streaming connection. Returns a potentially wrapped ServerStream
25+
// and an error if authorization fails, or the original/wrapped stream and nil if authorized.
26+
// The returned ServerStream can be used to intercept and authorize individual messages.
1427
AuthorizeStream(ctx context.Context, ss grpc.ServerStream, info *grpc.StreamServerInfo) (grpc.ServerStream, error)
1528
}

0 commit comments

Comments
 (0)