Skip to content

Add SSHFS-backed volumes - #13462

Merged
sipsma merged 5 commits into
dagger:mainfrom
sipsma:sshfs-thread-202606091733
Jul 21, 2026
Merged

sipsma merged 5 commits into
dagger:mainfrom
sipsma:sshfs-thread-202606091733

Conversation

@sipsma

@sipsma sipsma commented Jun 16, 2026 •

Copy link
Copy Markdown
Contributor

Goal

Let Dagger workflows mount a remote filesystem over SSH/SFTP into containers, without first copying it into the engine's content store. This is aimed at large or externally-managed datasets where snapshotting the whole tree into the cache is impractical or undesirable, and where you want a live, two-way view of a remote path.

The feature is exposed as a new opaque Volume object. "Opaque" is deliberate: a Volume only exposes its id. The backing endpoint, credentials, and the fact that it's SSHFS at all are never surfaced to clients. This keeps the door open for other volume backends later without an API break, and—more importantly—lets a Volume be handed to module code as a capability without leaking how it's wired up.

What this adds

  • Volume — new opaque object type (only id is exposed).
  • Container.withMountedVolume(path, volume, readOnly = false, expand = false) — mounts a volume into a container. Removal is handled by the existing Container.withoutMount.
  • Query.sshfsVolume(endpoint, privateKey, knownHosts, cacheKey, insecureSkipHostKeyCheck = false, experimentalServiceHost) — constructs an SSHFS-backed volume (main client only).
  • Address.volume — constructs a volume from an sshfs://… address string (main client only), so CLI/non-SDK callers can pass a volume as a single argument. The CLI gains a custom Volume argument flag that resolves through this.

New public API is version-gated (AfterVersion("v1.0.0-0")), and generated SDKs / schema / reference docs are included.

Approach

  • core.Volume carries a private backend config (SSHFSVolumeConfig): the endpoint plus the private-key and known_hosts Secrets and an optional experimental service host. The secrets/service are attached as normal dagql dependencies, so they participate in identity, lifecycle, and persistence like any other resource a container depends on.
  • The actual SSHFS mount is established at exec time, not at construction time. When a container that mounts a volume is run, the engine materializes the secrets to per-mount tmpfs files, invokes sshfs, bind-mounts the result into the container, and tears everything (mount, tmpfs, any service) down afterwards.
  • Module SDK introspection scrubs the constructors at the field level, and the resolvers are runtime-gated with RequireMainClient, so the constructors are genuinely unavailable to module code while Volume / withMountedVolume stay available.

Usage

In a module: accept and mount a Volume

A module never constructs the volume—it receives one and mounts it. This keeps modules portable across environments:

package main

import (
	"context"
	"dagger/my-mod/internal/dagger"
)

type MyMod struct{}

func (m *MyMod) Read(ctx context.Context, volume *dagger.Volume) (string, error) {
	return dag.Container().
		From("alpine:3.22").
		WithMountedVolume("/mnt", volume, dagger.ContainerWithMountedVolumeOpts{ReadOnly: true}).
		WithExec([]string{"cat", "/mnt/data.txt"}).
		Stdout(ctx)
}

From the CLI: pass a volume by address

The CLI (a main client) resolves the sshfs://… address into a Volume and passes it to the module function. Secrets are referenced with the usual secret URIs (e.g. env://, file://, op://, …):

export SSH_KEY="$(cat ~/.ssh/id_ed25519)"
export KNOWN_HOSTS="example.com ssh-ed25519 AAAA..."   # or: [example.com]:2222 ssh-ed25519 AAAA...

dagger call -m ./my-mod read \
  --volume 'sshfs://[email protected]:22/srv/data?privateKey=env://SSH_KEY&knownHosts=env://KNOWN_HOSTS'

Supported query params: privateKey (required), knownHosts, cacheKey, insecureSkipHostKeyCheck. If a nested secret address itself contains query characters, URL-encode it.

Constructing directly (main client / SDK)

vol := dag.SshfsVolume(
	"sshfs://[email protected]:22/srv/data",
	dag.SetSecret("ssh-key", privateKeyPEM),
	dagger.SshfsVolumeOpts{
		KnownHosts: dag.SetSecret("known-hosts", knownHosts),
	},
)

out, err := dag.Container().From("alpine:3.22").
	WithMountedVolume("/mnt", vol).
	WithExec([]string{"sh", "-c", "echo hi > /mnt/out.txt"}).
	Sync(ctx)

Module portability (why constructors are main-client-only)

Modules are meant to be environment-agnostic and reusable. A module that could call dag.sshfsVolume(...) (or dag.address("sshfs://...").volume()) would be able to bake host names, ports, and SSH wiring into its own code, which couples it to one environment and lets it reach out to arbitrary endpoints on its own. Instead, only the outside/main client constructs volumes; modules just declare a Volume parameter and mount whatever they're handed. The opacity of Volume reinforces this—module code cannot inspect or reconstruct the SSH details of a volume it receives.

Differences from #12049

This reworks the earlier #12049 (which implemented both SSHFS and host directory mounts). It was not copied; it was rebuilt from scratch, reusing only the pieces that held up under review. Meaningful differences:

  • Modules cannot construct SSHFS volumes. In Implement sshfs and host volume mounts #12049 the constructor lived on Query and was reachable from module code. Here the constructors are main-client-only (field-hidden from module introspection and runtime-gated via RequireMainClient), for the portability reasons above. A new Address.volume path is added for CLI/address use and is gated the same way.
  • No secret material persisted or written to stable disk. Implement sshfs and host volume mounts #12049 wrote the private key plaintext to a digest-named file under the engine's persistent state dir and never removed it. Here, key/known_hosts material is materialized only to per-mount tmpfs at use time and scrubbed afterward; secrets are tracked as dependencies and persisted only in handle form (never the contents).
  • Secure-by-default host key verification. Implement sshfs and host volume mounts #12049 disabled host-key checking (StrictHostKeyChecking=no, UserKnownHostsFile=/dev/null). Here, knownHosts is required unless insecureSkipHostKeyCheck is explicitly set, and StrictHostKeyChecking is on. When experimentalServiceHost is used, the connection dials the service while verification stays anchored to the user-facing endpoint host via OpenSSH HostKeyAlias.
  • No live mount paths in the cache. Implement sshfs and host volume mounts #12049 established the mount in the constructor and stored a host mount path on the cached object, which goes stale on cache hits / engine restarts. Here the mount is established at exec time and never persisted; persisted volumes record only the backend config and handle-form references.
  • Correct dependency/lifecycle handling. Volume mounts are attached as owned container dependencies (so required session resources propagate and persistence closure is correct), and mounts are unmounted/cleaned up after each exec rather than leaked.
  • Host directory bind mounting is intentionally out of scope here. Implement sshfs and host volume mounts #12049 also added host directory mounts; that is a separate scope and security surface and is deliberately not included in this PR. It should be followed up separately.

Cache behavior

  • Default volume identity is per-session input, so volumes don't accidentally get reused across unrelated sessions. Identity is never derived from remote contents.
  • Pass an optional cacheKey to opt into equivalence across matching constructor calls (the user asserts "these are the same volume"); resource-dependency requirements still apply.
  • A cached exec is not re-run, so it does not reread remote contents: an identical exec recipe returns the cached result even if the remote data changed afterward; a fresh/cache-busted exec observes the new contents.

Security notes

  • knownHosts required by default; insecure skip is an explicit, opt-in flag.
  • Private keys and known_hosts never touch stable disk and are never persisted as content.
  • The dev engine image installs sshfs and fuse3 and enables user_allow_other in /etc/fuse.conf so non-root container users can read the FUSE mount.

Tests & validation

  • go test ./cmd/codegen/introspection ./core ./core/schema
  • (cd toolchains/engine-dev && go test ./build)
  • dagger call engine-dev test --pkg ./core/integration --run TestVolume — covers an end-to-end SSHFS mount/read, RW write + cached-read-does-not-reread, wrong-known_hosts rejection (with a positive control), a module accepting/mounting a volume, and a module being unable to construct one.
  • dagger call engine-dev test --pkg ./cmd/dagger --run 'TestVolume(CustomFlagValue|SliceCustomFlagValue)'
  • dagger call go-sdk generate diff-stats

Generated outputs

