Skip to content

Commit

Permalink
Merge pull request #19 from montblu/16-add-option-to-get-ssh-logs-to-…
Browse files Browse the repository at this point in the history
…stdout

Add option to get ssh logs to stdout
  • Loading branch information
pessoa authored Oct 10, 2024
2 parents 39bf801 + 9272ffc commit 793dc2a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ No modules.
| <a name="input_ssh_host_rsa_key"></a> [ssh\_host\_rsa\_key](#input\_ssh\_host\_rsa\_key) | Private key used by the OpenSSH server. If not defined it will generated automatically, but won't be saved. | `string` | `""` | no |
| <a name="input_ssh_host_rsa_key_public"></a> [ssh\_host\_rsa\_key\_public](#input\_ssh\_host\_rsa\_key\_public) | Public key used by the OpenSSH server. If not defined it will generated automatically, but won't be saved. | `string` | `""` | no |
| <a name="input_ssh_keys"></a> [ssh\_keys](#input\_ssh\_keys) | List of SSH keys to be added to the authorized keys list. Should be in the same format as the 'authorized\_keys' file, represented in Heredoc style as a multi-line string value. | `string` | n/a | yes |
| <a name="input_ssh_log_to_stdout"></a> [ssh\_log\_to\_stdout](#input\_ssh\_log\_to\_stdout) | If set to true it will log the SSH connection to stdout. | `bool` | `false` | no |
| <a name="input_ssh_port"></a> [ssh\_port](#input\_ssh\_port) | Specify the port that OpenSSH server will bind to. The port value can't be below 1024. If not defined it will use '2222' as default. | `number` | `2222` | no |
| <a name="input_ssh_user"></a> [ssh\_user](#input\_ssh\_user) | Specify a username to connect to. If not defined it will use 'user' as default. | `string` | `"user"` | no |
| <a name="input_sshd_config"></a> [sshd\_config](#input\_sshd\_config) | Configuration file for SSH. If not defined it will use the default. | `string` | `""` | no |
Expand Down
18 changes: 13 additions & 5 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ resource "kubernetes_config_map" "main" {
}

data = {
"authorized_keys" = var.ssh_keys
"motd" = "Welcome to ${var.motd_name}.\n"
"delete-generated-ssh-keys" = <<EOT
"authorized_keys" = var.ssh_keys
"motd" = "Welcome to ${var.motd_name}.\n"
"delete-generated-ssh-keys" = <<EOT
#!/bin/bash
echo "**** remove not needed ecdsa and ed25519 keys ****"
rm /config/ssh_host_keys/ssh_host_ecdsa*
Expand Down Expand Up @@ -129,7 +129,15 @@ resource "kubernetes_deployment" "main" {
env {
# Ref: https://github.com/linuxserver/docker-mods/tree/openssh-server-ssh-tunnel
name = "DOCKER_MODS"
value = "linuxserver/mods:openssh-server-ssh-tunnel"
value = "linuxserver/mods:openssh-server-ssh-tunnel${var.ssh_log_to_stdout ? "|linuxserver/mods:universal-stdout-logs" : ""}"
}

dynamic "env" {
for_each = var.ssh_log_to_stdout ? ["dummy"] : []
content {
name = "LOGS_TO_STDOUT"
value = "/config/logs/openssh/current" # OpenSSH logs
}
}

env {
Expand Down Expand Up @@ -157,7 +165,7 @@ resource "kubernetes_deployment" "main" {
name = "delete-generated-ssh-keys"
mount_path = "/custom-cont-init.d/delete-generated-ssh-keys"
sub_path = "delete-generated-ssh-keys"
read_only = true
read_only = true
}

volume_mount {
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ variable "ssh_port" {
description = "Specify the port that OpenSSH server will bind to. The port value can't be below 1024. If not defined it will use '2222' as default."
}

variable "ssh_log_to_stdout" {
type = bool
default = false
description = "If set to true it will log the SSH connection to stdout."
}

variable "image_repository" {
type = string
default = "linuxserver/openssh-server"
Expand Down

0 comments on commit 793dc2a

Please sign in to comment.