Skip to content

Commit

Permalink
Add ClientIdentifier header
Browse files Browse the repository at this point in the history
Summary:
What?
- ClientIdentifier = Hash string of primary (non-host) tls client identities
- *Previous diffs* added and set ClientIdentifier field/value in RequestCommon
- **This diff** will set the value in thrift header in codegen
- This code path is ONLY for proxies and will be executed during shadow testing ONLY

WHY?
- SAP and uCache are working on securing look-aside cache called "Key Client Binding" feature where we bind keys in uCache with ClientIdentities. This ensures that cached data is restricted to the specific client who has access to the backed service.

- Design doc: https://fburl.com/gdoc/psjwp58j

Reviewed By: stuclar

Differential Revision: D62453803

fbshipit-source-id: 29f017a28a415cbe39fb3e76aaeec73131be75eb
  • Loading branch information
Hiral Singadia authored and facebook-github-bot committed Sep 30, 2024
1 parent 2f32271 commit c6ebd37
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 2 deletions.
3 changes: 3 additions & 0 deletions mcrouter/lib/carbon/MessageCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class MessageCommon {
static constexpr std::string_view kCryptoAuthTokenHeader =
"crypto_auth_tokens";

static constexpr std::string_view kClientIdentifierHeader =
"client_identifier";

protected:
std::string traceContext_;
};
Expand Down
6 changes: 4 additions & 2 deletions mcrouter/lib/carbon/RequestCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ class RequestCommon : public MessageCommon {
RequestCommon(const RequestCommon& other) {
traceContext_ = other.traceContext_;
cryptoAuthToken_ = other.cryptoAuthToken_;
clientIdentifier_ = other.clientIdentifier_;
}
RequestCommon& operator=(const RequestCommon& other) {
if (this != &other) {
traceContext_ = other.traceContext_;
cryptoAuthToken_ = other.cryptoAuthToken_;
clientIdentifier_ = other.clientIdentifier_;
}
return *this;
}
Expand Down Expand Up @@ -83,7 +85,7 @@ class RequestCommon : public MessageCommon {
return cryptoAuthToken_;
}

const std::string& getClientIdentifier() const noexcept {
const std::optional<std::string>& getClientIdentifier() const noexcept {
return clientIdentifier_;
}

Expand All @@ -101,7 +103,7 @@ class RequestCommon : public MessageCommon {
// cat token(s) in string serialzed format
std::optional<std::string> cryptoAuthToken_;
// Hash string of primary (non-host) tls client identities
std::string clientIdentifier_;
std::optional<std::string> clientIdentifier_;
};

} // namespace carbon
12 changes: 12 additions & 0 deletions mcrouter/lib/carbon/example/gen/HelloGoodbyeThriftTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ folly::Try<apache::thrift::RpcResponseComplete<hellogoodbye::GoodbyeReply>> send
rpcOptions.setWriteHeader(
std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value());
}
if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) {
rpcOptions.setWriteHeader(
std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value());
}
rpcOptions.setContextPropMask(0);

#ifndef LIBMC_FBTRACE_DISABLE
Expand Down Expand Up @@ -86,6 +90,10 @@ folly::Try<apache::thrift::RpcResponseComplete<hellogoodbye::HelloReply>> sendSy
rpcOptions.setWriteHeader(
std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value());
}
if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) {
rpcOptions.setWriteHeader(
std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value());
}
rpcOptions.setContextPropMask(0);

#ifndef LIBMC_FBTRACE_DISABLE
Expand Down Expand Up @@ -125,6 +133,10 @@ folly::Try<apache::thrift::RpcResponseComplete<McVersionReply>> sendSyncHelper(
rpcOptions.setWriteHeader(
std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value());
}
if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) {
rpcOptions.setWriteHeader(
std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value());
}
rpcOptions.setContextPropMask(0);

#ifndef LIBMC_FBTRACE_DISABLE
Expand Down
5 changes: 5 additions & 0 deletions mcrouter/lib/carbon/example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ class ThriftHandler : virtual public hellogoodbye::thrift::HelloGoodbyeSvIf {
LOG(INFO) << "Got optional header props " << it->second
<< " from thrift header.";
}
it = headers.find("client_identifier");
if (it != headers.end()) {
LOG(INFO) << "Got client_identifier " << it->second
<< " from thrift header.";
}
} else {
LOG(ERROR) << "Cannot get context.";
}
Expand Down
8 changes: 8 additions & 0 deletions mcrouter/lib/carbon/test/gen/AThriftTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ folly::Try<apache::thrift::RpcResponseComplete<carbon::test::A::TestAReply>> sen
rpcOptions.setWriteHeader(
std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value());
}
if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) {
rpcOptions.setWriteHeader(
std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value());
}
rpcOptions.setContextPropMask(0);

#ifndef LIBMC_FBTRACE_DISABLE
Expand Down Expand Up @@ -86,6 +90,10 @@ folly::Try<apache::thrift::RpcResponseComplete<McVersionReply>> sendSyncHelper(
rpcOptions.setWriteHeader(
std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value());
}
if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) {
rpcOptions.setWriteHeader(
std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value());
}
rpcOptions.setContextPropMask(0);

#ifndef LIBMC_FBTRACE_DISABLE
Expand Down
8 changes: 8 additions & 0 deletions mcrouter/lib/carbon/test/gen/BThriftTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ folly::Try<apache::thrift::RpcResponseComplete<carbon::test::B::TestBReply>> sen
rpcOptions.setWriteHeader(
std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value());
}
if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) {
rpcOptions.setWriteHeader(
std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value());
}
rpcOptions.setContextPropMask(0);

#ifndef LIBMC_FBTRACE_DISABLE
Expand Down Expand Up @@ -86,6 +90,10 @@ folly::Try<apache::thrift::RpcResponseComplete<McVersionReply>> sendSyncHelper(
rpcOptions.setWriteHeader(
std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value());
}
if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) {
rpcOptions.setWriteHeader(
std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value());
}
rpcOptions.setContextPropMask(0);

#ifndef LIBMC_FBTRACE_DISABLE
Expand Down
12 changes: 12 additions & 0 deletions mcrouter/lib/carbon/test/gen/CarbonTestThriftTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ folly::Try<apache::thrift::RpcResponseComplete<carbon::test::TestReply>> sendSyn
rpcOptions.setWriteHeader(
std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value());
}
if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) {
rpcOptions.setWriteHeader(
std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value());
}
rpcOptions.setContextPropMask(0);

#ifndef LIBMC_FBTRACE_DISABLE
Expand Down Expand Up @@ -86,6 +90,10 @@ folly::Try<apache::thrift::RpcResponseComplete<carbon::test::TestReplyStringKey>
rpcOptions.setWriteHeader(
std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value());
}
if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) {
rpcOptions.setWriteHeader(
std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value());
}
rpcOptions.setContextPropMask(0);

#ifndef LIBMC_FBTRACE_DISABLE
Expand Down Expand Up @@ -122,6 +130,10 @@ folly::Try<apache::thrift::RpcResponseComplete<McVersionReply>> sendSyncHelper(
rpcOptions.setWriteHeader(
std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value());
}
if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) {
rpcOptions.setWriteHeader(
std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value());
}
rpcOptions.setContextPropMask(0);

#ifndef LIBMC_FBTRACE_DISABLE
Expand Down
16 changes: 16 additions & 0 deletions mcrouter/lib/carbon/test/gen/CarbonThriftTestThriftTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ folly::Try<apache::thrift::RpcResponseComplete<carbon::test::CustomReply>> sendS
rpcOptions.setWriteHeader(
std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value());
}
if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) {
rpcOptions.setWriteHeader(
std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value());
}
rpcOptions.setContextPropMask(0);

#ifndef LIBMC_FBTRACE_DISABLE
Expand Down Expand Up @@ -86,6 +90,10 @@ folly::Try<apache::thrift::RpcResponseComplete<carbon::test::DummyThriftReply>>
rpcOptions.setWriteHeader(
std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value());
}
if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) {
rpcOptions.setWriteHeader(
std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value());
}
rpcOptions.setContextPropMask(0);

#ifndef LIBMC_FBTRACE_DISABLE
Expand Down Expand Up @@ -122,6 +130,10 @@ folly::Try<apache::thrift::RpcResponseComplete<carbon::test::ThriftTestReply>> s
rpcOptions.setWriteHeader(
std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value());
}
if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) {
rpcOptions.setWriteHeader(
std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value());
}
rpcOptions.setContextPropMask(0);

#ifndef LIBMC_FBTRACE_DISABLE
Expand Down Expand Up @@ -158,6 +170,10 @@ folly::Try<apache::thrift::RpcResponseComplete<McVersionReply>> sendSyncHelper(
rpcOptions.setWriteHeader(
std::string{carbon::MessageCommon::kCryptoAuthTokenHeader}, request.getCryptoAuthToken().value());
}
if (FOLLY_UNLIKELY(request.getClientIdentifier().has_value())) {
rpcOptions.setWriteHeader(
std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value());
}
rpcOptions.setContextPropMask(0);

#ifndef LIBMC_FBTRACE_DISABLE
Expand Down
Loading

0 comments on commit c6ebd37

Please sign in to comment.