Skip to content

🐋Implement k8s authorization#618

Merged
amorey merged 1 commit intokubetail-org:cluster-agent-rewritefrom
gikaragia:add/k8s-authorization
Aug 24, 2025
Merged

🐋Implement k8s authorization#618
amorey merged 1 commit intokubetail-org:cluster-agent-rewritefrom
gikaragia:add/k8s-authorization

Conversation

@gikaragia
Copy link
Copy Markdown
Collaborator

@gikaragia gikaragia commented Aug 23, 2025

Fixes #616

Summary

Similarly with the old cluster agent, we now check that the pods making a request have the proper rights.

Changes

  • Adds a new struct, the authorizer which is responsible for communicating with the k8s to confirm the requests are authorized.

Testing instructions

  • Observe first that everything is still working
  • Go to kubetail.yaml and remove the watch or list verb from the kubetail-cli cluster role:
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: kubetail-cli
  labels:
    app.kubernetes.io/name: kubetail
    app.kubernetes.io/component: cli
rules:
  - apiGroups: [""]
    resources: [nodes]
-    verbs: [get, list, watch]
+   verbs: [get, watch]
  - apiGroups: ["", apps, batch]
    resources:
      - cronjobs
      - daemonsets
      - deployments
      - jobs
      - pods
      - replicasets
      - statefulsets
    verbs: [get, list, watch]
  - apiGroups: [""]
    resources: [pods/log]
-   verbs: [list, watch]
+  verbs: [ watch]
  • Observe that now the dashboard is broken

Submitter checklist

  • Add the correct emoji to the PR title
  • Link the issue number, if any, to Fixes #
  • Add summary and explain changes in the PR description
  • Rebase branch to HEAD
  • Squash changes into one signed, single commit 1

Footnotes

  1. See suggested commit format

}

/// Checks that the the k8s doing the request has proper rights to access the log files.
#[cfg(not(test))]
Copy link
Copy Markdown
Collaborator Author

@gikaragia gikaragia Aug 23, 2025

Choose a reason for hiding this comment

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

There are a couple of issues with this implementation.

  • First, the ideal way to implement such functionality is with an interceptor (middleware). The problem is that tonic does not support async interceptors out of the box, and I would need to use a custom crate for this functionality. I chose not to use an interceptor.
  • Secondly, the ideal way to stub the authorizer in the tests would be to use dependency injection. However, this made the types very complicated, so I think that using #[cfg] directives is preferable

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Makes sense. When we switch over to treating the Cluster API as a "Kubernetes API extension" then authentication will work with impersonation headers rather than tokens so I think doing things quick-and-simple like this for now sounds good. When we have a better idea of how auth will work long-term we can revisit it.

Signed-off-by: Giannis K <ikaragi23@yahoo.gr>
@gikaragia gikaragia force-pushed the add/k8s-authorization branch from 9ef90eb to ad44135 Compare August 23, 2025 18:40
Copy link
Copy Markdown
Member

@amorey amorey left a comment

Choose a reason for hiding this comment

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

🔒

@github-project-automation github-project-automation Bot moved this to In Review in Kubetail Aug 24, 2025
@amorey amorey merged commit fb7d4c6 into kubetail-org:cluster-agent-rewrite Aug 24, 2025
37 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in Kubetail Aug 24, 2025
gikaragia added a commit to gikaragia/kubetail that referenced this pull request Aug 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants