Skip to content

Commit 53edc79

Browse files
authored
Merge pull request #64 from scalyr/raw_api_key_value
Prototype for using raw SCALYR_API_KEY environment variable value as-is (e.g. kube-secrets-init use case)
2 parents e1580a6 + 75799e3 commit 53edc79

File tree

10 files changed

+269
-3
lines changed

10 files changed

+269
-3
lines changed

.github/workflows/end_to_end_tests.yaml

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,173 @@ jobs:
226226
steps: ${{ toJson(steps) }}
227227
channel: '#cloud-tech'
228228

229+
# Here we test the scenario where an raw apiKey chart value is used for SCALYR_API_KEY pod
230+
# environment variable. This is to support the use cases like kube-secrets-init where
231+
# the raw value contains reference to the secret which is replaced by external operator.
232+
# Keep in mind that we only store raw api key itself in the secret for testing purposes,
233+
# this is a bad practice and should never be used in real life.
234+
daemonset_controller_type_raw_api_key_secret_value:
235+
name: Daemonset - raw secret - k8s ${{ matrix.k8s_version }} - ${{ matrix.image_type }}
236+
runs-on: ubuntu-latest
237+
238+
needs: pre_job
239+
timeout-minutes: 15
240+
# NOTE: We always want to run job on main branch
241+
if: ${{ needs.pre_job.outputs.should_skip != 'true' || github.ref == 'refs/heads/main' }}
242+
243+
strategy:
244+
fail-fast: false
245+
matrix:
246+
k8s_version:
247+
- 'v1.24.3'
248+
image_type:
249+
- "buster"
250+
251+
steps:
252+
- name: Checkout Repository
253+
uses: actions/checkout@v3
254+
with:
255+
fetch-depth: 1
256+
257+
- name: Set up Chart Testing Environment and Kubernetes Cluster
258+
uses: ./.github/actions/setup-chart-testing-environment/
259+
with:
260+
k8s_version: "${{ matrix.k8s_version }}"
261+
github_token: "${{ secrets.GITHUB_TOKEN }}"
262+
263+
- name: Install Scalyr Tool
264+
uses: ./.github/actions/install-scalyr-tool/
265+
266+
- name: Install Helm Chart
267+
uses: ./.github/actions/install-helm-chart
268+
with:
269+
scalyr_api_key: "${{ secrets.SCALYR_WRITE_API_KEY_US }}"
270+
values_file_path: "ci/daemonset-agent-values-raw-secret.yaml"
271+
image_type: "${{ matrix.image_type }}"
272+
273+
- name: Describe Pod
274+
run: |
275+
set -e
276+
277+
kubectl describe pod ${SCALYR_AGENT_POD_NAME}
278+
279+
# Verify test volume defined using chart volumes and volumeMounts value is there
280+
kubectl describe pod ${SCALYR_AGENT_POD_NAME} | grep "/test-volume from test-volume (rw)"
281+
kubectl describe pod ${SCALYR_AGENT_POD_NAME} | grep "test-volume:"
282+
283+
# Verify that secret hasn't been created since useRawApiKeyEnvValue is used
284+
kubectl get secret
285+
kubectl get secret | grep -vz scalyr-api-key
286+
287+
- name: Verify Agent Logs are Ingested
288+
env:
289+
scalyr_readlog_token: "${{ secrets.SCALYR_READ_API_KEY_US }}"
290+
SCALYR_AGENT_POD_NAME: "${{ env.SCALYR_AGENT_POD_NAME }}"
291+
run: |
292+
# Verify agent and kubernetes monitor has been started
293+
./ci/scripts/scalyr-query.sh '$serverHost="'${SCALYR_AGENT_POD_NAME}'" $logfile="/var/log/scalyr-agent-2/agent.log" attribute1="value1" "Starting scalyr agent..."'
294+
./ci/scripts/scalyr-query.sh '$serverHost="'${SCALYR_AGENT_POD_NAME}'" $logfile="/var/log/scalyr-agent-2/agent.log" attribute1="value1" "No checkpoints were found. All logs will be copied starting at their current end"'
295+
296+
./ci/scripts/scalyr-query.sh '$serverHost="'${SCALYR_AGENT_POD_NAME}'" $logfile="/var/log/scalyr-agent-2/agent.log" attribute1="value1" "Cluster name detected, enabling k8s metric reporting"'
297+
./ci/scripts/scalyr-query.sh '$serverHost="'${SCALYR_AGENT_POD_NAME}'" $logfile="/var/log/scalyr-agent-2/agent.log" attribute1="value1" "kubernetes_monitor parameters: "'
298+
299+
# Verify Kubernetes metrics are beeing ingested
300+
./ci/scripts/scalyr-query.sh '$serverHost="'${SCALYR_AGENT_POD_NAME}'" $logfile="/var/log/scalyr-agent-2/kubernetes_monitor.log" "k8s-daemon-set=\"scalyr-agent\""'
301+
302+
- name: Notify Slack on Failure
303+
# NOTE: github.ref is set to pr ref (and not branch name, e.g. refs/pull/28/merge) for pull
304+
# requests and that's why we need this special conditional and check for github.head_ref in
305+
# case of PRs
306+
if: ${{ failure() && (github.ref == 'refs/heads/main' || github.head_ref == 'main') }}
307+
uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f # v2.0.0
308+
env:
309+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
310+
with:
311+
status: ${{ job.status }}
312+
steps: ${{ toJson(steps) }}
313+
channel: '#cloud-tech'
314+
315+
deployment_controller_type_raw_api_key_secret_value:
316+
name: Deployment - raw secret - k8s ${{ matrix.k8s_version }} - ${{ matrix.image_type }}
317+
runs-on: ubuntu-latest
318+
319+
needs: pre_job
320+
timeout-minutes: 15
321+
# NOTE: We always want to run job on main branch
322+
if: ${{ needs.pre_job.outputs.should_skip != 'true' || github.ref == 'refs/heads/main' }}
323+
324+
strategy:
325+
fail-fast: false
326+
matrix:
327+
k8s_version:
328+
- 'v1.24.3'
329+
image_type:
330+
- "buster"
331+
332+
steps:
333+
- name: Checkout Repository
334+
uses: actions/checkout@v3
335+
with:
336+
fetch-depth: 1
337+
338+
- name: Set up Chart Testing Environment and Kubernetes Cluster
339+
uses: ./.github/actions/setup-chart-testing-environment/
340+
with:
341+
k8s_version: "${{ matrix.k8s_version }}"
342+
github_token: "${{ secrets.GITHUB_TOKEN }}"
343+
344+
- name: Install Scalyr Tool
345+
uses: ./.github/actions/install-scalyr-tool/
346+
347+
- name: Install Helm Chart
348+
uses: ./.github/actions/install-helm-chart
349+
with:
350+
scalyr_api_key: "${{ secrets.SCALYR_WRITE_API_KEY_US }}"
351+
values_file_path: "ci/deployment-agent-values-raw-secret.yaml"
352+
image_type: "${{ matrix.image_type }}"
353+
354+
- name: Describe Pod
355+
run: |
356+
set -e
357+
358+
kubectl describe pod ${SCALYR_AGENT_POD_NAME}
359+
360+
# Verify test volume defined using chart volumes and volumeMounts value is there
361+
kubectl describe pod ${SCALYR_AGENT_POD_NAME} | grep "/test-volume from test-volume (rw)"
362+
kubectl describe pod ${SCALYR_AGENT_POD_NAME} | grep "test-volume:"
363+
364+
# Verify that secret hasn't been created since useRawApiKeyEnvValue is used
365+
kubectl get secret
366+
kubectl get secret | grep -vz scalyr-api-key
367+
368+
- name: Verify Logs are Ingested
369+
env:
370+
scalyr_readlog_token: "${{ secrets.SCALYR_READ_API_KEY_US }}"
371+
SCALYR_AGENT_POD_NAME: "${{ env.SCALYR_AGENT_POD_NAME }}"
372+
run: |
373+
# Verify agent and kubernetes monitor has been started
374+
./ci/scripts/scalyr-query.sh '$serverHost="'${SCALYR_AGENT_POD_NAME}'" $logfile="/var/log/scalyr-agent-2/agent.log" attribute1="value1" "Starting scalyr agent..."'
375+
./ci/scripts/scalyr-query.sh '$serverHost="'${SCALYR_AGENT_POD_NAME}'" $logfile="/var/log/scalyr-agent-2/agent.log" attribute1="value1" "No checkpoints were found. All logs will be copied starting at their current end"'
376+
377+
./ci/scripts/scalyr-query.sh '$serverHost="'${SCALYR_AGENT_POD_NAME}'" $logfile="/var/log/scalyr-agent-2/agent.log" attribute1="value1" "Cluster name detected, enabling k8s metric reporting"'
378+
./ci/scripts/scalyr-query.sh '$serverHost="'${SCALYR_AGENT_POD_NAME}'" $logfile="/var/log/scalyr-agent-2/agent.log" attribute1="value1" "kubernetes_monitor parameters: "'
379+
380+
# Verify Kubernetes metrics are beeing ingested
381+
./ci/scripts/scalyr-query.sh '$serverHost="'${SCALYR_AGENT_POD_NAME}'" $logfile="/var/log/scalyr-agent-2/kubernetes_monitor.log" "k8s-deployment=\"scalyr-agent\""'
382+
383+
- name: Notify Slack on Failure
384+
# NOTE: github.ref is set to pr ref (and not branch name, e.g. refs/pull/28/merge) for pull
385+
# requests and that's why we need this special conditional and check for github.head_ref in
386+
# case of PRs
387+
if: ${{ failure() && (github.ref == 'refs/heads/main' || github.head_ref == 'main') }}
388+
uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f # v2.0.0
389+
env:
390+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
391+
with:
392+
status: ${{ job.status }}
393+
steps: ${{ toJson(steps) }}
394+
channel: '#cloud-tech'
395+
229396
daemonset_controller_type_k8s_explorer_no_deps:
230397
# In this workflow we manually install node exporter and kube state metrics exporter dependency
231398
name: K8s Explorer - no deps - k8s ${{ matrix.k8s_version }} - ${{ matrix.image_type }}

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22

