This repository has been archived by the owner on Nov 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
istio-dac-permissive.sh
125 lines (114 loc) · 3.52 KB
/
istio-dac-permissive.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash
# Assume helm, kubectl and kind are installed
set -eu
NAMESPACE=${NAMESPACE:-test}
SERVER_COUNT=${SERVER_COUNT:-3}
CONFIG_DIR=$(mktemp -d)
CLUSTER_NAME=${CLUSTER_NAME:-test-istio}
CLUSTER_CONFIG="${CONFIG_DIR}/multinode-cluster-conf.yaml"
K8S_VERSION=${K8S_VERSION:-v1.21.1}
# Create our cluster
cat << EOF > "${CLUSTER_CONFIG}"
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
EOF
for i in $(seq "$SERVER_COUNT"); do
echo "Adding worker $i"
cat << EOF >> "${CLUSTER_CONFIG}"
- role: worker
EOF
done
kind delete cluster --name="${CLUSTER_NAME}" && echo "Deleted old kind cluster, creating a new one..."
kind create cluster --name="${CLUSTER_NAME}" --config="${CLUSTER_CONFIG}" --image kindest/node:"${K8S_VERSION}"
# We load the images here to make sure we do not hit rate limits when run in a loop for CI
declare -a IMAGES_REQUIRED=("docker.io/istio/proxyv2:1.10.1"
"couchbase/server:7.0.2"
"couchbase/operator:2.2.1"
"couchbase/admission-controller:2.2.1"
"couchbase/couchbase-operator:v1"
)
for i in "${IMAGES_REQUIRED[@]}"
do
docker pull "$i" || true
kind load docker-image "$i" --name="${CLUSTER_NAME}"
done
# Add Istio
TEMPDIR=$(mktemp -d)
pushd "$TEMPDIR"
curl -L https://istio.io/downloadIstio | sh -
pushd istio-*/bin
./istioctl install --set profile=default --skip-confirmation --set values.global.istiod.enableAnalysis=true --set meshConfig.accessLogFile=/dev/stdout --set values.global.proxy.privileged=true
# https://istio.io/latest/docs/tasks/security/authentication/authn-policy/#globally-enabling-istio-mutual-tls-in-strict-mode
kubectl apply -f - <<EOF
---
apiVersion: v1
kind: Namespace
metadata:
name: $NAMESPACE
labels:
istio-injection: enabled
---
apiVersion: "security.istio.io/v1beta1"
kind: "PeerAuthentication"
metadata:
name: "peer-authentication-cluster"
namespace: $NAMESPACE
spec:
mtls:
mode: STRICT
---
apiVersion: "security.istio.io/v1beta1"
kind: "PeerAuthentication"
metadata:
name: "peer-authentication-dac"
namespace: $NAMESPACE
spec:
selector:
matchLabels:
app.kubernetes.io/name: couchbase-admission-controller
mtls:
mode: PERMISSIVE
---
apiVersion: "security.istio.io/v1beta1"
kind: "PeerAuthentication"
metadata:
name: "peer-authentication-metrics"
namespace: $NAMESPACE
spec:
selector:
matchLabels:
app: couchbase
portLevelMtls:
9091:
mode: PERMISSIVE
---
EOF
popd
popd
rm -rf "$TEMPDIR"
# Add Couchbase via helm chart
helm repo add couchbase https://couchbase-partners.github.io/helm-charts/
helm repo update
helm upgrade --install -n "$NAMESPACE" test1 couchbase/couchbase-operator --set cluster.networking.networkPlatform=Istio,couchbaseOperator.image.repository=couchbase/couchbase-operator,couchbaseOperator.image.tag=v1
#--set install.admissionController=false #--version 2.1.0
# Wait for 3 servers to come up
echo "Waiting for CB to start up..."
until [[ $(kubectl get pods -n "$NAMESPACE" --field-selector=status.phase=Running --selector='app=couchbase' --no-headers 2>/dev/null |wc -l) -eq 3 ]]; do
echo -n '.'
sleep 2
done
echo "CB started"
ORIGINAL=$(mktemp)
UPDATED=$(mktemp)
kubectl get -n test couchbaseclusters.couchbase.com test1-couchbase-cluster -o yaml > "$ORIGINAL"
sed 's/size: 3/size: 4/g' "$ORIGINAL" > "$UPDATED"
kubectl apply -f "$UPDATED"
cat "$UPDATED"
echo "Waiting for CB to update..."
until [[ $(kubectl get pods -n "$NAMESPACE" --field-selector=status.phase=Running --selector='app=couchbase' --no-headers 2>/dev/null |wc -l) -eq 4 ]]; do
echo -n '.'
sleep 2
done
echo "CB updated"