2026-03-26 13:59:42 +00:00
|
|
|
package client
|
2022-09-23 19:00:23 +00:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bytes"
|
Orbit config receiver (#18518)
New interface for adding periodic jobs that rely on notifications/config
changes in Orbit.
Previously if we wanted to have recurring checks in Orbit, we would add
them into a chain of `GetConfig` calls. This call chain would be run
periodically by one of the runners registered with the cli application
framework.
The new method to register `OrbitConfigReceivers` with the
`OrbitClient`, and then register the orbit client itself with the
application framework.
Instead of having giving each fetcher an internal reference to the
previous fetcher that it must call, the receiver is registered with the
client and the new config is passed to the receiver.
This is the old `GetConfig()` interface:
```go
type OrbitConfigFetcher interface {
GetConfig() (*fleet.OrbitConfig, error)
}
```
This is the new `OrbitConfigReceiver` interface:
```go
type OrbitConfigReceiver interface {
Run(*OrbitConfig) error
}
```
To register a new receiver, you call the `RegisterConfigReceiver` method
on the client.
```go
orbitClient.RegisterConfigReceiver(extRunner)
```
Downsides of the old method:
- Spaghetti call chain setup
- Cascading failure, of one fails, all after it fail
- Run in series, one long function call holds up the rest
- Anything that wants to restart orbit is added as a Runner to the
application, meaning there could be several timers calling `GetConfig`
and running the chain
Benefits of the new method:
- Clean `RegisterConfigReceiver` api, no call chaining required
- Config receivers can be added at runtime
- Isolated receivers, one failing call don't effect others
- All calls are run in parallel in goroutines, no calls can hold up the
rest
- No more need for multiple runners, using a context cancel, any
receiver can queue a call to restart orbit
- Single point to handle errors and logging for all receivers
- Panic recovery to stop orbit from crashing
- Easier to test, configs are passed in and do not require a call chain
This branch contains a little bit of code from the installer method I
was working on because I branched it off of that. (oops)
Not all code comments surrounding old `GetConfig()` methods have been
fully updated yet
Possible changes:
- Update the interface to take a context, so we can let receivers know
to exit early. I can imagine two cases for this:
- The application is about to restart
- We can set a timeout for how long receivers are allowed to take
Closes #12662
---------
Co-authored-by: Martin Angers <martin.n.angers@gmail.com>
Co-authored-by: Roberto Dip <dip.jesusr@gmail.com>
2024-05-09 19:22:56 +00:00
|
|
|
"context"
|
2023-04-27 11:44:39 +00:00
|
|
|
"crypto/tls"
|
2022-09-23 19:00:23 +00:00
|
|
|
"encoding/json"
|
2022-09-26 14:44:09 +00:00
|
|
|
"errors"
|
2022-09-23 19:00:23 +00:00
|
|
|
"fmt"
|
2024-08-21 14:08:16 +00:00
|
|
|
"io"
|
2022-10-03 20:28:19 +00:00
|
|
|
"io/fs"
|
2024-08-21 14:08:16 +00:00
|
|
|
"mime"
|
2024-02-21 18:36:15 +00:00
|
|
|
"net"
|
2022-09-23 19:00:23 +00:00
|
|
|
"net/http"
|
2024-05-09 11:54:11 +00:00
|
|
|
"net/http/httptrace"
|
2024-05-14 20:25:35 +00:00
|
|
|
"net/url"
|
2022-10-03 20:28:19 +00:00
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
2023-01-26 21:51:24 +00:00
|
|
|
"runtime"
|
2022-10-03 20:28:19 +00:00
|
|
|
"sync"
|
|
|
|
|
"time"
|
add headers denoting capabilities between fleet server / desktop / orbit (#7833)
This adds a new mechanism to allow us to handle compatibility issues between Orbit, Fleet Server and Fleet Desktop.
The general idea is to _always_ send a custom header of the form:
```
fleet-capabilities-header = "X-Fleet-Capabilities:" capabilities
capabilities = capability * (,)
capability = string
```
Both from the server to the clients (Orbit, Fleet Desktop) and vice-versa. For an example, see: https://github.com/fleetdm/fleet/commit/8c0bbdd291f54e03e19766bcdfead0fb8067f60c
Also, the following applies:
- Backwards compat: if the header is not present, assume that orbit/fleet doesn't have the capability
- The current capabilities endpoint will be removed
### Motivation
This solution is trying to solve the following problems:
- We have three independent processes communicating with each other (Fleet Desktop, Orbit and Fleet Server). Each process can be updated independently, and therefore we need a way for each process to know what features are supported by its peers.
- We originally implemented a dedicated API endpoint in the server that returned a list of the capabilities (or "features") enabled, we found this, and any other server-only solution (like API versioning) to be insufficient because:
- There are cases in which the server also needs to know which features are supported by its clients
- Clients needed to poll for changes to detect if the capabilities supported by the server change, by sending the capabilities on each request we have a much cleaner way to handling different responses.
- We are also introducing an unauthenticated endpoint to get the server features, this gives us flexibility if we need to implement different authentication mechanisms, and was one of the pitfalls of the first implementation.
Related to https://github.com/fleetdm/fleet/issues/7929
2022-09-26 10:53:53 +00:00
|
|
|
|
2022-10-03 20:28:19 +00:00
|
|
|
"github.com/fleetdm/fleet/v4/orbit/pkg/constant"
|
2023-08-25 21:25:07 +00:00
|
|
|
"github.com/fleetdm/fleet/v4/orbit/pkg/logging"
|
2024-11-21 16:31:03 +00:00
|
|
|
"github.com/fleetdm/fleet/v4/orbit/pkg/luks"
|
2023-01-26 21:51:24 +00:00
|
|
|
"github.com/fleetdm/fleet/v4/orbit/pkg/platform"
|
2022-10-03 20:28:19 +00:00
|
|
|
"github.com/fleetdm/fleet/v4/pkg/retry"
|
add headers denoting capabilities between fleet server / desktop / orbit (#7833)
This adds a new mechanism to allow us to handle compatibility issues between Orbit, Fleet Server and Fleet Desktop.
The general idea is to _always_ send a custom header of the form:
```
fleet-capabilities-header = "X-Fleet-Capabilities:" capabilities
capabilities = capability * (,)
capability = string
```
Both from the server to the clients (Orbit, Fleet Desktop) and vice-versa. For an example, see: https://github.com/fleetdm/fleet/commit/8c0bbdd291f54e03e19766bcdfead0fb8067f60c
Also, the following applies:
- Backwards compat: if the header is not present, assume that orbit/fleet doesn't have the capability
- The current capabilities endpoint will be removed
### Motivation
This solution is trying to solve the following problems:
- We have three independent processes communicating with each other (Fleet Desktop, Orbit and Fleet Server). Each process can be updated independently, and therefore we need a way for each process to know what features are supported by its peers.
- We originally implemented a dedicated API endpoint in the server that returned a list of the capabilities (or "features") enabled, we found this, and any other server-only solution (like API versioning) to be insufficient because:
- There are cases in which the server also needs to know which features are supported by its clients
- Clients needed to poll for changes to detect if the capabilities supported by the server change, by sending the capabilities on each request we have a much cleaner way to handling different responses.
- We are also introducing an unauthenticated endpoint to get the server features, this gives us flexibility if we need to implement different authentication mechanisms, and was one of the pitfalls of the first implementation.
Related to https://github.com/fleetdm/fleet/issues/7929
2022-09-26 10:53:53 +00:00
|
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
2022-10-03 20:28:19 +00:00
|
|
|
"github.com/rs/zerolog/log"
|
2022-09-23 19:00:23 +00:00
|
|
|
)
|
|
|
|
|
|
2022-10-03 20:28:19 +00:00
|
|
|
// OrbitClient exposes the Orbit API to communicate with the Fleet server.
|
2022-09-23 19:00:23 +00:00
|
|
|
type OrbitClient struct {
|
2026-03-26 13:59:42 +00:00
|
|
|
*BaseClient
|
2022-10-03 20:28:19 +00:00
|
|
|
nodeKeyFilePath string
|
|
|
|
|
enrollSecret string
|
2023-03-13 21:54:18 +00:00
|
|
|
hostInfo fleet.OrbitHostInfo
|
2022-10-03 20:28:19 +00:00
|
|
|
|
|
|
|
|
enrolledMu sync.Mutex
|
|
|
|
|
enrolled bool
|
|
|
|
|
|
|
|
|
|
lastRecordedErrMu sync.Mutex
|
|
|
|
|
lastRecordedErr error
|
2022-10-28 17:27:21 +00:00
|
|
|
|
2024-02-21 18:36:15 +00:00
|
|
|
configCache configCache
|
2024-02-22 17:24:17 +00:00
|
|
|
onGetConfigErrFns *OnGetConfigErrFuncs
|
2024-02-21 18:36:15 +00:00
|
|
|
lastNetErrOnGetConfigLogged time.Time
|
2023-12-11 13:04:24 +00:00
|
|
|
|
2024-05-09 11:54:11 +00:00
|
|
|
lastIdleConnectionsCleanupMu sync.Mutex
|
|
|
|
|
lastIdleConnectionsCleanup time.Time
|
|
|
|
|
|
2022-10-28 17:27:21 +00:00
|
|
|
// TestNodeKey is used for testing only.
|
|
|
|
|
TestNodeKey string
|
Orbit config receiver (#18518)
New interface for adding periodic jobs that rely on notifications/config
changes in Orbit.
Previously if we wanted to have recurring checks in Orbit, we would add
them into a chain of `GetConfig` calls. This call chain would be run
periodically by one of the runners registered with the cli application
framework.
The new method to register `OrbitConfigReceivers` with the
`OrbitClient`, and then register the orbit client itself with the
application framework.
Instead of having giving each fetcher an internal reference to the
previous fetcher that it must call, the receiver is registered with the
client and the new config is passed to the receiver.
This is the old `GetConfig()` interface:
```go
type OrbitConfigFetcher interface {
GetConfig() (*fleet.OrbitConfig, error)
}
```
This is the new `OrbitConfigReceiver` interface:
```go
type OrbitConfigReceiver interface {
Run(*OrbitConfig) error
}
```
To register a new receiver, you call the `RegisterConfigReceiver` method
on the client.
```go
orbitClient.RegisterConfigReceiver(extRunner)
```
Downsides of the old method:
- Spaghetti call chain setup
- Cascading failure, of one fails, all after it fail
- Run in series, one long function call holds up the rest
- Anything that wants to restart orbit is added as a Runner to the
application, meaning there could be several timers calling `GetConfig`
and running the chain
Benefits of the new method:
- Clean `RegisterConfigReceiver` api, no call chaining required
- Config receivers can be added at runtime
- Isolated receivers, one failing call don't effect others
- All calls are run in parallel in goroutines, no calls can hold up the
rest
- No more need for multiple runners, using a context cancel, any
receiver can queue a call to restart orbit
- Single point to handle errors and logging for all receivers
- Panic recovery to stop orbit from crashing
- Easier to test, configs are passed in and do not require a call chain
This branch contains a little bit of code from the installer method I
was working on because I branched it off of that. (oops)
Not all code comments surrounding old `GetConfig()` methods have been
fully updated yet
Possible changes:
- Update the interface to take a context, so we can let receivers know
to exit early. I can imagine two cases for this:
- The application is about to restart
- We can set a timeout for how long receivers are allowed to take
Closes #12662
---------
Co-authored-by: Martin Angers <martin.n.angers@gmail.com>
Co-authored-by: Roberto Dip <dip.jesusr@gmail.com>
2024-05-09 19:22:56 +00:00
|
|
|
|
|
|
|
|
// Interfaces that will receive updated configs
|
|
|
|
|
ConfigReceivers []fleet.OrbitConfigReceiver
|
|
|
|
|
// How frequently a new config will be fetched
|
|
|
|
|
ReceiverUpdateInterval time.Duration
|
2024-07-19 15:44:43 +00:00
|
|
|
// receiverUpdateContext used by ExecuteConfigReceivers to cancel the update loop.
|
|
|
|
|
receiverUpdateContext context.Context
|
|
|
|
|
// receiverUpdateCancelFunc is used to cancel receiverUpdateContext.
|
|
|
|
|
receiverUpdateCancelFunc context.CancelFunc
|
2025-07-18 14:31:52 +00:00
|
|
|
|
2026-04-13 21:19:47 +00:00
|
|
|
// euaToken is a one-time Fleet-signed JWT from Windows MDM enrollment,
|
|
|
|
|
// sent during orbit enrollment to link the IdP account without prompting.
|
|
|
|
|
euaToken string
|
|
|
|
|
|
2025-07-18 14:31:52 +00:00
|
|
|
// hostIdentityCertPath is the file path to the host identity certificate issued using SCEP.
|
|
|
|
|
//
|
|
|
|
|
// If set then it will be deleted on HTTP 401 errors from Fleet and it will cause ExecuteConfigReceivers
|
|
|
|
|
// to terminate to trigger a restart.
|
|
|
|
|
hostIdentityCertPath string
|
End-user authentication for Window/Linux setup experience: agent (#34847)
<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #34528
# Details
This PR implements the agent changes for allowing Fleet admins to
require that users authenticate with an IdP prior to having their
devices set up. I'll comment on changes inline but the high-level is:
1. Orbit calls the enroll endpoint as usual. This is triggered lazily by
any one of a number of subsystems like device token rotation or
requesting Fleet config
2. If the enroll endpoint returns the new `ErrEndUserAuthRequired`
response, then it opens a window to the `/mdm/sso` Fleet page and
retries the enroll endpoint every 30 seconds indefinitely.
3. Any other non-200 response to the enroll request is treated as before
(limited # of retries, with backoff)
# Checklist for submitter
If some of the following don't apply, delete the relevant line.
- [ ] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-
changes.md#changes-files) for more information.
Will add changelog when story is one.
## Testing
- [X] Added/updated automated tests
Added test for new retry logic
- [X] QA'd all new/changed functionality manually
This is kinda hard to test without the associated backend PR:
https://github.com/fleetdm/fleet/pull/34835
## fleetd/orbit/Fleet Desktop
- [X] Verified compatibility with the latest released version of Fleet
(see [Must
rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md))
This is compatible with all Fleet versions, since older ones won't send
the new error.
- [X] If the change applies to only one platform, confirmed that
`runtime.GOOS` is used as needed to isolate changes
This is compatible with all platforms, although it currently should only
ever run on Windows and Linux since macOS devices will have end-user
auth taken care of before they even download Orbit.
- [ ] Verified that fleetd runs on macOS, Linux and Windows
Testing this now.
- [ ] Verified auto-update works from the released version of component
to the new version (see [tools/tuf/test](../tools/tuf/test/README.md))
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Added SSO (Single Sign-On) enrollment support for end-user
authentication
* Enhanced error messaging for authentication-required scenarios
* **Bug Fixes**
* Improved error handling and retry logic for enrollment failures
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-11-03 22:41:57 +00:00
|
|
|
|
|
|
|
|
// initiatedIdpAuth is a flag indicating whether a window has been opened
|
|
|
|
|
// to the sign-on page for the organization's Identity Provider.
|
|
|
|
|
initiatedIdpAuth bool
|
|
|
|
|
|
|
|
|
|
// openSSOWindow is a function that opens a browser window to the SSO URL.
|
|
|
|
|
openSSOWindow func() error
|
2022-09-23 19:00:23 +00:00
|
|
|
}
|
|
|
|
|
|
2023-12-11 13:04:24 +00:00
|
|
|
// time-to-live for config cache
|
|
|
|
|
const configCacheTTL = 3 * time.Second
|
|
|
|
|
|
|
|
|
|
type configCache struct {
|
|
|
|
|
mu sync.Mutex
|
|
|
|
|
lastUpdated time.Time
|
|
|
|
|
config *fleet.OrbitConfig
|
|
|
|
|
err error
|
|
|
|
|
}
|
|
|
|
|
|
End-user authentication for Window/Linux setup experience: agent (#34847)
<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #34528
# Details
This PR implements the agent changes for allowing Fleet admins to
require that users authenticate with an IdP prior to having their
devices set up. I'll comment on changes inline but the high-level is:
1. Orbit calls the enroll endpoint as usual. This is triggered lazily by
any one of a number of subsystems like device token rotation or
requesting Fleet config
2. If the enroll endpoint returns the new `ErrEndUserAuthRequired`
response, then it opens a window to the `/mdm/sso` Fleet page and
retries the enroll endpoint every 30 seconds indefinitely.
3. Any other non-200 response to the enroll request is treated as before
(limited # of retries, with backoff)
# Checklist for submitter
If some of the following don't apply, delete the relevant line.
- [ ] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-
changes.md#changes-files) for more information.
Will add changelog when story is one.
## Testing
- [X] Added/updated automated tests
Added test for new retry logic
- [X] QA'd all new/changed functionality manually
This is kinda hard to test without the associated backend PR:
https://github.com/fleetdm/fleet/pull/34835
## fleetd/orbit/Fleet Desktop
- [X] Verified compatibility with the latest released version of Fleet
(see [Must
rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md))
This is compatible with all Fleet versions, since older ones won't send
the new error.
- [X] If the change applies to only one platform, confirmed that
`runtime.GOOS` is used as needed to isolate changes
This is compatible with all platforms, although it currently should only
ever run on Windows and Linux since macOS devices will have end-user
auth taken care of before they even download Orbit.
- [ ] Verified that fleetd runs on macOS, Linux and Windows
Testing this now.
- [ ] Verified auto-update works from the released version of component
to the new version (see [tools/tuf/test](../tools/tuf/test/README.md))
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Added SSO (Single Sign-On) enrollment support for end-user
authentication
* Enhanced error messaging for authentication-required scenarios
* **Bug Fixes**
* Improved error handling and retry logic for enrollment failures
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-11-03 22:41:57 +00:00
|
|
|
func (oc *OrbitClient) SetOpenSSOWindowFunc(f func() error) {
|
|
|
|
|
oc.openSSOWindow = f
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-26 13:59:42 +00:00
|
|
|
func (oc *OrbitClient) request(verb string, path string, params any, resp any) error {
|
2025-01-29 16:24:44 +00:00
|
|
|
return oc.requestWithExternal(verb, path, params, resp, false)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// requestWithExternal is used to make requests to Fleet or external URLs. If external is true, the pathOrURL
|
|
|
|
|
// is used as the full URL to make the request to.
|
2026-03-26 13:59:42 +00:00
|
|
|
func (oc *OrbitClient) requestWithExternal(verb string, pathOrURL string, params any, resp any, external bool) error {
|
2022-09-23 19:00:23 +00:00
|
|
|
var bodyBytes []byte
|
|
|
|
|
var err error
|
|
|
|
|
if params != nil {
|
|
|
|
|
bodyBytes, err = json.Marshal(params)
|
|
|
|
|
if err != nil {
|
2022-10-03 20:28:19 +00:00
|
|
|
return fmt.Errorf("making request json marshalling : %w", err)
|
2022-09-23 19:00:23 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-09 11:54:11 +00:00
|
|
|
oc.closeIdleConnections()
|
|
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
if os.Getenv("FLEETD_TEST_HTTPTRACE") == "1" {
|
|
|
|
|
ctx = httptrace.WithClientTrace(ctx, testStdoutHTTPTracer)
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-29 16:24:44 +00:00
|
|
|
var request *http.Request
|
|
|
|
|
if external {
|
|
|
|
|
request, err = http.NewRequestWithContext(
|
|
|
|
|
ctx,
|
|
|
|
|
verb,
|
|
|
|
|
pathOrURL,
|
|
|
|
|
nil,
|
|
|
|
|
)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
parsedURL, err := url.Parse(pathOrURL)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("parsing URL: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request, err = http.NewRequestWithContext(
|
|
|
|
|
ctx,
|
|
|
|
|
verb,
|
2026-03-26 13:59:42 +00:00
|
|
|
oc.URL(parsedURL.Path, parsedURL.RawQuery).String(),
|
2025-01-29 16:24:44 +00:00
|
|
|
bytes.NewBuffer(bodyBytes),
|
|
|
|
|
)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2026-03-26 13:59:42 +00:00
|
|
|
oc.SetClientCapabilitiesHeader(request)
|
2022-09-23 19:00:23 +00:00
|
|
|
}
|
2026-03-26 13:59:42 +00:00
|
|
|
response, err := oc.DoHTTPRequest(request)
|
2022-09-23 19:00:23 +00:00
|
|
|
if err != nil {
|
2022-10-03 20:28:19 +00:00
|
|
|
oc.setLastRecordedError(err)
|
2025-01-29 16:24:44 +00:00
|
|
|
return fmt.Errorf("%s %s: %w", verb, pathOrURL, err)
|
2022-09-23 19:00:23 +00:00
|
|
|
}
|
|
|
|
|
defer response.Body.Close()
|
|
|
|
|
|
2026-03-26 13:59:42 +00:00
|
|
|
if err := oc.ParseResponse(verb, pathOrURL, response, resp); err != nil {
|
2022-10-03 20:28:19 +00:00
|
|
|
oc.setLastRecordedError(err)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return nil
|
2022-09-23 19:00:23 +00:00
|
|
|
}
|
|
|
|
|
|
2024-02-22 17:24:17 +00:00
|
|
|
// OnGetConfigErrFuncs defines functions to be executed on GetConfig errors.
|
|
|
|
|
type OnGetConfigErrFuncs struct {
|
|
|
|
|
// OnNetErrFunc receives network and 5XX errors on GetConfig requests.
|
|
|
|
|
// These errors are rate limited to once every 5 minutes.
|
|
|
|
|
OnNetErrFunc func(err error)
|
|
|
|
|
// DebugErrFunc receives all errors on GetConfig requests.
|
|
|
|
|
DebugErrFunc func(err error)
|
|
|
|
|
}
|
2024-02-21 18:36:15 +00:00
|
|
|
|
|
|
|
|
var (
|
Orbit config receiver (#18518)
New interface for adding periodic jobs that rely on notifications/config
changes in Orbit.
Previously if we wanted to have recurring checks in Orbit, we would add
them into a chain of `GetConfig` calls. This call chain would be run
periodically by one of the runners registered with the cli application
framework.
The new method to register `OrbitConfigReceivers` with the
`OrbitClient`, and then register the orbit client itself with the
application framework.
Instead of having giving each fetcher an internal reference to the
previous fetcher that it must call, the receiver is registered with the
client and the new config is passed to the receiver.
This is the old `GetConfig()` interface:
```go
type OrbitConfigFetcher interface {
GetConfig() (*fleet.OrbitConfig, error)
}
```
This is the new `OrbitConfigReceiver` interface:
```go
type OrbitConfigReceiver interface {
Run(*OrbitConfig) error
}
```
To register a new receiver, you call the `RegisterConfigReceiver` method
on the client.
```go
orbitClient.RegisterConfigReceiver(extRunner)
```
Downsides of the old method:
- Spaghetti call chain setup
- Cascading failure, of one fails, all after it fail
- Run in series, one long function call holds up the rest
- Anything that wants to restart orbit is added as a Runner to the
application, meaning there could be several timers calling `GetConfig`
and running the chain
Benefits of the new method:
- Clean `RegisterConfigReceiver` api, no call chaining required
- Config receivers can be added at runtime
- Isolated receivers, one failing call don't effect others
- All calls are run in parallel in goroutines, no calls can hold up the
rest
- No more need for multiple runners, using a context cancel, any
receiver can queue a call to restart orbit
- Single point to handle errors and logging for all receivers
- Panic recovery to stop orbit from crashing
- Easier to test, configs are passed in and do not require a call chain
This branch contains a little bit of code from the installer method I
was working on because I branched it off of that. (oops)
Not all code comments surrounding old `GetConfig()` methods have been
fully updated yet
Possible changes:
- Update the interface to take a context, so we can let receivers know
to exit early. I can imagine two cases for this:
- The application is about to restart
- We can set a timeout for how long receivers are allowed to take
Closes #12662
---------
Co-authored-by: Martin Angers <martin.n.angers@gmail.com>
Co-authored-by: Roberto Dip <dip.jesusr@gmail.com>
2024-05-09 19:22:56 +00:00
|
|
|
netErrInterval = 5 * time.Minute
|
|
|
|
|
configRetryOnNetworkError = 30 * time.Second
|
|
|
|
|
defaultOrbitConfigReceiverInterval = 30 * time.Second
|
2024-02-21 18:36:15 +00:00
|
|
|
)
|
|
|
|
|
|
2022-10-03 20:28:19 +00:00
|
|
|
// NewOrbitClient creates a new OrbitClient.
|
|
|
|
|
//
|
2023-03-13 21:54:18 +00:00
|
|
|
// - rootDir is the Orbit's root directory, where the Orbit node key is loaded-from/stored.
|
|
|
|
|
// - addr is the address of the Fleet server.
|
|
|
|
|
// - orbitHostInfo is the host system information used for enrolling to Fleet.
|
2024-02-22 17:24:17 +00:00
|
|
|
// - onGetConfigErrFns can be used to handle errors in the GetConfig request.
|
2023-03-13 21:54:18 +00:00
|
|
|
func NewOrbitClient(
|
|
|
|
|
rootDir string,
|
|
|
|
|
addr string,
|
|
|
|
|
rootCA string,
|
|
|
|
|
insecureSkipVerify bool,
|
|
|
|
|
enrollSecret string,
|
2023-04-27 11:44:39 +00:00
|
|
|
fleetClientCert *tls.Certificate,
|
2023-03-13 21:54:18 +00:00
|
|
|
orbitHostInfo fleet.OrbitHostInfo,
|
2024-02-22 17:24:17 +00:00
|
|
|
onGetConfigErrFns *OnGetConfigErrFuncs,
|
2025-07-18 14:31:52 +00:00
|
|
|
httpSignerWrapper func(*http.Client) *http.Client,
|
|
|
|
|
hostIdentityCertPath string,
|
2023-03-13 21:54:18 +00:00
|
|
|
) (*OrbitClient, error) {
|
2024-08-02 19:06:21 +00:00
|
|
|
orbitCapabilities := fleet.GetOrbitClientCapabilities()
|
2026-03-26 13:59:42 +00:00
|
|
|
bc, err := NewBaseClient(addr, insecureSkipVerify, rootCA, "", fleetClientCert, orbitCapabilities, httpSignerWrapper)
|
2022-09-23 19:00:23 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-03 20:28:19 +00:00
|
|
|
nodeKeyFilePath := filepath.Join(rootDir, constant.OrbitNodeKeyFileName)
|
Orbit config receiver (#18518)
New interface for adding periodic jobs that rely on notifications/config
changes in Orbit.
Previously if we wanted to have recurring checks in Orbit, we would add
them into a chain of `GetConfig` calls. This call chain would be run
periodically by one of the runners registered with the cli application
framework.
The new method to register `OrbitConfigReceivers` with the
`OrbitClient`, and then register the orbit client itself with the
application framework.
Instead of having giving each fetcher an internal reference to the
previous fetcher that it must call, the receiver is registered with the
client and the new config is passed to the receiver.
This is the old `GetConfig()` interface:
```go
type OrbitConfigFetcher interface {
GetConfig() (*fleet.OrbitConfig, error)
}
```
This is the new `OrbitConfigReceiver` interface:
```go
type OrbitConfigReceiver interface {
Run(*OrbitConfig) error
}
```
To register a new receiver, you call the `RegisterConfigReceiver` method
on the client.
```go
orbitClient.RegisterConfigReceiver(extRunner)
```
Downsides of the old method:
- Spaghetti call chain setup
- Cascading failure, of one fails, all after it fail
- Run in series, one long function call holds up the rest
- Anything that wants to restart orbit is added as a Runner to the
application, meaning there could be several timers calling `GetConfig`
and running the chain
Benefits of the new method:
- Clean `RegisterConfigReceiver` api, no call chaining required
- Config receivers can be added at runtime
- Isolated receivers, one failing call don't effect others
- All calls are run in parallel in goroutines, no calls can hold up the
rest
- No more need for multiple runners, using a context cancel, any
receiver can queue a call to restart orbit
- Single point to handle errors and logging for all receivers
- Panic recovery to stop orbit from crashing
- Easier to test, configs are passed in and do not require a call chain
This branch contains a little bit of code from the installer method I
was working on because I branched it off of that. (oops)
Not all code comments surrounding old `GetConfig()` methods have been
fully updated yet
Possible changes:
- Update the interface to take a context, so we can let receivers know
to exit early. I can imagine two cases for this:
- The application is about to restart
- We can set a timeout for how long receivers are allowed to take
Closes #12662
---------
Co-authored-by: Martin Angers <martin.n.angers@gmail.com>
Co-authored-by: Roberto Dip <dip.jesusr@gmail.com>
2024-05-09 19:22:56 +00:00
|
|
|
ctx, cancelFunc := context.WithCancel(context.Background())
|
|
|
|
|
|
2022-09-23 19:00:23 +00:00
|
|
|
return &OrbitClient{
|
2024-05-09 11:54:11 +00:00
|
|
|
nodeKeyFilePath: nodeKeyFilePath,
|
2026-03-26 13:59:42 +00:00
|
|
|
BaseClient: bc,
|
2024-05-09 11:54:11 +00:00
|
|
|
enrollSecret: enrollSecret,
|
|
|
|
|
hostInfo: orbitHostInfo,
|
|
|
|
|
enrolled: false,
|
|
|
|
|
onGetConfigErrFns: onGetConfigErrFns,
|
|
|
|
|
lastIdleConnectionsCleanup: time.Now(),
|
2024-05-15 22:55:02 +00:00
|
|
|
ReceiverUpdateInterval: defaultOrbitConfigReceiverInterval,
|
2024-07-19 15:44:43 +00:00
|
|
|
receiverUpdateContext: ctx,
|
|
|
|
|
receiverUpdateCancelFunc: cancelFunc,
|
2025-07-18 14:31:52 +00:00
|
|
|
hostIdentityCertPath: hostIdentityCertPath,
|
2022-10-03 20:28:19 +00:00
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 21:19:47 +00:00
|
|
|
// SetEUAToken sets a one-time EUA token to include in the enrollment request.
|
|
|
|
|
func (oc *OrbitClient) SetEUAToken(token string) {
|
|
|
|
|
oc.euaToken = token
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-19 15:44:43 +00:00
|
|
|
// TriggerOrbitRestart triggers a orbit process restart.
|
|
|
|
|
func (oc *OrbitClient) TriggerOrbitRestart(reason string) {
|
|
|
|
|
log.Info().Msgf("orbit restart triggered: %s", reason)
|
|
|
|
|
oc.receiverUpdateCancelFunc()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// RestartTriggered returns true if any of the config receivers triggered an orbit restart.
|
|
|
|
|
func (oc *OrbitClient) RestartTriggered() bool {
|
|
|
|
|
select {
|
|
|
|
|
case <-oc.receiverUpdateContext.Done():
|
|
|
|
|
return true
|
|
|
|
|
default:
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-26 13:59:42 +00:00
|
|
|
// closeIdleConnections attempts to close idle connections from the pool every 55 minutes.
|
2024-05-09 11:54:11 +00:00
|
|
|
//
|
|
|
|
|
// Some load balancers (e.g. AWS ELB) have a maximum lifetime for a connection
|
|
|
|
|
// (no matter if the connection is active or not) and will forcefully close the
|
|
|
|
|
// connection causing errors in the client (e.g. https://github.com/fleetdm/fleet/issues/18783).
|
|
|
|
|
// To prevent these errors, we will attempt to cleanup idle connections every 55
|
|
|
|
|
// minutes to not let these connection grow too old. (AWS ELB's default value for maximum
|
|
|
|
|
// lifetime of a connection is 3600 seconds.)
|
|
|
|
|
func (oc *OrbitClient) closeIdleConnections() {
|
|
|
|
|
oc.lastIdleConnectionsCleanupMu.Lock()
|
|
|
|
|
defer oc.lastIdleConnectionsCleanupMu.Unlock()
|
|
|
|
|
|
|
|
|
|
if time.Since(oc.lastIdleConnectionsCleanup) < 55*time.Minute {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
oc.lastIdleConnectionsCleanup = time.Now()
|
|
|
|
|
|
2026-03-26 13:59:42 +00:00
|
|
|
rawClient := oc.GetRawHTTPClient()
|
|
|
|
|
c, ok := rawClient.(*http.Client)
|
2024-05-09 11:54:11 +00:00
|
|
|
if !ok {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
t, ok := c.Transport.(*http.Transport)
|
|
|
|
|
if !ok {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
t.CloseIdleConnections()
|
2022-10-03 20:28:19 +00:00
|
|
|
}
|
|
|
|
|
|
Orbit config receiver (#18518)
New interface for adding periodic jobs that rely on notifications/config
changes in Orbit.
Previously if we wanted to have recurring checks in Orbit, we would add
them into a chain of `GetConfig` calls. This call chain would be run
periodically by one of the runners registered with the cli application
framework.
The new method to register `OrbitConfigReceivers` with the
`OrbitClient`, and then register the orbit client itself with the
application framework.
Instead of having giving each fetcher an internal reference to the
previous fetcher that it must call, the receiver is registered with the
client and the new config is passed to the receiver.
This is the old `GetConfig()` interface:
```go
type OrbitConfigFetcher interface {
GetConfig() (*fleet.OrbitConfig, error)
}
```
This is the new `OrbitConfigReceiver` interface:
```go
type OrbitConfigReceiver interface {
Run(*OrbitConfig) error
}
```
To register a new receiver, you call the `RegisterConfigReceiver` method
on the client.
```go
orbitClient.RegisterConfigReceiver(extRunner)
```
Downsides of the old method:
- Spaghetti call chain setup
- Cascading failure, of one fails, all after it fail
- Run in series, one long function call holds up the rest
- Anything that wants to restart orbit is added as a Runner to the
application, meaning there could be several timers calling `GetConfig`
and running the chain
Benefits of the new method:
- Clean `RegisterConfigReceiver` api, no call chaining required
- Config receivers can be added at runtime
- Isolated receivers, one failing call don't effect others
- All calls are run in parallel in goroutines, no calls can hold up the
rest
- No more need for multiple runners, using a context cancel, any
receiver can queue a call to restart orbit
- Single point to handle errors and logging for all receivers
- Panic recovery to stop orbit from crashing
- Easier to test, configs are passed in and do not require a call chain
This branch contains a little bit of code from the installer method I
was working on because I branched it off of that. (oops)
Not all code comments surrounding old `GetConfig()` methods have been
fully updated yet
Possible changes:
- Update the interface to take a context, so we can let receivers know
to exit early. I can imagine two cases for this:
- The application is about to restart
- We can set a timeout for how long receivers are allowed to take
Closes #12662
---------
Co-authored-by: Martin Angers <martin.n.angers@gmail.com>
Co-authored-by: Roberto Dip <dip.jesusr@gmail.com>
2024-05-09 19:22:56 +00:00
|
|
|
func (oc *OrbitClient) RunConfigReceivers() error {
|
|
|
|
|
config, err := oc.GetConfig()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("RunConfigReceivers get config: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var errs []error
|
|
|
|
|
var errMu sync.Mutex
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
wg.Add(len(oc.ConfigReceivers))
|
|
|
|
|
|
|
|
|
|
for _, receiver := range oc.ConfigReceivers {
|
|
|
|
|
go func() {
|
|
|
|
|
defer func() {
|
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
|
errMu.Lock()
|
|
|
|
|
errs = append(errs, fmt.Errorf("panic occured in receiver: %v", err))
|
|
|
|
|
errMu.Unlock()
|
|
|
|
|
}
|
|
|
|
|
wg.Done()
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
err := receiver.Run(config)
|
|
|
|
|
if err != nil {
|
|
|
|
|
errMu.Lock()
|
|
|
|
|
errs = append(errs, err)
|
|
|
|
|
errMu.Unlock()
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wg.Wait()
|
|
|
|
|
|
|
|
|
|
if len(errs) != 0 {
|
|
|
|
|
return errors.Join(errs...)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (oc *OrbitClient) RegisterConfigReceiver(cr fleet.OrbitConfigReceiver) {
|
|
|
|
|
oc.ConfigReceivers = append(oc.ConfigReceivers, cr)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (oc *OrbitClient) ExecuteConfigReceivers() error {
|
|
|
|
|
ticker := time.NewTicker(oc.ReceiverUpdateInterval)
|
|
|
|
|
defer ticker.Stop()
|
|
|
|
|
|
|
|
|
|
for {
|
|
|
|
|
select {
|
2024-07-19 15:44:43 +00:00
|
|
|
case <-oc.receiverUpdateContext.Done():
|
Orbit config receiver (#18518)
New interface for adding periodic jobs that rely on notifications/config
changes in Orbit.
Previously if we wanted to have recurring checks in Orbit, we would add
them into a chain of `GetConfig` calls. This call chain would be run
periodically by one of the runners registered with the cli application
framework.
The new method to register `OrbitConfigReceivers` with the
`OrbitClient`, and then register the orbit client itself with the
application framework.
Instead of having giving each fetcher an internal reference to the
previous fetcher that it must call, the receiver is registered with the
client and the new config is passed to the receiver.
This is the old `GetConfig()` interface:
```go
type OrbitConfigFetcher interface {
GetConfig() (*fleet.OrbitConfig, error)
}
```
This is the new `OrbitConfigReceiver` interface:
```go
type OrbitConfigReceiver interface {
Run(*OrbitConfig) error
}
```
To register a new receiver, you call the `RegisterConfigReceiver` method
on the client.
```go
orbitClient.RegisterConfigReceiver(extRunner)
```
Downsides of the old method:
- Spaghetti call chain setup
- Cascading failure, of one fails, all after it fail
- Run in series, one long function call holds up the rest
- Anything that wants to restart orbit is added as a Runner to the
application, meaning there could be several timers calling `GetConfig`
and running the chain
Benefits of the new method:
- Clean `RegisterConfigReceiver` api, no call chaining required
- Config receivers can be added at runtime
- Isolated receivers, one failing call don't effect others
- All calls are run in parallel in goroutines, no calls can hold up the
rest
- No more need for multiple runners, using a context cancel, any
receiver can queue a call to restart orbit
- Single point to handle errors and logging for all receivers
- Panic recovery to stop orbit from crashing
- Easier to test, configs are passed in and do not require a call chain
This branch contains a little bit of code from the installer method I
was working on because I branched it off of that. (oops)
Not all code comments surrounding old `GetConfig()` methods have been
fully updated yet
Possible changes:
- Update the interface to take a context, so we can let receivers know
to exit early. I can imagine two cases for this:
- The application is about to restart
- We can set a timeout for how long receivers are allowed to take
Closes #12662
---------
Co-authored-by: Martin Angers <martin.n.angers@gmail.com>
Co-authored-by: Roberto Dip <dip.jesusr@gmail.com>
2024-05-09 19:22:56 +00:00
|
|
|
return nil
|
|
|
|
|
case <-ticker.C:
|
2024-05-14 20:25:35 +00:00
|
|
|
if err := oc.RunConfigReceivers(); err != nil {
|
|
|
|
|
log.Error().Err(err).Msg("running config receivers")
|
|
|
|
|
}
|
Orbit config receiver (#18518)
New interface for adding periodic jobs that rely on notifications/config
changes in Orbit.
Previously if we wanted to have recurring checks in Orbit, we would add
them into a chain of `GetConfig` calls. This call chain would be run
periodically by one of the runners registered with the cli application
framework.
The new method to register `OrbitConfigReceivers` with the
`OrbitClient`, and then register the orbit client itself with the
application framework.
Instead of having giving each fetcher an internal reference to the
previous fetcher that it must call, the receiver is registered with the
client and the new config is passed to the receiver.
This is the old `GetConfig()` interface:
```go
type OrbitConfigFetcher interface {
GetConfig() (*fleet.OrbitConfig, error)
}
```
This is the new `OrbitConfigReceiver` interface:
```go
type OrbitConfigReceiver interface {
Run(*OrbitConfig) error
}
```
To register a new receiver, you call the `RegisterConfigReceiver` method
on the client.
```go
orbitClient.RegisterConfigReceiver(extRunner)
```
Downsides of the old method:
- Spaghetti call chain setup
- Cascading failure, of one fails, all after it fail
- Run in series, one long function call holds up the rest
- Anything that wants to restart orbit is added as a Runner to the
application, meaning there could be several timers calling `GetConfig`
and running the chain
Benefits of the new method:
- Clean `RegisterConfigReceiver` api, no call chaining required
- Config receivers can be added at runtime
- Isolated receivers, one failing call don't effect others
- All calls are run in parallel in goroutines, no calls can hold up the
rest
- No more need for multiple runners, using a context cancel, any
receiver can queue a call to restart orbit
- Single point to handle errors and logging for all receivers
- Panic recovery to stop orbit from crashing
- Easier to test, configs are passed in and do not require a call chain
This branch contains a little bit of code from the installer method I
was working on because I branched it off of that. (oops)
Not all code comments surrounding old `GetConfig()` methods have been
fully updated yet
Possible changes:
- Update the interface to take a context, so we can let receivers know
to exit early. I can imagine two cases for this:
- The application is about to restart
- We can set a timeout for how long receivers are allowed to take
Closes #12662
---------
Co-authored-by: Martin Angers <martin.n.angers@gmail.com>
Co-authored-by: Roberto Dip <dip.jesusr@gmail.com>
2024-05-09 19:22:56 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (oc *OrbitClient) InterruptConfigReceivers(err error) {
|
2024-07-19 15:44:43 +00:00
|
|
|
oc.receiverUpdateCancelFunc()
|
Orbit config receiver (#18518)
New interface for adding periodic jobs that rely on notifications/config
changes in Orbit.
Previously if we wanted to have recurring checks in Orbit, we would add
them into a chain of `GetConfig` calls. This call chain would be run
periodically by one of the runners registered with the cli application
framework.
The new method to register `OrbitConfigReceivers` with the
`OrbitClient`, and then register the orbit client itself with the
application framework.
Instead of having giving each fetcher an internal reference to the
previous fetcher that it must call, the receiver is registered with the
client and the new config is passed to the receiver.
This is the old `GetConfig()` interface:
```go
type OrbitConfigFetcher interface {
GetConfig() (*fleet.OrbitConfig, error)
}
```
This is the new `OrbitConfigReceiver` interface:
```go
type OrbitConfigReceiver interface {
Run(*OrbitConfig) error
}
```
To register a new receiver, you call the `RegisterConfigReceiver` method
on the client.
```go
orbitClient.RegisterConfigReceiver(extRunner)
```
Downsides of the old method:
- Spaghetti call chain setup
- Cascading failure, of one fails, all after it fail
- Run in series, one long function call holds up the rest
- Anything that wants to restart orbit is added as a Runner to the
application, meaning there could be several timers calling `GetConfig`
and running the chain
Benefits of the new method:
- Clean `RegisterConfigReceiver` api, no call chaining required
- Config receivers can be added at runtime
- Isolated receivers, one failing call don't effect others
- All calls are run in parallel in goroutines, no calls can hold up the
rest
- No more need for multiple runners, using a context cancel, any
receiver can queue a call to restart orbit
- Single point to handle errors and logging for all receivers
- Panic recovery to stop orbit from crashing
- Easier to test, configs are passed in and do not require a call chain
This branch contains a little bit of code from the installer method I
was working on because I branched it off of that. (oops)
Not all code comments surrounding old `GetConfig()` methods have been
fully updated yet
Possible changes:
- Update the interface to take a context, so we can let receivers know
to exit early. I can imagine two cases for this:
- The application is about to restart
- We can set a timeout for how long receivers are allowed to take
Closes #12662
---------
Co-authored-by: Martin Angers <martin.n.angers@gmail.com>
Co-authored-by: Roberto Dip <dip.jesusr@gmail.com>
2024-05-09 19:22:56 +00:00
|
|
|
}
|
|
|
|
|
|
2022-10-03 20:28:19 +00:00
|
|
|
// GetConfig returns the Orbit config fetched from Fleet server for this instance of OrbitClient.
|
2024-02-21 18:36:15 +00:00
|
|
|
// Since this method is called in multiple places, we use a cache with configCacheTTL time-to-live
|
|
|
|
|
// to reduce traffic to the Fleet server.
|
|
|
|
|
// Upon network errors, this method will retry the get config request (every 30 seconds).
|
2023-01-25 20:03:40 +00:00
|
|
|
func (oc *OrbitClient) GetConfig() (*fleet.OrbitConfig, error) {
|
2023-12-11 13:04:24 +00:00
|
|
|
oc.configCache.mu.Lock()
|
|
|
|
|
defer oc.configCache.mu.Unlock()
|
2024-02-21 18:36:15 +00:00
|
|
|
|
2023-12-11 13:04:24 +00:00
|
|
|
// If time-to-live passed, we update the config cache
|
|
|
|
|
now := time.Now()
|
|
|
|
|
if now.After(oc.configCache.lastUpdated.Add(configCacheTTL)) {
|
2024-02-22 17:24:17 +00:00
|
|
|
verb, path := "POST", "/api/fleet/orbit/config"
|
2024-02-21 18:36:15 +00:00
|
|
|
var (
|
|
|
|
|
resp fleet.OrbitConfig
|
|
|
|
|
err error
|
|
|
|
|
)
|
2024-02-22 17:24:17 +00:00
|
|
|
// Retry until we don't get a network error or a 5XX error.
|
2024-02-21 18:36:15 +00:00
|
|
|
_ = retry.Do(func() error {
|
2026-03-26 13:59:42 +00:00
|
|
|
err = oc.authenticatedRequest(verb, path, &fleet.OrbitGetConfigRequest{}, &resp)
|
2024-02-22 17:24:17 +00:00
|
|
|
var (
|
|
|
|
|
netErr net.Error
|
2026-03-26 13:59:42 +00:00
|
|
|
statusCodeErr *StatusCodeErr
|
2024-02-22 17:24:17 +00:00
|
|
|
)
|
|
|
|
|
if err != nil && oc.onGetConfigErrFns != nil && oc.onGetConfigErrFns.DebugErrFunc != nil {
|
|
|
|
|
oc.onGetConfigErrFns.DebugErrFunc(err)
|
|
|
|
|
}
|
2026-03-26 13:59:42 +00:00
|
|
|
if errors.As(err, &netErr) || (errors.As(err, &statusCodeErr) && statusCodeErr.StatusCode() >= 500) {
|
2024-02-21 18:36:15 +00:00
|
|
|
now := time.Now()
|
2024-02-22 17:24:17 +00:00
|
|
|
if oc.onGetConfigErrFns != nil && oc.onGetConfigErrFns.OnNetErrFunc != nil && now.After(oc.lastNetErrOnGetConfigLogged.Add(netErrInterval)) {
|
|
|
|
|
oc.onGetConfigErrFns.OnNetErrFunc(err)
|
2024-02-21 18:36:15 +00:00
|
|
|
oc.lastNetErrOnGetConfigLogged = now
|
|
|
|
|
}
|
2024-02-22 17:24:17 +00:00
|
|
|
return err // retry on network or server 5XX errors
|
2024-02-21 18:36:15 +00:00
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}, retry.WithInterval(configRetryOnNetworkError))
|
2023-12-11 13:04:24 +00:00
|
|
|
oc.configCache.config = &resp
|
|
|
|
|
oc.configCache.err = err
|
|
|
|
|
oc.configCache.lastUpdated = now
|
2022-10-03 20:28:19 +00:00
|
|
|
}
|
2023-12-11 13:04:24 +00:00
|
|
|
return oc.configCache.config, oc.configCache.err
|
2022-09-23 19:00:23 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-26 13:59:42 +00:00
|
|
|
// SetOrUpdateDeviceToken sends a request to the server to set or update the device token.
|
2022-10-10 20:15:35 +00:00
|
|
|
func (oc *OrbitClient) SetOrUpdateDeviceToken(deviceAuthToken string) error {
|
|
|
|
|
verb, path := "POST", "/api/fleet/orbit/device_token"
|
2026-03-26 13:59:42 +00:00
|
|
|
params := fleet.SetOrUpdateDeviceTokenRequest{
|
2022-10-10 20:15:35 +00:00
|
|
|
DeviceAuthToken: deviceAuthToken,
|
|
|
|
|
}
|
2026-03-26 13:59:42 +00:00
|
|
|
var resp fleet.SetOrUpdateDeviceTokenResponse
|
2022-10-10 20:15:35 +00:00
|
|
|
if err := oc.authenticatedRequest(verb, path, ¶ms, &resp); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-26 13:59:42 +00:00
|
|
|
// SetOrUpdateDeviceMappingEmail sends a request to the server to set or update the device mapping email.
|
2023-12-21 17:22:59 +00:00
|
|
|
func (oc *OrbitClient) SetOrUpdateDeviceMappingEmail(email string) error {
|
|
|
|
|
verb, path := "PUT", "/api/fleet/orbit/device_mapping"
|
2026-03-26 13:59:42 +00:00
|
|
|
params := fleet.OrbitPutDeviceMappingRequest{
|
2023-12-21 17:22:59 +00:00
|
|
|
Email: email,
|
|
|
|
|
}
|
2026-03-26 13:59:42 +00:00
|
|
|
var resp fleet.OrbitPutDeviceMappingResponse
|
2023-12-21 17:22:59 +00:00
|
|
|
if err := oc.authenticatedRequest(verb, path, ¶ms, &resp); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-26 13:59:42 +00:00
|
|
|
// GetHostScript returns the script fetched from Fleet server to run on this host.
|
2023-08-23 22:31:47 +00:00
|
|
|
func (oc *OrbitClient) GetHostScript(execID string) (*fleet.HostScriptResult, error) {
|
|
|
|
|
verb, path := "POST", "/api/fleet/orbit/scripts/request"
|
2026-03-26 13:59:42 +00:00
|
|
|
var resp fleet.OrbitGetScriptResponse
|
|
|
|
|
if err := oc.authenticatedRequest(verb, path, &fleet.OrbitGetScriptRequest{
|
2023-08-23 22:31:47 +00:00
|
|
|
ExecutionID: execID,
|
|
|
|
|
}, &resp); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return resp.HostScriptResult, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SaveHostScriptResult saves the result of running the script on this host.
|
|
|
|
|
func (oc *OrbitClient) SaveHostScriptResult(result *fleet.HostScriptResultPayload) error {
|
|
|
|
|
verb, path := "POST", "/api/fleet/orbit/scripts/result"
|
2026-03-26 13:59:42 +00:00
|
|
|
var resp fleet.OrbitPostScriptResultResponse
|
|
|
|
|
if err := oc.authenticatedRequest(verb, path, &fleet.OrbitPostScriptResultRequest{
|
2023-08-23 22:31:47 +00:00
|
|
|
HostScriptResultPayload: result,
|
|
|
|
|
}, &resp); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-14 20:25:35 +00:00
|
|
|
func (oc *OrbitClient) GetInstallerDetails(installId string) (*fleet.SoftwareInstallDetails, error) {
|
|
|
|
|
verb, path := "POST", "/api/fleet/orbit/software_install/details"
|
2026-03-26 13:59:42 +00:00
|
|
|
var resp fleet.OrbitGetSoftwareInstallResponse
|
|
|
|
|
if err := oc.authenticatedRequest(verb, path, &fleet.OrbitGetSoftwareInstallRequest{
|
2024-05-14 20:25:35 +00:00
|
|
|
InstallUUID: installId,
|
|
|
|
|
}, &resp); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return resp.SoftwareInstallDetails, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (oc *OrbitClient) SaveInstallerResult(payload *fleet.HostSoftwareInstallResultPayload) error {
|
|
|
|
|
verb, path := "POST", "/api/fleet/orbit/software_install/result"
|
2026-03-26 13:59:42 +00:00
|
|
|
var resp fleet.OrbitPostSoftwareInstallResultResponse
|
|
|
|
|
if err := oc.authenticatedRequest(verb, path, &fleet.OrbitPostSoftwareInstallResultRequest{
|
2024-05-14 20:25:35 +00:00
|
|
|
HostSoftwareInstallResultPayload: payload,
|
|
|
|
|
}, &resp); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-20 14:09:57 +00:00
|
|
|
func (oc *OrbitClient) DownloadSoftwareInstaller(installerID uint, downloadDirectory string, progressFunc func(n int)) (string, error) {
|
2024-05-14 20:25:35 +00:00
|
|
|
verb, path := "POST", "/api/fleet/orbit/software_install/package?alt=media"
|
2025-03-20 14:09:57 +00:00
|
|
|
resp := FileResponse{
|
|
|
|
|
DestPath: downloadDirectory,
|
|
|
|
|
ProgressFunc: progressFunc,
|
|
|
|
|
}
|
2026-03-26 13:59:42 +00:00
|
|
|
if err := oc.authenticatedRequest(verb, path, &fleet.OrbitDownloadSoftwareInstallerRequest{
|
2024-05-14 20:25:35 +00:00
|
|
|
InstallerID: installerID,
|
|
|
|
|
}, &resp); err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
return resp.GetFilePath(), nil
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-20 14:09:57 +00:00
|
|
|
func (oc *OrbitClient) DownloadSoftwareInstallerFromURL(url string, filename string, downloadDirectory string, progressFunc func(int)) (string, error) {
|
|
|
|
|
resp := FileResponse{
|
|
|
|
|
DestPath: downloadDirectory,
|
|
|
|
|
DestFile: filename,
|
|
|
|
|
SkipMediaType: true,
|
|
|
|
|
ProgressFunc: progressFunc,
|
|
|
|
|
}
|
2025-01-29 16:24:44 +00:00
|
|
|
if err := oc.requestWithExternal("GET", url, nil, &resp, true); err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
return resp.GetFilePath(), nil
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-26 13:59:42 +00:00
|
|
|
// NullFileResponse discards downloaded file content.
|
2024-10-09 19:48:16 +00:00
|
|
|
type NullFileResponse struct{}
|
2024-08-21 14:08:16 +00:00
|
|
|
|
|
|
|
|
func (f *NullFileResponse) Handle(resp *http.Response) error {
|
|
|
|
|
_, _, err := mime.ParseMediaType(resp.Header.Get("Content-Disposition"))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("parsing media type from response header: %w", err)
|
|
|
|
|
}
|
|
|
|
|
_, err = io.Copy(io.Discard, resp.Body)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("copying from http stream to io.Discard: %w", err)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DownloadAndDiscardSoftwareInstaller downloads the software installer and discards it.
|
|
|
|
|
// This method is used during load testing by osquery-perf.
|
|
|
|
|
func (oc *OrbitClient) DownloadAndDiscardSoftwareInstaller(installerID uint) error {
|
|
|
|
|
verb, path := "POST", "/api/fleet/orbit/software_install/package?alt=media"
|
|
|
|
|
resp := NullFileResponse{}
|
2026-03-26 13:59:42 +00:00
|
|
|
return oc.authenticatedRequest(verb, path, &fleet.OrbitDownloadSoftwareInstallerRequest{
|
2024-08-21 14:08:16 +00:00
|
|
|
InstallerID: installerID,
|
|
|
|
|
}, &resp)
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-10 20:15:35 +00:00
|
|
|
// Ping sends a ping request to the orbit/ping endpoint.
|
2022-10-03 20:28:19 +00:00
|
|
|
func (oc *OrbitClient) Ping() error {
|
|
|
|
|
verb, path := "HEAD", "/api/fleet/orbit/ping"
|
|
|
|
|
err := oc.request(verb, path, nil, nil)
|
2026-03-26 13:59:42 +00:00
|
|
|
if err == nil || IsNotFoundErr(err) {
|
2022-10-03 20:28:19 +00:00
|
|
|
// notFound is ok, it means an old server without the capabilities header
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (oc *OrbitClient) enroll() (string, error) {
|
2022-09-23 19:00:23 +00:00
|
|
|
verb, path := "POST", "/api/fleet/orbit/enroll"
|
2026-03-26 13:59:42 +00:00
|
|
|
params := fleet.EnrollOrbitRequest{
|
2023-12-15 18:26:32 +00:00
|
|
|
EnrollSecret: oc.enrollSecret,
|
|
|
|
|
HardwareUUID: oc.hostInfo.HardwareUUID,
|
|
|
|
|
HardwareSerial: oc.hostInfo.HardwareSerial,
|
|
|
|
|
Hostname: oc.hostInfo.Hostname,
|
|
|
|
|
Platform: oc.hostInfo.Platform,
|
2025-09-05 19:05:19 +00:00
|
|
|
PlatformLike: oc.hostInfo.PlatformLike,
|
2023-12-15 18:26:32 +00:00
|
|
|
OsqueryIdentifier: oc.hostInfo.OsqueryIdentifier,
|
2024-11-18 21:51:36 +00:00
|
|
|
ComputerName: oc.hostInfo.ComputerName,
|
|
|
|
|
HardwareModel: oc.hostInfo.HardwareModel,
|
2026-04-13 21:19:47 +00:00
|
|
|
EUAToken: oc.euaToken,
|
2023-03-13 21:54:18 +00:00
|
|
|
}
|
2026-03-26 13:59:42 +00:00
|
|
|
var resp fleet.EnrollOrbitResponse
|
2022-09-23 19:00:23 +00:00
|
|
|
err := oc.request(verb, path, params, &resp)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
return resp.OrbitNodeKey, nil
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-03 20:28:19 +00:00
|
|
|
// enrollLock helps protect the enrolling process in case mutliple OrbitClients
|
|
|
|
|
// want to re-enroll at the same time.
|
|
|
|
|
var enrollLock sync.Mutex
|
|
|
|
|
|
|
|
|
|
// getNodeKeyOrEnroll attempts to read the orbit node key if the file exists on disk
|
|
|
|
|
// otherwise it enrolls the host with Fleet and saves the node key to disk
|
|
|
|
|
func (oc *OrbitClient) getNodeKeyOrEnroll() (string, error) {
|
2022-10-28 17:27:21 +00:00
|
|
|
if oc.TestNodeKey != "" {
|
|
|
|
|
return oc.TestNodeKey, nil
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-03 20:28:19 +00:00
|
|
|
enrollLock.Lock()
|
|
|
|
|
defer enrollLock.Unlock()
|
|
|
|
|
|
2023-10-27 18:28:54 +00:00
|
|
|
orbitNodeKey, err := os.ReadFile(oc.nodeKeyFilePath)
|
2022-10-03 20:28:19 +00:00
|
|
|
switch {
|
|
|
|
|
case err == nil:
|
|
|
|
|
return string(orbitNodeKey), nil
|
|
|
|
|
case errors.Is(err, fs.ErrNotExist):
|
|
|
|
|
// OK, if there's no orbit node key, proceed to enroll.
|
|
|
|
|
default:
|
|
|
|
|
return "", fmt.Errorf("read orbit node key file: %w", err)
|
2022-09-23 19:00:23 +00:00
|
|
|
}
|
End-user authentication for Window/Linux setup experience: agent (#34847)
<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #34528
# Details
This PR implements the agent changes for allowing Fleet admins to
require that users authenticate with an IdP prior to having their
devices set up. I'll comment on changes inline but the high-level is:
1. Orbit calls the enroll endpoint as usual. This is triggered lazily by
any one of a number of subsystems like device token rotation or
requesting Fleet config
2. If the enroll endpoint returns the new `ErrEndUserAuthRequired`
response, then it opens a window to the `/mdm/sso` Fleet page and
retries the enroll endpoint every 30 seconds indefinitely.
3. Any other non-200 response to the enroll request is treated as before
(limited # of retries, with backoff)
# Checklist for submitter
If some of the following don't apply, delete the relevant line.
- [ ] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-
changes.md#changes-files) for more information.
Will add changelog when story is one.
## Testing
- [X] Added/updated automated tests
Added test for new retry logic
- [X] QA'd all new/changed functionality manually
This is kinda hard to test without the associated backend PR:
https://github.com/fleetdm/fleet/pull/34835
## fleetd/orbit/Fleet Desktop
- [X] Verified compatibility with the latest released version of Fleet
(see [Must
rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md))
This is compatible with all Fleet versions, since older ones won't send
the new error.
- [X] If the change applies to only one platform, confirmed that
`runtime.GOOS` is used as needed to isolate changes
This is compatible with all platforms, although it currently should only
ever run on Windows and Linux since macOS devices will have end-user
auth taken care of before they even download Orbit.
- [ ] Verified that fleetd runs on macOS, Linux and Windows
Testing this now.
- [ ] Verified auto-update works from the released version of component
to the new version (see [tools/tuf/test](../tools/tuf/test/README.md))
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Added SSO (Single Sign-On) enrollment support for end-user
authentication
* Enhanced error messaging for authentication-required scenarios
* **Bug Fixes**
* Improved error handling and retry logic for enrollment failures
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-11-03 22:41:57 +00:00
|
|
|
var orbitNodeKey_ string
|
2022-10-03 20:28:19 +00:00
|
|
|
if err := retry.Do(
|
|
|
|
|
func() error {
|
|
|
|
|
orbitNodeKey_, err = oc.enrollAndWriteNodeKeyFile()
|
End-user authentication for Window/Linux setup experience: agent (#34847)
<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #34528
# Details
This PR implements the agent changes for allowing Fleet admins to
require that users authenticate with an IdP prior to having their
devices set up. I'll comment on changes inline but the high-level is:
1. Orbit calls the enroll endpoint as usual. This is triggered lazily by
any one of a number of subsystems like device token rotation or
requesting Fleet config
2. If the enroll endpoint returns the new `ErrEndUserAuthRequired`
response, then it opens a window to the `/mdm/sso` Fleet page and
retries the enroll endpoint every 30 seconds indefinitely.
3. Any other non-200 response to the enroll request is treated as before
(limited # of retries, with backoff)
# Checklist for submitter
If some of the following don't apply, delete the relevant line.
- [ ] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-
changes.md#changes-files) for more information.
Will add changelog when story is one.
## Testing
- [X] Added/updated automated tests
Added test for new retry logic
- [X] QA'd all new/changed functionality manually
This is kinda hard to test without the associated backend PR:
https://github.com/fleetdm/fleet/pull/34835
## fleetd/orbit/Fleet Desktop
- [X] Verified compatibility with the latest released version of Fleet
(see [Must
rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md))
This is compatible with all Fleet versions, since older ones won't send
the new error.
- [X] If the change applies to only one platform, confirmed that
`runtime.GOOS` is used as needed to isolate changes
This is compatible with all platforms, although it currently should only
ever run on Windows and Linux since macOS devices will have end-user
auth taken care of before they even download Orbit.
- [ ] Verified that fleetd runs on macOS, Linux and Windows
Testing this now.
- [ ] Verified auto-update works from the released version of component
to the new version (see [tools/tuf/test](../tools/tuf/test/README.md))
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Added SSO (Single Sign-On) enrollment support for end-user
authentication
* Enhanced error messaging for authentication-required scenarios
* **Bug Fixes**
* Improved error handling and retry logic for enrollment failures
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-11-03 22:41:57 +00:00
|
|
|
return err
|
2022-10-03 20:28:19 +00:00
|
|
|
},
|
2024-03-13 10:57:00 +00:00
|
|
|
// The below configuration means the following retry intervals (exponential backoff):
|
|
|
|
|
// 10s, 20s, 40s, 80s, 160s and then return the failure (max attempts = 6)
|
|
|
|
|
// thus executing no more than ~6 enroll request failures every ~5 minutes.
|
|
|
|
|
retry.WithInterval(orbitEnrollRetryInterval()),
|
2022-10-03 20:28:19 +00:00
|
|
|
retry.WithMaxAttempts(constant.OrbitEnrollMaxRetries),
|
2024-03-13 10:57:00 +00:00
|
|
|
retry.WithBackoffMultiplier(constant.OrbitEnrollBackoffMultiplier),
|
End-user authentication for Window/Linux setup experience: agent (#34847)
<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #34528
# Details
This PR implements the agent changes for allowing Fleet admins to
require that users authenticate with an IdP prior to having their
devices set up. I'll comment on changes inline but the high-level is:
1. Orbit calls the enroll endpoint as usual. This is triggered lazily by
any one of a number of subsystems like device token rotation or
requesting Fleet config
2. If the enroll endpoint returns the new `ErrEndUserAuthRequired`
response, then it opens a window to the `/mdm/sso` Fleet page and
retries the enroll endpoint every 30 seconds indefinitely.
3. Any other non-200 response to the enroll request is treated as before
(limited # of retries, with backoff)
# Checklist for submitter
If some of the following don't apply, delete the relevant line.
- [ ] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-
changes.md#changes-files) for more information.
Will add changelog when story is one.
## Testing
- [X] Added/updated automated tests
Added test for new retry logic
- [X] QA'd all new/changed functionality manually
This is kinda hard to test without the associated backend PR:
https://github.com/fleetdm/fleet/pull/34835
## fleetd/orbit/Fleet Desktop
- [X] Verified compatibility with the latest released version of Fleet
(see [Must
rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md))
This is compatible with all Fleet versions, since older ones won't send
the new error.
- [X] If the change applies to only one platform, confirmed that
`runtime.GOOS` is used as needed to isolate changes
This is compatible with all platforms, although it currently should only
ever run on Windows and Linux since macOS devices will have end-user
auth taken care of before they even download Orbit.
- [ ] Verified that fleetd runs on macOS, Linux and Windows
Testing this now.
- [ ] Verified auto-update works from the released version of component
to the new version (see [tools/tuf/test](../tools/tuf/test/README.md))
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Added SSO (Single Sign-On) enrollment support for end-user
authentication
* Enhanced error messaging for authentication-required scenarios
* **Bug Fixes**
* Improved error handling and retry logic for enrollment failures
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-11-03 22:41:57 +00:00
|
|
|
retry.WithErrorFilter(func(err error) (errorOutcome retry.ErrorOutcome) {
|
|
|
|
|
log.Info().Err(err).Msg("orbit enroll attempt failed")
|
|
|
|
|
switch {
|
2026-03-26 13:59:42 +00:00
|
|
|
case IsNotFoundErr(err):
|
End-user authentication for Window/Linux setup experience: agent (#34847)
<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #34528
# Details
This PR implements the agent changes for allowing Fleet admins to
require that users authenticate with an IdP prior to having their
devices set up. I'll comment on changes inline but the high-level is:
1. Orbit calls the enroll endpoint as usual. This is triggered lazily by
any one of a number of subsystems like device token rotation or
requesting Fleet config
2. If the enroll endpoint returns the new `ErrEndUserAuthRequired`
response, then it opens a window to the `/mdm/sso` Fleet page and
retries the enroll endpoint every 30 seconds indefinitely.
3. Any other non-200 response to the enroll request is treated as before
(limited # of retries, with backoff)
# Checklist for submitter
If some of the following don't apply, delete the relevant line.
- [ ] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-
changes.md#changes-files) for more information.
Will add changelog when story is one.
## Testing
- [X] Added/updated automated tests
Added test for new retry logic
- [X] QA'd all new/changed functionality manually
This is kinda hard to test without the associated backend PR:
https://github.com/fleetdm/fleet/pull/34835
## fleetd/orbit/Fleet Desktop
- [X] Verified compatibility with the latest released version of Fleet
(see [Must
rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md))
This is compatible with all Fleet versions, since older ones won't send
the new error.
- [X] If the change applies to only one platform, confirmed that
`runtime.GOOS` is used as needed to isolate changes
This is compatible with all platforms, although it currently should only
ever run on Windows and Linux since macOS devices will have end-user
auth taken care of before they even download Orbit.
- [ ] Verified that fleetd runs on macOS, Linux and Windows
Testing this now.
- [ ] Verified auto-update works from the released version of component
to the new version (see [tools/tuf/test](../tools/tuf/test/README.md))
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Added SSO (Single Sign-On) enrollment support for end-user
authentication
* Enhanced error messaging for authentication-required scenarios
* **Bug Fixes**
* Improved error handling and retry logic for enrollment failures
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-11-03 22:41:57 +00:00
|
|
|
// Do not retry if the endpoint does not exist.
|
|
|
|
|
return retry.ErrorOutcomeDoNotRetry
|
|
|
|
|
case errors.Is(err, ErrEndUserAuthRequired):
|
|
|
|
|
// If we get an ErrEndUserAuthRequired error, then the user
|
|
|
|
|
// needs to authenticate with the identity provider.
|
|
|
|
|
//
|
|
|
|
|
// Open a browser window to the sign-on page and
|
|
|
|
|
// then keep retrying until they authenticate.
|
|
|
|
|
log.Debug().Msg("enroll unauthenticated, waiting for end-user to authenticate via SSO")
|
|
|
|
|
if !oc.initiatedIdpAuth {
|
|
|
|
|
if oc.openSSOWindow == nil {
|
|
|
|
|
log.Error().Msg("SSO window open function not set")
|
|
|
|
|
return retry.ErrorOutcomeNormalRetry
|
|
|
|
|
}
|
|
|
|
|
log.Debug().Msg("opening SSO window")
|
|
|
|
|
openWindowErr := oc.openSSOWindow()
|
|
|
|
|
if openWindowErr != nil {
|
|
|
|
|
log.Error().Err(openWindowErr).Msg("opening SSO window")
|
|
|
|
|
return retry.ErrorOutcomeNormalRetry
|
|
|
|
|
}
|
|
|
|
|
oc.initiatedIdpAuth = true
|
|
|
|
|
}
|
|
|
|
|
// Sleep for 20 seconds, making the total retry interval 30 seconds
|
|
|
|
|
time.Sleep(20 * time.Second)
|
|
|
|
|
return retry.ErrorOutcomeResetAttempts
|
|
|
|
|
default:
|
|
|
|
|
logging.LogErrIfEnvNotSet(constant.SilenceEnrollLogErrorEnvVar, err, "enroll failed, retrying")
|
|
|
|
|
return retry.ErrorOutcomeNormalRetry
|
|
|
|
|
}
|
|
|
|
|
}),
|
2022-10-03 20:28:19 +00:00
|
|
|
); err != nil {
|
2026-03-26 13:59:42 +00:00
|
|
|
if IsNotFoundErr(err) {
|
End-user authentication for Window/Linux setup experience: agent (#34847)
<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #34528
# Details
This PR implements the agent changes for allowing Fleet admins to
require that users authenticate with an IdP prior to having their
devices set up. I'll comment on changes inline but the high-level is:
1. Orbit calls the enroll endpoint as usual. This is triggered lazily by
any one of a number of subsystems like device token rotation or
requesting Fleet config
2. If the enroll endpoint returns the new `ErrEndUserAuthRequired`
response, then it opens a window to the `/mdm/sso` Fleet page and
retries the enroll endpoint every 30 seconds indefinitely.
3. Any other non-200 response to the enroll request is treated as before
(limited # of retries, with backoff)
# Checklist for submitter
If some of the following don't apply, delete the relevant line.
- [ ] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-
changes.md#changes-files) for more information.
Will add changelog when story is one.
## Testing
- [X] Added/updated automated tests
Added test for new retry logic
- [X] QA'd all new/changed functionality manually
This is kinda hard to test without the associated backend PR:
https://github.com/fleetdm/fleet/pull/34835
## fleetd/orbit/Fleet Desktop
- [X] Verified compatibility with the latest released version of Fleet
(see [Must
rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md))
This is compatible with all Fleet versions, since older ones won't send
the new error.
- [X] If the change applies to only one platform, confirmed that
`runtime.GOOS` is used as needed to isolate changes
This is compatible with all platforms, although it currently should only
ever run on Windows and Linux since macOS devices will have end-user
auth taken care of before they even download Orbit.
- [ ] Verified that fleetd runs on macOS, Linux and Windows
Testing this now.
- [ ] Verified auto-update works from the released version of component
to the new version (see [tools/tuf/test](../tools/tuf/test/README.md))
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Added SSO (Single Sign-On) enrollment support for end-user
authentication
* Enhanced error messaging for authentication-required scenarios
* **Bug Fixes**
* Improved error handling and retry logic for enrollment failures
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-11-03 22:41:57 +00:00
|
|
|
return "", errors.New("enroll endpoint does not exist")
|
|
|
|
|
}
|
2022-10-03 20:28:19 +00:00
|
|
|
return "", fmt.Errorf("orbit node key enroll failed, attempts=%d", constant.OrbitEnrollMaxRetries)
|
|
|
|
|
}
|
|
|
|
|
return orbitNodeKey_, nil
|
|
|
|
|
}
|
2022-09-23 19:00:23 +00:00
|
|
|
|
2023-08-29 13:50:13 +00:00
|
|
|
// GetNodeKey gets the orbit node key from file.
|
|
|
|
|
func (oc *OrbitClient) GetNodeKey() (string, error) {
|
|
|
|
|
orbitNodeKey, err := os.ReadFile(oc.nodeKeyFilePath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
return string(orbitNodeKey), nil
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-03 20:28:19 +00:00
|
|
|
func (oc *OrbitClient) enrollAndWriteNodeKeyFile() (string, error) {
|
|
|
|
|
orbitNodeKey, err := oc.enroll()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", fmt.Errorf("enroll request: %w", err)
|
|
|
|
|
}
|
2023-01-26 21:51:24 +00:00
|
|
|
|
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
|
// creating the secret file with empty content
|
|
|
|
|
if err := os.WriteFile(oc.nodeKeyFilePath, nil, constant.DefaultFileMode); err != nil {
|
|
|
|
|
return "", fmt.Errorf("create orbit node key file: %w", err)
|
|
|
|
|
}
|
|
|
|
|
// restricting file access
|
|
|
|
|
if err := platform.ChmodRestrictFile(oc.nodeKeyFilePath); err != nil {
|
|
|
|
|
return "", fmt.Errorf("apply ACLs: %w", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// writing raw key material to the acl-ready secret file
|
2022-10-03 20:28:19 +00:00
|
|
|
if err := os.WriteFile(oc.nodeKeyFilePath, []byte(orbitNodeKey), constant.DefaultFileMode); err != nil {
|
|
|
|
|
return "", fmt.Errorf("write orbit node key file: %w", err)
|
|
|
|
|
}
|
2023-01-26 21:51:24 +00:00
|
|
|
|
2022-10-03 20:28:19 +00:00
|
|
|
return orbitNodeKey, nil
|
2022-09-23 19:00:23 +00:00
|
|
|
}
|
2022-09-26 14:44:09 +00:00
|
|
|
|
2026-03-26 13:59:42 +00:00
|
|
|
func (oc *OrbitClient) authenticatedRequest(verb string, path string, params any, resp any) error {
|
2022-10-03 20:28:19 +00:00
|
|
|
nodeKey, err := oc.getNodeKeyOrEnroll()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2022-09-26 14:44:09 +00:00
|
|
|
|
2026-03-26 13:59:42 +00:00
|
|
|
s := params.(fleet.SetOrbitNodeKeyer)
|
|
|
|
|
s.SetOrbitNodeKey(nodeKey)
|
2022-10-03 20:28:19 +00:00
|
|
|
|
2022-11-29 16:54:36 +00:00
|
|
|
err = oc.request(verb, path, params, resp)
|
|
|
|
|
switch {
|
2022-10-03 20:28:19 +00:00
|
|
|
case err == nil:
|
|
|
|
|
oc.setEnrolled(true)
|
2022-09-26 14:44:09 +00:00
|
|
|
return nil
|
2022-10-03 20:28:19 +00:00
|
|
|
case errors.Is(err, ErrUnauthenticated):
|
|
|
|
|
if err := os.Remove(oc.nodeKeyFilePath); err != nil {
|
|
|
|
|
log.Info().Err(err).Msg("remove orbit node key")
|
|
|
|
|
}
|
|
|
|
|
oc.setEnrolled(false)
|
2025-07-18 14:31:52 +00:00
|
|
|
|
|
|
|
|
if oc.hostIdentityCertPath != "" {
|
|
|
|
|
if err := os.Remove(oc.hostIdentityCertPath); err != nil {
|
|
|
|
|
log.Info().Err(err).Msg("remove orbit host identity cert")
|
|
|
|
|
}
|
|
|
|
|
log.Info().Msg("removed orbit host identity cert, triggering a restart")
|
|
|
|
|
oc.receiverUpdateCancelFunc()
|
|
|
|
|
}
|
2022-10-03 20:28:19 +00:00
|
|
|
return err
|
|
|
|
|
default:
|
|
|
|
|
return err
|
2022-09-26 14:44:09 +00:00
|
|
|
}
|
2022-10-03 20:28:19 +00:00
|
|
|
}
|
2022-09-26 14:44:09 +00:00
|
|
|
|
2022-10-03 20:28:19 +00:00
|
|
|
func (oc *OrbitClient) Enrolled() bool {
|
|
|
|
|
oc.enrolledMu.Lock()
|
|
|
|
|
defer oc.enrolledMu.Unlock()
|
|
|
|
|
return oc.enrolled
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (oc *OrbitClient) setEnrolled(v bool) {
|
|
|
|
|
oc.enrolledMu.Lock()
|
|
|
|
|
defer oc.enrolledMu.Unlock()
|
|
|
|
|
oc.enrolled = v
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (oc *OrbitClient) LastRecordedError() error {
|
|
|
|
|
oc.lastRecordedErrMu.Lock()
|
|
|
|
|
defer oc.lastRecordedErrMu.Unlock()
|
|
|
|
|
return oc.lastRecordedErr
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (oc *OrbitClient) setLastRecordedError(err error) {
|
|
|
|
|
oc.lastRecordedErrMu.Lock()
|
|
|
|
|
defer oc.lastRecordedErrMu.Unlock()
|
|
|
|
|
oc.lastRecordedErr = fmt.Errorf("%s: %w", time.Now().UTC().Format("2006-01-02T15:04:05Z"), err)
|
2022-09-26 14:44:09 +00:00
|
|
|
}
|
2023-08-04 21:50:03 +00:00
|
|
|
|
2024-03-13 10:57:00 +00:00
|
|
|
func orbitEnrollRetryInterval() time.Duration {
|
2023-08-04 21:50:03 +00:00
|
|
|
interval := os.Getenv("FLEETD_ENROLL_RETRY_INTERVAL")
|
|
|
|
|
if interval != "" {
|
|
|
|
|
d, err := time.ParseDuration(interval)
|
|
|
|
|
if err == nil {
|
|
|
|
|
return d
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return constant.OrbitEnrollRetrySleep
|
|
|
|
|
}
|
2023-10-06 22:04:33 +00:00
|
|
|
|
2026-03-26 13:59:42 +00:00
|
|
|
// SetOrUpdateDiskEncryptionKey sends a request to the server to set or update the disk encryption keys.
|
2023-10-06 22:04:33 +00:00
|
|
|
func (oc *OrbitClient) SetOrUpdateDiskEncryptionKey(diskEncryptionStatus fleet.OrbitHostDiskEncryptionKeyPayload) error {
|
|
|
|
|
verb, path := "POST", "/api/fleet/orbit/disk_encryption_key"
|
2026-03-26 13:59:42 +00:00
|
|
|
var resp fleet.OrbitPostDiskEncryptionKeyResponse
|
|
|
|
|
if err := oc.authenticatedRequest(verb, path, &fleet.OrbitPostDiskEncryptionKeyRequest{
|
2023-10-06 22:04:33 +00:00
|
|
|
EncryptionKey: diskEncryptionStatus.EncryptionKey,
|
|
|
|
|
ClientError: diskEncryptionStatus.ClientError,
|
|
|
|
|
}, &resp); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2024-05-09 11:54:11 +00:00
|
|
|
|
|
|
|
|
const httpTraceTimeFormat = "2006-01-02T15:04:05Z"
|
|
|
|
|
|
|
|
|
|
var testStdoutHTTPTracer = &httptrace.ClientTrace{
|
|
|
|
|
ConnectStart: func(network, addr string) {
|
|
|
|
|
fmt.Printf(
|
|
|
|
|
"httptrace: %s: ConnectStart: %s, %s\n",
|
|
|
|
|
time.Now().UTC().Format(httpTraceTimeFormat), network, addr,
|
|
|
|
|
)
|
|
|
|
|
},
|
|
|
|
|
ConnectDone: func(network, addr string, err error) {
|
|
|
|
|
fmt.Printf(
|
|
|
|
|
"httptrace: %s: ConnectDone: %s, %s, err='%s'\n",
|
|
|
|
|
time.Now().UTC().Format(httpTraceTimeFormat), network, addr, err,
|
|
|
|
|
)
|
|
|
|
|
},
|
|
|
|
|
}
|
2024-10-14 21:15:42 +00:00
|
|
|
|
|
|
|
|
// GetSetupExperienceStatus checks the status of the setup experience for this host.
|
Stop setup experience on software install failure (#34173)
<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #33173
**Related issue:** Resolves #33111
# Details
This is the remaining work to implement the "Stop the setup experience
when required software fails to install" feature. This didn't turn out
to be quite as straightforward as expected so I ended up doing a bit of
design-by-code and expect some feedback on the approach. I tried to make
it as low-touch as possible. The general design is:
1. In the `maybeUpdateSetupExperienceStatus` function which is called in
various places when a setup experience step is marked as completed, call
a new `maybeCancelPendingSetupExperienceSteps` function if the setup
step was marked as failed. Similarly call
`maybeCancelPendingSetupExperienceSteps` if a VPP app install fails to
enqueue.
2. In `maybeCancelPendingSetupExperienceSteps`, check whether the
specified host is MacOS and whether the "RequireAllSoftwareMacOS" flag
is set in the team (or global) config. If so, mark the remaining setup
experience items as canceled and cancel any upcoming activities related
to those steps.
3. On the front-end, if the `require_all_software_macos` is set and a
software step is marked as failed, show a new failure page indicating
that setup has failed and showing details of the failed software.
4. On the agent side, when checking setup experience status, send a
`reset_after_failure` flag _only the first time_. If this flag is set,
then the code in the `/orbit/setup_experience/status` handler will clear
and re-queue any failed setup experience steps (but leave successful
steps to avoid re-installing already-installed software). This
facilitates re-starting the setup experience when the host is rebooted.
I also updated the way that software (packages and VPP) is queued up for
the setup experience to be ordered alphabetically, to make it easier to
test _and_ because this is a desired outcome for a future story. Since
the order is not deterministic now, this update shouldn't cause any
problems (aside from a couple of test updates), but I'm ok taking it out
if desired.
# Checklist for submitter
If some of the following don't apply, delete the relevant line.
- [X] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files)
for more information.
- [X] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
## Testing
- [X] Added/updated automated tests
* Added a new integration test for software packages, testing that a
failed software package causes the rest of the setup experience to be
marked as failed when `require_all_software_macos` is set, and testing
that the "reset after failure" code works.
* Added a new integration test for VPP packages, testing that a failed
VPP enqueue causes the same halting of the setup experience.
I _don't_ have test for a failure _during_ a VPP install. It should go
through the same code path as the software package failure, so it's not
a huge gap.
- [ ] QA'd all new/changed functionality manually
Working on it
## fleetd/orbit/Fleet Desktop
- [X] Verified compatibility with the latest released version of Fleet
(see [Must
rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md))
- [X] If the change applies to only one platform, confirmed that
`runtime.GOOS` is used as needed to isolate changes
- [X] Verified that fleetd runs on macOS, Linux and Windows
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
- New Features
- Configurable option to halt macOS device setup if any software install
fails.
- Device setup page now shows a clear “Device setup failed” state with
expandable error details when all software is required on macOS.
- Improvements
- Setup status now includes per-step error messages for better
troubleshooting.
- Pending setup steps are automatically canceled after a failure when
applicable, with support to reset and retry the setup flow as
configured.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Ian Littman <iansltx@gmail.com>
2025-10-17 13:38:53 +00:00
|
|
|
func (oc *OrbitClient) GetSetupExperienceStatus(resetFailedSetupSteps bool) (*fleet.SetupExperienceStatusPayload, error) {
|
2024-10-14 21:15:42 +00:00
|
|
|
verb, path := "POST", "/api/fleet/orbit/setup_experience/status"
|
2026-03-26 13:59:42 +00:00
|
|
|
var resp fleet.GetOrbitSetupExperienceStatusResponse
|
|
|
|
|
err := oc.authenticatedRequest(verb, path, &fleet.GetOrbitSetupExperienceStatusRequest{
|
Stop setup experience on software install failure (#34173)
<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #33173
**Related issue:** Resolves #33111
# Details
This is the remaining work to implement the "Stop the setup experience
when required software fails to install" feature. This didn't turn out
to be quite as straightforward as expected so I ended up doing a bit of
design-by-code and expect some feedback on the approach. I tried to make
it as low-touch as possible. The general design is:
1. In the `maybeUpdateSetupExperienceStatus` function which is called in
various places when a setup experience step is marked as completed, call
a new `maybeCancelPendingSetupExperienceSteps` function if the setup
step was marked as failed. Similarly call
`maybeCancelPendingSetupExperienceSteps` if a VPP app install fails to
enqueue.
2. In `maybeCancelPendingSetupExperienceSteps`, check whether the
specified host is MacOS and whether the "RequireAllSoftwareMacOS" flag
is set in the team (or global) config. If so, mark the remaining setup
experience items as canceled and cancel any upcoming activities related
to those steps.
3. On the front-end, if the `require_all_software_macos` is set and a
software step is marked as failed, show a new failure page indicating
that setup has failed and showing details of the failed software.
4. On the agent side, when checking setup experience status, send a
`reset_after_failure` flag _only the first time_. If this flag is set,
then the code in the `/orbit/setup_experience/status` handler will clear
and re-queue any failed setup experience steps (but leave successful
steps to avoid re-installing already-installed software). This
facilitates re-starting the setup experience when the host is rebooted.
I also updated the way that software (packages and VPP) is queued up for
the setup experience to be ordered alphabetically, to make it easier to
test _and_ because this is a desired outcome for a future story. Since
the order is not deterministic now, this update shouldn't cause any
problems (aside from a couple of test updates), but I'm ok taking it out
if desired.
# Checklist for submitter
If some of the following don't apply, delete the relevant line.
- [X] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files)
for more information.
- [X] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
## Testing
- [X] Added/updated automated tests
* Added a new integration test for software packages, testing that a
failed software package causes the rest of the setup experience to be
marked as failed when `require_all_software_macos` is set, and testing
that the "reset after failure" code works.
* Added a new integration test for VPP packages, testing that a failed
VPP enqueue causes the same halting of the setup experience.
I _don't_ have test for a failure _during_ a VPP install. It should go
through the same code path as the software package failure, so it's not
a huge gap.
- [ ] QA'd all new/changed functionality manually
Working on it
## fleetd/orbit/Fleet Desktop
- [X] Verified compatibility with the latest released version of Fleet
(see [Must
rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md))
- [X] If the change applies to only one platform, confirmed that
`runtime.GOOS` is used as needed to isolate changes
- [X] Verified that fleetd runs on macOS, Linux and Windows
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
- New Features
- Configurable option to halt macOS device setup if any software install
fails.
- Device setup page now shows a clear “Device setup failed” state with
expandable error details when all software is required on macOS.
- Improvements
- Setup status now includes per-step error messages for better
troubleshooting.
- Pending setup steps are automatically canceled after a failure when
applicable, with support to reset and retry the setup flow as
configured.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Ian Littman <iansltx@gmail.com>
2025-10-17 13:38:53 +00:00
|
|
|
ResetFailedSetupSteps: resetFailedSetupSteps,
|
|
|
|
|
}, &resp)
|
2024-10-14 21:15:42 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return resp.Results, nil
|
|
|
|
|
}
|
2024-11-21 16:31:03 +00:00
|
|
|
|
|
|
|
|
func (oc *OrbitClient) SendLinuxKeyEscrowResponse(lr luks.LuksResponse) error {
|
|
|
|
|
verb, path := "POST", "/api/fleet/orbit/luks_data"
|
2026-03-26 13:59:42 +00:00
|
|
|
var resp fleet.OrbitPostLUKSResponse
|
|
|
|
|
if err := oc.authenticatedRequest(verb, path, &fleet.OrbitPostLUKSRequest{
|
2024-11-21 16:31:03 +00:00
|
|
|
Passphrase: lr.Passphrase,
|
|
|
|
|
KeySlot: lr.KeySlot,
|
|
|
|
|
Salt: lr.Salt,
|
|
|
|
|
ClientError: lr.Err,
|
|
|
|
|
}, &resp); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2025-09-05 14:07:03 +00:00
|
|
|
|
|
|
|
|
func (oc *OrbitClient) InitiateSetupExperience() (fleet.SetupExperienceInitResult, error) {
|
|
|
|
|
verb, path := "POST", "/api/fleet/orbit/setup_experience/init"
|
2026-03-26 13:59:42 +00:00
|
|
|
var resp fleet.OrbitSetupExperienceInitResponse
|
|
|
|
|
if err := oc.authenticatedRequest(verb, path, &fleet.OrbitSetupExperienceInitRequest{}, &resp); err != nil {
|
2025-09-05 14:07:03 +00:00
|
|
|
return fleet.SetupExperienceInitResult{}, err
|
|
|
|
|
}
|
|
|
|
|
return resp.Result, nil
|
|
|
|
|
}
|