From ab62a6c4417562d2a67d6e825c31139c2b911e7c Mon Sep 17 00:00:00 2001 From: Hidekazu Nakamura Date: Tue, 5 Feb 2019 05:44:03 +0000 Subject: [PATCH] Support keystone with cacert --- .../examples/openstack/generate-yaml.sh | 25 ++++- .../clouds-secrets/kustomization.yaml | 1 + .../centos/templates/master-user-data.sh | 10 ++ .../centos/templates/worker-user-data.sh | 2 + .../user-data/coreos/templates/common.yaml | 10 ++ .../user-data/coreos/templates/master.yaml | 6 ++ .../ubuntu/templates/master-user-data.sh | 10 ++ .../ubuntu/templates/worker-user-data.sh | 2 + ...v1alpha1_openstackclusterproviderspec.yaml | 6 ++ .../openstackproviderconfig/v1alpha1/types.go | 6 ++ .../v1alpha1/zz_generated.deepcopy.go | 5 + pkg/cloud/openstack/clients/machineservice.go | 56 +++++++--- pkg/cloud/openstack/cluster/actuator.go | 100 +++++++++++++++++- 13 files changed, 222 insertions(+), 17 deletions(-) diff --git a/cmd/clusterctl/examples/openstack/generate-yaml.sh b/cmd/clusterctl/examples/openstack/generate-yaml.sh index a507e883ae..e4bead45a5 100755 --- a/cmd/clusterctl/examples/openstack/generate-yaml.sh +++ b/cmd/clusterctl/examples/openstack/generate-yaml.sh @@ -136,6 +136,7 @@ OPENSTACK_CLOUD_CONFIG_PLAIN=$(cat "$CLOUDS_PATH") MACHINE_CONTROLLER_SSH_PRIVATE_FILE=openstack_tmp MACHINE_CONTROLLER_SSH_HOME=${HOME}/.ssh/ +CACERT="/etc/certs/cacert" # Set up the output dir if it does not yet exist mkdir -p $PWD/$OUTPUT @@ -159,7 +160,7 @@ PASSWORD=$(echo "$OPENSTACK_CLOUD_CONFIG_PLAIN" | yq r - clouds.$CLOUD.auth.pass REGION=$(echo "$OPENSTACK_CLOUD_CONFIG_PLAIN" | yq r - clouds.$CLOUD.region_name) PROJECT_ID=$(echo "$OPENSTACK_CLOUD_CONFIG_PLAIN" | yq r - clouds.$CLOUD.auth.project_id) DOMAIN_NAME=$(echo "$OPENSTACK_CLOUD_CONFIG_PLAIN" | yq r - clouds.$CLOUD.auth.user_domain_name) - +CACERT_ORIGINAL=$(echo "$OPENSTACK_CLOUD_CONFIG_PLAIN" | yq r - clouds.$CLOUD.cacert) # Basic cloud.conf, no LB configuration as that data is not known yet. OPENSTACK_CLOUD_PROVIDER_CONF_PLAIN="[Global] @@ -171,11 +172,23 @@ tenant-id=\"$PROJECT_ID\" domain-name=\"$DOMAIN_NAME\" " +if [ "$CACERT_ORIGINAL" != "null" ]; then + OPENSTACK_CLOUD_PROVIDER_CONF_PLAIN="$OPENSTACK_CLOUD_PROVIDER_CONF_PLAIN + ca-file=\"$CACERT\" + " +fi + OS=$(uname) if [[ "$OS" =~ "Linux" ]]; then OPENSTACK_CLOUD_PROVIDER_CONF=$(echo "$OPENSTACK_CLOUD_PROVIDER_CONF_PLAIN"|base64 -w0) + if [ "$CACERT_ORIGINAL" != "null" ]; then + OPENSTACK_CLOUD_CACERT_CONFIG=$(cat "$CACERT_ORIGINAL"|base64 -w0) + fi elif [[ "$OS" =~ "Darwin" ]]; then OPENSTACK_CLOUD_PROVIDER_CONF=$(echo "$OPENSTACK_CLOUD_PROVIDER_CONF_PLAIN"|base64) + if [ "$CACERT_ORIGINAL" != "null" ]; then + OPENSTACK_CLOUD_CACERT_CONFIG=$(cat "$CACERT_ORIGINAL"|base64) + fi else echo "Unrecognized OS : $OS" exit 1 @@ -184,24 +197,32 @@ fi if [[ "$PROVIDER_OS" == "coreos" ]]; then cat $COREOS_COMMON_SECTION \ | sed -e "s#\$OPENSTACK_CLOUD_PROVIDER_CONF#$OPENSTACK_CLOUD_PROVIDER_CONF#" \ + | sed -e "s#\$OPENSTACK_CLOUD_CACERT_CONFIG#$OPENSTACK_CLOUD_CACERT_CONFIG#" \ | yq m -a - $COREOS_MASTER_SECTION \ > $COREOS_MASTER_USER_DATA cat $COREOS_COMMON_SECTION \ | sed -e "s#\$OPENSTACK_CLOUD_PROVIDER_CONF#$OPENSTACK_CLOUD_PROVIDER_CONF#" \ + | sed -e "s#\$OPENSTACK_CLOUD_CACERT_CONFIG#$OPENSTACK_CLOUD_CACERT_CONFIG#" \ | yq m -a - $COREOS_WORKER_SECTION \ > $COREOS_WORKER_USER_DATA else cat "$MASTER_USER_DATA" \ | sed -e "s#\$OPENSTACK_CLOUD_PROVIDER_CONF#$OPENSTACK_CLOUD_PROVIDER_CONF#" \ + | sed -e "s#\$OPENSTACK_CLOUD_CACERT_CONFIG#$OPENSTACK_CLOUD_CACERT_CONFIG#" \ > $USERDATA/$PROVIDER_OS/master-user-data.sh cat "$WORKER_USER_DATA" \ | sed -e "s#\$OPENSTACK_CLOUD_PROVIDER_CONF#$OPENSTACK_CLOUD_PROVIDER_CONF#" \ + | sed -e "s#\$OPENSTACK_CLOUD_CACERT_CONFIG#$OPENSTACK_CLOUD_CACERT_CONFIG#" \ > $USERDATA/$PROVIDER_OS/worker-user-data.sh fi printf $CLOUD > $CONFIG_DIR/os_cloud.txt echo "$OPENSTACK_CLOUD_CONFIG_PLAIN" > $CONFIG_DIR/clouds.yaml - +if [ "$CACERT_ORIGINAL" != "null" ]; then + cat "$CACERT_ORIGINAL" > $CONFIG_DIR/cacert +else + echo "dummy" > $CONFIG_DIR/cacert +fi # Build provider-components.yaml with kustomize # Coreos has a different kubeadm path (/usr is read-only) so gets a different kustomization. diff --git a/cmd/clusterctl/examples/openstack/provider-component/clouds-secrets/kustomization.yaml b/cmd/clusterctl/examples/openstack/provider-component/clouds-secrets/kustomization.yaml index b827b58782..036c9ee8f7 100644 --- a/cmd/clusterctl/examples/openstack/provider-component/clouds-secrets/kustomization.yaml +++ b/cmd/clusterctl/examples/openstack/provider-component/clouds-secrets/kustomization.yaml @@ -7,6 +7,7 @@ secretGenerator: - name: cloud-config commands: clouds.yaml: "cat configs/clouds.yaml" + cacert: "cat configs/cacert" type: Opaque - name: cloud-selector commands: diff --git a/cmd/clusterctl/examples/openstack/provider-component/user-data/centos/templates/master-user-data.sh b/cmd/clusterctl/examples/openstack/provider-component/user-data/centos/templates/master-user-data.sh index e3f999b9f8..2741ef6e03 100644 --- a/cmd/clusterctl/examples/openstack/provider-component/user-data/centos/templates/master-user-data.sh +++ b/cmd/clusterctl/examples/openstack/provider-component/user-data/centos/templates/master-user-data.sh @@ -86,6 +86,8 @@ echo '1' > /proc/sys/net/bridge/bridge-nf-call-iptables echo '1' > /proc/sys/net/ipv4/ip_forward echo $OPENSTACK_CLOUD_PROVIDER_CONF | base64 -d > /etc/kubernetes/cloud.conf +mkdir /etc/certs +echo $OPENSTACK_CLOUD_CACERT_CONFIG | base64 -d > /etc/certs/cacert # Set up kubeadm config file to pass parameters to kubeadm init. cat > /etc/kubernetes/kubeadm_config.yaml < /etc/kubernetes/cloud.conf +mkdir /etc/certs +echo $OPENSTACK_CLOUD_CACERT_CONFIG | base64 -d > /etc/certs/cacert # Set up kubeadm config file to pass to kubeadm join. cat > /etc/kubernetes/kubeadm_config.yaml < /etc/kubernetes/cloud.conf chmod 600 /etc/kubernetes/cloud.conf +mkdir /etc/certs +echo $OPENSTACK_CLOUD_CACERT_CONFIG | base64 -d > /etc/certs/cacert systemctl daemon-reload systemctl restart kubelet.service @@ -150,6 +152,10 @@ apiServer: mountPath: /etc/kubernetes/cloud.conf name: cloud readOnly: true + - hostPath: "/etc/certs/cacert" + mountPath: "/etc/certs/cacert" + name: cacert + readOnly: true timeoutForControlPlane: 4m0s certificatesDir: /etc/kubernetes/pki clusterName: kubernetes @@ -166,6 +172,10 @@ controllerManager: mountPath: /etc/kubernetes/cloud.conf name: cloud readOnly: true + - hostPath: "/etc/certs/cacert" + mountPath: "/etc/certs/cacert" + name: cacert + readOnly: true dns: type: CoreDNS etcd: diff --git a/cmd/clusterctl/examples/openstack/provider-component/user-data/ubuntu/templates/worker-user-data.sh b/cmd/clusterctl/examples/openstack/provider-component/user-data/ubuntu/templates/worker-user-data.sh index 3e8d787b43..461db40e05 100644 --- a/cmd/clusterctl/examples/openstack/provider-component/user-data/ubuntu/templates/worker-user-data.sh +++ b/cmd/clusterctl/examples/openstack/provider-component/user-data/ubuntu/templates/worker-user-data.sh @@ -79,6 +79,8 @@ CLUSTER_DNS_SERVER=$(prips ${SERVICE_CIDR} | head -n 11 | tail -n 1) # Write the cloud.conf so that the kubelet can use it. echo $OPENSTACK_CLOUD_PROVIDER_CONF | base64 -d > /etc/kubernetes/cloud.conf +mkdir /etc/certs +echo $OPENSTACK_CLOUD_CACERT_CONFIG | base64 -d > /etc/certs/cacert # Set up kubeadm config file to pass to kubeadm join. cat > /etc/kubernetes/kubeadm_config.yaml <