Skip to content

Instantly share code, notes, and snippets.

@blessedwithsins
Forked from alexeldeib/nginx.yaml
Created April 3, 2021 06:59
Show Gist options
  • Save blessedwithsins/5193606d6c29181ec1f72b5b31313977 to your computer and use it in GitHub Desktop.
Save blessedwithsins/5193606d6c29181ec1f72b5b31313977 to your computer and use it in GitHub Desktop.
rbac with raw token demo
---
apiVersion: v1
kind: Namespace
metadata:
name: nginx
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: nginx-service-account
namespace: nginx
rules:
- apiGroups: ["apps/v1"]
resources: ["deployments"]
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: nginx-serviceaccount-rolebinding
namespace: nginx
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: nginx-service-account
subjects:
- apiGroup: ""
kind: ServiceAccount
name: default
namespace: nginx
---
#!/usr/bin/env bash
set -euo pipefail
SECRET="$(kubectl -n nginx get serviceaccount default -o jsonpath="{.secrets[0].name}")"
TOKEN="$(kubectl -n nginx get secret $SECRET -o jsonpath="{.data.token}" | base64 -d)"
curl.exe -k -H "Authorization: Bearer $TOKEN" https://$FQDN:443/apis/apps/v1/namespaces/nginx/deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment