support multiple SSH CA key pairs

This commit is contained in:
Pim Kunis 2023-04-25 17:50:02 +02:00
parent 9866130719
commit 9c1aa00775
3 changed files with 33 additions and 26 deletions

View file

@ -2,11 +2,11 @@
set -euo pipefail
IFS=$'\n\t'
eval "$(jq -r '@sh "PUBKEY=\(.pubkey) HOST=\(.host) CAHOST=\(.cahost) CASCRIPT=\(.cascript)"')"
eval "$(jq -r '@sh "PUBKEY=\(.pubkey) HOST=\(.host) CAHOST=\(.cahost) CASCRIPT=\(.cascript) CAKEY=\(.cakey)"')"
# TODO: Can this be done more eye-pleasingly?
set +e
CERT=$(ssh -o ConnectTimeout=3 -o ConnectionAttempts=1 root@$CAHOST '"'"$CASCRIPT"'" host "'"$PUBKEY"'" "'"$HOST"'".dmz')
CERT=$(ssh -o ConnectTimeout=3 -o ConnectionAttempts=1 root@$CAHOST '"'"$CASCRIPT"'" "'"$CAKEY"'" host "'"$PUBKEY"'" "'"$HOST"'".dmz')
retval=$?
set -e

View file

@ -35,10 +35,11 @@ data "external" "cert" {
program = ["bash", "${path.module}/files/get_cert.sh"]
query = {
pubkey = trimspace(data.tls_public_key.debian.public_key_openssh)
host = var.name
cahost = var.ca_host
pubkey = trimspace(data.tls_public_key.debian.public_key_openssh)
host = var.name
cahost = var.ca_host
cascript = var.ca_script
cakey = var.ca_key
}
}
@ -53,7 +54,7 @@ resource "null_resource" "cert" {
]
postcondition {
condition = data.external.cert.result["cert"] != "" || !var.use_host_cert
condition = data.external.cert.result["cert"] != "" || !var.use_host_cert
error_message = "Error retrieving host certificate."
}
}

View file

@ -8,40 +8,46 @@ variable "admin_authorized_keys" {
}
variable "disk_pool" {
type = string
type = string
description = "Libvirt volume pool for the machine's main disk."
}
variable "disk_base" {
type = string
type = string
description = "Base image for the machine's operating system."
}
variable "disk_base_pool" {
type = string
type = string
description = "Libvirt volume pool for the base image of the machine's operating system."
}
variable "cloudinit_pool" {
type = string
type = string
description = "Libvirt volume pool for the machine's Cloud-init image."
}
variable "bridge_name" {
type = string
type = string
description = "Host bridge to connect the machine's network interface to."
}
variable "ca_host" {
type = string
type = string
description = "Host to contact when fetching a SSH host certificate."
}
variable "ca_script" {
type = string
type = string
description = "Script to call when fetching a SSH host certificate."
}
variable "ca_key" {
type = string
default = ""
description = "File name of the SSH CA key pair."
}
variable "domain_name" {
type = string
default = null
@ -61,32 +67,32 @@ variable "memory" {
}
variable "mac" {
type = string
default = null
type = string
default = null
description = "MAC address of the machine's network interface."
}
variable "insecure_password" {
type = bool
default = false
type = bool
default = false
description = "Whether to enable insecure password (for testing purposes). Allows logging in via SSH with `root:root` credentials."
}
variable "use_host_cert" {
type = bool
default = false
type = bool
default = false
description = "Whether this machine should receive a SSH host certificate."
}
variable "data_disk" {
type = string
default = null
type = string
default = null
description = "Identifier of the machine's persistent data disk."
}
variable "fixed_address" {
type = string
default = ""
type = string
default = ""
description = "Fixed IPv4 address the machine should have."
}
@ -96,7 +102,7 @@ variable "ansible_command" {
}
variable "fixed_dns" {
type = string
default = ""
type = string
default = ""
description = "Fixed DNS server the machine should have."
}