diff --git a/internal/db/schema/migrations/oss/postgres/64/01_ssh_targets.up.sql b/internal/db/schema/migrations/oss/postgres/64/01_ssh_targets.up.sql index ee40098af..37fc815cc 100644 --- a/internal/db/schema/migrations/oss/postgres/64/01_ssh_targets.up.sql +++ b/internal/db/schema/migrations/oss/postgres/64/01_ssh_targets.up.sql @@ -79,7 +79,7 @@ begin; drop view if exists whx_credential_dimension_source; drop view if exists target_all_subtypes; - -- Replaced in oss/70/08_targets.up.sql + -- Replaced in oss/70/09_targets.up.sql create view target_all_subtypes as select public_id, @@ -116,7 +116,7 @@ begin; from target_ssh; - -- Replaced in oss/70/08_targets.up.sql + -- Replaced in oss/70/09_targets.up.sql create view whx_host_dimension_source as with host_sources ( @@ -249,7 +249,7 @@ begin; -- The whx_credential_dimension_source view shows the current values in the -- operational tables of the credential dimension. - -- Replaced in oss/70/08_targets.up.sql + -- Replaced in oss/70/09_targets.up.sql create view whx_credential_dimension_source as with vault_generic_library as ( select vcl.public_id as public_id, diff --git a/internal/db/schema/migrations/oss/postgres/70/08_session_recording_views.up.sql b/internal/db/schema/migrations/oss/postgres/70/08_session_recording_views.up.sql new file mode 100644 index 000000000..20bac1ce5 --- /dev/null +++ b/internal/db/schema/migrations/oss/postgres/70/08_session_recording_views.up.sql @@ -0,0 +1,38 @@ +-- Copyright (c) HashiCorp, Inc. +-- SPDX-License-Identifier: MPL-2.0 + +begin; + +create view session_recording_aggregate as +select + rs.public_id, + rs.storage_bucket_id, + rs.session_id, + rs.create_time, + rs.update_time, + rs.start_time, + rs.end_time, + sb.scope_id as storage_bucket_scope_id, + -- fields that cover the user fields at creation time + uh.public_id as user_history_public_id, + uh.name as user_history_name, + uh.description as user_history_description, + uh.scope_id as user_history_scope_id, + -- fields that cover the user's scope information at creation time + ush.public_id as user_scope_history_public_id, + ush.name as user_scope_history_name, + ush.description as user_scope_history_description, + ush.type as user_scope_history_type, + ush.parent_id as user_scope_history_parent_id, + ush.primary_auth_method_id as user_scope_history_primary_auth_method_id +from recording_session rs + join storage_plugin_storage_bucket sb on + rs.storage_bucket_id = sb.public_id + join iam_user_hst uh on + rs.user_hst_id = uh.history_id + join iam_scope_hst as ush on + rs.user_scope_hst_id = ush.history_id; +comment on view session_recording_aggregate is + 'session_recording_aggregate contains the session recording resource with its storage bucket scope info and historical user info.'; + +commit; diff --git a/internal/db/schema/migrations/oss/postgres/70/08_targets.up.sql b/internal/db/schema/migrations/oss/postgres/70/09_targets.up.sql similarity index 100% rename from internal/db/schema/migrations/oss/postgres/70/08_targets.up.sql rename to internal/db/schema/migrations/oss/postgres/70/09_targets.up.sql diff --git a/internal/db/sqltest/tests/recording/recording_session.sql b/internal/db/sqltest/tests/recording/recording_session.sql index 044a0eb3a..fe2a73b13 100644 --- a/internal/db/sqltest/tests/recording/recording_session.sql +++ b/internal/db/sqltest/tests/recording/recording_session.sql @@ -8,9 +8,11 @@ -- end_time_null_or_after_start_time begin; - select plan(19); + select plan(21); select wtt_load('widgets', 'iam', 'kms', 'auth', 'hosts', 'targets', 'sessions'); + select has_view('session_recording_aggregate', 'view for aggregating session recording info does not exist'); + -- tests a fk column referencing a history table -- add 5 to the plan for each time this function is called create function hst_fk_column(column_name name, pk_table name) returns text @@ -72,6 +74,18 @@ begin; where public_id = 'sr_123456789'; select lives_ok('close_recording_session'); + prepare select_session_recordings as + select public_id::text, storage_bucket_id::text, storage_bucket_scope_id::text, session_id::text, user_history_public_id::text, user_history_name::text, user_history_scope_id::text, user_scope_history_type::text + from session_recording_aggregate + where public_id in ('sr_123456789') + order by public_id; + + select results_eq( + 'select_session_recordings', + $$VALUES + ('sr_123456789', 'sb_________g', 'global', 's1_____clare', 'u______clare', 'Clare', 'o_____colors', 'org')$$ + ); + -- Closing a second time should error select throws_ok('close_recording_session', '23602', null, 'closing a recording_session twice succeeded');