Skip to content

Add permanent errors to Fleet Desktop for TPM-backed httpsig work - #31220

Merged
lucasmrod merged 1 commit into
mainfrom
add-fleet-desktop-perm-errors
Jul 24, 2025
Merged

Add permanent errors to Fleet Desktop for TPM-backed httpsig work#31220
lucasmrod merged 1 commit into
mainfrom
add-fleet-desktop-perm-errors

Conversation

@lucasmrod

@lucasmrod lucasmrod commented Jul 24, 2025

Copy link
Copy Markdown
Member

For #30478.

Figma: https://www.figma.com/design/qBsJ8Qpz0ZSCASbLBYL59v/-28818-Verify-identity-of-Linux-hosts-when-talking-to-Fleet--ala-Apple-MDM-?node-id=5301-90&t=t9Kuq7QUXOJkhaff-1

When the host doesn't have a TPM 2.0 device:
Screenshot 2025-07-24 at 9 35 38 AM

When the host was installed with an invalid enroll secret (which means it cannot generate a certificate):
Screenshot from 2025-07-24 10-00-01

Summary by CodeRabbit

  • New Features

    • Fleet Desktop now displays a permanent error message in the system tray if a critical error is detected, preventing normal app startup and informing the user of the issue.
  • Bug Fixes

    • Improved handling of missing or outdated host identity certificates to ensure proper cleanup before generating new keys.
  • Documentation

    • Updated environment variable names in documentation and scripts for clarity and accuracy regarding TPM-backed certificate usage.

@coderabbitai

coderabbitai Bot commented Jul 24, 2025

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This update adds logic to handle missing or mismatched host identity certificates and secure hardware keys. It introduces a permanent error display in Fleet Desktop when certificate setup fails, updates environment variable names in documentation and scripts, and ensures stale certificate files are removed if a secure hardware key is not found.

Changes

Files / Paths Change Summary
ee/orbit/pkg/hostidentity/host_identity.go Removes stale host identity certificate file if secure hardware key is missing before key creation.
orbit/cmd/desktop/desktop.go Adds logic to show a permanent error in Fleet Desktop using a new environment variable.
orbit/cmd/orbit/orbit.go Handles certificate setup errors by launching Fleet Desktop with a permanent error message.
orbit/changes/fleetd-tpm-key,
tools/tuf/test/gen_pkgs.sh
Updates environment variable references and documentation for TPM-backed host identity certificates.

Sequence Diagram(s)

sequenceDiagram
    participant OrbitAgent
    participant HostIdentity
    participant FleetDesktop
    participant User

    OrbitAgent->>HostIdentity: Setup TPM-backed certificate
    alt Key or certificate error
        HostIdentity-->>OrbitAgent: Error (e.g., TPM unavailable, key missing)
        OrbitAgent->>FleetDesktop: Launch with FLEET_DESKTOP_PERMANENT_ERROR
        FleetDesktop->>User: Display permanent error message in tray
    else Success
        HostIdentity-->>OrbitAgent: Certificate ready
        OrbitAgent->>User: Normal operation
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Possibly related issues

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch add-fleet-desktop-perm-errors

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Comment on lines +61 to +67
// First let's clear any existing certificate in
// case a user or process deleted the keyfile but not
// the issued-via-SCEP certificate.
certPath := filepath.Join(metadataDir, constant.FleetHTTPSignatureCertificateFileName)
if err := os.RemoveAll(certPath); err != nil {
return nil, fmt.Errorf("failed to clear the host identity certificate: %w", err)
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is not related to the Fleet Desktop change, I added this for the following scenario described in the main story:

- Delete one or more certificate files host_identity* in the host, restart fleetd, and make sure fleetd is able to get a new cert and talk to Fleet.

@@ -1 +1 @@
* Added support to generate a TPM 2.0 private key and issue a SCEP certificate for signing of HTTP requests (via new environment variable `ORBIT_FLEET_MANAGED_CLIENT_CERTIFICATE`).
- Added support to generate a TPM 2.0 private key and issue a SCEP certificate for signing of HTTP requests (via new environment variable `ORBIT_FLEET_MANAGED_HOST_IDENTITY_CERTIFICATE`).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I missed this rename on the previous rename PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I missed these renames on the previous rename PR.

@lucasmrod lucasmrod linked an issue Jul 24, 2025 that may be closed by this pull request
@codecov

codecov Bot commented Jul 24, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 0% with 50 lines in your changes missing coverage. Please review.

Project coverage is 64.00%. Comparing base (82ce7b8) to head (ae2adc7).
Report is 15 commits behind head on main.

Files with missing lines Patch % Lines
orbit/cmd/orbit/orbit.go 0.00% 42 Missing ⚠️
ee/orbit/pkg/hostidentity/host_identity.go 0.00% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #31220      +/-   ##
==========================================
- Coverage   64.03%   64.00%   -0.03%     
==========================================
  Files        1908     1908              
  Lines      187750   187799      +49     
  Branches     5336     5336              
==========================================
- Hits       120224   120208      -16     
- Misses      58079    58139      +60     
- Partials     9447     9452       +5     
Flag Coverage Δ
backend 64.86% <0.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lucasmrod

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 24, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
ee/orbit/pkg/hostidentity/host_identity.go (1)

61-67: Consider using os.Remove instead of os.RemoveAll for better safety.

Since you're removing a single certificate file, os.Remove would be more appropriate and safer than os.RemoveAll. The RemoveAll function is designed for removing directories and their contents, which could potentially remove more than intended if the path unexpectedly becomes a directory.

-		if err := os.RemoveAll(certPath); err != nil {
+		if err := os.Remove(certPath); err != nil && !os.IsNotExist(err) {

Note: I also added a check for os.IsNotExist(err) since it's fine if the certificate file doesn't exist - we just want to ensure it's not there.

orbit/cmd/orbit/orbit.go (1)

981-992: Good error handling approach with clear user messaging

This error handling logic properly provides user-friendly error messages through Fleet Desktop when TPM certificate setup fails. The approach of checking the fleet-desktop flag before showing UI errors and providing different messages based on error type is well thought out.

There's a small typo on line 2321: "permantent" should be "permanent".

-	log.Debug().Msg("opening Fleet Desktop with permantent error")
+	log.Debug().Msg("opening Fleet Desktop with permanent error")
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 82ce7b8 and ae2adc7.

📒 Files selected for processing (5)
  • ee/orbit/pkg/hostidentity/host_identity.go (1 hunks)
  • orbit/changes/fleetd-tpm-key (1 hunks)
  • orbit/cmd/desktop/desktop.go (3 hunks)
  • orbit/cmd/orbit/orbit.go (2 hunks)
  • tools/tuf/test/gen_pkgs.sh (5 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: getvictor
PR: fleetdm/fleet#30589
File: ee/server/service/hostidentity/depot/depot.go:104-119
Timestamp: 2025-07-08T16:06:54.576Z
Learning: In ee/server/service/hostidentity/depot/depot.go, the security concern where shared challenges allow certificate revocation (lines 104-119) is a known issue that will be addressed in a later feature, not an immediate concern to fix.
ee/orbit/pkg/hostidentity/host_identity.go (3)

Learnt from: getvictor
PR: #30589
File: ee/server/service/hostidentity/depot/depot.go:104-119
Timestamp: 2025-07-08T16:06:54.576Z
Learning: In ee/server/service/hostidentity/depot/depot.go, the security concern where shared challenges allow certificate revocation (lines 104-119) is a known issue that will be addressed in a later feature, not an immediate concern to fix.

Learnt from: getvictor
PR: #30825
File: ee/server/service/hostidentity/httpsig/httpsig.go:86-88
Timestamp: 2025-07-15T07:26:38.930Z
Learning: In ee/server/service/hostidentity/httpsig/httpsig.go, the Fetch method stub returning "not implemented" is safe because the verification profile requires MetaKeyID in RequiredMetadata, ensuring the httpsig library always calls FetchByKeyID instead of Fetch for valid signatures.

Learnt from: getvictor
PR: #30589
File: server/fleet/datastore.go:13-14
Timestamp: 2025-07-08T16:12:48.182Z
Learning: The Fleet team is not currently testing or enforcing OSS build compatibility, so imports of enterprise-only packages (like ee/server/service/hostidentity/types) into OSS code are acceptable for now.

tools/tuf/test/gen_pkgs.sh (1)

Learnt from: getvictor
PR: #30589
File: server/fleet/datastore.go:13-14
Timestamp: 2025-07-08T16:12:48.182Z
Learning: The Fleet team is not currently testing or enforcing OSS build compatibility, so imports of enterprise-only packages (like ee/server/service/hostidentity/types) into OSS code are acceptable for now.

orbit/cmd/orbit/orbit.go (1)

Learnt from: getvictor
PR: #30589
File: ee/server/service/hostidentity/depot/depot.go:104-119
Timestamp: 2025-07-08T16:06:54.576Z
Learning: In ee/server/service/hostidentity/depot/depot.go, the security concern where shared challenges allow certificate revocation (lines 104-119) is a known issue that will be addressed in a later feature, not an immediate concern to fix.

🧬 Code Graph Analysis (1)
ee/orbit/pkg/hostidentity/host_identity.go (1)
orbit/pkg/constant/constant.go (1)
  • FleetHTTPSignatureCertificateFileName (79-79)
🔇 Additional comments (6)
orbit/changes/fleetd-tpm-key (1)

1-1: Good correction to align the documentation with the actual variable name.

This change properly updates the environment variable reference to match the consistent naming used throughout the codebase for TPM-backed host identity certificates.

tools/tuf/test/gen_pkgs.sh (2)

30-30: Good documentation update to reflect the corrected variable name.

The comment now accurately describes the FLEET_MANAGED_HOST_IDENTITY_CERTIFICATE environment variable and correctly notes it's Linux-only.


85-85: Consistent variable name updates across all Linux package types.

All references to the environment variable have been properly updated from FLEET_MANAGED_CLIENT_CERTIFICATE to FLEET_MANAGED_HOST_IDENTITY_CERTIFICATE across DEB and RPM package generation commands. The MSI sections correctly omit this variable since it's Linux-only.

Also applies to: 110-110, 135-135, 160-160

orbit/cmd/desktop/desktop.go (2)

90-92: Excellent early error handling to prevent normal startup flow.

This check ensures that when a permanent error is detected, the application immediately switches to error display mode rather than attempting normal initialization, which is exactly the right approach for critical TPM/certificate failures.


798-824: Permanent error display implementation approved

We’ve confirmed that the project’s go.mod specifies Go 1.24.5 and that strings.SplitSeq is available (added in Go 1.23). No compatibility issues—no changes needed.

orbit/cmd/orbit/orbit.go (1)

2300-2343: Well-designed function for displaying permanent errors

This function handles the Fleet Desktop error display flow nicely:

  • Properly checks for GUI user availability before attempting to launch
  • Kills existing instances to prevent conflicts
  • Uses environment variables to pass error messages cleanly
  • Runs as the correct user with proper permissions
  • Provides adequate time (5 minutes) for users to see the error

The implementation follows established patterns from the existing desktopRunner.Execute() method and handles errors appropriately with good context.

@sgress454 sgress454 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Tested that the "launch desktop w/ permanent error" feature works. Only thing I noticed was that when launched w/ permanent error, quitting Orbit doesn't cause the desktop to immediately quit. I don't think this is an issue since when Orbit starts, it explicitly quits any desktop instances it finds. Just pointing it out.

@lucasmrod

Copy link
Copy Markdown
Member Author

quitting Orbit doesn't cause the desktop to immediately quit.

Did you test this on macOS? On Linux as a fleetd package it seems to work (killing orbit kills child processes). IIRC macOS is different due to the use of open.

@lucasmrod
lucasmrod merged commit 5363ce1 into main Jul 24, 2025
53 checks passed
@lucasmrod
lucasmrod deleted the add-fleet-desktop-perm-errors branch July 24, 2025 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TPM: fleet-desktop displays errors

2 participants