]> birchwood-abbey.net Git - Institute/commitdiff
Replace Secret/ssh_front/ with private/front_ed25519_key.pub.
authorMatt Birkholz <matt@birchwood-abbey.net>
Tue, 16 Dec 2025 21:57:13 +0000 (14:57 -0700)
committerMatt Birkholz <matt@birchwood-abbey.net>
Tue, 16 Dec 2025 21:57:13 +0000 (14:57 -0700)
Treating Front's SSH host key like a WireGuard™ keypair.  The secret
key never leaves the machine.

Though =Secret/ssh_front/= is "replaced" by one pubkey, it contained 3
useful example/test SSH host keypairs.  These were moved to
=private/front_ssh/=, and the one pubkey symlinked to the
corresponding key in this directory.

13 files changed:
README.org
inst
private/front_ed25519_key.pub [new symlink]
private/front_ssh/ssh_host_ecdsa_key [moved from Secret/ssh_front/etc/ssh/ssh_host_ecdsa_key with 100% similarity]
private/front_ssh/ssh_host_ecdsa_key.pub [moved from Secret/ssh_front/etc/ssh/ssh_host_ecdsa_key.pub with 100% similarity]
private/front_ssh/ssh_host_ed25519_key [moved from Secret/ssh_front/etc/ssh/ssh_host_ed25519_key with 100% similarity]
private/front_ssh/ssh_host_ed25519_key.pub [moved from Secret/ssh_front/etc/ssh/ssh_host_ed25519_key.pub with 100% similarity]
private/front_ssh/ssh_host_rsa_key [moved from Secret/ssh_front/etc/ssh/ssh_host_rsa_key with 100% similarity]
private/front_ssh/ssh_host_rsa_key.pub [moved from Secret/ssh_front/etc/ssh/ssh_host_rsa_key.pub with 100% similarity]
private/test-front-prep
roles_t/core/tasks/main.yml
roles_t/front/handlers/main.yml
roles_t/front/tasks/main.yml

index e1b2fb838db546e221e012ecba8dbe155170bc2a..63521cdffe5f0e56e9da3946c116250981a3099f 100644 (file)
@@ -418,10 +418,6 @@ institute's SSH keys:
     Administrator.
   - [[file:Secret/ssh_monkey/][=Secret/ssh_monkey/=]] :: The key pair used by Monkey to update the
     website on Front (and other unprivileged tasks).
-  - [[file:Secret/ssh_front/][=Secret/ssh_front/=]] :: The host key pair used by Front to
-    authenticate itself.  The automatically generated key pair is
-    /not/ used.  (Thus Core's configuration does not depend on
-    Front's.)
 
 The institute uses a couple X.509 certificates to authenticate
 servers.  They are created by the EasyRSA Certificate Authority stored
@@ -876,25 +872,6 @@ file, copied it to the droplet, and installed it as the
 : notebook$ rm admin_keys
 : notebook$
 
-The Ansible configuration expects certain host keys on the new front.
-The administrator should install them now, and deal with the machine's
-change of SSH identity.  The following commands copied the host keys
-in =Secret/ssh_front/= to the droplet and restarted the SSH server.
-
-: notebook$ ( cd Secret/ssh_front/etc/ssh/;
-: notebook_   scp ssh_host_* sysadm@159.65.75.60: )
-: notebook$ ssh sysadm@159.65.75.60
-: sysadm@ubuntu$ chmod 600 ssh_host_*
-: sysadm@ubuntu$ chmod 644 ssh_host_*.pub
-: sysadm@ubuntu$ sudo cp -b ssh_host_* /etc/ssh/
-: sysadm@ubuntu$ sudo systemctl restart ssh
-: sysadm@ubuntu$ logout
-: notebook$ ssh-keygen -f ~/.ssh/known_hosts -R 159.65.75.60
-
-The last command removed the old host key from the administrator's
-=known_hosts= file.  The next few commands served to test
-password-less login as well as the privilege escalation command
-~sudo~.
 
 The Droplet needed a couple additional software packages immediately.
 The ~wireguard~ package was needed to generate the Droplet's private
@@ -932,6 +909,12 @@ were indeed denied.
 : notebook$ ssh root@159.65.75.60
 : root@159.65.75.60: Permission denied (publickey).
 : notebook$ 
+Finally, the new machine's ssh public host is copied to
+=private/front_ed25519_key.pub=.
+
+: notebook$ scp sysadm@$H:/etc/ssh/ssh_host_ed25519_key.pub \
+: notebook_     private/front_ed25519_key.pub
+: notebook$
 
 At this point the droplet was ready for configuration by Ansible.
 Later, provisioned with all of Front's services /and/ tested, the
@@ -1424,42 +1407,6 @@ these groups speeds up debugging.
     groups: root,adm
 #+END_SRC
 
-** Configure SSH
-
-The SSH service on Front needs to be known to Monkey.  The following
-tasks ensure this by replacing the automatically generated keys with
-those stored in [[file:Secret/ssh_front/etc/ssh/][=Secret/ssh_front/etc/ssh/=]] and restarting the server.
-
-#+CAPTION: [[file:roles_t/front/tasks/main.yml][=roles_t/front/tasks/main.yml=]]
-#+BEGIN_SRC conf :tangle roles_t/front/tasks/main.yml
-
-- name: Install SSH host keys.
-  become: yes
-  copy:
-    src: ../Secret/ssh_front/etc/ssh/{{ item.name }}
-    dest: /etc/ssh/{{ item.name }}
-    mode: "{{ item.mode }}"
-  loop:
-  - { name: ssh_host_ecdsa_key,       mode: "u=rw,g=,o=" }
-  - { name: ssh_host_ecdsa_key.pub,   mode: "u=rw,g=r,o=r" }
-  - { name: ssh_host_ed25519_key,     mode: "u=rw,g=,o=" }
-  - { name: ssh_host_ed25519_key.pub, mode: "u=rw,g=r,o=r" }
-  - { name: ssh_host_rsa_key,         mode: "u=rw,g=,o=" }
-  - { name: ssh_host_rsa_key.pub,     mode: "u=rw,g=r,o=r" }
-  notify: Reload SSH server.
-#+END_SRC
-
-#+CAPTION: [[file:roles_t/front/handlers/main.yml][=roles_t/front/handlers/main.yml=]]
-#+BEGIN_SRC conf :tangle roles_t/front/handlers/main.yml :mkdirp yes
----
-- name: Reload SSH server.
-  become: yes
-  systemd:
-    service: ssh
-    state: reloaded
-  tags: actualizer
-#+END_SRC
-
 ** Configure Monkey
 
 The small institute runs cron jobs and web scripts that generate
@@ -1720,8 +1667,8 @@ start and enable the service.
 #+END_SRC
 
 #+CAPTION: [[file:roles_t/front/handlers/main.yml][=roles_t/front/handlers/main.yml=]]
-#+BEGIN_SRC conf :tangle roles_t/front/handlers/main.yml
-
+#+BEGIN_SRC conf :tangle roles_t/front/handlers/main.yml :mkdirp yes
+---
 - name: Restart Postfix.
   become: yes
   systemd:
@@ -2921,11 +2868,9 @@ described in [[apache2-core][*Configure Apache2]]).
 - name: Configure Monkey SSH known hosts.
   become: yes
   vars:
-    pubkeypath: ../Secret/ssh_front/etc/ssh
-    pubkeyfile: "{{ pubkeypath }}/ssh_host_ecdsa_key.pub"
-    pubkey: "{{ lookup('file', pubkeyfile) }}"
+    pubkey: "{{ lookup('file', '../private/front_ed25519_key.pub') }}"
   lineinfile:
-    regexp: "^{{ domain_name }},{{ front_addr }} ecdsa-sha2-nistp256 "
+    regexp: "^{{ domain_name }},{{ front_addr }} ssh-ed25519 "
     line: "{{ domain_name }},{{ front_addr }} {{ pubkey }}"
     path: /home/monkey/.ssh/known_hosts
     create: yes
@@ -6087,10 +6032,6 @@ if (defined $ARGV[0] && $ARGV[0] eq "CA") {
   mysystem "echo 'HashKnownHosts  no' >Secret/ssh_monkey/config";
   mysystem ("ssh-keygen -q -t rsa -C monkey\@core",
            "-N '' -f Secret/ssh_monkey/id_rsa");
-
-  mysystem "mkdir Secret/ssh_front";
-  chmod 0700, "Secret/ssh_front";
-  mysystem "ssh-keygen -A -f Secret/ssh_front -C $dom";
   exit;
 }
 #+END_SRC
@@ -7239,10 +7180,9 @@ networks.  If ~USER@SERVER~ is such an account, the script would be
 copied and executed thusly:
 
 : notebook$ scp private/test-front-prep USER@SERVER:
-: notebook$ scp -r Secret/ssh_front/ USER@SERVER:
+: notebook$ scp -r private/front_ssh/ USER@SERVER:
 
 : sysadm@front$ scp USER@SERVER:test-front-prep ./
-: sysadm@front$ scp -r USER@SERVER:ssh_front/ ./
 : sysadm@front$ ./test-front-prep
 
 The script starts by installing additional software packages.  The
@@ -7321,19 +7261,16 @@ iface enp0s8 inet static
 EOF
 #+END_SRC
 
-Ansible expects ~front~ to use the SSH host keys in
-=Secret/ssh_front/=, so it is prepared with these keys in advance.
-(If Ansible installed them, ~front~ would change identities while
-Ansible was configuring it.  Ansible would lose subsequent access
-until the administrator's =~/.ssh/known_hosts= was updated!)
+Ansible expects =private/front_ed25519_key.pub= to be the SSH host key
+in use on ~front~, so it is prepared with a set of test keys in
+advance.  Doing so now avoids ~front~ changing identities while
+Ansible is configuring it (if Ansible were to install the test
+identities).
 
 #+CAPTION: [[file:private/test-front-prep][=private/test-front-prep=]]
 #+BEGIN_SRC sh :tangle private/test-front-prep
 
-( cd ssh_front/etc/ssh/
-  chmod 600 ssh_host_*
-  chmod 644 ssh_host_*.pub
-  sudo cp -b ssh_host_* /etc/ssh/ )
+( cd front_ssh/; sudo cp -b ssh_host_* /etc/ssh/ )
 #+END_SRC
 
 With the preparatory script successfully executed, ~front~ is shut
diff --git a/inst b/inst
index 7d44a6d98a3c8bbc5db5d7b1efe1bba22696dca0..4f6b5c4e3a732dc5b299e73a0800f2f8a0e5969b 100755 (executable)
--- a/inst
+++ b/inst
@@ -110,10 +110,6 @@ if (defined $ARGV[0] && $ARGV[0] eq "CA") {
   mysystem "echo 'HashKnownHosts  no' >Secret/ssh_monkey/config";
   mysystem ("ssh-keygen -q -t rsa -C monkey\@core",
            "-N '' -f Secret/ssh_monkey/id_rsa");
-
-  mysystem "mkdir Secret/ssh_front";
-  chmod 0700, "Secret/ssh_front";
-  mysystem "ssh-keygen -A -f Secret/ssh_front -C $dom";
   exit;
 }
 
diff --git a/private/front_ed25519_key.pub b/private/front_ed25519_key.pub
new file mode 120000 (symlink)
index 0000000..c5a6af1
--- /dev/null
@@ -0,0 +1 @@
+front_ssh/ssh_host_ed25519_key.pub
\ No newline at end of file
index ab3ca3873d00aa9bfdd0f2936ba1a8f539a0b11e..69d1cb4814aca64eb933bc4543177dfd592ffab4 100755 (executable)
@@ -48,7 +48,4 @@ iface enp0s8 inet static
     address 192.168.58.3/24
 EOF
 
-( cd ssh_front/etc/ssh/
-  chmod 600 ssh_host_*
-  chmod 644 ssh_host_*.pub
-  sudo cp -b ssh_host_* /etc/ssh/ )
+( cd front_ssh/; sudo cp -b ssh_host_* /etc/ssh/ )
index 125b43b4f8a37b9cfb82d1c0d900b865c92cbef2..90e0b8a525c78c81df7f90d2f0fec6032a5fcc7d 100644 (file)
 - name: Configure Monkey SSH known hosts.
   become: yes
   vars:
-    pubkeypath: ../Secret/ssh_front/etc/ssh
-    pubkeyfile: "{{ pubkeypath }}/ssh_host_ecdsa_key.pub"
-    pubkey: "{{ lookup('file', pubkeyfile) }}"
+    pubkey: "{{ lookup('file', '../private/front_ed25519_key.pub') }}"
   lineinfile:
-    regexp: "^{{ domain_name }},{{ front_addr }} ecdsa-sha2-nistp256 "
+    regexp: "^{{ domain_name }},{{ front_addr }} ssh-ed25519 "
     line: "{{ domain_name }},{{ front_addr }} {{ pubkey }}"
     path: /home/monkey/.ssh/known_hosts
     create: yes
index 21f962a4a13b013e710d48af8f8c8ac961762008..3b46b633d43998a6dcb87b9508c1d6b149d132ec 100644 (file)
@@ -1,11 +1,4 @@
 ---
-- name: Reload SSH server.
-  become: yes
-  systemd:
-    service: ssh
-    state: reloaded
-  tags: actualizer
-
 - name: Restart Postfix.
   become: yes
   systemd:
index 5c73f967c63955709196763849ccaaf63715e0cd..24809dd1948399ed33837e8940e60082813a16c4 100644 (file)
     append: yes
     groups: root,adm
 
-- name: Install SSH host keys.
-  become: yes
-  copy:
-    src: ../Secret/ssh_front/etc/ssh/{{ item.name }}
-    dest: /etc/ssh/{{ item.name }}
-    mode: "{{ item.mode }}"
-  loop:
-  - { name: ssh_host_ecdsa_key,       mode: "u=rw,g=,o=" }
-  - { name: ssh_host_ecdsa_key.pub,   mode: "u=rw,g=r,o=r" }
-  - { name: ssh_host_ed25519_key,     mode: "u=rw,g=,o=" }
-  - { name: ssh_host_ed25519_key.pub, mode: "u=rw,g=r,o=r" }
-  - { name: ssh_host_rsa_key,         mode: "u=rw,g=,o=" }
-  - { name: ssh_host_rsa_key.pub,     mode: "u=rw,g=r,o=r" }
-  notify: Reload SSH server.
-
 - name: Create monkey.
   become: yes
   user: