Skip to content

Add Rbac Access Denied Policy Info in Access logs #3100

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

Merged
merged 4 commits into from
Nov 18, 2020

Conversation

gargnupur
Copy link
Contributor

What this PR does / why we need it:
Add Rbac Access Denied Policy Info in Access logs

Which issue this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged): fixes #

Special notes for your reviewer:

@gargnupur gargnupur requested a review from a team as a code owner November 13, 2020 22:10
@google-cla google-cla bot added the cla: yes Set by the Google CLA bot to indicate the author of a PR has signed the Google CLA. label Nov 13, 2020
@istio-testing istio-testing added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 13, 2020
Signed-off-by: gargnupur <[email protected]>
Copy link
Contributor

@yangminzhu yangminzhu left a comment

Choose a reason for hiding this comment

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

Looks great! just a small comment, thanks.

// It is of the format:
// "rbac_access_denied_matched_policy[ns[NAMESPACE]-policy[POLICY]-rule[POLICY_INDEX]]"
const RE2 rbac_denied_match(
"rbac_access_denied_matched_policy\\[ns\\[(.*)\\]-policy\\[(.*)\\]-rule\\[("
Copy link
Contributor

Choose a reason for hiding this comment

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

The suffix is istio specific. Should we just look for prefix to support non-Istio RBAC?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

/cc @yangminzhu

We wanted to extract policy name and rule, hence the suffix...
what is the exact scenario you thinking Kuat?

Copy link
Contributor

Choose a reason for hiding this comment

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

Custom RBAC rules with EnvoyFilter. I guess we could have a fallback in case regex does not match, just log the whole thing.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm fine either way, I think we normally don't do anything special to handle customized config from EnvoyFilter but I think it also doesn't harm anything with a fallback here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah we are actually logging the whole thing if regex doesn't match.

!request_info.connection_termination_details.empty()) {
const std::string response_details =
!request_info.response_code_details.empty()
? request_info.response_code_details
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you could re-use the same field for both.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks.. Fixed

@@ -6,7 +6,7 @@
rules:
action: DENY
policies:
"test":
ns[foo]-policy[httpbin-deny]-rule[0]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need an example for network RBAC?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be similar to this one with response to extracting stuff? I can add if needed..

Copy link
Contributor

Choose a reason for hiding this comment

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

Could be done in a follow-up. Just want to make sure we have coverage for network filter as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, will add one

Signed-off-by: gargnupur <[email protected]>
Signed-off-by: gargnupur <[email protected]>
@@ -428,6 +428,11 @@ void populateExtendedHTTPRequestInfo(RequestInfo* request_info) {
getValue({"request", "url_path"}, &request_info->url_path);
getValue({"request", "host"}, &request_info->url_host);
getValue({"request", "scheme"}, &request_info->url_scheme);
std::string response_details;
getValue({"response", "code_details"}, &response_details);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kyessenov : It's not possible for both connection_termination_details and response_code_details to have values right as one is filled for TCP and other for HTTP

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: no need to stack allocate a string I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will fix in the follow-up pr

@istio-testing istio-testing merged commit 9efad2b into istio:master Nov 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Set by the Google CLA bot to indicate the author of a PR has signed the Google CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants