Skip to content

Commit 12567d4

Browse files
larsewiclaude
andcommitted
Rewrite sshd promise type to use the keyword as the promiser
Instead of passing sshd directives as named attributes on a single promise, each directive is now its own promise where the promiser is the sshd keyword and "value" is the sole attribute. This simplifies validation and aligns with a one-promise-per-directive model. Ticket: ENT-13797 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 489311a commit 12567d4

7 files changed

Lines changed: 489 additions & 596 deletions

File tree

cfbs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@
307307
"subdirectory": "promise-types/sshd",
308308
"dependencies": ["library-for-promise-types-in-python"],
309309
"steps": [
310-
"copy sshd.py modules/promises/",
310+
"copy sshd_promise_type.py modules/promises/",
311311
"append enable.cf services/init.cf"
312312
]
313313
},

promise-types/sshd/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2025 Northern.tech
3+
Copyright (c) 2026 Northern.tech
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

promise-types/sshd/README.md

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,18 @@
33
Configures sshd and restarts the service when configuration changes.
44

55
## Promiser
6-
An arbitrary human-readable label that appears in log messages and reports.
7-
Since there is only one global sshd configuration, the promiser is not used to identify a resource.
8-
Example: `"global sshd config"`.
6+
The sshd configuration keyword to manage (e.g. `PermitRootLogin`, `AllowUsers`).
7+
Each promise manages a single directive in the drop-in config file.
98

109
## Attributes
11-
- Named using sshd's native directive names (e.g. `PermitRootLogin`, not `permit_root_login`)
12-
- Values can be strings or slists
13-
- Validated against `sshd -t` during promise evaluation
10+
- `value` (required) — the value for the directive, either a string or an slist
1411

1512
## What the module manages internally
1613
1. **Include directive** — ensures the base `sshd_config` includes the drop-in directory (`sshd_config.d/`) as its first non-comment directive
1714
2. **Drop-in directory** — creates the drop-in directory if it doesn't exist
1815
3. **Drop-in file** — writes directives to `sshd_config.d/00-cfengine.conf`
1916
4. **Service restart** — restarts sshd if configuration was changed and the service is already running
20-
5. **Verification** — verifies the desired attributes appear in the effective sshd config (`sshd -T`)
17+
5. **Verification** — verifies the desired directive appears in the effective sshd config (`sshd -T`)
2118

2219
## What the module does NOT do
2320
- Install sshd — that is a `packages:` promise
@@ -29,22 +26,19 @@ Example: `"global sshd config"`.
2926
bundle agent sshd_config
3027
{
3128
packages:
32-
"openssh-server"
33-
policy => "present";
29+
"openssh-server" policy => "present";
3430
3531
services:
36-
"sshd"
37-
service_policy => "start";
32+
"sshd" service_policy => "start";
3833
3934
vars:
40-
"allowed_users" slist => { "alice", "bob" };
35+
"allowed_users" slist => { "alice", "bob" };
4136
4237
sshd:
43-
"global"
44-
PermitRootLogin => "no",
45-
PasswordAuthentication => "no",
46-
Port => "22",
47-
AllowUsers => @(allowed_users);
38+
"PermitRootLogin" value => "no";
39+
"PasswordAuthentication" value => "no";
40+
"Port" value => "22";
41+
"AllowUsers" value => @(allowed_users);
4842
}
4943
```
5044

promise-types/sshd/enable.cf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
promise agent sshd
22
# @brief Define sshd promise type
33
{
4-
path => "$(sys.workdir)/modules/promises/sshd.py";
4+
path => "$(sys.workdir)/modules/promises/sshd_promise_type.py";
55
interpreter => "/usr/bin/python3";
66
}

promise-types/sshd/example.cf

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
promise agent sshd
22
# @brief Define sshd promise type
33
{
4-
path => "$(sys.workdir)/modules/promises/sshd.py";
4+
path => "$(sys.workdir)/modules/promises/sshd_promise_type.py";
55
interpreter => "/usr/bin/python3";
66
}
77

@@ -19,11 +19,10 @@ bundle agent example
1919
"allowed_users" slist => { "alice", "bob" };
2020

2121
sshd:
22-
"global"
23-
PermitRootLogin => "no",
24-
PasswordAuthentication => "no",
25-
Port => "22",
26-
AllowUsers => @(allowed_users);
22+
"PermitRootLogin" value => "no";
23+
"PasswordAuthentication" value => "no";
24+
"Port" value => "22";
25+
"AllowUsers" value => @(allowed_users);
2726
}
2827

2928
bundle agent __main__

0 commit comments

Comments
 (0)