Public Access
Add data model, DbContext and initial migration (M1)
Schema for identity, vaults, grants, hosts and the sync change log, verified against a real PostgreSQL 18 container rather than an in-memory provider: partial unique indexes, CHECK constraints, citext and identity-always columns are all provider behaviour that an in-memory fake would not exercise. Invariants pushed into the database, so they hold even when application code has a bug: - ck_host_relay_target is a security boundary, not tidiness. A host may carry a plaintext hostname and port ONLY when relay is deliberately enabled. Both directions are tested; the important one is that relay-disabled hosts cannot carry an address, since otherwise a bug would silently give the server infrastructure visibility it was never granted. - ck_vault_owner: exactly one of owner_user_id or team_id, or permission resolution would have no defined answer. - ck_vault_key_grant_recipient: member grants name a user; recovery and escrow grants are wrapped to a key and must not. - ck_user_key_wrap_kdf: a password-derived wrap without its parameters is permanently unopenable, so a partial write is rejected outright. Present from the first migration on purpose: - GrantKind (Member/Recovery/Escrow). Recovery cannot be bolted on later — every vault created before it existed would be unrecoverable by design. - team and team_membership, though team features are M3. Adding them later would mean introducing a foreign key on a live vault table. - Host.ContentKeyId, reserved for per-item content keys wrapped to individual users. - user_key as its own table, so key rotation does not require altering the user row. Two things verified rather than assumed: - Npgsql's UseXminAsConcurrencyToken helper no longer exists in EF 10, so xmin is mapped directly in XminConcurrency. The generated migration *looks* like it creates an xmin column; it does not. Confirmed by inspecting pg_attribute (attnum -2, a system column) and by grepping the emitted DDL. A test pins both, because had it created a real column PostgreSQL would have rejected the name. - EF Core is now pinned centrally. The Npgsql provider asks for 10.0.4 while EntityFrameworkCore.Design pulls 10.0.10, and because Design is PrivateAssets=all that higher version does not flow to referencing projects — producing a CS1705 in any test project referencing Infrastructure. Also commits artifacts/schema/v0.1.sql, the idempotent script, as the baseline for future upgrade tests. Verified: 0 warnings, 122 tests pass (27 new against Postgres), format clean.
This commit is contained in:
@@ -0,0 +1,165 @@
|
||||
namespace DodoSSH.Domain;
|
||||
|
||||
/// <summary>Lifecycle state of a user account.</summary>
|
||||
public enum UserStatus
|
||||
{
|
||||
/// <summary>Not a legal value.</summary>
|
||||
Unspecified = 0,
|
||||
|
||||
/// <summary>Normal, active account.</summary>
|
||||
Active = 1,
|
||||
|
||||
/// <summary>Sign-in blocked, data retained.</summary>
|
||||
Suspended = 2,
|
||||
|
||||
/// <summary>Offboarded. Grants revoked; audit history retained.</summary>
|
||||
Deprovisioned = 3,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Which key the user's secret bundle is wrapped under.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Every kind wraps the <em>same</em> bundle, which is what makes a passphrase change a
|
||||
/// single-row update instead of a re-encryption of the whole vault. See docs/crypto.md §3.
|
||||
/// </remarks>
|
||||
public enum UserKeyWrapKind
|
||||
{
|
||||
/// <summary>Not a legal value.</summary>
|
||||
Unspecified = 0,
|
||||
|
||||
/// <summary>Wrapped under a key derived from the vault passphrase.</summary>
|
||||
Passphrase = 1,
|
||||
|
||||
/// <summary>Sealed to one enrolled device's public key.</summary>
|
||||
Device = 2,
|
||||
|
||||
/// <summary>Wrapped under a key derived from the printable recovery code.</summary>
|
||||
Recovery = 3,
|
||||
|
||||
/// <summary>Sealed to a team break-glass key. Opt-in; M5.</summary>
|
||||
Escrow = 4,
|
||||
}
|
||||
|
||||
/// <summary>Operating system family of an enrolled device, for display only.</summary>
|
||||
public enum DevicePlatform
|
||||
{
|
||||
/// <summary>Unknown or unreported.</summary>
|
||||
Unspecified = 0,
|
||||
|
||||
/// <summary>Windows.</summary>
|
||||
Windows = 1,
|
||||
|
||||
/// <summary>macOS.</summary>
|
||||
MacOs = 2,
|
||||
|
||||
/// <summary>Linux.</summary>
|
||||
Linux = 3,
|
||||
}
|
||||
|
||||
/// <summary>A member's role within a team.</summary>
|
||||
public enum TeamRole
|
||||
{
|
||||
/// <summary>Not a legal value.</summary>
|
||||
Unspecified = 0,
|
||||
|
||||
/// <summary>Read-only.</summary>
|
||||
Viewer = 10,
|
||||
|
||||
/// <summary>Ordinary member.</summary>
|
||||
Member = 20,
|
||||
|
||||
/// <summary>May manage members and create vaults.</summary>
|
||||
Admin = 30,
|
||||
|
||||
/// <summary>Sole owner. Transferable.</summary>
|
||||
Owner = 40,
|
||||
}
|
||||
|
||||
/// <summary>State of a team membership.</summary>
|
||||
public enum MembershipStatus
|
||||
{
|
||||
/// <summary>Not a legal value.</summary>
|
||||
Unspecified = 0,
|
||||
|
||||
/// <summary>Invited but not yet accepted.</summary>
|
||||
Invited = 1,
|
||||
|
||||
/// <summary>Active member.</summary>
|
||||
Active = 2,
|
||||
|
||||
/// <summary>Revoked. Retained so audit history stays resolvable.</summary>
|
||||
Revoked = 3,
|
||||
}
|
||||
|
||||
/// <summary>Whether a vault belongs to one user or to a team.</summary>
|
||||
public enum VaultOwnerKind
|
||||
{
|
||||
/// <summary>Not a legal value.</summary>
|
||||
Unspecified = 0,
|
||||
|
||||
/// <summary>Owned by a single user.</summary>
|
||||
Personal = 1,
|
||||
|
||||
/// <summary>Owned by a team.</summary>
|
||||
Team = 2,
|
||||
}
|
||||
|
||||
/// <summary>Why a vault key grant exists.</summary>
|
||||
/// <remarks>
|
||||
/// Present from the first migration on purpose. Recovery is not a feature that can be bolted on
|
||||
/// later: the schema has to allow a vault key to be wrapped to something other than a member
|
||||
/// from the outset, or every existing vault becomes unrecoverable by design.
|
||||
/// </remarks>
|
||||
public enum GrantKind
|
||||
{
|
||||
/// <summary>Not a legal value.</summary>
|
||||
Unspecified = 0,
|
||||
|
||||
/// <summary>Wrapped to a member's identity key.</summary>
|
||||
Member = 1,
|
||||
|
||||
/// <summary>Wrapped to a recovery key held by the vault owner.</summary>
|
||||
Recovery = 2,
|
||||
|
||||
/// <summary>Wrapped to a team break-glass key. Opt-in; M5.</summary>
|
||||
Escrow = 3,
|
||||
}
|
||||
|
||||
/// <summary>State of a vault key grant.</summary>
|
||||
public enum GrantState
|
||||
{
|
||||
/// <summary>Not a legal value.</summary>
|
||||
Unspecified = 0,
|
||||
|
||||
/// <summary>Usable.</summary>
|
||||
Active = 1,
|
||||
|
||||
/// <summary>
|
||||
/// The recipient's identity key changed or the vault was rekeyed, so this grant must be
|
||||
/// re-wrapped by a member holding Share before the recipient can read the vault again.
|
||||
/// </summary>
|
||||
AwaitingRewrap = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Revoked. Blocks future reads only; anything already downloaded is already gone. See
|
||||
/// ADR 0001.
|
||||
/// </summary>
|
||||
Revoked = 3,
|
||||
}
|
||||
|
||||
/// <summary>Why a vault needs rekeying.</summary>
|
||||
public enum RekeyReason
|
||||
{
|
||||
/// <summary>No rekey pending.</summary>
|
||||
None = 0,
|
||||
|
||||
/// <summary>A member was removed.</summary>
|
||||
MemberRemoved = 1,
|
||||
|
||||
/// <summary>A member's identity key was rotated.</summary>
|
||||
KeyRotated = 2,
|
||||
|
||||
/// <summary>An operator or member requested it.</summary>
|
||||
Requested = 3,
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
namespace DodoSSH.Domain;
|
||||
|
||||
/// <summary>
|
||||
/// An SSH host.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// The only vault item type in M1. Everything sensitive — username, notes, jump chain, SSH
|
||||
/// options — lives inside <see cref="Payload"/>. There is deliberately no plaintext label:
|
||||
/// access-control administration happens in the client, which can decrypt names, so the server
|
||||
/// never needs a searchable title.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <see cref="Hostname"/> and <see cref="Port"/> are the one deliberate plaintext concession, and
|
||||
/// only when <see cref="RelayEnabled"/> is set. The relay must resolve its target server-side or
|
||||
/// it becomes an authenticated open TCP proxy into the operator's own network. A database CHECK
|
||||
/// constraint enforces the pairing so it cannot drift. See ADR 0004.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public sealed class Host
|
||||
{
|
||||
/// <summary>Primary key. UUIDv7, generated by the client so items can be created offline.</summary>
|
||||
public Guid Id { get; set; }
|
||||
|
||||
/// <summary>Owning vault.</summary>
|
||||
public Guid VaultId { get; set; }
|
||||
|
||||
/// <summary>Owning vault.</summary>
|
||||
public Vault? Vault { get; set; }
|
||||
|
||||
/// <summary>The encrypted item: a DSH1 envelope. Opaque to the server.</summary>
|
||||
public byte[] Payload { get; set; } = [];
|
||||
|
||||
/// <summary>The item's data key, wrapped under the vault key. Opaque.</summary>
|
||||
public byte[]? DataKeyWrap { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Reserved for per-item content keys wrapped to individual users, which is what will make
|
||||
/// per-item access control cryptographic rather than server-enforced. Present from the first
|
||||
/// migration so that lands without a migration; see docs/crypto.md §3.
|
||||
/// </summary>
|
||||
public Guid? ContentKeyId { get; set; }
|
||||
|
||||
/// <summary>Vault key generation this payload was encrypted under.</summary>
|
||||
public int KeyGeneration { get; set; }
|
||||
|
||||
/// <summary>AAD rule version, enabling a lazy re-encrypt-on-write migration later.</summary>
|
||||
public short PayloadAadVersion { get; set; }
|
||||
|
||||
/// <summary>Whether this host may be dialled through the server relay.</summary>
|
||||
public bool RelayEnabled { get; set; }
|
||||
|
||||
/// <summary>Target hostname. Permitted only when <see cref="RelayEnabled"/> is set.</summary>
|
||||
public string? Hostname { get; set; }
|
||||
|
||||
/// <summary>Target port. Permitted only when <see cref="RelayEnabled"/> is set.</summary>
|
||||
public int? Port { get; set; }
|
||||
|
||||
/// <summary>Owning group, for tree placement. Groups arrive in M2.</summary>
|
||||
public Guid? GroupId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Client-visible, monotonic item version. Used for optimistic concurrency on push, and
|
||||
/// deliberately distinct from the internal <c>xmin</c> guard, which is never exposed because
|
||||
/// it is not stable across VACUUM FREEZE.
|
||||
/// </summary>
|
||||
public int Version { get; set; }
|
||||
|
||||
/// <summary>Latest change-log sequence touching this row, so a delta pull can join directly.</summary>
|
||||
public long ChangeSequence { get; set; }
|
||||
|
||||
/// <summary>Creation timestamp.</summary>
|
||||
public DateTimeOffset CreatedAtUtc { get; set; }
|
||||
|
||||
/// <summary>Last modification timestamp.</summary>
|
||||
public DateTimeOffset UpdatedAtUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Soft-delete marker. Deletes are tombstones: a client that has been offline must be able to
|
||||
/// learn an item went away, and a vanished row is indistinguishable from one never seen.
|
||||
/// </summary>
|
||||
public DateTimeOffset? DeletedAtUtc { get; set; }
|
||||
|
||||
/// <summary>Who created it.</summary>
|
||||
public Guid CreatedByUserId { get; set; }
|
||||
|
||||
/// <summary>Who last modified it.</summary>
|
||||
public Guid UpdatedByUserId { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,242 @@
|
||||
namespace DodoSSH.Domain;
|
||||
|
||||
/// <summary>
|
||||
/// A user, keyed on their identity-provider subject.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Provisioned just-in-time on first authenticated request. Matching an existing account by
|
||||
/// email is an account-takeover vector and is therefore opt-in configuration, never the default.
|
||||
/// </remarks>
|
||||
public sealed class UserAccount
|
||||
{
|
||||
/// <summary>Primary key. UUIDv7, generated by the application.</summary>
|
||||
public Guid Id { get; set; }
|
||||
|
||||
/// <summary>OIDC issuer. Part of the natural key, so multiple providers can coexist.</summary>
|
||||
public string Issuer { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>OIDC subject.</summary>
|
||||
public string Subject { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>Email, for display and invitations. Case-insensitive.</summary>
|
||||
public string? Email { get; set; }
|
||||
|
||||
/// <summary>Display name.</summary>
|
||||
public string? DisplayName { get; set; }
|
||||
|
||||
/// <summary>Lifecycle state.</summary>
|
||||
public UserStatus Status { get; set; } = UserStatus.Active;
|
||||
|
||||
/// <summary>When the identity key was first enrolled; null until then.</summary>
|
||||
public DateTimeOffset? EnrolledAtUtc { get; set; }
|
||||
|
||||
/// <summary>Creation timestamp.</summary>
|
||||
public DateTimeOffset CreatedAtUtc { get; set; }
|
||||
|
||||
/// <summary>Last modification timestamp.</summary>
|
||||
public DateTimeOffset UpdatedAtUtc { get; set; }
|
||||
|
||||
/// <summary>Last authenticated request.</summary>
|
||||
public DateTimeOffset? LastSeenAtUtc { get; set; }
|
||||
|
||||
/// <summary>Soft-delete marker.</summary>
|
||||
public DateTimeOffset? DeletedAtUtc { get; set; }
|
||||
|
||||
/// <summary>Identity key generations, current and historic.</summary>
|
||||
public ICollection<UserKey> Keys { get; } = [];
|
||||
|
||||
/// <summary>Wraps of this user's secret bundle.</summary>
|
||||
public ICollection<UserKeyWrap> KeyWraps { get; } = [];
|
||||
|
||||
/// <summary>Enrolled devices.</summary>
|
||||
public ICollection<Device> Devices { get; } = [];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// One generation of a user's identity key pair. Public halves only.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// A separate table from the first migration, because retrofitting key rotation onto columns
|
||||
/// hanging off the user row is painful.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Encryption and signing keys are distinct: reusing one key for both agreement and signatures
|
||||
/// is a standing cryptographic mistake, and the signing key is what gives grants attribution
|
||||
/// that the server cannot forge.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public sealed class UserKey
|
||||
{
|
||||
/// <summary>Primary key.</summary>
|
||||
public Guid Id { get; set; }
|
||||
|
||||
/// <summary>Owning user.</summary>
|
||||
public Guid UserId { get; set; }
|
||||
|
||||
/// <summary>Owning user.</summary>
|
||||
public UserAccount? User { get; set; }
|
||||
|
||||
/// <summary>Generation number, starting at 1.</summary>
|
||||
public int Generation { get; set; }
|
||||
|
||||
/// <summary>X25519 public key, 32 bytes. Used for wrapping.</summary>
|
||||
public byte[] EncryptionPublicKey { get; set; } = [];
|
||||
|
||||
/// <summary>Ed25519 public key, 32 bytes. Used for signatures.</summary>
|
||||
public byte[] SigningPublicKey { get; set; } = [];
|
||||
|
||||
/// <summary>SHA-256 fingerprint over both public keys. See docs/crypto.md §8.</summary>
|
||||
public byte[] FingerprintSha256 { get; set; } = [];
|
||||
|
||||
/// <summary>The signed key statement, verbatim, as JSON.</summary>
|
||||
public string Statement { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>Ed25519 self-signature over the statement.</summary>
|
||||
public byte[] StatementSignature { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Evidence that the identity provider signed over this statement's hash: the verified
|
||||
/// claims of the binding ID token, as JSON. Retained so a client can audit the binding
|
||||
/// rather than trusting our word for it.
|
||||
/// </summary>
|
||||
public string? IdentityProviderBinding { get; set; }
|
||||
|
||||
/// <summary>Whether this is the user's current generation.</summary>
|
||||
public bool IsCurrent { get; set; }
|
||||
|
||||
/// <summary>Creation timestamp.</summary>
|
||||
public DateTimeOffset CreatedAtUtc { get; set; }
|
||||
|
||||
/// <summary>When this generation was superseded or revoked.</summary>
|
||||
public DateTimeOffset? RevokedAtUtc { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// One wrap of a user's secret bundle.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// KDF parameters are stored in plaintext beside the wrap. Salts are not secrets, and keeping
|
||||
/// the parameters with the wrap makes raising them later a per-user, unlock-time migration
|
||||
/// rather than a breaking change.
|
||||
/// </remarks>
|
||||
public sealed class UserKeyWrap
|
||||
{
|
||||
/// <summary>Primary key.</summary>
|
||||
public Guid Id { get; set; }
|
||||
|
||||
/// <summary>Owning user.</summary>
|
||||
public Guid UserId { get; set; }
|
||||
|
||||
/// <summary>Owning user.</summary>
|
||||
public UserAccount? User { get; set; }
|
||||
|
||||
/// <summary>Which key this wrap is under.</summary>
|
||||
public UserKeyWrapKind Kind { get; set; }
|
||||
|
||||
/// <summary>The device, for <see cref="UserKeyWrapKind.Device"/> wraps.</summary>
|
||||
public Guid? DeviceId { get; set; }
|
||||
|
||||
/// <summary>The device, for <see cref="UserKeyWrapKind.Device"/> wraps.</summary>
|
||||
public Device? Device { get; set; }
|
||||
|
||||
/// <summary>The wrapped bundle: an opaque DSH1 envelope.</summary>
|
||||
public byte[] Wrap { get; set; } = [];
|
||||
|
||||
/// <summary>Optimistic concurrency guard against two devices racing a passphrase change.</summary>
|
||||
public int WrapVersion { get; set; }
|
||||
|
||||
/// <summary>KDF identifier, for password-derived wraps.</summary>
|
||||
public string? KdfAlgorithm { get; set; }
|
||||
|
||||
/// <summary>KDF salt. Not a secret.</summary>
|
||||
public byte[]? KdfSalt { get; set; }
|
||||
|
||||
/// <summary>Argon2id memory cost, in kibibytes.</summary>
|
||||
public int? KdfMemoryKibibytes { get; set; }
|
||||
|
||||
/// <summary>Argon2id pass count.</summary>
|
||||
public int? KdfPasses { get; set; }
|
||||
|
||||
/// <summary>Argon2id lanes. Always 1; libsodium supports no other value.</summary>
|
||||
public int? KdfParallelism { get; set; }
|
||||
|
||||
/// <summary>Creation timestamp.</summary>
|
||||
public DateTimeOffset CreatedAtUtc { get; set; }
|
||||
|
||||
/// <summary>Last successful unlock through this wrap.</summary>
|
||||
public DateTimeOffset? LastUsedAtUtc { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A device enrolled for unlock without re-entering the passphrase.
|
||||
/// </summary>
|
||||
public sealed class Device
|
||||
{
|
||||
/// <summary>Primary key.</summary>
|
||||
public Guid Id { get; set; }
|
||||
|
||||
/// <summary>Owning user.</summary>
|
||||
public Guid UserId { get; set; }
|
||||
|
||||
/// <summary>Owning user.</summary>
|
||||
public UserAccount? User { get; set; }
|
||||
|
||||
/// <summary>Human-readable name.</summary>
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>Operating system family.</summary>
|
||||
public DevicePlatform Platform { get; set; }
|
||||
|
||||
/// <summary>The device's X25519 public key. Its private half lives in the OS keystore.</summary>
|
||||
public byte[] PublicKey { get; set; } = [];
|
||||
|
||||
/// <summary>Enrollment timestamp.</summary>
|
||||
public DateTimeOffset EnrolledAtUtc { get; set; }
|
||||
|
||||
/// <summary>Last activity.</summary>
|
||||
public DateTimeOffset? LastSeenAtUtc { get; set; }
|
||||
|
||||
/// <summary>Revocation timestamp.</summary>
|
||||
public DateTimeOffset? RevokedAtUtc { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An append-only log of every identity key statement ever published.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Cheap key transparency. Every signed grant records the log head its signer observed, so for
|
||||
/// the server to show two clients divergent views of a user's keys it must keep both forks
|
||||
/// consistent across every subsequent shared operation. Any two clients touching the same vault
|
||||
/// will then surface the mismatch. This converts an otherwise undetectable key-substitution
|
||||
/// attack into a detectable one; it does not prevent it. See ADR 0001.
|
||||
/// </remarks>
|
||||
public sealed class KeyLogEntry
|
||||
{
|
||||
/// <summary>Monotonic sequence. Database-generated.</summary>
|
||||
public long Sequence { get; set; }
|
||||
|
||||
/// <summary>The user whose key this is.</summary>
|
||||
public Guid UserId { get; set; }
|
||||
|
||||
/// <summary>Generation published.</summary>
|
||||
public int Generation { get; set; }
|
||||
|
||||
/// <summary>X25519 public key.</summary>
|
||||
public byte[] EncryptionPublicKey { get; set; } = [];
|
||||
|
||||
/// <summary>Ed25519 public key.</summary>
|
||||
public byte[] SigningPublicKey { get; set; } = [];
|
||||
|
||||
/// <summary>Ed25519 self-signature over the key statement.</summary>
|
||||
public byte[] StatementSignature { get; set; } = [];
|
||||
|
||||
/// <summary>Hash of the preceding entry, forming the chain.</summary>
|
||||
public byte[] PreviousHash { get; set; } = [];
|
||||
|
||||
/// <summary>Hash of this entry, over the previous hash and this entry's contents.</summary>
|
||||
public byte[] Hash { get; set; } = [];
|
||||
|
||||
/// <summary>Creation timestamp.</summary>
|
||||
public DateTimeOffset CreatedAtUtc { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
namespace DodoSSH.Domain;
|
||||
|
||||
/// <summary>What a change did to an entity.</summary>
|
||||
public enum ChangeOperation
|
||||
{
|
||||
/// <summary>Not a legal value.</summary>
|
||||
Unspecified = 0,
|
||||
|
||||
/// <summary>Created or modified.</summary>
|
||||
Upsert = 1,
|
||||
|
||||
/// <summary>Soft-deleted, leaving a tombstone.</summary>
|
||||
Delete = 2,
|
||||
}
|
||||
|
||||
/// <summary>The kind of item a change refers to. Mirrors the contract enum; append only.</summary>
|
||||
public enum ChangeEntityType
|
||||
{
|
||||
/// <summary>Not a legal value.</summary>
|
||||
Unspecified = 0,
|
||||
|
||||
/// <summary>An SSH host.</summary>
|
||||
Host = 1,
|
||||
|
||||
/// <summary>A credential. M2.</summary>
|
||||
Credential = 2,
|
||||
|
||||
/// <summary>An SSH key pair. M2.</summary>
|
||||
SshKey = 3,
|
||||
|
||||
/// <summary>A host group. M2.</summary>
|
||||
HostGroup = 4,
|
||||
|
||||
/// <summary>A tag. M2.</summary>
|
||||
Tag = 5,
|
||||
|
||||
/// <summary>A host-to-tag association. M2.</summary>
|
||||
HostTag = 6,
|
||||
|
||||
/// <summary>A host-to-credential association. M2.</summary>
|
||||
HostCredential = 7,
|
||||
|
||||
/// <summary>A snippet. M2.</summary>
|
||||
Snippet = 8,
|
||||
|
||||
/// <summary>A port forward. M2.</summary>
|
||||
PortForward = 9,
|
||||
|
||||
/// <summary>A known SSH host key. M2.</summary>
|
||||
KnownHostKey = 10,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// One entry in a vault's change log, which is what delta sync reads.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// <see cref="Sequence"/> comes from a <c>bigserial</c>, and that carries a trap worth stating
|
||||
/// where the code lives: sequence values are handed out <em>before</em> commit. If transaction A
|
||||
/// takes 5 and B takes 6 but B commits first, a reader that advances its cursor to 6 permanently
|
||||
/// misses 5 — silent sync corruption that only appears under concurrent writes to one vault.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Every push therefore takes a per-vault transaction-scoped advisory lock as its first
|
||||
/// statement, so sequence order equals commit order. See ADR 0003.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public sealed class SyncChange
|
||||
{
|
||||
/// <summary>Monotonic sequence. Database-generated.</summary>
|
||||
public long Sequence { get; set; }
|
||||
|
||||
/// <summary>Owning vault. Cursors are scoped per vault.</summary>
|
||||
public Guid VaultId { get; set; }
|
||||
|
||||
/// <summary>Kind of item.</summary>
|
||||
public ChangeEntityType EntityType { get; set; }
|
||||
|
||||
/// <summary>The item.</summary>
|
||||
public Guid EntityId { get; set; }
|
||||
|
||||
/// <summary>What happened.</summary>
|
||||
public ChangeOperation Operation { get; set; }
|
||||
|
||||
/// <summary>The item's version after the change.</summary>
|
||||
public int Revision { get; set; }
|
||||
|
||||
/// <summary>Who made the change.</summary>
|
||||
public Guid ActorUserId { get; set; }
|
||||
|
||||
/// <summary>When it was recorded.</summary>
|
||||
public DateTimeOffset OccurredAtUtc { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Records that a client operation was applied, so a retry is a no-op.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Keyed on the client-generated operation id, which makes retries exactly-once at
|
||||
/// <em>operation</em> granularity. A batch-level idempotency key alone would not: a client that
|
||||
/// times out mid-push and retries with a partially overlapping batch would otherwise double-apply
|
||||
/// the operations that did land.
|
||||
/// </remarks>
|
||||
public sealed class SyncOperationReceipt
|
||||
{
|
||||
/// <summary>The client-generated operation id. Primary key.</summary>
|
||||
public Guid OperationId { get; set; }
|
||||
|
||||
/// <summary>Vault the operation targeted.</summary>
|
||||
public Guid VaultId { get; set; }
|
||||
|
||||
/// <summary>Change-log sequence produced, when the operation was applied.</summary>
|
||||
public long? AppliedChangeSequence { get; set; }
|
||||
|
||||
/// <summary>The item's version after the operation.</summary>
|
||||
public int? ResultVersion { get; set; }
|
||||
|
||||
/// <summary>Creation timestamp.</summary>
|
||||
public DateTimeOffset CreatedAtUtc { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
namespace DodoSSH.Domain;
|
||||
|
||||
/// <summary>
|
||||
/// A group of users who can share vaults.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The tables exist from the first migration although team features ship in M3. Adding them
|
||||
/// later would mean altering <see cref="Vault"/> to introduce a foreign key on a live table, and
|
||||
/// the cost of carrying two unused tables is far lower than that.
|
||||
/// </remarks>
|
||||
public sealed class Team
|
||||
{
|
||||
/// <summary>Primary key.</summary>
|
||||
public Guid Id { get; set; }
|
||||
|
||||
/// <summary>Display name.</summary>
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>URL-safe unique identifier.</summary>
|
||||
public string Slug { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>Optional description.</summary>
|
||||
public string? Description { get; set; }
|
||||
|
||||
/// <summary>Who created it.</summary>
|
||||
public Guid CreatedByUserId { get; set; }
|
||||
|
||||
/// <summary>Creation timestamp.</summary>
|
||||
public DateTimeOffset CreatedAtUtc { get; set; }
|
||||
|
||||
/// <summary>Soft-delete marker.</summary>
|
||||
public DateTimeOffset? DeletedAtUtc { get; set; }
|
||||
|
||||
/// <summary>Members.</summary>
|
||||
public ICollection<TeamMembership> Memberships { get; } = [];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A user's membership of a team.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Revoked memberships are retained rather than deleted, so historic audit entries remain
|
||||
/// resolvable to a person.
|
||||
/// </remarks>
|
||||
public sealed class TeamMembership
|
||||
{
|
||||
/// <summary>Primary key.</summary>
|
||||
public Guid Id { get; set; }
|
||||
|
||||
/// <summary>The team.</summary>
|
||||
public Guid TeamId { get; set; }
|
||||
|
||||
/// <summary>The team.</summary>
|
||||
public Team? Team { get; set; }
|
||||
|
||||
/// <summary>The member.</summary>
|
||||
public Guid UserId { get; set; }
|
||||
|
||||
/// <summary>The member.</summary>
|
||||
public UserAccount? User { get; set; }
|
||||
|
||||
/// <summary>Role within the team.</summary>
|
||||
public TeamRole Role { get; set; }
|
||||
|
||||
/// <summary>Membership state.</summary>
|
||||
public MembershipStatus Status { get; set; }
|
||||
|
||||
/// <summary>Who invited them.</summary>
|
||||
public Guid? InvitedByUserId { get; set; }
|
||||
|
||||
/// <summary>When the invitation was accepted.</summary>
|
||||
public DateTimeOffset? JoinedAtUtc { get; set; }
|
||||
|
||||
/// <summary>Creation timestamp.</summary>
|
||||
public DateTimeOffset CreatedAtUtc { get; set; }
|
||||
|
||||
/// <summary>Soft-delete marker.</summary>
|
||||
public DateTimeOffset? DeletedAtUtc { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
namespace DodoSSH.Domain;
|
||||
|
||||
/// <summary>
|
||||
/// A container of encrypted items sharing one vault key.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The vault name is plaintext, unlike item names. A user has to be able to pick a vault before
|
||||
/// anything is decrypted, and vault names are few and low-signal compared with a full host
|
||||
/// inventory.
|
||||
/// </remarks>
|
||||
public sealed class Vault
|
||||
{
|
||||
/// <summary>Primary key.</summary>
|
||||
public Guid Id { get; set; }
|
||||
|
||||
/// <summary>Display name.</summary>
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>Whether this belongs to a user or a team.</summary>
|
||||
public VaultOwnerKind OwnerKind { get; set; }
|
||||
|
||||
/// <summary>Owning user, for a personal vault.</summary>
|
||||
public Guid? OwnerUserId { get; set; }
|
||||
|
||||
/// <summary>Owning user, for a personal vault.</summary>
|
||||
public UserAccount? OwnerUser { get; set; }
|
||||
|
||||
/// <summary>Owning team, for a team vault.</summary>
|
||||
public Guid? TeamId { get; set; }
|
||||
|
||||
/// <summary>Owning team, for a team vault.</summary>
|
||||
public Team? Team { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Current key generation. Bumped on rekey, and part of every item's AAD, so a server cannot
|
||||
/// roll a row back to a superseded generation.
|
||||
/// </summary>
|
||||
public int KeyGeneration { get; set; } = 1;
|
||||
|
||||
/// <summary>Whether a membership or key change has left this vault needing a rekey.</summary>
|
||||
public bool RekeyRequired { get; set; }
|
||||
|
||||
/// <summary>Why a rekey is pending.</summary>
|
||||
public RekeyReason RekeyReason { get; set; }
|
||||
|
||||
/// <summary>Creation timestamp.</summary>
|
||||
public DateTimeOffset CreatedAtUtc { get; set; }
|
||||
|
||||
/// <summary>Last modification timestamp.</summary>
|
||||
public DateTimeOffset UpdatedAtUtc { get; set; }
|
||||
|
||||
/// <summary>Soft-delete marker.</summary>
|
||||
public DateTimeOffset? DeletedAtUtc { get; set; }
|
||||
|
||||
/// <summary>Wrapped vault keys, one per recipient per generation.</summary>
|
||||
public ICollection<VaultKeyGrant> KeyGrants { get; } = [];
|
||||
|
||||
/// <summary>Hosts in this vault.</summary>
|
||||
public ICollection<Host> Hosts { get; } = [];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A vault key wrapped to one recipient, for one key generation.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// The server stores <see cref="WrappedKey"/> verbatim and cannot verify that it is the correct
|
||||
/// vault key. A malicious granter can seal garbage; the recipient detects it on first unwrap as a
|
||||
/// tag failure, and <see cref="Signature"/> names who did it. Detectable and attributable is the
|
||||
/// right failure mode here — silent is not achievable, since verification would require the
|
||||
/// server to hold the key.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <see cref="GranterKeyFingerprint"/> and <see cref="KeyLogHead"/> are recorded so a recipient
|
||||
/// can check both who wrapped this and what view of the key log they held at the time.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public sealed class VaultKeyGrant
|
||||
{
|
||||
/// <summary>Primary key.</summary>
|
||||
public Guid Id { get; set; }
|
||||
|
||||
/// <summary>The vault.</summary>
|
||||
public Guid VaultId { get; set; }
|
||||
|
||||
/// <summary>The vault.</summary>
|
||||
public Vault? Vault { get; set; }
|
||||
|
||||
/// <summary>Key generation this grant is for.</summary>
|
||||
public int KeyGeneration { get; set; }
|
||||
|
||||
/// <summary>Why this grant exists: a member, a recovery key, or escrow.</summary>
|
||||
public GrantKind Kind { get; set; }
|
||||
|
||||
/// <summary>Recipient, for a member grant.</summary>
|
||||
public Guid? RecipientUserId { get; set; }
|
||||
|
||||
/// <summary>Recipient, for a member grant.</summary>
|
||||
public UserAccount? RecipientUser { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Fingerprint of the exact public key this was wrapped to, so a later key rotation
|
||||
/// invalidates the grant explicitly rather than silently.
|
||||
/// </summary>
|
||||
public byte[] RecipientKeyFingerprint { get; set; } = [];
|
||||
|
||||
/// <summary>The vault key, sealed to the recipient. Opaque.</summary>
|
||||
public byte[] WrappedKey { get; set; } = [];
|
||||
|
||||
/// <summary>Who created this grant.</summary>
|
||||
public Guid GranterUserId { get; set; }
|
||||
|
||||
/// <summary>Fingerprint of the granter's identity key.</summary>
|
||||
public byte[] GranterKeyFingerprint { get; set; } = [];
|
||||
|
||||
/// <summary>Key log head the granter observed. Enables fork detection.</summary>
|
||||
public byte[]? KeyLogHead { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Ed25519 signature by the granter over the canonical grant tuple. Verified by clients, not
|
||||
/// by the server: server-side verification would be a convenience, never the boundary.
|
||||
/// </summary>
|
||||
public byte[] Signature { get; set; } = [];
|
||||
|
||||
/// <summary>Grant state.</summary>
|
||||
public GrantState State { get; set; }
|
||||
|
||||
/// <summary>Creation timestamp.</summary>
|
||||
public DateTimeOffset CreatedAtUtc { get; set; }
|
||||
|
||||
/// <summary>Revocation timestamp.</summary>
|
||||
public DateTimeOffset? RevokedAtUtc { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user