Skip to content

Error Forbidden: unknown while running kubectl wait #78227

Closed

Description

@brycecr

What happened:
I gave a user ([email protected]) very limited permissions in the kube-system namespace, specifically:

- apiGroups: ["extensions"]
  resources: ["deployments", "deployments/scale"]
  verbs: ["get", "update"]
- apiGroups: [""] 
  resources: ["pods"]
  verbs: ["list", "get"]

I then ran:
kubectl -n kube-system scale deployment my-deployment --replicas=0 --as [email protected] && kubectl wait -n kube-system --for=delete pods -l k8s-app=my-deployment --as [email protected]

This was the output:

deployment.extensions/my-deployment scaled
Error from server (Forbidden): unknown

What you expected to happen:
I would have expected the Forbidden error to describe what permission I lack in order to run the kubectl wait command. In particular this is "watch" on pods, I discovered through trial and error.

How to reproduce it (as minimally and precisely as possible):
Apply the following roles/rolebindings:

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  namespace: kube-system
  name: deployment-scaler
rules:
- apiGroups: ["extensions"]
  resources: ["deployments", "deployments/scale"]
  verbs: ["get", "update"]
- apiGroups: [""] 
  resources: ["pods"]
  verbs: ["list", "get"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: scale-deployments
  namespace: kube-system
subjects:
- kind: User
  name: [email protected]
  apiGroup: rbac.authorization.k8s.io
roleRef:
  kind: Role
  name: deployment-scaler
  apiGroup: rbac.authorization.k8s.io

Create a deployment in kube-system called my-deployment with 1 available replica.
Then run
kubectl -n kube-system scale deployment my-deployment --replicas=0 --as [email protected] && kubectl wait -n kube-system --for=delete pods -l k8s-app=my-deployemnt --as [email protected]

Anything else we need to know?:

Environment:

  • Kubernetes version (use kubectl version):
    Client Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.2", GitCommit:"66049e3b21efe110454d67df4fa62b08ea79a19b", GitTreeState:"clean", BuildDate:"2019-05-16T16:23:09Z", GoVersion:"go1.12.5", Compiler:"gc", Platform:"linux/amd64"}
    Server Version: version.Info{Major:"1", Minor:"12+", GitVersion:"v1.12.7-gke.17", GitCommit:"b1adfec15b29a53b3dcf4af600952861b5819ede", GitTreeState:"clean", BuildDate:"2019-05-01T18:59:13Z", GoVersion:"go1.10.8b4", Compiler:"gc", Platform:"linux/amd64"}
  • Cloud provider or hardware configuration:
    GKE 1.12.7, 3 node cluster
  • OS (e.g: cat /etc/os-release):
    PRETTY_NAME="Debian GNU/Linux buster/sid"
    NAME="Debian GNU/Linux"
    ID=debian
    HOME_URL="https://www.debian.org/"
    SUPPORT_URL="https://www.debian.org/support"
    BUG_REPORT_URL="https://bugs.debian.org/"
  • Kernel (e.g. uname -a):
    Linux 4.19.28-2rodete1-amd64 Unit test coverage in Kubelet is lousy. (~30%) #1 SMP Debian 4.19.28-2rodete1 (2019-03-18 > 2018) x86_64 GNU/Linux
  • Install tools:
  • Network plugin and version (if this is a network-related bug):
  • Others:

Activity

  1. added
    kind/bugCategorizes issue or PR as related to a bug.
    on May 23, 2019
  2. added
    needs-sigIndicates an issue or PR lacks a `sig/foo` label and requires one.
    on May 23, 2019
  3. brycecr commented on May 23, 2019

    @brycecr
    Author

    @kubernetes/sig-cli

  4. added
    sig/cliCategorizes an issue or PR as relevant to SIG CLI.
    and removed
    kind/bugCategorizes issue or PR as related to a bug.
    on May 23, 2019
  5. removed
    needs-sigIndicates an issue or PR lacks a `sig/foo` label and requires one.
    on May 23, 2019
  6. pswica commented on Jun 15, 2019

    @pswica
    Contributor

    I can confirm, on test, that this issue exists. It ends up being pretty difficult, in my opinion.

    As stated above, it only affects pods and not deployments.

    Error is caused here: https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/client-go/rest/request.go#L1142

    When I tested, I got r.err == nil and !errors.IsUnexpectedServerError(r.err). Even if I forced to the next block, I had issues decoding r.body.

    This was the error message: no kind "PodList" is registered for version "v1" in scheme "k8s.io/client-go/dynamic/scheme.go:29"

  7. fejta-bot commented on Sep 13, 2019

    @fejta-bot

    Issues go stale after 90d of inactivity.
    Mark the issue as fresh with /remove-lifecycle stale.
    Stale issues rot after an additional 30d of inactivity and eventually close.

    If this issue is safe to close now please do so with /close.

    Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
    /lifecycle stale

  8. added
    lifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale.
    on Sep 13, 2019
  9. brycecr commented on Sep 17, 2019

    @brycecr
    Author

    /remove-lifecycle stale

  10. removed
    lifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale.
    on Sep 17, 2019
  11. caarlos0 commented on Oct 22, 2019

    @caarlos0
    Contributor

    BTW: happens to jobs too.

    had to give watch permission to jobs.

  12. fejta-bot commented on Jan 20, 2020

    @fejta-bot

    Issues go stale after 90d of inactivity.
    Mark the issue as fresh with /remove-lifecycle stale.
    Stale issues rot after an additional 30d of inactivity and eventually close.

    If this issue is safe to close now please do so with /close.

    Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
    /lifecycle stale

  13. added
    lifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale.
    on Jan 20, 2020
  14. fejta-bot commented on Feb 19, 2020

    @fejta-bot

    Stale issues rot after 30d of inactivity.
    Mark the issue as fresh with /remove-lifecycle rotten.
    Rotten issues close after an additional 30d of inactivity.

    If this issue is safe to close now please do so with /close.

    Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
    /lifecycle rotten

  15. added
    lifecycle/rottenDenotes an issue or PR that has aged beyond stale and will be auto-closed.
    and removed
    lifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale.
    on Feb 19, 2020
  16. fejta-bot commented on Mar 20, 2020

    @fejta-bot

    Rotten issues close after 30d of inactivity.
    Reopen the issue with /reopen.
    Mark the issue as fresh with /remove-lifecycle rotten.

    Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
    /close

  17. k8s-ci-robot commented on Mar 20, 2020

    @k8s-ci-robot
    Contributor

    @fejta-bot: Closing this issue.

    Details

    In response to this:

    Rotten issues close after 30d of inactivity.
    Reopen the issue with /reopen.
    Mark the issue as fresh with /remove-lifecycle rotten.

    Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
    /close

    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.

  18. lexsys27 commented on Nov 27, 2020

    @lexsys27

    I see this issue in 1.18.8 for nodes.

    SA has following permissions:

    rules:
      - apiGroups: [""]
        resources: ["nodes"]
        verbs: ["get", "list"]
    

    Script should wait until node is ready:

    kubectl wait --for=condition=Ready node -l dedicated=true --timeout 120s
    

    Instead I get Error from server (Forbidden): unknown message. It is doesn't say what permissions kubectl miss so is not very helpful.

    I believe this issue should be reopened.

  19. alitoufighi commented on Oct 3, 2021

    @alitoufighi

    It seems that the API verb to access for waiting for a resource is not documented and not mentioned anywhere.

  20. YevheniiPokhvalii commented on Feb 3, 2022

    @YevheniiPokhvalii

    You need to add get, list, watch to your role to avoid this error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/usabilitylifecycle/rottenDenotes an issue or PR that has aged beyond stale and will be auto-closed.sig/cliCategorizes an issue or PR as relevant to SIG CLI.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions