19
19
# * step: https://smallstep.com/docs/step-cli/installation/
20
20
# * curl: https://www.man7.org/linux/man-pages/man1/curl.1.html
21
21
# * 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
22
29
23
30
set -o nounset
24
31
set -o errexit
25
32
set -o pipefail
33
+ set -o xtrace
26
34
27
35
# Your Venafi Cloud API key.
28
36
: ${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?}
29
40
30
41
# The Venafi Cloud team which will be the owner of the generated Venafi service
31
42
# accounts.
32
43
: ${VEN_OWNING_TEAM?}
33
44
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
+
34
54
# The base URL of the OCI registry used for Docker images and Helm charts
35
55
# E.g. ttl.sh/63773370-0bcf-4ac0-bd42-5515616089ff
36
56
: ${OCI_BASE?}
@@ -50,13 +70,27 @@ helm package deploy/charts/venafi-kubernetes-agent --version "${VERSION}" --app-
50
70
helm push venafi-kubernetes-agent-${VERSION} .tgz " oci://${OCI_BASE} /charts"
51
71
popd
52
72
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?}
54
78
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
55
88
kubectl create ns venafi || true
56
89
57
90
# Pull secret for Venafi OCI registry
58
91
if ! kubectl get secret venafi-image-pull-secret -n venafi; then
59
92
venctl iam service-accounts registry create \
93
+ --api-key " ${VEN_API_KEY_PULL} " \
60
94
--no-prompts \
61
95
--owning-team " ${VEN_OWNING_TEAM} " \
62
96
--name " venafi-kubernetes-agent-e2e-registry-${RANDOM} " \
@@ -82,55 +116,80 @@ if ! kubectl get secret venafi-image-pull-secret -n venafi; then
82
116
| kubectl create -n venafi -f -
83
117
fi
84
118
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
-
107
119
export VENAFI_KUBERNETES_AGENT_CLIENT_ID=" not-used-but-required-by-venctl"
108
120
venctl components kubernetes apply \
121
+ --cert-manager \
122
+ --venafi-enhanced-issuer \
123
+ --approver-policy-enterprise \
109
124
--venafi-kubernetes-agent \
110
- --venafi-kubernetes-agent-version " $VERSION " \
125
+ --venafi-kubernetes-agent-version " ${ VERSION} " \
111
126
--venafi-kubernetes-agent-values-files " ${script_dir} /values.venafi-kubernetes-agent.yaml" \
112
127
--venafi-kubernetes-agent-custom-image-registry " ${OCI_BASE} /images" \
113
128
--venafi-kubernetes-agent-custom-chart-repository " oci://${OCI_BASE} /charts"
114
129
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
134
193
135
194
# Wait for log message indicating success.
136
195
# Filter out distracting data gatherer errors and warnings.
0 commit comments