Add ListSSHAuthKeys to the System D-Bus interface - #281
Conversation
AddSSHAuthKey and ClearSSHAuthKeys allow managing root's SSH authorized keys, but there is no way to see which keys are configured. That makes the file effectively write-only for API consumers: the Supervisor is growing endpoints on top of these methods, and without read-back a user cannot audit what keys grant access to the box, or whether any exist at all. Add ListSSHAuthKeys, returning the authorized_keys entries verbatim, one per line as stored. Blank lines and comment lines are skipped, as sshd and dropbear do when reading the file. A missing file returns an empty list. Reads take the same lock as modifications so a list never observes a partially rewritten file.
There was a problem hiding this comment.
Pull request overview
This PR extends the io.hass.os.System D-Bus interface to make root’s SSH authorized_keys auditable by API consumers by adding a read-back method.
Changes:
- Add
ListSSHAuthKeysD-Bus method to return the configured SSH authorized keys as a string array. - Implement
listSSHAuthKeyshelper that readsauthorized_keysunder the same lock used for modifications and skips blank/comment lines. - Add unit tests covering missing-file behavior, comment/blank skipping, and add→list roundtrip.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| system/system.go | Adds the listSSHAuthKeys helper and exports ListSSHAuthKeys over D-Bus. |
| system/system_test.go | Adds tests validating the new list behavior and its interaction with existing add/clear helpers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe system package now lists SSH authorized keys. It handles missing files, filters blank and comment lines, preserves key order, exposes the list through D-Bus, and adds test coverage. ChangesSSH authorized-key listing
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
sairon
left a comment
There was a problem hiding this comment.
Looks good. I couldn't really figure how to grasp the SSH editing feature without having any insight what's already configured.
Proposed change
AddSSHAuthKeyandClearSSHAuthKeysallow managing root's SSH authorized keys, but there is no way to see which keys are configured — the file is effectively write-only for API consumers. The Supervisor is growing endpoints on top of these methods (home-assistant/supervisor#7039), and without read-back a user cannot audit which keys grant access to the box, or whether any exist at all.Add
ListSSHAuthKeysto theio.hass.os.SystemD-Bus object, returning theauthorized_keysentries verbatim (one string per stored line, D-Bus signatureas). Blank and#comment lines are skipped, matching how sshd and dropbear read the file; a missing file returns an empty list. Reads take the same lock as modifications, so a list never observes a partially rewritten file.This enables a
GET /os/ssh/authorized_keysin the Supervisor and an auditable key table in the frontend, addressing the discoverability concern raised in review of the Supervisor API: with add/clear alone, keys granting root access (including ones imported via USB or written by add-ons) are invisible to the user.Follow-up candidates deliberately not included here:
RemoveSSHAuthKeyfor per-key deletion, and duplicate suppression inAddSSHAuthKey(now cheap to implement against the read path).Summary by CodeRabbit