Generated SDK clients (Go/Python/TypeScript/Rust/Elixir/PHP), the GraphQL schema doc, and the PHP static reference are included from dagger generate. Constructor hiding is consistent across them: client SDKs expose sshfsVolume / Address.volume, while module SDKs do not.

@sipsma

sipsma commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

cc @suprjinx

@IljaKroonen

Copy link
Copy Markdown

Thank you @sipsma this looks good from our perspective!

I have been able to test the capability, and it seems to work nicely; although we can't test it at scale just yet as our build for this contains other changes (which look dagger v1 related) that we're not ready to ship just yet.

All the choices you've made make sense to me as well.

would be able to bake host names, ports, and SSH wiring into its own code, which couples it to one environment and lets it reach out to arbitrary endpoints on its own

out of curiosity isn't that the case already for http calls in modules? how is the sshfs case different?

@suprjinx

suprjinx commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

@sipsma we think this is going to work great for us, so do please 🚢 it :-)

@sipsma
sipsma force-pushed the sshfs-thread-202606091733 branch 2 times, most recently from a63eb7a to f052627 Compare July 20, 2026 23:51
@sipsma
sipsma marked this pull request as ready for review July 20, 2026 23:55
@sipsma
sipsma requested review from a team as code owners July 20, 2026 23:55
sipsma and others added 5 commits July 21, 2026 17:34
Introduce an opaque Volume object backed by SSHFS, letting workflows mount a
remote filesystem (over SSH/SFTP) into containers. This enables using large or
externally-managed filesystems in Dagger pipelines without copying them into
the engine's content store.

API
- New opaque `Volume` object type. Only its `id` is exposed; the backing
  endpoint, credentials, and SSHFS specifics are never surfaced to clients.
- `Container.withMountedVolume(path, volume, readOnly=false, expand=false)`
  mounts a volume into a container. Removal uses the existing
  `Container.withoutMount`.
- `Query.sshfsVolume(endpoint, privateKey, knownHosts, cacheKey,
  insecureSkipHostKeyCheck=false, experimentalServiceHost)` constructs an
  SSHFS-backed volume.
- `Address.volume` constructs a volume from an address string such as
  `sshfs://user@host[:port]/abs/path?privateKey=env://KEY&knownHosts=env://KNOWN`
  for CLI and non-SDK use; the CLI gains a custom `Volume` argument flag.

Module boundary
- Modules can accept, pass, and mount Volume values, but cannot construct SSHFS
  volumes. `Query.sshfsVolume` and `Address.volume` are constructors for the
  main (outside) client only: they are hidden from module SDK introspection via
  field-level scrubbing and runtime-gated with RequireMainClient. The `Volume`
  type itself and `Container.withMountedVolume` remain available to modules.

Implementation
- `core.Volume` carries a private backend config (SSHFSVolumeConfig) holding the
  endpoint plus the private-key and known_hosts Secrets and an optional
  experimental service host, all attached as dagql dependencies.
- At exec time the engine establishes the SSHFS mount: secrets are materialized
  only to per-mount tmpfs files, sshfs is invoked, and the result is
  bind-mounted into the container; the mount and temp state are cleaned up after
  use.
- `experimentalServiceHost` dials a Dagger service as the endpoint while still
  verifying the original endpoint host's key via OpenSSH HostKeyAlias.
- New public API is version-gated with AfterVersion("v1.0.0-0").

Security
- Host-key verification is secure by default: `knownHosts` is required unless
  `insecureSkipHostKeyCheck` is explicitly true.
- Private keys and known_hosts are attached as Secret dependencies and are never
  written to the persisted cache; persisted volumes record only handle-form
  references and config, never key material or a live mount path.
- The dev engine image installs sshfs and fuse3 and enables `user_allow_other`
  in /etc/fuse.conf so non-root container users can read the FUSE mount.

Cache semantics
- Default volume identity is per-session input, avoiding accidental
  cross-session reuse. Users may pass `cacheKey` to opt into equivalence across
  matching constructor calls; identity is never derived from remote contents.
- A cached exec is not re-run and therefore does not reread remote contents: an
  identical exec recipe returns the cached result even after the remote data
  changes, while a fresh/cache-busted exec observes new contents.

Includes generated SDK, schema, and reference doc outputs from `dagger generate`.

Validation
- go test ./cmd/codegen/introspection ./core ./core/schema
- (cd toolchains/engine-dev && go test ./build)
- dagger call engine-dev test --pkg ./core/integration --run TestVolume
- dagger call engine-dev test --pkg ./cmd/dagger --run 'TestVolume(CustomFlagValue|SliceCustomFlagValue)'
- dagger call go-sdk generate diff-stats

Signed-off-by: Erik Sipsma <[email protected]>
Co-authored-by: Geoff Wilson <[email protected]>
Co-authored-by: Nikola Jokic <[email protected]>
The SSHFS volume mount support added another branch to the persisted container encode/decode dispatch, which pushed both functions just over the gocyclo threshold in CI. These functions intentionally centralize persisted container mount, secret, and socket serialization, so suppress the complexity lint at the function boundary with scoped explanations.

Signed-off-by: Erik Sipsma <[email protected]>
@sipsma
sipsma force-pushed the sshfs-thread-202606091733 branch from cd5f3ef to 5500d33 Compare July 21, 2026 17:37
@sipsma
sipsma merged commit 903e583 into dagger:main Jul 21, 2026
85 of 87 checks passed
sipsma added a commit that referenced this pull request Aug 24, 2026
* core: add field-level schema introspection scrubbing

Signed-off-by: Erik Sipsma <[email protected]>
(cherry picked from commit 49b99b6)
Signed-off-by: Erik Sipsma <[email protected]>

