ceph: adds scripts and components to support admission controllers
adds deploy.sh script to deploy validatingwebhookconfiguration and create secrets. adds new command ceph admission-controller to start webhook servers. adds validation for various rook custom resources Signed-off-by: Vineet Badrinath <vbadrina@redhat.com>
This commit is contained in:
1 parent
675c9673ca
commit
ce1003aef8
27 files changed
+1088
-19
No files matched your search
Executable
+30
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env bash
|
||||
# deploy_admission_controller.sh
|
||||
# Sets up the environment for the admission controller webhook in the active cluster.
|
||||
set -eo pipefail
|
||||
|
||||
# Set our known directories and parameters.
|
||||
BASE_DIR=$(cd "$(dirname "$0")"; pwd)
|
||||
|
||||
# Set the variables for webhook. Any change here for namespace and service name should be done in pkg/operator/admission/init.go also
|
||||
[ -z "${NAMESPACE}" ] && NAMESPACE="rook-ceph"
|
||||
WEBHOOK_CONFIG_NAME="rook-ceph-webhook"
|
||||
SERVICE_NAME="rook-ceph-admission-controller"
|
||||
|
||||
INSTALL_SELF_SIGNED_CERT=true
|
||||
echo "$BASE_DIR"
|
||||
|
||||
if [ "${INSTALL_SELF_SIGNED_CERT}" == true ]; then
|
||||
"${BASE_DIR}"/webhook-create-signed-cert.sh --namespace ${NAMESPACE}
|
||||
fi
|
||||
echo "Deploying webhook config"
|
||||
export NAMESPACE
|
||||
export WEBHOOK_CONFIG_NAME
|
||||
export SERVICE_NAME
|
||||
cat ${BASE_DIR}/webhook-config.yaml | \
|
||||
"${BASE_DIR}"/webhook-patch-ca-bundle.sh | \
|
||||
sed -e "s|\${NAMESPACE}|${NAMESPACE}|g" | \
|
||||
sed -e "s|\${WEBHOOK_CONFIG_NAME}|${WEBHOOK_CONFIG_NAME}|g" | \
|
||||
sed -e "s|\${SERVICE_NAME}|${SERVICE_NAME}|g" | \
|
||||
kubectl create -f -
|
||||
echo "Webhook deployed! Please start the rook operator to create the service and admission controller pods"
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
BASE_DIR=$(cd "$(dirname "$0")"; pwd)
|
||||
|
||||
if [ -z "$KUBECONFIG" ];then
|
||||
if [ -f "$HOME/.kube/config" ]; then
|
||||
export KUBECONFIG="$HOME/.kube/config"
|
||||
else
|
||||
sudo cp /etc/kubernetes/admin.conf $HOME/
|
||||
sudo chown $(id -u):$(id -g) $HOME/admin.conf
|
||||
export KUBECONFIG=$HOME/admin.conf
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -f "${BASE_DIR}"/deploy_admission_controller.sh ];then
|
||||
bash "${BASE_DIR}"/deploy_admission_controller.sh
|
||||
else
|
||||
echo ""${BASE_DIR}"/deploy_admission_controller.sh not found !"
|
||||
fi
|
||||
@@ -0,0 +1,22 @@
|
||||
apiVersion: admissionregistration.k8s.io/v1beta1
|
||||
kind: ValidatingWebhookConfiguration
|
||||
metadata:
|
||||
name: ${WEBHOOK_CONFIG_NAME}
|
||||
namespace: ${NAMESPACE}
|
||||
webhooks:
|
||||
- name: ${SERVICE_NAME}.${NAMESPACE}.svc
|
||||
rules:
|
||||
- apiGroups: ["ceph.rook.io"]
|
||||
apiVersions: ["v1"]
|
||||
operations: ["CREATE","UPDATE","DELETE"]
|
||||
resources: ["*"]
|
||||
clientConfig:
|
||||
service:
|
||||
name: ${SERVICE_NAME}
|
||||
namespace: ${NAMESPACE}
|
||||
path: /validate
|
||||
caBundle: ${CA_BUNDLE}
|
||||
admissionReviewVersions: ["v1beta1"]
|
||||
sideEffects: None
|
||||
timeoutSeconds: 5
|
||||
|
||||
Executable
+135
@@ -0,0 +1,135 @@
|
||||
#!/bin/bash
|
||||
# Original script found at: https://github.com/morvencao/kube-mutating-webhook-tutorial/blob/master/deployment/webhook-create-signed-cert.sh
|
||||
|
||||
set -e
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Generate certificate suitable for use with an trace-context-injector webhook service.
|
||||
|
||||
This script uses k8s' CertificateSigningRequest API to a generate a
|
||||
certificate signed by k8s CA suitable for use with trace-context-injector webhook
|
||||
services. This requires permissions to create and approve CSR. See
|
||||
https://kubernetes.io/docs/tasks/tls/managing-tls-in-a-cluster for
|
||||
detailed explantion and additional instructions.
|
||||
|
||||
The server key/cert k8s CA cert are stored in a k8s secret.
|
||||
|
||||
usage: ${0} [OPTIONS]
|
||||
|
||||
The following flags are required.
|
||||
|
||||
--service Service name of webhook.
|
||||
--namespace Namespace where webhook service and secret reside.
|
||||
--secret Secret name for CA certificate and server certificate/key pair.
|
||||
EOF
|
||||
exit 1
|
||||
}
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case ${1} in
|
||||
--service)
|
||||
service="$2"
|
||||
shift
|
||||
;;
|
||||
--secret)
|
||||
secret="$2"
|
||||
shift
|
||||
;;
|
||||
--namespace)
|
||||
namespace="$2"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
[ -z "${service}" ] && service=rook-ceph-admission-controller
|
||||
[ -z "${secret}" ] && secret=rook-ceph-admission-controller
|
||||
[ -z "${namespace}" ] && namespace=rook-ceph
|
||||
|
||||
if [ ! -x "$(command -v openssl)" ]; then
|
||||
echo "openssl not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
csrName=${service}.${namespace}
|
||||
tmpdir=$(mktemp -d)
|
||||
echo "creating certs in tmpdir ${tmpdir} "
|
||||
|
||||
cat <<EOF >> ${tmpdir}/csr.conf
|
||||
[req]
|
||||
req_extensions = v3_req
|
||||
distinguished_name = req_distinguished_name
|
||||
[req_distinguished_name]
|
||||
[ v3_req ]
|
||||
basicConstraints = CA:FALSE
|
||||
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
|
||||
extendedKeyUsage = serverAuth
|
||||
subjectAltName = @alt_names
|
||||
[alt_names]
|
||||
DNS.1 = ${service}
|
||||
DNS.2 = ${service}.${namespace}
|
||||
DNS.3 = ${service}.${namespace}.svc
|
||||
EOF
|
||||
|
||||
openssl genrsa -out ${tmpdir}/server-key.pem 2048
|
||||
openssl req -new -key ${tmpdir}/server-key.pem -subj "/CN=${service}.${namespace}.svc" -out ${tmpdir}/server.csr -config ${tmpdir}/csr.conf
|
||||
|
||||
cat ${tmpdir}/server.csr
|
||||
# clean-up any previously created CSR for our service. Ignore errors if not present.
|
||||
kubectl delete csr ${csrName} 2>/dev/null || true
|
||||
|
||||
# create server cert/key CSR and send to k8s API
|
||||
cat <<EOF | kubectl create -f -
|
||||
apiVersion: certificates.k8s.io/v1beta1
|
||||
kind: CertificateSigningRequest
|
||||
metadata:
|
||||
name: ${csrName}
|
||||
spec:
|
||||
groups:
|
||||
- system:authenticated
|
||||
request: $(cat ${tmpdir}/server.csr | base64 | tr -d '\n')
|
||||
usages:
|
||||
- digital signature
|
||||
- key encipherment
|
||||
- server auth
|
||||
EOF
|
||||
|
||||
# verify CSR has been created
|
||||
while true; do
|
||||
kubectl get csr ${csrName}
|
||||
if [ "$?" -eq 0 ]; then
|
||||
echo "Successfully verified CSR"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
# approve and fetch the signed certificate
|
||||
kubectl certificate approve ${csrName}
|
||||
# verify certificate has been signed
|
||||
for x in $(seq 10); do
|
||||
serverCert=$(kubectl get csr ${csrName} -o jsonpath='{.status.certificate}')
|
||||
if [[ ${serverCert} != '' ]]; then
|
||||
echo "Successfully verified certificate signatures"
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
if [[ ${serverCert} == '' ]]; then
|
||||
echo "ERROR: After approving csr ${csrName}, the signed certificate did not appear on the resource. Giving up after 10 attempts." >&2
|
||||
exit 1
|
||||
fi
|
||||
echo ${serverCert} | openssl base64 -d -A -out ${tmpdir}/server-cert.pem
|
||||
|
||||
|
||||
kubectl create secret generic ${secret} \
|
||||
--from-file=tls.key=${tmpdir}/server-key.pem \
|
||||
--from-file=tls.crt=${tmpdir}/server-cert.pem \
|
||||
--dry-run -o yaml |
|
||||
kubectl -n ${namespace} apply -f -
|
||||
|
||||
Executable
+14
@@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
# Original script found at: https://github.com/morvencao/kube-mutating-webhook-tutorial/blob/master/deployment/webhook-patch-ca-bundle.sh
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
export CA_BUNDLE=$(kubectl get configmap -n kube-system extension-apiserver-authentication -o=jsonpath='{.data.client-ca-file}' | base64 | tr -d '\n')
|
||||
|
||||
if command -v envsubst >/dev/null 2>&1; then
|
||||
envsubst
|
||||
else
|
||||
sed -e "s|\${CA_BUNDLE}|${CA_BUNDLE}|g"
|
||||
fi
|
||||
Reference in new issue
Block a user