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

kubeadm: improve the kubeconfig file validation phase #79165

Merged

Conversation

@neolit123
Copy link
Member

commented Jun 19, 2019

What this PR does / why we need it:
When a kubeconfig file is read from disk it may lack the
propper mapping between contexts and clusters.

In such a case the kubeconfig phase backend will panic,
without throwing a sensible error.

Add nil checks for a couple of map operations in
validateKubeConfig().

Which issue(s) this PR fixes:

Fixes #79069
xref kubernetes/kubeadm#1382

Special notes for your reviewer:
NONE

Does this PR introduce a user-facing change?:

kubeadm: fix a potential panic if kubeadm discovers an invalid, existing kubeconfig file

/priority backlog
/assign @fabriziopandini @rosti
/kind bug
@kubernetes/sig-cluster-lifecycle-pr-reviews
/hold

@k8s-ci-robot

This comment has been minimized.

Copy link
Contributor

commented Jun 19, 2019

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: neolit123

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Member

left a comment

Thanks @neolit123

@@ -224,7 +224,13 @@ func validateKubeConfig(outDir, filename string, config *clientcmdapi.Config) er
expectedCtx := config.CurrentContext
expectedCluster := config.Contexts[expectedCtx].Cluster
currentCtx := currentConfig.CurrentContext
if config.Contexts[currentCtx] == nil {

This comment has been minimized.

Copy link
@yagonobre

yagonobre Jun 19, 2019

Member

Should it be currentConfig? Also, should we check the config.Contexts[expectedCtx].Cluster above?

This comment has been minimized.

Copy link
@neolit123

neolit123 Jun 19, 2019

Author Member

Should it be currentConfig?

yeah already sent a change.

Also, should we check the config.Contexts[expectedCtx].Cluster above

its a file we just generated, so doesn't seem we need to.

When a kubeconfig file is read from disk it may lack the
propper mapping between contexts and clusters.

In such a case the kubeconfig phase backend will panic,
without throwing a sensible error.

Add nil checks for a couple of map operations in
validateKubeConfig().
@neolit123 neolit123 force-pushed the neolit123:kubeadm-1.16-fix-panic-kubeconfig branch from 12866fc to 14408be Jun 19, 2019
@rosti
rosti approved these changes Jun 19, 2019
Copy link
Member

left a comment

Thanks @neolit123 !
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm label Jun 19, 2019
Copy link
Member

left a comment

/lgtm

@neolit123

This comment has been minimized.

Copy link
Member Author

commented Jun 19, 2019

/hold cancel
thanks

@k8s-ci-robot k8s-ci-robot merged commit 4683054 into kubernetes:master Jun 19, 2019
22 of 23 checks passed
22 of 23 checks passed
tide Not mergeable. Should not have do-not-merge/hold label.
Details
cla/linuxfoundation neolit123 authorized
Details
pull-kubernetes-bazel-build Job succeeded.
Details
pull-kubernetes-bazel-test Job succeeded.
Details
pull-kubernetes-conformance-image-test Skipped.
pull-kubernetes-cross Skipped.
pull-kubernetes-dependencies Job succeeded.
Details
pull-kubernetes-e2e-gce Job succeeded.
Details
pull-kubernetes-e2e-gce-100-performance Job succeeded.
Details
pull-kubernetes-e2e-gce-csi-serial Skipped.
pull-kubernetes-e2e-gce-device-plugin-gpu Job succeeded.
Details
pull-kubernetes-e2e-gce-iscsi Skipped.
pull-kubernetes-e2e-gce-iscsi-serial Skipped.
pull-kubernetes-e2e-gce-storage-slow Skipped.
pull-kubernetes-godeps Skipped.
pull-kubernetes-integration Job succeeded.
Details
pull-kubernetes-kubemark-e2e-gce-big Job succeeded.
Details
pull-kubernetes-local-e2e Skipped.
pull-kubernetes-node-e2e Job succeeded.
Details
pull-kubernetes-node-e2e-containerd Job succeeded.
Details
pull-kubernetes-typecheck Job succeeded.
Details
pull-kubernetes-verify Job succeeded.
Details
pull-publishing-bot-validate Skipped.
Copy link
Member

left a comment

@neolit123 many thanks for this fix!
/approve
/lgtm

Are U planning to back port this fix in older releases?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.