-
Notifications
You must be signed in to change notification settings - Fork 134
/
sensor.sh
144 lines (125 loc) · 5.4 KB
/
sensor.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env bash
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)"
KUBE_COMMAND=${KUBE_COMMAND:-oc}
SKIP_ORCHESTRATOR_CHECK=${SKIP_ORCHESTRATOR_CHECK:-false}
if [[ "${SKIP_ORCHESTRATOR_CHECK}" == "true" ]] ; then
echo >&2 "WARN: Skipping orchestrator check..."
else
count="$(${KUBE_COMMAND} api-resources | grep "securitycontextconstraints" -c || true)"
if [[ "${count}" -eq 0 ]]; then
echo >&2 "Detected an attempt to deploy a cluster bundle designed to be deployed on OpenShift, \\
on a vanilla Kubernetes cluster. Please regenerate the cluster bundle using cluster type 'k8s' and redeploy. \\
If you think this message is in error, and would like to continue deploying the cluster bundle, please rerun \\
the script using 'SKIP_ORCHESTRATOR_CHECK=true ./sensor.sh'"
exit 1
fi
fi
SUPPORTS_PSP=$(${KUBE_COMMAND} api-resources | grep "podsecuritypolicies" -c || true)
${KUBE_COMMAND} get namespace stackrox &>/dev/null || ${KUBE_COMMAND} create namespace stackrox
${KUBE_COMMAND} -n stackrox annotate namespace/stackrox --overwrite openshift.io/node-selector=""
${KUBE_COMMAND} project "stackrox"
echo "Creating sensor secrets..."
${KUBE_COMMAND} apply -f "$DIR/sensor-secret.yaml"
echo "Creating sensor RBAC roles..."
${KUBE_COMMAND} apply -f "$DIR/sensor-rbac.yaml"
if [[ -f "$DIR/sensor-compliance-rbac.yaml" ]]; then
echo "Creating sensor compliance RBAC roles..."
${KUBE_COMMAND} apply -f "$DIR/sensor-compliance-rbac.yaml"
fi
echo "Creating sensor network policies..."
${KUBE_COMMAND} apply -f "$DIR/sensor-netpol.yaml"
if [[ -f "$DIR/sensor-pod-security.yaml" ]]; then
# Checking if the cluster supports pod security policies
if [[ "${SUPPORTS_PSP}" -eq 0 ]]; then
echo "Pod security policies are not supported on this cluster. Skipping..."
else
echo "Creating sensor pod security policies..."
${KUBE_COMMAND} apply -f "$DIR/sensor-pod-security.yaml"
fi
fi
if [[ -f "$DIR/openshift-monitoring.yaml" ]]; then
echo "Creating OpenShift monitoring configuration..."
${KUBE_COMMAND} apply -f "$DIR/openshift-monitoring.yaml"
fi
# OpenShift roles can be delayed to be added
sleep 5
if ! ${KUBE_COMMAND} get secret/stackrox -n stackrox &>/dev/null; then
registry_auth="$("${DIR}/docker-auth.sh" -m k8s "{{ required "" .MainRegistry }}")"
[[ -n "$registry_auth" ]] || { echo >&2 "Unable to get registry auth info." ; exit 1 ; }
${KUBE_COMMAND} create --namespace "stackrox" -f - <<EOF
apiVersion: v1
data:
.dockerconfigjson: ${registry_auth}
kind: Secret
metadata:
name: stackrox
namespace: stackrox
labels:
app.kubernetes.io/name: stackrox
type: kubernetes.io/dockerconfigjson
EOF
fi
${KUBE_COMMAND} secrets link serviceaccount/sensor secrets/stackrox --for=pull
if ! ${KUBE_COMMAND} get secret/collector-stackrox -n stackrox &>/dev/null; then
registry_auth="$("${DIR}/docker-auth.sh" -m k8s "{{ required "" .CollectorRegistry }}")"
[[ -n "$registry_auth" ]] || { echo >&2 "Unable to get registry auth info." ; exit 1 ; }
${KUBE_COMMAND} create --namespace "stackrox" -f - <<EOF
apiVersion: v1
data:
.dockerconfigjson: ${registry_auth}
kind: Secret
metadata:
name: collector-stackrox
namespace: stackrox
type: kubernetes.io/dockerconfigjson
EOF
fi
echo "Creating admission controller secrets..."
${KUBE_COMMAND} apply -f "$DIR/admission-controller-secret.yaml"
echo "Creating admission controller RBAC roles..."
${KUBE_COMMAND} apply -f "$DIR/admission-controller-rbac.yaml"
echo "Creating admission controller network policies..."
${KUBE_COMMAND} apply -f "$DIR/admission-controller-netpol.yaml"
if [[ -f "$DIR/admission-controller-pod-security.yaml" ]]; then
if [[ "${SUPPORTS_PSP}" -eq 0 ]]; then
echo "Pod security policies are not supported on this cluster. Skipping..."
else
echo "Creating admission controller pod security policies..."
${KUBE_COMMAND} apply -f "$DIR/admission-controller-pod-security.yaml"
fi
fi
echo "Creating admission controller deployment..."
${KUBE_COMMAND} apply -f "$DIR/admission-controller.yaml"
echo "Creating collector security context constraints..."
${KUBE_COMMAND} apply -f "$DIR/collector-scc.yaml"
echo "Creating collector secrets..."
${KUBE_COMMAND} apply -f "$DIR/collector-secret.yaml"
echo "Creating collector RBAC roles..."
${KUBE_COMMAND} apply -f "$DIR/collector-rbac.yaml"
echo "Creating collector network policies..."
${KUBE_COMMAND} apply -f "$DIR/collector-netpol.yaml"
if [[ -f "$DIR/collector-pod-security.yaml" ]]; then
if [[ "${SUPPORTS_PSP}" -eq 0 ]]; then
echo "Pod security policies are not supported on this cluster. Skipping..."
else
echo "Creating collector pod security policies..."
${KUBE_COMMAND} apply -f "$DIR/collector-pod-security.yaml"
fi
fi
echo "Creating collector daemon set..."
${KUBE_COMMAND} apply -f "$DIR/collector.yaml"
if [[ -f "$DIR/additional-ca-sensor.yaml" ]]; then
echo "Creating secret for additional CAs for sensor..."
${KUBE_COMMAND} apply -f "$DIR/additional-ca-sensor.yaml"
fi
echo "Creating sensor deployment..."
${KUBE_COMMAND} apply -f "$DIR/sensor.yaml"
{{- if .CreateUpgraderSA }}
echo "Creating upgrader service account"
${KUBE_COMMAND} apply -f "${DIR}/upgrader-serviceaccount.yaml"
{{- else }}
if [[ -f "${DIR}/upgrader-serviceaccount.yaml" ]]; then
printf "%s\n\n%s\n" "Did not create the upgrader service account. To create it later, please run" "${KUBE_COMMAND} apply -f \"${DIR}/upgrader-serviceaccount.yaml\""
fi
{{- end }}