Skip to content

Commit cae1e4e

Browse files
authored
Merge pull request #50 from jullianow/improved_agent_setup_args
Improvements in defining arguments to setup tsagent
2 parents 2fead5d + ac4213f commit cae1e4e

File tree

6 files changed

+97
-38
lines changed

6 files changed

+97
-38
lines changed

README.md

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ Threat Stack Agent Helm Chart
77

88
This project defines the helm chart to deploy the Threat Stack container agent in the recommended configuration for kubernetes.
99

10-
>>>
11-
**Note:** The chart `version` is independent of the version of the agent packaged/installed by the chart. The default version of the Threat Stack agent to be installed by the helm chart is defined by the helm chart's `appVersion` field.
10+
> **Note**
11+
>
12+
> The chart `version` is independent of the version of the agent packaged/installed by the chart. The default version of the Threat Stack agent to be installed by the helm chart is defined by the helm chart's `appVersion` field.
1213
1314
Because agent updates and improvements from version to version can require backwards-incompatible chart changes, *we do not recommend customers override the agent version*.
14-
>>>
1515

1616
This chart installs the agent in the recommended configuration for kubernetes clusters. Configuration values should be overridden by passing helm one or more yaml files of overrides. See [Additional Installation Notes](#additional-installation-notes) section for specific recommendations. For a full list of values defined for this chart, see the `values.yaml` in this repository.
1717

@@ -62,16 +62,16 @@ The following kubernetes objects are created when the chart is installed:
6262
| ebpfEnabled | bool | `false` | Enables using ebpf-based monitoring where applicable. With some workloads, an increase in resource usage by the agent has been seen, so you may need to increase cpu and/or memory limits when enabling eBPF sensors |
6363
| eksAmazon2 | bool | `false` | If `true`, the Daemonset definition will be modified to execute commands for the agent to work correctly on EKS with Amazon Linux 2 nodes. Defaults to `false` |
6464
| eksAmazon2Cmd.args[0] | string | `"-c"` | |
65-
| eksAmazon2Cmd.args[1] | string | `"chroot /threatstackfs /bin/bash -c 'service auditd stop; systemctl disable auditd'; eval tsagent setup $THREATSTACK_SETUP_ARGS; eval tsagent config --set $THREATSTACK_CONFIG_ARGS; sleep 5; /opt/threatstack/sbin/tsagentd -logstdout"` | |
65+
| eksAmazon2Cmd.args[1] | string | `"chroot /threatstackfs /bin/bash -c 'service auditd stop; systemctl disable auditd'; eval tsagent setup --deploy-key $THREATSTACK_SETUP_DEPLOY_KEY $THREATSTACK_SETUP_ARGS; eval tsagent config --set $THREATSTACK_CONFIG_ARGS; sleep 5; /opt/threatstack/sbin/tsagentd -logstdout"` | |
6666
| eksAmazon2Cmd.command[0] | string | `"bash"` | |
6767
| fullnameOverride | string | `""` | |
6868
| gkeContainerOs | bool | `false` | If `true`, the Daemonset definition will be modified to execute commands for the agent to work correctly on GKE with ContainerOS node |
6969
| gkeContainerOsCmd.args[0] | string | `"-c"` | |
70-
| gkeContainerOsCmd.args[1] | string | `"chroot /threatstackfs /bin/bash -c 'systemctl stop systemd-journald-audit.socket; systemctl mask systemd-journald-audit.socket; systemctl restart systemd-journald; auditctl --backlog_wait_time 0'; eval tsagent setup $THREATSTACK_SETUP_ARGS; eval tsagent config --set $THREATSTACK_CONFIG_ARGS; sleep 5; /opt/threatstack/sbin/tsagentd -logstdout"` | |
70+
| gkeContainerOsCmd.args[1] | string | `"chroot /threatstackfs /bin/bash -c 'systemctl stop systemd-journald-audit.socket; systemctl mask systemd-journald-audit.socket; systemctl restart systemd-journald; auditctl --backlog_wait_time 0'; eval tsagent setup --deploy-key $THREATSTACK_SETUP_DEPLOY_KEY $THREATSTACK_SETUP_ARGS; eval tsagent config --set $THREATSTACK_CONFIG_ARGS; sleep 5; /opt/threatstack/sbin/tsagentd -logstdout"` | |
7171
| gkeContainerOsCmd.command[0] | string | `"bash"` | |
7272
| gkeUbuntu | bool | `false` | If `true`, the Daemonset definition will be modified to execute commands for the agent to work correctly on GKE with Ubuntu nodes. Defaults to `false` |
7373
| gkeUbuntuCmd.args[0] | string | `"-c"` | |
74-
| gkeUbuntuCmd.args[1] | string | `"chroot /threatstackfs /bin/bash -c 'systemctl stop auditd; systemctl disable auditd'; eval tsagent setup $THREATSTACK_SETUP_ARGS; eval tsagent config --set $THREATSTACK_CONFIG_ARGS; sleep 5; /opt/threatstack/sbin/tsagentd -logstdout"` | |
74+
| gkeUbuntuCmd.args[1] | string | `"chroot /threatstackfs /bin/bash -c 'systemctl stop auditd; systemctl disable auditd'; eval tsagent setup --deploy-key $THREATSTACK_SETUP_DEPLOY_KEY $THREATSTACK_SETUP_ARGS; eval tsagent config --set $THREATSTACK_CONFIG_ARGS; sleep 5; /opt/threatstack/sbin/tsagentd -logstdout"` | |
7575
| gkeUbuntuCmd.command[0] | string | `"bash"` | |
7676
| image.pullPolicy | string | `"Always"` | |
7777
| image.repository | string | `"threatstack/ts-docker2"` | The docker repository for the container image to install. It defaults to Threat Stack's offical docker hub repository for the agent. **NOTE:** Changing this could lead to pulling an unofficial, incorrect, or incompatible image, and is strongly discouraged. |
@@ -89,9 +89,9 @@ The instructions below assume the helm chart has been released to a repository.
8989

9090
In this, one should not add the helm repository as directed below (step 1), and omit the `--repo https://pkg.threatstack.com/helm` from any command. Also, instead of the chart name being `threatstack-agent`, you should use `<PATH_TO_CHART>/threatstack-agent-<VERSION>.tgz` in helm commands.
9191

92-
>>>
93-
**WARNING:** Creating a local helm chart does not sign the chart package. Any verfication of the provenance of the chart will fail.
94-
>>>
92+
> **Warning**
93+
>
94+
> Creating a local helm chart does not sign the chart package. Any verfication of the provenance of the chart will fail.
9595
9696
#### Installing publicly released chart
9797

@@ -101,8 +101,8 @@ The threatstack agent helm chart follows the standard installation process for c
101101
```shell
102102
> helm repo add threatstack https://pkg.threatstack.com/helm
103103
```
104-
1. Using the default `values.yaml`, create a local yaml that overrides the configuration as desired or needed for the target cluster (See [Additional Installation Notes][#additional-installation-notes] below)
105-
1. Install the threatstack agent with helm
104+
2. Using the default `values.yaml`, create a local yaml that overrides the configuration as desired or needed for the target cluster (See [Additional Installation Notes][#additional-installation-notes] below)
105+
3. Install the threatstack agent with helm
106106
* `Helm 2:`
107107
```shell
108108
> helm install --name <HELM_RELEASE_NAME> --values ./<values-override-filename>.yaml threatstack/threatstack-agent
@@ -145,30 +145,51 @@ Assuming you override the default values to match our environment in a `values.y
145145
> helm install --name my-threatstack-agents --values values.yaml --values deploykey-override.yaml threatstack/threatstack-agent
146146
```
147147

148-
> **NOTE:** Most of the overridable values for the threatstack agent helm chart are **not** sensitive, and therefore can (and should) be checked into a source control system.
148+
> **Note**
149+
>
150+
> Most of the overridable values for the threatstack agent helm chart are **not** sensitive, and therefore can (and should) be checked into a source control system.
149151
150152
##### Using the `agentSetupExternalSecretRef` value block
151153

152-
>>>
153-
**IMPORTANT:** Using `agentSetupExternalSecretRef` decouples secret management from the helm chart. Therefore, if the value of the secret changes, the agent DaemonSet and Deployment will _not_ be redeployed/restarted. The user will need to force a redeployment of the helm chart explicitly.
154+
> **Warning**
155+
>
156+
> Using `agentSetupExternalSecretRef` decouples secret management from the helm chart. Therefore, if the value of the secret changes, the agent DaemonSet and Deployment will _not_ be redeployed/restarted. The user will need to force a redeployment of the helm chart explicitly.
154157
155-
However, if the secret's name or secret's entry name changes in the `values.yaml` of the chart, helm will recognize this change with a new release, and trigger a redeployment of the DaemonsSet and Deployment. One way to take advantage of this is to update the secrets entry value name (what is defined at `agentSetupExternalSecretRef.value`) when changing the secret data, and doing a redeploy of the chart. The chart trigger a redeployment of the agent pods.
156-
>>>
158+
However, if the secret's name or secret's entry name changes in the `values.yaml` of the chart, helm will recognize this change with a new release, and trigger a redeployment of the DaemonsSet and Deployment. One way to take advantage of this is to update the secrets entry value name (what is defined at `agentDeployKey`) when changing the secret data, and doing a redeploy of the chart. The chart trigger a redeployment of the agent pods.
157159

158-
An alternative to having the chart define the `ts-setup-args` secret itself, you can instead have it point to your own self-managed secret. Doing so requires the following three values to be set:
160+
An alternative to having the chart define secret itself, you can instead have it point to your own self-managed secret. Doing so requires the following three values to be set:
159161

160-
* `agentSetupExternalSecretRef.name` :: This is the name of your self-managed secret.
161-
* `agentSetupExternalSecretRef.key` :: This is the key in your self-managed secret that is associated with the data you want to supply from the secret, to the Threat Stack agent setup registration.
162+
* `agentSetupExternalSecretRef.name` : This is the name of your self-managed secret.
163+
* `agentSetupExternalSecretRef.key` : This is the key in your self-managed secret that is associated with the data you want to supply from the secret, to the Threat Stack agent setup registration.
164+
165+
E.g:
166+
```yaml
167+
# self-managed secret spec
168+
apiVersion: v1
169+
kind: Secret
170+
metadata:
171+
name: tsagent-setup-key
172+
type: Opaque
173+
stringData:
174+
value: "foo"
175+
```
176+
177+
```yaml
178+
# values.yaml
179+
...
180+
181+
agentSetupExternalSecretRef:
182+
name: tsagent-setup-key
183+
key: value
184+
...
185+
```
162186

163187
Do not set the `agentSetupExternalSecretRef` block *and* the `agentDeployKey` settings at the same time. This will cause unnecessary kubernetes resource definitions to be created. If you had previously used the `agentDeployKey` value, the secret associated with it may be destroyed on deployment.
164188

165-
Using the `agentSetupExternalSecretRef` block will cause the chart to ignore the `agentDeployKey`, `rulesets`, and `additionalSetupConfig` values defined in `values.yaml` or any other values override file, until existing pods are terminated/rescheduled.
189+
Using the `agentSetupExternalSecretRef` block will cause the chart to ignore the `agentDeployKey`.
166190

167-
The value defined in the secret by `agentSetupExternalSecretRef.name`/`agentSetupExternalSecretRef.key` should be defined as in the example below to properly setup up the agent. Failure to do so can cause the agent to not properly register itself with the Threat Stack platform.
191+
The value defined in the secret by `agentSetupExternalSecretRef.name`/`agentSetupExternalSecretRef.key` must be set only with the **Agent key**.
168192

169-
```shell
170-
--deploy-key <your-deploy-key> --ruleset '<your-rulesets>' <additional-setup-configuration>"
171-
```
172193

173194
### Contributing enhancements/fixes
174195

@@ -182,4 +203,4 @@ See the [LICENSE](LICENSE)
182203

183204
| Name | Email | Url |
184205
| ---- | ------ | --- |
185-
| Threat Stack Inc. | [email protected] | |
206+
| Threat Stack Inc. | [email protected] | |

templates/configmap.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ metadata:
3232
data:
3333
config-args: {{ include "threatstack-agent.daemonset-runtimeConfig" . }}
3434
kubernetes-api-config-args: enable_kubes_master 1 {{ .Values.apiReader.additionalRuntimeConfig }}
35+
setup-args: "--ruleset {{ .Values.rulesets | squote }} {{ .Values.additionalSetupConfig }}"
3536
{{- if .Values.daemonset.customAuditRules }}
3637
custom-audit-rules-content: {{ toYaml .Values.daemonset.customAuditRules | indent 4 }}
3738
{{- end }}

templates/daemonset.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,21 @@ spec:
113113
failureThreshold: 5
114114
{{- end }}
115115
env:
116-
- name: THREATSTACK_SETUP_ARGS
116+
- name: THREATSTACK_SETUP_DEPLOY_KEY
117117
valueFrom:
118-
{{- if not .Values.agentSetupExternalSecretRef }}
119118
secretKeyRef:
119+
{{- if not .Values.agentSetupExternalSecretRef }}
120120
name: {{ include "threatstack-agent.fullname" . }}
121-
key: ts-setup-args
121+
key: ts-setup-deploy-key
122122
{{- else }}
123-
secretKeyRef:
124123
name: {{ .Values.agentSetupExternalSecretRef.name }}
125124
key: {{ .Values.agentSetupExternalSecretRef.key }}
126125
{{- end }}
126+
- name: THREATSTACK_SETUP_ARGS
127+
valueFrom:
128+
configMapKeyRef:
129+
name: {{ include "threatstack-agent.name" . }}-config-args
130+
key: setup-args
127131
- name: THREATSTACK_CONFIG_ARGS
128132
valueFrom:
129133
configMapKeyRef:

templates/deployment-api-reader.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,21 @@ spec:
102102
failureThreshold: 5
103103
{{- end }}
104104
env:
105-
- name: THREATSTACK_SETUP_ARGS
105+
- name: THREATSTACK_SETUP_DEPLOY_KEY
106106
valueFrom:
107-
{{- if not .Values.agentSetupExternalSecretRef }}
108107
secretKeyRef:
108+
{{- if not .Values.agentSetupExternalSecretRef }}
109109
name: {{ include "threatstack-agent.fullname" . }}
110-
key: ts-setup-args
110+
key: ts-setup-deploy-key
111111
{{- else }}
112-
secretKeyRef:
113112
name: {{ .Values.agentSetupExternalSecretRef.name }}
114113
key: {{ .Values.agentSetupExternalSecretRef.key }}
115114
{{- end }}
115+
- name: THREATSTACK_SETUP_ARGS
116+
valueFrom:
117+
configMapKeyRef:
118+
name: {{ include "threatstack-agent.name" . }}-config-args
119+
key: setup-args
116120
- name: THREATSTACK_CONFIG_ARGS
117121
valueFrom:
118122
configMapKeyRef:

templates/secrets.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ metadata:
3232
app.kubernetes.io/managed-by: {{ .Release.Service }}
3333
type: Opaque
3434
stringData:
35-
ts-setup-args: "--deploy-key {{ .Values.agentDeployKey }} --ruleset '{{ .Values.rulesets }}' {{ .Values.additionalSetupConfig }}"
35+
ts-setup-deploy-key: {{ .Values.agentDeployKey | quote }}
3636
{{- end }}

values.yaml

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,40 @@ imagePullSecrets: []
3333
gkeContainerOs: false
3434
gkeContainerOsCmd:
3535
command: ["bash"]
36-
args: ["-c", "chroot /threatstackfs /bin/bash -c 'systemctl stop systemd-journald-audit.socket; systemctl mask systemd-journald-audit.socket; systemctl restart systemd-journald; auditctl --backlog_wait_time 0'; eval tsagent setup $THREATSTACK_SETUP_ARGS; eval tsagent config --set $THREATSTACK_CONFIG_ARGS; sleep 5; /opt/threatstack/sbin/tsagentd -logstdout"]
36+
args:
37+
- -c
38+
- >-
39+
chroot /threatstackfs /bin/bash -c 'systemctl stop systemd-journald-audit.socket;
40+
systemctl mask systemd-journald-audit.socket;
41+
systemctl restart systemd-journald; auditctl --backlog_wait_time 0';
42+
eval tsagent setup --deploy-key $THREATSTACK_SETUP_DEPLOY_KEY $THREATSTACK_SETUP_ARGS;
43+
eval tsagent config --set $THREATSTACK_CONFIG_ARGS; sleep 5; /opt/threatstack/sbin/tsagentd -logstdout
3744
3845
# Using Ubuntu nodes
3946
gkeUbuntu: false
4047
gkeUbuntuCmd:
4148
command: ["bash"]
42-
args: ["-c", "chroot /threatstackfs /bin/bash -c 'systemctl stop auditd; systemctl disable auditd'; eval tsagent setup $THREATSTACK_SETUP_ARGS; eval tsagent config --set $THREATSTACK_CONFIG_ARGS; sleep 5; /opt/threatstack/sbin/tsagentd -logstdout"]
49+
args:
50+
- -c
51+
- >-
52+
chroot /threatstackfs /bin/bash -c 'systemctl stop auditd; systemctl disable auditd';
53+
eval tsagent setup --deploy-key $THREATSTACK_SETUP_DEPLOY_KEY $THREATSTACK_SETUP_ARGS;
54+
eval tsagent config --set $THREATSTACK_CONFIG_ARGS;
55+
sleep 5;
56+
/opt/threatstack/sbin/tsagentd -logstdout
4357
4458
# Using EKS Amazon Linux 2 nodes
4559
eksAmazon2: false
4660
eksAmazon2Cmd:
4761
command: ["bash"]
48-
args: ["-c", "chroot /threatstackfs /bin/bash -c 'service auditd stop; systemctl disable auditd'; eval tsagent setup $THREATSTACK_SETUP_ARGS; eval tsagent config --set $THREATSTACK_CONFIG_ARGS; sleep 5; /opt/threatstack/sbin/tsagentd -logstdout"]
62+
args:
63+
- -c
64+
- >-
65+
chroot /threatstackfs /bin/bash -c 'service auditd stop; systemctl disable auditd';
66+
eval tsagent setup --deploy-key $THREATSTACK_SETUP_DEPLOY_KEY $THREATSTACK_SETUP_ARGS;
67+
eval tsagent config --set $THREATSTACK_CONFIG_ARGS;
68+
sleep 5;
69+
/opt/threatstack/sbin/tsagentd -logstdout
4970
5071
# Uncomment the command and args sub-attributes, and define them as desired to run custom commands in the Daemonset.
5172
#
@@ -54,7 +75,15 @@ eksAmazon2Cmd:
5475
# This example turns off and disables auditd running on the host so the container agent can properly monitor activity
5576
customDaemonsetCmd: {}
5677
# command: ["bash"]
57-
# args: ["-c", "chroot /threatstackfs /bin/bash -c 'service auditd stop >/dev/null || systemctl stop auditd; systemctl disable auditd'; eval tsagent setup $THREATSTACK_SETUP_ARGS; eval tsagent config --set $THREATSTACK_CONFIG_ARGS; sleep 5; /opt/threatstack/sbin/tsagentd -logstdout"]
78+
# args:
79+
# - -c
80+
# - >-
81+
# chroot /threatstackfs /bin/bash -c 'service auditd stop >/dev/null || systemctl stop auditd;
82+
# systemctl disable auditd';
83+
# eval tsagent setup --deploy-key $THREATSTACK_SETUP_DEPLOY_KEY $THREATSTACK_SETUP_ARGS;
84+
# eval tsagent config --set $THREATSTACK_CONFIG_ARGS;
85+
# sleep 5;
86+
# /opt/threatstack/sbin/tsagentd -logstdout
5887

5988
# Use ebpf monitoring where applicable
6089
# Enabling this setting has been observed to cause an increase in resource usage by the agent with some workloads,

0 commit comments

Comments
 (0)