-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: add the script to download certs and apply azure policy operation on … #2054
Draft
shahramk64
wants to merge
1
commit into
ratify-project:dev
Choose a base branch
from
shahramk64:skalantari/ratify-aks-on-azure-marketplace
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+83
−0
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,83 @@ | ||
#!/bin/bash | ||
|
||
echo "Starting Ratify on Azure\n" | ||
echo "RESOURCE_GROUP: $RESOURCE_GROUP\n" | ||
echo "CLUSTER_NAME: $CLUSTER_NAME\n" | ||
echo "ENABLE_MUTATION: $ENABLE_MUTATION\n" | ||
echo "ENABLE_CERT_ROTATION: $ENABLE_CERT_ROTATION\n" | ||
echo "MANAGED_IDENTITY_CLIENT_ID: $MANAGED_IDENTITY_CLIENT_ID\n" | ||
echo "TRUSTED_IDENTITIES: $TRUSTED_IDENTITIES\n" | ||
echo "REGISTRY_SCOPE: $REGISTRY_SCOPE\n" | ||
echo "ROOT_CERT_URL: $ROOT_CERT_URL\n" | ||
|
||
# File names for the certificates | ||
CA_CRT_FILE="ca.crt" | ||
CA_PEM_FILE="ca.pem" | ||
TSA_CRT_FILE="tsa.crt" | ||
TSA_PEM_FILE="tsa.pem" | ||
|
||
echo "Downloading CA certificate from $ROOT_CERT_URL..." | ||
curl -s -o $CA_CRT_FILE $ROOT_CERT_URL | ||
if [ -f "$CA_CRT_FILE" ]; then | ||
echo "$CA_CRT_FILE was downloaded successfully." | ||
else | ||
echo "$CA_CRT_FILE download failed." | ||
exit 1 | ||
fi | ||
|
||
echo "Converting the CA certificate..." | ||
openssl x509 -in "$CA_CRT_FILE" -inform DER -out "$CA_PEM_FILE" -outform PEM | ||
if [ -f "$CA_PEM_FILE" ]; then | ||
echo "$CA_PEM_FILE was created successfully." | ||
else | ||
echo "$CA_PEM_FILE creation failed." | ||
exit 1 | ||
fi | ||
|
||
# Download and process the TSA certificate (optional) | ||
if [[ -n "$CERT_URL_TSA" ]]; then | ||
echo "Downloading TSA certificate from $CERT_URL_TSA..." | ||
curl -s -o $TSA_CRT_FILE $CERT_URL_TSA | ||
openssl x509 -in $TSA_CRT_FILE -out $TSA_PEM_FILE -outform PEM | ||
TSA_HELM_ARG="--set-file notationCerts[1]=$TSA_PEM_FILE --set notation.trustPolicies[0].trustStores[1]=ca:notationCerts[1]" | ||
else | ||
echo "TSA certificate URL not provided. Skipping TSA certificate configuration." | ||
TSA_HELM_ARG="" | ||
fi | ||
|
||
echo "TSA_HELM_ARG: $TSA_HELM_ARG" | ||
|
||
# Get AKS credentials | ||
az aks get-credentials --resource-group $RESOURCE_GROUP --name $CLUSTER_NAME --overwrite-existing | ||
|
||
# Get the client id | ||
clientId=$(az aks show --resource-group $RESOURCE_GROUP --name $CLUSTER_NAME --query "identityProfile.kubeletidentity.clientId" -o tsv) | ||
echo "clientId: $clientId" | ||
|
||
# Install Helm | ||
curl -s https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash | ||
# Add a Helm repo | ||
helm repo add ratify https://ratify-project.github.io/ratify | ||
|
||
# Install Ratify | ||
helm install ratify ratify/ratify --atomic \ | ||
--namespace gatekeeper-system --create-namespace \ | ||
--set azureWorkloadIdentity.clientId=$clientId \ | ||
--set provider.enableMutation=$ENABLE_MUTATION \ | ||
--set featureFlags.RATIFY_CERT_ROTATION=$ENABLE_CERT_ROTATION \ | ||
--set-file notationCerts[0]=$CA_PEM_FILE \ | ||
--set notation.trustPolicies[0].registryScopes[0]=$REGISTRYSCOPE \ | ||
--set notation.trustPolicies[0].trustStores[0]=ca:notationCerts[0] \ | ||
--set notation.trustPolicies[0].trustedIdentities[0]=$TRUSTEDIDENTITY | ||
|
||
export CUSTOM_POLICY=$(curl -L https://raw.githubusercontent.com/deislabs/ratify/main/library/default/customazurepolicy.json) | ||
export DEFINITION_NAME="ratify-default-custom-policy" | ||
export POLICY_SCOPE=$(az aks show -g "${RESOURCE_GROUP}" -n "${CLUSTER_NAME}" --query id -o tsv) | ||
|
||
export DEFINITION_ID=$(az policy definition create --name "${DEFINITION_NAME}" --rules "$(echo "${CUSTOM_POLICY}" | jq .policyRule)" --params "$(echo "${CUSTOM_POLICY}" | jq .parameters)" --mode "Microsoft.Kubernetes.Data" --query id -o tsv) | ||
|
||
export ASSIGNMENT_ID=$(az policy assignment create --policy "${DEFINITION_ID}" --name "${DEFINITION_NAME}" --scope "${POLICY_SCOPE}" --query id -o tsv) | ||
|
||
echo "Please wait policy assignment with id ${ASSIGNMENT_ID} taking effect" | ||
echo "It often requires 15 min" | ||
echo "You can run 'kubectl get constraintTemplate ratifyverification' to verify the policy takes effect" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / Scorecard
Pinned-Dependencies Medium