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

feat(scripts): add script to create users #39

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ secrets.yaml
# Helm
kubernetes/chart/charts/*.tgz

# Pre-commit > Prettier
.prettier-cache
# Generated kube configs
*.config
18 changes: 18 additions & 0 deletions kubernetes/manifests/_/rbac/cluster-roles/vipyrsec-admins.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole

metadata:
name: vipyrsec-admins

rules:
- apiGroups:
- '*'
resources:
- '*'
verbs:
- '*'
- nonResourceURLs:
- '*'
verbs:
- '*'
52 changes: 52 additions & 0 deletions kubernetes/manifests/_/rbac/cluster-roles/vipyrsec-core-devs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole

metadata:
name: vipyrsec-core-devs

rules:
- apiGroups:
- ''
resources:
- pods
- services
- configmaps
- secrets
verbs:
- list
- get
- patch
- update

- apiGroups:
- apps
resources:
- daemonsets
- replicasets
- deployments
verbs:
- list
- get
- patch
- update

- apiGroups:
- batch
resources:
- jobs
verbs:
- list
- get
- patch
- update

- apiGroups:
- networking.k8s.io
resources:
- ingresses
verbs:
- list
- get
- patch
- update
39 changes: 39 additions & 0 deletions kubernetes/manifests/_/rbac/cluster-roles/vipyrsec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole

metadata:
name: vipyrsec

rules:
- apiGroups:
- ''
resources:
- pods
- services
- configmaps
verbs:
- list

- apiGroups:
- apps
resources:
- daemonsets
- replicasets
- deployments
verbs:
- list

- apiGroups:
- batch
resources:
- jobs
verbs:
- list

- apiGroups:
- networking.k8s.io
resources:
- ingresses
verbs:
- list
65 changes: 65 additions & 0 deletions kubernetes/rbac/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Kubernetes RBAC

## Create a user

> [!IMPORTANT]
> Make sure to set the `kubectl` context to the cluster to which you want to add the user!

```bash
./create_user.py <user> -g <group>
```

This will,

1. Create a private key for the user
2. Provision a client certificate for the user using the private key
3. Grant the permissions for the requested groups to the user
4. Generate a kubeconfig using the private key, and the client certificate for use with `kubectl`

### Examples

1. Create a user `foo` with group `vipyrsec`

```bash
./create_user.py foo -g vipyrsec
```

2. Create a user `bar` with groups `vipyrsec`, and `vipyrsec-core-devs` with a day's validity

```bash
./create_user.py bar -g vipyrsec -g vipyrsec-core-devs --expiry-seconds 86400
```

## Revoke a user's access granted by a specific role

> [!IMPORTANT]
> Make sure to set the `kubectl` context to the cluster from which you want to revoke the user's access!

```bash
kubectl delete clusterrolebinding <user>@<group>
```

### Example

Revoke user `foo`'s access granted by `vipyrsec-core-devs`

```bash
kubectl delete clusterrolebinding foo@vipyrsec-core-devs
```

## Revoke all permissions granted to a user (AKA, delete the user)

> [!IMPORTANT]
> Make sure to set the `kubectl` context to the cluster from which you want to revoke the user's access!

```bash
kubectl delete clusterrolebinding -luser=<user>
```

### Example

Revoke all permissions granted to user `foo`

```bash
kubectl delete clusterrolebinding -luser=foo
```
Loading
Loading