Skip to content

Commit

Permalink
fix: remote authorizers with request body (#1185)
Browse files Browse the repository at this point in the history
  • Loading branch information
alnr authored Sep 11, 2024
1 parent ba39541 commit 62ca1e8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
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

0 comments on commit 62ca1e8

Please sign in to comment.