using kubectl
and kops
1.8
When spinning of a cluster in aws
using kops
the client certificate (present as string in the client-certificate-data
field of ~/.kube/config
) created has the following values:
Subject: O=system:masters, CN=kubecfg
Unless I am wrong, starting from kubernetes 1.4
, the value for O
rganitazion is interpeted as group
information (string associated with CN
value is the so-called user, since k8s
does not inherently have such a concept)
1: How can I see what permissions are associated with the system:masters
group and/or the kubecfg
user?
RBAC
? How can I check this?2: Why the entries in my ~/.kube/config
do not incorporate a kubecfg
user? (but rather a user bearing my cluster name and another user named admin
?)
$ kubectl config view
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: REDACTED
server: <server_url>
name: <my_cluster_name>
contexts:
- context:
cluster: <my_cluster_name>
user: <my_cluster_name>
name: <my_cluster_name>
current-context: <my_cluster_name>
kind: Config
preferences: {}
users:
- name: <my_cluster_name>
user:
client-certificate-data: REDACTED
client-key-data: REDACTED
password: <some_pass>
username: admin
- name: <my_cluster_name>.local-basic-auth
user:
password: <some_pass>
username: admin
At the end of the day, what user I am performing api calls with, when executing kubectl
commands?
update: I tried to mess up the value of client-certificate-data
in my ~/.kube/config
and I got
error: tls: private key does not match public key
I am assuming this means I am using a x509
based auth (?)
So I am making api calls as kubecfg
?
Note that there is a difference between authentication and authorization.
Kubernetes Authentication
In Kubernetes, there are many mechanisms which may be used to to authenticate a user such as tokens, passwords, OIDC connect tokens, and SSL x509 client certs.
As you have discovered above, kops
will auto-generate a ~/.kube/config file with an embedded SSL x509 client certificate.
Presenting the client certificate along with any REST call to the kube-apiserver allows the kube-apiserver to authenticate the caller by validating that the client certificate has been signed by the cluster Certificate Authority (CA). If the client cert has been properly signed, then the caller is who they say they are.
The identity of the holder of the client certificate is determined by the Subject field of the SSL x509 client certificate.
user
name in the kubeconfig file is just an opaque value user for the convenience of the kubectl tool. The real identity of the user
is that which has been embedded in the SSL x509 client certificate or any other token.Kubernetes Authorization
verb
operations are allowed (e.g. "get", "list", "watch", "create", "update", "patch", "delete"). role
which is a set of permissions that define access to kube-apiserver REST endpoints.rolebinding
which binds a user id or a group id to a specific role
.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: role-grantor
rules:
- apiGroups: ["rbac.authorization.k8s.io"]
resources: ["rolebindings"]
verbs: ["create"]
- apiGroups: ["rbac.authorization.k8s.io"]
resources: ["clusterroles"]
verbs: ["bind"]
resourceNames: ["admin","edit","view"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: role-grantor-binding
namespace: user-1-namespace
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: role-grantor
subjects:
- apiGroup: rbac.authorization.k8s.io
kind: User
name: user-1
Checking if you have RBAC enabled
Simply verify the kube-apiserver startup options. If kube-apiserver is running as a pod, you can check it like this:
$ kubectl get po kube-apiserver-ubuntu-18 -n kube-system -o name |grep api
pod/kube-apiserver-ubuntu-18
$ kubectl get po kube-apiserver-ubuntu-18 -n kube-system -o yaml
# THEN SEARCH FOR RBAC
spec:
containers:
- command:
- kube-apiserver
- --authorization-mode=Node,RBAC
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With