-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Populate origin.user attribute from the SAN field of client cert #142
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 4 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 |
|---|---|---|
|
|
@@ -31,17 +31,19 @@ namespace Mixer { | |
| namespace { | ||
|
|
||
| // Define attribute names | ||
| const std::string kRequestPath = "request.path"; | ||
| const std::string kOriginUser = "origin.user"; | ||
|
|
||
| const std::string kRequestHeaders = "request.headers"; | ||
| const std::string kRequestHost = "request.host"; | ||
| const std::string kRequestPath = "request.path"; | ||
| const std::string kRequestSize = "request.size"; | ||
| const std::string kRequestTime = "request.time"; | ||
| const std::string kRequestHeaders = "request.headers"; | ||
|
|
||
| const std::string kResponseHeaders = "response.headers"; | ||
| const std::string kResponseHttpCode = "response.http.code"; | ||
| const std::string kResponseLatency = "response.latency"; | ||
| const std::string kResponseSize = "response.size"; | ||
| const std::string kResponseTime = "response.time"; | ||
| const std::string kResponseLatency = "response.latency"; | ||
| const std::string kResponseHttpCode = "response.http.code"; | ||
|
|
||
| Attributes::Value StringValue(const std::string& str) { | ||
| Attributes::Value v; | ||
|
|
@@ -169,9 +171,12 @@ void HttpControl::FillCheckAttributes(HeaderMap& header_map, Attributes* attr) { | |
| } | ||
| } | ||
|
|
||
| void HttpControl::Check(HttpRequestDataPtr request_data, HeaderMap& headers, | ||
| void HttpControl::Check(HttpRequestDataPtr request_data, HeaderMap& headers, std::string origin_user, | ||
| DoneFunc on_done) { | ||
| FillCheckAttributes(headers, &request_data->attributes); | ||
| if (origin_user != "") { | ||
|
Contributor
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. you can call SetStringAttribute
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 |
||
| request_data->attributes.attributes[kOriginUser] = StringValue(origin_user); | ||
| } | ||
| log().debug("Send Check: {}", request_data->attributes.DebugString()); | ||
| mixer_client_->Check(request_data->attributes, on_done); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
| #include "common/http/headers.h" | ||
| #include "common/http/utility.h" | ||
| #include "envoy/server/instance.h" | ||
| #include "envoy/ssl/connection.h" | ||
| #include "server/config/network/http_connection_manager.h" | ||
| #include "src/envoy/mixer/http_control.h" | ||
| #include "src/envoy/mixer/utils.h" | ||
|
|
@@ -151,8 +152,15 @@ class Instance : public Http::StreamFilter, public Http::AccessLog::Instance { | |
| state_ = Calling; | ||
| initiating_call_ = true; | ||
| request_data_ = std::make_shared<HttpRequestData>(); | ||
|
|
||
| std::string origin_user; | ||
| Ssl::Connection* ssl = const_cast<Ssl::Connection *>(decoder_callbacks_->ssl()); | ||
| if (ssl != nullptr) { | ||
| origin_user = ssl->uriSanPeerCertificate(); | ||
|
Contributor
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. can we use const for this function? or why do we need const_cast?
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. Yes, it's something i can add to envoy. |
||
| } | ||
|
|
||
| http_control_->Check( | ||
| request_data_, headers, | ||
| request_data_, headers, origin_user, | ||
| wrapper([this](const Status& status) { completeCheck(status); })); | ||
| initiating_call_ = false; | ||
|
|
||
|
|
@@ -180,13 +188,15 @@ class Instance : public Http::StreamFilter, public Http::AccessLog::Instance { | |
| } | ||
| return FilterTrailersStatus::Continue; | ||
| } | ||
|
|
||
| void setDecoderFilterCallbacks( | ||
| StreamDecoderFilterCallbacks& callbacks) override { | ||
| Log().debug("Called Mixer::Instance : {}", __func__); | ||
| decoder_callbacks_ = &callbacks; | ||
| decoder_callbacks_->addResetStreamCallback( | ||
| [this]() { state_ = Responded; }); | ||
| } | ||
|
|
||
| void completeCheck(const Status& status) { | ||
| Log().debug("Called Mixer::Instance : check complete {}", | ||
| status.ToString()); | ||
|
|
@@ -197,6 +207,7 @@ class Instance : public Http::StreamFilter, public Http::AccessLog::Instance { | |
| status.ToString()); | ||
| return; | ||
| } | ||
|
|
||
| state_ = Complete; | ||
| if (!initiating_call_) { | ||
| decoder_callbacks_->continueDecoding(); | ||
|
|
@@ -208,15 +219,18 @@ class Instance : public Http::StreamFilter, public Http::AccessLog::Instance { | |
| Log().debug("Called Mixer::Instance : {}", __func__); | ||
| return FilterHeadersStatus::Continue; | ||
| } | ||
|
|
||
| virtual FilterDataStatus encodeData(Buffer::Instance& data, | ||
| bool end_stream) override { | ||
| Log().debug("Called Mixer::Instance : {}", __func__); | ||
| return FilterDataStatus::Continue; | ||
| } | ||
|
|
||
| virtual FilterTrailersStatus encodeTrailers(HeaderMap& trailers) override { | ||
| Log().debug("Called Mixer::Instance : {}", __func__); | ||
| return FilterTrailersStatus::Continue; | ||
| } | ||
|
|
||
| virtual void setEncoderFilterCallbacks( | ||
| StreamEncoderFilterCallbacks& callbacks) override { | ||
| Log().debug("Called Mixer::Instance : {}", __func__); | ||
|
|
||
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.
it seems that format is wrong.
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