Skip to content

fleetd generate TPM key and issue SCEP certificate - #30932

Merged
lucasmrod merged 19 commits into
mainfrom
30461-fleetd-generate-tpm-key
Jul 18, 2025
Merged

fleetd generate TPM key and issue SCEP certificate#30932
lucasmrod merged 19 commits into
mainfrom
30461-fleetd-generate-tpm-key

Conversation

@lucasmrod

@lucasmrod lucasmrod commented Jul 16, 2025

Copy link
Copy Markdown
Member

#30461

This PR contains the changes for the happy path.
On a separate PR we will be adding tests and further fixes for edge cases.

  • Changes file added for user-visible changes in changes/, orbit/changes/ or ee/fleetd-chrome/changes.
    See Changes files for more information.
  • Added/updated automated tests
  • Manual QA for all new/changed functionality
  • For Orbit and Fleet Desktop changes:
    • Make sure fleetd is compatible with the latest released version of Fleet (see Must rule).
    • Orbit runs on macOS, Linux and Windows. Check if the orbit feature/bugfix should only apply to one platform (runtime.GOOS).
    • Manual QA must be performed in the three main OSs, macOS, Windows and Linux.
    • Auto-update manual QA, from released version of component to new version (see tools/tuf/test).

Summary by CodeRabbit

  • New Features

    • Added support for using a TPM-backed key and SCEP-issued certificate to sign HTTP requests, enhancing security through hardware-based key management.
    • Introduced new CLI and environment flags to enable TPM-backed client certificates for Linux packages and Orbit.
    • Added a local HTTPS proxy that automatically signs requests using the TPM-backed key.
  • Bug Fixes

    • Improved cleanup and restart behavior when authentication fails with a host identity certificate.
  • Tests

    • Added comprehensive tests for SCEP client functionality and TPM integration.
  • Chores

    • Updated scripts and documentation to support TPM-backed client certificate packaging and configuration.

@coderabbitai

coderabbitai Bot commented Jul 16, 2025

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

This change introduces support for using TPM-backed keys and SCEP-issued client certificates for signing HTTP requests from fleetd/orbit on Linux. It adds new CLI flags, packaging options, hardware key management via a new secure hardware abstraction, SCEP client and certificate issuance logic, and a local HTTPS proxy for HTTP signature signing. Related code paths, tests, and scripts are updated accordingly.

Changes

