fix(grpc/session-server): authorise to token introspection endpoint#263
fix(grpc/session-server): authorise to token introspection endpoint#263alienvspredator merged 3 commits intomainfrom
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughThe pull request refactors server construction by moving credentials building before gRPC session server instantiation and extracting session server options into a dedicated file. The Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
internal/grpc/session.go (2)
235-241: Consider reusing HTTP clients for connection pooling.A new
http.Clientis created for each introspection call (after cache miss). While functionally correct, this prevents connection reuse and pooling. For high-throughput scenarios, consider caching HTTP clients per clientID.This is a minor optimization and may not be necessary depending on expected load.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/grpc/session.go` around lines 235 - 241, The code creates a new http.Client for each introspection provider by calling s.httpClient(oidcTrust) before oidc.NewProvider, which prevents connection pooling; modify s.httpClient (or add a new method) to cache and return an *http.Client per client identifier (e.g., oidcTrust.ClientID) using a protected map (sync.Mutex or sync.RWMutex) stored on the session object so subsequent calls to oidc.NewProvider reuse the same client; update callers (where s.httpClient is invoked) to pass the clientID or let s.httpClient derive it from oidcTrust so connection reuse and pooling are achieved.
212-217: Add timeout to HTTP client for introspection requests.The
http.Clientis created without explicitTimeoutconfiguration. While the introspection call uses context-based timeouts (line 249:provider.IntrospectToken(ctx, token)), adding an HTTP client timeout provides an additional safety net against slow or unresponsive OIDC introspection endpoints, preventing potential resource exhaustion.♻️ Proposed fix
func (s *SessionServer) httpClient(mapping *trust.OIDCMapping) *http.Client { creds := s.newCreds(s.getClientID(mapping)) return &http.Client{ Transport: creds.Transport(), + Timeout: 30 * time.Second, } }Note: An identical
httpClientmethod exists ininternal/session/manager.go(lines 611-615) and should receive the same treatment.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/grpc/session.go` around lines 212 - 217, The http.Client returned by SessionServer.httpClient lacks a Timeout and should set a sensible timeout to guard OIDC introspection calls; update the SessionServer.httpClient (which uses newCreds(s.getClientID(mapping)) and is used around provider.IntrospectToken(ctx, token)) to return &http.Client{Transport: creds.Transport(), Timeout: <reasonable duration>} and apply the same change to the duplicate httpClient in internal/session/manager.go so both places have an explicit timeout value (use a constant or config-driven duration rather than a magic literal).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@internal/grpc/session.go`:
- Around line 235-241: The code creates a new http.Client for each introspection
provider by calling s.httpClient(oidcTrust) before oidc.NewProvider, which
prevents connection pooling; modify s.httpClient (or add a new method) to cache
and return an *http.Client per client identifier (e.g., oidcTrust.ClientID)
using a protected map (sync.Mutex or sync.RWMutex) stored on the session object
so subsequent calls to oidc.NewProvider reuse the same client; update callers
(where s.httpClient is invoked) to pass the clientID or let s.httpClient derive
it from oidcTrust so connection reuse and pooling are achieved.
- Around line 212-217: The http.Client returned by SessionServer.httpClient
lacks a Timeout and should set a sensible timeout to guard OIDC introspection
calls; update the SessionServer.httpClient (which uses
newCreds(s.getClientID(mapping)) and is used around
provider.IntrospectToken(ctx, token)) to return &http.Client{Transport:
creds.Transport(), Timeout: <reasonable duration>} and apply the same change to
the duplicate httpClient in internal/session/manager.go so both places have an
explicit timeout value (use a constant or config-driven duration rather than a
magic literal).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 565c0133-40c7-4424-a9f0-1366555a6a4a
📒 Files selected for processing (9)
internal/business/business.gointernal/business/server/grpc_server_test.gointernal/credentials/credentials.gointernal/grpc/options.gointernal/grpc/session.gointernal/grpc/session_test.gointernal/session/manager.gointernal/session/manager_test.gointernal/session/options.go
5e93bc7 to
239b97e
Compare
239b97e to
ae8531a
Compare
ae8531a to
74e28e4
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/business/business.go (1)
100-103: Consider a more accurate error message.The error message says "failed to load http client" but this code builds transport credentials, not an HTTP client. A more precise message like
"failed to build transport credentials: %w"would better describe the actual failure point and aid debugging.This same message is used at line 134 in
initSessionManager, so both could be updated for consistency.Suggested improvement
credsBuilder, err := newCredsBuilder(cfg) if err != nil { - return fmt.Errorf("failed to load http client: %w", err) + return fmt.Errorf("failed to build transport credentials: %w", err) }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/business/business.go` around lines 100 - 103, Update the error messages to accurately reflect the failure to build transport credentials: replace the generic "failed to load http client" with "failed to build transport credentials: %w" in the block where newCredsBuilder(cfg) is called (symbol: newCredsBuilder) and make the same change in initSessionManager where the identical message is used so both locations consistently report failures constructing transport credentials.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@internal/business/business.go`:
- Around line 100-103: Update the error messages to accurately reflect the
failure to build transport credentials: replace the generic "failed to load http
client" with "failed to build transport credentials: %w" in the block where
newCredsBuilder(cfg) is called (symbol: newCredsBuilder) and make the same
change in initSessionManager where the identical message is used so both
locations consistently report failures constructing transport credentials.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 8039748e-1f5f-47f1-a419-28bc8e7eaca4
📒 Files selected for processing (11)
integration/grpc_test.gointegration/session_grpc_test.gointernal/business/business.gointernal/business/server/grpc_server_test.gointernal/credentials/credentials.gointernal/grpc/options.gointernal/grpc/session.gointernal/grpc/session_test.gointernal/session/manager.gointernal/session/manager_test.gointernal/session/options.go
✅ Files skipped from review due to trivial changes (1)
- internal/grpc/session_test.go
🚧 Files skipped from review as they are similar to previous changes (8)
- internal/credentials/credentials.go
- internal/session/options.go
- integration/session_grpc_test.go
- internal/business/server/grpc_server_test.go
- internal/session/manager.go
- internal/grpc/options.go
- internal/session/manager_test.go
- internal/grpc/session.go
fix(grpc/session-server): call token introspection endpoint with authorisation
Summary by CodeRabbit
Release Notes
Bug Fixes
Improvements