Skip to content

Conversation

@lynnagara
Copy link
Member

@lynnagara lynnagara commented Jan 13, 2026

This PR replaces the ServiceRpcSignatureAuthentication with a more generic HmacSignatureAuthentication class which attempts to provide a class to do hmac authentication which is not RPC specific in any way.

The motivation for this change to enable new service (Synapse), which does not use RPC to be able to utilize this implementation.

The are two main changes here:

  • make the service prefix (which was previously hardcoded to rpc0:) configurable. Since this class never did any parsing of request bodies and just did cryptographic validation on body bytes this should be a fairly easy/safe change to make
  • make it possible to sign both the URL as well as body. Currently the implementation only signs the body which is not great for GET requests which have none.

Default args are set for backward compatibility.

Note: the querystring is not included in the url that is signed. I didn't add this here to avoid more changes / encoding complexities.

This PR replaces the ServiceRpcSignatureAuthentication with a more generic HmacSignatureAuthentication class
which attempts to provide a class to do hmac authentication which is not RPC specific
in any way.

The motivation for this change to enable new service (Synapse), which does not use RPC
to be able to utilize this implementation.

The main change involved here is making the service prefix (which was previously hardcoded to rpc0:)
configurable. Since this class never did any parsing of request bodies and just did cryptographic
validation on body bytes this should be a fairly easy/safe change to make.
@lynnagara lynnagara requested review from a team as code owners January 13, 2026 22:32
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jan 13, 2026
Copy link
Contributor

@michelletran-sentry michelletran-sentry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes generally LGTM except for the one comment below!

)

signature_input = body
if include_url_in_signature:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not seeing a test that uses include_url_in_signature. Should we have a test for this route?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, added a test with include_url_in_signature=True

Copy link
Member

@markstory markstory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. I agree with Michelle that we should have one more test covering the URL in signature flow.

Comment on lines +730 to +731
- signature_prefix: str - prefix for the signature format (e.g., "rpc0", "service0"). The colon will be added automatically. Defaults to "rpc0" for backward compatibility.
- include_url_in_signature: bool - If True, signs "url:body". If False, signs only "body". Defaults to False for backward compatibility.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Nice. This is a great way to capture the existing differences in the implementations we have right now.

Comment on lines 7 to 14
def generate_service_request_signature(
url_path: str, body: bytes, shared_secret_setting: list[str] | None, service_name: str
url_path: str,
body: bytes,
shared_secret_setting: list[str] | None,
service_name: str,
signature_prefix: str = "rpc0",
include_url_in_signature: bool = False,
) -> str:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After this merges it would be good to merge this with the other signature generation function we have for sentry's region RPC system as well.

@lynnagara lynnagara merged commit c6f308b into master Jan 14, 2026
66 checks passed
@lynnagara lynnagara deleted the generic-service-authentication branch January 14, 2026 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants