Skip to content

Commit

Permalink
POL-1451 Add sys- and app- Project Filtering to Google Policy Templat…
Browse files Browse the repository at this point in the history
…es (#2955)

* update

* fix

* update

* fix

* update

* fix

* update

* update

* update

* update

* update
  • Loading branch information
XOmniverse authored Feb 13, 2025
1 parent b284800 commit 1fcff97
Show file tree
Hide file tree
Showing 61 changed files with 553 additions and 125 deletions.
4 changes: 4 additions & 0 deletions compliance/google/long_stopped_instances/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v4.1.0

- Added support for filtering system and Google Apps Script projects from the results.

## v4.0.2

- Added `hide_skip_approvals` field to the info section. It dynamically controls "Skip Action Approvals" visibility.
Expand Down
2 changes: 2 additions & 0 deletions compliance/google/long_stopped_instances/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ This policy finds Google virtual machines which have been stopped for more than
- *Email Addresses* - Email addresses of the recipients you wish to notify.
- *Allow/Deny Projects* - Whether to treat Allow/Deny Projects List parameter as allow or deny list. Has no effect if Allow/Deny Projects List is left empty.
- *Allow/Deny Projects List* - Filter results by project ID/name, either only allowing this list or denying it depending on how the above parameter is set. Leave blank to consider all projects
- *Ignore System Projects* - Whether or not to automatically ignore system projects e.g. projects whose id begins with `sys-`
- *Ignore Google Apps Script Projects* - Whether or not to automatically ignore Google Apps Script projects e.g. projects whose id begins with `app-`
- *Allow/Deny Regions* - Whether to treat Allow/Deny Regions List parameter as allow or deny list. Has no effect if Allow/Deny Regions List is left empty.
- *Allow/Deny Regions List* - Filter results by region, either only allowing this list or denying it depending on how the above parameter is set. Leave blank to consider all the regions.
- *Exclusion Labels* - The policy will filter resources containing the specified labels from the results. The following formats are supported:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ category "Compliance"
severity "low"
default_frequency "weekly"
info(
version: "4.0.2",
version: "4.1.0",
provider: "Google",
service: "Compute",
policy_set: "Long Stopped Instances",
Expand Down Expand Up @@ -43,6 +43,24 @@ parameter "param_projects_list" do
default []
end

parameter "param_projects_ignore_sys" do
type "string"
category "Filters"
label "Ignore System Projects"
description "Whether or not to automatically ignore system projects e.g. projects whose id begins with 'sys-'"
allowed_values "Yes", "No"
default "No"
end

parameter "param_projects_ignore_app" do
type "string"
category "Filters"
label "Ignore Google Apps Script Projects"
description "Whether or not to automatically ignore Google Apps Script projects e.g. projects whose id begins with 'app-'"
allowed_values "Yes", "No"
default "No"
end

parameter "param_regions_allow_or_deny" do
type "string"
category "Filters"
Expand Down Expand Up @@ -273,15 +291,15 @@ datasource "ds_google_projects" do
end

datasource "ds_google_projects_filtered" do
run_script $js_google_projects_filtered, $ds_google_projects, $param_projects_allow_or_deny, $param_projects_list
run_script $js_google_projects_filtered, $ds_google_projects, $param_projects_allow_or_deny, $param_projects_list, $param_projects_ignore_sys, $param_projects_ignore_app
end

script "js_google_projects_filtered", type: "javascript" do
parameters "ds_google_projects", "param_projects_allow_or_deny", "param_projects_list"
parameters "ds_google_projects", "param_projects_allow_or_deny", "param_projects_list", "param_projects_ignore_sys", "param_projects_ignore_app"
result "result"
code <<-EOS
if (param_projects_list.length > 0) {
result = _.filter(ds_google_projects, function(project) {
filtered = _.filter(ds_google_projects, function(project) {
include_project = _.contains(param_projects_list, project['id']) || _.contains(param_projects_list, project['name']) || _.contains(param_projects_list, project['number'])
if (param_projects_allow_or_deny == "Deny") {
Expand All @@ -291,8 +309,12 @@ script "js_google_projects_filtered", type: "javascript" do
return include_project
})
} else {
result = ds_google_projects
filtered = ds_google_projects
}
result = _.reject(filtered, function(project) {
return (project['id'].substring(0, 4) == "sys-" && param_projects_ignore_sys == "Yes") || (project['id'].substring(0, 4) == "app-" && param_projects_ignore_app == "Yes")
})
EOS
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ category "Meta"
default_frequency "15 minutes"
info(
provider: "Google",
version: "4.0.2", # This version of the Meta Parent Policy Template should match the version of the Child Policy Template as it appears in the Catalog for best reliability
version: "4.1.0", # This version of the Meta Parent Policy Template should match the version of the Child Policy Template as it appears in the Catalog for best reliability
publish: "true",
deprecated: "false",
hide_skip_approvals: "true"
Expand Down
4 changes: 4 additions & 0 deletions compliance/google/unlabeled_resources/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v3.2.0

- Added support for filtering system and Google Apps Script projects from the results.

## v3.1.1

- Added `hide_skip_approvals` field to the info section. It dynamically controls "Skip Action Approvals" visibility.
Expand Down
2 changes: 2 additions & 0 deletions compliance/google/unlabeled_resources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ This policy template checks for Google Cloud resources missing the user-specifie
- *Email Addresses* - Email addresses of the recipients you wish to notify when new incidents are created.
- *Allow/Deny Projects* - Whether to treat Allow/Deny Projects List parameter as allow or deny list. Has no effect if Allow/Deny Projects List is left empty.
- *Allow/Deny Projects List* - Filter results by project ID/name, either only allowing this list or denying it depending on how the above parameter is set. Leave blank to consider all projects.
- *Ignore System Projects* - Whether or not to automatically ignore system projects e.g. projects whose id begins with `sys-`
- *Ignore Google Apps Script Projects* - Whether or not to automatically ignore Google Apps Script projects e.g. projects whose id begins with `app-`
- *Resource Types* - The types of resources to check labels for. Any options not selected will not be reported on.
- *Labels* - The policy will report resources missing the specified labels. The following formats are supported:
- `Key` - Find all resources missing the specified label key.
Expand Down
32 changes: 27 additions & 5 deletions compliance/google/unlabeled_resources/unlabeled_resources.pt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ category "Compliance"
severity "low"
default_frequency "weekly"
info(
version: "3.1.1",
version: "3.2.0",
provider: "Google",
service: "Compute",
policy_set: "Untagged Resources",
Expand Down Expand Up @@ -60,6 +60,24 @@ parameter "param_projects_list" do
default []
end

parameter "param_projects_ignore_sys" do
type "string"
category "Filters"
label "Ignore System Projects"
description "Whether or not to automatically ignore system projects e.g. projects whose id begins with 'sys-'"
allowed_values "Yes", "No"
default "No"
end

parameter "param_projects_ignore_app" do
type "string"
category "Filters"
label "Ignore Google Apps Script Projects"
description "Whether or not to automatically ignore Google Apps Script projects e.g. projects whose id begins with 'app-'"
allowed_values "Yes", "No"
default "No"
end

parameter "param_resource_types" do
type "list"
category "Filters"
Expand Down Expand Up @@ -247,15 +265,15 @@ datasource "ds_google_projects" do
end

datasource "ds_google_projects_filtered" do
run_script $js_google_projects_filtered, $ds_google_projects, $param_projects_allow_or_deny, $param_projects_list
run_script $js_google_projects_filtered, $ds_google_projects, $param_projects_allow_or_deny, $param_projects_list, $param_projects_ignore_sys, $param_projects_ignore_app
end

script "js_google_projects_filtered", type: "javascript" do
parameters "ds_google_projects", "param_projects_allow_or_deny", "param_projects_list"
parameters "ds_google_projects", "param_projects_allow_or_deny", "param_projects_list", "param_projects_ignore_sys", "param_projects_ignore_app"
result "result"
code <<-EOS
if (param_projects_list.length > 0) {
result = _.filter(ds_google_projects, function(project) {
filtered = _.filter(ds_google_projects, function(project) {
include_project = _.contains(param_projects_list, project['id']) || _.contains(param_projects_list, project['name']) || _.contains(param_projects_list, project['number'])
if (param_projects_allow_or_deny == "Deny") {
Expand All @@ -265,8 +283,12 @@ script "js_google_projects_filtered", type: "javascript" do
return include_project
})
} else {
result = ds_google_projects
filtered = ds_google_projects
}
result = _.reject(filtered, function(project) {
return (project['id'].substring(0, 4) == "sys-" && param_projects_ignore_sys == "Yes") || (project['id'].substring(0, 4) == "app-" && param_projects_ignore_app == "Yes")
})
EOS
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ category "Meta"
default_frequency "15 minutes"
info(
provider: "Google",
version: "3.1.1", # This version of the Meta Parent Policy Template should match the version of the Child Policy Template as it appears in the Catalog for best reliability
version: "3.2.0", # This version of the Meta Parent Policy Template should match the version of the Child Policy Template as it appears in the Catalog for best reliability
publish: "true",
deprecated: "false",
hide_skip_approvals: "true"
Expand Down
4 changes: 4 additions & 0 deletions cost/google/cloud_run_anomaly_detection/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v0.2.0

- Added support for filtering system and Google Apps Script projects from the results.

## v0.1.3

- Minor code improvements to conform with current standards. Functionality unchanged.
Expand Down
6 changes: 4 additions & 2 deletions cost/google/cloud_run_anomaly_detection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ This policy only uses Google Cloud Metric data and is designed to notify of anom

This policy has the following input parameters required when launching the policy.

- *Allow/Deny Subscriptions* - Determines whether the Allow/Deny Subscriptions List parameter functions as an allow list (only providing results for the listed subscriptions) or a deny list (providing results for all subscriptions except for the listed subscriptions).
- *Allow/Deny Subscriptions List* - A list of allowed or denied Subscription IDs/names. If empty, no filtering will occur and recommendations will be produced for all subscriptions.
- *Allow/Deny Projects* - Whether to treat Allow/Deny Projects List parameter as allow or deny list. Has no effect if Allow/Deny Projects List is left empty.
- *Allow/Deny Projects List* - Filter results by project ID/name, either only allowing this list or denying it depending on how the above parameter is set. Leave blank to consider all projects.
- *Ignore System Projects* - Whether or not to automatically ignore system projects e.g. projects whose id begins with `sys-`
- *Ignore Google Apps Script Projects* - Whether or not to automatically ignore Google Apps Script projects e.g. projects whose id begins with `app-`
- *Allow/Deny Regions* - Whether to treat Allow/Deny Regions List parameter as allow or deny list. Has no effect if Allow/Deny Regions List is left empty.
- *Allow/Deny Regions List* - Filter results by region, either only allowing this list or denying it depending on how the above parameter is set. Leave blank to consider all the regions.
- *Lookback Time Period* - The time period to look back for anomalies. The longer the time period, the more accurate the anomaly detection will be.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ category "Cost"
default_frequency "daily"
info(
publish: "false",
version: "0.1.3",
version: "0.2.0",
provider: "Google",
service: "Cloud Run",
policy_set: "Anomaly Detection"
Expand Down Expand Up @@ -43,6 +43,24 @@ parameter "param_projects_list" do
default []
end

parameter "param_projects_ignore_sys" do
type "string"
category "Filters"
label "Ignore System Projects"
description "Whether or not to automatically ignore system projects e.g. projects whose id begins with 'sys-'"
allowed_values "Yes", "No"
default "No"
end

parameter "param_projects_ignore_app" do
type "string"
category "Filters"
label "Ignore Google Apps Script Projects"
description "Whether or not to automatically ignore Google Apps Script projects e.g. projects whose id begins with 'app-'"
allowed_values "Yes", "No"
default "No"
end

parameter "param_regions_allow_or_deny" do
type "string"
category "Filters"
Expand Down Expand Up @@ -243,16 +261,16 @@ datasource "ds_google_projects" do
end

datasource "ds_google_projects_filtered" do
run_script $js_google_projects_filtered, $ds_google_projects, $param_projects_allow_or_deny, $param_projects_list
run_script $js_google_projects_filtered, $ds_google_projects, $param_projects_allow_or_deny, $param_projects_list, $param_projects_ignore_sys, $param_projects_ignore_app
end

script "js_google_projects_filtered", type: "javascript" do
parameters "ds_google_projects", "param_projects_allow_or_deny", "param_projects_list"
parameters "ds_google_projects", "param_projects_allow_or_deny", "param_projects_list", "param_projects_ignore_sys", "param_projects_ignore_app"
result "result"
code <<-EOS
if (param_projects_list.length > 0) {
result = _.filter(ds_google_projects, function(project) {
include_project = _.contains(param_projects_list, project['projectId']) || _.contains(param_projects_list, project['projectName']) || _.contains(param_projects_list, project['projectNumber'])
filtered = _.filter(ds_google_projects, function(project) {
include_project = _.contains(param_projects_list, project['id']) || _.contains(param_projects_list, project['name']) || _.contains(param_projects_list, project['number'])
if (param_projects_allow_or_deny == "Deny") {
include_project = !include_project
Expand All @@ -261,8 +279,12 @@ script "js_google_projects_filtered", type: "javascript" do
return include_project
})
} else {
result = ds_google_projects
filtered = ds_google_projects
}
result = _.reject(filtered, function(project) {
return (project['id'].substring(0, 4) == "sys-" && param_projects_ignore_sys == "Yes") || (project['id'].substring(0, 4) == "app-" && param_projects_ignore_app == "Yes")
})
EOS
end

Expand Down
4 changes: 4 additions & 0 deletions cost/google/cloud_storage_lifecycle/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v0.2.0

- Added support for filtering system and Google Apps Script projects from the results.

## v0.1.1

- Added `hide_skip_approvals` field to the info section. It dynamically controls "Skip Action Approvals" visibility.
Expand Down
2 changes: 2 additions & 0 deletions cost/google/cloud_storage_lifecycle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ This policy template reports all Google Cloud Storage Buckets that don't have a
- *Email Addresses* - Email addresses of the recipients you wish to notify when new incidents are created.
- *Allow/Deny Projects* - Whether to treat Allow/Deny Projects List parameter as allow or deny list. Has no effect if Allow/Deny Projects List is left empty.
- *Allow/Deny Projects List* - Filter results by project ID/name, either only allowing this list or denying it depending on how the above parameter is set. Leave blank to consider all projects.
- *Ignore System Projects* - Whether or not to automatically ignore system projects e.g. projects whose id begins with `sys-`
- *Ignore Google Apps Script Projects* - Whether or not to automatically ignore Google Apps Script projects e.g. projects whose id begins with `app-`
- *Exclusion Labels* - The policy will filter resources containing the specified labels from the results. The following formats are supported:
- `Key` - Filter all resources with the specified label key.
- `Key==Value` - Filter all resources with the specified label key:value pair.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ category "Cost"
severity "low"
default_frequency "weekly"
info(
version: "0.1.1",
version: "0.2.0",
provider: "Google",
service: "Storage",
policy_set: "",
Expand Down Expand Up @@ -43,6 +43,24 @@ parameter "param_projects_list" do
default []
end

parameter "param_projects_ignore_sys" do
type "string"
category "Filters"
label "Ignore System Projects"
description "Whether or not to automatically ignore system projects e.g. projects whose id begins with 'sys-'"
allowed_values "Yes", "No"
default "No"
end

parameter "param_projects_ignore_app" do
type "string"
category "Filters"
label "Ignore Google Apps Script Projects"
description "Whether or not to automatically ignore Google Apps Script projects e.g. projects whose id begins with 'app-'"
allowed_values "Yes", "No"
default "No"
end

parameter "param_exclusion_labels" do
type "list"
category "Filters"
Expand Down Expand Up @@ -127,15 +145,15 @@ datasource "ds_google_projects" do
end

datasource "ds_google_projects_filtered" do
run_script $js_google_projects_filtered, $ds_google_projects, $param_projects_allow_or_deny, $param_projects_list
run_script $js_google_projects_filtered, $ds_google_projects, $param_projects_allow_or_deny, $param_projects_list, $param_projects_ignore_sys, $param_projects_ignore_app
end

script "js_google_projects_filtered", type: "javascript" do
parameters "ds_google_projects", "param_projects_allow_or_deny", "param_projects_list"
parameters "ds_google_projects", "param_projects_allow_or_deny", "param_projects_list", "param_projects_ignore_sys", "param_projects_ignore_app"
result "result"
code <<-EOS
if (param_projects_list.length > 0) {
result = _.filter(ds_google_projects, function(project) {
filtered = _.filter(ds_google_projects, function(project) {
include_project = _.contains(param_projects_list, project['id']) || _.contains(param_projects_list, project['name']) || _.contains(param_projects_list, project['number'])
if (param_projects_allow_or_deny == "Deny") {
Expand All @@ -145,8 +163,12 @@ script "js_google_projects_filtered", type: "javascript" do
return include_project
})
} else {
result = ds_google_projects
filtered = ds_google_projects
}
result = _.reject(filtered, function(project) {
return (project['id'].substring(0, 4) == "sys-" && param_projects_ignore_sys == "Yes") || (project['id'].substring(0, 4) == "app-" && param_projects_ignore_app == "Yes")
})
EOS
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ category "Meta"
default_frequency "15 minutes"
info(
provider: "Google",
version: "0.1.1", # This version of the Meta Parent Policy Template should match the version of the Child Policy Template as it appears in the Catalog for best reliability
version: "0.2.0", # This version of the Meta Parent Policy Template should match the version of the Child Policy Template as it appears in the Catalog for best reliability
publish: "true",
deprecated: "false",
hide_skip_approvals: "true"
Expand Down
4 changes: 4 additions & 0 deletions cost/google/cud_expiration/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v3.1.0

- Added support for filtering system and Google Apps Script projects from the results.

## v3.0.1

- Added `hide_skip_approvals` field to the info section. It dynamically controls "Skip Action Approvals" visibility.
Expand Down
2 changes: 2 additions & 0 deletions cost/google/cud_expiration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ This policy generates a report of all Google Committed Use Discounts (CUDs) that
- *Days Until Expiration* - The number of days until expiration to include a Committed Use Discount in the report. Set to `0` to only report expired Committed Use Discounts.
- *Allow/Deny Projects* - Whether to treat Allow/Deny Projects List parameter as allow or deny list. Has no effect if Allow/Deny Projects List is left empty.
- *Allow/Deny Projects List* - Filter results by project ID/name, either only allowing this list or denying it depending on how the above parameter is set. Leave blank to consider all projects
- *Ignore System Projects* - Whether or not to automatically ignore system projects e.g. projects whose id begins with `sys-`
- *Ignore Google Apps Script Projects* - Whether or not to automatically ignore Google Apps Script projects e.g. projects whose id begins with `app-`
- *Allow/Deny Regions* - Whether to treat Allow/Deny Regions List parameter as allow or deny list. Has no effect if Allow/Deny Regions List is left empty.
- *Allow/Deny Regions List* - Filter results by region, either only allowing this list or denying it depending on how the above parameter is set. Leave blank to consider all the regions.

Expand Down
Loading

0 comments on commit 1fcff97

Please sign in to comment.