Provide credential and session management capabilities for Kubernetes clusters.
For use with CyberArk PAM self-hosted or Privilege Cloud.
Tested with:
Software | Version |
---|---|
CyberArk PAM self-hosted | 13.2 |
Kubernetes | 1.28 |
Name | Publisher | Version | Purpose | Link |
---|---|---|---|---|
BouncyCastle.Cryptography.dll | Legion of The Bouncy Castle Inc. | 2.2.1.47552 | Certificate operations | https://www.bouncycastle.org/csharp/ |
Newtonsoft.Json.dll | Newtonsoft | 13.0.3.27908 | Parse json data | https://www.newtonsoft.com/json |
YamlDotNet.dll | Antoine Aubry | 13.7.1.0 | Parse yaml data | https://github.com/aaubry/YamlDotNet |
Create user and bind to a role/clusterrole:
USERNAME=joe.tan
BINDINGNAME=joe.tan-clusterrolebinding
CLUSTERROLE=cluster-admin
kubectl create clusterrolebinding $BINDINGNAME --clusterrole=$CLUSTERROLE --user=$USERNAME
Create key-pair and CSR:
openssl ecparam -name secp384r1 -genkey -out $USERNAME.key
openssl req -new -key $USERNAME.key -subj "/CN=$USERNAME" -out $USERNAME.csr
openssl x509 -req -in $USERNAME.csr -CA /etc/kubernetes/pki/ca.crt -CAkey /etc/kubernetes/pki/ca.key -CAcreateserial -days 10958 -sha256 -out $USERNAME.pem
Submit CSR to Kubernetes cluster:
CSRNAME=joe.tan-csr
kubectl apply -f - <<EOF
apiVersion: certificates.k8s.io/v1
kind: CertificateSigningRequest
metadata:
name: $CSRNAME
spec:
request: $CSR
signerName: kubernetes.io/kube-apiserver-client
expirationSeconds: $CERTVALIDITY
usages:
- client auth
EOF
Approve the CSR:
kubectl certificate approve $CSRNAME
- Username
- Kubernetes Cluster URL
- Groups (comma separated)
- Certificate Validity (Days)
- Kubernetes Cluster Version
Note
The method provided by CPM for returning credentials to CPM requires the KeyID
field to be populated
The Kubernetes Cluster Version
field maps to the KeyID
field
This parameter has no real effect on the account, but is required for the change
and reconcile
actions to work
The plugin works with a Base-64 encoded kubeconfig file.
Example:
echo .kube/config | base64 -w0
Note
The kubeconfig file should only contain 1 user entry
If there are multiple user entries, only the first one will be managed
The plugin creates a new user certificate with the following flow:
- Create a RSA-2048 private key-pair
- Create a CSR and submit to the Kubernetes cluster
- Approve the CSR
Note
The user principal in the kubeconfig file needs to have the appropriate permissions to submit and approve CSR for the change operation to succeed
Otherwise, use reconcile method with another kubeconfig account with the permissions
Warning
Kubernetes does not support certificate revocation
Minimize the chance of certificate abuse by minimizing the certificate validity and adjusting the change period to issue a new certificate for the current one expires
NAMESPACE=kube-system
SERVICEACCOUNTNAME=joe.tan
CLUSTERROLE=cluster-admin
kubectl -n $NAMESPACE create serviceaccount $SERVICEACCOUNTNAME
kubectl -n $NAMESPACE create clusterrolebinding $CLUSTERROLE-binding --clusterrole=$CLUSTERROLE --serviceaccount=$NAMESPACE:$SERVICEACCOUNTNAME
kubectl -n $NAMESPACE create token $SERVICEACCOUNTNAME --duration=24h
- Service Account Name
- Kubernetes Cluster URL
- Namespace
- Token Lifetime (Days)
- Kubernetes Cluster Version
Note
The method provided by CPM for returning credentials to CPM requires the KeyID
field to be populated
The Kubernetes Cluster Version
field maps to the KeyID
field
This parameter has no real effect on the account, but is required for the change
and reconcile
actions to work
The plugin works with service account tokens
The plugin works with Kubernetes time-limited API tokens
Example:
kubectl -n $NAMESPACE create token $SERVICEACCOUNTNAME --duration=24h
Note
The service account needs to have the appropriate permissions to create tokens for the change operation to succeed
Otherwise, use reconcile method with a kubeconfig account with the permissions
Warning
Kubernetes does not support revocation of time-limited API token
Minimize the chance of token abuse by minimizing the token lifetime and adjusting the change period to issue a new token for the current one expires
The PSM connector for kubectl comprises of:
- AutoIT script to work with the PSM universal connector framework
- Dispatcher flow:
- Retrieve the account values (username/service account name, kubeconfig/service account token, kubernetes cluster URL, kubectl directory)
- Set the account values as environment variables for the kubectl wrapper
- Launch the kubectl wrapper
- The
kubectlWrapper.
- Restricted shell inteface built using C# to limit user inputs to kubectl commands
- Wrapper flow:
- Determine whether the password type is kubeconfig or service account token
- Generate the kubeconfig file according to the password type
- Enforce accepted/denied user inputs:
- Accepted: inputs that starts with
kubectl
- Denied: inputs that contains:
&&
,|
,<
and>
- Accepted: inputs that starts with
Note
Using kubectl apply
:
-
kubectl apply -f -
does not work as Windows doesn't work with the<< EOF
+EOF
redirection -
The restricted shell interface prevents file creation/edit on the kubectl connector, to apply a Kubernetes manifest file, use the PSM drive mapping feature to upload the manifest via the drive mapping, and use
kubectl apply -f Z:\<filename>
Note
Executables directory:
The kubectlWrapper.exe
and kubectl.exe
executables must be put into the same directory on each PSM server
The directory where the executables are in should be populated in the connection component setting: ConnectionComponent
/ TargetSettings
/ ClientSpecific
/ kubectlDirectory