Ryan Cragun a087f7b267
[QT-627] enos: add pkcs11 seal testing with softhsm (#24349)
Add support for testing `+ent.hsm` and `+ent.hsm.fips1402` Vault editions
with `pkcs11` seal types utilizing a shared `softhsm` token. Softhsm2 is
a software HSM that will load seal keys from a local disk via pkcs11.
The pkcs11 seal implementation is fairly complex as we have to create a
one or more shared tokens with various keys and distribute them to all
nodes in the cluster before starting Vault. We also have to ensure that
each sets labels are unique.

We also make a few quality of life updates by utilizing globals for
variants that don't often change and update base versions for various
scenarios.

* Add `seal_pkcs11` module for creating a `pkcs11` seal key using
  `softhsm2` as our backing implementation.
* Require the latest enos provider to gain access to the `enos_user`
  resource to ensure correct ownership and permissions of the
  `softhsm2` data directory and files.
* Add `pkcs11` seal to all scenarios that support configuring a seal
  type.
* Extract system package installation out of the `vault_cluster` module
  and into its own `install_package` module that we can reuse.
* Fix a bug when using the local builder variant that mangled the path.
  This likely slipped in during the migration to auto-version bumping.
* Fix an issue where restarting Vault nodes with a socket seal would
  fail because a seal socket sync wasn't available on all nodes. Now we
  start the socket listener on all nodes to ensure any node can become
  primary and "audit" to the socket listner.
* Remove unused attributes from some verify modules.
* Go back to using cheaper AWS regions.
* Use globals for variants.
* Update initial vault version for `upgrade` and `autopilot` scenarios.
* Update the consul versions for all scenarios that support a consul
  storage backend.

Signed-off-by: Ryan Cragun <me@ryan.ec>
2023-12-08 14:00:45 -07:00

82 lines
1.6 KiB
HCL

# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: BUSL-1.1
terraform {
required_providers {
enos = {
source = "app.terraform.io/hashicorp-qti/enos"
version = ">= 0.4.9"
}
}
}
variable "hosts" {
type = map(object({
private_ip = string
public_ip = string
}))
description = "The hosts for whom default softhsm configuration will be applied"
}
variable "skip" {
type = bool
default = false
description = "Whether or not to skip initializing softhsm"
}
locals {
// The location on disk to write the softhsm tokens to
token_dir = "/var/lib/softhsm/tokens"
// Where the default configuration is
config_paths = {
"rhel" = "/etc/softhsm2.conf"
"ubuntu" = "/etc/softhsm/softhsm2.conf"
}
host_key = element(keys(enos_host_info.hosts), 0)
config_path = local.config_paths[enos_host_info.hosts[local.host_key].distro]
}
resource "enos_host_info" "hosts" {
for_each = var.hosts
transport = {
ssh = {
host = each.value.public_ip
}
}
}
resource "enos_remote_exec" "init_softhsm" {
for_each = var.hosts
depends_on = [enos_host_info.hosts]
environment = {
CONFIG_PATH = local.config_paths[enos_host_info.hosts[each.key].distro]
TOKEN_DIR = local.token_dir
SKIP = var.skip ? "true" : "false"
}
scripts = [abspath("${path.module}/scripts/init-softhsm.sh")]
transport = {
ssh = {
host = each.value.public_ip
}
}
}
output "config_path" {
// Technically this is actually just the first config path of our hosts.
value = local.config_path
}
output "token_dir" {
value = local.token_dir
}
output "skipped" {
value = var.skip
}