Control: Ensure that the 'log_disconnections' database flag for Cloud SQL PostgreSQL instance is set to 'on'
Description
Enabling the log_disconnections setting logs the end of each session, including the session duration.
Usage
Run the control in your terminal:
powerpipe control run gcp_compliance.control.sql_instance_postgresql_log_disconnections_database_flag_onSnapshot and share results via Turbot Pipes:
powerpipe loginpowerpipe control run gcp_compliance.control.sql_instance_postgresql_log_disconnections_database_flag_on --shareSQL
This control uses a named query:
select  self_link resource,  case    when database_version not like 'POSTGRES%' then 'skip'    when database_flags @> '[{"name":"log_disconnections","value":"on"}]' then 'ok'    else 'alarm'  end as status,  case    when database_version not like 'POSTGRES%'      then title || ' not a PostgreSQL database.'    when database_flags is null or not (database_flags @> '[{"name":"log_disconnections"}]')      then title || ' ''log_disconnections'' database flag not set.'    when database_flags @> '[{"name":"log_disconnections","value":"on"}]'      then title || ' ''log_disconnections'' database flag set to ''on''.'    else title || ' ''log_disconnections'' database flag set to ''off''.'  end as reason    , location as location, project as projectfrom  gcp_sql_database_instance;