33
For actual scalyr agent changelog, please see https://github.com/scalyr/scalyr-agent-2/blob/release/CHANGELOG.md
44

5+
## 0.2.34
6+
7+
- Add new ``useRawApiKeyEnvValue`` chart value. When this value is set to true (defaults to false),
8+
``scalyr.apiKey`` chart value is used as-is for the ``SCALYR_API_KEY`` pod environment variable.
9+
10+
When this value is set to true, corresponding ``Secret`` object is also not created.
11+
12+
This value can be used in deployments which utilize an operator / tool like kube-secrets-init
13+
which directly replaces matching prefixed environment variable value with a secret value.
14+
15+
For more information on the use case and usage of this chart value, please refer to the
16+
README.md.
17+
18+
#61 #64
19+
520
## 0.2.33
621

722
- Update chart for DataSet agent v2.2.4 release.

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,23 @@ Example:
127127
```
128128
This gives the pod permission to read the secret as defined in the IAM Policy. (Something in the cluster such as a MutatingWebhook will need to actually facilitate the secret lookup)
129129

130+
## Using raw value for "SCALYR_API_KEY" pod environment variable
131+
132+
By default, ``scalyr.apiKey`` chart value is stored in a Kubernetes Secret and then this secret is
133+
referenced by the ``SCALYR_API_KEY`` pod environment variable.
134+
135+
In some situations, you may want to define a raw value for this environment variable. An example of
136+
that is using a tool like ``kube-secrets-init`` which relies on environment variable being set to a
137+
special prefixed value which will eventually get replaced with the actual secret by the tool itself.
138+
139+
Here is an example excerpt chart configuration for such use case:
140+
141+
```yaml
142+
# Values relevant to ServiceAccount
143+
scalyr:
144+
apiKey: gcp:secretmanager:projects/$PROJECT_ID/secrets/myscalyragentapikey/versions/2
145+
useRawApiKeyEnvValue: true
146+
```
130147
131148
## Changelog
132149

charts/scalyr-agent/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v2
22
name: scalyr-agent
33
description: A Helm chart for deploying the Scalyr agent
44
type: application
5-
version: 0.2.33
5+
version: 0.2.34
66
appVersion: 2.2.4
77
keywords:
88
- scalyr

charts/scalyr-agent/templates/daemonset.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ spec:
8989
- name: "SCALYR_SERVER"
9090
value: {{ .Values.scalyr.server }}
9191
- name: "SCALYR_API_KEY"
92+
{{- if .Values.useRawApiKeyEnvValue }}
93+
value: {{ .Values.scalyr.apiKey }}
94+
{{- else }}
9295
valueFrom:
9396
secretKeyRef:
9497
{{- if .Values.existingSecretRef }}
@@ -97,6 +100,7 @@ spec:
97100
name: "{{ include "scalyr-helm.fullname" . }}-scalyr-api-key"
98101
{{- end }}
99102
key: "scalyr-api-key"
103+
{{- end }}
100104
{{- if (or (or (.Values.scalyr.k8s.enableMetrics) (.Values.scalyr.k8s.enableLogs)) (.Values.scalyr.k8s.enableExplorer)) }}
101105
- name: "SCALYR_K8S_CLUSTER_NAME"
102106
value: "{{ .Values.scalyr.k8s.clusterName }}"

charts/scalyr-agent/templates/deployment.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ spec:
8787
- name: "SCALYR_SERVER"
8888
value: {{ .Values.scalyr.server }}
8989
- name: "SCALYR_API_KEY"
90+
{{- if .Values.useRawApiKeyEnvValue }}
91+
value: {{ .Values.scalyr.apiKey }}
92+
{{- else }}
9093
valueFrom:
9194
secretKeyRef:
9295
{{- if .Values.existingSecretRef }}
@@ -95,6 +98,7 @@ spec:
9598
name: "{{ include "scalyr-helm.fullname" . }}-scalyr-api-key"
9699
{{- end }}
97100
key: "scalyr-api-key"
101+
{{- end }}
98102
{{- if (or (or (.Values.scalyr.k8s.enableMetrics) (.Values.scalyr.k8s.enableLogs)) (.Values.scalyr.k8s.enableExplorer)) }}
99103
- name: "SCALYR_K8S_CLUSTER_NAME"
100104
value: "{{ .Values.scalyr.k8s.clusterName }}"

charts/scalyr-agent/templates/secret.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{- if not (.Values.useRawApiKeyEnvValue) }}
12
{{- if eq .Values.existingSecretRef "" -}}
23
{{- $name := .Values.scalyr.apiKey | required ".Values.scalyr.apiKey is required." -}}
34

@@ -9,4 +10,5 @@ metadata:
910
{{- include "scalyr-helm.labels" . | nindent 4 }}
1011
data:
1112
scalyr-api-key: {{ .Values.scalyr.apiKey | b64enc }}
12-
{{- end }}
13+
{{- end }}
14+
{{- end }}

charts/scalyr-agent/values.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ volumeMounts: {}
2828
scalyr:
2929
# scalyr.server -- The Scalyr server to send logs to. Use eu.scalyr.com for EU
3030
server: "agent.scalyr.com"
31-
# scalyr.apiKey -- The Scalyr API key to use
31+
# scalyr.apiKey -- The Scalyr API key to use. Can also be used in combination with "useRawApiKeyEnvValue" when using something like kube-secrets-init. In that case, this should be a reference to the secret which will be replaced by kube-secrets-init.
3232
apiKey: ""
3333
# scalyr.debugLevel -- Set this to number between 1 and 5 (inclusive - 1 being least verbose and
3434
# 5 being most verbose) to enable additional debug logging into agent_debug.log file.
@@ -151,5 +151,8 @@ serviceAccount:
151151
# serviceAccount.annotations -- optional arbitrary service account annotations
152152
annotations: {}
153153

154+
# useRawApiKeyEnvValue -- Set this to true if you want raw API key from "scalyr.apiKey" chart value to be used for the SCALYR_API_KEY pod environment variable. This comes handy in situations where you don't want to use a secret (e.g. you utilize something like kube-secrets-init which directly replaces environment variable value with the actual secret).
155+
useRawApiKeyEnvValue: false
156+
154157
# existingSecretRef -- Use this value if the Scalyr API key is already stored in a Kubernetes secret that was created by an external secrets operator or similar.
155158
existingSecretRef: ""
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Values file used by end to end tests
2+
controllerType: "daemonset"
3+
podLabels:
4+
test: "true"
5+
extraEnvVars:
6+
- name: SCALYR_FOO_1
7+
value: "foo1"
8+
- name: SCALYR_BAR_2
9+
value: "bar2"
10+
scalyr:
11+
apiKey: "REPLACE_ME"
12+
k8s:
13+
clusterName: "k8s-explorer-e2e-tests"
14+
verifyKubeletQueries: false
15+
base64Config: true
16+
config:
17+
# ci/examples/agent.d/test-config.json
18+
test-config.json: e3NlcnZlcl9hdHRyaWJ1dGVzOiB7YXR0cmlidXRlMTogInZhbHVlMSIsYXR0cmlidXRlMjogInZhbHVlMiIsfSx9
19+
20+
useRawApiKeyEnvValue: true
21+
22+
volumes:
23+
- name: test-volume
24+
emptyDir: {}
25+
26+
volumeMounts:
27+
- mountPath: /test-volume
28+
name: test-volume
29+
30+
image:
31+
distro: "IMAGE_TYPE"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Values file used by end to end tests
2+
controllerType: "deployment"
3+
podLabels:
4+
test: "true"
5+
scalyr:
6+
apiKey: "REPLACE_ME"
7+
k8s:
8+
clusterName: "k8s-explorer-e2e-tests"
9+
verifyKubeletQueries: false
10+
base64Config: true
11+
config:
12+
# ci/examples/agent.d/test-config.json
13+
test-config.json: e3NlcnZlcl9hdHRyaWJ1dGVzOiB7YXR0cmlidXRlMTogInZhbHVlMSIsYXR0cmlidXRlMjogInZhbHVlMiIsfSx9
14+
15+
useRawApiKeyEnvValue: true
16+
17+
volumes:
18+
- name: test-volume
19+
emptyDir: {}
20+
21+
volumeMounts:
22+
- mountPath: /test-volume
23+
name: test-volume

0 commit comments

Comments
 (0)