forked from opencrvs/opencrvs-countryconfig
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Read backup server ssh key from its environment variables, use for an…
…sible provisioning
- Loading branch information
Showing
12 changed files
with
400 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
name: Reusable Fetch Secret Workflow | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
secret_name: | ||
required: true | ||
type: string | ||
env_name: | ||
required: true | ||
type: string | ||
secrets: | ||
github_token: | ||
required: true | ||
encryption_key: | ||
required: true | ||
|
||
jobs: | ||
check-environment: | ||
name: Check if Environment Exists | ||
runs-on: ubuntu-22.04 | ||
outputs: | ||
environment_exists: ${{ steps.check-env.outputs.exists }} | ||
steps: | ||
- name: Check if GITHUB_TOKEN is set | ||
id: check-token | ||
run: | | ||
if [ -z "${{ secrets.github_token }}" ]; then | ||
echo "Environment secret GITHUB_TOKEN is not set. Make sure you add a correct Github API token before running this pipeline." | ||
exit 1 | ||
fi | ||
- name: Check if environment exists | ||
id: check-env | ||
run: | | ||
ENV_NAME="${{ inputs.env_name }}" | ||
RESPONSE=$(curl -s -H "Authorization: Bearer ${{ secrets.github_token }}" \ | ||
"https://api.github.com/repos/${{ github.repository }}/environments/$ENV_NAME") | ||
if echo "$RESPONSE" | grep -q '"name": "'$ENV_NAME'"'; then | ||
echo "Environment $ENV_NAME exists." | ||
echo "::set-output name=exists::true" | ||
else | ||
echo "Environment $ENV_NAME does not exist." | ||
echo "::set-output name=exists::false" | ||
fi | ||
fetch-credentials: | ||
name: Fetch Secret | ||
needs: check-environment | ||
runs-on: ubuntu-22.04 | ||
if: needs.check-environment.outputs.environment_exists == 'true' | ||
outputs: | ||
secret_value: ${{ steps.fetch-credentials.outputs.secret_value }} | ||
environment_exists: ${{ needs.check-environment.outputs.environment_exists }} | ||
steps: | ||
- name: Fetch the secret | ||
id: fetch-credentials | ||
run: | | ||
SECRET_VALUE="${{ secrets[inputs.secret_name] }}" | ||
echo -n "$SECRET_VALUE" | openssl enc -aes-256-cbc -pbkdf2 -salt -k "${{ secrets.encryption_key }}" -out encrypted_key.bin | ||
ENCODED_ENCRYPTED_SECRET=$(base64 < encrypted_key.bin) | ||
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) | ||
echo "secret_value<<$EOF" >> $GITHUB_OUTPUT | ||
echo "$ENCODED_ENCRYPTED_SECRET" >> $GITHUB_OUTPUT | ||
echo "$EOF" >> $GITHUB_OUTPUT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.