Skip to content

Instantly share code, notes, and snippets.

@salrashid123
salrashid123 / authz.yaml
Created March 29, 2018 15:48
webhook_authz.yaml
clusters:
- name: my-authz-service
cluster:
certificate-authority: /var/lib/localkube/certs/webhook_ca.crt
server: https://webhook.domain.local:8081/authorize
users:
- name: my-api-server
user:
client-certificate: /var/lib/localkube/certs/webhook_plugin.crt
client-key: /var/lib/localkube/certs/webhook_plugin.key
@salrashid123
salrashid123 / webhook_minikube_start
Created March 29, 2018 15:49
webhook_minikube_start
$ minikube start \
--extra-config apiserver.Authentication.WebHook.ConfigFile=/var/lib/localkube/authn.yaml \
--extra-config apiserver.Authorization.Mode=Webhook \
--extra-config apiserver.Authorization.WebhookConfigFile=/var/lib/localkube/authz.yaml
@salrashid123
salrashid123 / webhook_curl_req
Created March 29, 2018 15:50
webhook_curl_req
curl -vk \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InVzZXIxQGRvbWFpbi5jb20ifQ.W0Ek34LU4WQOxXdTqZ9Z-0kESz0wIEdYehxZHlTjt2I" \
https://192.168.39.196:8443/api/
@salrashid123
salrashid123 / webhook_config.yaml
Created March 29, 2018 15:51
webhook_config.yaml
apiVersion: v1
clusters:
- cluster:
certificate-authority: /home/srashid/.minikube/ca.crt
server: https://192.168.39.196:8443
name: minikube
contexts:
- context:
cluster: minikube
user: minikube
@salrashid123
salrashid123 / webhook_au_req.json
Created March 29, 2018 15:51
webhook_au_req.json
{
"apiVersion": "authentication.k8s.io/v1beta1",
"kind": "TokenReview",
"metadata": {
"creationTimestamp": null
},
"spec": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InVzZXIxQGRvbWFpbi5jb20ifQ.W0Ek34LU4WQOxXdTqZ9Z-0kESz0wIEdYehxZHlTjt2I"
},
"status": {
@salrashid123
salrashid123 / webhook_au_resp.json
Created March 29, 2018 15:52
webhook_au_resp.json
{
"apiVersion": "authentication.k8s.io/v1beta1",
"kind": "TokenReview",
"status": {
"authenticated": true,
"user": {
"extra": {
"extrafield1": [
"extravalue1",
"extravalue2"
@salrashid123
salrashid123 / webhook_az_req.json
Created March 29, 2018 15:52
webhook_az_req.json
{
"apiVersion": "authorization.k8s.io/v1beta1",
"kind": "SubjectAccessReview",
"metadata": {
"creationTimestamp": null
},
"spec": {
"extra": {
"extrafield1": [
"extravalue1",
@salrashid123
salrashid123 / webhook_az_resp.json
Created March 29, 2018 15:53
webhook_az_resp.json
{
"apiVersion": "authorization.k8s.io/v1beta1",
"kind": "SubjectAccessReview",
"status": {
"allowed": true
}
}
@salrashid123
salrashid123 / webhook_cn.txt
Created March 29, 2018 15:54
webhook_cn.txt
CN = webhook.domain.local
X509v3 extensions:
Netscape Comment:
OpenSSL Generated Certificate
X509v3 Subject Alternative Name:
DNS:webhook.domain.local, DNS:webhook-srv, DNS:webhook-srv.kube-system, DNS:webhook-srv.kube-system.svc, DNS:webhook-srv.kube-system.svc.cluster.local
X509v3 Key Usage:
Digital Signature, Non Repudiation, Key Encipherment
@salrashid123
salrashid123 / webhook_hmac_jwt.py
Created March 29, 2018 15:54
webhook_hmac_jwt.py
import jwt
encoded = jwt.encode({'username': '[email protected]'}, 'secret', algorithm='HS256')
print encoded
decoded = jwt.decode(encoded, 'secret', algorithms=['HS256'])
print decoded