Skip to content

Commit

Permalink
Strip out "spiffe://" in the identity (envoyproxy#719)
Browse files Browse the repository at this point in the history
* Strip out "spiffe://" in the identity

* Addressed some review comments.

* Addressed review comments.
  • Loading branch information
JimmyCYJ authored and qiwzhang committed Dec 13, 2017
1 parent 13669ce commit 99a482f
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/envoy/mixer/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ namespace Envoy {
namespace Http {
namespace Utils {

namespace {

const std::string kSPIFFEPrefix("spiffe://");

} // namespace

std::map<std::string, std::string> ExtractHeaders(const HeaderMap& header_map) {
std::map<std::string, std::string> headers;
header_map.iterate(
Expand Down Expand Up @@ -54,7 +60,14 @@ bool GetSourceUser(const Network::Connection* connection, std::string* user) {
if (connection) {
Ssl::Connection* ssl = const_cast<Ssl::Connection*>(connection->ssl());
if (ssl != nullptr) {
*user = ssl->uriSanPeerCertificate();
std::string result = ssl->uriSanPeerCertificate();
if (result.length() >= kSPIFFEPrefix.length() &&
result.compare(0, kSPIFFEPrefix.length(), kSPIFFEPrefix) == 0) {
// Strip out the prefix "spiffe://" in the identity.
*user = result.substr(kSPIFFEPrefix.size());
} else {
*user = result;
}
return true;
}
}
Expand Down

0 comments on commit 99a482f

Please sign in to comment.