Commit c223aa8
authored
Implement custom configuration and SSH key path flexibility (#137)
* Add config merging with custom overrides, SSH key path flexibility, and switch from /etc to /target
- Implement default config loading from azure-init.conf with optional overrides via 10-azure-init-sshd.
- SSH now uses sshd -G or falls back to ~/.ssh/authorized_keys if query mode is disabled.
- Changed config path from /etc/azure-init to target/azure-init to avoid using sudo during testing.
- Requesting feedback on how to handle the /target vs /etc issue for production.
- Larger test cases needed once config and SSH key handling are finalized.
* Refactor configuration handling for azure-init
- Introduced Config struct to centralize configuration management and simplify passing configuration data within Provision.
- Default configuration values are now defined directly within config.rs, eliminating the need for an externally installed config file in /etc.
- Removed installation of /etc/azure-init/azure-init.toml from build.rs to reflect new default handling.
- Added support for --config CLI parameter in main.rs to allow users to specify either a configuration file or directory:
- When a file is specified, loads configuration directly from that file.
- When a directory is specified, loads the base azure-init.toml, followed by all .toml files in .d in alphabetical order.
- Integrated hostname_provisioner, user_provisioner, and password_provisioner enums into config.rs, allowing provisioners to be set directly within Config and ensuring that these settings can be controlled or overridden through the Config struct.
- Revised SSH provisioning to respect the Config struct and load defaults or user-specified configuration paths dynamically.
- Applied other requested changes for consistency, including error handling improvements, simplified default trait derivations, and ensuring centralized configuration for all settings.
- Updated documentation with configuration hierarchy and merging rules to reflect the new --config option and configuration handling behavior.
* Resolving problems with ssh.rs and addressing other general PR comments:
- Added strict tracing and error logging and fail-fast behavior for missing/invalid sshd -G output and authorized_keys_path,rather than falling back to a default.
- Updated the config structs for Imds and Wireserver to use floats and cleaned up unused config files / config.rs Structs.
- Updated markdown documentation to describe azure-init’s behavior on invalid configurations.
* Refactor SSH provisioning to use updated configuration and query logic
- Updated Ssh struct to use query_sshd_config boolean instead of fallback_sshd_default and query_mode, essentially combining those two into the same field.
- Modified provision_ssh function to align with new config:
- If query_sshd_config is true and sshd -G succeeds, dynamically sets authorized keys path.
- If sshd -G fails, logs a warning but uses authorized_keys_path to proceed with provisioning.
- If query_sshd_config is false, uses authorized_keys_path as configured.
- Removed unused configure_password_authentication field from the Ssh struct.
- Adjusted unit tests to reflect new query_sshd_config logic and ensure accurate path setup in all scenarios.
- Added documentation for updated Ssh struct and provision_ssh logic.
* PR comments, as well as broken logic for merge_toml for debugging help in preserving merged values
* Resolving broken merge logic to merge at the field level rather than at the function level.
- Consolidated merge and merge_toml into a unified merge_toml function for cleaner and more consistent merging logic.
- Refactored load_from_directory to work with raw TOML values, ensuring progressive merging while preserving values.
- Updated test suite to reflect changes in the merging and loading logic.
- Added missing rustdoc comment to fn provisioning() in mod.rs
* Add --config argument to CLI Struct and tests for file and directory inputs
- Added --config argument to the CLI struct for specifying configuration files or directories.
- Created MockCli to replicate CLI behavior for testing.
- Added test_custom_config_via_cli to verify --config with a file input.
- Added test_directory_config_via_cli to verify --config with a directory input.
* Removing extra whitespace and dependencies, simplifying configuration.md document
* Refactor HostnameProvisioner and switch to ok_or
- Consolidated HostnameProvisioner and Provisioner enums into a single enum in config.rs.
- Replaced ok_or_else with ok_or for static error handling in provision() to simplify and optimize the code.
* Refactor config load/merge logic to use Figment and other PR comments
- Replaced custom configuration load and merge logic with Figment to simplify and standardize handling of config sources.
- Resolved other minor PR comments about whitespace, spelling and unused dependencies.
- Updated unit tests to validate Figment-based configuration management.
* Unify UserProvisioner and PasswordProvisioner logic to exist entirely in config.rs, just like HostnameProvisioner. Removing strum dependency and defining those config structs as non-exhaustive
* Fix configuration loading logic to ensure proper merging order: apply defaults, load azure-init.toml if present, merge files from azure-init.toml.d in lexicographical order, and apply CLI overrides. Added helper function to avoid duplicate logic.
* PR comments resolved about load() using absolute paths instead of relative paths, refactoring config and unit tests to use load_from wrapper function, and other minor changes to configuration.md and merge_toml_directory().
* Amending rustdoc commment for load() function.1 parent 76e5aae commit c223aa8
File tree
11 files changed
+1245
-214
lines changed- doc
- libazureinit
- src
- provision
- src
- tests
11 files changed
+1245
-214
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | 22 | | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| 35 | + | |
34 | 36 | | |
35 | 37 | | |
36 | 38 | | |
| |||
0 commit comments