Skip to content

[Feature]: Let job images set the SSH crypto policy of the runner's sshd #4509

Open

Description

@andweng

Problem

The runner writes its own sshd_config for the job container (runner/internal/runner/ssh/sshd.go). It sets no Ciphers, MACs or KexAlgorithms and has no Include, so a job image can't set its SSH crypto policy. The job's sshd always negotiates OpenSSH's defaults.

The client side doesn't fill the gap. dstack attach runs ssh with its own -F config, so the client's system-wide settings (/etc/ssh/ssh_config, ssh_config.d/) aren't read either. On a client whose system-wide config allows only SHA-2 MACs, sessions to the job still came up with aes128-ctr / hmac-sha1 (dstack 0.22.6, OpenSSH 9.6p1 at both ends), while a plain ssh from the same client to the same sshd used AES-GCM.

Environments with a mandated SSH algorithm list (for example the DISA STIG for Ubuntu, which allows only hmac-sha2-512/hmac-sha2-256 MACs and their -etm forms, and AES-GCM/CTR ciphers) can't meet it for job sessions. On Kubernetes they can meet it for the jump pod hop, since that's an sshd the operator controls (#4508), but not for the hop to the job.

Solution

One of:

  1. Append Include /etc/ssh/sshd_config.d/*.conf at the end of the generated sshd_config. For each keyword sshd uses the first value it reads, so dstack's own settings (Port, AuthorizedKeysFile, PasswordAuthentication, ...) still win, and the image can only add settings dstack doesn't make, such as Ciphers, MACs and KexAlgorithms. Images that ship an sshd_config.d/ would start applying it, so this may need to be opt-in.
  2. A server or run setting, for example DSTACK_RUNNER_SSHD_EXTRA_CONFIG, whose lines the runner appends to the generated config.
  3. Have dstack attach and the generated SSH config include the client's system-wide ssh_config, or accept Ciphers/MACs/KexAlgorithms settings. That covers the client side only.

Option 1 is the smallest change, and it puts the policy in the image, next to the rest of the image's hardening.

Workaround

None for the job hop, short of patching the runner. The jump pod hop can be restricted with a custom jump pod image.

Would you like to help us implement this feature by sending a PR?

Yes, once there's agreement on the approach.

Activity

  1. peterschmidt85 commented on Nov 22, 2026

    @peterschmidt85
    Contributor
  2. un-def commented on Nov 30, 2026

    @un-def
    Collaborator

    Approach 1 (Include)

    For each keyword sshd uses the first value it reads, so dstack's own settings (Port, AuthorizedKeysFile, PasswordAuthentication, ...) still win, and the image can only add settings dstack doesn't make, such as Ciphers, MACs and KexAlgorithms.

    That's not quite true. Some options are additive, e.g, Port, ListenAddress, HostKey, AcceptEnv, {Allow,Deny}{Users,Groups}. Moreover, with Match directive, it's possible to override (almost?) any option, e.g.,

    # runner's sshd_config
    PermitRootLogin prohibit-password
    ...
    Include /path/to/conf.d/*.conf
    
    # no-root.conf
    # Ignored, runner's option wins
    PermitRootLogin no
    
    # no-root-match.conf
    # Overrides runner's option; dstack server/user can no longer connect to the runner
    Match All
        PermitRootLogin no
    

    In fact, we used to rely on the disto-/image-provided config but switched to our own generated config in #3421 precisely to avoid such problems.

    I'd suggest a dstack-specific location for includes, that is, still ignore distro-provided config and its includes but allow customization via includes baked into the image. That means that you'll need to build your images -- but with the default Include path this approach would require using a curated list of images with a) desired hardened options b) located at the correct path (Include /etc/ssh/sshd_config.d/*.conf) c) that don't break runner's config, so, the difference is "review third-party images" vs. "build your own images on top of third-party images".

    With any option (distro-default or dstack-specific include path), this approach relies on the assumption that users will use "approved" images, with no way to enforce it via dstack.

    Approach 2 (server-side setting)

    This approach enforces curated options for all images, which is both good and bad.

    Pros: no need for custom/curated images; all images get approved options; enforcement with no escape hatch (if you need it).
    Cons: fragile across OpenSSH versions, for example, mlkem768x25519-sha256 (9.9+) would break every job on a 22.04-based image.


    Overall, both approaches (I excluded the third one as it's client-only and is not mutually exclusive with others) have downsides. Could you tell us more about your use cases and overall setup (backend(s), policies, etc.)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions