templates/tfengine/components/resources/binary_authorization/main.tf (38 lines of code) (raw):
{{- /* Copyright 2021 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */ -}}
resource "google_binary_authorization_policy" "policy" {
project = module.project.project_id
# Allow Google-built images.
# See https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#globalpolicyevaluationmode
global_policy_evaluation_mode = "ENABLE"
# Block all other images.
# See https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#defaultadmissionrule
default_admission_rule {
evaluation_mode = "ALWAYS_DENY"
enforcement_mode = "ENFORCED_BLOCK_AND_AUDIT_LOG"
}
# Recommendations from https://cloud.google.com/binary-authorization/docs/policy-yaml-reference#admissionwhitelistpatterns
admission_whitelist_patterns {
name_pattern = "gcr.io/google_containers/*"
}
# Not all istio images are added by default in the "google images" policy.
admission_whitelist_patterns {
name_pattern = "gke.gcr.io/istio/*"
}
admission_whitelist_patterns {
# The more generic pattern above does not seem to be enough for all images.
name_pattern = "gke.gcr.io/istio/prometheus/*"
}
# Calico images in a new registry.
admission_whitelist_patterns {
name_pattern = "gcr.io/projectcalico-org/*"
}
# Allow images from this project.
admission_whitelist_patterns {
name_pattern = "gcr.io/${module.project.project_id}/*"
}
{{range get . "binary_authorization.admission_whitelist_patterns" -}}
admission_whitelist_patterns {
name_pattern = "{{.name_pattern}}"
}
{{end -}}
}