Skip to content

Commit bf4ebe9

Browse files
fix: protect mongo and redis by password [run-int-tests][run-ui-tests]
Signed-off-by: Ilya Kheifets <[email protected]>
1 parent c3dd6c3 commit bf4ebe9

File tree

5 files changed

+147
-6
lines changed

5 files changed

+147
-6
lines changed

charts/splunk-connect-for-snmp/templates/_helpers.tpl

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
{{- define "splunk-connect-for-snmp.mongo_uri" -}}
2+
3+
{{- if and .Values.mongodb.auth.enabled .Values.mongodb.auth.existingSecret }}
4+
{{- $mongoSecretName := .Values.mongodb.auth.existingSecret }}
5+
{{- $mongoSecret := lookup "v1" "Secret" .Release.Namespace $mongoSecretName }}
6+
7+
{{- if not $mongoSecret }}
8+
{{- fail (printf "Secret '%s' not found in namespace '%s'. Please create it before deploying." $mongoSecretName .Release.Namespace) }}
9+
{{- end }}
10+
11+
{{- $mongoPassword := get $mongoSecret.data "mongodb-root-password" | b64dec }}
12+
13+
{{- if eq .Values.mongodb.architecture "replicaset" }}
14+
{{- printf "mongodb+srv://root:%s@%s-mongodb-headless.%s.svc.%s/?tls=false&ssl=false&replicaSet=rs0" $mongoPassword .Release.Name .Release.Namespace .Values.mongodb.clusterDomain}}
15+
{{- else }}
16+
{{- printf "mongodb://root:%s@%s-mongodb:27017" $mongoPassword .Release.Name }}
17+
{{- end }}
18+
{{- else }}
19+
220
{{- if eq .Values.mongodb.architecture "replicaset" }}
321
{{- printf "mongodb+srv://%s-mongodb-headless.%s.svc.%s/?tls=false&ssl=false&replicaSet=rs0" .Release.Name .Release.Namespace .Values.mongodb.clusterDomain}}
422
{{- else }}
523
{{- printf "mongodb://%s-mongodb:27017" .Release.Name }}
6-
{{- end }}
7-
{{- end }}
24+
{{- end }}
25+
26+
{{- end }}
27+
{{- end }}
828

929
{{- define "splunk-connect-for-snmp.mongodbHost" -}}
1030
{{- if .Values.mongodbHost }}
@@ -15,18 +35,59 @@
1535
{{- end }}
1636

1737
{{- define "splunk-connect-for-snmp.celery_url" -}}
38+
39+
{{- if and .Values.redis.auth.enabled .Values.redis.auth.existingSecret }}
40+
{{- $redisSecretName := .Values.redis.auth.existingSecret }}
41+
{{- $redisSecret := lookup "v1" "Secret" .Release.Namespace $redisSecretName }}
42+
43+
{{- if not $redisSecret }}
44+
{{- fail (printf "Secret '%s' not found in namespace '%s'. Please create it before deploying." $redisSecretName .Release.Namespace) }}
45+
{{- end }}
46+
47+
{{- $redisPassword := get $redisSecret.data "redis-password" | b64dec }}
48+
49+
{{- if and ( eq .Values.redis.architecture "replication" ) .Values.redis.sentinel.enabled }}
50+
{{- printf "redis://:%s@%s-redis:6379/0" $redisPassword .Release.Name }}
51+
{{- else }}
52+
{{- printf "redis://:%s@%s-redis-master:6379/0" $redisPassword .Release.Name }}
53+
{{- end }}
54+
{{- else }}
55+
56+
1857
{{- if and ( eq .Values.redis.architecture "replication" ) .Values.redis.sentinel.enabled }}
1958
{{- printf "redis://%s-redis:6379/0" .Release.Name }}
2059
{{- else }}
2160
{{- printf "redis://%s-redis-master:6379/0" .Release.Name }}
61+
{{- end }}
62+
2263
{{- end }}
2364
{{- end }}
2465

