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

apf: exempt probes /healthz /livez /readyz #100678

Merged
merged 1 commit into from Apr 9, 2021

Conversation

tkashem
Copy link
Contributor

@tkashem tkashem commented Mar 30, 2021

What type of PR is this?

/kind bug

What this PR does / why we need it:

Add a FlowSchema that exempts the following probes from any user:

  • /readyz
  • /livez
  • /healthz

Which issue(s) this PR fixes:

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Fixes a regression in 1.20+ default configurations in the priority and fairness API server filter by exempting all probes (/readyz, /healthz, /livez) to prevent restarting of "healthy" kube-apiserver instance(s) by kubelet.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/bug Categorizes issue or PR as related to a bug. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API labels Mar 30, 2021
@tkashem
Copy link
Contributor Author

tkashem commented Mar 30, 2021

/assign @deads2k @MikeSpreitzer

@lavalamp
Copy link
Member

Is this the right thing to do? Isn't it common for unathenticated users to have access to these endpoints?

@fejta-bot
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.

@tkashem
Copy link
Contributor Author

tkashem commented Mar 30, 2021

Is this the right thing to do? Isn't it common for unauthenticated users to have access to these endpoints?

kubelet liveness probe gets a 429 response (the priority level is saturated due to load or degradation) and this may cause kubelet to restart the apiserver instance.

Is your concern that a bad actor can drown the apiserver with probe requests and bring it down? I think the health checks in the apiserver are designed to be asynchronous and these are very cheap. But yeah, making it exempt does leave a window open. An alternative is to use a dedicated non-exempt priority level (maybe with a small concurrency share)

@MikeSpreitzer
Copy link
Member

@kubernetes/sig-api-machinery-bugs

@k8s-ci-robot k8s-ci-robot added sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Apr 2, 2021
@MikeSpreitzer
Copy link
Member

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Apr 2, 2021
@MikeSpreitzer
Copy link
Member

/priority important-soon

@k8s-ci-robot k8s-ci-robot added priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Apr 2, 2021
Copy link
Member

@MikeSpreitzer MikeSpreitzer left a comment

Choose a reason for hiding this comment

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

@lavalamp : we discussed it in the meeting on Monday. Our thinking was that we do not like making this available to bad actors, but having kubelets kill loaded apiservers is worse.

@tkashem : what you suggested sounds interesting. Have you tried it?

// the following flow schema exempts probes
SuggestedFlowSchemaProbes = newFlowSchema(
"probes", "exempt", 2,
flowcontrol.FlowDistinguisherMethodByUserType,
Copy link
Member

Choose a reason for hiding this comment

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

The choice of flow distinguisher method is not obvious. Since these requests are exempt and thus not queued, there is no wrong answer from a functional point of view. Why not go with the simplest choice, the one that makes the flow distinguisher always be the empty string? Specifying something more specific suggests there is a reason, which would be misleading to readers if there is not a reason. Is there thinking that this will produce better metrics or debug output or something? If there is a positive reason, it would be best to comment it, since it is not obvious.

@lavalamp
Copy link
Member

lavalamp commented Apr 2, 2021

I guess the right thing to do is to figure out what user kubelet identifies as and make only kubelet exempt.

I have conflicting feelings about that, however, like imagine we get into a situation where all the queues go into a deadlock, but exempt requests are getting handled fine. Then the proper thing would be for kubelet to restart apiserver, but it will appear as if apiserver is perfectly happy. I guess maybe instead of relying on the health check itself going through the system, we should make them exempt and somehow continuously test the queues ourselves, and report a health failure if they are stuck for a long time?

E.g., we could periodically insert sentry requests in each PL and verify that they actually eventually get handled or canceled.

Anyway I agree restarting healthy apiservers is quite bad and we should prevent that. But failing to restart unhealthy apiservers is also bad!

@tkashem
Copy link
Contributor Author

tkashem commented Apr 5, 2021

I guess the right thing to do is to figure out what user kubelet identifies as and make only kubelet exempt.

So I grabbed the kubelet probes for /healthz from audit.

{
  "kind": "Event",
  "apiVersion": "audit.k8s.io/v1",
  "level": "RequestResponse",
  "auditID": "af13ff6f-fcd7-444d-8224-0429d8a52b43",
  "stage": "RequestReceived",
  "requestURI": "/healthz",
  "verb": "get",
  "user": {
    "username": "system:anonymous",
    "groups": [
      "system:unauthenticated"
    ]
  },
  "sourceIPs": [
    "10.0.132.119"
  ],
  "userAgent": "kube-probe/1.20",
  "requestReceivedTimestamp": "2021-03-16T20:17:36.069405Z",
  "stageTimestamp": "2021-03-16T20:17:36.069405Z"
}

It appears as system:anonymous to kube-apiserver, there is no information in the user to identify whether it's coming from kubelet. The user agent is kube-probe/{version}. So it appears we can't exempt kubelet probes exclusively.

The audit is taken from an OpenShift cluster, and I assume it will be the same for other clusters as well.
Thoughts?

@lavalamp
Copy link
Member

lavalamp commented Apr 5, 2021

Long term, we need to make sure kubelet has its own account.

We probably can't block on that.

People can always change this back on individual clusters if it gets abused, I guess.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 5, 2021
@lavalamp
Copy link
Member

lavalamp commented Apr 5, 2021

/approve

(with the understanding that @tkashem is going to start a conversation with SIG Auth about them getting kubelet its own identity somehow)

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lavalamp, MikeSpreitzer, tkashem

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 5, 2021
@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

@tkashem
Copy link
Contributor Author

tkashem commented Apr 5, 2021

Long term, we need to make sure kubelet has its own account.

opened an issue #100844 to have a discussion on this

@wojtek-t
Copy link
Member

@lavalamp @deads2k - should we consider cherrypicking back to 1.21 and 1.20 (where APF is Beta already)?

@deads2k
Copy link
Contributor

deads2k commented Apr 13, 2021

@lavalamp @deads2k - should we consider cherrypicking back to 1.21 and 1.20 (where APF is Beta already)?

Yes. I'm willing to go back to all supported versions.

@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 release-note-none Denotes a PR that doesn't merit a release note. labels Apr 14, 2021
k8s-ci-robot added a commit that referenced this pull request Apr 15, 2021
…678-upstream-release-1.21

Automated cherry pick of #100678: apf: exempt probes /healthz /livez /readyz
k8s-ci-robot added a commit that referenced this pull request Apr 15, 2021
…678-upstream-release-1.20

Automated cherry pick of #100678: apf: exempt probes /healthz /livez /readyz
k8s-ci-robot added a commit that referenced this pull request Apr 15, 2021
…678-upstream-release-1.18

Automated cherry pick of #100678: apf: exempt probes /healthz /livez /readyz
k8s-ci-robot added a commit that referenced this pull request Apr 30, 2021
…678-upstream-release-1.19

Automated cherry pick of #100678: apf: exempt probes /healthz /livez /readyz
@liggitt liggitt added the kind/regression Categorizes issue or PR as related to a regression from a prior release. label Apr 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. 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/bug Categorizes issue or PR as related to a bug. kind/regression Categorizes issue or PR as related to a regression from a prior release. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants