|
| 1 | +export default { |
| 2 | + id: 'gcp-cis-1.3.0-6.2.9', |
| 3 | + title: |
| 4 | + "GCP CIS 6.2.9 Ensure That 'cloudsql.enable_pgaudit' Database Flag for each Cloud Sql Postgresql Instance Is Set to 'on' For Centralized Logging", |
| 5 | + description: `Ensure *cloudsql.enable_pgaudit* database flag for Cloud SQL PostgreSQL instance is set |
| 6 | + to *on* to allow for centralized logging.`, |
| 7 | + audit: `**Determining if the pgAudit Flag is set to 'on' |
| 8 | + |
| 9 | + From Console:** |
| 10 | +
|
| 11 | + 1. Go to https://console.cloud.google.com/sql/instances. |
| 12 | + 2. Select the instance to open its *Overview* page. |
| 13 | + 3. Click *Edit*. |
| 14 | + 4. Scroll down and expand Flags. |
| 15 | + 5. Ensure that *cloudsql.enable_pgaudit* flag is set to *on*. |
| 16 | +
|
| 17 | + **From Command Line:** |
| 18 | +
|
| 19 | + Run the command by providing *<INSTANCE_NAME>*. Ensure the value of the flag is *on*. |
| 20 | +
|
| 21 | + gcloud sql instances describe <INSTANCE_NAME> --format="json" | jq '.settings|.|.databaseFlags[]|select(.name=="cloudsql.enable_pgaudit")|.value ' |
| 22 | +
|
| 23 | + **Determine if the pgAudit extension is installed** |
| 24 | +
|
| 25 | + 1. Connect to the the server running PostgreSQL or through a SQL client of your choice. |
| 26 | + 2. Via command line open the PostgreSQL shell by typing psql |
| 27 | + 3. Run the following command |
| 28 | +
|
| 29 | + SELECT * FROM pg_extension; |
| 30 | +
|
| 31 | + 4. If pgAudit is in this list. If so, it is installed. |
| 32 | +
|
| 33 | + **Determine if Data Access Audit logs are enabled for your project and have sufficient privileges** |
| 34 | +
|
| 35 | + 1. From the homepage open the hamburger menu in the top left. |
| 36 | + 2. Scroll down to IAM & Adminand hover over it. |
| 37 | + 3. In the menu that opens up, select Audit Logs |
| 38 | + 4. In the middle of the page, in the search box next to filter search for Cloud Composer API |
| 39 | + 5. Select it, and ensure that both 'Admin Read' and 'Data Read' are checked. |
| 40 | +
|
| 41 | + **Determine if logs are being sent to Logs Explorer** |
| 42 | +
|
| 43 | + 1. From the Google Console home page, open the hamburger menu in the top left. |
| 44 | + 2. In the menu that pops open, scroll down to Logs Explorer under Operations. |
| 45 | + 3. In the query box, paste the following and search |
| 46 | +
|
| 47 | + resource.type="cloudsql_database" |
| 48 | + logName="projects/<your-project-name>/logs/cloudaudit.googleapis.com%2Fdata_access" |
| 49 | + protoPayload.request.@type="type.googleapis.com/google.cloud.sql.audit.v1.PgA uditEntry" |
| 50 | +
|
| 51 | + 4. If it returns any log sources, they are correctly setup. |
| 52 | +`, |
| 53 | + rationale: 'As numerous other recommendations in this section consist of turning on flags for logging purposes, your organization will need a way to manage these logs. You may have a solution already in place. If you do not, consider installing and enabling the open source pgaudit extension within PostgreSQL and enabling its corresponding flag of cloudsql.enable_pgaudit. This flag and installing the extension enables database auditing in PostgreSQL through the open-source pgAudit extension. This extension provides detailed session and object logging to comply with government, financial, & ISO standards and provides auditing capabilities to mitigate threats by monitoring security events on the instance. Enabling the flag and settings later in this recommendation will send these logs to Google Logs Explorer so that you can access them in a central location. to This recommendation is applicable only to PostgreSQL database instances.', |
| 54 | + remediation: `**Initialize the pgAudit flag |
| 55 | + |
| 56 | + From Console:** |
| 57 | +
|
| 58 | + 1. Go to https://console.cloud.google.com/sql/instances. |
| 59 | + 2. Select the instance to open its Overview page. |
| 60 | + 3. Click *Edit*. |
| 61 | + 4. Scroll down and expand Flags. |
| 62 | + 5. To set a flag that has not been set on the instance before, click *Add item*. |
| 63 | + 6. Enter *cloudsql.enable_pgaudit* for the flag name and set the flag to *on*. |
| 64 | + 7. Click *Done*. |
| 65 | + 8. Click *Save* to update the configuration. |
| 66 | + 9. Confirm your changes under *Flags* on the *Overview* page. |
| 67 | +
|
| 68 | + **From Command Line:** |
| 69 | +
|
| 70 | + Run the below command by providing *<INSTANCE_NAME>* to enable *cloudsql.enable_pgaudit* flag. |
| 71 | +
|
| 72 | + gcloud sql instances patch <INSTANCE_NAME> --database- flags=cloudsql.enable_pgaudit=on |
| 73 | +
|
| 74 | + Note: *RESTART* is required to get this configuration in effect. |
| 75 | +
|
| 76 | + **Creating the extension** |
| 77 | +
|
| 78 | + 1. Connect to the the server running PostgreSQL or through a SQL client of your choice. |
| 79 | + 2. If SSHing to the server in the command line open the PostgreSQL shell by typing *psql* |
| 80 | + 3. Run the following command as a superuser. |
| 81 | +
|
| 82 | + CREATE EXTENSION pgaudit; |
| 83 | +
|
| 84 | + **Updating the previously created pgaudit.log flag for your Logging Needs |
| 85 | + |
| 86 | + From Console:** |
| 87 | +
|
| 88 | + Note: there are multiple options here. This command will enable logging for all databases on a server. Please see the customizing database audit logging reference for more flag options. |
| 89 | +
|
| 90 | + 1. Go to https://console.cloud.google.com/sql/instances. |
| 91 | + 2. Select the instance to open its *Overview* page. |
| 92 | + 3. Click *Edit*. |
| 93 | + 4. Scroll down and expand *Flags*. |
| 94 | + 5. To set a flag that has not been set on the instance before, click *Add item*. |
| 95 | + 6. Enter *pgaudit.log=all* for the flag name and set the flag to on. |
| 96 | + 7. Click *Done*. |
| 97 | + 8. Click *Save* to update the configuration. |
| 98 | + 9. Confirm your changes under *Flags* on the *Overview* page. |
| 99 | +
|
| 100 | + **From Command Line:** |
| 101 | + Run the command |
| 102 | +
|
| 103 | + gcloud sql instances patch <INSTANCE_NAME> --database-flags cloudsql.enable_pgaudit=on,pgaudit.log=all |
| 104 | + |
| 105 | + **Determine if logs are being sent to Logs Explorer** |
| 106 | +
|
| 107 | + 1. From the Google Console home page, open the hamburger menu in the top left. |
| 108 | + 2. In the menu that pops open, scroll down to Logs Explorer under Operations. |
| 109 | + 3. In the query box, paste the following and search |
| 110 | +
|
| 111 | + resource.type="cloudsql_database" logName="projects//logs/cloudaudit.googleapis.com%2Fdata_access" protoPayload.request.@type="type.googleapis.com/google.cloud.sql.audit.v1.PgAuditEntry " |
| 112 | +
|
| 113 | + If it returns any log sources, they are correctly setup. |
| 114 | +
|
| 115 | + **Default Value:** |
| 116 | +
|
| 117 | + By default *cloudsql.enable_pgaudit* database flag is set to *off* and the extension is not enabled.`, |
| 118 | + references: [ |
| 119 | + 'https://cloud.google.com/sql/docs/postgres/flags#list-flags-postgres', |
| 120 | + 'https://cloud.google.com/sql/docs/postgres/pg-audit#enable-auditing-flag', |
| 121 | + 'https://cloud.google.com/sql/docs/postgres/pg-audit#customizing-database-audit-logging', |
| 122 | + 'https://cloud.google.com/logging/docs/audit/configure-data-access#config-console-enable', |
| 123 | + ], |
| 124 | + gql: `{ |
| 125 | + querygcpSqlInstance(filter:{ databaseVersion: {regexp: "/POSTGRES*/"}}){ |
| 126 | + name |
| 127 | + id |
| 128 | + __typename |
| 129 | + settings{ |
| 130 | + databaseFlags{ |
| 131 | + name |
| 132 | + value |
| 133 | + } |
| 134 | + } |
| 135 | + } |
| 136 | + }`, |
| 137 | + resource: 'querygcpSqlInstance[*]', |
| 138 | + exclude: { not: { path: '@.databaseVersion', match: /POSTGRES*/ } }, |
| 139 | + severity: 'medium', |
| 140 | + conditions: { |
| 141 | + and: [ |
| 142 | + { |
| 143 | + path: '@.settings.databaseFlags', |
| 144 | + isEmpty: false, |
| 145 | + }, |
| 146 | + { |
| 147 | + path: '@.settings.databaseFlags', |
| 148 | + array_any: { |
| 149 | + and: [ |
| 150 | + { |
| 151 | + path: '[*].name', |
| 152 | + equal: 'cloudsql.enable_pgaudit', |
| 153 | + }, |
| 154 | + { |
| 155 | + path: '[*].value', |
| 156 | + equal: 'on', |
| 157 | + }, |
| 158 | + ], |
| 159 | + }, |
| 160 | + }, |
| 161 | + ], |
| 162 | + }, |
| 163 | +} |
0 commit comments