Skip to content

Instantly share code, notes, and snippets.

@xchandan
Last active April 22, 2024 16:45
Show Gist options
  • Select an option

  • Save xchandan/b25ef1a56643c17c272581838f026b58 to your computer and use it in GitHub Desktop.

Select an option

Save xchandan/b25ef1a56643c17c272581838f026b58 to your computer and use it in GitHub Desktop.

Revisions

  1. xchandan revised this gist Apr 22, 2024. No changes.
  2. xchandan revised this gist Apr 22, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -36,4 +36,4 @@ kubectl auth can-i create deployments --namespace=default --as=chandan

    kubectl get pods --as=chandan


    #https://aungzanbaw.medium.com/a-step-by-step-guide-to-creating-users-in-kubernetes-6a5a2cfd8c71
  3. xchandan created this gist Apr 21, 2024.
    39 changes: 39 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    openssl genpkey -out chandan.key -algorithm Ed25519
    cat chandan.key
    openssl req -new -key chandan.key -out chandan.csr -subj "/CN=chandan/O=edit"
    creq=$(cat chandan.csr | base64 | tr -d "\n")

    cat <<EOF | kubectl apply -f -
    apiVersion: certificates.k8s.io/v1
    kind: CertificateSigningRequest
    metadata:
    name: chandan
    spec:
    request: ${creq}
    signerName: kubernetes.io/kube-apiserver-client
    expirationSeconds: 86400 # one day
    usages:
    - client auth
    EOF

    kubectl get certificatesigningrequest.certificates.k8s.io

    kubectl certificate approve chandan

    kubectl describe csr/chandan

    kubectl get csr/chandan -o json

    kubectl get csr/chandan -o jsonpath="{.status.certificate}" | base64 -d > chandan.crt


    cp ~/.kube/config chandan-kube-config #always backup

    kubectl --kubeconfig chandan-kube-config config set-credentials chandan --client-key chandan.key --client-certificate chandan.crt --embed-certs=true


    kubectl auth can-i create deployments --namespace=default --as=chandan

    kubectl get pods --as=chandan