Files
coder/database/migrations/000003_workspaces.up.sql
T
Kyle Carberry 8958b641e9 feat: Add agent authentication based on instance ID (#336)
* feat: Add agent authentication based on instance ID

Each cloud has it's own unique instance identity signatures, which
can be used for zero-token authentication. This change adds support
for tracking by "instance_id", and automatically authenticating
with Google Cloud.

* Add test for CLI

* Fix workspace agent request name

* Fix race with adding to wait group

* Fix name of instance identity token
2022-02-21 20:36:29 +00:00

68 lines
2.2 KiB
SQL

CREATE TABLE workspace (
id uuid NOT NULL UNIQUE,
created_at timestamptz NOT NULL,
updated_at timestamptz NOT NULL,
owner_id text NOT NULL,
project_id uuid NOT NULL REFERENCES project (id),
name varchar(64) NOT NULL,
UNIQUE(owner_id, name)
);
CREATE TYPE workspace_transition AS ENUM (
'start',
'stop',
'delete'
);
-- Workspace transition represents a change in workspace state.
CREATE TABLE workspace_history (
id uuid NOT NULL UNIQUE,
created_at timestamptz NOT NULL,
updated_at timestamptz NOT NULL,
workspace_id uuid NOT NULL REFERENCES workspace (id) ON DELETE CASCADE,
project_version_id uuid NOT NULL REFERENCES project_version (id) ON DELETE CASCADE,
name varchar(64) NOT NULL,
before_id uuid,
after_id uuid,
transition workspace_transition NOT NULL,
initiator varchar(255) NOT NULL,
-- State stored by the provisioner
provisioner_state bytea,
-- Job ID of the action
provision_job_id uuid NOT NULL,
UNIQUE(workspace_id, name)
);
-- Cloud resources produced by a provision job.
CREATE TABLE workspace_resource (
id uuid NOT NULL UNIQUE,
created_at timestamptz NOT NULL,
workspace_history_id uuid NOT NULL REFERENCES workspace_history (id) ON DELETE CASCADE,
-- A unique identifier for the resource. This can be used
-- to exchange for an agent token with various providers.
instance_id varchar(64),
-- Resource type produced by a provisioner.
-- eg. "google_compute_instance"
type varchar(256) NOT NULL,
-- Name of the resource.
-- eg. "kyle-dev-instance"
name varchar(64) NOT NULL,
-- Token for an agent to connect.
workspace_agent_token varchar(128) NOT NULL UNIQUE,
-- If an agent has been conencted for this resource,
-- the agent table is not null.
workspace_agent_id uuid,
UNIQUE(workspace_history_id, type, name)
);
CREATE TABLE workspace_agent (
id uuid NOT NULL UNIQUE,
workspace_resource_id uuid NOT NULL REFERENCES workspace_resource (id) ON DELETE CASCADE,
created_at timestamptz NOT NULL,
updated_at timestamptz NOT NULL,
-- Identifies instance architecture, cloud, etc.
instance_metadata jsonb NOT NULL,
-- Identifies resources.
resource_metadata jsonb NOT NULL
);