Giter Site home page Giter Site logo

gen-role's Introduction

gen-role kubectl

A kubectl plugin to generate roles and ClusterRoles based on kubectl interactions

Say you want to run a script inside your cluster with a ServiceAccount, and want to know which RBAC is necessary for it.

For example, if the script should do the following:

kubectl run -n default curl --image=curlimages/curl --command sleep 30h
kubectl wait --for=condition=ready pod curl
kubectl exec -n default curl -- curl -s http://platform:8080
kubectl delete pod curl -n default
kubectl get deployment -A

By running the commands with the gen-role plugin on your local machine, the necessary RBAC will be accumulated in the files gen-role.yaml and gen-clusterrole.yaml.

kubectl gen-role run -n default curl --image=curlimages/curl --command sleep 30h
kubectl gen-role wait --for=condition=ready pod curl
kubectl gen-role exec -n default curl -- curl -s http://platform:8080
kubectl gen-role delete pod curl -n default
kubectl gen-role get deployment -A

The the RBAC files will be populated as follows:

$ tail -n +1 gen*.yaml
==> gen-cluster-role.yaml <==
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  creationTimestamp: null
  name: gen-role-generated-clusterrole
  namespace: gen-role-generated-clusterrole
rules:
- apiGroups:
  - apps/v1
  resourceNames:
  - deployments
  verbs:
  - list

==> gen-role.yaml <==
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  creationTimestamp: null
  name: gen-role-generated-role
  namespace: gen-role-generated-role
rules:
- apiGroups:
  - ""
  resourceNames:
  - pods
  verbs:
  - post
  - get
  - list
  - watch
  - delete

All you need to do is bind them to the right ServiceAccount in the cluster.

Setup

Clone this repo and run

make bin
sudo make install

Use it with any kubectl command:

kubectl gen-role get po

The default is that the binary will be installed in /usr/local/bin. To change the destination, set the BINDIR variable:

make bin
sudo make install BINDIR=/home/me/bin

However, the binary needs to be available in the PATH to be recognized as a kubectl plugin.

gen-role's People

Contributors

nautilux avatar

Stargazers

Ron Green avatar David Ansari avatar

Watchers

James Cloos avatar  avatar

gen-role's Issues

It should consider namespaces

Currently the plugin only generates one role and doesn't consider multiple commands may run against different namespaces and hence need a role per namespace.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.