Snap Packaging
Relevant source files
The following files were used as context for generating this wiki page:
The sshpiperd Snap package provides a containerized, cross-distribution method for deploying the SSH reverse proxy. It simplifies installation and configuration management by leveraging the snapd ecosystem's snapctl tool for configuration and a dedicated launcher to manage the lifecycle of the daemon and its associated plugins.
Sources: cmd/sshpiperd/snap/README.md:1-10, cmd/sshpiperd/snap/launcher/main.go:15-20
Architecture and Components
The Snap implementation utilizes a wrapper-based architecture where a specialized launcher manages the execution of the main sshpiperd binary. This launcher handles environment variable mapping, directory setup, and the dynamic construction of command-line arguments based on Snap configuration settings.
Snap Launcher
The launcher acts as the entry point for the Snap service. It performs two primary roles:
- Configuration Generation: When invoked with the
generateargument, it retrieves settings fromsnapctl, serializes them into aflags.jsonfile in theSNAP_DATAdirectory. - Daemon Orchestration: In standard execution, it reads the cached flags and executes
sshpiperdwith the appropriate arguments and attached plugins.
Sources: cmd/sshpiperd/snap/launcher/main.go:19-45
Deployment Workflow
The following diagram illustrates how the launcher interacts with the Snap environment to start sshpiperd.
The launcher ensures that directories for working data (using SNAP_COMMON) and binary locations (using SNAP) are correctly mapped to the containerized environment.
Sources: cmd/sshpiperd/snap/launcher/main.go:20-55
Configuration Management
Configuration is managed via the snap set command. The launcher dynamically builds the command-line interface for sshpiperd by parsing these settings.
Flag Extraction
The configgen utility is used during the build process to scan Go source files (main.go for the daemon and various plugins) and extract supported flags. This ensures the Snap package remains synchronized with the upstream CLI options.
Sources: cmd/sshpiperd/snap/configgen/main.go:15-30
Core Configuration Options
The following table summarizes the primary Snap-specific configuration keys available for the daemon.
| Snap Key | CLI Equivalent | Description | Default |
|---|---|---|---|
sshpiperd.plugins | N/A | Space-separated list of plugins to load. | workingdir |
sshpiperd.address | --address | Listening address for the proxy. | 0.0.0.0 |
sshpiperd.port | --port | Listening port for the proxy. | 2222 |
sshpiperd.server-key | --server-key | Path to host key files. | ssh_host_ed25519_key |
sshpiperd.log-level | --log-level | Logging verbosity (trace, debug, info, etc). | info |
Sources: cmd/sshpiperd/snap/README.md:15-30, cmd/sshpiperd/snap/launcher/main.go:90-120
Plugin Integration
The Snap package includes several pre-compiled plugins. The launcher is responsible for chaining these plugins to the sshpiperd execution command.
Supported Plugins
- workingdir: Provides directory-based routing. The launcher automatically creates the
workingdirdirectory withinSNAP_COMMONif it does not exist. - yaml: Allows configuration via YAML files.
- fixed: Routes all traffic to a single static target.
- failtoban: Adds basic brute-force protection.
Sources: cmd/sshpiperd/snap/README.md:32-50, cmd/sshpiperd/snap/launcher/main.go:135-145
Plugin Execution Logic
The launcher iterates through the plugins specified in sshpiperd.plugins and appends them to the command-line. Each plugin can have its own specific flags prefixed by the plugin name (e.g., workingdir.root).
Implementation Details
The launcher uses an embedded filesystem to track valid configuration entries.
// cmd/sshpiperd/snap/launcher/main.go:13-14
//go:embed all:*.txt
var configentry embed.FS
The loadFromSnapctl function reads configentry.txt to determine which keys to query from the Snap environment. It also enforces "known defaults," such as setting the server-key-generate-mode to notexist if not explicitly configured, ensuring the daemon can generate its own host keys on first run.
Sources: cmd/sshpiperd/snap/launcher/main.go:63-95
Conclusion
Snap Packaging for sshpiperd provides a robust, self-contained deployment model. By using a Go-based launcher to bridge the gap between Snap's configuration system and the sshpiperd plugin architecture, it allows users to manage a complex SSH proxy with standard Snap commands while maintaining the security and isolation benefits of the Snap platform.