From 125596756741f9207e5b92449c324e3c9b8d96bd Mon Sep 17 00:00:00 2001 From: Shreyas Rao Date: Fri, 16 Aug 2019 11:56:36 +0530 Subject: [PATCH] Add TLS support for backup-restore server Signed-off-by: Shreyas Rao --- README.md | 1 + .../templates/etcd-bootstrap-configmap.yaml | 17 +- .../templates/etcd-ca-secret.yaml | 6 +- .../templates/etcd-statefulset.yaml | 41 +++- .../templates/etcd-tls-secret.yaml | 6 +- .../templates/etcdbr-ca-secret.yaml | 14 ++ .../templates/etcdbr-tls-secret.yaml | 15 ++ chart/etcd-backup-restore/values.yaml | 221 ++++++++++++++++-- cmd/server.go | 59 +++-- cmd/types.go | 6 +- doc/usage/generating_ssl_certificates.md | 140 +++++++++++ pkg/server/httpAPI.go | 37 ++- 12 files changed, 495 insertions(+), 68 deletions(-) create mode 100644 chart/etcd-backup-restore/templates/etcdbr-ca-secret.yaml create mode 100644 chart/etcd-backup-restore/templates/etcdbr-tls-secret.yaml create mode 100644 doc/usage/generating_ssl_certificates.md diff --git a/README.md b/README.md index 194cef7f2..6aee39ed4 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ Etcd-backup-restore is collection of components to backup and restore the [etcd] * [Getting started](doc/usage/getting_started.md) * [Manual restoration](doc/usage/manual_restoration.md) * [Monitoring](doc/usage/metrics.md) +* [Generating SSL certificates](doc/usage/generating_ssl_certificates.md) ### Design and Proposals diff --git a/chart/etcd-backup-restore/templates/etcd-bootstrap-configmap.yaml b/chart/etcd-backup-restore/templates/etcd-bootstrap-configmap.yaml index db3d87830..f4089d447 100644 --- a/chart/etcd-backup-restore/templates/etcd-bootstrap-configmap.yaml +++ b/chart/etcd-backup-restore/templates/etcd-bootstrap-configmap.yaml @@ -13,6 +13,13 @@ data: #!/bin/sh VALIDATION_MARKER=/var/etcd/data/validation_marker +{{- if .Values.backupRestoreTLS }} + # install wget from apk in order to pass --ca-certificate flag because + # busybox wget only has bare minimum features, without --ca-certificate option + apk update + apk add wget +{{- end }} + trap_and_propagate() { PID=$1 shift @@ -35,11 +42,11 @@ data: check_and_start_etcd(){ while true; do - wget "http://localhost:{{ .Values.servicePorts.backupRestore }}/initialization/status" -S -O status; + wget {{ if .Values.backupRestoreTLS }}--ca-certificate=/var/etcdbr/ssl/ca/ca.crt "https{{ else }}"http{{ end }}://localhost:{{ .Values.servicePorts.backupRestore }}/initialization/status" -S -O status; STATUS=`cat status`; case $STATUS in "New") - wget "http://localhost:{{ .Values.servicePorts.backupRestore }}/initialization/start?mode=$1{{- if .Values.backup.failBelowRevision }}&failbelowrevision={{ int $.Values.backup.failBelowRevision }}{{- end }}" -S -O - ;; + wget {{ if .Values.backupRestoreTLS }}--ca-certificate=/var/etcdbr/ssl/ca/ca.crt "https{{ else }}"http{{ end }}://localhost:{{ .Values.servicePorts.backupRestore }}/initialization/start?mode=$1{{- if .Values.backup.failBelowRevision }}&failbelowrevision={{ int $.Values.backup.failBelowRevision }}{{- end }}" -S -O - ;; "Progress") sleep 1; continue;; @@ -95,11 +102,11 @@ data: {{- end }} # List of comma separated URLs to listen on for client traffic. - listen-client-urls: {{ if .Values.tls }}https{{ else }}http{{ end }}://0.0.0.0:{{ .Values.servicePorts.client }} + listen-client-urls: {{ if .Values.etcdTLS }}https{{ else }}http{{ end }}://0.0.0.0:{{ .Values.servicePorts.client }} # List of this member's client URLs to advertise to the public. # The URLs needed to be a comma-separated list. - advertise-client-urls: {{ if .Values.tls }}https{{ else }}http{{ end }}://0.0.0.0:{{ .Values.servicePorts.client }} + advertise-client-urls: {{ if .Values.etcdTLS }}https{{ else }}http{{ end }}://0.0.0.0:{{ .Values.servicePorts.client }} # Initial cluster token for the etcd cluster during bootstrap. initial-cluster-token: 'new' @@ -107,7 +114,7 @@ data: # Initial cluster state ('new' or 'existing'). initial-cluster-state: 'new' -{{- if .Values.tls }} +{{- if .Values.etcdTLS }} client-transport-security: # Path to the client server TLS cert file. cert-file: /var/etcd/ssl/tls/tls.crt diff --git a/chart/etcd-backup-restore/templates/etcd-ca-secret.yaml b/chart/etcd-backup-restore/templates/etcd-ca-secret.yaml index ff6154d16..7a4abc01c 100644 --- a/chart/etcd-backup-restore/templates/etcd-ca-secret.yaml +++ b/chart/etcd-backup-restore/templates/etcd-ca-secret.yaml @@ -1,5 +1,6 @@ -{{- if .Values.tls }} +{{- if .Values.etcdTLS }} apiVersion: v1 +kind: Secret metadata: name: {{ .Release.Name }}-etcd-ca namespace: {{ .Release.Namespace }} @@ -9,6 +10,5 @@ metadata: app.kubernetes.io/instance: {{ .Release.Name }} type: Opaque data: - ca.crt: {{ .Values.tls.caBundle | b64enc }} -kind: Secret + ca.crt: {{ .Values.etcdTLS.caBundle | b64enc }} {{- end }} \ No newline at end of file diff --git a/chart/etcd-backup-restore/templates/etcd-statefulset.yaml b/chart/etcd-backup-restore/templates/etcd-statefulset.yaml index 760a50286..c11505742 100644 --- a/chart/etcd-backup-restore/templates/etcd-statefulset.yaml +++ b/chart/etcd-backup-restore/templates/etcd-statefulset.yaml @@ -35,6 +35,9 @@ spec: - /var/etcd/bin/bootstrap.sh readinessProbe: httpGet: +{{- if .Values.backupRestoreTLS }} + scheme: HTTPS +{{- end }} path: /healthz port: {{ .Values.servicePorts.backupRestore }} initialDelaySeconds: 5 @@ -46,10 +49,12 @@ spec: - -ec - ETCDCTL_API=3 - etcdctl +{{ if .Values.etcdTLS }} - --cert=/var/etcd/ssl/tls/tls.crt - --key=/var/etcd/ssl/tls/tls.key - --cacert=/var/etcd/ssl/ca/ca.crt - - --endpoints={{ if .Values.tls }}https{{ else }}http{{ end }}://{{ .Release.Name }}-etcd-0:{{ .Values.servicePorts.client }} +{{ end }} + - --endpoints={{ if .Values.etcdTLS }}https{{ else }}http{{ end }}://{{ .Release.Name }}-etcd-0:{{ .Values.servicePorts.client }} {{- if and .Values.etcdAuth.username .Values.etcdAuth.password }} - --user={{ .Values.etcdAuth.username }}:{{ .Values.etcdAuth.password }} {{- end }} @@ -73,11 +78,15 @@ spec: mountPath: /var/etcd/bin/ - name: etcd-config-file mountPath: /var/etcd/config/ -{{- if .Values.tls }} +{{- if .Values.etcdTLS }} - name: ca-etcd mountPath: /var/etcd/ssl/ca - name: etcd-tls mountPath: /var/etcd/ssl/tls +{{- end }} +{{- if .Values.backupRestoreTLS }} + - name: ca-etcdbr + mountPath: /var/etcdbr/ssl/ca {{- end }} - name: backup-restore command: @@ -94,7 +103,7 @@ spec: {{- if .Values.backup.etcdQuotaBytes }} - --embedded-etcd-quota-bytes={{ int $.Values.backup.etcdQuotaBytes }} {{- end }} -{{- if .Values.tls }} +{{- if .Values.etcdTLS }} - --cert=/var/etcd/ssl/tls/tls.crt - --key=/var/etcd/ssl/tls/tls.key - --cacert=/var/etcd/ssl/ca/ca.crt @@ -115,6 +124,10 @@ spec: {{- if and .Values.etcdAuth.username .Values.etcdAuth.password }} - --etcd-username={{ .Values.etcdAuth.username }} - --etcd-password={{ .Values.etcdAuth.password }} +{{- end }} +{{- if .Values.backupRestoreTLS }} + - --server-cert=/var/etcdbr/ssl/tls/tls.crt + - --server-key=/var/etcdbr/ssl/tls/tls.key {{- end }} image: {{ .Values.images.etcdBackupRestore.repository }}:{{ .Values.images.etcdBackupRestore.tag }} imagePullPolicy: {{ .Values.images.etcdBackupRestore.pullPolicy }} @@ -205,12 +218,18 @@ spec: mountPath: /var/etcd/data/ - name: etcd-config-file mountPath: /var/etcd/config/ -{{- if .Values.tls }} +{{- if .Values.etcdTLS }} - name: ca-etcd mountPath: /var/etcd/ssl/ca - name: etcd-tls mountPath: /var/etcd/ssl/tls {{- end }} +{{- if .Values.backupRestoreTLS }} + - name: ca-etcdbr + mountPath: /var/etcdbr/ssl/ca + - name: etcdbr-tls + mountPath: /var/etcdbr/ssl/tls +{{- end }} {{- if eq .Values.backup.storageProvider "GCS" }} - name: etcd-backup mountPath: "/root/.gcp/" @@ -230,13 +249,21 @@ spec: items: - key: etcd.conf.yaml path: etcd.conf.yaml -{{- if .Values.tls }} +{{- if .Values.etcdTLS }} + - name: ca-etcd + secret: + secretName: {{ .Release.Name }}-etcd-ca - name: etcd-tls secret: secretName: {{ .Release.Name }}-etcd-tls - - name: ca-etcd +{{- end }} +{{- if .Values.backupRestoreTLS }} + - name: ca-etcdbr secret: - secretName: {{ .Release.Name }}-etcd-ca + secretName: {{ .Release.Name }}-etcdbr-ca + - name: etcdbr-tls + secret: + secretName: {{ .Release.Name }}-etcdbr-tls {{- end }} {{- if and .Values.backup.storageProvider (not (eq .Values.backup.storageProvider "Local")) }} - name: etcd-backup diff --git a/chart/etcd-backup-restore/templates/etcd-tls-secret.yaml b/chart/etcd-backup-restore/templates/etcd-tls-secret.yaml index c4c6b2c6e..b5bfc3239 100644 --- a/chart/etcd-backup-restore/templates/etcd-tls-secret.yaml +++ b/chart/etcd-backup-restore/templates/etcd-tls-secret.yaml @@ -1,4 +1,4 @@ -{{- if .Values.tls }} +{{- if .Values.etcdTLS }} apiVersion: v1 kind: Secret metadata: @@ -10,6 +10,6 @@ metadata: app.kubernetes.io/instance: {{ .Release.Name }} type: kubernetes.io/tls data: - tls.crt: {{ .Values.tls.crt | b64enc }} - tls.key: {{ .Values.tls.key | b64enc }} + tls.crt: {{ .Values.etcdTLS.crt | b64enc }} + tls.key: {{ .Values.etcdTLS.key | b64enc }} {{- end }} \ No newline at end of file diff --git a/chart/etcd-backup-restore/templates/etcdbr-ca-secret.yaml b/chart/etcd-backup-restore/templates/etcdbr-ca-secret.yaml new file mode 100644 index 000000000..ca456fa05 --- /dev/null +++ b/chart/etcd-backup-restore/templates/etcdbr-ca-secret.yaml @@ -0,0 +1,14 @@ +{{- if .Values.backupRestoreTLS }} +apiVersion: v1 +kind: Secret +metadata: + name: {{ .Release.Name }}-etcdbr-ca + namespace: {{ .Release.Namespace }} + labels: + app.kubernetes.io/name: etcd + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/instance: {{ .Release.Name }} +type: Opaque +data: + ca.crt: {{ .Values.backupRestoreTLS.caBundle | b64enc }} +{{- end }} \ No newline at end of file diff --git a/chart/etcd-backup-restore/templates/etcdbr-tls-secret.yaml b/chart/etcd-backup-restore/templates/etcdbr-tls-secret.yaml new file mode 100644 index 000000000..ee8ddf419 --- /dev/null +++ b/chart/etcd-backup-restore/templates/etcdbr-tls-secret.yaml @@ -0,0 +1,15 @@ +{{- if .Values.backupRestoreTLS }} +apiVersion: v1 +kind: Secret +metadata: + name: {{ .Release.Name }}-etcdbr-tls + namespace: {{ .Release.Namespace }} + labels: + app.kubernetes.io/name: etcd + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/instance: {{ .Release.Name }} +type: kubernetes.io/tls +data: + tls.crt: {{ .Values.backupRestoreTLS.crt | b64enc }} + tls.key: {{ .Values.backupRestoreTLS.key | b64enc }} +{{- end }} \ No newline at end of file diff --git a/chart/etcd-backup-restore/values.yaml b/chart/etcd-backup-restore/values.yaml index db4461895..09426bfd1 100644 --- a/chart/etcd-backup-restore/values.yaml +++ b/chart/etcd-backup-restore/values.yaml @@ -2,12 +2,12 @@ images: # etcd image to use etcd: repository: quay.io/coreos/etcd - tag: v3.3.12 + tag: v3.3.13 pullPolicy: IfNotPresent # etcd-backup-restore image to use etcdBackupRestore: repository: eu.gcr.io/gardener-project/gardener/etcdbrctl - tag: 0.7.0 + tag: 0.8.0 pullPolicy: IfNotPresent resources: @@ -31,12 +31,7 @@ servicePorts: server: 2380 backupRestore: 8080 -etcdAuth: {} - #username: username - #password: password - backup: - # schedule is cron standard schedule to take full snapshots. schedule: "0 */1 * * *" @@ -90,23 +85,201 @@ backup: # accessKeySecret: secret-access-key-with-object-storage-privileges # accessKeyID: access-key-id-with-object-storage-privileges -metrics: basic +# etcdAuth field contains the pre-created username-password pair +# for etcd. Comment this whole section if you dont want to use +# password-based authentication for the etcd. +etcdAuth: {} + # username: username + # password: password + +etcdTLS: + caBundle: | + -----BEGIN CERTIFICATE----- + MIICxDCCAaygAwIBAgIJAP0c7UGkoNMsMA0GCSqGSIb3DQEBCwUAMA8xDTALBgNV + BAMM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mX3wg/djhQ== + -----END CERTIFICATE----- + key: | + -----BEGIN RSA PRIVATE KEY----- + MIIEowIBAAKCAQEA+z/sd+bPj20x9RyWKbqPtI2QZFBPA4AH0udag+jSKon6A3Kq + IqRYac5K/U+pKMfvMbD3Ozcf5BxiZyRpeELR3wmZvdrMa98DAtYcQuaEELEFv7GH + r6CfgxbVVXs4cqXcaxGMVHrwidP0TxTyvHxfTJlczkoKNmJS0e0CfQFUpUSwjs0Y + 0aka0wmbSKahxVKNtsFGvStoZyYvfgoBFmxAHYyMWr52Xdp37139to05p64ljX58 + WBKznhTHcHHm4nHByLdQwhrikkVYRvnNIQQ90lqMgqbOx3mxgDGMNJWpJdk4tMsO + zzGw32klvkCp5+u1Y68wkaJQ7x7+07ds/LQGfQIDAQABAoIBAHaVkTJ2SfjT/QRH + XciMOU9qkYAHN4PbZdXxRBOGS8uwG8SM1ihLkT8/Er3EX37T/t1hPQ9B0VeE3hz4 + Xp9YSl4O1fV504oGVBF+pRAeZK7MHn5/eB84nJDusfoKknXqOsJ+IdGtxOIInALH + TFoSCZjJubfT0kYg2h4i003U1vK5LYSFwmdr3X5p6XXPNntyBQ1RBzjpyA6Qpe1G + hcSdUqxJXpZKS6DB/oZ+O4IQyAlP5uXwtz+rl6AiD+NIE8osVKJrw8XdiwCkiitx + 8vYJBi9pHb0hSA0g1k6+vei/tyM8UcQ+JJm5MHFegvMihv3gInS32aKhy96zTwb4 + XhODjDECgYEA/hZ+3UsVIVRzEZdoyqBGa7njOVhC3xFPkUzHrcVcc8IxfvK0WpN9 + SoHf67XJny11tOi9D+hocRdSmMLdDxQMTiqhzyREGuPkIDOJXZBihnCxvNQam5+i + cGP3dnuqxq7XLatqXaFpubk1vRDku/LRMaiIluXWomTZnz3sWKPdO3cCgYEA/SP1 + 2fSy/Hz4h4J97dUpQszZHYALyP48rRtXBh+LWf/SAev8+6/Eb/9hHr7y/gGnLJCQ + lYQiK+sE6+1w5hbDNunblnWKGhge2oWM/ELE562KpKj2Br32ztXvwk1hItzPWeu/ + 5Q4msZMf39dS6EsNEj2QnZ+Et6PNOLN+TPUUoqsCgYANrJpBQJQvigLzVGmwVfXU + QFnJMUXQCXd1w2MPqAp0tGPDiD5KjZt1kg3B+rOSHHk0Nj5Oh9xvEalBTWNmN1b+ + Me8pXbNImzEgxoVDAs06nQADwIp6C5pLYCXmO3uSW8B61bnQtiohc6U/upQExWma + uY44SMBHVxQbLNL2ZkM2uwKBgA+cyir5Jpjf9EwXRkEG5paSH8nr/c4VsBRVHVbp + VyTj3EX2EhJL0ue9bnYA/OehnnfnKqOuFJV010bdzBrEyKF4ZuyuryfQ2QZNOlbM + n2xSjbx+Fz5vNOuo0jK/pwAJclhva9RqvQQyuMKLezeMeW/okCTIk9zno16d42pH + q1AlAoGBAJTGwGr4a552zwAFLaLpIyxExFfwCotp56iFpnptO/lBEnXgYS2MAphz + I/3egoVJocgXHunhPuxM2aL2mwv8dQFVeizBc4N49RMQOkF4zLr6wADc5gMyvWKD + bXWo/568mFNORqDSugSA72UfGKs7BQNXhb1zmwRJPkiISEO98RcY + -----END RSA PRIVATE KEY----- +# clientCrt: | +# -----BEGIN CERTIFICATE----- +# MIIC3TCCAcWgAwIBAgIJAOCUEyg0VlWlMA0GCSqGSIb3DQEBCwUAMA8xDTALBgNV +# BAMMBGV0Y2QwHhcNMTkxMDE2MDM1MzEwWhcNMjkxMDE2MDM1MzEwWjAWMRQwEgYD +# VQQDDAtldGNkLWNsaWVudDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB +# ALMJuHyGjxzHG6bFL+78kcJkQFQWtEdEuAAFLxbkFAY8968+jclkP93Yio1DXi5E +# obIGDEfpselv+7jk61AoqKOELMzvfzBnem6lWusOI/zdvbCv341G8iT+HeD7ul1O +# u/5ggVM/U6+8ZDDKgC4TtBtICsFKXtGgY3P8m2Kt4lmYOV8r1EJOD7yooDLlT1+w +# ywkNWtXSRHgPo842oKRKRus7DEtYe9WLRbK/ThtRB17jVO0FIsULv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qjKXC4wZYrsDpgQfR0 +# aKuPHk9cgoqZeh0tyQeHXYGTmpXuS5Eaz2FteMkvPDNxiNn1+a1iZAIpoxsdzWQi +# 2OcAnF1B6UWMmn4l5x+ImLrQ2Q7y+PTibLqKmRjDBKBXe8D3O2Iflg== +# -----END RSA PRIVATE KEY----- -# tls field contains the pre-created secrets for etcd. Uncomment the -# whole tls section if you dont want to use tls for the etcd. -tls: {} - # caBundle: | - # -----BEGIN CERTIFICATE----- - # ... - # -----END CERTIFICATE----- - # crt: | - # -----BEGIN CERTIFICATE----- - # ... - # -----END CERTIFICATE----- - # key: | - # -----BEGIN RSA PRIVATE KEY----- - # ... - # -----END RSA PRIVATE KEY----- +# backupRestoreTLS field contains the pre-created secrets for backup-restore server. +# Comment this whole section if you dont want to use tls for the backup-restore server. +backupRestoreTLS: + caBundle: | + -----BEGIN CERTIFICATE----- + MIICyDCCAbCgAwIBAgIJAJXpfajKHqSTMA0GCSqGSIb3DQEBCwUAMBExDzANBgNV + BAMMBmV0Y2RicjAeFw0xOTEwMTYwNTI2MTdaFw0yOTEwMTYwNTI2MTdaMBExDzAN + BgNVBAMMBmV0Y2RicjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALxk + 1yYGtFOIME29mck7Ttg9istd3kksK0HcP6C9boEeWTb+ruQjoc980cFl0rGEWsuq + aBFPGg3OFnWgl+5+F7Dt62FXDGpXhqceztVP9vPMxgHZiocjt7RSQAUhin381dTD + Nz2leq5fZ9QrjePIDV8PdoIHl7DVnrrnnLBM6XwDCIfOHTiwpTtsdKPMOk7yLOdA + 049u/1rOIZITXJcMwtftqLqS7UpZRFZQVvi2X8lC1pK7N7kfgtEYjhJ0xdnsDric + BZe8ujtwWhRUP7FJRkz9FsEYBjykzBF1IZuSm7kq3rAA9Ucs1pRB1FK8359fKqu+ + ZfaSOWSp9PEnPnxuvGUCAwEAAaMjMCEwDgYDVR0PAQH/BAQDAgGmMA8GA1UdEwEB + /wQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBACmP7cjWVeucSd/kfS58zvJU25lT + MhFrcGyncgTbqxM5eZzVQlDRFc5SgGUYN1OT+SG+SOJBIO5IE9AlB7we3Sj7/L+W + WNfDFYDh1hkkTsVi6qWOMAWBuGca2FiHOOnFLX6OuK+s1Ly/w7oDFRY0Eu0i1B7Y + fq/kH+8uhY4h+/c/ugq6PyD0q4RNw4nG+x8QDD2FFQGNl0wDNgXzytRAJoCJvtaO + a87eo8wBXS8RAT7GqMnXz7dWGUXZBgvBWRwTjXKb1XziOFosBR/pT6V1qOMQyoWf + FDjeX+fpnfXXf9Ile6vUiTKiD7v2SCUnvM7Z6u/jlYtuI2ZW3qynLB/Gflk= + -----END CERTIFICATE----- + crt: | + -----BEGIN CERTIFICATE----- + MIIDgDCCAmigAwIBAgIJALWjKCeVMRP7MA0GCSqGSIb3DQEBCwUAMBExDzANBgNV + BAMMBmV0Y2RicjAeFw0xOTEwMTYwNjAzMTZaFw0yOTEwMTYwNjAzMTZaMBgxFjAU + BgNVBAMMDWV0Y2Rici1zZXJ2ZXIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK + AoIBAQDH7WBlS61BUUtnqZqjR3H4O0UUX6b/LhtWI0PMTgt14GBMefadNGUofSof + ewDCRxUIgpvcD76v64iS2TATcL7jxjtXoN/gQLarivJQTl80BUfzLSElXf8UrplX + xOZAqHtebM45q495wmSa2kCceYKk1lDw/Pxt2aLh6N5RCchO7rC9NXX4jNltpsdS + RsquY9DhK2A9NqIQ0pAJ0HEEMKupA/khv/TCzQYKki2SHDP9RcpuuLdffVuCYccc + xDzBGuyoNLbbF2pcvnU1UD0abgd2j07J6hbbuaZd4h9gGwrpyXI7XQeVw4wlRwXr + /M9zXNR8HCnW27L732jqiavGCS7JAgMBAAGjgdMwgdAwDgYDVR0PAQH/BAQDAgWg + MB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjAMBgNVHRMBAf8EAjAAMIGQ + BgNVHREEgYgwgYWCCWxvY2FsaG9zdIILbWFpbi1ldGNkLTCCEG1haW4tZXRjZC1j + bGllbnSCFW1haW4tZXRjZC1jbGllbnQudGVzdIIZbWFpbi1ldGNkLWNsaWVudC50 + ZXN0LnN2Y4InbWFpbi1ldGNkLWNsaWVudC50ZXN0LnN2Yy5jbHVzdGVyLmxvY2Fs + MA0GCSqGSIb3DQEBCwUAA4IBAQB5PnZ90l9O4jxZ6J/t7T9OWfYvF7pPByy473ew + /RBGy1R4S10VgNKwWO4MgeHPGCip5M8kElhetpeYpsYN7ejbdTdKv8AzyS8xXRE3 + ngyKwqFts/wnErc4VX080oZxQhV42EKNJiL2zmSr4hd93xInX4xZythNmn2zeqvQ + fgY3JDwKuLDaK8QYQ0SbRA7sS/HYk3urY7Li19oPpr0P5B4kyOQr+F0L5IlQ7qRS + lulQiJSqB10nIwK/nAFo04XFxC5qo8GHoAgTAnhNZ1fZ1E/tF9CPGhAA91riNmbd + shJYGh7RtyZxSEAzr6DnEJ30Sl0FYQwZoYwe/uEPmvFZlsbN + -----END CERTIFICATE----- + key: | + -----BEGIN RSA PRIVATE KEY----- + MIIEpAIBAAKCAQEAx+1gZUutQVFLZ6mao0dx+DtFFF+m/y4bViNDzE4LdeBgTHn2 + nTRlKH0qH3sAwkcVCIKb3A++r+uIktkwE3C+48Y7V6Df4EC2q4ryUE5fNAVH8y0h + JV3/FK6ZV8TmQKh7XmzOOauPecJkmtpAnHmCpNZQ8Pz8bdmi4ejeUQnITu6wvTV1 + +IzZbabHUkbKrmPQ4StgPTaiENKQCdBxBDCrqQP5Ib/0ws0GCpItkhwz/UXKbri3 + X31bgmHHHMQ8wRrsqDS22xdqXL51NVA9Gm4Hdo9OyeoW27mmXeIfYBsK6clyO10H + lcOMJUcF6/zPc1zUfBwp1tuy+99o6omrxgkuyQIDAQABAoIBACJsSLCoOwiICseq + eCms336yFc7QOVyuf55xK/c9aNO+8lW4mjGvF8vE4T/SWesZehGhC1z0iQyZLUa7 + hn+SZgup0g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RSM+nOhXZeR+9u4fbCeEkU2l+ + U2PdNe+wd7tQDeCL5aCFQCsvA554sHsXwbfbG5Wx5yg+29JgIsEFTw== + -----END RSA PRIVATE KEY----- -# podAnnotations will be placed to the resulting etcd pod +# podAnnotations that will be passed to the resulting etcd pod podAnnotations: {} diff --git a/cmd/server.go b/cmd/server.go index 4e938f26b..abf97f4e8 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -18,6 +18,7 @@ import ( "context" "fmt" "net/http" + "os" "path" "sync/atomic" "time" @@ -102,18 +103,32 @@ func NewServerCommand(ctx context.Context) *cobra.Command { // startHTTPServer creates and starts the HTTP handler // with status 503 (Service Unavailable) -func startHTTPServer(initializer initializer.Initializer, ssr *snapshotter.Snapshotter) *server.HTTPHandler { +func startHTTPServer(initializer initializer.Initializer, ssr *snapshotter.Snapshotter) (*server.HTTPHandler, error) { + enableTLS := serverTLSCertFile != "" && serverTLSKeyFile != "" + if enableTLS { + // Check for existence of server cert and key files before proceeding + if _, err := os.Stat(serverTLSCertFile); err != nil { + return nil, fmt.Errorf("TLS enabled but server TLS cert file is invalid. Will not start HTTPS server") + } + if _, err := os.Stat(serverTLSKeyFile); err != nil { + return nil, fmt.Errorf("TLS enabled but server TLS key file is invalid. Will not start HTTPS server") + } + } + // Start http handler with Error state and wait till snapshotter is up // and running before setting the status to OK. handler := &server.HTTPHandler{ - Port: port, - Initializer: initializer, - Snapshotter: ssr, - Logger: logger, - StopCh: make(chan struct{}), - EnableProfiling: enableProfiling, - ReqCh: make(chan struct{}), - AckCh: make(chan struct{}), + Port: port, + Initializer: initializer, + Snapshotter: ssr, + Logger: logger, + StopCh: make(chan struct{}), + EnableProfiling: enableProfiling, + ReqCh: make(chan struct{}), + AckCh: make(chan struct{}), + EnableTLS: enableTLS, + ServerTLSCertFile: serverTLSCertFile, + ServerTLSKeyFile: serverTLSKeyFile, } handler.SetStatus(http.StatusServiceUnavailable) logger.Info("Registering the http request handlers...") @@ -121,7 +136,7 @@ func startHTTPServer(initializer initializer.Initializer, ssr *snapshotter.Snaps logger.Info("Starting the http server...") go handler.Start() - return handler + return handler, nil } // runServerWithoutSnapshotter runs the etcd-backup-restore @@ -164,7 +179,10 @@ func runServerWithSnapshotter(ctx context.Context, tlsConfig *etcdutil.TLSConfig snapshotterConfig, ) - handler := startHTTPServer(etcdInitializer, ssr) + handler, err := startHTTPServer(etcdInitializer, ssr) + if err != nil { + logger.Fatalf("Failed to start HTTP server: %v", err) + } defer handler.Stop() ssrStopCh := make(chan struct{}) @@ -274,7 +292,10 @@ func runServerWithoutSnapshotter(ctx context.Context, tlsConfig *etcdutil.TLSCon // If no storage provider is given, snapshotter will be nil, in which // case the status is set to OK as soon as etcd probe is successful - handler := startHTTPServer(etcdInitializer, nil) + handler, err := startHTTPServer(etcdInitializer, nil) + if err != nil { + logger.Fatalf("Failed to start HTTP server: %v", err) + } defer handler.Stop() // start defragmentation without trigerring full snapshot @@ -311,12 +332,6 @@ func runEtcdProbeLoopWithoutSnapshotter(ctx context.Context, tlsConfig *etcdutil } } -// initializeServerFlags adds the flags to -func initializeServerFlags(serverCmd *cobra.Command) { - serverCmd.Flags().IntVarP(&port, "server-port", "p", defaultServerPort, "port on which server should listen") - serverCmd.Flags().BoolVar(&enableProfiling, "enable-profiling", false, "enable profiling") -} - // ProbeEtcd will make the snapshotter probe for etcd endpoint to be available // before it starts taking regular snapshots. func ProbeEtcd(tlsConfig *etcdutil.TLSConfig) error { @@ -368,3 +383,11 @@ func handleSsrStopRequest(ctx context.Context, handler *server.HTTPHandler, ssr } } } + +// initializeServerFlags adds the flags to +func initializeServerFlags(serverCmd *cobra.Command) { + serverCmd.Flags().IntVarP(&port, "server-port", "p", defaultServerPort, "port on which server should listen") + serverCmd.Flags().BoolVar(&enableProfiling, "enable-profiling", false, "enable profiling") + serverCmd.Flags().StringVar(&serverTLSCertFile, "server-cert", "", "TLS certificate file for backup-restore server") + serverCmd.Flags().StringVar(&serverTLSKeyFile, "server-key", "", "TLS key file for backup-restore server") +} diff --git a/cmd/types.go b/cmd/types.go index f55461352..b9150a53e 100644 --- a/cmd/types.go +++ b/cmd/types.go @@ -49,8 +49,10 @@ var ( defragmentationSchedule string //server flags - port int - enableProfiling bool + port int + enableProfiling bool + serverTLSCertFile string + serverTLSKeyFile string //restore flags restoreCluster string diff --git a/doc/usage/generating_ssl_certificates.md b/doc/usage/generating_ssl_certificates.md new file mode 100644 index 000000000..afe11bf19 --- /dev/null +++ b/doc/usage/generating_ssl_certificates.md @@ -0,0 +1,140 @@ +# Generating certificates + +If you wish to enable TLS authentication for either etcd or etcdbr server or both, please follow this guide. The SSL certificate configurations given here are meant to facilitate smooth deployment of the etcd setup via the provided [helm chart](../../chart/etcd-backup-restore). + +## Certificates structure + +While deploying the etcd setup via the provided helm chart, TLS can be enabled for the etcd server and/or etcd-backup-restore server by adding the certificate data to the `values.yaml` file as necessary. This data is converted into the respective secrets and mounted onto the pod's containers according to the following directory structure: + +- `etcd` container + +```console +/ +└── var + ├── etcd Contains the CA and server TLS certs for etcd server + | └── ssl + | ├── ca + | | └── ca.crt + | └── tls + | ├── tls.crt + | └── tls.key + └── etcdbr Contains the CA and server TLS certs for etcd backup-restore server + └── ssl + ├── ca + | └── ca.crt + └── tls + ├── tls.crt + └── tls.key +``` + +
+ +- `backup-restore` container + +```console +/ +└── var + ├── etcd Contains the CA and server certs for etcd server + | └── ssl + | ├── ca + | | └── ca.crt + | └── tls + | ├── tls.crt + | └── tls.key + └── etcdbr Contains the CA cert for etcd backup-restore server + └── ssl + └── ca + └── ca.crt +``` + +## Generating the certificates + +### Installing openssl + +```console +# For Mac users +brew install openssl + +# For other flavours of Unix +apk install openssl + +mkdir openssl && cd openssl +``` + +### Generating certs for etcd server authentication + +#### Generating CA cert bundle + +```console +openssl genrsa -out ca.key 2048 +openssl req -new -key ca.key -subj "/CN=etcd" -out ca.csr + +cat > ca.csr.conf < server.csr.conf <