Skip to content

Commit dbc704a

Browse files
committed
Custom promise type for managing global sshd configuration
Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
1 parent c817bb3 commit dbc704a

File tree

6 files changed

+701
-0
lines changed

6 files changed

+701
-0
lines changed

cfbs.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,15 @@
302302
"append enable.cf services/init.cf"
303303
]
304304
},
305+
"promise-type-sshd": {
306+
"description": "Promise type to configure sshd.",
307+
"subdirectory": "promise-types/sshd",
308+
"dependencies": ["library-for-promise-types-in-python"],
309+
"steps": [
310+
"copy sshd.py modules/promises/",
311+
"append enable.cf services/init.cf"
312+
]
313+
},
305314
"promise-type-systemd": {
306315
"description": "Promise type to manage systemd services.",
307316
"subdirectory": "promise-types/systemd",

promise-types/sshd/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Northern.tech
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

promise-types/sshd/README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# `sshd` promise type
2+
3+
Configures sshd and restarts the service when configuration changes.
4+
5+
## 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"`.
9+
10+
## 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
14+
15+
## What the module manages internally
16+
1. **Include directive** — ensures the base `sshd_config` includes the drop-in directory (`sshd_config.d/`) as its first non-comment directive
17+
2. **Drop-in directory** — creates the drop-in directory if it doesn't exist
18+
3. **Drop-in file** — writes directives to `sshd_config.d/00-cfengine.conf`
19+
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`)
21+
22+
## What the module does NOT do
23+
- Install sshd — that is a `packages:` promise
24+
- Ensure sshd is running — that is a `services:` promise
25+
- Manage match blocks — those are a policy-level concern
26+
27+
## Policy
28+
```cf3
29+
bundle agent sshd_config
30+
{
31+
packages:
32+
"openssh-server"
33+
policy => "present";
34+
35+
services:
36+
"sshd"
37+
service_policy => "start";
38+
39+
vars:
40+
"allowed_users" slist => { "alice", "bob" };
41+
42+
sshd:
43+
"global"
44+
PermitRootLogin => "no",
45+
PasswordAuthentication => "no",
46+
Port => "22",
47+
AllowUsers => @(allowed_users);
48+
}
49+
```
50+
51+
## Authors
52+
53+
This software was created by the team at [Northern.tech](https://northern.tech), with many contributions from the community.
54+
Thanks everyone!
55+
56+
## Contribute
57+
58+
Feel free to open pull requests to expand this documentation, add features, or fix problems.
59+
You can also pick up an existing task or file an issue in [our bug tracker](https://northerntech.atlassian.net/).
60+
61+
## License
62+
63+
This software is licensed under the MIT License. See LICENSE in the root of the repository for the full license text.

promise-types/sshd/enable.cf

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

promise-types/sshd/example.cf

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
promise agent sshd
2+
# @brief Define sshd promise type
3+
{
4+
path => "$(sys.workdir)/modules/promises/sshd.py";
5+
interpreter => "/usr/bin/python3";
6+
}
7+
8+
bundle agent example
9+
{
10+
packages:
11+
"openssh-server"
12+
policy => "present";
13+
14+
services:
15+
"sshd"
16+
service_policy => "start";
17+
18+
vars:
19+
"allowed_users" slist => { "alice", "bob" };
20+
21+
sshd:
22+
"global"
23+
PermitRootLogin => "no",
24+
PasswordAuthentication => "no",
25+
Port => "22",
26+
AllowUsers => @(allowed_users);
27+
}
28+
29+
bundle agent __main__
30+
{
31+
methods:
32+
"example";
33+
}

0 commit comments

Comments
 (0)