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

Generate kube config based on plugin RBAC #1020

Merged
merged 15 commits into from
Mar 23, 2023

Conversation

josefkarasek
Copy link

@josefkarasek josefkarasek commented Mar 20, 2023

Description

Changes proposed in this pull request:

  • Add kubeConfig string to executor context
  • Generate kube config per plugin invocation based on plugin RBAC

Testing

Use executors:

  • helm
  • kubectl

Sources:

  • kubernetes
  • cm-watcher
sources:
  'cm':
    displayName: "Events based on plugin"
    botkube/cm-watcher:
      enabled: true
      config:
        configMap:
          name: cm-watcher-trigger
          namespace: botkube
          event: ADDED
      context: *defaultExecutorContext

Self-host plugins

make gen-plugins-index
PLUGIN_SERVER_HOST=http://host.k3d.internal go run test/helpers/plugin_server.go
plugins:
  repositories:
    botkube:
      url: http://host.k3d.internal:3000/botkube.yaml

Install botkube with helm or make sure SA and CluterRole(s) and bindings exist.
ClusterRole botkube-plugins-default will be used for generating kube config for plugins.

# executor kubectl
kubectl get pod -n botkube
# source kubernets
kubectl run nginx --image=nginx
# source cm-watcher
kubectl create cm cm-watcher-trigger -n botkube
# executor helm
helm list
helm install --namespace botkube --repo https://charts.bitnami.com/bitnami psql postgresql

During testing add create/update/delete verbs to ClusterRole botkube-plugins-default.

Related issue(s)

#934

@github-advanced-security
Copy link

You have successfully added a new Trivy configuration .github/workflows/vulnerability-scan.yml:scan-repo. As part of the setup process, we have scanned this repository and found 1 existing alert. Please check the repository Security tab to see all alerts.

cmd/botkube/main.go Outdated Show resolved Hide resolved
cmd/botkube/main.go Outdated Show resolved Hide resolved
pkg/execute/plugin_executor.go Show resolved Hide resolved
pkg/execute/plugin_executor.go Outdated Show resolved Hide resolved
proto/executor.proto Outdated Show resolved Hide resolved
proto/source.proto Outdated Show resolved Hide resolved
ctx := dispatch.ctx
out, err := sourceClient.Stream(ctx, source.StreamInput{
Configs: dispatch.pluginConfigs,
Context: source.StreamInputContext{
IsInteractivitySupported: dispatch.isInteractivitySupported,
ClusterName: dispatch.cfg.Settings.ClusterName,
KubeConfig: dispatch.cfg.Settings.Kubeconfig,
Copy link
Author

@josefkarasek josefkarasek Mar 22, 2023

Choose a reason for hiding this comment

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

This might break existing functionality. We might as well remove kube config from config

Copy link
Collaborator

Choose a reason for hiding this comment

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

🤔 I think it would be great to keep the existing functionality of passing external kubeconfig. This functionality is great to connect to an external cluster. So Botkube can reside e.g. on cluster A, but it can listen for events + execute commands from cluster B.

Options I see:

  1. have kubeconfig as it were before, which overrides kubeconfig for all (sources, executors) and we ignore context.rbac 🤔 That would need to load the file from path, right?
  2. load external kubeconfig as a base for generated kubeconfigs (with modifying impersonate-related properties)
  3. add context.kubeconfig.path property which takes custom kubeconfig as a path and injects it in a given plugin.

I'd prefer third option I think 🤔 Let's chat about this in our team.

Copy link
Collaborator

@mszostok mszostok Mar 23, 2023

Choose a reason for hiding this comment

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

2 cents from my side: I like that option however, even Argo Workflow which is quite popular project, it doesn't support external/multi-cluster (they have issue opened for more that 2years now). If someone wants to have such functionality, they can always use https://github.com/virtual-kubelet/virtual-kubelet#providers. Of course, it brings additional maintenance cost, but it's also a more powerful and “safer” option.

Maybe at the end it just brings not necessary complexity to the Botkube itself? Probably it's a question to @brampling whether we should leave that functionality or not.


However, if we will decide to leave that functionality, it would be good to name it like context.remote.kubeconfig? so it is easier to distinguish current cluster RBAC usage vs external one.

@josefkarasek josefkarasek marked this pull request as ready for review March 22, 2023 14:50
@josefkarasek josefkarasek requested a review from a team March 22, 2023 14:50
@huseyinbabal
Copy link
Contributor

@josefkarasek could you please share an rbac config for channel based configuration? I am doing e2e test, I only managed to handle static one

Copy link
Collaborator

@pkosiec pkosiec left a comment

Choose a reason for hiding this comment

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

Good work! Just a few comments/open questions.

pkg/pluginx/kubeconfig.go Show resolved Hide resolved
}

func generateGroupSubject(rbac config.GroupPolicySubject) (group []string) {
switch rbac.Type {
Copy link
Collaborator

Choose a reason for hiding this comment

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

When exactly the channel name based group mapping will be supported? I know that it'll block the #945 task.

internal/executor/helm/executor.go Outdated Show resolved Hide resolved
@josefkarasek josefkarasek merged commit aad0d19 into kubeshop:main Mar 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants