Skip to content

Extend support for all built-in - #49354

Merged
juan-fdz-hawa merged 3 commits into
mainfrom
38806-extend-to-all-built-in
Jul 16, 2026
Merged

Extend support for all built-in#49354
juan-fdz-hawa merged 3 commits into
mainfrom
38806-extend-to-all-built-in

Conversation

@juan-fdz-hawa

@juan-fdz-hawa juan-fdz-hawa commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Relates to #38806

Extend host name templates beyond the three host-identity variables to also accept the IdP end-user variables, and re-enqueue the rename when a referenced variable's value changes.

Re-enqueue on value change:

  • An IdP data change (SCIM user/group create/update/delete) re-queues only the affected hosts whose template uses the changed IdP variable — IdP values are per host, so the scope is the specific hosts mapped to that user/group.
  • A custom (secret) value change re-queues every eligible host in each team / "No team" whose template references the changed secret — secret values are global, so the scope is the whole team/No-team.

Built-in variables intentionally NOT supported:

  • Certificate/CA variables — $FLEET_VAR_NDES_SCEP_CHALLENGE, _NDES_SCEP_PROXY_URL, CUSTOM_SCEP_CHALLENGE, CUSTOM_SCEP_PROXY_URL, SMALLSTEP_SCEP_CHALLENGE, SMALLSTEP_SCEP_PROXY_URL, DIGICERT_DATA, DIGICERT_PASSWORD, _SCEP_WINDOWS_CERTIFICATE_ID, _CERTIFICATE_RENEWAL_ID (and legacy _SCEP_RENEWAL_ID), _PSSO_DEVICE_REGISTRATION_TOKEN. These resolve to one-time SCEP challenges, proxy URLs, base64 PKCS12 cert data, or Fleet-minted tokens — meaningless as a device name, and resolving them has side effects (issuing certificates, consuming one-time challenges) and would leak secrets into a name that's broadcast on-device, in osquery, and in the UI.
  • Legacy $FLEET_VAR_HOST_END_USER_EMAIL_IDP — deprecated ("avoid in new replacements") and not a documented built-in variable, so it's excluded in favor of the supported IDP_USERNAME variables.

Checklist for submitter

If some of the following don't apply, delete the relevant line.

Testing

  • Added/updated automated tests
  • QA'd all new/changed functionality manually

Summary by CodeRabbit

  • New Features
    • Host name templates now support additional identity-provider attributes (username, groups, full name, department, username local part).
    • Apple host device-name reconciliation now resolves identity-provider variables when generating device names.
  • Bug Fixes
    • Device-name enforcement is re-queued when referenced secret values or supported identity-provider variables change, with correct scoping and retry behavior.
    • Host name template validation and MDM error classification are improved (secret-related issues treated as user input where appropriate).
    • Global template usage errors are now labeled “Unassigned”.
    • GitOps team-spec handling for name_template better supports secret placeholders and preserves them for server-side processing.
  • Tests
    • Expanded unit and integration coverage for identity-provider, secret-variable, and re-enqueue scenarios.

Base automatically changed from 38806-extend-secrets to main July 15, 2026 18:29
Relates to #38806

Extend host name templates beyond the three host-identity variables to
also accept the IdP end-user variables, and re-enqueue the rename when
a referenced variable's value changes.

Re-enqueue on value change:
- An IdP data change (SCIM user/group create/update/delete) re-queues only
the affected hosts whose template uses the changed IdP variable — IdP
values are per host, so the scope is the specific hosts mapped to that
user/group.
- A custom (secret) value change re-queues every eligible host in each
team / "No team" whose template references the changed secret — secret
values are global, so the scope is the whole team/No-team.

Built-in variables intentionally NOT supported:
- Certificate/CA variables — $FLEET_VAR_NDES_SCEP_CHALLENGE,
_NDES_SCEP_PROXY_URL, _CUSTOM_SCEP_CHALLENGE_*, _CUSTOM_SCEP_PROXY_URL_*,
_SMALLSTEP_SCEP_CHALLENGE_*, _SMALLSTEP_SCEP_PROXY_URL_*, _DIGICERT_DATA_*,
_DIGICERT_PASSWORD_*, _SCEP_WINDOWS_CERTIFICATE_ID, _CERTIFICATE_RENEWAL_ID
(and legacy _SCEP_RENEWAL_ID), _PSSO_DEVICE_REGISTRATION_TOKEN. These
resolve to one-time SCEP challenges, proxy URLs, base64 PKCS12 cert data,
or Fleet-minted tokens — meaningless as a device name, and resolving them
has side effects (issuing certificates, consuming one-time challenges) and
would leak secrets into a name that's broadcast on-device, in osquery, and
in the UI.
- Legacy $FLEET_VAR_HOST_END_USER_EMAIL_IDP — deprecated ("avoid in new
replacements") and not a documented built-in variable, so it's excluded
in favor of the supported IDP_USERNAME variables.
@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 68.57143% with 44 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.97%. Comparing base (0e78132) to head (ab955d2).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
server/service/apple_device_names.go 66.66% 17 Missing and 4 partials ⚠️
server/datastore/mysql/apple_device_names.go 47.36% 5 Missing and 5 partials ⚠️
server/datastore/mysql/scim.go 64.28% 5 Missing and 5 partials ⚠️
server/datastore/mysql/secret_variables.go 66.66% 1 Missing and 1 partial ⚠️
pkg/spec/gitops.go 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main   #49354    +/-   ##
========================================
  Coverage   67.97%   67.97%            
========================================
  Files        3823     3823            
  Lines      241031   241232   +201     
  Branches    12702    12702            
========================================
+ Hits       163831   163979   +148     
- Misses      62325    62360    +35     
- Partials    14875    14893    +18     
Flag Coverage Δ
backend 69.54% <68.57%> (+<0.01%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 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.

@juan-fdz-hawa
juan-fdz-hawa force-pushed the 38806-extend-to-all-built-in branch from 5171525 to fbbda2f Compare July 15, 2026 18:40
@juan-fdz-hawa
juan-fdz-hawa marked this pull request as ready for review July 15, 2026 18:40
@juan-fdz-hawa
juan-fdz-hawa requested a review from a team as a code owner July 15, 2026 18:40
@juan-fdz-hawa

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4ad7f4ab-496a-4633-a218-c646046ba144

📥 Commits

Reviewing files that changed from the base of the PR and between f2f0d0e and ab955d2.

📒 Files selected for processing (3)
  • cmd/fleetctl/fleetctl/gitops_test.go
  • pkg/spec/gitops.go
  • pkg/spec/spec.go

Walkthrough

Host-name templates now distinguish host-identity and IdP end-user variables. Apple device-name reconciliation resolves IdP values after host fields, while missing data produces delivery failures and datastore errors remain retryable. Secret and SCIM variable changes re-queue affected enforcement records. App-config, team, and GitOps validation paths classify errors and skip validation for unchanged templates. Tests cover resolution, re-enqueueing, global templates, and GitOps behavior.

Possibly related issues

  • fleetdm/fleet issue 49109 — Overlaps with this PR’s global-scope hostname enforcement and re-enqueue behavior.

Possibly related PRs

  • fleetdm/fleet#48690 — Introduced the hostname template validation, resolution, and enforcement flow extended here with IdP variables.
  • fleetdm/fleet#48693 — Added the Apple host-device enforcement datastore surface used for secret- and IdP-driven re-enqueueing.
  • fleetdm/fleet#48793 — Added the reconciliation pipeline that processes enforcement records re-queued by this PR.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 69.23% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is related but too vague to clearly describe the main change. Use a specific title like 'Extend host name templates to support IdP end-user variables and re-enqueue on value changes'.
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The description covers the issue, summarizes the behavior changes, and notes automated testing, so it is mostly complete.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 38806-extend-to-all-built-in

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.

@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

🧹 Nitpick comments (1)
server/service/apple_device_names.go (1)

261-268: 🚀 Performance & Scalability | 🔵 Trivial | ⚖️ Poor tradeoff

Per-host GetEndUsers lookup when the template uses IdP variables.

Unlike the secret expansion above (memoized once per distinct template), this issues one fleet.GetEndUsers datastore call per host whenever the team's template contains an IdP variable — a per-host DB round trip inside the batch loop. Given the batch is capped by reconcileHostDeviceNamesBatchSize and mirrors how profile-side IdP resolution already works per host, this is likely an acceptable tradeoff, but worth keeping in mind if the cron's batch size or IdP-template adoption grows.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@server/service/apple_device_names.go` around lines 261 - 268, No code change
is required: retain the per-host GetEndUsers lookup in the device-name template
flow, as it matches existing profile-side IdP resolution and the bounded batch
size. Avoid introducing memoization or broader refactoring unless future
performance requirements change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@server/datastore/mysql/secret_variables.go`:
- Around line 99-108: The secret writes and resendDeviceNamesForSecretChange
call must execute atomically. Update the surrounding secret-update flow and
resendDeviceNamesForSecretChange to share one transaction-aware helper or
durable retry/outbox mechanism, ensuring a failed requeue cannot commit the
secret changes without preserving the pending device-name requeue for retries.

---

Nitpick comments:
In `@server/service/apple_device_names.go`:
- Around line 261-268: No code change is required: retain the per-host
GetEndUsers lookup in the device-name template flow, as it matches existing
profile-side IdP resolution and the bounded batch size. Avoid introducing
memoization or broader refactoring unless future performance requirements
change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8159a4ab-9ed5-4b59-b286-07c3a2deac43

📥 Commits

Reviewing files that changed from the base of the PR and between 0e78132 and fbbda2f.

📒 Files selected for processing (13)
  • ee/server/service/teams.go
  • server/datastore/mysql/apple_device_names.go
  • server/datastore/mysql/scim.go
  • server/datastore/mysql/secret_variables.go
  • server/datastore/mysql/secret_variables_test.go
  • server/fleet/name_template.go
  • server/fleet/name_template_test.go
  • server/service/appconfig.go
  • server/service/appconfig_test.go
  • server/service/apple_device_names.go
  • server/service/apple_device_names_test.go
  • server/service/apple_mdm_test.go
  • server/service/integration_mdm_test.go

Comment thread server/datastore/mysql/secret_variables.go

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@server/datastore/mysql/apple_device_names.go`:
- Around line 325-330: The SQL regex patterns in
server/datastore/mysql/apple_device_names.go lines 325-330 and
server/datastore/mysql/scim.go lines 1594-1610 must match only actual template
tokens: update the patterns used by the team query and SCIM query to require the
`$` prefix and support both `$FLEET_SECRET_NAME`/`${FLEET_SECRET_NAME}` and
`$FLEET_VAR_NAME`/`${FLEET_VAR_NAME}` forms, respectively, so unrelated literal
text is excluded.

In `@server/service/apple_device_names.go`:
- Around line 270-275: Update the substitution flow around
resolveHostNameIDPValue so all IdP variable values are resolved first, then
apply replacements against the original name template in a single pass; do not
feed each replacement’s output into subsequent substitutions. Preserve existing
error details and return behavior, and add a regression test covering an IdP
value containing syntax for a later variable so that syntax remains literal.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 415948a5-f41a-4608-af49-19ff927a25cf

📥 Commits

Reviewing files that changed from the base of the PR and between 0e78132 and fbbda2f.

📒 Files selected for processing (13)
  • ee/server/service/teams.go
  • server/datastore/mysql/apple_device_names.go
  • server/datastore/mysql/scim.go
  • server/datastore/mysql/secret_variables.go
  • server/datastore/mysql/secret_variables_test.go
  • server/fleet/name_template.go
  • server/fleet/name_template_test.go
  • server/service/appconfig.go
  • server/service/appconfig_test.go
  • server/service/apple_device_names.go
  • server/service/apple_device_names_test.go
  • server/service/apple_mdm_test.go
  • server/service/integration_mdm_test.go

Comment thread server/datastore/mysql/apple_device_names.go
Comment thread server/service/apple_device_names.go

@nulmete nulmete left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM.

Comment on lines +265 to +268
var user *fleet.HostEndUser
if len(users) > 0 && users[0].IdpUserName != "" {
user = &users[0]
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is there a real-world case where a host has more than one end user but this would still always pick the first one?

}
}

// TestModifyAppConfigHostNameTemplateSecretErrors verifies that when the "No team"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is this really "No team"? I might be missing something but I don't see how this test is specific to "No team" 😬

@juan-fdz-hawa
juan-fdz-hawa merged commit 83cef54 into main Jul 16, 2026
46 checks passed
@juan-fdz-hawa
juan-fdz-hawa deleted the 38806-extend-to-all-built-in branch July 16, 2026 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants