Skip to content

Commit 9c7a4a9

Browse files
speb-metameta-codesync[bot]
authored andcommitted
Propagate PrivacyLibAgenticContext through Carbon requests and Thrift transport headers (#479)
Summary: Pull Request resolved: #479 X-link: facebook/hhvm#9778 X-link: facebookresearch/DCPerf#621 Propagate the `PrivacyLibAgenticContext` as a `privacylib-propagation` Thrift header from clients through mcrouter to DevProxy. We capture the context before enqueuing the request in the mcrouter message queue. And then we set the header in the mcrouter Thrift transport layer. Diagram: ``` Caller thread (RequestContext available) │ ├── CacheClientImplBase::buildSingleRequest() ← captures context here │ └── carbonReq.setPrivacyLibAgenticContext(serialized) │ ├── RequestBuilderHelper::updateTaoRequestCommonPart() ← also captures here (TAO-specific) │ └── carbonReq.setPrivacyLibAgenticContext(serialized) │ ╧ ── MessageQueue ──────────────────── (RequestContext lost, but field survives) │ └── ThriftTransport::sendSyncHelper() └── request.getPrivacyLibAgenticContext().has_value() └── rpcOptions.setWriteHeader("privacylib-propagation", value) ``` We are focusing on Thrift transport exclusively as we are trying to close gaps in DevProxy layer. Reviewed By: ghostonhuang Differential Revision: D105269091 fbshipit-source-id: d362d4053651b95db31e758665922a8883b6a5af
1 parent 6747145 commit 9c7a4a9

9 files changed

Lines changed: 156 additions & 0 deletions

‎mcrouter/lib/carbon/MessageCommon.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ class MessageCommon {
4242

4343
static constexpr std::string_view kKcbIdentityHeader = "kcb_identity";
4444

45+
static constexpr std::string_view kPrivacyLibAgenticContextHeader =
46+
"privacylib-propagation";
47+
4548
protected:
4649
std::string traceContext_;
4750
};

‎mcrouter/lib/carbon/RequestCommon.cpp‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ RequestCommon::RequestCommon(const RequestCommon& other)
2222
cryptoAuthToken_ = other.cryptoAuthToken_;
2323
replyBitMask_ = other.replyBitMask_;
2424
clientIdentifier_ = other.clientIdentifier_;
25+
privacyLibAgenticContext_ = other.privacyLibAgenticContext_;
2526
}
2627

