File tree 1 file changed +41
-0
lines changed
github-actions/kind-add-user
1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ name : " Add custom user to KinD"
2
+ description : " Step to add custom user to KinD"
3
+
4
+ inputs :
5
+ user-name :
6
+ description : " Name of the user added to KinD"
7
+ required : true
8
+ cluster-name :
9
+ description : " Name of the KinD cluster"
10
+ required : false
11
+ default : cluster
12
+
13
+ runs :
14
+ using : " composite"
15
+ steps :
16
+ - name : Add user to KinD context
17
+ run : |
18
+ # Get KinD certificates
19
+ docker cp ${{ inputs.cluster-name }}-control-plane:/etc/kubernetes/pki/ca.crt .
20
+ docker cp ${{ inputs.cluster-name }}-control-plane:/etc/kubernetes/pki/ca.key .
21
+
22
+ # Generate certificates for new user
23
+ openssl genrsa -out user.key 2048
24
+ openssl req -new -key user.key -out user.csr -subj '/CN=${{ inputs.user-name }}/O=tenant'
25
+ openssl x509 -req -in user.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out user.crt -days 360
26
+
27
+ # Add generated certificated to KinD context
28
+ user_crt=$(base64 --wrap=0 user.crt)
29
+ user_key=$(base64 --wrap=0 user.key)
30
+ yq eval -i ".contexts += {\"context\": {\"cluster\": \"kind-${{ inputs.cluster-name }}\", \"user\": \"${{ inputs.user-name }}\"}, \"name\": \"${{ inputs.user-name }}\"}" $HOME/.kube/config
31
+ yq eval -i ".users += {\"name\": \"${{ inputs.user-name }}\", \"user\": {\"client-certificate-data\": \"$user_crt\", \"client-key-data\": \"$user_key\"}}" $HOME/.kube/config
32
+
33
+ cat $HOME/.kube/config
34
+
35
+ # Cleanup
36
+ rm ca.crt
37
+ rm ca.key
38
+ rm user.crt
39
+ rm user.key
40
+ rm user.csr
41
+ shell : bash
You can’t perform that action at this time.
0 commit comments