Skip to content

Commit 2b99a7f

Browse files
authored
Update Istio configuration to use CNI node agents instead of istio-init containers (#474)
# Summary We are using `Istio` as a service mesh provider for our Multi Cluster tests. The way it works by default is `Istio` adds privileged `init-istio` container to every Pod that configures network accordingly. >By default Istio injects an init container, istio-init, in pods deployed in the mesh. The istio-init container sets up the pod network traffic redirection to/from the Istio sidecar proxy. This requires the user or service-account deploying pods to the mesh to have sufficient Kubernetes RBAC permissions to deploy [containers with the NET_ADMIN and NET_RAW capabilities](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-capabilities-for-a-container). While this works fine it is not meeting the [PSS](https://v1-32.docs.kubernetes.io/docs/concepts/security/pod-security-standards/) restricted level, thus making it less secure. Related [HELP-81729](https://jira.mongodb.org/browse/HELP-81729) and #473 that enables `restricted` level in `warn` mode. Additionally we provide Istio sidecar configuration as an example in our code snippets thus not following the best practice. There is another way to configure Istio mesh that does not require `istio-init` init-container - using [Istio CNI node agent](https://istio.io/latest/docs/setup/additional-setup/cni/#using-the-istio-cni-node-agent). This PR configures our e2e tests and code snippets that way. Great blog entry about difference between `istio-init` and Istio CNI node agent architecture -> https://www.solo.io/blog/traffic-ambient-mesh-istio-cni-node-configuration. With `istio-init`: <img width="810" height="820" alt="image" src="https://github.com/user-attachments/assets/026350af-3b51-4fe9-9cb8-c8911e661eca" /> With `Istio CNI node agent`: <img width="942" height="1084" alt="image" src="https://github.com/user-attachments/assets/37733169-7737-4063-90a0-de3d116402a9" /> ⚠️ Init containers execute before the sidecar proxy starts, which can result in traffic loss during their execution. This can be avoided by setting `runAsUser: 1337`. More info -> https://istio.io/latest/docs/setup/additional-setup/cni/#compatibility-with-application-init-containers ## Proof of Work Passing CI is enough. Since `private_gke_code_snippets` are not run automatically in CI I've triggered manual patch to test this -> https://spruce.mongodb.com/version/68d50e694baed3000742566d/tasks?sorts=STATUS%3AASC%3BBASE_STATUS%3ADESC ## Checklist - [ ] Have you linked a jira ticket and/or is the ticket in the title? - [x] Have you checked whether your jira ticket required DOCSP changes? - [x] Have you added changelog file? - use `skip-changelog` label if not needed - refer to [Changelog files and Release Notes](https://github.com/mongodb/mongodb-kubernetes/blob/master/CONTRIBUTING.md#changelog-files-and-release-notes) section in CONTRIBUTING.md for more details
1 parent fd4450b commit 2b99a7f

File tree

9 files changed

+81
-199
lines changed

9 files changed

+81
-199
lines changed

docker/mongodb-kubernetes-tests/tests/opsmanager/fixtures/om_https_enabled.yaml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ spec:
2222
spec:
2323
volumes:
2424
- name: mongodb-versions
25-
emptyDir: {}
25+
emptyDir: { }
2626
containers:
2727
- name: mongodb-ops-manager
2828
volumeMounts:
@@ -37,6 +37,8 @@ spec:
3737
initContainers:
3838
- name: setting-up-rhel-mongodb
3939
image: curlimages/curl:latest
40+
securityContext:
41+
runAsUser: 1337 # workaround for init-container istio issue -> https://istio.io/latest/docs/setup/additional-setup/cni/#compatibility-with-application-init-containers
4042
command:
4143
- curl
4244
- -L
@@ -48,6 +50,8 @@ spec:
4850
mountPath: /mongodb-ops-manager/mongodb-releases
4951
- name: setting-up-rhel-mongodb-4-4
5052
image: curlimages/curl:latest
53+
securityContext:
54+
runAsUser: 1337 # workaround for init-container istio issue -> https://istio.io/latest/docs/setup/additional-setup/cni/#compatibility-with-application-init-containers
5155
command:
5256
- curl
5357
- -L
@@ -59,6 +63,8 @@ spec:
5963
mountPath: /mongodb-ops-manager/mongodb-releases
6064
- name: setting-up-rhel-mongodb-5-0
6165
image: curlimages/curl:latest
66+
securityContext:
67+
runAsUser: 1337 # workaround for init-container istio issue -> https://istio.io/latest/docs/setup/additional-setup/cni/#compatibility-with-application-init-containers
6268
command:
6369
- curl
6470
- -L
@@ -70,6 +76,8 @@ spec:
7076
mountPath: /mongodb-ops-manager/mongodb-releases
7177
- name: setting-up-rhel-mongodb-6-0
7278
image: curlimages/curl:latest
79+
securityContext:
80+
runAsUser: 1337 # workaround for init-container istio issue -> https://istio.io/latest/docs/setup/additional-setup/cni/#compatibility-with-application-init-containers
7381
command:
7482
- curl
7583
- -L
@@ -81,6 +89,8 @@ spec:
8189
mountPath: /mongodb-ops-manager/mongodb-releases
8290
- name: setting-up-rhel-mongodb-6-0-sig
8391
image: curlimages/curl:latest
92+
securityContext:
93+
runAsUser: 1337 # workaround for init-container istio issue -> https://istio.io/latest/docs/setup/additional-setup/cni/#compatibility-with-application-init-containers
8494
command:
8595
- curl
8696
- -L
@@ -92,6 +102,8 @@ spec:
92102
mountPath: /mongodb-ops-manager/mongodb-releases
93103
- name: setting-up-rhel-mongodb-6-0-21
94104
image: curlimages/curl:latest
105+
securityContext:
106+
runAsUser: 1337 # workaround for init-container istio issue -> https://istio.io/latest/docs/setup/additional-setup/cni/#compatibility-with-application-init-containers
95107
command:
96108
- curl
97109
- -L
@@ -103,6 +115,8 @@ spec:
103115
mountPath: /mongodb-ops-manager/mongodb-releases
104116
- name: setting-up-rhel-mongodb-6-0-21-sig
105117
image: curlimages/curl:latest
118+
securityContext:
119+
runAsUser: 1337 # workaround for init-container istio issue -> https://istio.io/latest/docs/setup/additional-setup/cni/#compatibility-with-application-init-containers
106120
command:
107121
- curl
108122
- -L
@@ -112,9 +126,10 @@ spec:
112126
volumeMounts:
113127
- name: mongodb-versions
114128
mountPath: /mongodb-ops-manager/mongodb-releases
115-
116129
- name: setting-up-rhel-mongodb-7-0
117130
image: curlimages/curl:latest
131+
securityContext:
132+
runAsUser: 1337 # workaround for init-container istio issue -> https://istio.io/latest/docs/setup/additional-setup/cni/#compatibility-with-application-init-containers
118133
command:
119134
- curl
120135
- -L
@@ -126,6 +141,8 @@ spec:
126141
mountPath: /mongodb-ops-manager/mongodb-releases
127142
- name: setting-up-rhel-mongodb-7-0-sig
128143
image: curlimages/curl:latest
144+
securityContext:
145+
runAsUser: 1337 # workaround for init-container istio issue -> https://istio.io/latest/docs/setup/additional-setup/cni/#compatibility-with-application-init-containers
129146
command:
130147
- curl
131148
- -L
@@ -137,6 +154,8 @@ spec:
137154
mountPath: /mongodb-ops-manager/mongodb-releases
138155
- name: setting-up-rhel-mongodb-8-0
139156
image: curlimages/curl:latest
157+
securityContext:
158+
runAsUser: 1337 # workaround for init-container istio issue -> https://istio.io/latest/docs/setup/additional-setup/cni/#compatibility-with-application-init-containers
140159
command:
141160
- curl
142161
- -L
@@ -148,6 +167,8 @@ spec:
148167
mountPath: /mongodb-ops-manager/mongodb-releases
149168
- name: setting-up-rhel-mongodb-8-0-sig
150169
image: curlimages/curl:latest
170+
securityContext:
171+
runAsUser: 1337 # workaround for init-container istio issue -> https://istio.io/latest/docs/setup/additional-setup/cni/#compatibility-with-application-init-containers
151172
command:
152173
- curl
153174
- -L

docker/mongodb-kubernetes-tests/tests/opsmanager/fixtures/om_localmode-single-pv.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ spec:
3535
initContainers:
3636
- name: setting-up-rhel-mongodb-4-2-8
3737
image: curlimages/curl:latest
38+
securityContext:
39+
runAsUser: 1337 # workaround for init-container istio issue -> https://istio.io/latest/docs/setup/additional-setup/cni/#compatibility-with-application-init-containers
3840
command:
3941
- curl
4042
- -L
@@ -46,6 +48,8 @@ spec:
4648
mountPath: /mongodb-ops-manager/mongodb-releases
4749
- name: setting-up-rhel-mongodb-6-0-21
4850
image: curlimages/curl:latest
51+
securityContext:
52+
runAsUser: 1337 # workaround for init-container istio issue -> https://istio.io/latest/docs/setup/additional-setup/cni/#compatibility-with-application-init-containers
4953
command:
5054
- curl
5155
- -L
@@ -57,6 +61,8 @@ spec:
5761
mountPath: /mongodb-ops-manager/mongodb-releases
5862
- name: setting-up-rhel-mongodb-7-0
5963
image: curlimages/curl:latest
64+
securityContext:
65+
runAsUser: 1337 # workaround for init-container istio issue -> https://istio.io/latest/docs/setup/additional-setup/cni/#compatibility-with-application-init-containers
6066
command:
6167
- curl
6268
- -L
@@ -68,6 +74,8 @@ spec:
6874
mountPath: /mongodb-ops-manager/mongodb-releases
6975
- name: setting-up-rhel-mongodb-8-0
7076
image: curlimages/curl:latest
77+
securityContext:
78+
runAsUser: 1337 # workaround for init-container istio issue -> https://istio.io/latest/docs/setup/additional-setup/cni/#compatibility-with-application-init-containers
7179
command:
7280
- curl
7381
- -L

docker/mongodb-kubernetes-tests/tests/opsmanager/fixtures/remote_fixtures/nginx.yaml

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ spec:
2929
initContainers:
3030
- name: setting-up-mongosh-1-4-1
3131
image: curlimages/curl:latest
32+
securityContext:
33+
runAsUser: 1337 # workaround for init-container istio issue -> https://istio.io/latest/docs/setup/additional-setup/cni/#compatibility-with-application-init-containers
3234
command:
3335
- sh
3436
- -c
@@ -38,6 +40,8 @@ spec:
3840
mountPath: /mongodb-ops-manager/mongodb-releases/compass
3941
- name: setting-up-mongosh-1-9-1
4042
image: curlimages/curl:latest
43+
securityContext:
44+
runAsUser: 1337 # workaround for init-container istio issue -> https://istio.io/latest/docs/setup/additional-setup/cni/#compatibility-with-application-init-containers
4145
command:
4246
- sh
4347
- -c
@@ -47,6 +51,8 @@ spec:
4751
mountPath: /mongodb-ops-manager/mongodb-releases/compass
4852
- name: setting-up-mongosh-1-10-4
4953
image: curlimages/curl:latest
54+
securityContext:
55+
runAsUser: 1337 # workaround for init-container istio issue -> https://istio.io/latest/docs/setup/additional-setup/cni/#compatibility-with-application-init-containers
5056
command:
5157
- sh
5258
- -c
@@ -56,6 +62,8 @@ spec:
5662
mountPath: /mongodb-ops-manager/mongodb-releases/compass
5763
- name: setting-up-mongosh-2-0-0
5864
image: curlimages/curl:latest
65+
securityContext:
66+
runAsUser: 1337 # workaround for init-container istio issue -> https://istio.io/latest/docs/setup/additional-setup/cni/#compatibility-with-application-init-containers
5967
command:
6068
- sh
6169
- -c
@@ -65,6 +73,8 @@ spec:
6573
mountPath: /mongodb-ops-manager/mongodb-releases/compass
6674
- name: setting-up-mongosh-2-0-2
6775
image: curlimages/curl:latest
76+
securityContext:
77+
runAsUser: 1337 # workaround for init-container istio issue -> https://istio.io/latest/docs/setup/additional-setup/cni/#compatibility-with-application-init-containers
6878
command:
6979
- sh
7080
- -c
@@ -74,6 +84,8 @@ spec:
7484
mountPath: /mongodb-ops-manager/mongodb-releases/compass
7585
- name: setting-up-mongosh-2-0-2-om7
7686
image: curlimages/curl:latest
87+
securityContext:
88+
runAsUser: 1337 # workaround for init-container istio issue -> https://istio.io/latest/docs/setup/additional-setup/cni/#compatibility-with-application-init-containers
7789
command:
7890
- sh
7991
- -c
@@ -83,6 +95,8 @@ spec:
8395
mountPath: /mongodb-ops-manager/mongodb-releases/compass
8496
- name: setting-up-mongosh-2-1-5-om7
8597
image: curlimages/curl:latest
98+
securityContext:
99+
runAsUser: 1337 # workaround for init-container istio issue -> https://istio.io/latest/docs/setup/additional-setup/cni/#compatibility-with-application-init-containers
86100
command:
87101
- sh
88102
- -c
@@ -92,6 +106,8 @@ spec:
92106
mountPath: /mongodb-ops-manager/mongodb-releases/compass
93107
- name: setting-up-mongosh-2-2-3-om7
94108
image: curlimages/curl:latest
109+
securityContext:
110+
runAsUser: 1337 # workaround for init-container istio issue -> https://istio.io/latest/docs/setup/additional-setup/cni/#compatibility-with-application-init-containers
95111
command:
96112
- sh
97113
- -c
@@ -101,6 +117,8 @@ spec:
101117
mountPath: /mongodb-ops-manager/mongodb-releases/compass
102118
- name: setting-up-mongosh-2-2-4-om7
103119
image: curlimages/curl:latest
120+
securityContext:
121+
runAsUser: 1337 # workaround for init-container istio issue -> https://istio.io/latest/docs/setup/additional-setup/cni/#compatibility-with-application-init-containers
104122
command:
105123
- sh
106124
- -c
@@ -110,6 +128,8 @@ spec:
110128
mountPath: /mongodb-ops-manager/mongodb-releases/compass
111129
- name: setting-up-mongosh-2-4-0
112130
image: curlimages/curl:latest
131+
securityContext:
132+
runAsUser: 1337 # workaround for init-container istio issue -> https://istio.io/latest/docs/setup/additional-setup/cni/#compatibility-with-application-init-containers
113133
command:
114134
- sh
115135
- -c
@@ -119,22 +139,23 @@ spec:
119139
mountPath: /mongodb-ops-manager/mongodb-releases/compass
120140
- name: setting-up-mongosh-2-5-6
121141
image: curlimages/curl:latest
142+
securityContext:
143+
runAsUser: 1337 # workaround for init-container istio issue -> https://istio.io/latest/docs/setup/additional-setup/cni/#compatibility-with-application-init-containers
122144
command:
123145
- sh
124146
- -c
125147
- curl -LO https://downloads.mongodb.com/compass/mongosh-2.5.6-linux-x64-openssl11.tgz --output-dir /mongodb-ops-manager/mongodb-releases/compass && true
126148
volumeMounts:
127149
- name: mongosh-versions
128150
mountPath: /mongodb-ops-manager/mongodb-releases/compass
129-
130151
restartPolicy: Always
131-
securityContext: {}
152+
securityContext: { }
132153
terminationGracePeriodSeconds: 30
133154
volumes:
134155
- name: mongodb-versions
135-
emptyDir: {}
156+
emptyDir: { }
136157
- name: mongosh-versions
137-
emptyDir: {}
158+
emptyDir: { }
138159
- configMap:
139160
name: nginx-conf
140161
name: nginx-conf

docker/mongodb-kubernetes-tests/tests/opsmanager/om_remotemode.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
VERSION_NOT_IN_WEB_SERVER = "4.2.1"
1616

17+
1718
# If this test is failing after an OM Bump, ensure that the nginx deployment fixture contains the associated mongosh
1819
# version. More details in this ticket: https://jira.mongodb.org/browse/CLOUDP-332640
1920

@@ -47,6 +48,10 @@ def add_mdb_version_to_deployment(deployment: Dict[str, Any], version: str):
4748
"name": KubernetesTester.random_k8s_name(prefix="mdb-download"),
4849
"image": "curlimages/curl:latest",
4950
"command": ["sh", "-c", f"{curl_command} && true"],
51+
"securityContext": {
52+
# workaround for init-container istio issue -> https://istio.io/latest/docs/setup/additional-setup/cni/#compatibility-with-application-init-containers
53+
"runAsUser": 1337,
54+
},
5055
"volumeMounts": [
5156
{
5257
"name": "mongodb-versions",

multi_cluster/tools/install_istio.sh

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ make -f ../tools/certs/Makefile.selfsigned.mk "${CTX_CLUSTER3}-cacerts" || make
3838
# create cluster secret objects with the certs and keys
3939
kubectl --context="${CTX_CLUSTER1}" delete ns istio-system || true
4040
kubectl --context="${CTX_CLUSTER1}" create ns istio-system
41+
kubectl --context="${CTX_CLUSTER1}" label --overwrite ns istio-system pod-security.kubernetes.io/enforce=privileged
4142
kubectl --context="${CTX_CLUSTER1}" create secret generic cacerts -n istio-system \
4243
--from-file=${CTX_CLUSTER1}/ca-cert.pem \
4344
--from-file=${CTX_CLUSTER1}/ca-key.pem \
@@ -46,6 +47,7 @@ kubectl --context="${CTX_CLUSTER1}" create secret generic cacerts -n istio-syste
4647

4748
kubectl --context="${CTX_CLUSTER2}" delete ns istio-system || true
4849
kubectl --context="${CTX_CLUSTER2}" create ns istio-system
50+
kubectl --context="${CTX_CLUSTER2}" label --overwrite ns istio-system pod-security.kubernetes.io/enforce=privileged
4951
kubectl --context="${CTX_CLUSTER2}" create secret generic cacerts -n istio-system \
5052
--from-file=${CTX_CLUSTER2}/ca-cert.pem \
5153
--from-file=${CTX_CLUSTER2}/ca-key.pem \
@@ -54,6 +56,7 @@ kubectl --context="${CTX_CLUSTER2}" create secret generic cacerts -n istio-syste
5456

5557
kubectl --context="${CTX_CLUSTER3}" delete ns istio-system || true
5658
kubectl --context="${CTX_CLUSTER3}" create ns istio-system
59+
kubectl --context="${CTX_CLUSTER3}" label --overwrite ns istio-system pod-security.kubernetes.io/enforce=privileged
5760
kubectl --context="${CTX_CLUSTER3}" create secret generic cacerts -n istio-system \
5861
--from-file=${CTX_CLUSTER3}/ca-cert.pem \
5962
--from-file=${CTX_CLUSTER3}/ca-key.pem \
@@ -67,6 +70,10 @@ apiVersion: install.istio.io/v1alpha1
6770
kind: IstioOperator
6871
spec:
6972
tag: ${VERSION}
73+
components:
74+
cni:
75+
namespace: istio-system
76+
enabled: true
7077
meshConfig:
7178
defaultConfig:
7279
terminationDrainDuration: 30s
@@ -81,13 +88,17 @@ spec:
8188
network: network1
8289
EOF
8390

84-
bin/istioctl install --context="${CTX_CLUSTER1}" -f cluster1.yaml -y &
91+
bin/istioctl install --context="${CTX_CLUSTER1}" --set components.cni.enabled=true -f cluster1.yaml -y &
8592

8693
cat <<EOF >cluster2.yaml
8794
apiVersion: install.istio.io/v1alpha1
8895
kind: IstioOperator
8996
spec:
9097
tag: ${VERSION}
98+
components:
99+
cni:
100+
namespace: istio-system
101+
enabled: true
91102
meshConfig:
92103
defaultConfig:
93104
terminationDrainDuration: 30s
@@ -102,13 +113,17 @@ spec:
102113
network: network1
103114
EOF
104115

105-
bin/istioctl install --context="${CTX_CLUSTER2}" -f cluster2.yaml -y &
116+
bin/istioctl install --context="${CTX_CLUSTER2}" --set components.cni.enabled=true -f cluster2.yaml -y &
106117

107118
cat <<EOF >cluster3.yaml
108119
apiVersion: install.istio.io/v1alpha1
109120
kind: IstioOperator
110121
spec:
111122
tag: ${VERSION}
123+
components:
124+
cni:
125+
namespace: istio-system
126+
enabled: true
112127
meshConfig:
113128
defaultConfig:
114129
terminationDrainDuration: 30s
@@ -123,7 +138,7 @@ spec:
123138
network: network1
124139
EOF
125140

126-
bin/istioctl install --context="${CTX_CLUSTER3}" -f cluster3.yaml -y &
141+
bin/istioctl install --context="${CTX_CLUSTER3}" --set components.cni.enabled=true -f cluster3.yaml -y &
127142

128143
wait
129144

multi_cluster/tools/install_istio_central.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ source multi_cluster/tools/download_istio.sh
1010
cd istio-${VERSION}
1111

1212
bin/istioctl x uninstall --context="${CTX_CLUSTER}" --purge --skip-confirmation
13-
bin/istioctl install --context="${CTX_CLUSTER}" --set profile=default --set meshConfig.outboundTrafficPolicy.mode=REGISTRY_ONLY --skip-confirmation
13+
bin/istioctl install --context="${CTX_CLUSTER}" --set components.cni.enabled=true --set profile=default --set meshConfig.outboundTrafficPolicy.mode=REGISTRY_ONLY --skip-confirmation

public/architectures/setup-multi-cluster/ra-03-setup-istio/install_istio_separate_network.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ spec:
9494
network: network1
9595
EOF
9696
bin/istioctl install --context="${CTX_CLUSTER1}" -f cluster1.yaml -y
97+
9798
samples/multicluster/gen-eastwest-gateway.sh \
9899
--mesh mesh1 --cluster cluster1 --network network1 | \
99100
bin/istioctl --context="${CTX_CLUSTER1}" install -y -f -

public/samples/ops-manager/ops-manager-remote-mode.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ spec:
7373
volumeMounts:
7474
- name: mongodb-versions
7575
mountPath: /mongodb-ops-manager/mongodb-releases/linux
76-
7776
- name: setting-up-rhel-mongodb-4-4-ent
7877
image: curlimages/curl:latest
7978
command:

0 commit comments

Comments
 (0)