Skip to content

Add ListSSHAuthKeys to the System D-Bus interface - #281

Merged
agners merged 1 commit into
mainfrom
ssh-list-auth-keys
Aug 5, 2026
Merged

Add ListSSHAuthKeys to the System D-Bus interface#281
agners merged 1 commit into
mainfrom
ssh-list-auth-keys

Conversation

@agners

@agners agners commented Aug 4, 2026

Copy link
Copy Markdown
Member

Proposed change

AddSSHAuthKey and ClearSSHAuthKeys allow 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 ListSSHAuthKeys to the io.hass.os.System D-Bus object, returning the authorized_keys entries verbatim (one string per stored line, D-Bus signature as). 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_keys in 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: RemoveSSHAuthKey for per-key deletion, and duplicate suppression in AddSSHAuthKey (now cheap to implement against the read path).

Summary by CodeRabbit

  • New Features
    • Added support for listing configured SSH authorized keys.
    • Returns valid keys in their existing order while excluding blank lines and comments.
    • Handles missing key files as an empty list and reports other access errors clearly.

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ListSSHAuthKeys D-Bus method to return the configured SSH authorized keys as a string array.
  • Implement listSSHAuthKeys helper that reads authorized_keys under 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.

Comment thread system/system.go
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f5298776-4a32-417e-8e70-83d49992a3aa

📥 Commits

Reviewing files that changed from the base of the PR and between cd70fa9 and 53c7e1d.

📒 Files selected for processing (2)
  • system/system.go
  • system/system_test.go

📝 Walkthrough

Walkthrough

The 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.

Changes

SSH authorized-key listing

Layer / File(s) Summary
Parse authorized keys
system/system.go, system/system_test.go
The helper serializes access, treats a missing file as empty, filters blank and comment lines, preserves order, and supports round-trip tests with added keys.
Expose authorized keys through D-Bus
system/system.go
ListSSHAuthKeys() returns parsed keys and translates read failures into D-Bus errors.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • home-assistant/os-agent#273: Adds the mutex-based authorized-key write and clear operations used by this complementary listing method.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: adding ListSSHAuthKeys to the System D-Bus interface.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ssh-list-auth-keys

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sairon sairon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I couldn't really figure how to grasp the SSH editing feature without having any insight what's already configured.

Comment thread system/system.go
@agners
agners merged commit b6ad346 into main Aug 5, 2026
5 checks passed
@agners
agners deleted the ssh-list-auth-keys branch August 5, 2026 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants