Skip to content

ext-authz: fix missing UAEX flag on Denied CheckResponse#18965

Merged
yanavlasov merged 2 commits intoenvoyproxy:mainfrom
pims:pims/fix-extauthz-uaex-flag
Nov 30, 2021
Merged

ext-authz: fix missing UAEX flag on Denied CheckResponse#18965
yanavlasov merged 2 commits intoenvoyproxy:mainfrom
pims:pims/fix-extauthz-uaex-flag

Conversation

@pims
Copy link
Copy Markdown
Contributor

@pims pims commented Nov 10, 2021

This fixes a bug in which the UAEX flag is not set prior to calling
callback->sendLocalReply(...).

Commit Message: ext-authz: fix missing UAEX flag on Denied CheckResponse
Additional Description: See #18964
Risk Level: low
Testing: manual
Docs Changes: n/a
Release Notes: ext-authz: fix missing UAEX flag on Denied CheckResponse

Fixes #18964

@pims pims requested a review from dio as a code owner November 10, 2021 18:36
@repokitteh-read-only
Copy link
Copy Markdown

Hi @pims, welcome and thank you for your contribution.

We will try to review your Pull Request as quickly as possible.

In the meantime, please take a look at the contribution guidelines if you have not done so already.

🐱

Caused by: #18965 was opened by pims.

see: more, trace.

@yanavlasov
Copy link
Copy Markdown
Contributor

@pims thanks for fixing this. Can you also add a test case for the fixed problem, please?

@pims
Copy link
Copy Markdown
Contributor Author

pims commented Nov 12, 2021

@yanavlasov thanks for taking a look at this PR.

I've updated the tests to reflect the new call sequence.
To expand a little bit on why this PR exists.

Original code

decoder_callbacks_->sendLocalReply(response->status_code, …);
decoder_callbacks_->streamInfo().setResponseFlag(
        StreamInfo::ResponseFlag::UnauthorizedExternalService);

My understanding is that the code intends to set the UnauthorizedExternalService response flag, but that flag is never visible in Access Logs.

After re-ordering the calls, the unit tests were failing.
In order to understand why, I looked at the fault filter for inspiration/confirmation that the expected behavior is:

// source/extensions/filters/http/fault/fault_filter.cc

decoder_callbacks_->streamInfo().setResponseFlag(StreamInfo::ResponseFlag::FaultInjected);
decoder_callbacks_->sendLocalReply(http_status_code, "fault filter abort", …);

// test/extensions/filters/http/fault/fault_filter_test.cc
EXPECT_CALL(decoder_filter_callbacks_.stream_info_,
            setResponseFlag(StreamInfo::ResponseFlag::DelayInjected));
EXPECT_EQ(Http::FilterHeadersStatus::StopIteration,
            filter_->decodeHeaders(request_headers_, false));

Following the above pattern, tests are now passing.

EXPECT_CALL(filter_callbacks_.stream_info_,
            setResponseFlag(Envoy::StreamInfo::ResponseFlag::UnauthorizedExternalService));
EXPECT_EQ(Http::FilterHeadersStatus::StopAllIterationAndWatermark,
            filter_->decodeHeaders(request_headers_, false));

I'm very new to the Envoy code base, so please let me know if my assumptions aren't correct.
Thanks again for reviewing this PR.

This fixes a bug in which the UAEX flag is not set prior to calling
`callback->sendLocalReply(...)`.

Signed-off-by: Tim Bart <tbart@cloudflare.com>
@pims pims force-pushed the pims/fix-extauthz-uaex-flag branch from 85818f2 to cab2f0b Compare November 15, 2021 23:36
@pims
Copy link
Copy Markdown
Contributor Author

pims commented Nov 15, 2021

@pims
Copy link
Copy Markdown
Contributor Author

pims commented Nov 22, 2021

@dio @soulxu let me know if there’s anything I can do to make this PR worthy of merging.

dio
dio previously approved these changes Nov 22, 2021
Copy link
Copy Markdown
Member

@dio dio left a comment

Choose a reason for hiding this comment

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

Looks good. Thank you. A small optional request:

And could you add an entry in release notes that we fixed the bug?

config_->httpContext().codeStats().chargeResponseStat(info, false);
}

decoder_callbacks_->streamInfo().setResponseFlag(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This makes sense.

Optional: Mind to add a comment for future readers, that is why we set it prior to calling sendLocalReply.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

also can put setResponseFlag and sendLocalReply into a inline method, but currently this is enough for me.

soulxu
soulxu previously approved these changes Nov 23, 2021
Copy link
Copy Markdown
Member

@soulxu soulxu left a comment

Choose a reason for hiding this comment

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

This is LGTM. Thanks you. and sorry for review late.

config_->httpContext().codeStats().chargeResponseStat(info, false);
}

decoder_callbacks_->streamInfo().setResponseFlag(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

also can put setResponseFlag and sendLocalReply into a inline method, but currently this is enough for me.

Signed-off-by: Tim Bart <tbart@cloudflare.com>
@pims pims dismissed stale reviews from soulxu and dio via 0decbc4 November 24, 2021 03:53
@pims
Copy link
Copy Markdown
Contributor Author

pims commented Nov 24, 2021

@dio added a note to the release notes about this bug fix, following the format you used for the network filter bug fix.

@soulxu thanks for the review.

Copy link
Copy Markdown
Member

@soulxu soulxu left a comment

Choose a reason for hiding this comment

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

still LGTM

@pims
Copy link
Copy Markdown
Contributor Author

pims commented Nov 29, 2021

@dio gentle nudge. Anything else you think should be added to this PR for it to be merged?

I have found a similar bug in another filter, and was hoping to follow this PR’s template when submitting a bug fix.

Copy link
Copy Markdown
Member

@dio dio left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks!

@yanavlasov yanavlasov merged commit 3001370 into envoyproxy:main Nov 30, 2021
mpuncel added a commit to mpuncel/envoy that referenced this pull request Nov 30, 2021
* main:
  Stats: Filter stats to be flushed to sinks (envoyproxy#18805)
  build(deps): bump sphinx from 4.3.0 to 4.3.1 in /tools/base (envoyproxy#19122)
  ext-authz: fix missing UAEX flag on Denied CheckResponse (envoyproxy#18965)
  lua: support body setBytes with header content length set automatically (envoyproxy#18989)

Signed-off-by: Michael Puncel <mpuncel@squareup.com>
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.

Bug: Missing Access Log UAEX flag for ext-authz denied requests

4 participants