Snowflake Container Services
One outbound SSH tunnel, traffic in both directions
Reach your DMZ, home lab or PC from SPCS, and expose SPCS services on your own domain.
Kevin Keller · kevinkeller.org
Why it matters
SPCS blocks inbound connections. SSH doesn't care.
- Containers run in Snowflake's managed, locked-down network.
- If a container can reach port 22 on a machine you control, it can tunnel anything back.
- Result: on-prem resources reachable from SPCS, and SPCS apps reachable from your network.
How it works
The tunnel starts outbound, then works both ways
- Forward: a SOCKS proxy (
-D 1080) routes container traffic through your server's network - Forward: on-prem Postgres appears at the container's
localhost:5432 - Reverse:
-Rforwards expose Streamlit, an API and a web terminal on your server - Reverse: port 22 forwarded back means you can SSH into the container
The setup
Five steps to a persistent tunnel
- Base64-encode the SSH key and store it as a Snowflake Secret.
- Create an external access integration that allows egress to your SSH server.
- Mount the secrets as environment variables in the service spec.
- Run
autosshwith a SOCKS proxy and fixed reverse ports 9001 to 9004. - Unset the secrets once the tunnels are up.
Design choices
Two small decisions keep it running
| Choice | Why |
|---|---|
autossh instead of plain SSH | Plain tunnels die silently on network blips. autossh restarts them. |
| Fixed reverse ports | nginx on the DMZ gets a static configuration, no discovery, no reloads. |
The step people miss
Secrets stay in the environment after startup
- Every process in the container can read the base64 private key.
- Unset the variables in the entrypoint.
- Add the same
unsetto/etc/bash.bashrcso web terminals and SSH shells don't inherit them. - This does not cover
/proc/1/environ: for depth, use a temporary file and shred it.
Query on-prem from SQL
A Snowflake query can reach your Postgres through the tunnel
- A SQL query calls a service function.
- The function hits a FastAPI endpoint in the SPCS container.
- The request routes through the SSH tunnel to on-prem Postgres.
- Snowflake handles batching, load balancing and retries.
Your own domain
nginx on the DMZ turns tunnel ports into proper sites
- SSL termination for browsers and users.
- One subdomain per SPCS service.
- WebSocket support for Streamlit and the web terminal.
- Basic auth or an OAuth proxy in front of anything sensitive.
The idea
The outbound tunnel is just transport. Every SSH capability works in return.
Tunnels, port forwards, file transfers and jump hosts, chained as deep as you need.
Security
You are punching a hole from a managed cloud to your network
- Dedicated DMZ user, no sudo, consider
ForceCommand. - Keep
GatewayPorts noso tunnel ports bind to localhost only. - Expose only nginx on 443. Never the tunnel ports.
- Rotate ed25519 keys, protect the web terminal, monitor connections.
The takeaway
Store the key as a secret, tunnel out with autossh, clean up the environment.
Kevin Keller · kevinkeller.org