Skip to main content

tenant_id_for_token

Function tenant_id_for_token 

Source
pub fn tenant_id_for_token(token: &str) -> String
Expand description

The tenant id BearerTokenTenantResolver derives from a bearer token it has not verified: sha256: and the first 16 bytes of the token’s SHA-256 digest as lowercase hex (39 characters).

A tenant id is stored (every task row carries it), exported (telemetry attributes), and chained into the audit log, so a resolver that used the token itself put a live credential in each of those (audit SEC-11). The digest does not: SHA-256 cannot be run backwards, and 128 bits of it are plenty to keep two tokens apart. It is a name for the token, not a check of it; see BearerTokenTenantResolver.

The format is part of the contract, so that a deployment that moves data from the raw-token tenant of earlier releases can compute the new id of each token it holds.

§Example

use a2a_protocol_server::tenant_resolver::tenant_id_for_token;

assert_eq!(
    tenant_id_for_token("abc"),
    "sha256:ba7816bf8f01cfea414140de5dae2223"
);