Skip to content

Commit 7474e67

Browse files
authored
fix(seer-rpc): Test and monitor seer rpc validation (#93246)
Enable seer RPC check but only log an error for now
1 parent a82eeb9 commit 7474e67

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

src/sentry/api/endpoints/seer_rpc.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,35 @@ def compare_signature(url: str, body: bytes, signature: str) -> bool:
7070
if not signature.startswith("rpc0:"):
7171
return False
7272

73-
# We aren't using the version bits currently.
74-
body = orjson.dumps(orjson.loads(body))
75-
_, signature_data = signature.split(":", 2)
76-
# TODO: For backward compatibility with the current Seer implementation, allow all signatures
77-
# while we deploy the fix to both services
73+
if not body:
74+
logger.error("Seer RPC signature validation failed: no body")
75+
# TODO: For stability and backward compatibility, we are allowing all signatures
76+
# while we deploy the fix to both services. But we are logging an error if it fails.
77+
return True
78+
79+
try:
80+
# We aren't using the version bits currently.
81+
body = orjson.dumps(orjson.loads(body))
82+
_, signature_data = signature.split(":", 2)
83+
84+
signature_input = body
85+
86+
for key in settings.SEER_RPC_SHARED_SECRET:
87+
computed = hmac.new(key.encode(), signature_input, hashlib.sha256).hexdigest()
88+
is_valid = hmac.compare_digest(computed.encode(), signature_data.encode())
89+
if is_valid:
90+
logger.info("Seer RPC signature validated")
91+
return True
92+
except Exception:
93+
logger.exception("Seer RPC signature validation failed")
94+
return True
95+
96+
logger.error("Seer RPC signature validation failed")
97+
98+
# TODO: For stability and backward compatibility, we are allowing all signatures
99+
# while we deploy the fix to both services. But we are logging an error if it fails.
78100
return True
79101

80-
# signature_input = body
81-
82-
# for key in settings.SEER_RPC_SHARED_SECRET:
83-
# computed = hmac.new(key.encode(), signature_input, hashlib.sha256).hexdigest()
84-
# is_valid = hmac.compare_digest(computed.encode(), signature_data.encode())
85-
# if is_valid:
86-
# return True
87-
88-
# return False
89-
90102

91103
@AuthenticationSiloLimit(SiloMode.CONTROL, SiloMode.REGION)
92104
class SeerRpcSignatureAuthentication(StandardAuthentication):

0 commit comments

Comments
 (0)