Skip to content
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

fix: decryption shells #282

Merged
merged 3 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/tf_sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ jobs:
arg_backend_config: ${{ contains(matrix.dir, 'bucket') && format('backend/{0}.tfbackend', matrix.env) || '' }}
arg_var_file: ${{ contains(matrix.dir, 'instance') && format('env/{0}.tfvars', matrix.env) || '' }}
arg_workspace: ${{ matrix.env }}
encrypt_passphrase: ${{ secrets.TF_ENCRYPTION }}
arg_or_create: true
cache_plugins: true
encrypt_passphrase: ${{ secrets.TF_ENCRYPTION }}
60 changes: 21 additions & 39 deletions action.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,52 +290,34 @@ module.exports = async ({ context, core, exec, github }) => {
});

// Download and unzip the TF plan artifact.
await exec.exec("curl", [
"--no-progress-meter",
"--location",
download_artifact.url,
"--output",
tf_identifier,
await exec.exec("/bin/bash", [
"-c",
`curl --no-progress-meter --location ${download_artifact.url} --output ${tf_identifier}`,
]);
await exec.exec("unzip", [
tf_identifier,
"-d",
process.env.arg_chdir.replace(/^-chdir=/, ""),
await exec.exec("/bin/bash", [
"-c",
`unzip ${tf_identifier} -d ${process.env.arg_chdir.replace(/^-chdir=/, "")}`,
]);

// Decrypt the TF plan file if encrypted.
if (process.env.encrypt_passphrase) {
const working_directory = [
process.env.arg_chdir.replace(/^-chdir=/, ""),
process.env.arg_out.replace(/^-out=/, ""),
].join("/");

await exec.exec("/bin/bash", ["-c", "TEMP_FILE=$(mktemp)"]);
await exec.exec("printf", ["%s", process.env.encrypt_passphrase, `> "$TEMP_FILE"`]);
await exec.exec("openssl", [
"enc",
"-aes-256-ctr",
"-pbkdf2",
"-salt",
"-in",
[
process.env.arg_chdir.replace(/^-chdir=/, ""),
process.env.arg_out.replace(/^-out=/, ""),
].join("/"),
"-out",
[
process.env.arg_chdir.replace(/^-chdir=/, ""),
`${process.env.arg_out.replace(/^-out=/, "")}.decrypted`,
].join("/"),
"-pass",
"file:$TEMP_FILE",
"-d",
await exec.exec("/bin/bash", [
"-c",
`printf %s "${process.env.encrypt_passphrase}" > "$TEMP_FILE"`,
]);

await exec.exec("mv", [
[
process.env.arg_chdir.replace(/^-chdir=/, ""),
`${process.env.arg_out.replace(/^-out=/, "")}.decrypted`,
].join("/"),
[
process.env.arg_chdir.replace(/^-chdir=/, ""),
process.env.arg_out.replace(/^-out=/, ""),
].join("/"),
await exec.exec("/bin/bash", [
"-c",
`openssl enc -aes-256-ctr -pbkdf2 -salt -in "${working_directory}" -out "${working_directory}.decrypted" -pass file:"$TEMP_FILE" -d`,
]);
await exec.exec("/bin/bash", [
"-c",
`mv ${working_directory}.decrypted ${working_directory}`,
]);
}
}
Expand Down
Loading