* Add SSHFS-backed volumes (#13462)

* feat(engine): add SSHFS-backed volumes

Introduce an opaque Volume object backed by SSHFS, letting workflows mount a
remote filesystem (over SSH/SFTP) into containers. This enables using large or
externally-managed filesystems in Dagger pipelines without copying them into
the engine's content store.

API
- New opaque `Volume` object type. Only its `id` is exposed; the backing
  endpoint, credentials, and SSHFS specifics are never surfaced to clients.
- `Container.withMountedVolume(path, volume, readOnly=false, expand=false)`
  mounts a volume into a container. Removal uses the existing
  `Container.withoutMount`.
- `Query.sshfsVolume(endpoint, privateKey, knownHosts, cacheKey,
  insecureSkipHostKeyCheck=false, experimentalServiceHost)` constructs an
  SSHFS-backed volume.
- `Address.volume` constructs a volume from an address string such as
  `sshfs://user@host[:port]/abs/path?privateKey=env://KEY&knownHosts=env://KNOWN`
  for CLI and non-SDK use; the CLI gains a custom `Volume` argument flag.

Module boundary
- Modules can accept, pass, and mount Volume values, but cannot construct SSHFS
  volumes. `Query.sshfsVolume` and `Address.volume` are constructors for the
  main (outside) client only: they are hidden from module SDK introspection via
  field-level scrubbing and runtime-gated with RequireMainClient. The `Volume`
  type itself and `Container.withMountedVolume` remain available to modules.

Implementation
- `core.Volume` carries a private backend config (SSHFSVolumeConfig) holding the
  endpoint plus the private-key and known_hosts Secrets and an optional
  experimental service host, all attached as dagql dependencies.
- At exec time the engine establishes the SSHFS mount: secrets are materialized
  only to per-mount tmpfs files, sshfs is invoked, and the result is
  bind-mounted into the container; the mount and temp state are cleaned up after
  use.
- `experimentalServiceHost` dials a Dagger service as the endpoint while still
  verifying the original endpoint host's key via OpenSSH HostKeyAlias.
- New public API is version-gated with AfterVersion("v1.0.0-0").

Security
- Host-key verification is secure by default: `knownHosts` is required unless
  `insecureSkipHostKeyCheck` is explicitly true.
- Private keys and known_hosts are attached as Secret dependencies and are never
  written to the persisted cache; persisted volumes record only handle-form
  references and config, never key material or a live mount path.
- The dev engine image installs sshfs and fuse3 and enables `user_allow_other`
  in /etc/fuse.conf so non-root container users can read the FUSE mount.

Cache semantics
- Default volume identity is per-session input, avoiding accidental
  cross-session reuse. Users may pass `cacheKey` to opt into equivalence across
  matching constructor calls; identity is never derived from remote contents.
- A cached exec is not re-run and therefore does not reread remote contents: an
  identical exec recipe returns the cached result even after the remote data
  changes, while a fresh/cache-busted exec observes new contents.

Includes generated SDK, schema, and reference doc outputs from `dagger generate`.

Validation
- go test ./cmd/codegen/introspection ./core ./core/schema
- (cd toolchains/engine-dev && go test ./build)
- dagger call engine-dev test --pkg ./core/integration --run TestVolume
- dagger call engine-dev test --pkg ./cmd/dagger --run 'TestVolume(CustomFlagValue|SliceCustomFlagValue)'
- dagger call go-sdk generate diff-stats

Signed-off-by: Erik Sipsma <[email protected]>
Co-authored-by: Geoff Wilson <[email protected]>
Co-authored-by: Nikola Jokic <[email protected]>

* lint: suppress persisted container complexity

The SSHFS volume mount support added another branch to the persisted container encode/decode dispatch, which pushed both functions just over the gocyclo threshold in CI. These functions intentionally centralize persisted container mount, secret, and socket serialization, so suppress the complexity lint at the function boundary with scoped explanations.

Signed-off-by: Erik Sipsma <[email protected]>

* engine: update bundled sshfs to 3.7.6

Signed-off-by: Erik Sipsma <[email protected]>

* engine: harden SSHFS credential and cleanup handling

Signed-off-by: Erik Sipsma <[email protected]>

* test: update hidden fields for SSHFS volume constructors

Signed-off-by: Erik Sipsma <[email protected]>

---------

Signed-off-by: Erik Sipsma <[email protected]>
Co-authored-by: Geoff Wilson <[email protected]>
Co-authored-by: Nikola Jokic <[email protected]>
(cherry picked from commit 903e583)
Signed-off-by: Erik Sipsma <[email protected]>

* chore: adapt SSHFS volumes for v0.21

Open the API at v0.21.9, use the maintenance-line integration fixture helpers, regenerate SDK and reference outputs, and add the release note.

Also include the applicable lint compatibility from e17f17d so the DagQL staticcheck suppression does not flap under the current pinned linter.

Signed-off-by: Erik Sipsma <[email protected]>

---------

Signed-off-by: Erik Sipsma <[email protected]>
Co-authored-by: Geoff Wilson <[email protected]>
Co-authored-by: Nikola Jokic <[email protected]>
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
dagger 0.21.9

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## v0.21.9 - 2026-08-25

### Added
- Added SSHFS-backed volumes, allowing remote filesystems to be mounted into containers without copying their contents into Dagger's content store by @sipsma in dagger/dagger#13462

### Fixed
- `Container.withDirectory` and `Directory.withDirectory` no longer restore by @sipsma in dagger/dagger#13848 \
  deleted nested files after execs remove and recreate an ancestor
  directory.
- Engine client enumeration no longer blocks behind another session's by @sipsma in dagger/dagger#13542 \
  initialization or teardown, preventing Cloud keeper heartbeats from stalling
  and live engines from being suspended.
- Session teardown now runs in the background after the main client disconnects, by @sipsma in dagger/dagger#13681 \
  preventing shutdown responses from timing out while the engine releases
  session-owned cache results.
- The engine now bounds retained DAGQL cache metadata independently of disk by @sipsma in dagger/dagger#13846 \
  usage by pruning cold persisted results when the structural estimate exceeds
  its configured limit. This may mitigate metadata growth at scale while
  preserving active and engine-lifetime cache roots.
- Registry protocol probes no longer appear as scary errors in progress output by @vito in dagger/dagger#13410 \
  when image pulls or publishes succeed, while genuine registry failures remain
  visible.
- Registry authentication no longer invalidates downstream container cache reuse across sessions when applied before or after `Container.from` by @sipsma in dagger/dagger#13901

### What to do next?
- Read the [documentation](https://docs.dagger.io)
- Join our [Discord server](https://discord.gg/dagger-io)
- Follow us on [Twitter](https://twitter.com/dagger_io)

</pre>
  <p>View the full release notes at <a href="https://github.com/dagger/dagger/releases/tag/v0.21.9">https://github.com/dagger/dagger/releases/tag/v0.21.9</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!17786
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants