• Stars
    star
    163
  • Rank 231,141 (Top 5 %)
  • Language
    Shell
  • License
    MIT License
  • Created about 6 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Run kubernetes commands with the security privileges of another user

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

More Repositories

1

kubenurse

Kubernetes network monitoring
Go
406
star
2

kubelet-csr-approver

Kubernetes controller to enable automatic kubelet CSR validation after a series of (configurable) security checks
Go
167
star
3

vault-kubernetes

Authenticate services to @hashicorp Vault via the Kubernetes auth method
Go
78
star
4

single

single ensures that only one instance of your program is running
Go
55
star
5

kubectl-ctx

Simple kubectl plugin to display/switch contexts
Go
35
star
6

kuota-calc

Simple utility to calculate the resource quota needed for your k8s deployment(s)
Go
22
star
7

hlfabric-k8scc

Chaincode builder and launcher for Hyperledger Fabric on Kubernetes
Go
22
star
8

kubectl-ns

Simple kubectl plugin to display/switch namespaces
Go
20
star
9

discovery

Service discovery for prometheus.
Go
14
star
10

httpclient

Generates a HTTP client from a service definition (interface). The created client is ready to use in production with many configuration options and sensible defaults.
Go
13
star
11

kubewire

Kubernetes integrity checker
Go
10
star
12

kubectl-vault_sync

Kubernetes plugin to synchronize secrets from vault as kubernetes secrets.
Go
8
star
13

terraform-registry

Go
6
star
14

hostlookuper

DNS monitoring tool
Go
4
star
15

mage

mage (magefile.org) helper functions
Go
4
star
16

vault

Helper and wrapper functions for @hashicorp Vault
Go
2
star
17

vaultkv

Package kv provides version agnostic methods for read, write and list of secrets from @hashicorp Vault's KV secret engines
Go
2
star
18

argocd-cmp-ytt

ArgoCD ConfigManagementPlugin to permit templating with ytt
Go
2
star
19

profiler

pprof endpoint for Go applications that can be activated by a signal
Go
2
star
20

flash

Configures an opinionated zap logger.
Go
1
star
21

secfs

Go package secretfs implements afero.Fs and afero.File for Kubernetes secrets.
Go
1
star
22

vaultk8s

Package k8s provides authentication with Vault on Kubernetes
Go
1
star
23

promi

CLI to query targets and alerts of multiple prometheus servers.
Go
1
star
24

store

store with etcd or in-memory hash as backend
Go
1
star