Skip to content

feat(proxyd): add external authentication support and refactor auth handling #228

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

Draft
wants to merge 33 commits into
base: main
Choose a base branch
from

Conversation

aayushijain21
Copy link

@aayushijain21 aayushijain21 commented Mar 13, 2025

Description
Implement authentication for RPC endpoints through authentication callback in proxyd. Proxyd will make an outgoing call to an auxiliary service for authentication instead of relying on hardcoded/environment values provided in the configuration file.

  • Adds performAuthCallback function
  • Adds AuthCallbackRequest struct
  • Modifies populateContext to use performAuthCallback when flagged
  • Updates authentication configuration in Start function in proxyd.go to check if if auth_url is specified in the authentication map. If it is, use it to set authURL and pass it into the NewServer object.

Tests

Please describe any tests you've added. If you've added no tests, or left important behavior untested, please explain why not.

Additional context

Add any other context about the problem you're solving.

Metadata

  • Fixes #[Link to Issue]

@aayushijain21 aayushijain21 requested a review from a team as a code owner March 13, 2025 20:09
@aayushijain21 aayushijain21 requested a review from sigma March 13, 2025 20:09
@aayushijain21 aayushijain21 marked this pull request as draft March 13, 2025 20:09
Aayushi Jain and others added 20 commits March 13, 2025 13:19
…ging and add helper function to retrieve map keys
…ctions, fix error handling in performAuthCallback for failed auth
proxyd/server.go Outdated
Comment on lines 623 to 624
s.srvMu.Lock()
defer s.srvMu.Unlock()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you need this mutex here? what concurrent access is there in this function?

proxyd/server.go Outdated
Comment on lines 663 to 673
func (s *Server) performAuthCallback(r *http.Request, apiKey string, authURL string) (string, error) {
authReqBody := map[string]string{
"id": apiKey,
}

// Marshal the auth request to JSON
jsonBody, err := json.Marshal(authReqBody)
if err != nil {
log.Error("performAuthCallback failed to marshal request", "err", err)
return "", fmt.Errorf("failed to marshal auth request: %w", err)
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too implementation specific, just forward the request as-is to the auth_url

proxyd/server.go Outdated
Comment on lines 705 to 725
// Read response body for logging
body, err := io.ReadAll(resp.Body)
if err != nil {
log.Error("performAuthCallback failed to read response body", "err", err)
return "", fmt.Errorf("failed to read auth response: %w", err)
}

// Parse response to check authenticated status
var authResponse struct {
Authenticated bool `json:"authenticated"`
}
if err := json.Unmarshal(body, &authResponse); err != nil {
log.Error("performAuthCallback failed to decode response",
"err", err)
return "", fmt.Errorf("failed to decode auth response: %w", err)
}

if !authResponse.Authenticated {
log.Error("performAuthCallback authentication failed")
return "", fmt.Errorf("authentication failed")
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont think this logic is necessary, just reject if response is 401 otherwise fail open

proxyd/server.go Outdated
req.Header = r.Header

// Make the request
client := &http.Client{Timeout: 5 * time.Second}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can store a http client instead of creating a new one each time

proxyd/server.go Outdated
}

// Copy original headers
req.Header = r.Header

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be able to use Clone() instead here

proxyd/server.go Outdated
log.Error("performAuthCallback failed to read request body", "err", err)
return "", fmt.Errorf("failed to read request body: %w", err)
}
r.Body.Close()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defer r.Body.Close()

Copy link

@chunter-cb chunter-cb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some comments. Not as familiar in depth with proxyd so will wait for optimisim team to accept

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants