-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(e2e): Add infra for ssh certificate injection test
- Loading branch information
Showing
6 changed files
with
174 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
enos/modules/docker_openssh_server_ca_key/custom-cont-init.d/00-trust-user-ca
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/with-contenv bash | ||
|
||
cp /ca/ca-key.pub /etc/ssh/ca-key.pub | ||
chown 1000:1000 /etc/ssh/ca-key.pub | ||
chmod 644 /etc/ssh/ca-key.pub | ||
echo TrustedUserCAKeys /etc/ssh/ca-key.pub >> /etc/ssh/sshd_config | ||
echo PermitTTY yes >> /etc/ssh/sshd_config | ||
sed -i 's/X11Forwarding no/X11Forwarding yes/' /etc/ssh/sshd_config | ||
echo "X11UseLocalhost no" >> /etc/ssh/sshd_config | ||
|
||
apk update | ||
apk add xterm util-linux dbus ttf-freefont xauth firefox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# Copyright (c) HashiCorp, Inc. | ||
# SPDX-License-Identifier: MPL-2.0 | ||
|
||
terraform { | ||
required_providers { | ||
docker = { | ||
source = "kreuzwerker/docker" | ||
version = "3.0.1" | ||
} | ||
|
||
tls = { | ||
source = "hashicorp/tls" | ||
version = "4.0.4" | ||
} | ||
|
||
enos = { | ||
source = "app.terraform.io/hashicorp-qti/enos" | ||
} | ||
} | ||
} | ||
|
||
variable "image_name" { | ||
description = "Name of Docker Image" | ||
type = string | ||
default = "docker.mirror.hashicorp.services/linuxserver/openssh-server:latest" | ||
} | ||
variable "network_name" { | ||
description = "Name of Docker Network" | ||
type = string | ||
} | ||
variable "container_name" { | ||
description = "Name of Docker Container" | ||
type = string | ||
default = "openssh-server" | ||
} | ||
variable "target_user" { | ||
description = "SSH username for target" | ||
type = string | ||
default = "ubuntu" | ||
} | ||
variable "private_key_file_path" { | ||
description = "Local Path to key used to SSH onto created hosts" | ||
type = string | ||
} | ||
|
||
data "tls_public_key" "host_key_openssh" { | ||
private_key_openssh = file(var.private_key_file_path) | ||
} | ||
|
||
locals { | ||
public_key = data.tls_public_key.host_key_openssh.public_key_openssh | ||
} | ||
|
||
resource "docker_image" "openssh_server" { | ||
name = var.image_name | ||
keep_locally = true | ||
} | ||
|
||
resource "docker_container" "openssh_server" { | ||
image = docker_image.openssh_server.image_id | ||
name = var.container_name | ||
env = [ | ||
"PUID=1000", | ||
"PGID=1000", | ||
"TZ=US/Eastern", | ||
"USER_NAME=${var.target_user}", | ||
"PUBLIC_KEY=${local.public_key}", | ||
] | ||
networks_advanced { | ||
name = var.network_name | ||
} | ||
ports { | ||
internal = 2222 | ||
external = 2222 | ||
} | ||
volumes { | ||
host_path = format("%s/%s", abspath(path.module), "/custom-cont-init.d") | ||
container_path = "/custom-cont-init.d" | ||
} | ||
volumes { | ||
host_path = format("%s/%s", abspath(path.module), "/ca") | ||
container_path = "/ca" | ||
} | ||
} | ||
|
||
resource "enos_local_exec" "wait" { | ||
depends_on = [ | ||
docker_container.openssh_server | ||
] | ||
|
||
inline = ["timeout 20s bash -c 'until ssh -t -t -i ${var.private_key_file_path} -p 2222 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o IdentitiesOnly=yes ${var.target_user}@localhost hostname; do sleep 2; done'"] | ||
} | ||
|
||
output "user" { | ||
value = var.target_user | ||
} | ||
|
||
output "address" { | ||
value = docker_container.openssh_server.network_data[0].ip_address | ||
} | ||
|
||
output "port" { | ||
value = "2222" | ||
} | ||
|
||
output "ca_dir" { | ||
value = format("%s/%s", abspath(path.module), "/ca") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters