Skip to content

Pass SSH private key using env var #71

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions deploy_nixos/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,16 @@ resource "null_resource" "deploy_nixos" {
data.external.nixos-instantiate.result["out_path"],
"${var.target_user}@${var.target_host}",
var.target_port,
local.build_on_target,
local.ssh_private_key == "" ? "-" : local.ssh_private_key,
"switch",
var.delete_older_than,
],
local.extra_build_args
)
command = "ignoreme"
environment = {
BUILD_ON_TARGET = local.build_on_target
Copy link

@scottbot95 scottbot95 Apr 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making the ssh_private_key a environmnet variable makes sense to me to avoid sensitive data in the output, but why is build_on_target also being moved to an env var? I don't think there's necessary any reason it shouldn't be an env var, but I also see no reason to move it.

SSH_PRIVATE_KEY = local.ssh_private_key == "" ? "-" : local.ssh_private_key

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this will hide the key itself from output, a variable still marked as sensitive will cause the output to be suppressed. Might be worth wrapping this in nonsensitive() although that would require bumping the minimum required terraform version from 0.12 to 0.15. Also there should be nothing stopping callers from wrapping the key in nonsensitive() when they pass it to this module.

}
}
}

Expand Down
11 changes: 6 additions & 5 deletions deploy_nixos/nixos-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@ sshOpts=(
-v
)

buildOnTarget="${BUILD_ON_TARGET:-}"
sshPrivateKey="${SSH_PRIVATE_KEY:--}"

### Argument parsing ###

drvPath="$1"
outPath="$2"
targetHost="$3"
targetPort="$4"
buildOnTarget="$5"
sshPrivateKey="$6"
action="$7"
deleteOlderThan="$8"
shift 8
action="$5"
deleteOlderThan="$6"
shift 6

# remove the last argument
set -- "${@:1:$(($# - 1))}"
Expand Down