Skip to content

Commit 00f1138

Browse files
committed
Add YAML config and profile-based creation
Introduce a viper-backed YAML configuration system and profile-driven instance creation to simplify deployment and reuse. This centralizes flags into a single options definition and enables: - persistent config files with command-line precedence and a generated packaging/config.yaml for packaging - create-config.yaml profiles and file-include support for cloud-init and other external snippets, allowing multi-profile merging and overrides - banner and welcome templates, built-in SFTP chroot option, and packaging changes to ship examples and defaults - unified option handling via server/options.yaml and a generate step to produce the config template; allow dumping parsed configs for debugging Also improve login string parsing and on-demand instance flow, add supporting helpers (cron, tooling), and update various types/flags to match the new config model.
1 parent 538d339 commit 00f1138

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+4737
-452
lines changed

.aiignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.idea/
2+
.zed/
3+
build/
4+
dist/
5+
release/

.gitignore

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ cmd/nutshell
1717
/scripts
1818
/nutshell
1919
/toybox
20+
/ssh2incus
21+
/PRESS_*.md
2022

23+
*.bak
2124
.envrc
2225
makefile
23-
*.yaml
24-
**/terminfo/**
26+
**/terminfo/**
27+
/*.yaml
28+
/*.txt

CHANGELOG.md

Lines changed: 166 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,171 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [v0.7.0] - 2025-09-25
8+
## v0.8.0 — 2025-10-02
9+
10+
### Added
11+
12+
#### Configuration File Support
13+
- **YAML Configuration**: New `config.yaml` file support for persistent server configuration
14+
- Configuration file loads from current directory, `$HOME/.config/ssh2incus/`, or `/etc/ssh2incus/` (checked in order)
15+
- All configuration options available as YAML settings with same names as command-line flags
16+
- All options commented out by default to use system defaults
17+
- Command-line flags have higher priority than configuration file options
18+
- **Flexible Configuration Management**: Simplified server configuration without modifying system service files
19+
- Each YAML setting maps directly to corresponding command-line flag
20+
- Easy to enable/disable features by uncommenting configuration options
21+
- Better configuration organization and documentation
22+
23+
#### Enhanced Instance Creation Configuration
24+
- **Profile-Based Instance Creation**: New `%profile` syntax allows applying predefined configuration profiles during instance creation
25+
- Use `%profile1+%profile2` in login string (e.g., `ssh +instance+%web-server+%database@host`)
26+
- Profiles are applied in order with later profiles overriding earlier ones
27+
- Direct configuration options always override profile settings
28+
- **File Include Support**: Configuration files now support external file includes
29+
- `!include filename.ext` syntax for loading file contents into configuration values
30+
- `<@filename.ext` alternative syntax for file includes
31+
- Smart path resolution: first tries relative to config file directory, then current working directory
32+
- **Advanced Configuration Templates**: Enhanced `create-config.yaml` with profile support
33+
- New `profiles` section for defining reusable configuration templates
34+
- Hierarchical configuration resolution: defaults → profiles → direct options
35+
- Support for complex multi-profile scenarios
36+
37+
#### Instance Creation Workflow Improvements
38+
- **Configuration Override Hierarchy**: Clear precedence order for configuration resolution
39+
- Base defaults from `create-config.yaml`
40+
- Applied profiles in specified order
41+
- Direct SSH login string options (highest priority)
42+
- **Enhanced Login String Parsing**: Improved parsing of complex instance creation syntax
43+
- Support for multiple profiles: `+instance+%profile1+%profile2+options@host`
44+
- Better error handling for malformed login strings
45+
- Validation of profile existence before instance creation
46+
47+
#### Built-in SFTP Server Enhancements
48+
- **CHROOT Support**: New `-c` flag enables chrooting to the start directory for enhanced security isolation
49+
- **Directory Control**: Enhanced `-d` flag for setting custom start directories in SFTP sessions
50+
- **Security Improvements**: Better privilege separation and directory access control
51+
52+
#### SSH Banner and Welcome Message Customization
53+
- **Custom Banner Support**: Server now looks for `banner.txt` file to display custom SSH login banners
54+
- **Welcome Message**: Optional `welcome.txt` file provides personalized welcome messages for users
55+
- **Template Variables**: Both banner and welcome files support template variables:
56+
- `[INSTANCE_USER]`: Current instance user
57+
- `[INSTANCE]`: Instance name
58+
- `[PROJECT]`: Project name
59+
- `[REMOTE]`: Remote server name
60+
- `[HOSTNAME]`: System hostname
61+
- **Example Files**: Provided `banner.txt.example` and `welcome.txt.example` templates in packaging
62+
63+
#### Improved Login String Parsing
64+
- **Enhanced Parser**: Completely refactored login string parsing with better modularity
65+
- **Comprehensive Testing**: Extensive test coverage for all login string formats and edge cases
66+
- **Better Error Handling**: Improved validation and error reporting for malformed login strings
67+
- **Backward Compatibility**: Maintained full compatibility with existing login string formats
68+
69+
### Changed
70+
71+
#### Configuration System
72+
- **Extended CreateConfig Structure**: Enhanced configuration file format
73+
- Added `profiles` map for named configuration templates
74+
- Improved validation and error reporting for configuration files
75+
- Better handling of optional configuration sections
76+
- **Enhanced File Processing**: Improved `LoadCreateConfig` function
77+
- Added file include processing for both defaults and profile configurations
78+
- Better error messages for missing include files or invalid paths
79+
- Support for nested configuration scenarios
80+
81+
#### SFTP Server Implementation
82+
- **Command-line Flags**: Added support for standard OpenSSH SFTP server flags (-c, -d, -R, -e, -u, -l, -h)
83+
- **Security Model**: Enhanced security with proper chroot and directory change operations
84+
- **Environment Integration**: Better integration with UID/GID environment variables
85+
86+
#### Login String Processing
87+
- **Modular Architecture**: Split parsing logic into focused, testable functions
88+
- **Performance Improvements**: Optimized parsing for complex login string formats
89+
- **Code Organization**: Better separation of concerns for different login string components
90+
91+
### Improved
92+
93+
#### User Experience
94+
- **Intuitive Profile Usage**: Simple syntax for applying complex configurations
95+
- Example: `ssh +web01+%nginx+%ssl+ubuntu/24.04@host` applies nginx and SSL profiles with Ubuntu 24.04
96+
- **Flexible Configuration Management**: Easy organization of instance templates
97+
- Separate profile files can be included via file include directives
98+
- Configuration inheritance allows for base profiles with specialized extensions
99+
- **Better Error Handling**: Enhanced error messages for configuration issues
100+
- Clear indication when profiles are missing or invalid
101+
- Better path resolution error reporting for file includes
102+
- **Visual Feedback**: Custom banners provide better visual identification of servers and instances
103+
- **Personalization**: Welcome messages can be customized per deployment
104+
- **Security**: SFTP chroot functionality provides better file access isolation
105+
106+
#### Development & Maintenance
107+
- **Modular Configuration**: Profile-based system enables better configuration organization
108+
- **Template Reusability**: Profiles can be shared across different instance creation scenarios
109+
- **Configuration Validation**: Enhanced validation ensures configuration consistency
110+
111+
### Examples
112+
113+
#### Profile-Based Instance Creation
114+
```bash
115+
# Create instance with web-server profile
116+
ssh -p 2222 +web01+%web-server@host
117+
118+
# Create instance with multiple profiles (database settings override web-server)
119+
ssh -p 2222 +app01+%web-server+%database@host
120+
121+
# Override profile settings with direct options
122+
ssh -p 2222 +dev01+%development+m16+c8@host
123+
```
124+
125+
#### Configuration File with Profiles
126+
```yaml
127+
version: 1
128+
defaults:
129+
image: alpine/edge
130+
memory: 1
131+
cpu: 1
132+
133+
profiles:
134+
web-server:
135+
image: ubuntu/24.04
136+
memory: 2
137+
cpu: 2
138+
config:
139+
user.user-data: "!include web-server-init.yaml"
140+
141+
database:
142+
memory: 4
143+
cpu: 2
144+
config:
145+
user.user-data: "<@database-setup.sh"
146+
```
147+
148+
### Technical Details
149+
150+
#### New Configuration Processing
151+
- File includes processed after YAML unmarshaling but before instance creation
152+
- Profile merging follows last-wins precedence for conflicting settings
153+
- Path resolution tries config directory first, then current working directory
154+
- Enhanced error reporting with specific failure contexts
155+
156+
#### SFTP Server Flags
157+
- `-c`: Enable chroot to start directory
158+
- `-d DIR`: Set start directory
159+
- `-R`: Read-only mode
160+
- `-e`: Debug to stderr
161+
- `-u UMASK`: Set explicit umask
162+
- `-l LEVEL`: Debug level (ignored for compatibility)
163+
- `-h`: Show help
164+
165+
#### Banner and Welcome File Locations
166+
- Files are searched in standard configuration directories
167+
- Template variable substitution occurs at runtime
168+
- Graceful fallback when files are not present
169+
170+
---
171+
172+
## v0.7.0 — 2025-09-25
9173

10174
### Added
11175

@@ -117,7 +281,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
117281

118282
---
119283

120-
## [v0.6.0] - 2025-04-07
284+
## v0.6.0 2025-04-07
121285

122286
Release with core SSH-to-Incus functionality, including:
123287
- Basic SSH server with Incus integration

0 commit comments

Comments
 (0)