-
Notifications
You must be signed in to change notification settings - Fork 5.5k
rbac: add some debug logging. #3744
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,13 +65,30 @@ RoleBasedAccessControlRouteSpecificFilterConfig::RoleBasedAccessControlRouteSpec | |
|
|
||
| Http::FilterHeadersStatus RoleBasedAccessControlFilter::decodeHeaders(Http::HeaderMap& headers, | ||
| bool) { | ||
| ENVOY_LOG( | ||
| debug, | ||
| "checking request:\n" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "checking request" isn't a very descriptive message. Either make a new "rbac" log type, or prefix all of the messages you added with "rbac: " (or something similar).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the suggestion, I added a new "rbac" log type. |
||
| "remoteAddress: {}, localAddress: {}" | ||
| "ssl: {}\n" | ||
| "headers:\n{}\n" | ||
| "dynamicMetadata:\n{}\n", | ||
| callbacks_->connection()->remoteAddress()->asString(), | ||
| callbacks_->connection()->localAddress()->asString(), | ||
| callbacks_->connection()->ssl() | ||
| ? "uriSanPeerCertificate: " + callbacks_->connection()->ssl()->uriSanPeerCertificate() + | ||
| ", subjectPeerCertificate: " + | ||
| callbacks_->connection()->ssl()->subjectPeerCertificate() | ||
| : "none", | ||
| headers, callbacks_->requestInfo().dynamicMetadata().DebugString()); | ||
| const absl::optional<Filters::Common::RBAC::RoleBasedAccessControlEngineImpl>& shadow_engine = | ||
| config_->engine(callbacks_->route(), EnforcementMode::Shadow); | ||
| if (shadow_engine.has_value()) { | ||
| if (shadow_engine->allowed(*callbacks_->connection(), headers, | ||
| callbacks_->requestInfo().dynamicMetadata())) { | ||
| ENVOY_LOG(debug, "shadow allowed"); | ||
| config_->stats().shadow_allowed_.inc(); | ||
| } else { | ||
| ENVOY_LOG(debug, "shadow denied"); | ||
| config_->stats().shadow_denied_.inc(); | ||
| } | ||
| } | ||
|
|
@@ -81,15 +98,18 @@ Http::FilterHeadersStatus RoleBasedAccessControlFilter::decodeHeaders(Http::Head | |
| if (engine.has_value()) { | ||
| if (engine->allowed(*callbacks_->connection(), headers, | ||
| callbacks_->requestInfo().dynamicMetadata())) { | ||
| ENVOY_LOG(debug, "enforced allowed"); | ||
| config_->stats().allowed_.inc(); | ||
| return Http::FilterHeadersStatus::Continue; | ||
| } else { | ||
| ENVOY_LOG(debug, "enforced denied"); | ||
| callbacks_->sendLocalReply(Http::Code::Forbidden, "RBAC: access denied", nullptr); | ||
| config_->stats().denied_.inc(); | ||
| return Http::FilterHeadersStatus::StopIteration; | ||
| } | ||
| } | ||
|
|
||
| ENVOY_LOG(debug, "no engine, allowed by default"); | ||
| return Http::FilterHeadersStatus::Continue; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,11 +46,11 @@ class RoleBasedAccessControlFilterTest : public testing::Test { | |
| filter_.setDecoderFilterCallbacks(callbacks_); | ||
| } | ||
|
|
||
| void setDestinationPort(uint16_t port, int times = 2) { | ||
| void setDestinationPort(uint16_t port, int at_most_times = 3) { | ||
| address_ = Envoy::Network::Utility::parseInternetAddress("1.2.3.4", port, false); | ||
| auto& expect = EXPECT_CALL(connection_, localAddress()); | ||
| if (times > 0) { | ||
| expect.Times(times); | ||
| if (at_most_times > 0) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't a useful expectation. Please just make this an ON_CALL(...).WillByDefault(...)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| expect.Times(testing::AtMost(at_most_times)); | ||
| } | ||
| expect.WillRepeatedly(ReturnRef(address_)); | ||
| } | ||
|
|
||
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.
Debug lines in general should be single line. Please remove the newlines.
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.
Done