2566
{{- define "splunk-connect-for-snmp.redis_url" -}}
67+
68+
{{- if and .Values.redis.auth.enabled .Values.redis.auth.existingSecret }}
69+
{{- $redisSecretName := .Values.redis.auth.existingSecret }}
70+
{{- $redisSecret := lookup "v1" "Secret" .Release.Namespace $redisSecretName }}
71+
72+
{{- if not $redisSecret }}
73+
{{- fail (printf "Secret '%s' not found in namespace '%s'. Please create it before deploying." $redisSecretName .Release.Namespace) }}
74+
{{- end }}
75+
76+
{{- $redisPassword := get $redisSecret.data "redis-password" | b64dec }}
77+
78+
{{- if and ( eq .Values.redis.architecture "replication" ) .Values.redis.sentinel.enabled }}
79+
{{- printf "redis://:%s@%s-redis:6379/1" $redisPassword .Release.Name }}
80+
{{- else }}
81+
{{- printf "redis://:%s@%s-redis-master:6379/1" $redisPassword .Release.Name }}
82+
{{- end }}
83+
{{- else }}
84+
2685
{{- if and ( eq .Values.redis.architecture "replication" ) .Values.redis.sentinel.enabled }}
2786
{{- printf "redis://%s-redis:6379/1" .Release.Name }}
2887
{{- else }}
2988
{{- printf "redis://%s-redis-master:6379/1" .Release.Name }}
89+
{{- end }}
90+
3091
{{- end }}
3192
{{- end }}
3293

charts/splunk-connect-for-snmp/templates/mongodb-6.0-upgrade-job.yaml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,27 @@ spec:
1616
containers:
1717
- name: mongo-fcv-check
1818
image: {{ .Values.mongodb.image.repository }}:{{ .Values.mongodb.image.tag }}
19+
20+
{{- $secret := lookup "v1" "Secret" .Release.Namespace .Values.mongodb.auth.existingSecret }}
21+
{{- if $secret }}
22+
env:
23+
- name: MONGO_PASSWORD
24+
valueFrom:
25+
secretKeyRef:
26+
name: {{ .Values.mongodb.auth.existingSecret }}
27+
key: mongodb-root-password
28+
{{- end }}
1929
command:
2030
- /bin/bash
2131
- -c
2232
- |
2333
echo "Checking current mongo FCV"
24-
FCV=$(mongosh --host {{ include "splunk-connect-for-snmp.mongodbHost" . | quote }} --quiet --eval 'db.adminCommand({ getParameter: 1, featureCompatibilityVersion: 1 }).featureCompatibilityVersion.version')
34+
FCV=$(mongosh --host {{ include "splunk-connect-for-snmp.mongodbHost" . | quote }} {{- if $secret }} --username root --password $MONGO_PASSWORD {{- end }} --quiet --eval 'db.adminCommand({ getParameter: 1, featureCompatibilityVersion: 1 }).featureCompatibilityVersion.version')
2535
echo "Current Mongo Feature Compatibility Version: $FCV"
2636
2737
if [[ "$FCV" < "6.0" ]]; then
2838
echo "FCV < 6.0, setting to 6.0"
29-
mongosh --host {{ include "splunk-connect-for-snmp.mongodbHost" . | quote }} --eval 'db.adminCommand({ setFeatureCompatibilityVersion: "6.0" })'
39+
mongosh --host {{ include "splunk-connect-for-snmp.mongodbHost" . | quote }} {{- if $secret }} --username root --password $MONGO_PASSWORD {{- end }} --eval 'db.adminCommand({ setFeatureCompatibilityVersion: "6.0" })'
3040
else
3141
echo "FCV >= 6.0, nothing to be changed"
3242
fi

