@@ -31,17 +31,16 @@ set -o nounset
3131set -o errexit
3232set -o pipefail
3333set -o xtrace
34+ script_dir=$( cd -- " $( dirname -- " ${BASH_SOURCE[0]} " ) " & > /dev/null && pwd)
35+ root_dir=$( cd " ${script_dir} /../.." && pwd)
36+ export TERM=dumb
3437
3538# Your Venafi Cloud API key.
3639: ${VEN_API_KEY?}
3740# Separate API Key for getting a pull secret, if your main venafi cloud tenant
3841# doesn't allow you to create registry service accounts.
3942: ${VEN_API_KEY_PULL?}
4043
41- # The Venafi Cloud team which will be the owner of the generated Venafi service
42- # accounts.
43- : ${VEN_OWNING_TEAM?}
44-
4544# The Venafi Cloud zone (application/issuing_template) which will be used by the
4645# issuer an policy.
4746: ${VEN_ZONE?}
@@ -55,22 +54,6 @@ set -o xtrace
5554# E.g. ttl.sh/63773370-0bcf-4ac0-bd42-5515616089ff
5655: ${OCI_BASE?}
5756
58- export VERSION=$( git describe --tags --always --match=' v*' --abbrev=14 --dirty)
59- export KO_DOCKER_REPO=$OCI_BASE /images/venafi-agent
60- export TERM=dumb
61-
62- script_dir=$( cd -- " $( dirname -- " ${BASH_SOURCE[0]} " ) " & > /dev/null && pwd)
63- root_dir=$( cd " ${script_dir} /../.." && pwd)
64-
65- cd " ${script_dir} "
66-
67- pushd " ${root_dir} "
68- ko build --bare --tags " ${VERSION} "
69- helm package deploy/charts/venafi-kubernetes-agent --version " ${VERSION} " --app-version " ${VERSION} "
70- helm push venafi-kubernetes-agent-${VERSION} .tgz " oci://${OCI_BASE} /charts"
71- popd
72-
73- export USE_GKE_GCLOUD_AUTH_PLUGIN=True
7457# Required gcloud environment variables
7558# https://cloud.google.com/sdk/docs/configurations#setting_configuration_properties
7659: ${CLOUDSDK_CORE_PROJECT?}
@@ -79,22 +62,36 @@ export USE_GKE_GCLOUD_AUTH_PLUGIN=True
7962# The name of the cluster to create
8063: ${CLUSTER_NAME?}
8164
65+ # IMPORTANT: we pick the first team as the owning team for the registry and
66+ # workload identity service account as it doesn't matter.
67+
68+ version=$( git describe --tags --always --match=' v*' --abbrev=14 --dirty)
69+
70+ cd " ${script_dir} "
71+
72+ pushd " ${root_dir} "
73+ KO_DOCKER_REPO=$OCI_BASE /images/venafi-agent ko build --bare --tags " ${version} "
74+ helm package deploy/charts/venafi-kubernetes-agent --version " ${version} " --app-version " ${version} "
75+ helm push " venafi-kubernetes-agent-${version} .tgz" " oci://${OCI_BASE} /charts"
76+ popd
77+
78+ export USE_GKE_GCLOUD_AUTH_PLUGIN=True
8279if ! gcloud container clusters get-credentials " ${CLUSTER_NAME} " ; then
83- gcloud container clusters create " ${CLUSTER_NAME} " \
84- --preemptible \
85- --machine-type e2-small \
86- --num-nodes 3
80+ gcloud container clusters create " ${CLUSTER_NAME} " \
81+ --preemptible \
82+ --machine-type e2-small \
83+ --num-nodes 3
8784fi
8885kubectl create ns venafi || true
8986
9087# Pull secret for Venafi OCI registry
9188if ! kubectl get secret venafi-image-pull-secret -n venafi; then
92- venctl iam service-accounts registry create \
93- --api-key " ${VEN_API_KEY_PULL} " \
94- --no-prompts \
95- --owning-team " ${VEN_OWNING_TEAM} " \
96- --name " venafi-kubernetes-agent-e2e-registry-${RANDOM} " \
97- --scopes enterprise-cert-manager,enterprise-venafi-issuer,enterprise-approver-policy \
89+ venctl iam service-accounts registry create \
90+ --api-key " ${VEN_API_KEY_PULL} " \
91+ --no-prompts \
92+ --owning-team " $( curl --fail-with-body -sS " https:// ${VEN_API_HOST} /v1/teams " -H " tppl-api-key: $VEN_API_KEY_PULL " | jq ' .teams[0].id ' -r ) " \
93+ --name " venafi-kubernetes-agent-e2e-registry-${RANDOM} " \
94+ --scopes enterprise-cert-manager,enterprise-venafi-issuer,enterprise-approver-policy \
9895 | jq ' {
9996 "apiVersion": "v1",
10097 "kind": "Secret",
118115
119116export VENAFI_KUBERNETES_AGENT_CLIENT_ID=" not-used-but-required-by-venctl"
120117venctl components kubernetes apply \
121- --cert-manager \
122- --venafi-enhanced-issuer \
123- --approver-policy-enterprise \
124- --venafi-kubernetes-agent \
125- --venafi-kubernetes-agent-version " ${VERSION } " \
126- --venafi-kubernetes-agent-values-files " ${script_dir} /values.venafi-kubernetes-agent.yaml" \
127- --venafi-kubernetes-agent-custom-image-registry " ${OCI_BASE} /images" \
128- --venafi-kubernetes-agent-custom-chart-repository " oci://${OCI_BASE} /charts"
118+ --cert-manager \
119+ --venafi-enhanced-issuer \
120+ --approver-policy-enterprise \
121+ --venafi-kubernetes-agent \
122+ --venafi-kubernetes-agent-version " ${version } " \
123+ --venafi-kubernetes-agent-values-files " ${script_dir} /values.venafi-kubernetes-agent.yaml" \
124+ --venafi-kubernetes-agent-custom-image-registry " ${OCI_BASE} /images" \
125+ --venafi-kubernetes-agent-custom-chart-repository " oci://${OCI_BASE} /charts"
129126
130127kubectl apply -n venafi -f venafi-components.yaml
131128
132129subject=" system:serviceaccount:venafi:venafi-components"
133130audience=" https://${VEN_API_HOST} "
134131issuerURL=" $( kubectl create token -n venafi venafi-components | step crypto jwt inspect --insecure | jq -r ' .payload.iss' ) "
135132openidDiscoveryURL=" ${issuerURL} /.well-known/openid-configuration"
136- jwksURI=$( curl -fsSL ${openidDiscoveryURL} | jq -r ' .jwks_uri' )
133+ jwksURI=$( curl --fail-with-body -sSL ${openidDiscoveryURL} | jq -r ' .jwks_uri' )
137134
138135# Create the Venafi agent service account if one does not already exist
139136while true ; do
140- tenantID=$( curl -fsSL -H " tppl-api-key: $VEN_API_KEY " https://${VEN_API_HOST} /v1/serviceaccounts \
141- | jq -r ' .[] | select(.issuerURL==$issuerURL and .subject == $subject) | .companyId' \
142- --arg issuerURL " ${issuerURL} " \
143- --arg subject " ${subject} " )
137+ tenantID=$( curl --fail-with-body -sSL -H " tppl-api-key: $VEN_API_KEY " https://${VEN_API_HOST} /v1/serviceaccounts \
138+ | jq -r ' .[] | select(.issuerURL==$issuerURL and .subject == $subject) | .companyId' \
139+ --arg issuerURL " ${issuerURL} " \
140+ --arg subject " ${subject} " )
144141
145- if [[ " ${tenantID} " != " " ]]; then
146- break
147- fi
142+ if [[ " ${tenantID} " != " " ]]; then
143+ break
144+ fi
148145
149- jq -n ' {
146+ jq -n ' {
150147 "name": "venafi-kubernetes-agent-e2e-agent-\($random)",
151148 "authenticationType": "rsaKeyFederated",
152149 "scopes": ["kubernetes-discovery-federated", "certificate-issuance"],
@@ -155,19 +152,19 @@ while true; do
155152 "issuerURL": $issuerURL,
156153 "jwksURI": $jwksURI,
157154 "applications": [$applications.applications[].id],
158- "owner": $teams.teams[] | select(.name==$teamName) | .id
155+ "owner": $owningTeamID
159156 }' \
160- --arg random " ${RANDOM} " \
161- --arg teamName " ${VEN_OWNING_TEAM } " \
162- --arg subject " ${subject } " \
163- --arg audience " ${audience } " \
164- --arg issuerURL " ${issuerURL } " \
165- --arg jwksURI " ${jwksURI} " \
166- --argjson teams " $( curl https://${VEN_API_HOST} /v1/teams -fsSL -H tppl-api-key:\ ${VEN_API_KEY} ) " \
167- --argjson applications " $( curl https://${VEN_API_HOST} /outagedetection/ v1/applications -fsSL -H tppl-api-key: \ ${VEN_API_KEY} ) " \
168- | curl https:// ${VEN_API_HOST} /v1/serviceaccounts \
169- -H " tppl-api-key: $VEN_API_KEY " \
170- -fsSL --json @-
157+ --arg random " ${RANDOM} " \
158+ --arg subject " ${subject } " \
159+ --arg audience " ${audience } " \
160+ --arg issuerURL " ${issuerURL } " \
161+ --arg jwksURI " ${jwksURI } " \
162+ --arg owningTeamID " $( curl --fail-with-body -sS " https:// ${VEN_API_HOST} /v1/teams " -H " tppl-api-key: $VEN_API_KEY " | jq ' .teams[0].id ' -r ) " \
163+ --argjson applications " $( curl https://${VEN_API_HOST} /outagedetection/ v1/applications --fail-with-body -sSL -H tppl-api-key:\ ${VEN_API_KEY} ) " \
164+ | curl https://${VEN_API_HOST} /v1/serviceaccounts \
165+ -H " tppl-api-key: $VEN_API_KEY " \
166+ --fail-with-body \
167+ -sSL --json @-
171168done
172169
173170kubectl apply -n venafi -f - << EOF
@@ -188,14 +185,14 @@ spec:
188185 tenantID: ${tenantID}
189186EOF
190187
191- envsubst < application-team-1.yaml | kubectl apply -f -
188+ envsubst < application-team-1.yaml | kubectl apply -f -
192189kubectl -n team-1 wait certificate app-0 --for=condition=Ready
193190
194191# Wait for log message indicating success.
195192# Filter out distracting data gatherer errors and warnings.
196193# Show other useful log messages on stderr.
197194kubectl logs deployments/venafi-kubernetes-agent \
198- --follow \
199- --namespace venafi \
200- | tee >( grep -v -e " reflector\.go" -e " datagatherer" -e " data gatherer" > /dev/stderr) \
201- | grep -q " Data sent successfully"
195+ --follow \
196+ --namespace venafi \
197+ | tee >( grep -v -e " reflector\.go" -e " datagatherer" -e " data gatherer" > /dev/stderr) \
198+ | grep -q " Data sent successfully"
0 commit comments