Skip to content

collect metrics for RBAC shadow policy#4062

Merged
mattklein123 merged 6 commits intoenvoyproxy:masterfrom
quanjielin:quanlinmetric2
Aug 7, 2018
Merged

collect metrics for RBAC shadow policy#4062
mattklein123 merged 6 commits intoenvoyproxy:masterfrom
quanjielin:quanlinmetric2

Conversation

@quanjielin
Copy link
Copy Markdown
Contributor

@quanjielin quanjielin commented Aug 6, 2018

Description:
To complete RBAC policy dark launch from envoy side(#3552), shadow policy metrics needs to be collected(shadow response code + effective policyID); so that we could use those metrics to build report/dashboard to monitor dark launch policy running result.

Risk Level: Low

Signed-off-by: Quanjie Lin quanlin@google.com

@quanjielin quanjielin force-pushed the quanlinmetric2 branch 3 times, most recently from 2c46cd5 to f1b007d Compare August 6, 2018 17:11
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.

snake_case for all function parameters and local variables (throughout)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

updated.

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.

nit: std::make_pair

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done.

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.

Do we want to validate if there is a dup of policy ID?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

should be fine since rules.policies is map which guarantees no dup.

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.

filter_metadata() is not scoped to each filter, at least you should add .at(HttpFilterNames::get().Rbac) at the end.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

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.

make Struct first and then merge once?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

@quanjielin quanjielin force-pushed the quanlinmetric2 branch 2 times, most recently from 9840cd8 to 0b97f68 Compare August 6, 2018 21:29
Copy link
Copy Markdown
Member

@lizan lizan left a comment

Choose a reason for hiding this comment

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

Can you take a look on CI?

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.

effective_policy_id?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

renamed.

@quanjielin
Copy link
Copy Markdown
Contributor Author

quanjielin commented Aug 6, 2018

@lizan , seems the error is due to some files was removed recently, sync to latest master and see.


external/envoy/test/common/http/http2/codec_impl_fuzz_test.cc:14:10: fatal error: 'common/stats/stats_impl.h' file not found
#include "common/stats/stats_impl.h"
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
INFO: Elapsed time: 1157.336s, Critical Path: 54.36s

Signed-off-by: Quanjie Lin <quanlin@google.com>
Signed-off-by: Quanjie Lin <quanlin@google.com>
Signed-off-by: Quanjie Lin <quanlin@google.com>
lizan
lizan previously approved these changes Aug 7, 2018
@quanjielin
Copy link
Copy Markdown
Contributor Author

/cc @mattklein123 @rodaine

Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Few small comments, thank you!

virtual bool allowed(const Network::Connection& connection, const Envoy::Http::HeaderMap& headers,
const envoy::api::v2::core::Metadata& metadata) const PURE;
const envoy::api::v2::core::Metadata& metadata,
std::string& effective_policy_id) const PURE;
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.

please update doc comments

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added comment for effective_policy_id

const absl::optional<Filters::Common::RBAC::RoleBasedAccessControlEngineImpl>& shadow_engine =
config_->engine(callbacks_->route(), EnforcementMode::Shadow);
if (shadow_engine.has_value()) {
std::string shadow_resp_code = "200";
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.

Can we switch these to static constants.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done.

if (filter_it != filter_metadata.end()) {
ProtobufWkt::Struct metrics;

if (effective_policy_id != "") {
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.

nit: !effective_policy_id.empty() (can this happen btw, isn't every policy named even if default?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

updated.(when there is no matching policy found in allowed , effective_policy_id here is default to be empty)

if (effective_policy_id != "") {
ProtobufWkt::Value policy_id;
policy_id.set_string_value(effective_policy_id);
(*metrics.mutable_fields())["shadow_effective_policyID"] = policy_id;
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.

Static constants for "shadow_effective_policyID" to avoid construction (same below)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

updated.

if (engine.has_value()) {
if (engine->allowed(*callbacks_->connection(), headers,
callbacks_->requestInfo().dynamicMetadata())) {
callbacks_->requestInfo().dynamicMetadata(), effective_policy_id)) {
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.

Why don't we use this value here? Can we avoid cost by passing nullptr and not filling/copying?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we only need effective_policy_id for shadow case for now(can add later if needed); nullptr is invalid since allowed takes std::string& ?

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.

I would make it take std::string* then.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

updated.

Signed-off-by: Quanjie Lin <quanlin@google.com>
Signed-off-by: Quanjie Lin <quanlin@google.com>
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

LGTM, small comment. Thanks!

* @param headers the headers of the incoming request used to identify the action/principal. An
* empty map should be used if there are no headers available.
* @param metadata the metadata with additional information about the action/principal.
* @param effective_policy_id the matching policy's ID to identity the source of the allow/deny.
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.

Can you specify that this will be filled with the policy ID? It sounds like it's an input parameter.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

updated comment; thank you for the review !

Signed-off-by: Quanjie Lin <quanlin@google.com>
@mattklein123 mattklein123 merged commit e9dc109 into envoyproxy:master Aug 7, 2018
@quanjielin
Copy link
Copy Markdown
Contributor Author

/cc @liminw @qiwzhang @diemtvu @yangminzhu FYI.

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.

4 participants