docs/dockercompose/2-download-package.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,39 @@ To configure the deployment, follow the instructions in [Inventory configuration
88
[Scheduler configuration](./4-scheduler-configuration.md), [Traps configuration](./5-traps-configuration.md),
99
[.env file configuration](./6-env-file-configuration.md), [SNMPv3 secrets](./7-snmpv3-secrets.md).
1010

11+
12+
## Protect Mongo and Redis by password
13+
14+
In your `docker-compose.yaml` [specify](https://hub.docker.com/r/bitnami/redis) for Redis container `REDIS_PASSWORD` or `REDIS_PASSWORD_FILE`:
15+
16+
```
17+
redis:
18+
...
19+
environment:
20+
- REDIS_PASSWORD=...
21+
```
22+
23+
The same thing you to [specify](https://hub.docker.com/r/bitnami/mongodb) for Mongo container using `MONGODB_ROOT_PASSWORD`:
24+
25+
```
26+
mongo:
27+
...
28+
environment:
29+
- MONGODB_ROOT_PASSWORD=...
30+
```
31+
32+
After that just update connection string:
33+
34+
```
35+
REDIS_URL: redis://:pass@redis:6379/1
36+
CELERY_BROKER_URL: redis://:pass@redis:6379/0
37+
MONGO_URI: mongodb://root:pass@mongo:27017/
38+
```
39+
40+
!!! Warning
41+
If you wanna update the password you need to make it manually using `mongo` and `redis` cli.
42+
And only after that you need to update `REDIS_PASSWORD`/ `MONGODB_ROOT_PASSWORD` and connection strings.
43+
1144
## Deploying the app
1245
After configuration, application can be deployed by running the
1346
following command inside the `docker_compose` directory:

docs/microk8s/sc4snmp-installation.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,43 @@ rules:
6767
Configuration above can be found in the `examples` directory in SC4SNMP [GitHub repository](https://github.com/splunk/splunk-connect-for-snmp).
6868
Next run `yamllint -c <path to custom-config.yamllint> <path to values.yaml>` command. Warnings can be ignored.
6969

70+
71+
### Protect Mongo and Redis by password
72+
73+
Create secrets for Mongo and Redis:
74+
75+
```
76+
kubectl create secret generic redis-auth-secret \
77+
--from-literal=redis-password=your_password -n sc4snmp
78+
79+
microk8s kubectl create secret generic mongodb-auth-secret \
80+
--from-literal=mongodb-root-password=your_password -n sc4snmp
81+
```
82+
83+
Reference on this secrets in `values.yaml`:
84+
85+
```
86+
redis:
87+
auth:
88+
enabled: true
89+
existingSecret: "redis-auth-secret"
90+
91+
mongodb:
92+
auth:
93+
enabled: true
94+
existingSecret: "mongodb-auth-secret"
95+
```
96+
97+
And **only after that** you can deploy your SC4SNMP.
98+
99+
!!! warning
100+
If you wanna update the password, in case of mongo you need to use [passwordUpdateJob](https://artifacthub.io/packages/helm/bitnami/mongodb#automated-update-using-a-password-update-job) (for that just place it in `mongodb` section) and after that redeploy SC4SNMP.
101+
102+
But in case of redis helm charm [it's not supporting that automatically](https://artifacthub.io/packages/helm/bitnami/mongodb#automated-update-using-a-password-update-job), you need upadte the password using `redis-cli` and after that update existing secret and redeploy SC4SNMP.
103+
104+
For that reason will be good to provide credentials during first deploy.
105+
106+
70107
#### Install SC4SNMP
71108

72109
After the `values.yaml` creation, you can proceed with the SC4SNMP installation:

integration_tests/test_poller_integration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,6 +1801,6 @@ def run_retried_single_search(setup_splunk, search_string, retries):
18011801
result_count, metric_count = splunk_single_search(setup_splunk, search_string)
18021802
if result_count or metric_count:
18031803
return result_count, metric_count
1804-
logger.info("No results returned from search. Retrying in 2 seconds...")
1805-
time.sleep(2)
1804+
logger.info("No results returned from search. Retrying in 30 seconds...")
1805+
time.sleep(30)
18061806
return 0, 0

0 commit comments

Comments
 (0)