File(s) / Group Change summary
cmd/fleetctl/fleetctl/package.go, orbit/cmd/orbit/orbit.go, tools/tuf/test/gen_pkgs.sh Add --fleet-managed-client-certificate CLI flag for package/orbit, with validation and environment variable support.
orbit/pkg/packaging/packaging.go, orbit/pkg/packaging/linux_shared.go Add packaging option and env var for TPM-backed client certificate.
ee/orbit/pkg/hostidentity/host_identity.go New package for managing hardware-backed credentials and SCEP certificate issuance/validation.
ee/orbit/pkg/scep/scep.go, ee/orbit/pkg/scep/scep_test.go, ee/orbit/pkg/scep/testdata/* New SCEP client package with tests and test CA data for certificate enrollment.
ee/orbit/pkg/securehw/securehw.go, ee/orbit/pkg/securehw/securehw_linux.go, ee/orbit/pkg/securehw/securehw_stub.go, ee/orbit/pkg/securehw/example_linux_test.go New secure hardware abstraction for TEE/TPM key management, with Linux and stub implementations, plus example test.
ee/orbit/pkg/httpsigproxy/httpsigproxy.go New HTTPS proxy for local HTTP signature signing using hardware-backed keys.
pkg/fleethttpsig/fleethttpsig.go New package for HTTP signature signing and verification configuration.
server/service/base_client.go, server/service/base_client_test.go, server/service/client.go, server/service/device_client.go, server/service/orbit_client.go, cmd/osquery-perf/agent.go Update client constructors and usages to support optional HTTP signer wrapper and host identity certificate path.
orbit/pkg/constant/constant.go Add constant for host identity certificate file name.
ee/server/service/hostidentity/httpsig/httpsig.go, ee/server/service/hostidentity/httpsig/middleware.go Refactor HTTP signature verification to use new package and update request filtering/handling.
ee/server/service/hostidentity/depot/depot.go Remove comment about empty common name handling.
ee/server/service/scep_proxy.go, server/mdm/scep/client/client.go, server/mdm/scep/server/endpoint.go, server/mdm/scep/cmd/scepclient/scepclient.go Refactor SCEP client/server to use functional options for timeouts, root CA, and insecure mode.
ee/server/integrationtest/hostidentity/hostidentity_test.go Update SCEP client calls in tests for new signature.
go.mod Add github.com/google/go-tpm as an indirect dependency.
orbit/changes/fleetd-tpm-key Add documentation for new TPM-backed key feature.
tools/tuf/test/create_repository.sh Update script messages and default osquery version.
Dockerfile-desktop-linux Add third_party directory to build context.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant fleetd/orbit
    participant SecureHW (TPM)
    participant SCEP Server
    participant HTTPSig Proxy
    participant Fleet Server

    User->>fleetd/orbit: Start with --fleet-managed-client-certificate
    fleetd/orbit->>SecureHW (TPM): Create/load TPM key
    fleetd/orbit->>SCEP Server: Request certificate (CSR with TPM key)
    SCEP Server-->>fleetd/orbit: Issue certificate
    fleetd/orbit->>HTTPSig Proxy: Start local HTTPS proxy with signer
    User->>fleetd/orbit: Make HTTP request to Fleet
    fleetd/orbit->>HTTPSig Proxy: Proxy request (sign with TPM key)
    HTTPSig Proxy->>Fleet Server: Forward signed request
    Fleet Server-->>HTTPSig Proxy: Respond
    HTTPSig Proxy-->>fleetd/orbit: Return response
Loading

Possibly related issues

Possibly related PRs

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 30461-fleetd-generate-tpm-key

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

@getvictor

Copy link
Copy Markdown
Member

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 16, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Full review triggered.

@codecov

codecov Bot commented Jul 16, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 18.22183% with 929 lines in your changes missing coverage. Please review.

Project coverage is 64.04%. Comparing base (1d1c174) to head (2b1b7a7).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
ee/orbit/pkg/securehw/securehw_linux.go 0.00% 477 Missing ⚠️
ee/orbit/pkg/httpsigproxy/httpsigproxy.go 0.00% 113 Missing ⚠️
ee/orbit/pkg/hostidentity/host_identity.go 0.00% 95 Missing ⚠️
orbit/cmd/orbit/orbit.go 0.00% 92 Missing ⚠️
ee/orbit/pkg/scep/scep.go 69.07% 46 Missing and 14 partials ⚠️
server/mdm/scep/server/endpoint.go 41.02% 22 Missing and 1 partial ⚠️
.../server/service/hostidentity/httpsig/middleware.go 54.05% 14 Missing and 3 partials ⚠️
ee/orbit/pkg/securehw/securehw.go 0.00% 13 Missing ⚠️
pkg/fleethttpsig/fleethttpsig.go 50.00% 9 Missing ⚠️
server/service/orbit_client.go 0.00% 9 Missing ⚠️
... and 5 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #30932      +/-   ##
==========================================
- Coverage   64.24%   64.04%   -0.20%     
==========================================
  Files        1894     1900       +6     
  Lines      186345   187355    +1010     
  Branches     5450     5376      -74     
==========================================
+ Hits       119717   119995     +278     
- Misses      57238    57928     +690     
- Partials     9390     9432      +42     
Flag Coverage Δ
backend 64.91% <18.22%> (-0.25%) ⬇️

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.

@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: 5

🧹 Nitpick comments (7)
tools/tpm/README.md (1)

1-25: Well-structured documentation with clear prerequisites and usage instructions.

This README provides a good overview of the TPM tool's purpose and workflow. The step-by-step workflow explanation and clear prerequisites make it easy for users to understand what's needed. The build and run instructions are straightforward and include the necessary environment variables.

A few suggestions for improvement:

  • Consider adding a brief explanation of what SCEP is for users unfamiliar with the protocol
  • The architecture specification in the build command (arm64) might be confusing - consider explaining why this specific architecture is used or making it more generic
  • Consider adding troubleshooting tips for common TPM-related issues
tools/tpm/tpm.go (1)

47-57: Use log.Fatalf instead of log.Panicf for consistency.

 	if err != nil {
-		log.Panicf("Failed to create or load client certificate: %v", err)
+		log.Fatalf("Failed to create or load client certificate: %v", err)
 	}
 
 	// Verify the certificate was successfully saved
 	if clientCertificate.C == nil {
-		log.Panic("missing certificate")
+		log.Fatal("missing certificate")
 	}
 	if clientCertificate.C.SerialNumber.Cmp(big.NewInt(0)) == 0 {
-		log.Panicf("invalid serial number: %v", clientCertificate.C.SerialNumber)
+		log.Fatalf("invalid serial number: %v", clientCertificate.C.SerialNumber)
 	}
orbit/cmd/orbit/orbit.go (1)

952-975: Complete the TPM certificate integration for HTTP signing.

The certificate is successfully created but not used for HTTP signing as indicated by the TODO comment. This leaves the feature incomplete.

Would you like me to help implement the HTTP signing integration or create an issue to track this work?

ee/orbit/pkg/securehw/securehw_linux.go (2)

32-32: Consider making the TPM device path configurable.

Hardcoding /dev/tpmrm0 might not work on all systems. Some systems might use /dev/tpm0 or have the TPM at a different path.

Consider accepting the device path as a parameter or environment variable with /dev/tpmrm0 as the default.


354-356: Add clarifying comment about deterministic parent key.

The comment mentions that createParentKey is deterministic, which is important for loading child keys. This deserves emphasis.

 	// Get the parent key handle.
 	//
-	// NOTE: createParentKey calls CreatePrimary which creates the parent key
-	// deterministically so this can be called when loadind a child key.
+	// NOTE: createParentKey calls CreatePrimary which creates the parent key
+	// deterministically, allowing us to recreate the same parent key handle
+	// when loading a previously created child key.
ee/orbit/pkg/scep/scep.go (2)

126-129: Make the error message more specific.

When validation fails, specify which required field is missing to help with debugging.

 	// Check that required options are set.
 	// SCEP challenge is optional since the SCEP server could allow an empty challenge.
-	if c.scepURL == "" || c.commonName == "" || c.signingKey == nil {
-		return nil, errors.New("required SCEP client options not set")
+	if c.scepURL == "" {
+		return nil, errors.New("scep URL is required")
+	}
+	if c.commonName == "" {
+		return nil, errors.New("common name is required")
+	}
+	if c.signingKey == nil {
+		return nil, errors.New("signing key is required")
 	}

279-314: Consider preserving log levels in the adapter.

The adapter always logs at Info level, which might hide important debug or error messages from the SCEP library.

You could check for a "level" field in the keyvals and map it to the appropriate zerolog level. This would preserve the intended log levels from the kit/log interface.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 34f53b9 and 853cb90.

⛔ Files ignored due to path filters (2)
  • ee/orbit/pkg/scep/testdata/ca.pem is excluded by !**/*.pem
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (28)
  • changes/30461-fleetd-generate-tpm-key (1 hunks)
  • cmd/fleetctl/fleetctl/package.go (2 hunks)
  • ee/orbit/pkg/hostidentity/host_identity.go (1 hunks)
  • ee/orbit/pkg/scep/scep.go (1 hunks)
  • ee/orbit/pkg/scep/scep_test.go (1 hunks)
  • ee/orbit/pkg/scep/testdata/ca.crt (1 hunks)
  • ee/orbit/pkg/scep/testdata/ca.key (1 hunks)
  • ee/orbit/pkg/securehw/example_linux_test.go (1 hunks)
  • ee/orbit/pkg/securehw/securehw.go (1 hunks)
  • ee/orbit/pkg/securehw/securehw_linux.go (1 hunks)
  • ee/orbit/pkg/securehw/securehw_stub.go (1 hunks)
  • ee/server/integrationtest/hostidentity/hostidscep_test.go (2 hunks)
  • ee/server/service/hostidentity/depot/depot.go (0 hunks)
  • ee/server/service/scep_proxy.go (4 hunks)
  • go.mod (1 hunks)
  • orbit/changes/fleetd-tpm-key (1 hunks)
  • orbit/cmd/orbit/orbit.go (4 hunks)
  • orbit/pkg/constant/constant.go (1 hunks)
  • orbit/pkg/packaging/linux_shared.go (1 hunks)
  • orbit/pkg/packaging/packaging.go (1 hunks)
  • server/mdm/scep/client/client.go (1 hunks)
  • server/mdm/scep/cmd/scepclient/scepclient.go (1 hunks)
  • server/mdm/scep/depot/fleet.go (0 hunks)
  • server/mdm/scep/server/endpoint.go (3 hunks)
  • tools/tpm/README.md (1 hunks)
  • tools/tpm/tpm.go (1 hunks)
  • tools/tuf/test/create_repository.sh (1 hunks)
  • tools/tuf/test/gen_pkgs.sh (5 hunks)
💤 Files with no reviewable changes (2)
  • server/mdm/scep/depot/fleet.go
  • ee/server/service/hostidentity/depot/depot.go
