Skip to content

Implement request signing #65

Closed

Description

@llucax

What's needed?

Services will soon start require requests to be signed, so client should be able to do this signing.

Proposed solution

Implement signing requests somehow in ApiClientBase or utility functions/classes like GrpcStreamBroadcaster or call_stub_method. Ideally signing should be as transparent as possible to client implementers.

Signing works as follows:

Signature parts

The following request parts are used to generate the signature:

  • The user's API key (Metadata key: key)
  • The user's secret must be provided to the client, loaded from a file, env vars, etc.
  • The timestamp that the client sent the request (Metadata key: ts)
  • A one-time cryptographic random number called "nonce" generated for each request by the client (Metadata key: nonce)
  • The name of the requested gRPC method.
  • The serialized message body.

The signature is stored in the metadata key sig.

Algorithm

The algorithm uses HMAC with SHA-256 as the hashing algorithm. The resulting signature is encoded using URL-safe base64 without padding.

The algorithm can be outlined in pseudocode as follows:

hmac = Hmac(Sha256)
hmac.update(key)
hmac.update(secret)
hmac.update(ts)
hmac.update(nonce)
hmac.update(rpc_method)
hmac.update(msg_body)
signature = hmac.finalize()
encoded_sig = base64.url_safe_no_pad(signature)

Resources

Activity

  1. added
    type:enhancementNew feature or enhancement visitble to users
    part:codeAffects the code in general
    on Jul 30, 2024
  2. added this to the v0.6.0 milestone on Jul 30, 2024
  3. modified the milestones: v0.6.0, v0.7.0 on Aug 14, 2024
  4. modified the milestones: v0.7.0, v0.8.0 on Oct 29, 2024
  5. modified the milestones: v0.8.0, v0.9.0 on Nov 19, 2024
  6. llucax commented on Mar 25, 2025

    @llucax
    ContributorAuthor

    Since the API key is used, it would make probably a lot of sense to implement #70 before this.

  7. linked a pull request that will close this issueImplement HMAC for metadata #121on Apr 3, 2025
  8. modified the milestones: v0.9.0, v0.10.0 on May 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

part:codeAffects the code in generaltype:enhancementNew feature or enhancement visitble to users

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions