1919# * step: https://smallstep.com/docs/step-cli/installation/
2020# * curl: https://www.man7.org/linux/man-pages/man1/curl.1.html
2121# * envsubst: https://www.man7.org/linux/man-pages/man1/envsubst.1.html
22+ # * gcloud: https://cloud.google.com/sdk/docs/install
23+ # * gke-gcloud-auth-plugin: https://cloud.google.com/kubernetes-engine/docs/how-to/cluster-access-for-kubectl
24+ # > :warning: If you installed gcloud using snap, you have to install the kubectl plugin using apt:
25+ # > https://github.com/actions/runner-images/issues/6778#issuecomment-1360360603
26+ #
27+ # In case metrics and logs are missing from your cluster, see:
28+ # * https://cloud.google.com/kubernetes-engine/docs/troubleshooting/dashboards#write_permissions
2229
2330set -o nounset
2431set -o errexit
2532set -o pipefail
33+ set -o xtrace
2634
2735# Your Venafi Cloud API key.
2836: ${VEN_API_KEY?}
37+ # Separate API Key for getting a pull secret, if your main venafi cloud tenant
38+ # doesn't allow you to create registry service accounts.
39+ : ${VEN_API_KEY_PULL?}
2940
3041# The Venafi Cloud team which will be the owner of the generated Venafi service
3142# accounts.
3243: ${VEN_OWNING_TEAM?}
3344
45+ # The Venafi Cloud zone (application/issuing_template) which will be used by the
46+ # issuer an policy.
47+ : ${VEN_ZONE?}
48+
49+ # The hostname of the Venafi API server.
50+ # US: api.venafi.cloud
51+ # EU: api.venafi.eu
52+ : ${VEN_API_HOST?}
53+
3454# The base URL of the OCI registry used for Docker images and Helm charts
3555# E.g. ttl.sh/63773370-0bcf-4ac0-bd42-5515616089ff
3656: ${OCI_BASE?}
@@ -50,13 +70,27 @@ helm package deploy/charts/venafi-kubernetes-agent --version "${VERSION}" --app-
5070helm push venafi-kubernetes-agent-${VERSION} .tgz " oci://${OCI_BASE} /charts"
5171popd
5272
53- kind create cluster || true
73+ export USE_GKE_GCLOUD_AUTH_PLUGIN=True
74+ # Required gcloud environment variables
75+ # https://cloud.google.com/sdk/docs/configurations#setting_configuration_properties
76+ : ${CLOUDSDK_CORE_PROJECT?}
77+ : ${CLOUDSDK_COMPUTE_ZONE?}
5478
79+ # The name of the cluster to create
80+ : ${CLUSTER_NAME?}
81+
82+ if ! 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
87+ fi
5588kubectl create ns venafi || true
5689
5790# Pull secret for Venafi OCI registry
5891if ! kubectl get secret venafi-image-pull-secret -n venafi; then
5992 venctl iam service-accounts registry create \
93+ --api-key " ${VEN_API_KEY_PULL} " \
6094 --no-prompts \
6195 --owning-team " ${VEN_OWNING_TEAM} " \
6296 --name " venafi-kubernetes-agent-e2e-registry-${RANDOM} " \
@@ -82,55 +116,80 @@ if ! kubectl get secret venafi-image-pull-secret -n venafi; then
82116 | kubectl create -n venafi -f -
83117fi
84118
85- # Cache the Service account credentials for venafi-kubernetes-agent in the cluster
86- # but this Secret will not be mounted by the agent.
87- kubectl create ns venafi-kubernetes-agent-e2e || true
88- if ! kubectl get secret cached-venafi-agent-service-account -n venafi-kubernetes-agent-e2e; then
89- venctl iam service-account agent create \
90- --no-prompts \
91- --owning-team " ${VEN_OWNING_TEAM} " \
92- --name " venafi-kubernetes-agent-e2e-agent-${RANDOM} " \
93- | jq ' {
94- "apiVersion": "v1",
95- "kind": "Secret",
96- "metadata": {
97- "name": "cached-venafi-agent-service-account"
98- },
99- "stringData": {
100- "privatekey.pem": .private_key,
101- "client-id": .client_id
102- }
103- }' \
104- | kubectl create -n venafi-kubernetes-agent-e2e -f -
105- fi
106-
107119export VENAFI_KUBERNETES_AGENT_CLIENT_ID=" not-used-but-required-by-venctl"
108120venctl components kubernetes apply \
121+ --cert-manager \
122+ --venafi-enhanced-issuer \
123+ --approver-policy-enterprise \
109124 --venafi-kubernetes-agent \
110- --venafi-kubernetes-agent-version " $VERSION " \
125+ --venafi-kubernetes-agent-version " ${ VERSION} " \
111126 --venafi-kubernetes-agent-values-files " ${script_dir} /values.venafi-kubernetes-agent.yaml" \
112127 --venafi-kubernetes-agent-custom-image-registry " ${OCI_BASE} /images" \
113128 --venafi-kubernetes-agent-custom-chart-repository " oci://${OCI_BASE} /charts"
114129
115- privatekey=$( kubectl get secret cached-venafi-agent-service-account \
116- --namespace venafi-kubernetes-agent-e2e \
117- --template=" {{index .data \" privatekey.pem\" | base64decode}}" )
118- clientid=$( kubectl get secret cached-venafi-agent-service-account \
119- --namespace venafi-kubernetes-agent-e2e \
120- --template=" {{index .data \" client-id\" | base64decode}}" )
121- jwt=$( step crypto jwt sign \
122- --key <( sed ' s/ PRIVATE KEY/ EC PRIVATE KEY/g' <<< " $privatekey" ) \
123- --aud api.venafi.cloud/v1/oauth/token/serviceaccount \
124- --exp " $( [ " $( uname) " = " Darwin" ] && date -v +30M +' %s' || date -d ' +30 minutes' +' %s' ) " \
125- --sub " $clientid " \
126- --iss " $clientid " \
127- | tee >( step crypto jwt inspect --insecure > /dev/stderr) )
128- accesstoken=$( curl https://api.venafi.cloud/v1/oauth/token/serviceaccount \
129- -sS --fail-with-body \
130- --data-urlencode assertion=" $jwt " \
131- --data-urlencode grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer | tee /dev/stderr | jq ' .access_token' -r)
132- export accesstoken
133- envsubst < venafi-components.yaml | kubectl apply -n venafi -f -
130+ kubectl apply -n venafi -f venafi-components.yaml
131+
132+ subject=" system:serviceaccount:venafi:venafi-components"
133+ audience=" https://${VEN_API_HOST} "
134+ issuerURL=" $( kubectl create token -n venafi venafi-components | step crypto jwt inspect --insecure | jq -r ' .payload.iss' ) "
135+ openidDiscoveryURL=" ${issuerURL} /.well-known/openid-configuration"
136+ jwksURI=$( curl -fsSL ${openidDiscoveryURL} | jq -r ' .jwks_uri' )
137+
138+ # Create the Venafi agent service account if one does not already exist
139+ while 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} " )
144+
145+ if [[ " ${tenantID} " != " " ]]; then
146+ break
147+ fi
148+
149+ jq -n ' {
150+ "name": "venafi-kubernetes-agent-e2e-agent-\($random)",
151+ "authenticationType": "rsaKeyFederated",
152+ "scopes": ["kubernetes-discovery-federated", "certificate-issuance"],
153+ "subject": $subject,
154+ "audience": $audience,
155+ "issuerURL": $issuerURL,
156+ "jwksURI": $jwksURI,
157+ "applications": [$applications.applications[].id],
158+ "owner": $teams.teams[] | select(.name==$teamName) | .id
159+ }' \
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 @-
171+ done
172+
173+ kubectl apply -n venafi -f - << EOF
174+ apiVersion: jetstack.io/v1alpha1
175+ kind: VenafiConnection
176+ metadata:
177+ name: venafi-components
178+ spec:
179+ allowReferencesFrom: {}
180+ vcp:
181+ url: https://${VEN_API_HOST}
182+ accessToken:
183+ - serviceAccountToken:
184+ name: venafi-components
185+ audiences:
186+ - ${audience}
187+ - vcpOAuth:
188+ tenantID: ${tenantID}
189+ EOF
190+
191+ envsubst < application-team-1.yaml | kubectl apply -f -
192+ kubectl -n team-1 wait certificate app-0 --for=condition=Ready
134193
135194# Wait for log message indicating success.
136195# Filter out distracting data gatherer errors and warnings.
0 commit comments