Skip to content

Commit da091b4

Browse files
committed
Revert "deploy_nixos: add ssh_private_key (#37)"
This reverts commit 5761c05. This was not ready
1 parent 5761c05 commit da091b4

File tree

3 files changed

+9
-21
lines changed

3 files changed

+9
-21
lines changed

deploy_nixos/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ see also:
108108
| keys | A map of filename to content to upload as secrets in /var/keys | `map(string)` | `{}` | no |
109109
| nixos\_config | Path to a NixOS configuration | `string` | `""` | no |
110110
| ssh\_agent | Whether to use an SSH agent | `bool` | `true` | no |
111-
| ssh\_private\_key | Content of private key used to connect to the target\_host. Ignored if empty. | `string` | `""` | no |
112111
| ssh\_private\_key\_file | Path to private key used to connect to the target\_host. Ignored if `-` or empty. | `string` | `"-"` | no |
113112
| target\_host | DNS host to deploy to | `any` | n/a | yes |
114113
| target\_port | SSH port used to connect to the target\_host | `number` | `22` | no |

deploy_nixos/main.tf

+2-8
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ variable "target_port" {
1313
default = 22
1414
}
1515

16-
variable "ssh_private_key" {
17-
description = "Content of private key used to connect to the target_host. Ignored if empty."
18-
default = ""
19-
}
20-
2116
variable "ssh_private_key_file" {
2217
description = "Path to private key used to connect to the target_host. Ignored if `-` or empty."
2318
default = "-"
@@ -100,7 +95,6 @@ locals {
10095
var.extra_build_args,
10196
)
10297
ssh_private_key_file = var.ssh_private_key_file == "" ? "-" : var.ssh_private_key_file
103-
ssh_private_key = local.ssh_private_key_file == "-" ? null : file(local.ssh_private_key_file)
10498
build_on_target = data.external.nixos-instantiate.result["currentSystem"] != var.target_system ? true : tobool(var.build_on_target)
10599
}
106100

@@ -129,7 +123,7 @@ resource "null_resource" "deploy_nixos" {
129123
user = var.target_user
130124
agent = var.ssh_agent
131125
timeout = "100s"
132-
private_key = local.ssh_private_key
126+
private_key = local.ssh_private_key_file != "-" ? file(var.ssh_private_key_file) : null
133127
}
134128

135129
# copy the secret keys to the host
@@ -170,7 +164,7 @@ resource "null_resource" "deploy_nixos" {
170164
"${var.target_user}@${var.target_host}",
171165
var.target_port,
172166
local.build_on_target,
173-
local.ssh_private_key,
167+
local.ssh_private_key_file,
174168
"switch",
175169
],
176170
local.extra_build_args

deploy_nixos/nixos-deploy.sh

+7-12
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ buildArgs=(
1111
)
1212
profile=/nix/var/nix/profiles/system
1313
# will be set later
14+
controlPath=
1415
sshOpts=(
1516
-o "ControlMaster=auto"
1617
-o "ControlPersist=60"
@@ -31,7 +32,7 @@ outPath="$2"
3132
targetHost="$3"
3233
targetPort="$4"
3334
buildOnTarget="$5"
34-
sshPrivateKey="$6"
35+
sshPrivateKeyFile="$6"
3536
action="$7"
3637
shift 7
3738

@@ -41,13 +42,8 @@ buildArgs+=("$@")
4142

4243
sshOpts+=( -p "${targetPort}" )
4344

44-
workDir=$(mktemp -d)
45-
trap 'rm -rf "$workDir"' EXIT
46-
47-
if [[ -n "${sshPrivateKey}" ]]; then
48-
sshPrivateKeyFile="$workDir/ssh_key"
49-
echo "$sshPrivateKey" > "$sshPrivateKeyFile"
50-
sshOpts+=( -o "IdentityFile=${sshPrivateKeyFile}" )
45+
if [[ -n "${sshPrivateKeyFile}" && "${sshPrivateKeyFile}" != "-" ]]; then
46+
sshOpts+=( -o "IdentityFile=${sshPrivateKeyFile}" )
5147
fi
5248

5349
### Functions ###
@@ -66,17 +62,16 @@ targetHostCmd() {
6662
# `ssh` did not properly maintain the array nature of the command line,
6763
# erroneously splitting arguments with internal spaces, even when using `--`.
6864
# Tested with OpenSSH_7.9p1.
69-
#
70-
# shellcheck disable=SC2029
7165
ssh "${sshOpts[@]}" "$targetHost" "./maybe-sudo.sh ${*@Q}"
7266
}
7367

7468
# Setup a temporary ControlPath for this session. This speeds-up the
7569
# operations by not re-creating SSH sessions between each command. At the end
7670
# of the run, the session is forcefully terminated.
7771
setupControlPath() {
72+
controlPath=$(mktemp)
7873
sshOpts+=(
79-
-o "ControlPath=$workDir/ssh_control"
74+
-o "ControlPath=$controlPath"
8075
)
8176
cleanupControlPath() {
8277
local ret=$?
@@ -85,7 +80,7 @@ setupControlPath() {
8580
# Close ssh multiplex-master process gracefully
8681
log "closing persistent ssh-connection"
8782
ssh "${sshOpts[@]}" -O stop "$targetHost"
88-
rm -rf "$workDir"
83+
rm -f "$controlPath"
8984
exit "$ret"
9085
}
9186
trap cleanupControlPath EXIT

0 commit comments

Comments
 (0)