Skip to content

Commit 184de24

Browse files
committed
Load the username and password from the agent-credentials secret
Signed-off-by: Richard Wall <[email protected]>
1 parent c9349f9 commit 184de24

File tree

4 files changed

+97
-28
lines changed

4 files changed

+97
-28
lines changed

deploy/charts/venafi-kubernetes-agent/templates/deployment.yaml

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ spec:
4949
valueFrom:
5050
fieldRef:
5151
fieldPath: spec.nodeName
52+
- name: ARK_USERNAME
53+
valueFrom:
54+
secretKeyRef:
55+
name: {{ .Values.authentication.secretName }}
56+
key: username
57+
- name: ARK_SECRET
58+
valueFrom:
59+
secretKeyRef:
60+
name: {{ .Values.authentication.secretName }}
61+
key: password
5262
{{- with .Values.http_proxy }}
5363
- name: HTTP_PROXY
5464
value: {{ . }}
@@ -71,18 +81,8 @@ spec:
7181
- "agent"
7282
- "-c"
7383
- "/etc/venafi/agent/config/{{ default "config.yaml" .Values.config.configmap.key }}"
74-
{{- if .Values.authentication.venafiConnection.enabled }}
75-
- --venafi-connection
76-
- {{ .Values.authentication.venafiConnection.name | quote }}
77-
- --venafi-connection-namespace
78-
- {{ .Values.authentication.venafiConnection.namespace | quote }}
79-
{{- else }}
80-
- "--client-id"
81-
- {{ .Values.config.clientId | quote }}
82-
- "--private-key-path"
83-
- "/etc/venafi/agent/key/{{ .Values.authentication.secretKey }}"
84-
{{- end }}
85-
- --venafi-cloud
84+
- --log-level=6
85+
- --machine-hub
8686
{{- if .Values.metrics.enabled }}
8787
- --enable-metrics
8888
{{- end }}
@@ -95,11 +95,6 @@ spec:
9595
- name: config
9696
mountPath: "/etc/venafi/agent/config"
9797
readOnly: true
98-
{{- if not .Values.authentication.venafiConnection.enabled }}
99-
- name: credentials
100-
mountPath: "/etc/venafi/agent/key"
101-
readOnly: true
102-
{{- end }}
10398
{{- with .Values.volumeMounts }}
10499
{{- toYaml . | nindent 12 }}
105100
{{- end }}
@@ -137,12 +132,6 @@ spec:
137132
configMap:
138133
name: {{ default "agent-config" .Values.config.configmap.name }}
139134
optional: false
140-
{{- if not .Values.authentication.venafiConnection.enabled }}
141-
- name: credentials
142-
secret:
143-
secretName: {{ .Values.authentication.secretName }}
144-
optional: false
145-
{{- end }}
146135
{{- with .Values.volumes }}
147136
{{- toYaml . | nindent 8 }}
148137
{{- end }}

hack/e2e/ca/test.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env bash
2+
#
3+
set -o nounset
4+
set -o errexit
5+
set -o pipefail
6+
7+
# CyberArk API configuration
8+
: ${ARK_USERNAME?}
9+
: ${ARK_SECRET?}
10+
: ${ARK_API_URL?}
11+
12+
# The base URL of the OCI registry used for Docker images and Helm charts
13+
# E.g. ttl.sh/6ee49a01-c8ba-493e-bae9-4d8567574b56
14+
: ${OCI_BASE?}
15+
16+
k8s_namespace=cyberark
17+
18+
script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
19+
root_dir=$(cd "${script_dir}/../../.." && pwd)
20+
export TERM=dumb
21+
22+
tmp_dir="$(mktemp -d /tmp/jetstack-secure.XXXXX)"
23+
24+
pushd "${tmp_dir}"
25+
> release.env
26+
make -C "$root_dir" release \
27+
OCI_SIGN_ON_PUSH=false \
28+
oci_platforms=linux/amd64 \
29+
oci_preflight_image_name=$OCI_BASE/images/venafi-agent \
30+
helm_chart_image_name=$OCI_BASE/charts/venafi-kubernetes-agent \
31+
GITHUB_OUTPUT="${tmp_dir}/release.env"
32+
source release.env
33+
34+
kind create cluster || true
35+
kubectl create ns "$k8s_namespace" || true
36+
37+
kubectl create secret generic agent-credentials \
38+
--namespace "$k8s_namespace" \
39+
--from-literal=username=$ARK_USERNAME \
40+
--from-literal=password=$ARK_SECRET
41+
42+
helm upgrade agent "oci://${OCI_BASE}/charts/venafi-kubernetes-agent" \
43+
--install \
44+
--create-namespace \
45+
--namespace "$k8s_namespace" \
46+
--version "${RELEASE_HELM_CHART_VERSION}" \
47+
--set fullnameOverride=agent \
48+
--set "image.repository=${OCI_BASE}/images/venafi-agent" \
49+
--values "${script_dir}/values.agent.yaml"
50+
51+
kubectl scale -n "$k8s_namespace" deployment agent --replicas=0
52+
kubectl get cm -n "$k8s_namespace" agent-config -o jsonpath={.data.config\\.yaml} > config.original.yaml
53+
yq eval-all '. as $item ireduce ({}; . * $item)' config.original.yaml "${script_dir}/config.yaml" > config.yaml
54+
kubectl delete cm -n "$k8s_namespace" agent-config
55+
kubectl create cm -n "$k8s_namespace" agent-config --from-file=config.yaml
56+
kubectl scale -n "$k8s_namespace" deployment agent --replicas=1
57+
58+
59+
60+

hack/e2e/ca/values.agent.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Empty

pkg/agent/run.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,37 @@ func Run(cmd *cobra.Command, args []string) (returnErr error) {
8383

8484
var caClient *client.CyberArkClient
8585
{
86+
platformDomain := os.Getenv("ARK_PLATFORM_DOMAIN")
87+
subdomain := os.Getenv("ARK_SUBDOMAIN")
88+
username := os.Getenv("ARK_USERNAME")
89+
password := []byte(os.Getenv("ARK_SECRET"))
8690

87-
discoveryClient := servicediscovery.New(servicediscovery.WithIntegrationEndpoint())
88-
identityClient, err := identity.NewWithDiscoveryClient(ctx, discoveryClient, cfg.MachineHub.Subdomain)
91+
const (
92+
discoveryContextServiceName = "inventory"
93+
separator = "."
94+
)
95+
96+
// TODO(wallrj): Maybe get this URL via the service discovery API.
97+
// https://platform-discovery.integration-cyberark.cloud/api/public/tenant-discovery?allEndpoints=true&bySubdomain=tlskp-test
98+
serviceURL := fmt.Sprintf("https://%s%s%s.%s", subdomain, separator, discoveryContextServiceName, platformDomain)
99+
100+
var (
101+
identityClient *identity.Client
102+
err error
103+
)
104+
if platformDomain == "cyberark.cloud" {
105+
identityClient, err = identity.New(ctx, subdomain)
106+
} else {
107+
discoveryClient := servicediscovery.New(servicediscovery.WithIntegrationEndpoint())
108+
identityClient, err = identity.NewWithDiscoveryClient(ctx, discoveryClient, subdomain)
109+
}
89110
if err != nil {
90111
return fmt.Errorf("while creating the CyberArk identity client: %v", err)
91112
}
92-
username := os.Getenv("ARK_USERNAME")
93-
password := []byte(os.Getenv("ARK_SECRET"))
94113
if err := identityClient.LoginUsernamePassword(ctx, username, password); err != nil {
95114
return fmt.Errorf("while logging in: %v", err)
96115
}
97-
caClient, err = client.NewCyberArkClient(nil, os.Getenv("ARK_API_URL"), identityClient.AuthenticateRequest)
116+
caClient, err = client.NewCyberArkClient(nil, serviceURL, identityClient.AuthenticateRequest)
98117
if err != nil {
99118
return fmt.Errorf("while creating the CyberArk dataupload client: %v", err)
100119
}

0 commit comments

Comments
 (0)