OXYGENHUB
◆ v0.9.24 oxygenhub / crates / hub / migrations-pg / 0075_agent_grants.sql
914 B · SQL · last changed Agent grants: agents act for their owner with no key (keyless step 5) 18 days ago source blame history raw
1
-- Agent grants (oxygenhub#241, keyless step 5): an account lets an agent
2
-- act for it. `grant` is the Oxygen grant its owner's key signed (spec
3
-- §14.7), which every certificate issued under it carries; the agent
4
-- holds only the token, which it exchanges for ten-minute certificates
5
-- and which signs nothing itself. Revoking stops the certificates.
6
CREATE TABLE agent_grants (
7
    id           BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
8
    account_id   BIGINT NOT NULL REFERENCES accounts(id) ON DELETE CASCADE,
9
    agent        TEXT NOT NULL,
10
    subject      TEXT NOT NULL,
11
    grantor      TEXT NOT NULL,
12
    scope        TEXT NOT NULL,
13
    signed       BYTEA NOT NULL,
14
    token_hash   TEXT NOT NULL UNIQUE,
15
    created_ms   BIGINT NOT NULL,
16
    expires_ms   BIGINT NOT NULL,
17
    revoked_ms   BIGINT,
18
    last_used_ms BIGINT
19
);
20
CREATE INDEX agent_grants_account ON agent_grants(account_id);