Skip to content

Commit eba3850

Browse files
Jay Ghuryemeta-codesync[bot]
authored andcommitted
Forward kcb_identity header to ucache backend from mcrouter
Summary: When KCB is enabled, mcrouter rebuilds the upstream thrift request from a fixed set of carbon fields and drops any transport header it does not explicitly capture. On the non-lookaside path it stored the verified identity into `client_identifier` (only for shadow) and never populated `kcbIdentity_`, so mcrouter never re-emitted the `kcb_identity` header to the ucache backend. As a result `KeyClientBinder::getObfuscatedClientIdFromKcbIdentityHeader` was unreachable for proxied traffic and the `ucache.kcb_identity_header_*` counters stayed flat. This forwards the client's `kcb_identity` header verbatim (via new `detail::rawKcbIdentityHeader`) whenever it is non-empty, inside the existing `enableKeyClientBinding_` guard. The vouching CAT is already forwarded alongside it, so the backend performs the authoritative `MEMCACHE_ID` check itself. Reviewed By: lenar-f Differential Revision: D111756121 fbshipit-source-id: 8f36cb6c35818c06bac5d6b75c989a288fd01a49
1 parent b42514d commit eba3850

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

mcrouter/ServerOnRequest.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,23 @@ inline std::optional<std::string> nonLookasideKcbIdentity(
8484
}
8585
return std::nullopt;
8686
}
87+
88+
// Returns the `kcb_identity` header value iff present and non-empty. No CAT
89+
// verification -- verbatim passthrough, leaving the check to the backend.
90+
inline std::optional<std::string> rawKcbIdentityHeader(
91+
const apache::thrift::Cpp2RequestContext& ctx) {
92+
const auto* header = ctx.getHeader();
93+
if (!header) {
94+
return std::nullopt;
95+
}
96+
const auto& headers = header->getHeaders();
97+
const auto it =
98+
headers.find(std::string(carbon::MessageCommon::kKcbIdentityHeader));
99+
if (it == headers.end() || it->second.empty()) {
100+
return std::nullopt;
101+
}
102+
return it->second;
103+
}
87104
} // namespace detail
88105
#endif
89106

@@ -278,6 +295,13 @@ class ServerOnRequest {
278295
if (serializedCat.has_value()) {
279296
reqRef.setCryptoAuthToken(std::string{serializedCat.value()});
280297
}
298+
299+
// Forward the client's `kcb_identity` header verbatim; the branches above
300+
// only set `client_identifier`, so the backend's non-lookaside path needs
301+
// this to see the header at all. The vouching CAT is forwarded above.
302+
if (auto rawKcbIdentity = detail::rawKcbIdentityHeader(*thriftCtx)) {
303+
reqRef.setKcbIdentity(*rawKcbIdentity);
304+
}
281305
}
282306
#endif
283307

0 commit comments

Comments
 (0)