Files
aevolution/include/evo/server/broker/access_token.hpp
T
dingoandClaude Opus 5.5 68880ba3b4
Foundation / checks (checks) (push) Successful in 42m13s
Foundation / checks (deploy) (push) Successful in 4m5s
Foundation / checks (ecs) (push) Successful in 2m25s
Foundation / checks (network) (push) Successful in 19m18s
Foundation / checks (postgres) (push) Successful in 44m19s
Foundation / checks (tsan) (push) Successful in 9m48s
Foundation / checks (client) (push) Failing after 12m6s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped
ADR-0131: Keycloak grant broker and schema v39 account identities
evo-grant-broker verifies realm aeternalis access tokens offline (RS256 against
the pinned JWKS; audience aevolution-grants, client aevolution-game, verified
email) and issues 10-minute session grants:
- POST /grant routes to the region holding the account's life, or the default.
- POST /logout makes every issued grant stale and expires current control.
- GET /healthz.

Schema v39 maps (issuer, subject) to stable accounts with strictly increasing
serials. The binary ships in the server image. The DEV manifests are in
deploy/kubernetes/grant-broker-dev and are not yet enabled in region/dev; that
waits for the image promotion and the out-of-band Secrets and Ingress.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 10:20:27 -04:00

67 lines
2.2 KiB
C++

#pragma once
#include <cstdint>
#include <expected>
#include <memory>
#include <optional>
#include <span>
#include <string>
#include <string_view>
#include <vector>
// ADR-0131: verifies Keycloak access tokens (RS256 JWTs) against the realm's public
// keys, offline. Only what the broker needs is checked and returned.
namespace evo::server::broker {
struct AccessTokenRules {
std::string issuer; // The realm's issuer URL, exact.
std::string audience; // Must appear in `aud` (string or array).
std::string authorized_party; // `azp`: the game's public client.
std::uint64_t leeway_seconds{30};
};
struct AccessTokenClaims {
std::string issuer, subject;
std::uint64_t expires_at{};
};
enum class TokenError : std::uint8_t {
malformed,
unsupported_algorithm,
unknown_key,
bad_signature,
wrong_issuer,
wrong_audience,
wrong_party,
wrong_type,
expired,
not_yet_valid,
unverified_email,
missing_subject
};
inline constexpr std::size_t max_access_token_bytes = 6144;
class TokenVerifier {
public:
// RSA signing keys (`use` sig or absent, `alg` RS256 or absent, at least 2048 bits)
// from a JWKS document; other keys are ignored. Fails when none is usable.
[[nodiscard]] static std::expected<TokenVerifier, TokenError> from_jwks(std::string_view jwks,
AccessTokenRules rules);
[[nodiscard]] std::expected<AccessTokenClaims, TokenError>
verify(std::string_view token, std::uint64_t now_seconds) const;
[[nodiscard]] std::size_t keys() const noexcept {
return keys_.size();
}
private:
struct Key {
std::string kid;
std::shared_ptr<void> public_key; // EVP_PKEY, freed by its deleter.
};
TokenVerifier(std::vector<Key> keys, AccessTokenRules rules)
: keys_{std::move(keys)}, rules_{std::move(rules)} {}
std::vector<Key> keys_;
AccessTokenRules rules_;
};
[[nodiscard]] std::optional<std::vector<std::uint8_t>> base64url_decode(std::string_view text);
[[nodiscard]] std::string base64_encode(std::span<const std::uint8_t> bytes);
} // namespace evo::server::broker