# SSH config for the bujang-mila clusters
#
# bujang runs everything with `ssh <alias>` from your machine. The aliases below match
# `ssh:` in clusters.yaml and the ssh executor hosts in nodes/*.yaml.
#
# Install it with
#   bujang ssh install --plugin mila --set MILA_USER=<mila username> --set ALLIANCE_USER=<alliance username>
#   MILA_USER       your Mila username (also used for Lynx)
#   ALLIANCE_USER   your Alliance (CCDB) username
#
# The compute nodes (cn-*, lg*, trig*) are reached through their login node, see the end.
#
# bujang needs ssh to work without prompts. The clusters with MFA use ControlMaster:
# run `ssh <alias>` once in a terminal, complete the MFA, and bujang reuses that
# connection until ControlPersist expires.

# ── Mila ────────────────────────────────────────────────────────────────────

Host mila
    HostName login.server.mila.quebec
    Port 2222
    User MILA_USER
    IdentityFile ~/.ssh/id_ed25519
    PreferredAuthentications publickey,keyboard-interactive
    ControlMaster auto
    ControlPath ~/.ssh/cm-%r@%h:%p
    ControlPersist 168h
    ServerAliveInterval 120
    ServerAliveCountMax 5
    ConnectTimeout 60

# ── Digital Research Alliance of Canada ─────────────────────────────────────

Host rorqual
    HostName rorqual.alliancecan.ca

Host fir
    HostName fir.alliancecan.ca

Host tamia
    HostName tamia.alliancecan.ca

Host nibi
    HostName nibi.alliancecan.ca

# Trillium has one login node per sub-cluster
Host trillium
    HostName trillium.alliancecan.ca

Host gpu-trillium
    HostName trillium-gpu.alliancecan.ca

# Trillium data mover (internet access), used by ssh steps; reached through the GPU login node
Host tri-dm1
    HostName tri-dm1.scinet.utoronto.ca
    ProxyJump gpu-trillium

# Shared settings for the Alliance hosts (ssh uses the first value it finds for each option,
# so the per-host blocks above can override any of these)
Host rorqual fir tamia nibi trillium gpu-trillium tri-dm1
    User ALLIANCE_USER
    IdentityFile ~/.ssh/id_ed25519
    ControlMaster auto
    ControlPath ~/.ssh/cm-%r@%h:%p
    ControlPersist 168h
    ServerAliveInterval 60
    ServerAliveCountMax 3

# ── Lynx ────────────────────────────────────────────────────────────────────

Host lynx
    # login node lynx1.lynx.stacc.site
    HostName 132.219.137.82
    Port 22
    User MILA_USER
    IdentityFile ~/.ssh/id_ed25519
    ControlMaster auto
    ControlPath ~/.ssh/cm-%r@%h:%p
    ControlPersist 168h
    ServerAliveInterval 120
    ServerAliveCountMax 5
    ConnectTimeout 60

# ── Compute nodes ───────────────────────────────────────────────────────────
#
# `ssh <node>` from your machine, through the login node: the node needs no internet, only the
# login node reaches it. bujang's early sync uses it to rsync the results of a running job
# (`rsync <node>:<path> ...`, the node is slurm's batch_host: the short name, cn-l008).
# The clusters only let you in a node while one of your jobs runs on it (pam_slurm_adopt), and
# your key in ~/.ssh/authorized_keys of the cluster home (shared with the nodes) is the one used.
# The node host keys are accepted the first time (no prompt: bujang cannot answer one).
# The `!*.*` keeps the short-name patterns off the full names (cn-l008.server.mila.quebec).

# Mila: cn-l008 (or cn-l008.server.mila.quebec), through the Mila login node
Host cn-* dn-* !*.*
    HostName %h.server.mila.quebec
Host cn-* dn-* cn-*.server.mila.quebec dn-*.server.mila.quebec
    User MILA_USER
    ProxyJump mila

# Lynx: lg01101 (or lg01101.lynx.stacc.site), through the Lynx login node
Host lg* !*.*
    HostName %h.lynx.stacc.site
Host lg* lg*.lynx.stacc.site
    User MILA_USER
    ProxyJump lynx

# Trillium GPU: trig0106 (the login node resolves the short name)
Host trig*
    User ALLIANCE_USER
    ProxyJump gpu-trillium

Host cn-* dn-* lg* trig* cn-*.server.mila.quebec dn-*.server.mila.quebec lg*.lynx.stacc.site
    IdentityFile ~/.ssh/id_ed25519
    StrictHostKeyChecking accept-new
    ServerAliveInterval 60
    ServerAliveCountMax 3
    ConnectTimeout 60
