Add M10.3a account-bound session grants and region session control
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m47s
Foundation / checks (client) (push) Failing after 9m42s
Foundation / checks (network) (push) Successful in 8m49s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (postgres) (push) Canceled after 8m13s
Foundation / checks (tsan) (push) Canceled after 7m13s
Foundation / checks (checks) (push) Canceled after 17m58s
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m47s
Foundation / checks (client) (push) Failing after 9m42s
Foundation / checks (network) (push) Successful in 8m49s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (postgres) (push) Canceled after 8m13s
Foundation / checks (tsan) (push) Canceled after 7m13s
Foundation / checks (checks) (push) Canceled after 17m58s
Provider-independent 128-bit AccountIds; ECDSA P-256 session grants v1 signed by issuer keys and verified by regions with public keys only, the environment byte signed so dev grants never verify in stage or World0. Per-account serials make the newest grant win: replay and older stolen grants are refused, a newer grant replaces the account's session, and refresh renews in place. Attempt rates and capacities are bounded. The evo_identity library provides the provider, account directory and grant issuer interfaces with a dev-only test provider. ADR-0091. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
#pragma once
|
||||
#include "evo/network/session_grant.hpp"
|
||||
#include <compare>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <expected>
|
||||
#include <map>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
// M10.3 backend identity adapter (ADR-0091). An identity provider authenticates an
|
||||
// external credential to a provider subject; the account directory maps subjects to
|
||||
// provider-independent AccountIds and orders their grants; the issuer signs short-lived
|
||||
// region-scoped session grants. Library only: no service, no Steam. Production
|
||||
// providers plug in behind IdentityProvider later. Credentials are never stored or
|
||||
// logged here.
|
||||
namespace evo::identity {
|
||||
using network::AccountId;
|
||||
using network::DeploymentEnvironment;
|
||||
|
||||
enum class ProviderKind : std::uint8_t { dev_test = 1 };
|
||||
struct ProviderSubject {
|
||||
ProviderKind provider{};
|
||||
std::string subject; // Provider-scoped, 1..128 bytes; never an account id.
|
||||
auto operator<=>(const ProviderSubject&) const = default;
|
||||
};
|
||||
enum class IdentityError : std::uint8_t {
|
||||
not_dev_environment,
|
||||
wrong_environment,
|
||||
unauthenticated,
|
||||
invalid_request,
|
||||
directory_full,
|
||||
serial_exhausted,
|
||||
signing
|
||||
};
|
||||
|
||||
class IdentityProvider {
|
||||
public:
|
||||
IdentityProvider() = default;
|
||||
IdentityProvider(const IdentityProvider&) = delete;
|
||||
IdentityProvider& operator=(const IdentityProvider&) = delete;
|
||||
virtual ~IdentityProvider() = default;
|
||||
[[nodiscard]] virtual DeploymentEnvironment environment() const noexcept = 0;
|
||||
[[nodiscard]] virtual std::expected<ProviderSubject, IdentityError>
|
||||
authenticate(std::span<const std::uint8_t> credential) = 0;
|
||||
|
||||
protected:
|
||||
IdentityProvider(IdentityProvider&&) = default;
|
||||
IdentityProvider& operator=(IdentityProvider&&) = default;
|
||||
};
|
||||
|
||||
// Dev-only test identities: the credential "dev-test:<name>" (name 1..32 of [a-z0-9-])
|
||||
// authenticates as that name without any secret. It cannot be created outside dev.
|
||||
class DevTestProvider final : public IdentityProvider {
|
||||
public:
|
||||
[[nodiscard]] static std::expected<DevTestProvider, IdentityError>
|
||||
create(DeploymentEnvironment environment);
|
||||
[[nodiscard]] DeploymentEnvironment environment() const noexcept override {
|
||||
return DeploymentEnvironment::dev;
|
||||
}
|
||||
[[nodiscard]] std::expected<ProviderSubject, IdentityError>
|
||||
authenticate(std::span<const std::uint8_t> credential) override;
|
||||
|
||||
private:
|
||||
DevTestProvider() = default;
|
||||
};
|
||||
|
||||
// Serial and issue time of the next grant for an account: both non-decreasing, serial
|
||||
// strictly increasing (regions rely on this to bound how long serials are remembered).
|
||||
struct GrantSequence {
|
||||
std::uint64_t serial{}, issued_at{};
|
||||
};
|
||||
class AccountDirectory {
|
||||
public:
|
||||
AccountDirectory() = default;
|
||||
AccountDirectory(const AccountDirectory&) = delete;
|
||||
AccountDirectory& operator=(const AccountDirectory&) = delete;
|
||||
virtual ~AccountDirectory() = default;
|
||||
// The subject's account, created with a fresh random id on first sight.
|
||||
[[nodiscard]] virtual std::expected<AccountId, IdentityError>
|
||||
resolve(const ProviderSubject& subject) = 0;
|
||||
[[nodiscard]] virtual std::expected<GrantSequence, IdentityError>
|
||||
next_grant(const AccountId& account, std::uint64_t now_seconds) = 0;
|
||||
|
||||
protected:
|
||||
AccountDirectory(AccountDirectory&&) = default;
|
||||
AccountDirectory& operator=(AccountDirectory&&) = default;
|
||||
};
|
||||
|
||||
// Bounded in-memory directory for tests and local tools; not durable.
|
||||
class MemoryAccountDirectory final : public AccountDirectory {
|
||||
public:
|
||||
explicit MemoryAccountDirectory(std::size_t max_accounts) : max_accounts_{max_accounts} {}
|
||||
[[nodiscard]] std::expected<AccountId, IdentityError>
|
||||
resolve(const ProviderSubject& subject) override;
|
||||
[[nodiscard]] std::expected<GrantSequence, IdentityError>
|
||||
next_grant(const AccountId& account, std::uint64_t now_seconds) override;
|
||||
|
||||
private:
|
||||
std::size_t max_accounts_;
|
||||
std::map<ProviderSubject, AccountId> subjects_;
|
||||
std::map<AccountId, GrantSequence> sequences_;
|
||||
};
|
||||
|
||||
class GrantIssuer {
|
||||
public:
|
||||
// The provider and signing key must belong to the same environment. Lifetime is
|
||||
// 1..3600 s; regions refuse lifetimes above their own maximum (300 s by default).
|
||||
[[nodiscard]] static std::expected<GrantIssuer, IdentityError>
|
||||
create(network::GrantSigningKey key, IdentityProvider& provider, AccountDirectory& directory,
|
||||
std::uint64_t lifetime_seconds);
|
||||
[[nodiscard]] std::expected<network::SessionGrant, IdentityError>
|
||||
issue(std::span<const std::uint8_t> credential, world::WorldIdentity world,
|
||||
std::uint64_t region, std::uint64_t now_seconds);
|
||||
|
||||
private:
|
||||
GrantIssuer(network::GrantSigningKey key, IdentityProvider& provider,
|
||||
AccountDirectory& directory, std::uint64_t lifetime)
|
||||
: key_{std::move(key)}, provider_{&provider}, directory_{&directory}, lifetime_{lifetime} {}
|
||||
network::GrantSigningKey key_;
|
||||
IdentityProvider* provider_;
|
||||
AccountDirectory* directory_;
|
||||
std::uint64_t lifetime_;
|
||||
};
|
||||
} // namespace evo::identity
|
||||
Reference in New Issue
Block a user