Add worker tagging (#862)

This allows workers to have tags assigned to them, which can then be filtered to control which targets they are allowed to serve.
This commit is contained in:
Jeff Mitchell authored and GitHub committed 2021-01-21 16:27:20 -05:00
1 parent 595a86508e
commit 717a3b52ee
54 files changed
+2150 -666

No files matched your search

+140 -2
View File
@@ -4,8 +4,8 @@ package schema
func init() {
migrationStates["postgres"] = migrationState{
devMigration: false,
binarySchemaVersion: 69,
devMigration: true,
binarySchemaVersion: 1001,
upMigrations: map[int][]byte{
1: []byte(`
begin;
@@ -2930,6 +2930,7 @@ before insert on target_tcp
-- target_all_subtypes is a union of all target subtypes
-- NOTE: this is replaced in 100 to add worker_filter
create view target_all_subtypes
as
select
@@ -3127,6 +3128,7 @@ begin;
endpoint text -- not part of the warehouse, used to send info to the worker
);
-- Replaced in 100 to add worker_filter
create trigger
immutable_columns
before
@@ -3422,6 +3424,7 @@ begin;
create trigger insert_session_state before insert on session_state
for each row execute procedure insert_session_state();
-- Replaced in 100 to add worker_filter
create view session_with_state as
select
s.public_id,
@@ -4861,6 +4864,131 @@ begin;
commit;
`),
1001: []byte(`
begin;
-- This series of expressions fixes the primary key on the server table
alter table session
drop constraint session_server_id_server_type_fkey;
alter table server
drop constraint server_pkey;
alter table server
drop column name;
alter table server
add primary key (private_id);
alter table server
add constraint server_id_must_not_be_empty
check(length(trim(private_id)) > 0);
alter table session
add constraint session_server_id_fkey
foreign key (server_id)
references server(private_id)
on delete set null
on update cascade;
create domain wt_bexprfilter as text
check(
value is null
or
(
length(trim(value)) > 0
and
length(trim(value)) <= 2048
)
);
comment on domain wt_bexprfilter is
'Text field with constraints for go-bexpr filters';
-- Add the worker filter to the target_tcp table and session table
alter table target_tcp
add column worker_filter wt_bexprfilter;
alter table session
add column worker_filter wt_bexprfilter;
-- Replace the immutable columns trigger from 50 to add worker_filter
drop trigger immutable_columns on session;
create trigger immutable_columns
before update on session
for each row execute procedure immutable_columns('public_id', 'certificate', 'expiration_time', 'connection_limit', 'create_time', 'endpoint', 'worker_filter');
-- Replaces the view created in 41 to include worker_filter
drop view target_all_subtypes;
create view target_all_subtypes
as
select
public_id,
scope_id,
name,
description,
default_port,
session_max_seconds,
session_connection_limit,
version,
create_time,
update_time,
worker_filter,
'tcp' as type
from target_tcp;
-- Replaces the view created in 50 to include worker_filter
drop view session_with_state;
create view session_with_state as
select
s.public_id,
s.user_id,
s.host_id,
s.server_id,
s.server_type,
s.target_id,
s.host_set_id,
s.auth_token_id,
s.scope_id,
s.certificate,
s.expiration_time,
s.connection_limit,
s.tofu_token,
s.key_id,
s.termination_reason,
s.version,
s.create_time,
s.update_time,
s.endpoint,
s.worker_filter,
ss.state,
ss.previous_end_time,
ss.start_time,
ss.end_time
from
session s,
session_state ss
where
s.public_id = ss.session_id;
create domain wt_tagpair as text
check(
value is not null
and
length(trim(value)) > 0
and
length(trim(value)) <= 512
and
lower(trim(value)) = value
);
comment on domain wt_tagpair is
'Text field with constraints for key/value pairs';
create table server_tag (
server_id text
references server(private_id)
on delete cascade
on update cascade,
key wt_tagpair,
value wt_tagpair,
primary key(server_id, key, value)
);
commit;
`),
},
downMigrations: map[int][]byte{
@@ -5216,6 +5344,16 @@ begin;
commit;
`),
1001: []byte(`
begin;
drop domain wt_bexprfilter;
drop table server_tag;
drop domain wt_tagpair;
commit;
`),
},
}