Skip to content

Add aliases for macos fields - #40959

Merged
sgress454 merged 13 commits into
mainfrom
sgress454/40488/multiplatform-names
Mar 6, 2026
Merged

Add aliases for macos fields#40959
sgress454 merged 13 commits into
mainfrom
sgress454/40488/multiplatform-names

Conversation

@sgress454

@sgress454 sgress454 commented Mar 4, 2026

Copy link
Copy Markdown
Contributor

Related issue: Resolves #40488

Details

Implements the renames requested in #40488:

  • Add a second name for macos_setup: setup_experience
  • Add a second name for macos_settings: apple_settings
  • Add a second name for custom_settings: configuration_profiles
  • Add a second name for macos_setup_assistant: apple_setup_assistant

Prior names are deprecated and log warnings. This uses the same renameto tags as previous aliases, and adds code in relevant sections in gitops.go to run the existing "rename new to old keys" function so that we can unmarshall into the existing structs (that still have their json tags set to the old key names until Fleet 5).

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 for more information.

Testing

  • Added/updated automated tests
  • QA'd all new/changed functionality manually
    • Ran current it-and-security GitOps files successfully locally (removing mdm stuff that wouldn't work for me locally, but wasn't relevant to the updated keys
    • Run same files successfully after changing the deprecated key names to their new aliases
    • Verified that new keys show up in API responses:
image

If you didn't check the box above, follow this checklist for GitOps-enabled settings:

  • Verified that the setting is exported via fleetctl generate-gitops
  • Verified the setting is documented in a separate PR to the GitOps documentation
  • Verified that the setting is cleared on the server if it is not supplied in a YAML file (or that it is documented as being optional)
  • Verified that any relevant UI is disabled when GitOps mode is enabled
    n/a

Summary by CodeRabbit

  • New Features
    • Introduces new configuration key aliases: apple_settings (macOS), configuration_profiles (profiles for macOS/Windows/Android), setup_experience (macOS setup), and apple_setup_assistant (macOS setup assistant).
    • Old configuration keys remain supported for backward compatibility; tooling and generated controls will accept either the new or legacy names.

@codecov

codecov Bot commented Mar 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.32%. Comparing base (83a0df3) to head (0e2547a).
⚠️ Report is 35 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #40959      +/-   ##
==========================================
+ Coverage   66.31%   66.32%   +0.01%     
==========================================
  Files        2469     2470       +1     
  Lines      197782   197934     +152     
  Branches     8675     8675              
==========================================
+ Hits       131154   131279     +125     
- Misses      54761    54771      +10     
- Partials    11867    11884      +17     
Flag Coverage Δ
backend 68.11% <100.00%> (+0.01%) ⬆️

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

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

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

Comment on lines +1158 to +1165
macosSettingsT := reflect.TypeFor[fleet.MacOSSettings]()
windowsSettingsT := reflect.TypeFor[fleet.WindowsSettings]()
androidSettingsT := reflect.TypeFor[fleet.AndroidSettings]()

if cmd.AppConfig.MDM.EnabledAndConfigured && profiles != nil {
if len(profiles["apple_profiles"].([]map[string]interface{})) > 0 {
result[jsonFieldName(t, "MacOSSettings")] = map[string]interface{}{
"custom_settings": profiles["apple_profiles"],
jsonFieldName(macosSettingsT, "CustomSettings"): profiles["apple_profiles"],

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Should have done this awhile ago; this just uses reflection to get the key name from the section rather than hardcoding it. Most of generate-gitops already uses this pattern.

@sgress454
sgress454 marked this pull request as ready for review March 4, 2026 19:52
@sgress454
sgress454 requested a review from a team as a code owner March 4, 2026 19:52
@sgress454

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Mar 4, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

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

@coderabbitai

coderabbitai Bot commented Mar 4, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

This PR adds alternative JSON/YAML key names for several MDM and GitOps control fields and implements key-rewriting so both old and new names are accepted. It introduces renameto struct tags on public types (GitOpsControls, MDM, MDMHostData, TeamMDM, TeamSpecMDM) to expose aliases: setup_experience for macos_setup, apple_settings for macos_settings, configuration_profiles for custom_settings, and apple_setup_assistant for macos_setup_assistant. Parsing now rewrites new keys to legacy keys after YAML→JSON conversion; gitops generation and tests were updated to derive and assert on the new key names.

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add aliases for macos fields' clearly summarizes the main change of adding new names for deprecated macOS GitOps configuration keys.
Linked Issues check ✅ Passed All coding requirements from #40488 are met: aliases added for macos_setup (setup_experience), macos_settings (apple_settings), custom_settings (configuration_profiles), and macos_setup_assistant (apple_setup_assistant) with backward compatibility maintained.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the field aliases specified in #40488; no unrelated modifications to other features or unscoped refactoring detected.
Description check ✅ Passed The pull request description is comprehensive and follows the template with completed relevant checklist items including changes file, testing, and GitOps verification.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch sgress454/40488/multiplatform-names

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
cmd/fleetctl/fleetctl/generate_gitops.go (1)

1273-1277: ⚠️ Potential issue | 🟡 Minor

Update the note text to match the emitted key name.

Line 1273 emits setup_experience, but Line 1276 still tells users to configure macos_setup. This is user-facing and likely confusing.

💡 Suggested text update
-				Note:     "The macos_setup configuration is not supported by this tool yet.  To configure it, please follow the Fleet documentation at https://fleetdm.com/docs/configuration/yaml-files#macos-setup",
+				Note:     "The setup_experience configuration is not supported by this tool yet. To configure it, please follow the Fleet documentation at https://fleetdm.com/docs/configuration/yaml-files#macos-setup (legacy key: macos_setup).",
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/fleetctl/fleetctl/generate_gitops.go` around lines 1273 - 1277, The
user-facing note references the wrong key name; when emitting
result[jsonFieldName(mdmT, "MacOSSetup")] (which produces the setup_experience
key) update the Note added to cmd.Messages.Notes (the Note struct created with
Filename: teamName) so its Note string mentions "setup_experience" instead of
"macos_setup" and otherwise keeps the same guidance/URL; locate the code that
constructs that Note (the append to cmd.Messages.Notes) and change the text
accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cmd/fleetctl/fleetctl/generate_gitops_test.go`:
- Around line 1388-1391: The test reuses the prior boolean `ok` when asserting
absence of `setup_experience` for the team-2 case; recompute the presence check
on the fresh `controlsRaw` returned by cmd.generateControls(ptr.Uint(2),
"some_team", nil) before the require.False assertion. Locate the team-2 block in
generate_gitops_test.go, re-evaluate the `ok` (the result of checking for the
"setup_experience" key in `controlsRaw`) from the new `controlsRaw` and then
call require.False(t, ok, ...) to correctly assert that setup_experience is not
present.

In `@pkg/spec/gitops.go`:
- Line 760: processControlsPathIfNeeded currently reassigns the local pointer
variable controlsFilePath instead of writing through it, so the caller's
controlsFilePath is never updated; change the function to set the pointee (e.g.,
*controlsFilePath = ptr.String(...)) after nil-checking controlsFilePath (and
allocate if needed) so the caller receives the new path; update the assignment
in processControlsPathIfNeeded and ensure any early returns still preserve the
intended updated value for the caller.

---

Outside diff comments:
In `@cmd/fleetctl/fleetctl/generate_gitops.go`:
- Around line 1273-1277: The user-facing note references the wrong key name;
when emitting result[jsonFieldName(mdmT, "MacOSSetup")] (which produces the
setup_experience key) update the Note added to cmd.Messages.Notes (the Note
struct created with Filename: teamName) so its Note string mentions
"setup_experience" instead of "macos_setup" and otherwise keeps the same
guidance/URL; locate the code that constructs that Note (the append to
cmd.Messages.Notes) and change the text accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b172fe7d-8ee4-4b76-a8dd-9154cbea53bb

📥 Commits

Reviewing files that changed from the base of the PR and between 83a0df3 and faed6f1.

📒 Files selected for processing (14)
  • changes/40488-add-more-aliases
  • cmd/fleetctl/fleetctl/generate_gitops.go
  • cmd/fleetctl/fleetctl/generate_gitops_test.go
  • cmd/fleetctl/fleetctl/testdata/generateGitops/expectedGlobalControls.yaml
  • cmd/fleetctl/fleetctl/testdata/generateGitops/expectedTeamControls.yaml
  • cmd/fleetctl/fleetctl/testdata/generateGitops/test_dir_free/default.yml
  • cmd/fleetctl/fleetctl/testdata/generateGitops/test_dir_premium/fleets/team-a-thumbsup.yml
  • cmd/fleetctl/fleetctl/testdata/generateGitops/test_dir_premium/fleets/unassigned.yml
  • pkg/spec/gitops.go
  • pkg/spec/gitops_test.go
  • pkg/spec/testdata/controls_new_names.yml
  • server/fleet/app.go
  • server/fleet/hosts.go
  • server/fleet/teams.go

Comment thread cmd/fleetctl/fleetctl/generate_gitops_test.go Outdated
Comment thread pkg/spec/gitops.go
@sgress454

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Mar 4, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cmd/fleetctl/fleetctl/generate_gitops_test.go`:
- Around line 1391-1392: The assertion message for the check on
controlsRaw["setup_experience"] is misleading for the team-2 scenario; update
the require.False call that currently reads require.False(t, ok, "Expected no
setup_experience section for no-team controls") to a message that references
team 2 (e.g., "Expected no setup_experience section for team-2 controls") so
test failures correctly indicate the tested scenario; locate the require.False
invocation that inspects controlsRaw and change only the failure string to
mention team-2.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 380e505a-e2dd-43c1-b342-53aff2203110

📥 Commits

Reviewing files that changed from the base of the PR and between faed6f1 and 20f8ea9.

📒 Files selected for processing (2)
  • cmd/fleetctl/fleetctl/generate_gitops_test.go
  • server/fleet/teams.go

Comment thread cmd/fleetctl/fleetctl/generate_gitops_test.go Outdated
Comment on lines +27 to +30
windows_enabled_and_configured: true
windows_migration_enabled: false
enable_turn_on_windows_mdm_manually: false
windows_entra_tenant_ids: []

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@noahtalerman Doesn't make sense to expand scope in this issue but these seem like they need to be looked at from a consistency perspective.

@iansltx iansltx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Doesn't look like we have tests for GitOps that will fail if you provide both old and new names. Mind adding those?

No feedback otherwise here.

@sgress454

Copy link
Copy Markdown
Contributor Author

Doesn't look like we have tests for GitOps that will fail if you provide both old and new names. Mind adding those?

Added missing unit tests for rewriteNewToOldKeys, and gitops tests for each controls section that rewrites keys.

@iansltx iansltx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Added a little more oomph to the tests to make sure we're marking the old fields as deprecated (we are) so we're good to go here.

@sgress454
sgress454 merged commit 51ab583 into main Mar 6, 2026
52 of 53 checks passed
@sgress454
sgress454 deleted the sgress454/40488/multiplatform-names branch March 6, 2026 00:08
@coderabbitai coderabbitai Bot mentioned this pull request Mar 6, 2026
3 tasks
sgress454 added a commit that referenced this pull request Mar 6, 2026
<!-- 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 #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>
@coderabbitai coderabbitai Bot mentioned this pull request Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multi-platform names for macos_setup and macos_settings

2 participants