add-ca-truststore/action.yml

79 lines
2.8 KiB
YAML
Raw Normal View History

name: "add-ca-truststore"
description: 'Github action to add a root certificate to a java truststore'
2024-08-25 16:58:28 +00:00
branding:
icon: upload
color: blue
2024-08-25 16:58:28 +00:00
inputs:
ca-cert:
description: 'root certificate to add to the truststore'
required: true
alias-name:
description: "alias name of the new added certificate, if not provided a random name is generate, beware with random name generated certificate is always inserted even if it already exist"
2024-08-25 16:58:28 +00:00
required: false
default: ""
store-path:
description: "java store path usually end with /cacert"
required: true
store-password:
description: "java store password"
required: false
default: "changeit"
2024-09-05 20:32:59 +00:00
debug:
description: "show debug information about certificate truststore content"
required: false
default: "false"
outputs:
certificate-alias:
value: ${{ steps.generate-alias-name.outputs.alias-name }}
description: "alias name of added certificate, generated if not provided as input"
2024-08-25 16:58:28 +00:00
runs:
using: "composite"
steps:
- name: Generate random pet name
if: ${{ inputs.alias-name == '' }}
id: generate-pet-name
2024-08-25 16:58:28 +00:00
shell: bash
run: |
apt update
apt-get install -y golang-petname
pet_name=$(golang-petname)
echo "pet-name=$pet_name" >> "$GITHUB_OUTPUT"
2024-08-25 16:58:28 +00:00
- name: Defined alias name
id: generate-alias-name
2024-08-25 16:58:28 +00:00
shell: bash
run: |
if [ "T${{ inputs.alias-name }}T" == "TT" ]; then
echo "alias-name=${{ steps.generate-pet-name.outputs.pet-name }}" >> "$GITHUB_OUTPUT"
else
echo "alias-name=${{ inputs.alias-name }}" >> "$GITHUB_OUTPUT"
fi
2024-08-25 16:58:28 +00:00
- name: Add certificate ${{ steps.generate-alias-name.outputs.alias-name }} to truststore
2024-08-25 16:58:28 +00:00
shell: bash
env:
does_not_exist_message: "does not exist"
2024-08-25 16:58:28 +00:00
run: |
already_exists=$(keytool -list -alias ${{ steps.generate-alias-name.outputs.alias-name }} -keystore ${{ inputs.store-path }} -storepass ${{ inputs.store-password }} 2>/dev/null | grep "${{ env.does_not_exist_message }}" || true)
if [ ! -z "$already_exists" ];
then
echo "${{ inputs.ca-cert }}" | keytool -import -noprompt -trustcacerts -alias ${{ steps.generate-alias-name.outputs.alias-name }} -keystore ${{ inputs.store-path }} -storepass ${{ inputs.store-password }};
else
echo "Certificate ${{ steps.generate-alias-name.outputs.alias-name }} already contained in the truststore";
2024-09-05 20:32:59 +00:00
fi
- name: Show added ${{ steps.generate-alias-name.outputs.alias-name }} for debugging
if: ${{ inputs.debug == 'true' }}
shell: bash
run: |
keytool -list -cacerts | grep antoine
- name: List cert for debugging
if: ${{ inputs.debug == 'true' }}
shell: bash
run: |
keytool -list -cacerts