fleet/cmd/fleetctl/fleetctl
Scott Gress d5eee802eb
Detect unknown keys in GitOps (phase 1) (#40963)
<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #40496

# Details

This is the first phase of an effort to detect unknown keys in GitOps
.yml files. In the regular `fleetctl gitops` case, it will fail when
unknown keys are detected. This behavior can be changed with a new
`--allow-unknown-keys` flag which will log the issues and continue.

In this first phase we are detecting unknown keys in _most_ GitOps
sections, other than the top-level `org_settings:` and `settings:`
sections which have more complicated typing. I will tackle those
separately as they require a bit more thought. Also ultimately I'd like
us to be doing this validation in a more top-down fashion in one place,
rather than spreading it across the code by doing it in each individual
section, but this is a good first step.

As a bonus, I invited my pal Mr. Levenshtein to the party so that we can
make suggestions when unknown keys are detected, like:

```
 * unknown key "queyr" in "./lib/some-report.yml"; did you mean "query"?
```
> Note: the goal is to return as many validation errors as possible to
the user, so they don't have to keep running `fleetctl gitops` to get
the next error. I did _not_ update any other errors to stop returning
early, in an effort to keep this as low-touch as possible.

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

## Testing

- [X] Added/updated automated tests
- [X] QA'd all new/changed functionality manually
- [X] Tested this against existing it-and-security folder and one with
updated keys from https://github.com/fleetdm/fleet/pull/40959; no
unknown keys detected
- [X] Added unknown keys at various levels, GitOps errored with helpful
messages
- [X] Same as above but with `--allow-unknown-keys`; GitOps outputted
helpful messages but continued.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* GitOps runs now fail when unknown or misspelled keys are present in
configuration files.
* New CLI flag --allow-unknown-keys lets unknown keys be treated as
warnings instead of errors.
* Unknown-key messages include suggested valid key names to help correct
mistakes.

* **Tests**
* Expanded test coverage to validate unknown-key detection and the
allow-as-warning option.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Ian Littman <iansltx@gmail.com>
2026-03-06 16:16:17 -06:00
..
testdata Add aliases for macos fields (#40959) 2026-03-05 18:08:54 -06:00
testing_utils Rework conditional access policy bypass conditions to use critical column (#40736) 2026-03-05 17:05:03 -05:00
api.go Update error message for Fleet API address (#38600) 2026-02-24 09:06:03 -07:00
api_test.go Rework conditional access policy bypass conditions to use critical column (#40736) 2026-03-05 17:05:03 -05:00
apply.go Add missing deprecation warning for --policies-team (#41071) 2026-03-05 17:29:33 -06:00
apply_test.go Add lock end user info migrations, API support and AccountConfiguration command updates (#40551) 2026-03-02 12:16:31 -05:00
config.go fleetctl config set --token: Simplify output message (#39788) 2026-02-13 09:34:25 -05:00
config_test.go Fix fleetctl config help display for missing arguments (#37769) 2026-01-08 09:55:18 -05:00
convert.go Add aliases to fleetctl commands and flags (#40548) 2026-02-27 08:38:29 -06:00
convert_test.go Moved fleetctl to fleetctl package. (#28932) 2025-05-07 15:53:35 -05:00
debug.go Fixed typo in debug.go (#31135) 2025-07-22 22:00:47 -05:00
debug_test.go Moved some integration tests into their own package. (#28978) 2025-05-09 09:26:57 -05:00
delete.go Moved fleetctl to fleetctl package. (#28932) 2025-05-07 15:53:35 -05:00
delete_test.go Move NewActivity to activity bounded context (#39521) 2026-02-25 14:11:03 -06:00
docker_test.go Moved some integration tests into their own package. (#28978) 2025-05-09 09:26:57 -05:00
flags.go Add aliases to fleetctl commands and flags (#40548) 2026-02-27 08:38:29 -06:00
fleetctl.go [fleetctl] api command: support request body, including file uploads (#30806) 2025-07-29 08:15:23 -05:00
generate.go Moved fleetctl to fleetctl package. (#28932) 2025-05-07 15:53:35 -05:00
generate_gitops.go Add aliases for macos fields (#40959) 2026-03-05 18:08:54 -06:00
generate_gitops_test.go Add aliases for macos fields (#40959) 2026-03-05 18:08:54 -06:00
generate_test.go Moved some integration tests into their own package. (#28978) 2025-05-09 09:26:57 -05:00
get.go Add aliases to fleetctl commands and flags (#40548) 2026-02-27 08:38:29 -06:00
get_test.go Rework conditional access policy bypass conditions to use critical column (#40736) 2026-03-05 17:05:03 -05:00
gitops.go Detect unknown keys in GitOps (phase 1) (#40963) 2026-03-06 16:16:17 -06:00
gitops_test.go Improved validation for packages (#40407) 2026-02-26 11:34:13 -06:00
goquery.go Moved fleetctl to fleetctl package. (#28932) 2025-05-07 15:53:35 -05:00
hosts.go Add aliases to fleetctl commands and flags (#40548) 2026-02-27 08:38:29 -06:00
hosts_test.go Add aliases to fleetctl commands and flags (#40548) 2026-02-27 08:38:29 -06:00
kill_process.go Moved fleetctl to fleetctl package. (#28932) 2025-05-07 15:53:35 -05:00
kill_process_windows.go Moved fleetctl to fleetctl package. (#28932) 2025-05-07 15:53:35 -05:00
login.go Moved fleetctl to fleetctl package. (#28932) 2025-05-07 15:53:35 -05:00
logout.go Moved fleetctl to fleetctl package. (#28932) 2025-05-07 15:53:35 -05:00
logout_test.go Moved some integration tests into their own package. (#28978) 2025-05-09 09:26:57 -05:00
mdm.go [fleetctl] api command: support request body, including file uploads (#30806) 2025-07-29 08:15:23 -05:00
mdm_test.go Move NewActivity to activity bounded context (#39521) 2026-02-25 14:11:03 -06:00
package.go Add initial Arch Linux support (#33096) 2025-09-18 18:55:31 -03:00
preview.go Final slog migration PR: test infrastructure + tools + remaining standalone files (#40727) 2026-02-28 05:52:21 -06:00
query.go Add aliases to fleetctl commands and flags (#40548) 2026-02-27 08:38:29 -06:00
query_output.go Moved fleetctl to fleetctl package. (#28932) 2025-05-07 15:53:35 -05:00
query_test.go Final slog migration PR: test infrastructure + tools + remaining standalone files (#40727) 2026-02-28 05:52:21 -06:00
scripts.go Add aliases to fleetctl commands and flags (#40548) 2026-02-27 08:38:29 -06:00
scripts_test.go Add aliases to fleetctl commands and flags (#40548) 2026-02-27 08:38:29 -06:00
session_test.go Show Manage Automations disabled button with tooltip on Queries page (#39302) 2026-02-09 15:16:28 -03:00
setup.go Moved fleetctl to fleetctl package. (#28932) 2025-05-07 15:53:35 -05:00
testing_utils.go Add aliases to fleetctl commands and flags (#40548) 2026-02-27 08:38:29 -06:00
trigger.go Moved fleetctl to fleetctl package. (#28932) 2025-05-07 15:53:35 -05:00
trigger_test.go Final slog migration PR: test infrastructure + tools + remaining standalone files (#40727) 2026-02-28 05:52:21 -06:00
upgrade_packs.go Support report/fleet as spec "kinds" (#40586) 2026-02-26 13:07:21 -06:00
upgrade_packs_test.go Support report/fleet as spec "kinds" (#40586) 2026-02-26 13:07:21 -06:00
user.go Add aliases to fleetctl commands and flags (#40548) 2026-02-27 08:38:29 -06:00
users_test.go Move NewActivity to activity bounded context (#39521) 2026-02-25 14:11:03 -06:00
vulnerability_data_stream.go Migrating vulnerabilities pkgs to slog. (#40106) 2026-02-20 15:36:38 -06:00