-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5b3ee3a
commit 69e473f
Showing
6 changed files
with
145 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: Attest Images | ||
on: [workflow_call] | ||
jobs: | ||
binary-auth: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: . | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- id: gcloud-auth | ||
name: Authenticate with gcloud | ||
uses: 'google-github-actions/auth@v1' | ||
with: | ||
credentials_json: '${{ secrets.GCP_CREDENTIALS }}' | ||
- name: Set up Cloud SDK | ||
id: setup-gcloud-sdk | ||
uses: 'google-github-actions/setup-gcloud@v1' | ||
- name: Install gcloud beta | ||
id: install-gcloud-beta | ||
run: gcloud components install beta | ||
- name: Attest Images | ||
run: | | ||
grep -ir "image:" ./manifests/blog-app/ | awk {'print $3'} | sort -t: -u -k1,1 > ./images | ||
for image in $(cat ./images); do | ||
no_of_slash=$(echo $image | tr -cd '/' | wc -c) | ||
prefix="" | ||
if [ $no_of_slash -eq 1 ]; then | ||
prefix="docker.io/" | ||
fi | ||
if [ $no_of_slash -eq 0 ]; then | ||
prefix="docker.io/library/" | ||
fi | ||
image_to_attest=$image | ||
if [[ $image =~ "@" ]]; then | ||
echo "Image $image has DIGEST" | ||
image_to_attest="${prefix}${image}" | ||
else | ||
echo "All images should be in the SHA256 digest format" | ||
exit 1 | ||
fi | ||
echo "Processing $image" | ||
attestation_present=$(gcloud beta container binauthz attestations list --attestor-project="${{ secrets.PROJECT_ID }}" --attestor="${{ secrets.ATTESTOR_NAME }}" --artifact-url="${image_to_attest}") | ||
if [ -z "${attestation_present// }" ]; then | ||
gcloud beta container binauthz attestations sign-and-create --artifact-url="${image_to_attest}" --attestor="${{ secrets.ATTESTOR_NAME }}" --attestor-project="${{ secrets.PROJECT_ID }}" --keyversion-project="${{ secrets.PROJECT_ID }}" --keyversion-location="${{ secrets.KMS_KEY_LOCATION }}" --keyversion-keyring="${{ secrets.KMS_KEYRING_NAME }}" --keyversion-key="${{ secrets.KMS_KEY_NAME }}" --keyversion="${{ secrets.KMS_KEY_VERSION }}" | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
for image in $(cat ./images); do | ||
no_of_slash=$(echo $image | tr -cd '/' | wc -c) | ||
prefix="" | ||
if [ $no_of_slash -eq 1 ]; then | ||
prefix="docker.io/" | ||
fi | ||
if [ $no_of_slash -eq 0 ]; then | ||
prefix="docker.io/library/" | ||
fi | ||
image_to_attest=$image | ||
if [[ $image =~ "@" ]]; then | ||
echo "Image $image has DIGEST" | ||
image_to_attest="${prefix}${image}" | ||
else | ||
DIGEST=$(docker pull $image | grep Digest | awk {'print $2'}) | ||
image_name=$(echo $image | awk -F ':' {'print $1'}) | ||
image_to_attest="${prefix}${image_name}@${DIGEST}" | ||
fi | ||
escaped_image=$(printf '%s\n' "${image}" | sed -e 's/[]\/$*.^[]/\\&/g') | ||
escaped_image_to_attest=$(printf '%s\n' "${image_to_attest}" | | ||
sed -e 's/[]\/$*.^[]/\\&/g') | ||
echo "Processing $image" | ||
grep -rl $image ./manifests | | ||
xargs sed -i "s/${escaped_image}/${escaped_image_to_attest}/g" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
resource "google_kms_key_ring" "qa-attestor-keyring" { | ||
count = var.branch == "dev" ? 1 : 0 | ||
name = "qa-attestor-keyring" | ||
location = var.region | ||
lifecycle { | ||
prevent_destroy = false | ||
} | ||
} | ||
|
||
module "qa-attestor" { | ||
count = var.branch == "dev" ? 1 : 0 | ||
source = "terraform-google-modules/kubernetes-engine/google//modules/binary-authorization" | ||
attestor-name = "quality-assurance" | ||
project_id = var.project_id | ||
keyring-id = google_kms_key_ring.qa-attestor-keyring[0].id | ||
} | ||
|
||
resource "google_binary_authorization_policy" "policy" { | ||
count = var.branch == "dev" ? 1 : 0 | ||
admission_whitelist_patterns { | ||
name_pattern = "gcr.io/google_containers/*" | ||
} | ||
admission_whitelist_patterns { | ||
name_pattern = "gcr.io/google-containers/*" | ||
} | ||
admission_whitelist_patterns { | ||
name_pattern = "k8s.gcr.io/**" | ||
} | ||
admission_whitelist_patterns { | ||
name_pattern = "gke.gcr.io/**" | ||
} | ||
admission_whitelist_patterns { | ||
name_pattern = "gcr.io/stackdriver-agents/*" | ||
} | ||
admission_whitelist_patterns { | ||
name_pattern = "quay.io/argoproj/*" | ||
} | ||
admission_whitelist_patterns { | ||
name_pattern = "ghcr.io/dexidp/*" | ||
} | ||
admission_whitelist_patterns { | ||
name_pattern = "docker.io/redis[@:]*" | ||
} | ||
admission_whitelist_patterns { | ||
name_pattern = "ghcr.io/external-secrets/*" | ||
} | ||
global_policy_evaluation_mode = "ENABLE" | ||
default_admission_rule { | ||
evaluation_mode = "REQUIRE_ATTESTATION" | ||
enforcement_mode = "ENFORCED_BLOCK_AND_AUDIT_LOG" | ||
require_attestations_by = [ | ||
module.qa-attestor[0].attestor | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters