Skip to content

Commit e1ffb76

Browse files
committed
ci: use ansible-valut for storing a private key
Part of #435
1 parent e1ca80d commit e1ffb76

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ infra/terraform/terraform.tfstate.backup
3939
infra/docker/application-prod.properties
4040
infra/docker/mysql_backup_mystamps.sql.gz
4141

42+
# created by src/main/scripts/ci/deploy.sh
43+
vault-pass.txt
44+
4245
# maven-wrapper
4346
.mvn/wrapper/maven-wrapper.jar
4447

5.29 KB
Binary file not shown.

src/main/scripts/ci/deploy.sh

+11-4
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ CURRENT_DIR="$(dirname "${0:-.}")"
1414
INVENTORY="$CURRENT_DIR/ansible/mystamps.inventory"
1515
PLAYBOOK="$CURRENT_DIR/ansible/deploy.yml"
1616
PRIVATE_KEY="$CURRENT_DIR/ansible/mystamps_rsa"
17+
PASS_FILE="$CURRENT_DIR/vault-pass.txt"
1718

1819
cleanup() {
19-
rm -f "$PRIVATE_KEY"
20+
rm -f "$PRIVATE_KEY" "$PASS_FILE"
2021
exit
2122
}
2223
trap 'cleanup' EXIT SIGHUP SIGINT SIGTERM
@@ -29,13 +30,19 @@ export ANSIBLE_HOST_KEY_CHECKING=False
2930
# See: https://docs.ansible.com/ansible/2.9/reference_appendices/config.html#envvar-ANSIBLE_STDOUT_CALLBACK
3031
export ANSIBLE_STDOUT_CALLBACK=debug
3132

32-
if [ -z "${encrypted_bf07cb25089f_key:-}" ] || [ -z "${encrypted_bf07cb25089f_iv:-}" ] ; then
33-
echo >&2 'ERROR: encrypted_bf07cb25089f_key or encrypted_bf07cb25089f_iv were not defined!'
33+
if [ -z "$VAULT_PASSWORD" ]; then
34+
echo >&2 "ERROR: env variable VAULT_PASSWORD is empty!"
3435
exit 1
3536
fi
3637

3738
# Decrypt private key
38-
openssl aes-256-cbc -K "$encrypted_bf07cb25089f_key" -iv "$encrypted_bf07cb25089f_iv" -in "$PRIVATE_KEY.enc" -out "$PRIVATE_KEY" -d
39+
echo -n "$VAULT_PASSWORD" >"$PASS_FILE"
40+
41+
ansible-vault decrypt \
42+
--vault-password-file "$PASS_FILE" \
43+
--output "$PRIVATE_KEY" \
44+
"${PRIVATE_KEY}.enc"
45+
3946
chmod 600 "$PRIVATE_KEY"
4047

4148
ansible-playbook \

0 commit comments

Comments
 (0)