Merge remote-tracking branch 'origin/main' into llb-byow

This commit is contained in:
Jeff Mitchell committed 2022-06-15 16:45:00 -05:00
commit 704d68848c
160 files changed
+15933 -4684

No files matched your search

@@ -29,6 +29,7 @@ begin;
create trigger immutable_columns before update on target_credential_library
for each row execute procedure immutable_columns('target_id', 'credential_library_id', 'credential_purpose', 'create_time');
-- replaced in 33/02_target.up.sql
-- target_library provides the store id along with the other data stored in
-- target_credential_library
create view target_library
@@ -2,6 +2,7 @@ begin;
create table credential_type_enm (
name text primary key
-- This constraint is replaced in 32/01_credential_type.up.sql
constraint only_predefined_credential_types_allowed
check (
name in (
@@ -0,0 +1,23 @@
begin;
-- drop constraint so we can migrate user_password to username_password
alter table credential_type_enm
drop constraint only_predefined_credential_types_allowed;
-- Next: we will update user_password to username_password
update credential_type_enm
set name = 'username_password'
where name = 'user_password';
-- Add new constraint that only allows unspecified and new username_password
-- This replaces the constraint defined in 2/02_credential_type.up.sql
alter table credential_type_enm
add constraint only_predefined_credential_types_allowed
check (
name in (
'unspecified',
'username_password'
)
);
commit;
@@ -0,0 +1,118 @@
begin;
create table credential_static_store (
public_id wt_public_id primary key,
scope_id wt_scope_id not null
constraint iam_scope_fkey
references iam_scope (public_id)
on delete cascade
on update cascade,
name wt_name,
description wt_description,
create_time wt_timestamp,
update_time wt_timestamp,
version wt_version,
constraint credential_store_fkey
foreign key (scope_id, public_id)
references credential_store (scope_id, public_id)
on delete cascade
on update cascade,
constraint credential_static_store_scope_id_name_uq
unique(scope_id, name)
);
comment on table credential_static_store is
'credential_static_store is a table where each row is a resource that represents a static credential store. '
'It is a credential_store subtype and an aggregate root.';
create trigger update_version_column after update on credential_static_store
for each row execute procedure update_version_column();
create trigger update_time_column before update on credential_static_store
for each row execute procedure update_time_column();
create trigger default_create_time_column before insert on credential_static_store
for each row execute procedure default_create_time();
create trigger immutable_columns before update on credential_static_store
for each row execute procedure immutable_columns('public_id', 'scope_id','create_time');
create trigger insert_credential_store_subtype before insert on credential_static_store
for each row execute procedure insert_credential_store_subtype();
create trigger delete_credential_store_subtype after delete on credential_static_store
for each row execute procedure delete_credential_store_subtype();
create table credential_static_username_password_credential (
public_id wt_public_id primary key,
store_id wt_public_id not null
constraint credential_static_store_fkey
references credential_static_store (public_id)
on delete cascade
on update cascade,
name wt_name,
description wt_description,
create_time wt_timestamp,
update_time wt_timestamp,
version wt_version,
username text not null
constraint username_must_not_be_empty
check(length(trim(username)) > 0),
password_encrypted bytea not null
constraint password_encrypted_must_not_be_empty
check(length(password_encrypted) > 0),
password_hmac bytea not null
constraint password_hmac_must_not_be_empty
check(length(password_hmac) > 0),
key_id text not null
constraint kms_data_key_version_fkey
references kms_data_key_version (private_id)
on delete restrict
on update cascade,
constraint credential_static_fkey
foreign key (store_id, public_id)
references credential_static (store_id, public_id)
on delete cascade
on update cascade,
constraint credential_static_username_password_credential_store_id_name_uq
unique(store_id, name),
-- The name of this constraint does not follow our naming conventions for
-- unique constraints because it would be to long. The max length for
-- identifiers in PostgreSQL is 63 characters.
-- credential_static_username_password_credential_store_id_public_id_uq
-- is 68 characters.
--
-- https://www.postgresql.org/docs/current/limits.html
constraint credential_static_username_password_store_id_public_id_uq
unique(store_id, public_id)
);
comment on table credential_static_username_password_credential is
'credential_static_username_password_credential is a table where each row is a resource that represents a static username password credential. '
'It is a credential_static subtype and an aggregate root.';
create trigger update_version_column after update on credential_static_username_password_credential
for each row execute procedure update_version_column();
create trigger update_time_column before update on credential_static_username_password_credential
for each row execute procedure update_time_column();
create trigger default_create_time_column before insert on credential_static_username_password_credential
for each row execute procedure default_create_time();
create trigger immutable_columns before update on credential_static_username_password_credential
for each row execute procedure immutable_columns('public_id', 'store_id','create_time');
create trigger insert_credential_static_subtype before insert on credential_static_username_password_credential
for each row execute procedure insert_credential_static_subtype();
create trigger delete_credential_static_subtype after delete on credential_static_username_password_credential
for each row execute procedure delete_credential_static_subtype();
insert into oplog_ticket (name, version)
values
('credential_static_store', 1),
('credential_static_username_password_credential', 1);
commit;
@@ -0,0 +1,82 @@
begin;
-- target_static_credential does not follow the normal table naming convention of target_credential_static
create table target_static_credential (
target_id wt_public_id not null
constraint target_fkey
references target (public_id)
on delete cascade
on update cascade,
credential_static_id wt_public_id not null
constraint credential_static_fkey
references credential_static (public_id)
on delete cascade
on update cascade,
credential_purpose text not null
constraint credential_purpose_enm_fkey
references credential_purpose_enm (name)
on delete restrict
on update cascade,
create_time wt_timestamp,
primary key(target_id, credential_static_id, credential_purpose)
);
comment on table target_static_credential is
'target_static_credential is a join table between the target, credential_static, and credential_purpose_enm tables. '
'A row in the target_static_credential table represents the assignment of a static credential to a target for the specified purpose.';
create trigger default_create_time_column before insert on target_static_credential
for each row execute procedure default_create_time();
create trigger immutable_columns before update on target_static_credential
for each row execute procedure immutable_columns('target_id', 'credential_static_id', 'credential_purpose', 'create_time');
-- replaces view from 10/05_target.up.sql
drop view target_library;
-- target_credential_source provides the store id along with the other data stored in
-- target_credential_library and target_static_credential
create view target_credential_source
as
select
tcl.target_id,
tcl.credential_library_id as credential_source_id,
tcl.credential_purpose,
cl.store_id,
'library' as type
from
target_credential_library tcl,
credential_library cl
where
cl.public_id = tcl.credential_library_id
union
select
tcs.target_id,
tcs.credential_static_id as credential_source_id,
tcs.credential_purpose,
cst.store_id,
'static' as type
from
target_static_credential tcs,
credential_static cst
where
cst.public_id = tcs.credential_static_id;
comment on view target_credential_source is
'target_credential_source is a view where each row contains a credential source and the id of the parent credential store. '
'No encrypted data is returned. This view can be used to retrieve data which will be returned external to boundary.';
create view credential_source_all_types
as
select
public_id,
'library' as type
from
credential_library
union
select
public_id,
'static' as type
from
credential_static;
comment on view credential_source_all_types is
'credential_source_all_types is a view where each row contains the credential source id and type.';
commit;
@@ -0,0 +1,32 @@
begin;
create table session_credential_static (
session_id wt_public_id not null
constraint session_fkey
references session (public_id)
on delete cascade
on update cascade,
credential_static_id wt_public_id
constraint credential_static_fkey
references credential_static (public_id)
on delete cascade
on update cascade,
credential_purpose text not null
constraint credential_purpose_fkey
references credential_purpose_enm (name)
on delete restrict
on update cascade,
primary key(session_id, credential_static_id, credential_purpose),
create_time wt_timestamp
);
comment on table session_credential_dynamic is
'session_credential_static is a join table between the session and static credential tables. '
'It also contains the credential purpose the relationship represents.';
create trigger default_create_time_column before insert on session_credential_static
for each row execute procedure default_create_time();
create trigger immutable_columns before update on session_credential_static
for each row execute procedure immutable_columns('session_id', 'credential_static_id', 'credential_purpose', 'create_time');
commit;