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

kubectl proxy should warn about dangerous configurations #122816

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

blackzlq
Copy link

@blackzlq blackzlq commented Jan 16, 2024

What this PR does / why we need it:

In AquaSec recent research, they have identified a common misconfiguration related to the use of the kubectl proxy command in Kubernetes clusters. This misconfiguration can expose the Kubernetes API server to unauthorized access and poses significant security risks.
Scope:
The misconfiguration occurs when practitioners run the kubectl proxy command with specific flags, such as --address=0.0.0.0 --accept-hosts .*. This configuration causes the proxy on the workstation to listen and forward authorized and authenticated requests to the API server from any host that has HTTP access to the workstation. Importantly, the privileges granted to the kubectl proxy command are the same as those of the user who ran it. Risks:
This misconfiguration can lead to unauthorized access to the Kubernetes cluster, potentially compromising the security of the cluster and the applications running on it. Threat actors can exploit this exposure to gain access to sensitive information, secrets, and other critical resources.

Which issue(s) this PR fixes:

To address this issue and mitigate the risks associated with misconfigured kubectl proxy commands, we propose the following steps:

Kuberenetes warning:
Securing kubectl proxy:
  • Ensure that the kubectl proxy is not exposed to the internet, and set it up within a secure network environment accessible only by authenticated and authorized users.

Special notes for your reviewer:

This issue highlights the security risks associated with misconfigured kubectl proxy commands and provides recommendations for addressing these risks. It's crucial for Kubernetes users to be aware of the potential dangers and take appropriate precautions to secure their clusters. References:
https://blog.aquasec.com/kubernetes-exposed-one-yaml-away-from-disaster

Does this PR introduce a user-facing change?

Users will get warnings when proxy set to 0.0.0.0 or accept hosts contains .*
[blog]: <https://blog.aquasec.com/kubernetes-exposed-one-yaml-away-from-disaster>

Problem:
In AquaSec recent research, they have identified a common misconfiguration related to the use of the kubectl proxy command in Kubernetes clusters. This misconfiguration can expose the Kubernetes API server to unauthorized access and poses significant security risks.
Scope:
The misconfiguration occurs when practitioners run the kubectl proxy command with specific flags, such as --address=0.0.0.0 --accept-hosts .*. This configuration causes the proxy on the workstation to listen and forward authorized and authenticated requests to the API server from any host that has HTTP access to the workstation. Importantly, the privileges granted to the kubectl proxy command are the same as those of the user who ran it.
Risks:
This misconfiguration can lead to unauthorized access to the Kubernetes cluster, potentially compromising the security of the cluster and the applications running on it. Threat actors can exploit this exposure to gain access to sensitive information, secrets, and other critical resources.
Proposed Solution:
To address this issue and mitigate the risks associated with misconfigured kubectl proxy commands, we propose the following steps:
Kuberenetes warning: Running kubectl proxy with wide-open configurations can expose your Kubernetes cluster to potential security threats. Attackers could exploit this vulnerability to gain unauthorized access to your cluster and its resources. Add one section check o.address and acceptHosts in https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/kubectl/pkg/cmd/proxy/proxy.go#L151
Securing kubectl proxy: Ensure that the kubectl proxy is not exposed to the internet, and set it up within a secure network environment accessible only by authenticated and authorized users.
Additional Information:
This issue highlights the security risks associated with misconfigured kubectl proxy commands and provides recommendations for addressing these risks. It's crucial for Kubernetes users to be aware of the potential dangers and take appropriate precautions to secure their clusters.
References:
https://blog.aquasec.com/kubernetes-exposed-one-yaml-away-from-disaster
@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Jan 16, 2024
@k8s-ci-robot
Copy link
Contributor

Welcome @blackzlq!

It looks like this is your first PR to kubernetes/kubernetes 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kubernetes has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jan 16, 2024
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

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.

@k8s-ci-robot
Copy link
Contributor

Hi @blackzlq. 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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@k8s-ci-robot k8s-ci-robot added the needs-priority Indicates a PR lacks a `priority/foo` label and requires one. label Jan 16, 2024
@k8s-ci-robot k8s-ci-robot added area/kubectl sig/cli Categorizes an issue or PR as relevant to SIG CLI. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jan 16, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: blackzlq
Once this PR has been reviewed and has the lgtm label, please assign knverey for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jan 16, 2024
@blackzlq
Copy link
Author

/kind documentation
/kind feature
/kind api-change

@k8s-ci-robot k8s-ci-robot added kind/documentation Categorizes issue or PR as related to documentation. kind/feature Categorizes issue or PR as related to a new feature. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API and removed do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Jan 16, 2024
@mpuckett159
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jan 16, 2024
@k8s-triage-robot
Copy link

This PR may require API review.

If so, when the changes are ready, complete the pre-review checklist and request an API review.

Status of requested reviews is tracked in the API Review project.

Copy link

@kumarankit999 kumarankit999 left a comment

Choose a reason for hiding this comment

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

Looks fixed now!

@blackzlq
Copy link
Author

blackzlq commented Jan 21, 2024

Looks fixed now!

Could you link the fix? @kumarankit999

@ardaguclu
Copy link
Member

Thanks. Sounds reasonable to me. But I'd like to ask @liggitt @aojea about their opinions before merging.

}
// string contains will use exact match, not regex.
if strings.Contains(o.acceptHosts, ".*") {
klog.Warning("--accept-hosts will accept any host, which may expose cluster access via the proxy to anyone who can access your network.")
Copy link
Member

Choose a reason for hiding this comment

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

this warning isn't necessarily true. .*\.example.com contains .* but does not accept any host

Copy link
Author

Choose a reason for hiding this comment

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

I think .*\.example.com will still accept kind of any. The range is too wide. But we can modify the warning sentence to be --accept-hosts will accept a wide range of hosts, which may expose cluster access via the proxy to anyone who can access your network. What do you think

Copy link
Member

Choose a reason for hiding this comment

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

I think .*.example.com will still accept kind of any.

I don't think it does? It only accepts subdomains of example.com, right?

The range is too wide

Not if you're intending to allow all subdomains of example.com, right?

Copy link
Member

Choose a reason for hiding this comment

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

I think there's two heuristics we can apply here (we could do both):

  1. actually attempt to match a random host string we construct ("$(random-uuid).$(random-uuid)" or something) against the acceptHosts pattern... if it gets accepted that's a good sign any host would be accepted
  2. detect .* and warn generically about a broad accept-hosts setting as you indicated in kubectl proxy should warn about dangerous configurations #122816 (comment)

Copy link
Author

Choose a reason for hiding this comment

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

I think .*.example.com will still accept kind of any.

I don't think it does? It only accepts subdomains of example.com, right?

The range is too wide

Not if you're intending to allow all subdomains of example.com, right?

Discussed with Michael, we think the sub domain is still very broad. What about we do both check. random match pattern OR contains .*

Copy link
Contributor

Choose a reason for hiding this comment

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

Warning for allowing any subdomain is too broad imo. We should stick to warnings for allowing the world and not try to get in the weeds of what constitutes "appropriately restricted" because this will be different for every organization.

@@ -185,6 +185,13 @@ func (o *ProxyOptions) Complete(f cmdutil.Factory) error {
RejectMethods: proxy.MakeRegexpArrayOrDie(o.rejectMethods),
}
}
if o.address == "0.0.0.0" {
Copy link
Member

Choose a reason for hiding this comment

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

@aojea should this be something net.ParseIP(o.address).IsUnspecified() to catch ipv6 "listen to all" addresses as well?

Copy link
Author

Choose a reason for hiding this comment

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

Does this address apply to ipv6? @aojea

Copy link
Member

Choose a reason for hiding this comment

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

what Jordan says https://pkg.go.dev/net#IP.IsUnspecified

The reality is that the address is "all zeros", 0.0.0.0 or :: are the representations , you have to use net.ParseIPSloppy() to avoid the linter problems

@@ -185,6 +185,13 @@ func (o *ProxyOptions) Complete(f cmdutil.Factory) error {
RejectMethods: proxy.MakeRegexpArrayOrDie(o.rejectMethods),
}
}
if o.address == "0.0.0.0" {
klog.Warning("kubectl proxy will serve on all network interfaces (0.0.0.0), which may expose cluster access via the proxy to anyone who can access your network.")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
klog.Warning("kubectl proxy will serve on all network interfaces (0.0.0.0), which may expose cluster access via the proxy to anyone who can access your network.")
klog.Warningf("kubectl proxy will serve on all network interfaces %s, which may expose cluster access via the proxy to anyone who can access your network.", o.address)

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label May 5, 2024
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle rotten
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/kubectl cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/documentation Categorizes issue or PR as related to documentation. kind/feature Categorizes issue or PR as related to a new feature. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cli Categorizes an issue or PR as relevant to SIG CLI. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
Status: Needs Triage
Development

Successfully merging this pull request may close these issues.

None yet

8 participants