2728
RequestCommon& RequestCommon::operator=(const RequestCommon& other) {
@@ -30,6 +31,7 @@ RequestCommon& RequestCommon::operator=(const RequestCommon& other) {
3031
cryptoAuthToken_ = other.cryptoAuthToken_;
3132
replyBitMask_ = other.replyBitMask_;
3233
clientIdentifier_ = other.clientIdentifier_;
34+
privacyLibAgenticContext_ = other.privacyLibAgenticContext_;
3335
uniqueId_ = other.uniqueId_;
3436
}
3537
return *this;
@@ -81,6 +83,15 @@ void RequestCommon::setClientIdentifier(
8183
clientIdentifier_ = clientIdentifier.str();
8284
}
8385

86+
const std::optional<std::string>& RequestCommon::getPrivacyLibAgenticContext()
87+
const {
88+
return privacyLibAgenticContext_;
89+
}
90+
91+
void RequestCommon::setPrivacyLibAgenticContext(std::string&& context) {
92+
privacyLibAgenticContext_.emplace(std::move(context));
93+
}
94+
8495
const std::optional<folly::IPAddress>& RequestCommon::getSourceIpAddr()
8596
const noexcept {
8697
return sourceIpAddr_;

‎mcrouter/lib/carbon/RequestCommon.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ class RequestCommon : public MessageCommon {
7272

7373
void setClientIdentifier(folly::StringPiece clientIdentifier) noexcept;
7474

75+
const std::optional<std::string>& getPrivacyLibAgenticContext() const;
76+
77+
void setPrivacyLibAgenticContext(std::string&& context);
78+
7579
const std::optional<folly::IPAddress>& getSourceIpAddr() const noexcept;
7680

7781
void setSourceIpAddr(const folly::IPAddress& sourceIpAddr) noexcept;
@@ -95,6 +99,8 @@ class RequestCommon : public MessageCommon {
9599
std::optional<std::string> cryptoAuthToken_;
96100
// Hash string of primary (non-host) tls client identities
97101
std::optional<std::string> clientIdentifier_;
102+
// Privacylib agentic context in base64-encoded serialized format
103+
std::optional<std::string> privacyLibAgenticContext_;
98104
// Source ip address.
99105
std::optional<folly::IPAddress> sourceIpAddr_;
100106
// write timestamp

‎mcrouter/lib/carbon/example/gen/HelloGoodbyeThriftTransport.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ folly::Try<apache::thrift::RpcResponseComplete<hellogoodbye::GoodbyeReply>> send
5656
rpcOptions.setWriteHeader(
5757
std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value());
5858
}
59+
if (FOLLY_UNLIKELY(request.getPrivacyLibAgenticContext().has_value())) {
60+
rpcOptions.setWriteHeader(
61+
std::string{carbon::MessageCommon::kPrivacyLibAgenticContextHeader}, request.getPrivacyLibAgenticContext().value());
62+
}
5963
rpcOptions.setContextPropMask(0);
6064

6165
#ifndef LIBMC_FBTRACE_DISABLE
@@ -96,6 +100,10 @@ folly::Try<apache::thrift::RpcResponseComplete<hellogoodbye::HelloReply>> sendSy
96100
rpcOptions.setWriteHeader(
97101
std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value());
98102
}
103+
if (FOLLY_UNLIKELY(request.getPrivacyLibAgenticContext().has_value())) {
104+
rpcOptions.setWriteHeader(
105+
std::string{carbon::MessageCommon::kPrivacyLibAgenticContextHeader}, request.getPrivacyLibAgenticContext().value());
106+
}
99107
rpcOptions.setContextPropMask(0);
100108

101109
#ifndef LIBMC_FBTRACE_DISABLE
@@ -139,6 +147,10 @@ folly::Try<apache::thrift::RpcResponseComplete<McVersionReply>> sendSyncHelper(
139147
rpcOptions.setWriteHeader(
140148
std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value());
141149
}
150+
if (FOLLY_UNLIKELY(request.getPrivacyLibAgenticContext().has_value())) {
151+
rpcOptions.setWriteHeader(
152+
std::string{carbon::MessageCommon::kPrivacyLibAgenticContextHeader}, request.getPrivacyLibAgenticContext().value());
153+
}
142154
rpcOptions.setContextPropMask(0);
143155

144156
#ifndef LIBMC_FBTRACE_DISABLE

‎mcrouter/lib/carbon/test/gen/AThriftTransport.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ folly::Try<apache::thrift::RpcResponseComplete<carbon::test::A::TestAReply>> sen
5454
rpcOptions.setWriteHeader(
5555
std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value());
5656
}
57+
if (FOLLY_UNLIKELY(request.getPrivacyLibAgenticContext().has_value())) {
58+
rpcOptions.setWriteHeader(
59+
std::string{carbon::MessageCommon::kPrivacyLibAgenticContextHeader}, request.getPrivacyLibAgenticContext().value());
60+
}
5761
rpcOptions.setContextPropMask(0);
5862

5963
#ifndef LIBMC_FBTRACE_DISABLE
@@ -94,6 +98,10 @@ folly::Try<apache::thrift::RpcResponseComplete<McVersionReply>> sendSyncHelper(
9498
rpcOptions.setWriteHeader(
9599
std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value());
96100
}
101+
if (FOLLY_UNLIKELY(request.getPrivacyLibAgenticContext().has_value())) {
102+
rpcOptions.setWriteHeader(
103+
std::string{carbon::MessageCommon::kPrivacyLibAgenticContextHeader}, request.getPrivacyLibAgenticContext().value());
104+
}
97105
rpcOptions.setContextPropMask(0);
98106

99107
#ifndef LIBMC_FBTRACE_DISABLE

‎mcrouter/lib/carbon/test/gen/BThriftTransport.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ folly::Try<apache::thrift::RpcResponseComplete<carbon::test::B::TestBReply>> sen
5454
rpcOptions.setWriteHeader(
5555
std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value());
5656
}
57+
if (FOLLY_UNLIKELY(request.getPrivacyLibAgenticContext().has_value())) {
58+
rpcOptions.setWriteHeader(
59+
std::string{carbon::MessageCommon::kPrivacyLibAgenticContextHeader}, request.getPrivacyLibAgenticContext().value());
60+
}
5761
rpcOptions.setContextPropMask(0);
5862

5963
#ifndef LIBMC_FBTRACE_DISABLE
@@ -94,6 +98,10 @@ folly::Try<apache::thrift::RpcResponseComplete<McVersionReply>> sendSyncHelper(
9498
rpcOptions.setWriteHeader(
9599
std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value());
96100
}
101+
if (FOLLY_UNLIKELY(request.getPrivacyLibAgenticContext().has_value())) {
102+
rpcOptions.setWriteHeader(
103+
std::string{carbon::MessageCommon::kPrivacyLibAgenticContextHeader}, request.getPrivacyLibAgenticContext().value());
104+
}
97105
rpcOptions.setContextPropMask(0);
98106

99107
#ifndef LIBMC_FBTRACE_DISABLE

