Skip to content

Commit c6f82e0

Browse files
authored
Improve SSH experience (#2)
Improve SSH
2 parents c3ea1a7 + aa3c661 commit c6f82e0

File tree

7 files changed

+27
-17
lines changed

7 files changed

+27
-17
lines changed

.spin.example.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
server_timezone: "Etc/UTC"
66
server_contact: [email protected]
77

8-
# SSH
8+
# If you the SSH port below, you may need to run `spin provision -p <your-default-ssh-port>`
9+
# to get a connection on your first provision. Otherwise, SSH will try connecting
10+
# to your new port before the SSH server configuration is updated.
911
ssh_port: "22"
1012

1113
## Email Notifications
@@ -58,4 +60,4 @@ docker_user:
5860
# groups: ['adm','sudo']
5961
# shell: "/bin/bash"
6062
# authorized_keys:
61-
# - public_key: "ssh-ed25519 AAAAC3NzaC1anotherfakekeyIMVIzwQXBzxxD9b8Erd1FKVvu bob"
63+
# - public_key: "ssh-ed25519 AAAAC3NzaC1anotherfakekeyIMVIzwQXBzxxD9b8Erd1FKVvu bob"

.vscode/settings.json

-5
This file was deleted.

playbooks/provision.yml

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
---
22
- name: Setup and provision Docker Swarm servers with Spin.
3-
hosts: '{{ target | default("all") }}'
4-
remote_user: '{{ remote_user | default("root") }}'
3+
hosts: "{{ target | default('all') }}"
4+
remote_user: "{{ ansible_user | default('root') }}"
55
become: true
66
vars:
7+
ansible_port: "{{ ssh_port }}"
78
ansible_ssh_common_args: "-o IgnoreUnknown=UseKeychain"
8-
pre_tasks:
9-
- name: Set ansible_ssh_port
10-
set_fact:
11-
ansible_ssh_port: "{{ ssh_port }}"
129
roles:
1310
- serversideup.spin.linux_common
1411
- serversideup.spin.swarm

roles/linux_common/defaults/main.yml

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ server_contact: [email protected]
99
ssh_port: "22"
1010
ssh_permit_root_login: "no"
1111
ssh_password_authentication: "no"
12+
ssh_allow_tcp_forwarding: "yes"
13+
ssh_gateway_ports: "yes"
1214

1315

1416
## Email Notifications

roles/linux_common/tasks/security.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
- name: Ensure secure SSH config is up to date.
1+
- name: Ensure SSH configurations are up to date.
22
ansible.builtin.template:
3-
src: "etc/ssh/sshd_config.d/spin-secure-ssh.conf.j2"
4-
dest: "/etc/ssh/sshd_config.d/spin-secure-ssh.conf"
3+
src: "etc/ssh/sshd_config.d/{{ item }}.j2"
4+
dest: "/etc/ssh/sshd_config.d/{{ item }}"
55
owner: root
66
group: root
77
mode: 0644
88
notify: Restart ssh
9+
with_items:
10+
- spin-secure-ssh.conf
11+
- spin-ssh-tunnels.conf
912

1013
- name: Open the firewall port for SSH.
1114
community.general.ufw:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# {{ ansible_managed }}
2+
AllowTcpForwarding {{ ssh_allow_tcp_forwarding }}
3+
GatewayPorts {{ ssh_gateway_ports }}

roles/swarm/tasks/configure-docker-user.yml

+9-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,12 @@
2121
state: present
2222
key: "{{ item }}"
2323
with_items: "{{ docker_user.authorized_ssh_keys }}"
24-
when: docker_user.authorized_ssh_keys is defined
24+
when: docker_user.authorized_ssh_keys is defined
25+
26+
- name: Add public keys of admin or sudo users to Docker user
27+
ansible.posix.authorized_key:
28+
user: "{{ docker_user.username }}"
29+
state: present
30+
key: "{{ item.authorized_keys.0.public_key }}"
31+
loop: "{{ users }}"
32+
when: "'adm' in item.groups or 'sudo' in item.groups"

0 commit comments

Comments
 (0)