🧰 Additional context used
🧠 Learnings (11)
📓 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/scep/testdata/ca.crt (1)
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.
tools/tpm/tpm.go (2)
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.
Learnt from: getvictor
PR: fleetdm/fleet#30589
File: ee/server/service/hostidentity/depot/depot.go:108-111
Timestamp: 2025-07-08T16:12:48.797Z
Learning: In ee/server/service/hostidentity/depot/depot.go, the SCEP depot interface methods like Put() do not accept context parameters, and the common_mysql.WithRetryTxx callback function type TxFn only receives a transaction parameter, not a context. Therefore, using context.Background() in tx.ExecContext calls within the transaction callback is the correct approach.
ee/server/integrationtest/hostidentity/hostidscep_test.go (3)
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.
Learnt from: getvictor
PR: fleetdm/fleet#30820
File: third_party/httpsig-go/base.go:241-248
Timestamp: 2025-07-13T10:10:47.201Z
Learning: In the vendored httpsig-go library at third_party/httpsig-go/, the @target-uri derived component is not being used, so bugs in the deriveTargetURI function are not a concern for the current implementation.
Learnt from: getvictor
PR: fleetdm/fleet#30589
File: ee/server/service/hostidentity/depot/depot.go:108-111
Timestamp: 2025-07-08T16:12:48.797Z
Learning: In ee/server/service/hostidentity/depot/depot.go, the SCEP depot interface methods like Put() do not accept context parameters, and the common_mysql.WithRetryTxx callback function type TxFn only receives a transaction parameter, not a context. Therefore, using context.Background() in tx.ExecContext calls within the transaction callback is the correct approach.
ee/server/service/scep_proxy.go (1)
Learnt from: getvictor
PR: fleetdm/fleet#30589
File: ee/server/service/hostidentity/depot/depot.go:108-111
Timestamp: 2025-07-08T16:12:48.797Z
Learning: In ee/server/service/hostidentity/depot/depot.go, the SCEP depot interface methods like Put() do not accept context parameters, and the common_mysql.WithRetryTxx callback function type TxFn only receives a transaction parameter, not a context. Therefore, using context.Background() in tx.ExecContext calls within the transaction callback is the correct approach.
ee/orbit/pkg/hostidentity/host_identity.go (1)
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.
server/mdm/scep/server/endpoint.go (1)
Learnt from: getvictor
PR: fleetdm/fleet#30589
File: ee/server/service/hostidentity/depot/depot.go:108-111
Timestamp: 2025-07-08T16:12:48.797Z
Learning: In ee/server/service/hostidentity/depot/depot.go, the SCEP depot interface methods like Put() do not accept context parameters, and the common_mysql.WithRetryTxx callback function type TxFn only receives a transaction parameter, not a context. Therefore, using context.Background() in tx.ExecContext calls within the transaction callback is the correct approach.
orbit/cmd/orbit/orbit.go (2)
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.
Learnt from: getvictor
PR: fleetdm/fleet#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.
ee/orbit/pkg/securehw/securehw_linux.go (1)
Learnt from: getvictor
PR: fleetdm/fleet#30825
File: ee/server/service/hostidentity/httpsig/httpsig.go:86-88
Timestamp: 2025-07-15T07:26:38.884Z
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.
ee/orbit/pkg/scep/scep_test.go (4)
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.
Learnt from: getvictor
PR: fleetdm/fleet#30825
File: ee/server/service/hostidentity/httpsig/httpsig.go:86-88
Timestamp: 2025-07-15T07:26:38.884Z
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: fleetdm/fleet#30589
File: ee/server/service/hostidentity/depot/depot.go:108-111
Timestamp: 2025-07-08T16:12:48.797Z
Learning: In ee/server/service/hostidentity/depot/depot.go, the SCEP depot interface methods like Put() do not accept context parameters, and the common_mysql.WithRetryTxx callback function type TxFn only receives a transaction parameter, not a context. Therefore, using context.Background() in tx.ExecContext calls within the transaction callback is the correct approach.
Learnt from: getvictor
PR: fleetdm/fleet#30820
File: third_party/httpsig-go/base.go:241-248
Timestamp: 2025-07-13T10:10:47.201Z
Learning: In the vendored httpsig-go library at third_party/httpsig-go/, the @target-uri derived component is not being used, so bugs in the deriveTargetURI function are not a concern for the current implementation.
ee/orbit/pkg/scep/scep.go (3)
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.
Learnt from: getvictor
PR: fleetdm/fleet#30825
File: ee/server/service/hostidentity/httpsig/httpsig.go:86-88
Timestamp: 2025-07-15T07:26:38.884Z
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: fleetdm/fleet#30589
File: ee/server/service/hostidentity/depot/depot.go:108-111
Timestamp: 2025-07-08T16:12:48.797Z
Learning: In ee/server/service/hostidentity/depot/depot.go, the SCEP depot interface methods like Put() do not accept context parameters, and the common_mysql.WithRetryTxx callback function type TxFn only receives a transaction parameter, not a context. Therefore, using context.Background() in tx.ExecContext calls within the transaction callback is the correct approach.
🧬 Code Graph Analysis (2)
server/mdm/scep/cmd/scepclient/scepclient.go (1)
server/mdm/scep/client/client.go (1)
  • New (50-74)
orbit/cmd/orbit/orbit.go (1)
ee/orbit/pkg/hostidentity/host_identity.go (1)
  • CreateOrLoadClientCertificate (28-90)
🪛 GitHub Actions: Go Tests
ee/orbit/pkg/securehw/example_linux_test.go

[error] 20-20: TestExampleTPM20Linux failed: Test needs to be run as root. Panic at example_linux_test.go:20.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: run-tuf-and-gen-pkgs
  • GitHub Check: run-server (mysql:8.0.36)
  • GitHub Check: publish
  • GitHub Check: test-packaging (ubuntu-latest, local)
🔇 Additional comments (40)
go.mod (1)

247-247: Confirm go-tpm v0.9.5 and review security

ee/orbit/pkg/scep/testdata/ca.key (1)

1-55: Test data file looks good

This encrypted RSA private key serves as appropriate test data for the SCEP functionality. The PEM format is correct and the encryption (while older DES-EDE3-CBC) is acceptable for test purposes.

orbit/pkg/packaging/linux_shared.go (1)

336-336: Environment variable template addition looks correct

The conditional template syntax properly sets ORBIT_FLEET_MANAGED_CLIENT_CERTIFICATE=true when the option is enabled. This integrates well with the new TPM-backed client certificate functionality.

ee/server/integrationtest/hostidentity/hostidscep_test.go (1)

72-72: API signature updates look correct

The removal of the third nil argument from scepclient.New calls aligns with the updated constructor signature that now uses functional options instead of a fixed timeout parameter. The changes are consistent across both test functions.

Also applies to: 256-256

orbit/pkg/packaging/packaging.go (1)

136-137: Well-documented struct field addition

The FleetManagedClientCertificate boolean field is appropriately named and clearly documented. It provides a clean configuration option for enabling TPM-backed key signing for HTTP requests.

orbit/pkg/constant/constant.go (1)

78-79: Good addition of the certificate filename constant.

The new constant follows the existing naming convention and provides a clear, consistent way to reference the host identity certificate file across the codebase.

changes/30461-fleetd-generate-tpm-key (1)

1-1: Clear and informative changelog entry.

The description accurately explains the new flag and its purpose for Linux TPM-based HTTP request signing.

orbit/changes/fleetd-tpm-key (1)

1-1: Comprehensive changelog entry for the TPM feature.

The description provides good technical detail about the TPM 2.0 key generation and SCEP certificate functionality, including the controlling environment variable.

tools/tuf/test/create_repository.sh (3)

26-26: Good improvement to user guidance.

Adding the Ctrl+C exit instruction makes the prompt more helpful and user-friendly.


33-33: Correct fix for the "no" response behavior.

Changing from break to exit 0 ensures the script actually exits when the user declines to remove the directory, rather than continuing execution.


41-41: More accurate terminology.

Changing "packages" to "components" better reflects what the script is actually generating.

ee/orbit/pkg/scep/testdata/ca.crt (1)

1-31: Appropriate test certificate for SCEP functionality.

This PEM-encoded CA certificate is properly formatted and appropriately placed in the testdata directory to support testing of the new SCEP client implementation.

server/mdm/scep/cmd/scepclient/scepclient.go (1)

73-73: Great cleanup - removing unnecessary nil parameter.

This change correctly aligns with the refactored scepclient.New function that now uses a variadic options pattern instead of requiring a fixed timeout parameter. The removal of the nil argument simplifies the call and matches the new API design shown in the relevant code snippets.

ee/orbit/pkg/securehw/securehw_stub.go (1)

1-14: Well-designed platform abstraction with clear error handling.

This stub implementation provides a clean way to handle TPM functionality on non-Linux platforms. The build constraints correctly exclude Linux, and the "not implemented" error message clearly communicates the limitation. This follows good Go practices for platform-specific code and allows the rest of the system to gracefully handle the absence of TPM support.

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

30-30: Good documentation addition for the new environment variable.

The documentation clearly explains the purpose of the FLEET_MANAGED_CLIENT_CERTIFICATE variable for TPM-backed key usage in HTTP signing. This helps users understand the new functionality.


85-85: Consistent integration of TPM certificate flag across Linux packages.

The conditional inclusion of --fleet-managed-client-certificate flag is properly implemented for all Linux package types (DEB/RPM, amd64/arm64). The flag is correctly tied to the USE_FLEET_SERVER_CERTIFICATE environment variable, which makes sense since TPM-backed certificates would be used in conjunction with custom certificate configurations.

Note that this flag is appropriately excluded from MSI packages, which aligns with the Linux-only TPM support based on the stub implementation in ee/orbit/pkg/securehw/securehw_stub.go.

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

ee/server/service/scep_proxy.go (1)

65-65: Consistent adoption of functional options pattern for SCEP client creation.

These changes properly update all SCEP client instantiations to use the new functional options pattern with scepclient.WithTimeout(). This refactoring improves the API design by making it more extensible and consistent with modern Go practices. All four locations are updated consistently, ensuring uniform behavior across the service.

Also applies to: 84-84, 104-104, 331-331

cmd/fleetctl/fleetctl/package.go (1)

258-263: LGTM!

The new flag and validation logic are well-implemented. The restrictions to deb/rpm packages and the mutual exclusivity with traditional TLS client certificates are appropriate for TPM-backed keys.

Also applies to: 294-302

tools/tpm/tpm.go (1)

31-35: Verify if removing the metadata directory is intended.

The deferred removal of the metadata directory might delete important TPM key blobs and certificates. Is this a one-time enrollment tool, or should it support persistent keys across runs?

server/mdm/scep/client/client.go (1)

18-66: Well-executed refactoring to the options pattern!

The migration from a single timeout parameter to a flexible options pattern improves the API's extensibility. The implementation follows Go best practices for functional options.

ee/orbit/pkg/securehw/securehw.go (3)

10-39: Well-designed interfaces for hardware cryptography!

The TEE and Key interfaces provide a clean abstraction for hardware-based cryptographic operations. The documentation is clear and helpful.


41-44: Good logging context addition.

Adding the component to the logger context will help with debugging TPM operations.


46-68: Proper error types for specific failure scenarios.

The custom error types will help callers distinguish between different failure modes (key not found vs hardware unavailable).

ee/orbit/pkg/hostidentity/host_identity.go (3)

43-55: Good error handling for key loading.

Nice use of error type checking to distinguish between "key not found" and other errors.


92-103: Proper certificate parsing implementation.

The function correctly reads and parses the PEM-encoded certificate with appropriate error messages.


105-119: Secure file permissions for certificate storage.

Good choice using 0o600 permissions to restrict access to the certificate file.

server/mdm/scep/server/endpoint.go (2)

118-147: Clean functional options implementation!

The functional options pattern is a great choice here. It makes the API more flexible and maintains backward compatibility.


171-191: Proper TLS configuration with security considerations.

Good implementation with:

  • Minimum TLS 1.2 enforcement
  • Proper root CA pool handling
  • Clear comment about InsecureSkipVerify being for development/testing only
ee/orbit/pkg/scep/scep_test.go (3)

33-105: Thorough parameter validation tests!

Great test coverage for the NewClient function. The table-driven tests make it easy to add new cases.


107-167: Comprehensive integration tests for certificate fetching.

Good coverage of both success and error cases. The assertions verify important certificate properties.


178-222: Well-structured test server setup.

The test server properly simulates a SCEP server with appropriate cleanup.

ee/orbit/pkg/securehw/securehw_linux.go (3)

64-157: Robust key creation with proper cleanup!

The implementation:

  • Handles errors properly with cleanup
  • Saves context for future use
  • Writes blobs atomically

Good error handling pattern with cleanUpOnError.


217-260: Smart curve selection implementation.

Testing for P-384 support by actually trying to create a key is more reliable than querying capabilities. Nice fallback to P-256!


516-575: Correct ECDSA signature implementation.

The signing implementation properly:

  • Supports both SHA256 and SHA384
  • Converts TPM signature format to ASN.1 DER format required for X.509
  • Handles the ECDSA signature structure correctly
ee/orbit/pkg/scep/scep.go (6)

1-21: The imports look good!

All imports are properly organized and appear to be used in the implementation.


23-28: Nice interface design!

The SigningKey interface follows Go best practices with a single method and clear documentation about thread safety.


30-46: Well-structured client type!

The Client struct has all the necessary fields with clear documentation. Good use of pointer for timeout to handle default values.


48-106: Great use of functional options pattern!

The options provide a clean and flexible API for configuring the client. Good documentation on the Insecure option noting it's for tests only.


137-277: Excellent implementation of the SCEP protocol!

The dual-key approach (temporary RSA for SCEP envelope, actual key for CSR) is correctly implemented and well-documented. The comments clearly explain why RSA is needed for the SCEP protocol even when using ECC keys for the actual certificate.


316-326: Good utility function for key comparison!

Using PKIX marshaling for comparison works universally for all key types.

Comment thread tools/tpm/tpm.go Outdated
Comment thread tools/tpm/tpm.go Outdated
Comment thread ee/orbit/pkg/securehw/example_linux_test.go
Comment thread ee/orbit/pkg/securehw/example_linux_test.go
Comment thread ee/orbit/pkg/hostidentity/host_identity.go Outdated
Comment thread changes/30461-fleetd-generate-tpm-key
Comment thread cmd/fleetctl/fleetctl/package.go
Comment thread ee/orbit/pkg/hostidentity/host_identity.go Outdated
Comment thread ee/orbit/pkg/hostidentity/host_identity.go
Comment thread ee/orbit/pkg/scep/scep.go

if c.timeout == nil {
// Set a sane default for the timeout.
c.timeout = ptr.Duration(30 * time.Second)

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.

Nit. Is there a global constant that we can use for timeout in orbit?

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.

Not that I know of.

Comment thread ee/orbit/pkg/scep/scep.go Outdated
Comment thread ee/orbit/pkg/securehw/securehw_linux.go Outdated
Restricted: true, // Limits use to decryption of child keys
},
Parameters: tpm2.NewTPMUPublicParms(
tpm2.TPMAlgRSA,

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.

Nit. Switch this to ECC 256 for faster unwrapping. But this should only happen once, so maybe not a big deal.

Comment thread orbit/cmd/orbit/orbit.go Outdated
Comment thread server/mdm/scep/depot/fleet.go
@lucasmrod
lucasmrod marked this pull request as ready for review July 18, 2025 03:34
@lucasmrod
lucasmrod requested a review from a team as a code owner July 18, 2025 03:34
@getvictor

Copy link
Copy Markdown
Member

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 18, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Full review triggered.

@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: 1

♻️ Duplicate comments (4)
cmd/fleetctl/fleetctl/package.go (1)

294-301: Appropriate validation for TPM certificate feature.

The validation correctly restricts the feature to Linux packages (deb/rpm) where TPM 2.0 is supported, and prevents conflicts with existing TLS certificate options.

ee/orbit/pkg/securehw/example_linux_test.go (1)

30-58: Use testing framework methods instead of log.Fatal.

For consistency with Go testing conventions, please use t.Fatalf instead of log.Fatalf throughout the test functions.

Also applies to: 60-91

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

239-243: Thank you for documenting the EE licensing requirement!

The flag clearly indicates this is a Fleet EE feature, addressing the previous review feedback about premium-only documentation.

ee/orbit/pkg/hostidentity/host_identity.go (1)

50-65: Consider updating TEE terminology to SecureHW or TPM.

The error messages still use "TEE" terminology. As mentioned in past review comments, this should be updated to use "SecureHW" or "TPM" for consistency.

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

226-230: Consider safer error formatting.

The error format %#v might expose sensitive request details. Consider using a more controlled error message.

 func (s *signingRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
 	// Sign the request before sending
 	if err := s.signer.Sign(req); err != nil {
-		return nil, fmt.Errorf("signing request: %#v", err)
+		return nil, fmt.Errorf("signing request: %w", err)
 	}
ee/orbit/pkg/scep/scep.go (1)

175-184: Consider making signature algorithm dynamic.

The code assumes signer.Public() will always be an ECDSA key and hardcodes ECDSAWithSHA256. Consider detecting the key type and selecting the appropriate algorithm.

+    var sigAlg x509.SignatureAlgorithm
+    switch signer.Public().(type) {
+    case *ecdsa.PublicKey:
+        sigAlg = x509.ECDSAWithSHA256
+    case *rsa.PublicKey:
+        sigAlg = x509.SHA256WithRSA
+    default:
+        return nil, fmt.Errorf("unsupported key type: %T", signer.Public())
+    }
+
     csrTemplate := x509util.CertificateRequest{
         CertificateRequest: x509.CertificateRequest{
             Subject: pkix.Name{
                 CommonName: c.commonName,
             },
-            // Currently, signer.Public() will always be of type *ecdsa.PublicKey.
-            SignatureAlgorithm: x509.ECDSAWithSHA256,
+            SignatureAlgorithm: sigAlg,
         },
         ChallengePassword: c.scepChallenge,
     }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8f2f805 and 9618bc0.

⛔ Files ignored due to path filters (2)
  • ee/orbit/pkg/scep/testdata/ca.pem is excluded by !**/*.pem
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (36)
  • Dockerfile-desktop-linux (1 hunks)
  • changes/30461-fleetd-generate-tpm-key (1 hunks)
  • cmd/fleetctl/fleetctl/package.go (2 hunks)
  • cmd/osquery-perf/agent.go (1 hunks)
  • ee/orbit/pkg/hostidentity/host_identity.go (1 hunks)
  • ee/orbit/pkg/httpsigproxy/httpsigproxy.go (1 hunks)
  • ee/orbit/pkg/scep/scep.go (1 hunks)
  • ee/orbit/pkg/scep/scep_test.go (1 hunks)
  • ee/orbit/pkg/scep/testdata/ca.crt (1 hunks)
  • ee/orbit/pkg/scep/testdata/ca.key (1 hunks)
  • ee/orbit/pkg/securehw/example_linux_test.go (1 hunks)
  • ee/orbit/pkg/securehw/securehw.go (1 hunks)
  • ee/orbit/pkg/securehw/securehw_linux.go (1 hunks)
  • ee/orbit/pkg/securehw/securehw_stub.go (1 hunks)
  • ee/server/integrationtest/hostidentity/hostidentity_test.go (2 hunks)
  • ee/server/service/hostidentity/depot/depot.go (0 hunks)
  • ee/server/service/hostidentity/httpsig/httpsig.go (2 hunks)
  • ee/server/service/hostidentity/httpsig/middleware.go (2 hunks)
  • ee/server/service/scep_proxy.go (4 hunks)
  • go.mod (1 hunks)
  • orbit/changes/fleetd-tpm-key (1 hunks)
  • orbit/cmd/orbit/orbit.go (10 hunks)
  • orbit/pkg/constant/constant.go (1 hunks)
  • orbit/pkg/packaging/linux_shared.go (1 hunks)
  • orbit/pkg/packaging/packaging.go (1 hunks)
  • pkg/fleethttpsig/fleethttpsig.go (1 hunks)
  • server/mdm/scep/client/client.go (1 hunks)
  • server/mdm/scep/cmd/scepclient/scepclient.go (1 hunks)
  • server/mdm/scep/server/endpoint.go (3 hunks)
  • server/service/base_client.go (2 hunks)
  • server/service/base_client_test.go (12 hunks)
  • server/service/client.go (1 hunks)
  • server/service/device_client.go (1 hunks)
  • server/service/orbit_client.go (4 hunks)
  • tools/tuf/test/create_repository.sh (1 hunks)
  • tools/tuf/test/gen_pkgs.sh (5 hunks)
💤 Files with no reviewable changes (1)
  • ee/server/service/hostidentity/depot/depot.go
🧰 Additional context used
🧠 Learnings (16)
📓 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/server/integrationtest/hostidentity/hostidentity_test.go (3)
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.
Learnt from: getvictor
PR: fleetdm/fleet#30589
File: ee/server/service/hostidentity/depot/depot.go:108-111
Timestamp: 2025-07-08T16:12:48.797Z
Learning: In ee/server/service/hostidentity/depot/depot.go, the SCEP depot interface methods like Put() do not accept context parameters, and the common_mysql.WithRetryTxx callback function type TxFn only receives a transaction parameter, not a context. Therefore, using context.Background() in tx.ExecContext calls within the transaction callback is the correct approach.
Learnt from: getvictor
PR: fleetdm/fleet#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.
orbit/pkg/constant/constant.go (1)
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/scep/testdata/ca.crt (1)
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/server/service/hostidentity/httpsig/middleware.go (3)
Learnt from: getvictor
PR: fleetdm/fleet#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: 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.
Learnt from: getvictor
PR: fleetdm/fleet#30820
File: third_party/httpsig-go/base.go:241-248
Timestamp: 2025-07-13T10:10:47.226Z
Learning: In the vendored httpsig-go library at third_party/httpsig-go/, the @target-uri derived component is not being used, so bugs in the deriveTargetURI function are not a concern for the current implementation.
ee/server/service/hostidentity/httpsig/httpsig.go (3)
Learnt from: getvictor
PR: fleetdm/fleet#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: fleetdm/fleet#30820
File: third_party/httpsig-go/base.go:241-248
Timestamp: 2025-07-13T10:10:47.226Z
Learning: In the vendored httpsig-go library at third_party/httpsig-go/, the @target-uri derived component is not being used, so bugs in the deriveTargetURI function are not a concern for the current implementation.
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/server/service/scep_proxy.go (1)
Learnt from: getvictor
PR: fleetdm/fleet#30589
File: ee/server/service/hostidentity/depot/depot.go:108-111
Timestamp: 2025-07-08T16:12:48.797Z
Learning: In ee/server/service/hostidentity/depot/depot.go, the SCEP depot interface methods like Put() do not accept context parameters, and the common_mysql.WithRetryTxx callback function type TxFn only receives a transaction parameter, not a context. Therefore, using context.Background() in tx.ExecContext calls within the transaction callback is the correct approach.
server/service/orbit_client.go (1)
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/securehw/example_linux_test.go (1)
Learnt from: sgress454
PR: fleetdm/fleet#30882
File: orbit/pkg/user/user_linux.go:75-100
Timestamp: 2025-07-15T18:52:39.239Z
Learning: In orbit/pkg/user/user_linux.go, for the GetUserContext function, the user considers PID validation unnecessary when using `pgrep -nx systemd` because pgrep with these flags should only return valid numeric PIDs, making additional validation overkill.
pkg/fleethttpsig/fleethttpsig.go (2)
Learnt from: getvictor
PR: fleetdm/fleet#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: fleetdm/fleet#30820
File: third_party/httpsig-go/base.go:241-248
Timestamp: 2025-07-13T10:10:47.226Z
Learning: In the vendored httpsig-go library at third_party/httpsig-go/, the @target-uri derived component is not being used, so bugs in the deriveTargetURI function are not a concern for the current implementation.
ee/orbit/pkg/hostidentity/host_identity.go (4)
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.
Learnt from: getvictor
PR: fleetdm/fleet#30589
File: ee/server/service/hostidentity/depot/depot.go:108-111
Timestamp: 2025-07-08T16:12:48.797Z
Learning: In ee/server/service/hostidentity/depot/depot.go, the SCEP depot interface methods like Put() do not accept context parameters, and the common_mysql.WithRetryTxx callback function type TxFn only receives a transaction parameter, not a context. Therefore, using context.Background() in tx.ExecContext calls within the transaction callback is the correct approach.
Learnt from: getvictor
PR: fleetdm/fleet#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: fleetdm/fleet#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.
ee/orbit/pkg/httpsigproxy/httpsigproxy.go (2)
Learnt from: getvictor
PR: fleetdm/fleet#30820
File: third_party/httpsig-go/base.go:241-248
Timestamp: 2025-07-13T10:10:47.226Z
Learning: In the vendored httpsig-go library at third_party/httpsig-go/, the @target-uri derived component is not being used, so bugs in the deriveTargetURI function are not a concern for the current implementation.
Learnt from: getvictor
PR: fleetdm/fleet#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.
orbit/cmd/orbit/orbit.go (4)
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.
Learnt from: getvictor
PR: fleetdm/fleet#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.
Learnt from: getvictor
PR: fleetdm/fleet#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: fleetdm/fleet#30820
File: third_party/httpsig-go/base.go:241-248
Timestamp: 2025-07-13T10:10:47.226Z
Learning: In the vendored httpsig-go library at third_party/httpsig-go/, the @target-uri derived component is not being used, so bugs in the deriveTargetURI function are not a concern for the current implementation.
ee/orbit/pkg/scep/scep_test.go (4)
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.
Learnt from: getvictor
PR: fleetdm/fleet#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: fleetdm/fleet#30589
File: ee/server/service/hostidentity/depot/depot.go:108-111
Timestamp: 2025-07-08T16:12:48.797Z
Learning: In ee/server/service/hostidentity/depot/depot.go, the SCEP depot interface methods like Put() do not accept context parameters, and the common_mysql.WithRetryTxx callback function type TxFn only receives a transaction parameter, not a context. Therefore, using context.Background() in tx.ExecContext calls within the transaction callback is the correct approach.
Learnt from: getvictor
PR: fleetdm/fleet#30820
File: third_party/httpsig-go/base.go:241-248
Timestamp: 2025-07-13T10:10:47.226Z
Learning: In the vendored httpsig-go library at third_party/httpsig-go/, the @target-uri derived component is not being used, so bugs in the deriveTargetURI function are not a concern for the current implementation.
ee/orbit/pkg/securehw/securehw_linux.go (2)
Learnt from: getvictor
PR: fleetdm/fleet#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: fleetdm/fleet#30820
File: third_party/httpsig-go/base.go:241-248
Timestamp: 2025-07-13T10:10:47.226Z
Learning: In the vendored httpsig-go library at third_party/httpsig-go/, the @target-uri derived component is not being used, so bugs in the deriveTargetURI function are not a concern for the current implementation.
ee/orbit/pkg/scep/scep.go (3)
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.
Learnt from: getvictor
PR: fleetdm/fleet#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: fleetdm/fleet#30589
File: ee/server/service/hostidentity/depot/depot.go:108-111
Timestamp: 2025-07-08T16:12:48.797Z
Learning: In ee/server/service/hostidentity/depot/depot.go, the SCEP depot interface methods like Put() do not accept context parameters, and the common_mysql.WithRetryTxx callback function type TxFn only receives a transaction parameter, not a context. Therefore, using context.Background() in tx.ExecContext calls within the transaction callback is the correct approach.
🧬 Code Graph Analysis (6)
server/mdm/scep/cmd/scepclient/scepclient.go (1)
server/mdm/scep/client/client.go (1)
  • New (50-74)
ee/orbit/pkg/securehw/securehw_stub.go (1)
ee/orbit/pkg/securehw/securehw.go (2)
  • TEE (12-26)
  • New (57-60)
ee/server/service/hostidentity/httpsig/httpsig.go (1)
pkg/fleethttpsig/fleethttpsig.go (1)
  • Verifier (19-28)
server/mdm/scep/client/client.go (1)
server/mdm/scep/server/endpoint.go (5)
  • ClientOption (125-125)
  • WithClientTimeout (143-147)
  • WithClientRootCA (128-132)
  • ClientInsecure (136-140)
  • MakeClientEndpoints (152-209)
pkg/fleethttpsig/fleethttpsig.go (3)
third_party/httpsig-go/sign.go (10)
  • Fields (73-82)
  • MetaKeyID (43-43)
  • MetaCreated (39-39)
  • MetaNonce (41-41)
  • DefaultSignatureLabel (48-48)
  • Algorithm (16-16)
  • Algo_ECDSA_P256_SHA256 (31-31)
  • Algo_ECDSA_P384_SHA384 (32-32)
  • MetaAlgorithm (42-42)
  • SigningProfile (55-63)
third_party/httpsig-go/verify.go (3)
  • KeyFetcher (65-70)
  • NewVerifier (123-131)
  • VerifyProfile (74-87)
ee/orbit/pkg/securehw/securehw.go (1)
  • Key (29-43)
ee/orbit/pkg/securehw/securehw_linux.go (1)
ee/orbit/pkg/securehw/securehw.go (9)
  • TEE (12-26)
  • New (57-60)
  • ErrTEEUnavailable (75-77)
  • Key (29-43)
  • ErrKeyNotFound (63-65)
  • HTTPSigner (45-48)
  • ECCAlgorithm (50-50)
  • ECCAlgorithmP256 (53-53)
  • ECCAlgorithmP384 (54-54)
🪛 Gitleaks (8.27.2)
ee/orbit/pkg/scep/testdata/ca.key

1-54: Identified a Private Key, which may compromise cryptographic security and sensitive data encryption.

(private-key)

ee/orbit/pkg/httpsigproxy/httpsigproxy.go

54-58: Identified a Private Key, which may compromise cryptographic security and sensitive data encryption.

(private-key)

🔇 Additional comments (51)
go.mod (1)

249-249: go-tpm v0.9.5 is up to date and free of known vulnerabilities

This dependency version is current and has no reported security issues.

orbit/changes/fleetd-tpm-key (1)

1-1: Nice clear documentation of the new feature

The changes file clearly documents the new TPM 2.0 key generation and SCEP certificate functionality. The description accurately reflects the feature's purpose and mentions the key environment variable users will need to know about.

orbit/pkg/packaging/linux_shared.go (1)

336-336: Good integration with existing packaging patterns

The addition of the conditional environment variable follows the established pattern in the template. The variable name ORBIT_FLEET_MANAGED_CLIENT_CERTIFICATE is consistent with the documentation and will properly enable the TPM-backed certificate feature when the packaging option is set.

orbit/pkg/constant/constant.go (1)

79-79: Well-named constant following existing conventions

The new constant FleetHTTPSignatureCertificateFileName with value "host_identity.crt" is clearly named and follows the established pattern of other certificate filename constants in this file. This will help maintain consistency across the codebase when referencing the host identity certificate file.

ee/server/integrationtest/hostidentity/hostidentity_test.go (2)

99-99: Good update to match the refactored SCEP client constructor

The removal of the third nil argument from scepclient.New aligns with the constructor refactoring mentioned in the AI summary. This change from scepclient.New(scepURL, s.Logger, nil) to scepclient.New(scepURL, s.Logger) is consistent with the move to a variadic functional options pattern.


665-665: Consistent constructor update

Same good update here - removing the unnecessary nil argument to match the refactored SCEP client constructor.

orbit/pkg/packaging/packaging.go (1)

136-137: Integration of FleetManagedClientCertificate verified

I’ve confirmed that this new field is wired up consistently across the codebase:

  • In orbit/pkg/packaging/linux_shared.go, it generates ORBIT_FLEET_MANAGED_CLIENT_CERTIFICATE=true when set.
  • In cmd/fleetctl/fleetctl/package.go, the --fleet-managed-client-certificate flag maps to opt.FleetManagedClientCertificate, includes the correct env var, and enforces deb/rpm only.
  • In cmd/orbit/orbit.go, the same flag and ORBIT_FLEET_MANAGED_CLIENT_CERTIFICATE env var are defined.
  • There is no existing validation method for Options in the packaging package, so no updates are needed there.

Everything looks properly integrated. Great work!

Dockerfile-desktop-linux (1)

13-13: Necessary addition for TPM/SCEP dependencies!

This addition properly includes the third_party directory needed for the new TPM and SCEP functionality. The COPY command follows the established pattern used for other directories.

ee/orbit/pkg/scep/testdata/ca.key (1)

1-54: Legitimate test data for SCEP testing!

This encrypted RSA private key is appropriate test data for the SCEP client implementation. The static analysis tool correctly identified it as a private key, but this is expected since it's intentionally placed in the testdata directory for testing certificate enrollment processes.

The key is properly encrypted with DES-EDE3-CBC and serves its intended purpose for testing SCEP functionality.

changes/30461-fleetd-generate-tpm-key (1)

1-1: Clear and accurate changelog entry!

The description accurately captures the new CLI flag functionality and clearly indicates it's for Linux packages using TPMs for HTTP request signing. The changelog entry is concise and informative.

cmd/osquery-perf/agent.go (1)

710-711: Good addition of new parameters for TPM certificate support

The new parameters for signerWrapper and hostIdentityCertificatePath are appropriately set to nil and "" respectively for this performance testing tool, which doesn't need actual TPM hardware functionality.

ee/orbit/pkg/scep/testdata/ca.crt (1)

1-31: Appropriate test certificate for SCEP functionality

This CA certificate provides the necessary test data for SCEP client testing and validation. The certificate is properly formatted and contains standard CA fields, making it suitable for testing certificate enrollment operations.

tools/tuf/test/create_repository.sh (4)

26-26: Nice user experience improvement

Adding the Ctrl+C exit instruction makes the prompt clearer and more user-friendly.


33-33: Good behavioral improvement

Changing from break to exit 0 when the user says "no" makes the script behavior more intuitive. If someone doesn't want to remove the existing directory, they likely want to stop the script entirely rather than continue execution.


41-41: Good terminology clarification

Changing "packages" to "components" better describes what the script generates and provides clearer messaging.


47-47: Appropriate version update

Updating the default osquery version from 5.16.0 to 5.18.1 keeps the script current with newer stable releases.

server/mdm/scep/cmd/scepclient/scepclient.go (1)

73-73: The API signature update looks correct.

This change properly adapts to the new variadic options pattern for the SCEP client constructor. The removal of the nil parameter aligns with the refactored scepclient.New function that now uses functional options instead of fixed parameters.

server/service/device_client.go (1)

36-36: The base client signature update looks good.

This change correctly adapts to the new newBaseClient signature by adding the nil parameter for the signerWrapper function. This is appropriate for the Device Client since it doesn't require HTTP request signing functionality.

server/service/client.go (1)

47-47: The base client signature update is correct.

This change properly adapts to the new newBaseClient signature by adding the nil parameter for the signerWrapper function. This is appropriate for the regular Fleet client since it doesn't require HTTP request signing functionality.

ee/orbit/pkg/securehw/securehw_stub.go (1)

1-14: The stub implementation handles cross-platform compatibility well.

This stub properly ensures the securehw package compiles on non-Linux platforms while providing a clear error message when TPM functionality is attempted. The build constraints are correct, and the error message "not implemented" clearly communicates that TPM support is unavailable on these platforms.

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

30-30: Documentation looks good!

The new environment variable documentation follows the existing pattern and clearly explains its purpose for TPM-backed key usage.


85-85: Confirmed Linux-only support for --fleet-managed-client-certificate
I verified in cmd/fleetctl/fleetctl/package.go that:

  • The code returns an error unless --fleet-managed-client-certificate is used with type=deb or type=rpm.

This matches its inclusion only in DEB/RPM package generation in tools/tuf/test/gen_pkgs.sh. No changes are needed unless you intend to extend support to PKG or MSI.

ee/server/service/scep_proxy.go (1)

65-65: Clean refactoring to functional options pattern.

The update to use scepclient.WithTimeout(svc.Timeout) instead of positional arguments is consistent across all client instantiation points. This improves the API's flexibility and follows Go best practices.

Also applies to: 84-84, 104-104, 331-331

ee/server/service/hostidentity/httpsig/httpsig.go (2)

12-12: Good addition of the fleethttpsig import.

This import supports the centralized HTTP signature verification functionality.


46-46: Excellent refactoring to centralize verifier creation.

Moving the verifier configuration to fleethttpsig.Verifier(h) is a great improvement. Based on the code in pkg/fleethttpsig/fleethttpsig.go, this maintains the same configuration (ECDSA algorithms, required fields, etc.) while promoting code reuse across Fleet components.

server/service/base_client_test.go (1)

20-20: Consistent test updates for new function signature.

All test calls to newBaseClient() have been properly updated to include the new signerWrapper parameter (passing nil to maintain existing behavior). The changes are mechanical and consistent.

Also applies to: 27-27, 47-47, 60-60, 74-74, 89-89, 100-100, 113-113, 134-134, 160-160, 177-177, 233-233, 245-245

server/service/base_client.go (2)

140-140: Clean addition of optional signerWrapper parameter.

The new parameter follows good Go practices for optional functionality and maintains backward compatibility when nil is passed.


188-190: Proper conditional application of signerWrapper.

The implementation correctly applies the signerWrapper only when it's not nil, and at the right point in the client creation flow - after the base HTTP client is configured but before it's assigned to the baseClient struct.

ee/server/service/hostidentity/httpsig/middleware.go (3)

46-49: Good optimization with early path filtering.

The inverted logic now efficiently excludes non-orbit/osquery requests early, which is cleaner and more performant than the previous approach.


63-64: Simplified error handling improves consistency.

The error creation is now more consistent throughout the middleware, removing unnecessary error wrapping where it wasn't needed.

Also applies to: 75-76, 82-83, 88-90


94-94: Helpful debug logging for signature verification.

This debug log will be useful for troubleshooting HTTP signature verification issues, providing visibility into successful verifications.

cmd/fleetctl/fleetctl/package.go (1)

258-263: Good addition of TPM-backed certificate support.

The new flag properly documents the EE license requirement and provides clear usage instructions for TPM-backed HTTP signing.

ee/orbit/pkg/securehw/example_linux_test.go (1)

19-21: Good use of t.Skip for test prerequisites.

The test properly skips when prerequisites aren't met, which is the correct approach for integration tests requiring specific hardware and privileges.

server/mdm/scep/client/client.go (2)

18-47: Well-designed functional options pattern.

The refactoring from a single timeout parameter to functional options provides better flexibility and extensibility while maintaining clear, readable code.


54-66: Clean integration with server-side options.

The option processing and conversion to server-side ClientOption values is handled cleanly, maintaining consistency across the SCEP client/server interface.

server/service/orbit_client.go (3)

65-70: Good documentation of the host identity certificate field.

The comment clearly explains the purpose and behavior of the field, particularly the cleanup and restart behavior on authentication failures.


177-179: Proper integration of HTTP signer wrapper.

The addition of the httpSignerWrapper parameter allows the Orbit client to use TPM-backed HTTP signing when configured, which integrates well with the overall architecture.

Also applies to: 200-200


630-636: Appropriate cleanup behavior on authentication failure.

The logic to remove the host identity certificate and trigger a restart on HTTP 401 errors ensures the system can recover from certificate-related authentication issues.

pkg/fleethttpsig/fleethttpsig.go (1)

10-40: Well-implemented HTTP signature configuration!

The package provides a clean abstraction for HTTP signature verification and signing. The security choices are sound:

  • Excluding @target-uri to avoid proxy issues is well-documented
  • Required fields provide comprehensive request coverage
  • Disallowing algorithm metadata prevents confusion attacks
  • Restricting to ECDSA P-256/P-384 ensures strong cryptography
ee/orbit/pkg/securehw/securehw.go (1)

10-84: Excellent interface design for hardware-based cryptography!

The abstractions are well-structured:

  • Clear separation between TEE device management and key operations
  • HTTPSigner interface cleanly extends crypto.Signer for algorithm identification
  • Error types provide good context with customizable messages
  • Using iota+1 for ECCAlgorithm constants prevents zero-value confusion
ee/orbit/pkg/httpsigproxy/httpsigproxy.go (1)

24-59: Hardcoded certificate is acceptable for localhost-only proxy.

The embedded certificate and key are appropriately documented as compromised and restricted to 127.0.0.1 connections. This is a reasonable design for a local signing proxy.

server/mdm/scep/server/endpoint.go (1)

118-191: Nice refactoring to functional options pattern!

The migration from a single timeout pointer to the flexible ClientOption pattern improves API extensibility. The TLS configuration handling is correct for both root CA and insecure modes, with appropriate documentation that insecure mode is test-only.

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

965-1045: Solid implementation of TPM-backed certificate handling!

The code properly:

  • Selects common name based on host identifier configuration
  • Constructs the SCEP endpoint URL correctly
  • Handles errors comprehensively
  • Cleans up resources with defer
  • Uses 127.0.0.1 for security (avoiding DNS resolution issues)

1047-1065: Clean integration with orbit client!

The HTTP signer wrapper and certificate path are correctly passed to the orbit client, enabling signed requests when TPM-backed certificates are used.

ee/orbit/pkg/hostidentity/host_identity.go (2)

98-120: Great defensive programming with key verification!

This sanity check effectively handles the edge case where TPM blobs might be deleted and regenerated. The automatic cleanup ensures the system will recover on the next startup.


144-158: Good security practice with file permissions.

Using 0o600 permissions ensures only the owner can read the certificate file. The defer pattern properly handles file closure.

ee/orbit/pkg/scep/scep_test.go (2)

33-105: Well-structured validation tests!

The table-driven approach makes it easy to understand what's being tested. Good coverage of both error cases and the happy path.


107-167: Excellent integration testing with SCEP server.

Testing against a real SCEP server provides confidence in the implementation. The verification of certificate properties ensures the issued certificate meets requirements.

ee/orbit/pkg/securehw/securehw_linux.go (2)

220-263: Smart approach to detecting ECC curve support!

Testing curve support by attempting to create a key is more reliable than querying capabilities. The automatic cleanup ensures no resources are leaked.


596-620: Excellent RFC 9421-compliant HTTP signature implementation.

The fixed-width r||s format with proper padding follows the RFC requirements. The clear distinction between HTTP and standard signature formats is well-handled.

ee/orbit/pkg/scep/scep.go (1)

107-134: Clean factory function with good defaults.

The validation of required fields and the 30-second default timeout are sensible choices. The component tagging for the logger helps with debugging.

Comment on lines +55 to +61
return &tpm2TEE{
device: device,

logger: zerolog.Nop(),
publicBlobPath: filepath.Join(metadataDir, "tpm_cms_pub.blob"),
privateBlobPath: filepath.Join(metadataDir, "tpm_cms_priv.blob"),
}, nil

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.

⚠️ Potential issue

Use the provided logger instead of Nop().

The logger is being set to zerolog.Nop() which discards all log messages. This should use the logger parameter that was passed to the function.

 return &tpm2TEE{
     device: device,
 
-    logger:          zerolog.Nop(),
+    logger:          logger,
     publicBlobPath:  filepath.Join(metadataDir, "tpm_cms_pub.blob"),
     privateBlobPath: filepath.Join(metadataDir, "tpm_cms_priv.blob"),
 }, nil
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return &tpm2TEE{
device: device,
logger: zerolog.Nop(),
publicBlobPath: filepath.Join(metadataDir, "tpm_cms_pub.blob"),
privateBlobPath: filepath.Join(metadataDir, "tpm_cms_priv.blob"),
}, nil
return &tpm2TEE{
device: device,
logger: logger,
publicBlobPath: filepath.Join(metadataDir, "tpm_cms_pub.blob"),
privateBlobPath: filepath.Join(metadataDir, "tpm_cms_priv.blob"),
}, nil
🤖 Prompt for AI Agents
In ee/orbit/pkg/securehw/securehw_linux.go around lines 55 to 61, the tpm2TEE
struct is incorrectly using zerolog.Nop() for the logger field, which discards
all logs. Replace zerolog.Nop() with the logger parameter passed into the
function to ensure proper logging.

getvictor
getvictor previously approved these changes Jul 18, 2025

@getvictor getvictor 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. We can submit as is, and make any fixes in subsequent PRs.

if err := os.Remove(certPath); err != nil {
return nil, fmt.Errorf("error cleaning up %s: %w", certPath, err)
}
return nil, fmt.Errorf("secure HW key does not match certificate public key, deleted %q to re-issue a new certificate in the next restart", certPath)

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.

Do we need to set a restart flag?

}, nil
}

// CreateKey partially implements TEE.

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.

Nit. This comment seems strange, maybe unnecessary.

t.logger.Debug().Msg("creating transient RSA 2048-bit parent key")

// Create a parent key template with required attributes
parentTemplate := tpm2.New2B(tpm2.TPMTPublic{

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.

It would be nice to know how to create this exact parent key directly from the command line. This could be useful for testing and/or debug.

I imagine it is something like this, but I did not manually check to make sure the public keys are the same:

tpm2_createprimary \
  --hierarchy=owner \
  --key-algorithm=rsa \
  --hash-algorithm=sha256 \
  --attributes="fixedtpm|fixedparent|sensitivedataorigin|userwithauth|decrypt|restricted" \
  --key-context=parent.ctx

@@ -0,0 +1,40 @@
// Package fleethttpsig is a common package to use by Fleet client and servers for HTTP signing/verification.
package fleethttpsig

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.

Feels like this naming pattern should go into our patterns.md
Currently we're prefixing with common, not fleet (commonmdm, common_mysql)

Comment thread orbit/cmd/orbit/orbit.go
Comment thread orbit/cmd/orbit/orbit.go
signerWrapper func(*http.Client) *http.Client
hostIdentityCertificatePath string
)
if c.Bool("fleet-managed-client-certificate") {

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.

This section is a lot of code for orbit.go. Where you going to move it to another package for better testability?

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.

Yeah, I may move stuff to a separate package. Too much stuff going on here.

MinVersion: tls.VersionTLS12,
}
switch {
case co.rootCA != "":

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.

Was this needed for mTLS support?

Technically, we don't need to support mTLS. The main story says to error out if we try:
Easy to understand error message if user provides this at the same time as --fleet-tls-client-certificate or --fleet-tls-client-key

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 for mTLS, rootCA and insecure are to configure the CA on clients to connect to Fleet servers (e.g. if you use https://localhost:8080 and tools/osquery/fleet.crt as certificate).

oc.setEnrolled(false)

if oc.hostIdentityCertPath != "" {
if err := os.Remove(oc.hostIdentityCertPath); err != nil {

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.

Is this risky? What if there was a server/infra issue that caused ErrUnauthenticated? Host may not be able to reconnect (if enrollment secret was rotated)

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.

We are already removing the orbit node key file when this happens.

orbitHostInfo fleet.OrbitHostInfo,
onGetConfigErrFns *OnGetConfigErrFuncs,
httpSignerWrapper func(*http.Client) *http.Client,
hostIdentityCertPath string,

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.

Nit. Consider switching to functional options at some point.

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.

Agree. Or maybe structs so that you know what you are setting caller side.

@getvictor getvictor 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.

LGTM

@lucasmrod

Copy link
Copy Markdown
Member Author

Merging as Victor will be OOO and we will continue iterating and fixing any bugs next week.

@lucasmrod
lucasmrod merged commit 4948325 into main Jul 18, 2025
53 checks passed
@lucasmrod
lucasmrod deleted the 30461-fleetd-generate-tpm-key branch July 18, 2025 14:31
@coderabbitai coderabbitai Bot mentioned this pull request Jul 29, 2025
8 tasks
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.

2 participants