‎mcrouter/lib/carbon/test/gen/CarbonTestThriftTransport.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ folly::Try<apache::thrift::RpcResponseComplete<carbon::test::TestReply>> sendSyn
5454
rpcOptions.setWriteHeader(
5555
std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value());
5656
}
57+
if (FOLLY_UNLIKELY(request.getPrivacyLibAgenticContext().has_value())) {
58+
rpcOptions.setWriteHeader(
59+
std::string{carbon::MessageCommon::kPrivacyLibAgenticContextHeader}, request.getPrivacyLibAgenticContext().value());
60+
}
5761
rpcOptions.setContextPropMask(0);
5862

5963
#ifndef LIBMC_FBTRACE_DISABLE
@@ -94,6 +98,10 @@ folly::Try<apache::thrift::RpcResponseComplete<carbon::test::TestReplyStringKey>
9498
rpcOptions.setWriteHeader(
9599
std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value());
96100
}
101+
if (FOLLY_UNLIKELY(request.getPrivacyLibAgenticContext().has_value())) {
102+
rpcOptions.setWriteHeader(
103+
std::string{carbon::MessageCommon::kPrivacyLibAgenticContextHeader}, request.getPrivacyLibAgenticContext().value());
104+
}
97105
rpcOptions.setContextPropMask(0);
98106

99107
#ifndef LIBMC_FBTRACE_DISABLE
@@ -134,6 +142,10 @@ folly::Try<apache::thrift::RpcResponseComplete<McVersionReply>> sendSyncHelper(
134142
rpcOptions.setWriteHeader(
135143
std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value());
136144
}
145+
if (FOLLY_UNLIKELY(request.getPrivacyLibAgenticContext().has_value())) {
146+
rpcOptions.setWriteHeader(
147+
std::string{carbon::MessageCommon::kPrivacyLibAgenticContextHeader}, request.getPrivacyLibAgenticContext().value());
148+
}
137149
rpcOptions.setContextPropMask(0);
138150

139151
#ifndef LIBMC_FBTRACE_DISABLE

‎mcrouter/lib/carbon/test/gen/CarbonThriftTestThriftTransport.h‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ folly::Try<apache::thrift::RpcResponseComplete<carbon::test::CustomReply>> sendS
5454
rpcOptions.setWriteHeader(
5555
std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value());
5656
}
57+
if (FOLLY_UNLIKELY(request.getPrivacyLibAgenticContext().has_value())) {
58+
rpcOptions.setWriteHeader(
59+
std::string{carbon::MessageCommon::kPrivacyLibAgenticContextHeader}, request.getPrivacyLibAgenticContext().value());
60+
}
5761
rpcOptions.setContextPropMask(0);
5862

5963
#ifndef LIBMC_FBTRACE_DISABLE
@@ -94,6 +98,10 @@ folly::Try<apache::thrift::RpcResponseComplete<carbon::test::DummyThriftReply>>
9498
rpcOptions.setWriteHeader(
9599
std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value());
96100
}
101+
if (FOLLY_UNLIKELY(request.getPrivacyLibAgenticContext().has_value())) {
102+
rpcOptions.setWriteHeader(
103+
std::string{carbon::MessageCommon::kPrivacyLibAgenticContextHeader}, request.getPrivacyLibAgenticContext().value());
104+
}
97105
rpcOptions.setContextPropMask(0);
98106

99107
#ifndef LIBMC_FBTRACE_DISABLE
@@ -134,6 +142,10 @@ folly::Try<apache::thrift::RpcResponseComplete<carbon::test::ThriftTestReply>> s
134142
rpcOptions.setWriteHeader(
135143
std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value());
136144
}
145+
if (FOLLY_UNLIKELY(request.getPrivacyLibAgenticContext().has_value())) {
146+
rpcOptions.setWriteHeader(
147+
std::string{carbon::MessageCommon::kPrivacyLibAgenticContextHeader}, request.getPrivacyLibAgenticContext().value());
148+
}
137149
rpcOptions.setContextPropMask(0);
138150

139151
#ifndef LIBMC_FBTRACE_DISABLE
@@ -174,6 +186,10 @@ folly::Try<apache::thrift::RpcResponseComplete<McVersionReply>> sendSyncHelper(
174186
rpcOptions.setWriteHeader(
175187
std::string{carbon::MessageCommon::kClientIdentifierHeader}, request.getClientIdentifier().value());
176188
}
189+
if (FOLLY_UNLIKELY(request.getPrivacyLibAgenticContext().has_value())) {
190+
rpcOptions.setWriteHeader(
191+
std::string{carbon::MessageCommon::kPrivacyLibAgenticContextHeader}, request.getPrivacyLibAgenticContext().value());
192+
}
177193
rpcOptions.setContextPropMask(0);
178194

179195
#ifndef LIBMC_FBTRACE_DISABLE

0 commit comments

Comments
 (0)