Skip to content
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

fix: remote authorizers #1185

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions pipeline/authz/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func (a *AuthorizerRemote) GetID() string {
func (a *AuthorizerRemote) Authorize(r *http.Request, session *authn.AuthenticationSession, config json.RawMessage, rl pipeline.Rule) (err error) {
ctx, span := a.tracer.Start(r.Context(), "pipeline.authz.AuthorizerRemote.Authorize")
defer otelx.End(span, &err)
r = r.WithContext(ctx)

c, err := a.Config(config)
if err != nil {
Expand All @@ -80,7 +79,7 @@ func (a *AuthorizerRemote) Authorize(r *http.Request, session *authn.Authenticat
write.CloseWithError(errors.Wrapf(err, `could not pipe request body in rule "%s"`, rl.GetID()))
}()

req, err := http.NewRequest("POST", c.Remote, read)
req, err := http.NewRequestWithContext(ctx, "POST", c.Remote, read)
if err != nil {
return errors.WithStack(err)
}
Expand Down Expand Up @@ -116,7 +115,7 @@ func (a *AuthorizerRemote) Authorize(r *http.Request, session *authn.Authenticat
req.Header.Set(hdr, headerValue.String())
}

res, err := a.client.Do(req.WithContext(r.Context()))
res, err := a.client.Do(req)

if err != nil {
return errors.WithStack(err)
Expand Down
5 changes: 5 additions & 0 deletions pipeline/authz/remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ func TestAuthorizerRemoteAuthorize(t *testing.T) {
if err := a.Authorize(r, tt.session, tt.config, &rule.Rule{}); (err != nil) != tt.wantErr {
t.Errorf("Authorize() error = %v, wantErr %v", err, tt.wantErr)
}
if tt.body != "" {
body, err := io.ReadAll(r.Body)
require.NoError(t, err)
require.Equal(t, tt.body, string(body), "body must stay intact")
}

if tt.sessionHeaderMatch != nil {
assert.Equal(t, tt.sessionHeaderMatch, &tt.session.Header)
Expand Down
Loading