Skip to content
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

Do not allow bootstrap tokens with a trailing newline #79

Merged
merged 1 commit into from
Jan 31, 2024

Conversation

olavst-spk
Copy link
Contributor

Pull Request (PR) description

The regex used to validate the bootstrap token allows strings that end with a newline.

This PR makes the regex more strict by using \z instead of $ to match the end of the string. (\z does not allow trailing newline characters).

This Pull Request (PR) fixes the following issues

When the bootstrap token contains a newline, worker nodes fail to join the cluster. The kubelet process emit strange errors like:

kubelet[10895]: E0130 14:00:33.287321   10895 certificate_manager.go:562] kubernetes.io/kube-apiserver-client-kubelet: Failed while requesting a signed certificate from the control plane: cannot create certificate signing request: Post "https://kubernetes.vagrant.local:6443/apis/certificates.k8s.io/v1/certificatesigningrequests": net/http: invalid header field value for "Authorization"
kubelet[10895]: E0130 14:00:33.616337   10895 kubelet_node_status.go:96] "Unable to register node with API server" err="nodes is forbidden: User \"system:anonymous\" cannot create resource \"nodes\" in API group \"\" at the cluster scope
kubelet[10895]: E0130 14:00:45.972707   10895 controller.go:145] "Failed to ensure lease exists, will retry" err="leases.coordination.k8s.io \"vagrant-k8s-k8s-worker1\" is forbidden: User \"system:anonymous\" cannot get resource \"leases\" in API group \"coordination.k8s.io\" in the namespace \"kube-node-lease\"" interval="7s"
kubelet[10895]: W0130 14:00:50.253971   10895 reflector.go:539] vendor/k8s.io/client-go/informers/factory.go:159: failed to list *v1.Node: nodes "vagrant-k8s-k8s-worker1" is forbidden: User "system:anonymous" cannot list resource "nodes" in API group "" at the cluster scope

@tuxmea tuxmea requested review from ananace and rwaffen January 30, 2024 16:32
@tuxmea tuxmea merged commit dd60b3b into voxpupuli:master Jan 31, 2024
3 checks passed
@@ -1,2 +1,2 @@
# @summary A Kubernetes bootstrap token, must be 16-characters lowercase alphanumerical
type K8s::Bootstrap_token = Pattern[/^[a-z0-9]{16}$/]
type K8s::Bootstrap_token = Pattern[/^[a-z0-9]{16}\z/]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency, would it make sens to replace ^ with \A?

Copy link
Contributor Author

@olavst-spk olavst-spk Jan 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tested with a leading newline in the token and I got the same errors. It is probably a less common mistake to make, but it would be good to fix it too. I can make a follow up PR.

@bastelfreak bastelfreak added the bug Something isn't working label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants