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

inputs.prometheus require cluster level permissions even when scoped to a namespace #12780

Closed
redbaron opened this issue Mar 2, 2023 · 5 comments · Fixed by #13063
Closed
Labels
bug unexpected problem or unintended behavior

Comments

@redbaron
Copy link
Contributor

redbaron commented Mar 2, 2023

Relevant telegraf.conf

[[inputs.prometheus]]
monitor_kubernetes_pods = true
monitor_kubernetes_pods_namespace = "ns1"
monitor_kubernetes_pods_port = 7354

Logs from Telegraf

E0302 16:25:26.890248       1 reflector.go:140] pkg/mod/k8s.io/client-go@v0.25.0/tools/cache/reflector.go:169: Failed to watch *v1.Pod: failed to list *v1.Pod: pods is forbidden: User "system:serviceaccount:ns1:telegraf-prometheus" cannot list resource "pods" in API group "" at the cluster scope

System info

1.25.1

Docker

No response

Steps to reproduce

Grant kubernetes service account used to run telegraf followig role (important, NOT cluster role)

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: telegraf-prometheus
  namespace: n1
  rules:
  - verbs:
      - list
      - watch
      - get
    apiGroups:
      - ''
    resources:
      - namespaces
      - pods

Run telegraf with config from the above in the namespace ns1

Expected behavior

Scrapes metrics successfully

Actual behavior

Unable to list pods

Additional info

No response

@redbaron redbaron added the bug unexpected problem or unintended behavior label Mar 2, 2023
@powersj
Copy link
Contributor

powersj commented Mar 3, 2023

@redbaron have you looked into what might be required to reduce the permissions? It does look like the readme example expected cluster level permissions as you point out.

@skrech
Copy link

skrech commented Apr 6, 2023

Hello, we're facing the same issue where we need to scrape pods but don't have permissions in our cluster to create ClusterRoles.
In another related issue (#10928), a limitation of informer (on kubernetes side, kubernetes-sigs/controller-runtime#124) is referred to as the cause of the problem, but it seems it's been resolved in kubernetes-sigs/controller-runtime#136 so maybe telegraf could alleviate the requirement for ClusterRole.

@powersj
Copy link
Contributor

powersj commented Apr 10, 2023

@redbaron and @skrech,

Can you try the artifacts in #13063 to see if they resolve this issue?

@skrech
Copy link

skrech commented Apr 12, 2023

Uh, It was very hard for me to setup the environment, but I think I manage to do it in the end.
I used this Dockerfile (https://github.com/influxdata/influxdata-docker/blob/master/telegraf/nightly/Dockerfile), modified it to download the CI build linked in the PR, built it locally, and used a clever trick in Skaffold to test with local cluster.

The good news is the fix is working! With only Role and RoleBinding (as opposed to ClusterRole and ClusterRoleBining) I was able to scrape Pods from the namespace specified in monitor_kubernetes_pods_namespace.

Thank you @Ivaylogi98 for the fix!

@powersj
Copy link
Contributor

powersj commented Apr 12, 2023

@skrech thank you for taking the time to confirm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants