TokenRedisStore#
- class gafaelfawr.storage.token.TokenRedisStore(storage, slack_client, logger)#
Bases:
objectStores and retrieves token data in Redis.
Tokens are stored with the key of the token as the Redis key and the data of the token as encrypted JSON, including the secret portion of the token. To retrieve a token, the caller must provide the full token and the secret in the token must match the secret retrieved from Redis.
This setup means that an attacker who can list the keys in Redis cannot use those keys directly as tokens and still needs access to the stored Redis data plus the decryption key to be able to reconstruct a token.
- Parameters:
storage (
EncryptedPydanticRedisStorage[TokenData]) – Underlying storage for token data.slack_client (
Optional[SlackWebhookClient]) – If provided, Slack webhook client to report deserialization errors of Redis data.logger (
BoundLogger) – Logger for diagnostics.
Methods Summary
delete(key)Delete a token from Redis.
Delete all stored tokens.
get_data(token)Retrieve the data for a token from Redis.
get_data_by_key(key)Retrieve the data for a token from Redis by its key.
Retrieve the data for a token by key without catching errors.
list()List all token keys stored in Redis.
store_data(data)Store the data for a token.
Methods Documentation
- async delete(key)#
Delete a token from Redis.
This only requires the token key, not the full token, so that users can delete tokens for their account without needing possession of the token.
- async get_data(token)#
Retrieve the data for a token from Redis.
Doubles as a way to check the validity of the token.
- async get_data_by_key(key)#
Retrieve the data for a token from Redis by its key.
This method allows retrieving a working token while bypassing the check that the caller is in possession of the secret, and therefore must never be used with user-supplied keys.
- async get_data_by_key_unchecked(key)#
Retrieve the data for a token by key without catching errors.
This method allows retrieving a working token while bypassing the check that the caller is in possession of the secret, and therefore must never be used with user-supplied keys. It raises exceptions if the key is invalid rather than pretending the token doesn’t exist, making it suitable for lower-level audits.
- Parameters:
key (
str) – The key of the token.- Returns:
The data underlying the token, or
Noneif the token doesn’t exist.- Return type:
TokenData or None
- Raises:
safir.redis.DeserializeError – Raised if the data stored in Redis is invalid.
- async list()#
List all token keys stored in Redis.