diff --git a/ansible/ansible.cfg b/ansible/ansible.cfg index cadb523..7d83dc2 100644 --- a/ansible/ansible.cfg +++ b/ansible/ansible.cfg @@ -10,8 +10,11 @@ retry_files_enabled = False interpreter_python = auto_silent # Facts only under ansible_facts, never as top-level variables. inject_facts_as_vars = False -# The VMs are recloned from images and get new host keys each time. -host_key_checking = False +# SSH checks each host key. The hub's key is recorded at the first connection +# (group_vars/hub.yml) and refused if it changes later. The VMs get new host +# keys at each reclone, so their connections turn the check off for the VM only +# (vm_inventory, lab_vm, client's ssh_config); the jump to the hub still checks. +host_key_checking = True [ssh_connection] pipelining = True diff --git a/ansible/group_vars/hub.yml b/ansible/group_vars/hub.yml new file mode 100644 index 0000000..6afd521 --- /dev/null +++ b/ansible/group_vars/hub.yml @@ -0,0 +1,6 @@ +--- +# The hub's SSH host key is recorded in ~/.ssh/known_hosts at the first +# connection, and a different key is refused later. To accept a key that changed +# on purpose, such as after a reinstall of the hub: +# ssh-keygen -R && ssh true +ansible_ssh_common_args: -o StrictHostKeyChecking=accept-new diff --git a/ansible/playbooks/lab.yml b/ansible/playbooks/lab.yml index a6913eb..a53fa02 100644 --- a/ansible/playbooks/lab.yml +++ b/ansible/playbooks/lab.yml @@ -158,6 +158,31 @@ roles: - vm_inventory +# The base images ship the VM's user with the password "admin". The lab logs +# in with its key and runs sudo with no password, so each run turns the +# password off on each running VM, a new clone too: "*" matches no password, +# and, unlike a lock ("!"), it leaves key login when sshd runs without PAM. To +# get into a VM that SSH cannot reach, use the tart guest agent on the hub: +# tart exec lab- +- name: VM accounts + hosts: vms + gather_facts: false + become: true + tags: [vms] + tasks: + - name: Turn off the password of the VM's user + when: lab_mode != 'stop' + ansible.builtin.shell: | + set -euo pipefail + if [ "$(getent shadow {{ lab_vm_user | quote }} | cut -d: -f2)" != '*' ]; then + usermod -p '*' {{ lab_vm_user | quote }} + echo changed + fi + args: + executable: /bin/bash + register: lab_vm_password + changed_when: "'changed' in lab_vm_password.stdout" + - name: Read the agents before a restart hosts: hub gather_facts: true diff --git a/ansible/roles/client/templates/ssh_config.j2 b/ansible/roles/client/templates/ssh_config.j2 index 0076ba1..a143858 100644 --- a/ansible/roles/client/templates/ssh_config.j2 +++ b/ansible/roles/client/templates/ssh_config.j2 @@ -12,7 +12,8 @@ Host {{ vm }} User {{ lab_vm_user }} IdentityFile {{ lab_ssh_key }} ProxyJump {{ (hub.ansible_user ~ '@') if hub.ansible_user is defined else '' }}{{ hub.ansible_host }} - # Recloned VMs get new host keys. + # Recloned VMs get new host keys, so the check is off for the VM only. The + # jump to the hub reads ~/.ssh/known_hosts and checks the hub's key. StrictHostKeyChecking no UserKnownHostsFile /dev/null LogLevel ERROR diff --git a/ansible/roles/jaeger/tasks/main.yml b/ansible/roles/jaeger/tasks/main.yml index ec865db..b810146 100644 --- a/ansible/roles/jaeger/tasks/main.yml +++ b/ansible/roles/jaeger/tasks/main.yml @@ -42,6 +42,15 @@ executable: /bin/bash changed_when: true +# The UI has no authentication, so it listens only on the hub's tailnet +# address. The receiver of the traces stays on each interface, because the VMs +# reach it on the vmnet bridge. +- name: Read the hub's tailnet address + ansible.builtin.command: "{{ lab_tailscale_cli }} ip -4" + register: jaeger_tailnet_ip + changed_when: false + check_mode: false + - name: Write the trace collector config ansible.builtin.template: src: jaeger.yaml.j2 @@ -49,6 +58,7 @@ mode: "0600" vars: hub_state: "{{ lab_hub_state_abs }}" + jaeger_ui_addr: "{{ jaeger_tailnet_ip.stdout_lines | first | trim }}" - name: Let the VMs reach the trace collector through the firewall ansible.builtin.include_role: diff --git a/ansible/roles/jaeger/templates/jaeger.yaml.j2 b/ansible/roles/jaeger/templates/jaeger.yaml.j2 index 6f3e651..3c0b284 100644 --- a/ansible/roles/jaeger/templates/jaeger.yaml.j2 +++ b/ansible/roles/jaeger/templates/jaeger.yaml.j2 @@ -1,7 +1,8 @@ # Jaeger for the lab, in memory. OTLP gRPC on every interface, so that the VMs -# and remote agents can send traces. The UI on every interface too, so that a -# machine on the tailnet can open it; it has no authentication. Both serve the -# hub's Tailscale certificate, as the controller's API does. +# and remote agents can send traces. The UI only on the hub's tailnet address, +# because it has no authentication: a machine on the tailnet can open it, and a +# machine on the hub's local network cannot. Both serve the hub's Tailscale +# certificate, as the controller's API does. service: extensions: [jaeger_storage, jaeger_query] pipelines: @@ -15,7 +16,7 @@ extensions: storage: traces: memstore http: - endpoint: 0.0.0.0:{{ lab_tracing_ui_port }} + endpoint: {{ jaeger_ui_addr }}:{{ lab_tracing_ui_port }} tls: cert_file: {{ hub_state }}/tls/api.crt key_file: {{ hub_state }}/tls/api.key diff --git a/ansible/roles/lab_vm/tasks/main.yml b/ansible/roles/lab_vm/tasks/main.yml index b615823..daadc01 100644 --- a/ansible/roles/lab_vm/tasks/main.yml +++ b/ansible/roles/lab_vm/tasks/main.yml @@ -94,7 +94,9 @@ tart_vm_groups: "{{ ['vms'] + (['vms_in_place'] if (lab_vm_in_place | bool) else []) }}" tart_vm_user: "{{ lab_vm_user }}" tart_vm_ssh_key: "{{ lab_ssh_key }}" - # The VMs are on the hub's vmnet subnet, reachable only through the hub. + # The VMs are on the hub's vmnet subnet, reachable only through the hub. A + # recloned VM has a new host key, so the check is off for the VM only; the + # jump to the hub uses ~/.ssh/known_hosts and checks the hub's key. tart_vm_ssh_args: >- -o ProxyJump={{ (ansible_user ~ '@') if ansible_user is defined else '' }}{{ ansible_host }} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null diff --git a/ansible/roles/vm_inventory/tasks/main.yml b/ansible/roles/vm_inventory/tasks/main.yml index 57a5754..7df1a66 100644 --- a/ansible/roles/vm_inventory/tasks/main.yml +++ b/ansible/roles/vm_inventory/tasks/main.yml @@ -29,6 +29,8 @@ ansible_host: "{{ item.stdout }}" ansible_user: "{{ lab_vm_user }}" ansible_ssh_private_key_file: "{{ lab_ssh_key }}" + # A recloned VM has a new host key, so the check is off for the VM only. + # The jump to the hub uses ~/.ssh/known_hosts and checks the hub's key. ansible_ssh_common_args: >- -o ProxyJump={{ (ansible_user ~ '@') if ansible_user is defined else '' }}{{ ansible_host }} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=5