Skip to content

GitHub composite action for adding KinD user #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions github-actions/kind-add-user/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: "Add custom user to KinD"
description: "Step to add custom user to KinD"

inputs:
user-name:
description: "Name of the user added to KinD"
required: true
cluster-name:
description: "Name of the KinD cluster"
required: false
default: cluster

runs:
using: "composite"
steps:
- name: Add user to KinD context
run: |
# Get KinD certificates
docker cp ${{ inputs.cluster-name }}-control-plane:/etc/kubernetes/pki/ca.crt .
docker cp ${{ inputs.cluster-name }}-control-plane:/etc/kubernetes/pki/ca.key .

# Generate certificates for new user
openssl genrsa -out user.key 2048
openssl req -new -key user.key -out user.csr -subj '/CN=${{ inputs.user-name }}/O=tenant'
openssl x509 -req -in user.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out user.crt -days 360

# Add generated certificated to KinD context
user_crt=$(base64 --wrap=0 user.crt)
user_key=$(base64 --wrap=0 user.key)
yq eval -i ".contexts += {\"context\": {\"cluster\": \"kind-${{ inputs.cluster-name }}\", \"user\": \"${{ inputs.user-name }}\"}, \"name\": \"${{ inputs.user-name }}\"}" $HOME/.kube/config
yq eval -i ".users += {\"name\": \"${{ inputs.user-name }}\", \"user\": {\"client-certificate-data\": \"$user_crt\", \"client-key-data\": \"$user_key\"}}" $HOME/.kube/config

cat $HOME/.kube/config

# Cleanup
rm ca.crt
rm ca.key
rm user.crt
rm user.key
rm user.csr
shell: bash