-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Optimize CA cert hash calculation with community.crypto #11758
Optimize CA cert hash calculation with community.crypto #11758
Conversation
- name: Extract public key from CA certificate | ||
community.crypto.openssl_publickey_info: | ||
path: "{{ kube_cert_dir }}/ca.crt" | ||
type: x509 | ||
register: publickey_info |
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 problem with that is that community.crypto module requires to install python cryptography on the managed host, which is not that easy to do -> see #11158
An alternative to that, I think, is to fetch either the public key or the whole cert (but not the private key, ofc) and use the community.crypto filters ( for instance the x509_info filter ).
Since filter runs on the ansible control node, this only requires to install cryptography on the control node, which is much easier.
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 issue seems more complex than I expected. I'll update the PR later.
thanks for your suggestions.
b5d703b
to
2a53439
Compare
2a53439
to
f691d63
Compare
/ok-to-test |
bc0ccc1
to
33503a7
Compare
33503a7
to
4e9a111
Compare
Great work 🎉 |
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.
Some nitpicks, otherwise that's pretty good 👍
|
||
- name: Calculate kubeadm CA cert hash | ||
set_fact: | ||
kubeadm_ca_hash: "{{ (ca_cert_content.content | b64decode | community.crypto.x509_certificate_info).public_key_fingerprints.sha256 }}" | ||
when: ca_cert_content.content | length > 0 | ||
delegate_to: localhost | ||
run_once: true |
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 is pretty good, great work !
Just a thought though: do we need to use set fact ? I think it should be possible to simply have that expression directly in the jinja template in kubeadm-client.conf.j2, wdyt ? (adjusting the conditionals).
The only downside I could see is that it would compute it for each host, but I don't think the difference is noticeable.
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.
directly placing the expression in the kubeadm-client.conf.j2
template is indeed more concise.
# Supported asymmetric encryption algorithm types for the cluster's keys and certificates. | ||
# can be one of RSA-2048(default), RSA-3072, RSA-4096, ECDSA-P256 | ||
# ref: https://kubernetes.io/docs/reference/config-api/kubeadm-config.v1beta4/#kubeadm-k8s-io-v1beta4-ClusterConfiguration | ||
kube_asymmetric_encryption_algorithm: "RSA-2048" | ||
|
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.
You should probably mention in the commit message why we can do that (== since the switch makes it used only in one role), otherwise it can appear a bit random to the uninitiated ^.
Signed-off-by: bo.jiang <bo.jiang@daocloud.io>
4e9a111
to
00e4964
Compare
Thanks for the great work ! First step to replace our usage of dubious openssl pipelines with community.crypto o/ /approve I don't think we need a release-note though, this should not change anything for the users. /release-note-edit |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ErikJiang, VannTen The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
…igs#11758) Signed-off-by: bo.jiang <bo.jiang@daocloud.io>
What type of PR is this?
/kind feature
What this PR does / why we need it:
this PR optimizes the CA certificate hash calculation by using the
community.crypto
module.additionally, I've moved the default value of
kube_asymmetric_encryption_algorithm
back to theKubernetes/control-plane
role, as this variable is currently only used within that role.Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?: