Commit 30d1eda
committed
Merge #98: Add automatic security updates configuration to ConfigureCommand
3d8b153 docs: [#17] add comprehensive guide for adding static Ansible playbooks (Jose Celano)
b5d4e59 fix: [#17] include configure-security-updates.yml in static template copy list (Jose Celano)
d2d25d9 fix: [#17] add Debian family conditionals to security updates playbook (copilot-swe-agent[bot])
4d88cd5 feat: [#17] add automatic security updates configuration (copilot-swe-agent[bot])
db82319 Initial plan (copilot-swe-agent[bot])
Pull request description:
Implements unattended-upgrades configuration as a new step in the ConfigureCommand workflow, enabling automatic security patching with scheduled 2:00 AM reboots.
## Changes
**Domain Layer**
- Added `ConfigureSecurityUpdates` variant to `ConfigureStep` enum for failure tracking
**Application Layer**
- Created `ConfigureSecurityUpdatesStep` that executes Ansible playbook via `AnsibleClient`
- Integrated step into `ConfigureCommandHandler` workflow after Docker Compose installation
- Follows existing step pattern with proper error mapping and tracing
**Infrastructure Layer**
- Created `templates/ansible/configure-security-updates.yml` playbook:
- Installs and configures `unattended-upgrades` package
- Enables automatic security updates via APT configuration
- Sets automatic reboot schedule (02:00)
- Includes Debian family conditionals for cross-platform safety
- Verifies configuration with dry-run
## Usage
The step runs automatically in the configure workflow:
```rust
let current_step = ConfigureStep::ConfigureSecurityUpdates;
ConfigureSecurityUpdatesStep::new(Arc::clone(&self.ansible_client))
.execute()
.map_err(|e| (e.into(), current_step))?;
```
Configuration details in `/etc/apt/apt.conf.d/` files are backed up before modification.
<!-- START COPILOT CODING AGENT SUFFIX -->
<details>
<summary>Original prompt</summary>
>
> ----
>
> *This section details on the original issue you should resolve*
>
> <issue_title>Configure Automatic Security Updates</issue_title>
> <issue_description>Implement automatic security updates configuration in the `ConfigureCommand`. This task adds a new step that configures unattended-upgrades on provisioned instances to ensure they automatically receive and install security patches with scheduled reboots.
>
> This is the first phase of completing the system security configuration, chosen because it has lower implementation risk and provides immediate security value.
>
> ## Goals
>
> - [ ] **Automatic Security Updates**: Configure unattended-upgrades for automatic security patching
> - [ ] **Scheduled Reboots**: Enable automatic reboots at 2:00 AM for security updates that require restart
> - [ ] **New Domain Step**: Add `ConfigureSecurityUpdates` to the `ConfigureStep` enum
> - [ ] **Ansible Integration**: Create new Ansible playbook for security updates configuration
> - [ ] **Error Handling**: Implement proper error handling with actionable messages
> - [ ] **Testing**: Ensure E2E tests validate the security updates configuration
>
> ## Specifications
>
> ### Domain Integration
>
> Update `ConfigureStep` enum in `src/domain/environment/state/configure_failed.rs`:
>
> ```rust
> /// Steps in the configure workflow
> #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
> pub enum ConfigureStep {
> /// Installing Docker
> InstallDocker,
> /// Installing Docker Compose
> InstallDockerCompose,
> /// Configuring automatic security updates
> ConfigureSecurityUpdates, // <- NEW
> }
> ```
>
> ### New Application Step
>
> Create `src/application/steps/system/configure_security_updates.rs`:
> - Implements the ConfigureSecurityUpdatesStep
> - Uses AnsibleClient to execute security updates playbook
> - Handles ansible errors and maps them to domain errors
> - Follows the same pattern as existing Docker installation steps
>
> ### New Ansible Playbook
>
> Create `templates/ansible/configure-security-updates.yml` (static template):
> - Installs unattended-upgrades package
> - Configures automatic updates for security packages
> - Sets up automatic reboot schedule (2:00 AM)
> - Configures logging and notifications
>
> ### Integration
>
> Update `src/application/commands/configure.rs`:
> - Add new ConfigureSecurityUpdates case to step matching
> - Execute ConfigureSecurityUpdatesStep in the workflow
>
> ## Implementation Approach
>
> This is a **lower risk** implementation that:
> - Uses a static Ansible playbook (no Tera template variables needed)
> - Has no networking/firewall concerns
> - Follows established patterns from Docker installation steps
> - Can be implemented and tested independently
>
> ## Acceptance Criteria
>
> - [ ] **Security Updates Active**: Instances automatically check for and install security updates
> - [ ] **Scheduled Reboots**: Automatic reboots occur at 2:00 AM when needed for security updates
> - [ ] **Domain Integration**: ConfigureSecurityUpdates step properly integrated
> - [ ] **Error Handling**: Clear, actionable error messages for configuration failures
> - [ ] **Tests Pass**: All existing tests continue to pass
> - [ ] **E2E Validation**: E2E tests confirm security updates are properly configured
> - [ ] **Ansible Integration**: Security updates playbook executes successfully
>
> ## Related
>
> **Parent Epic**: #16 - Finish ConfigureCommand - System Security Configuration
> **Estimated Effort**: 1-2 days
>
> Full specification: [Security Updates Documentation](https://github.com/torrust/torrust-tracker-deployer/blob/main/docs/issues/17-configure-automatic-security-updates.md)</issue_description>
>
> ## Comments on the Issue (you are @copilot in this section)
>
> <comments>
> </comments>
>
</details>
- Fixes #17
<!-- START COPILOT CODING AGENT TIPS -->
---
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs.
ACKs for top commit:
josecelano:
ACK 3d8b153
Tree-SHA512: 6b94e8737e65a57c88e48d384577751d70219c47aff8b19b040fc532907dea80809f1ea2c210c1da53f7f314ba173b8b8dae8cfd3a7bbdbf15641f67c8260dfcFile tree
10 files changed
+412
-11
lines changed- .github
- docs
- contributing
- technical
- src
- application
- command_handlers/configure
- steps
- system
- domain/environment/state
- infrastructure/external_tools/ansible/template/renderer
- templates/ansible
10 files changed
+412
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
| 90 | + | |
91 | 91 | | |
92 | | - | |
| 92 | + | |
93 | 93 | | |
94 | | - | |
| 94 | + | |
95 | 95 | | |
96 | | - | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
97 | 99 | | |
98 | 100 | | |
99 | 101 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 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 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
45 | 47 | | |
46 | 48 | | |
47 | 49 | | |
48 | 50 | | |
49 | | - | |
50 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
51 | 54 | | |
52 | 55 | | |
53 | 56 | | |
| |||
63 | 66 | | |
64 | 67 | | |
65 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
66 | 84 | | |
67 | 85 | | |
68 | 86 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
| |||
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
| 26 | + | |
24 | 27 | | |
25 | 28 | | |
26 | 29 | | |
| |||
68 | 71 | | |
69 | 72 | | |
70 | 73 | | |
| 74 | + | |
71 | 75 | | |
72 | 76 | | |
73 | 77 | | |
| |||
152 | 156 | | |
153 | 157 | | |
154 | 158 | | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
155 | 164 | | |
156 | 165 | | |
157 | 166 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| |||
0 commit comments