Pick a cluster - https://docs.google.com/spreadsheets/d/1iLt6dAw3JlfP9EK5sp8z1CtNYnEvEEfvGOBtELpI6mA/edit?usp=sharing
- https://ou.apps.IP.nip.io/
- Login with the username / password - k8s-lab/$tart123
- Logout
- SSH to your server, user name
root
and this ssh key:
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABFwAAAAdzc2gtcn
NhAAAAAwEAAQAAAQEAwO4emjnsCc56OTYkNuYeJJFmBRSy33UgHEDgwIhTLQU7+C3npYJm
kaJP1VbeOzJGQH03La9KsDrZLDx5XsAIAgN91A8OCts2hKAO4ZKg+Y8XGKvN9Pqsz3uqXg
UFiGDEv4TDxRtk+sFtTnac+o6rUe8I5PmKZlCpLykYEmcV4evUii4/A1xDs5U82sruyrgi
am9EhVVJt7Nm7cP4ZGfjyzE9lBF7H4Suw4HKEM9whS8QQmGItxnhfmwjNeJ07Jw9GtZ5HV
Dbfvo8bVpoAqrVKcTH0iPnoBYqQ2UEqL0d2AjJhXVWkouSP7RE8BVrSA3mt2UB1O2a1Nz0
E3zw+EZRawAAA9jkwZMM5MGTDAAAAAdzc2gtcnNhAAABAQDA7h6aOewJzno5NiQ25h4kkW
YFFLLfdSAcQODAiFMtBTv4LeelgmaRok/VVt47MkZAfTctr0qwOtksPHlewAgCA33UDw4K
2zaEoA7hkqD5jxcYq830+qzPe6peBQWIYMS/hMPFG2T6wW1Odpz6jqtR7wjk+YpmUKkvKR
gSZxXh69SKLj8DXEOzlTzayu7KuCJqb0SFVUm3s2btw/hkZ+PLMT2UEXsfhK7DgcoQz3CF
LxBCYYi3GeF+bCM14nTsnD0a1nkdUNt++jxtWmgCqtUpxMfSI+egFipDZQSovR3YCMmFdV
aSi5I/tETwFWtIDea3ZQHU7ZrU3PQTfPD4RlFrAAAAAwEAAQAAAQAXMcl+Ey6cczVggXDT
JNFE5jIUtEtY8BTfMLGUlA8j33g5OxOZY1b/dT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MzGMY3yqVS8PsNDW5ItGUTvCg7wk48P071pJAz9Oa
PHxBZMTE/RAgatM0Ru2YFzjTC/wuwUdB2ermQGtGiIKrrxY=
Private-MAC: 0c1d4ff803a676cb0b0fbd25030a24370f39cd8b
- Make yourself an administrator
/usr/bin/mysql -u root -h $(/usr/bin/kubectl get svc -n mariadb -o json | /snap/bin/jq -r .items[0].spec.clusterIP) --password=start123 -e "insert into userGroups (userId,groupId) values (2,1);" unison
- Make yourself a cluster administrator
/usr/bin/mysql -u root -h $(/usr/bin/kubectl get svc -n mariadb -o json | /snap/bin/jq -r .items[0].spec.clusterIP) --password=start123 -e "insert into userGroups (userId,groupId) values (2,2);" unison
- Log back in
- Click on Kubernetes Dashboard
- SSH to your server
- Get api server parameter flags
kubectl describe configmap api-server-config -n openunison
- Export CA certificate
kubectl get secret ou-tls-certificate -n openunison -o json | jq -r '.data."tls.crt"' | base64 -d > /etc/kubernetes/pki/ou-ca.pem
- Update
/etc/kubernetes/manifests/kube-apiserver.yaml
with output of #2 - clear your k8s config
rm /root/.kube/config
kubectl get pods --all-namespaces
- Load token
kubectl get pods --all-namespaces
- Logout of openunison
watch kubectl get pods --all-namespaces
-
Login to your openunison with the user
makens
and the password$tart123
-
Setup kubectl using your token
-
Try to create a NS
kubectl create ns mynewns
, it will fail -
Enable audit logging:
mkdir /var/log/k8s
mkdir /etc/kubernetes/audit
cp k8s-audit-policy.yaml /etc/kubernetes/audit
- Edit
/etc/kubernetes/manifests/kube-apiserver.yaml
- add to
command
- add to
- --audit-log-path=/var/log/k8s/audit.log - --audit-log-maxage=1 - --audit-log-maxbackup=10 - --audit-log-maxsize=10 - --audit-policy-file=/etc/kubernetes/audit/k8s-audit-policy.yaml
- add:
- mountPath: /var/log/k8s name: var-log-k8s readOnly: false - mountPath: /etc/kubernetes/audit name: etc-kubernetes-audit readOnly: true
to
volumeMounts
section- add:
- hostPath: path: /var/log/k8s type: DirectoryOrCreate name: var-log-k8s - hostPath: path: /etc/kubernetes/audit type: DirectoryOrCreate name: etc-kubernetes-audit
to
volumes
-
Once the api server is running again, login as makens again and try creating a namespace again
kubectl create ns mynewns
, it will fail -
Look for the audit logs message
grep makens /var/log/k8s/audit.log
-
Generate RBAC rules from
audit2rbac
, replaceIP
with the IP of your cluster./audit2rbac --filename=/var/log/k8s/audit.log --user=https://ou.apps.IP.nip.io/auth/idp/k8sIdp#makens > newrbac.yaml
-
Set your context to admin
export KUBECONFIG=/root/.kube/config-admin
9 . Import the RBACkubectl create -f ./newrbac.yaml
-
Unset your kubeconfig to go back to your default
export KUBECONFIG=
-
kubectl create ns mynewns, SUCCESS!
- Create the policies -
kubectl create -f ./podsecuritypolicies.yaml
- Edit
/etc/kubernetes/manifests/kube-apiserver.yaml
, change--enable-admission-plugins=NodeRestriction
to--enable-admission-plugins=PodSecurityPolicy,NodeRestriction
- Save
- Delete all your pods
kubectl delete pods --all-namespaces --all
- Once done, check if OpenUnison is running and what policy its running under
kubectl describe pods -l application=openunison-orchestra -n openunison
- Chcek if tthe ingress pod is running
kubectl get pods -n ingress-nginx
- Check if mariadb is running
kubectl get pods -n mariadb
- Look at the events for both the
mariadb
andingress-nginx
namespace -kubectl get events -n mariadb
/kubectl get events -n ingress-nginx
- Why isn't it running? :
kubectl create -f - <<EOF
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: ingress-nginx
namespace: ingress-nginx
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: privileged-psp
subjects:
# For the kubeadm kube-system nodes
- kind: ServiceAccount
name: nginx-ingress-serviceaccount
namespace: ingress-nginx
EOF
- Update the ingress-nginx
Deployment
to force a redeploy -kubectl edit deployment nginx-ingress-controller -n ingress-nginx
- Fix mariadb:
kubectl create -f - <<EOF
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: mariadb
namespace: mariadb
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: privileged-psp
subjects:
# For the kubeadm kube-system nodes
- kind: ServiceAccount
name: default
namespace: mariadb
EOF