-
Notifications
You must be signed in to change notification settings - Fork 60
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
base: main
Are you sure you want to change the base?
Conversation
…ontext value assignment
… log level to debug
…nts for request handling
…nd authentication callback
…ing for auth_url resolution
…ging and add helper function to retrieve map keys
… server creation and context population
…ctions, fix error handling in performAuthCallback for failed auth
proxyd/server.go
Outdated
s.srvMu.Lock() | ||
defer s.srvMu.Unlock() |
There was a problem hiding this comment.
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
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) | ||
} |
There was a problem hiding this comment.
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
// 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") | ||
} |
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defer r.Body.Close()
There was a problem hiding this 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
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.
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