-
Notifications
You must be signed in to change notification settings - Fork 39.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Centos provider: generate SSL certificates for etcd cluster. #42994
Centos provider: generate SSL certificates for etcd cluster. #42994
Conversation
Hi @Shawyeok. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
cluster/centos/util.sh
Outdated
sudo mkdir -p /opt/kubernetes/bin; \ | ||
sudo mkdir -p /opt/kubernetes/cfg" | ||
} | ||
|
||
function ensure-etcd-cert() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems a lot like https://github.com/kubernetes/kubernetes/blob/master/cluster/gce/util.sh#L740
I wonder if @jszczepkowski would be interest in you moving that stuff up higher in the tree and making it reusable by more providers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's a good suggestion. Download the cfssl
binaries is duplicate at least https://github.com/kubernetes/kubernetes/blob/master/cluster/common.sh#L908.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It sound reasonable to move this up.
0306c9a
to
66af4df
Compare
@@ -18,10 +18,16 @@ | |||
ETCD_SERVERS=${1:-"http://8.8.8.18:2379"} | |||
FLANNEL_NET=${2:-"172.16.0.0/16"} | |||
|
|||
CA_FILE="/srv/kubernetes/etcd/ca.pem" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need it on node? Etcd peers are only on masters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it's not a peer certfile for etcd(A peer certfile just like peer-*.pem). Because flannel needs to access the etcd cluster, so...
cluster/centos/util.sh
Outdated
echo "Generate CA certificates ..." | ||
./cfssl gencert -initca ca-csr.json | ./cfssljson -bare ca - | ||
|
||
echo "Generate client certificates..." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need client & server certs? Aren't peer certs enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suppose a pod running in a k8s cluster(peer certs only), the pod still can access the etcd service, so I think it's necessary.
74045d4
to
2375a1d
Compare
# $2 (the ip of etcd member) | ||
# $3 (the type of etcd certificates, must be one of client, server, peer) | ||
# $4 (the prefix of the certificate filename, default is $3) | ||
function generate-etcd-cert() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've extracted generate-etcd-cert
method to the cluster/common.sh
, feel free to review, thanks a lot. @jszczepkowski
"size": 256 | ||
}, | ||
"names": [ | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this section needed? If so, shouldn't we fill it with some reasonable values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is. cfssl docs
I've changed the O (Organization)
to kubernetes.io
and deleted another unnecessary fields.
a01523e
to
13e4a45
Compare
cluster/centos/config-default.sh
Outdated
@@ -117,7 +120,7 @@ export FLANNEL_NET=${FLANNEL_NET:-"172.16.0.0/16"} | |||
|
|||
# Admission Controllers to invoke prior to persisting objects in cluster | |||
# If we included ResourceQuota, we should keep it at the end of the list to prevent incrementing quota usage prematurely. | |||
export ADMISSION_CONTROL=NamespaceLifecycle,LimitRanger,ServiceAccount,ResourceQuota,DefaultTolerationSeconds | |||
export ADMISSION_CONTROL=${ADMISSION_CONTROL:-"NamespaceLifecycle,LimitRanger,ServiceAccount,ResourceQuota,DefaultTolerationSeconds"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Support defined ADMISSION_CONTROL
outside by user, DefaultTolerationSeconds
is not exists before cd427fa4. /cc @kevin-wangzefeng
@@ -742,44 +742,14 @@ function create-etcd-certs { | |||
local ca_cert=${2:-} | |||
local ca_key=${3:-} | |||
|
|||
download-cfssl | |||
GEN_ETCD_CA_CERT="${ca_cert}" GEN_ETCD_CA_KEY="${ca_key}" \ | |||
generate-etcd-cert "${KUBE_TEMP}/cfssl" "${host}" "peer" "peer" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Who creates ${KUBE_TEMP}/cfssl
directory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The directory ${KUBE_TEMP}/cfssl
will create in download-cfssl
function, but it's not exists before call download in generate-etcd-cert
function. It maybe cause error: the file or directory not exists
. I'll fix it.
cluster/centos/util.sh
Outdated
local cert_dir="${ROOT}/etcd-cert" | ||
|
||
mkdir -p "${cert_dir}" | ||
pushd "${cert_dir}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be unnecessary: function generate-etcd-cert
does pushd
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I need to check client.pem
or client-key.pem
exists in the ${cert_dir}
directory. Use generate-etcd-cert "${cert_dir}"
instead of generate-etcd-cert .
seem could be better.
cluster/centos/util.sh
Outdated
local master_ip="$2" | ||
local cert_dir="${ROOT}/etcd-cert" | ||
|
||
mkdir -p "${cert_dir}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't better to create ${cert_dir}
inside generate-etcd-cert
function (if the dir does not exist). Currently, generate-etcd-cert
function has undocumented assumption that the directory already exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is.
13e4a45
to
92997ee
Compare
local master_ip="$2" | ||
local cert_dir="${ROOT}/etcd-cert" | ||
|
||
if [[ ! -r "${cert_dir}/client.pem" || ! -r "${cert_dir}/client-key.pem" ]]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check the client.pem
and client-key.pem
in the directory exists without cd
.
local GEN_ETCD_CA_CERT=${GEN_ETCD_CA_CERT:-} | ||
local GEN_ETCD_CA_KEY=${GEN_ETCD_CA_KEY:-} | ||
|
||
mkdir -p "${cert_dir}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create ${cert_dir}
directory inside generate-etcd-cert
function.
# | ||
function download-cfssl { | ||
mkdir -p "${KUBE_TEMP}/cfssl" | ||
pushd "${KUBE_TEMP}/cfssl" | ||
mkdir -p "$1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add a local variable with a meaningful name for "$1" (like here)?
@k8s-bot ok to test |
92997ee
to
ca4ea4e
Compare
cluster/common.sh
Outdated
local cfssl_dir="${1}" | ||
|
||
mkdir -p "${cfssl_dir}" | ||
pushd "${cfssl_dir}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use ${cfssl_dir}
instead of $1
.
cluster/centos/util.sh
Outdated
if [[ -f $service_file ]]; then \ | ||
sudo systemctl stop $service_name; \ | ||
sudo systemctl disable $service_name; \ | ||
sudo rm -f $service_file; \ | ||
fi" | ||
done | ||
kube-ssh "${1}" "sudo rm -rf /opt/kubernetes" | ||
kube-ssh "${1}" "sudo rm -rf ${KUBE_TEMP}" | ||
kube-ssh "${1}" "sudo rm -rf /var/lib/etcd" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use ${master}
instead of $1
.
cluster/centos/util.sh
Outdated
if [[ -f $service_file ]]; then \ | ||
sudo systemctl stop $service_name; \ | ||
sudo systemctl disable $service_name; \ | ||
sudo rm -f $service_file; \ | ||
fi" | ||
done | ||
kube-ssh "$1" "sudo rm -rf /run/flannel" | ||
kube-ssh "$1" "sudo rm -rf /opt/kubernetes" | ||
kube-ssh "$1" "sudo rm -rf ${KUBE_TEMP}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use ${node}
instead of $1
.
/lgtm |
FYI: I did manual tests of this patch for GCE and it is passing. |
@zmerlynn |
/approve |
ca4ea4e
to
92997ee
Compare
@k8s-bot cvm gce e2e test this |
It's strange. Why tests The diff between two commits are:
Full PR test history: #42994 /cc @k8s-oncall @kubernetes/test-infra-maintainers |
Making download-cfssl reusable. Extract generate-etcd-cert method up to common.sh.
92997ee
to
c692b55
Compare
This PR needs LGTM again after rebase, please. @jszczepkowski @zmerlynn |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Shawyeok, eparis, jszczepkowski
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
Automatic merge from submit-queue |
What this PR does / why we need it:
Support secure etcd cluster for centos provider, generate SSL certificates for etcd in default. Running it w/o SSL is exposing cluster data to everyone and is not recommended. #39462
/cc @jszczepkowski @zmerlynn
Release note: