Files
fleet/orbit/pkg/update/debug_log_runner.go
Jordan MontgomeryandCopilot Autofix powered by AI bee5edaa0b Add server-side orbit debug logging enablement - currently only configurable as a duration-after-enrollment setting (#45367)
<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #43997 

# 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), JS
inline code is prevented especially for url redirects, and untrusted
data interpolated into shell scripts/commands is validated against shell
metacharacters.
- [x] Timeouts are implemented and retries are limited to avoid infinite
loops
- [x] If paths of existing endpoints are modified without backwards
compatibility, checked the frontend/CLI for any necessary changes

## Testing

- [x] Added/updated automated tests
- [x] Where appropriate, [automated tests simulate multiple hosts and
test for host
isolation](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/reference/patterns-backend.md#unit-testing)
(updates to one hosts's records do not affect another)

- [x] QA'd all new/changed functionality manually

## Database migrations

- [x] Checked schema for all modified table for columns that will
auto-update timestamps during migration.
- [x] Confirmed that updating the timestamps is acceptable, and will not
cause unwanted side effects.
- [x] Ensured the correct collation is explicitly set for character
columns (`COLLATE utf8mb4_unicode_ci`).

## 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] Verified that fleetd runs on macOS, Linux and Windows
- [x] 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**
* Configure Orbit to enable debug logging for a limited window on agent
enrollment; enrolled hosts receive debug/verbose behavior while the
window is active and it is reflected in agent config.

* **Chores**
* Added database column to record per-host debug-until timestamps and
datastore support to extend it safely.

* **Tests**
* Added integration and unit tests covering validation, enrollment
stamping, config generation, and runtime debug toggling.

<!-- review_stack_entry_start -->

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/fleetdm/fleet/pull/45367)

<!-- review_stack_entry_end -->
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-05-14 13:32:02 -04:00

47 lines
1.2 KiB
Go

package update
import (
"github.com/fleetdm/fleet/v4/server/fleet"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
// DebugLogReceiver toggles orbit's zerolog level in response to
// OrbitConfig.DebugLogging.
type DebugLogReceiver struct {
// startedInDebug acts as a floor: when orbit was launched with --debug
// or ORBIT_DEBUG=1, the server can raise the level but cannot lower it.
startedInDebug bool
}
func NewDebugLogReceiver(startedInDebug bool) *DebugLogReceiver {
return &DebugLogReceiver{startedInDebug: startedInDebug}
}
// Run sets the global zerolog level to match config.DebugLogging. Nil
// returns the value to the default, either info level or debug if the
// agent was started in debug mode.
func (r *DebugLogReceiver) Run(config *fleet.OrbitConfig) error {
if config == nil {
return nil
}
currentGlobalLevel := zerolog.GlobalLevel()
desired := zerolog.InfoLevel
if (config.DebugLogging != nil && *config.DebugLogging) || r.startedInDebug {
desired = zerolog.DebugLevel
}
if currentGlobalLevel == desired {
return nil
}
zerolog.SetGlobalLevel(desired)
log.Info().
Str("from", currentGlobalLevel.String()).
Str("to", desired.String()).
Msg("orbit log level changed by server config")
return nil
}