Coder Social home page Coder Social logo

kubectl-sudo's Introduction

Table of Contents

kubectl sudo

TL;DR

This plugin allows users to run kubernetes commands with the security privileges of another user:

$ kubectl get nodes
Error from server (Forbidden): nodes is forbidden: User "bofh" cannot list nodes at the cluster scope
$ kubectl sudo get nodes
NAME                     STATUS   ROLES    AGE   VERSION
kubelet1.example.com     Ready    <none>   96d   v1.11.2
kubelet2.example.com     Ready    <none>   96d   v1.11.2

With audit log containing the origin and the impersonated user and group, if configured correctly:

{
  "kind": "Event",
  "apiVersion": "audit.k8s.io/v1beta1",
  "level": "Metadata",
  "stage": "ResponseComplete",
  "requestURI": "/api/v1/nodes?limit=500",
  "verb": "list",
  "user": {
    "username": "bofh",
    "groups": [
      "bofh_accounts",
      "system:authenticated"
    ]
  },
  "impersonatedUser": {
    "username": "bofh",
    " groups": [
      "system:masters"
    ]
  },
  "objectRef": {
    "resource": "nodes",
    "apiVersion": "v1"
  },
}

Why

Kubernetes cluster administrators have great power. A mistake could cause the cluster to become unhealthy or insecure and, as such, could impact any or all tenants sharing the cluster. A simple kubectl -f with the wrong namespace can end badly.

How

This project does not really introduce a kubectl plugin, but a concept of how to provide a sudo like system for kubernetes access.

To reduce the surface of unwanted or unexpected actions you can reduce the default priviledges a cluster administrator has to the level of an unprivileged account and give them the ability to impersonate users and groups. When cluster administrators need to do more priviledged actions, they can switch the group to system:masters or another group or user according to the needed privilidge level.

In order to implement that concept, you need to declare a ClusterRole for impersonation:

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: impersonator
rules:
- apiGroups: [""]
  verbs: ["impersonate"]
  resources: ["users", "groups", "serviceaccounts"]

Now you can assign this ClusterRole to the cluster administrators (e.g. group bofh_accounts):

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: cluster-administrators
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: impersonator
subjects:
- apiGroup: rbac.authorization.k8s.io
  kind: Group
  name: bofh_accounts

Any user which has the group bofh_accounts can now do administration tasks with:

kubectl --as=$USER --as-group=system:masters delete node kubelet3.example.com

The provided kubectl plugin is just a wrapper for kubectl to shorten the --as and --as-group part.

Installation

Place kubectl-sudo anywhere in your $PATH with execute permissions. For further information, see the offical plugin documentation.

Plugin Compatibility

Works on systems with /bin/sh and kubectl >= 1.12. kubectl must be inside $PATH.

Configuration

This plugin can be configured using environment variables:

  • KUBECTL_SUDO_PROMPT=true whether or not the plugin prompts the user before executing the kubectl command. Default value is false.

Similar projects

kubectl-sudo's People

Contributors

alexgervais avatar djboris9 avatar erjanmx avatar jfoy avatar luisdavim avatar marsom avatar schnatterer avatar zbindenren avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kubectl-sudo's Issues

Release 1.1?

It would be nice to get the changes on main since 1.0.1.

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.