fleet/server/datastore/mysql
Scott Gress fca1e1ab42
Add GitOps for policy labels (#27781)
For #27301 

# Checklist for submitter

<!-- Note that API documentation changes are now addressed by the
product design team. -->

- [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/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)
- [X] Added/updated automated tests
- [X] A detailed QA plan exists on the associated ticket (if it isn't
there, work with the product group's QA engineer to add it)
- [X] Manual QA for all new/changed functionality

# Details

This PR adds the ability to set/unset labels on policies via GitOps. It
builds on https://github.com/fleetdm/fleet/pull/27575 (back end for
policy labels) and updates the `PolicySpec` type and `ApplyPolicySpecs`
methods to update the `policy_labels` table where needed.

## Testing

1. Create a few labels in the UI
1. Create a global policy "foo" in the UI without labels
2. Create a global policy "bar" in the UI with labels
2. Create a global policy "baz" in the UI with labels
4. Use `fleetctl gitops` with a global .yml file, and under `policies:`
add "foo", "bar", "baz" and "boop".
  * Add labels to "foo" with `labels_include_any:`
  * Don't add `labels_include_any:` to "bar"
* Add labels to "baz" with `labels_include_any:`, but different labels
than what you added in the UI
  * Add labels to "boop" with `labels_include_any:`

The expected outcome when viewing the queries in the UI (on the "edit
query" screen)
* Foo, Baz and Boop should have the labels specified in gitops
* Bar should have no labels

Repeat testing with _excluded_ labels.

---------

Co-authored-by: dantecatalfamo <dante.catalfamo@gmail.com>
Co-authored-by: Dante Catalfamo <43040593+dantecatalfamo@users.noreply.github.com>
2025-04-04 09:46:51 -05:00
..
common_mysql Basic Android enroll functionality (#26386) 2025-02-24 14:31:21 -06:00
migrations Add more test coverage for Fleet-maintained apps (#27722) 2025-04-03 09:18:27 -05:00
activities.go Cancel upcoming activities: DB schema and backend (#27710) 2025-04-01 14:08:56 -04:00
activities_test.go Upcoming Activities feature branch (#25450) 2025-02-11 14:53:11 -05:00
aggregated_stats.go Updating golangci-lint to 1.61.0 (#22973) 2024-10-18 12:38:26 -05:00
aggregated_stats_test.go
android.go Refactoring Android datastore interface (#26982) 2025-03-13 14:28:52 -05:00
android_test.go Refactoring Android datastore interface (#26982) 2025-03-13 14:28:52 -05:00
app_configs.go Update to Go 1.24.1 (#27506) 2025-03-31 11:14:09 -05:00
app_configs_test.go Include Linux disk encryption status in configuration profiles aggregate status response when applicable, fix disk encryption/MDM configuration order-of-operations issues, add integration tests for LUKS (#24114) 2024-11-25 08:34:43 -06:00
apple_mdm.go Bugfix: support removing labels associated with profiles (custom settings) in gitops (#27546) 2025-03-31 11:42:43 -04:00
apple_mdm_test.go Bugfix: support removing labels associated with profiles (custom settings) in gitops (#27546) 2025-03-31 11:42:43 -04:00
ca_config_assets.go Add custom SCEP configs (#27045) 2025-03-14 12:16:51 -05:00
ca_config_assets_test.go Add custom SCEP configs (#27045) 2025-03-14 12:16:51 -05:00
calendar_events.go Enable staticcheck Go linter. (#23487) 2024-11-05 11:16:24 -06:00
calendar_events_test.go Correctly handle NULL timezones (#20605) 2024-07-22 10:04:29 -07:00
campaigns.go Updating golangci-lint to 1.61.0 (#22973) 2024-10-18 12:38:26 -05:00
campaigns_test.go Updating golangci-lint to 1.61.0 (#22973) 2024-10-18 12:38:26 -05:00
carves.go Updating golangci-lint to 1.61.0 (#22973) 2024-10-18 12:38:26 -05:00
carves_test.go
config.go Refactoring common mysql (#26367) 2025-02-18 15:28:54 -06:00
cron_stats.go Monitor and alert on errors in cron jobs (#24347) 2024-12-19 15:55:29 -06:00
cron_stats_test.go Monitor and alert on errors in cron jobs (#24347) 2024-12-19 15:55:29 -06:00
delete.go Updating golangci-lint to 1.61.0 (#22973) 2024-10-18 12:38:26 -05:00
delete_test.go
disk_encryption.go Disk encryption keys are now archived when created/updated (#25638) 2025-01-22 14:54:40 -06:00
disk_encryption_test.go Disk encryption keys are now archived when created/updated (#25638) 2025-01-22 14:54:40 -06:00
email_changes.go
email_changes_test.go
errors.go Refactoring common mysql (#26367) 2025-02-18 15:28:54 -06:00
fulltext.go Update to Go 1.24.1 (#27506) 2025-03-31 11:14:09 -05:00
fulltext_test.go
host_certificates.go CHV: implement paginated list certificates endpoints (#26554) 2025-02-24 12:52:39 -05:00
host_certificates_test.go Add datastore methods for host certificates feature (#26416) 2025-02-18 17:49:02 -06:00
hosts.go Custom targets for policies - backend (#27575) 2025-04-02 12:36:03 -04:00
hosts_test.go Bugfix: ignore Linux hosts in disk encryption stats and filters if disk encryption is disabled (#27187) 2025-03-18 08:36:38 -04:00
invites.go Allow opting in users to email verification on login (#24273) 2024-12-05 08:37:10 -06:00
invites_test.go Allow opting in users to email verification on login (#24273) 2024-12-05 08:37:10 -06:00
jobs.go Updating golangci-lint to 1.61.0 (#22973) 2024-10-18 12:38:26 -05:00
jobs_test.go Send DeviceConfigured MDM command after DEP enrollment (#17737) 2024-03-25 13:25:29 -04:00
labels.go Add author ID to labels (#27055) 2025-03-20 16:05:16 -05:00
labels_test.go Add author ID to labels (#27055) 2025-03-20 16:05:16 -05:00
linux_mdm.go Linux OS settings + disk encryption host filter fixes (#24200) 2024-11-26 19:26:22 -06:00
linux_mdm_test.go Disk encryption keys are now archived when created/updated (#25638) 2025-01-22 14:54:40 -06:00
locks.go Optimize software_titles query to use indexes (#25722) 2025-01-23 15:48:21 -03:00
locks_test.go Improvements for select next Apple MDM command query. (#24128) 2024-12-05 12:02:48 -06:00
maintained_apps.go Update FMA refreshing logic to remove apps that were removed upstream (#27594) 2025-03-28 14:04:08 -04:00
maintained_apps_test.go Add more test coverage for Fleet-maintained apps (#27722) 2025-04-03 09:18:27 -05:00
mdm.go Bugfix: support removing labels associated with profiles (custom settings) in gitops (#27546) 2025-03-31 11:42:43 -04:00
mdm_test.go Bugfix: support removing labels associated with profiles (custom settings) in gitops (#27546) 2025-03-31 11:42:43 -04:00
microsoft_mdm.go Bugfix: support removing labels associated with profiles (custom settings) in gitops (#27546) 2025-03-31 11:42:43 -04:00
microsoft_mdm_test.go Resend Windows profiles on change (#27308) 2025-03-20 14:43:04 -05:00
migrations_test.go Refactoring common mysql (#26367) 2025-02-18 15:28:54 -06:00
mysql.go Refactoring Android datastore interface (#26982) 2025-03-13 14:28:52 -05:00
mysql_test.go Refactoring common mysql (#26367) 2025-02-18 15:28:54 -06:00
nanomdm_storage.go Bugfix: Clear the unified queue when turning off and re-enrolling in MDM (#26816) 2025-03-05 08:59:07 -05:00
nanomdm_storage_test.go 19016 ingest certs on start (#19360) 2024-05-30 18:18:42 -03:00
operating_system_vulnerabilities.go Add gosimple linter (#23250) 2024-10-29 14:17:51 -05:00
operating_system_vulnerabilities_test.go Profiles batch activity (#21604) 2024-08-30 16:00:35 -05:00
operating_systems.go Android scaffold (#26274) 2025-02-13 14:32:19 -06:00
operating_systems_test.go Updating golangci-lint to 1.61.0 (#22973) 2024-10-18 12:38:26 -05:00
packs.go Updating golangci-lint to 1.61.0 (#22973) 2024-10-18 12:38:26 -05:00
packs_test.go Enable staticcheck Go linter. (#23487) 2024-11-05 11:16:24 -06:00
password_reset.go Updating golangci-lint to 1.61.0 (#22973) 2024-10-18 12:38:26 -05:00
password_reset_test.go Updating golangci-lint to 1.61.0 (#22973) 2024-10-18 12:38:26 -05:00
policies.go Add GitOps for policy labels (#27781) 2025-04-04 09:46:51 -05:00
policies_test.go Add GitOps for policy labels (#27781) 2025-04-04 09:46:51 -05:00
queries.go Add labels to queries using gitops (#27259) 2025-03-20 15:32:52 -05:00
queries_test.go Add labels to queries using gitops (#27259) 2025-03-20 15:32:52 -05:00
query_results.go Added server_settings.query_report_cap (#19692) 2024-06-14 12:24:01 -03:00
query_results_test.go Added server_settings.query_report_cap (#19692) 2024-06-14 12:24:01 -03:00
scep.go 19016 ingest certs on start (#19360) 2024-05-30 18:18:42 -03:00
scep_test.go use Fleet instead of FleetDM in certificates (#19748) 2024-06-14 11:08:49 -03:00
scheduled_queries.go Update to Go 1.24.1 (#27506) 2025-03-31 11:14:09 -05:00
scheduled_queries_test.go
schema.sql Custom targets for policies - backend (#27575) 2025-04-02 12:36:03 -04:00
scim.go Add SCIM Groups (#27702) 2025-04-02 17:10:40 -05:00
scim_test.go Add SCIM Groups (#27702) 2025-04-02 17:10:40 -05:00
scripts.go Switch Fleet-maintained apps to use manifest-based structure (#27201) 2025-03-20 21:21:56 -05:00
scripts_test.go Android: compute MDM enrollment stats (#26854) 2025-03-05 15:47:06 -05:00
secret_variables.go Update Apple config/DDM profiles if secret variables changed (#24995) 2024-12-30 17:58:39 -06:00
secret_variables_test.go Update Apple config/DDM profiles if secret variables changed (#24995) 2024-12-30 17:58:39 -06:00
sessions.go Include expiration info, drop "personalized", in MFA email (#24630) 2024-12-10 18:58:40 -06:00
sessions_test.go Include expiration info, drop "personalized", in MFA email (#24630) 2024-12-10 18:58:40 -06:00
setup_experience.go feat: do not run setup experience on hosts in a team with no software or script configured (#24073) 2024-11-22 13:52:28 -05:00
setup_experience_test.go SSVL: Add labels to upload endpoint; add validations and related datastore methods (#24733) 2024-12-16 18:17:13 -06:00
software.go Filter out pending software on VulnerableOnly (#27859) 2025-04-03 15:52:45 -05:00
software_installers.go Switch Fleet-maintained apps to use manifest-based structure (#27201) 2025-03-20 21:21:56 -05:00
software_installers_test.go Switch Fleet-maintained apps to use manifest-based structure (#27201) 2025-03-20 21:21:56 -05:00
software_test.go Filter pending installs/uninstalls for vulnerabilities (#27752) 2025-04-02 17:04:52 -05:00
software_titles.go Batched selectSoftwareVersionsSQL (#27361) 2025-03-20 16:47:24 -05:00
software_titles_test.go Batched selectSoftwareVersionsSQL (#27361) 2025-03-20 16:47:24 -05:00
statistics.go Added statistics for number of saved queries. (#24043) 2024-11-22 11:24:29 -05:00
statistics_test.go Allow opting in users to email verification on login (#24273) 2024-12-05 08:37:10 -06:00
targets.go Updating golangci-lint to 1.61.0 (#22973) 2024-10-18 12:38:26 -05:00
targets_test.go Updating golangci-lint to 1.61.0 (#22973) 2024-10-18 12:38:26 -05:00
teams.go Updating golangci-lint to 1.61.0 (#22973) 2024-10-18 12:38:26 -05:00
teams_test.go Enable staticcheck Go linter. (#23487) 2024-11-05 11:16:24 -06:00
testing_utils.go Bugfix: re-create deleted iOS/iPadOS host entries in Fleet if it checks in again via MDM (#27231) 2025-03-26 09:33:38 -04:00
unicode_test.go Bugfix: only count hosts that user has permission to see in count field of label endpoints (#18859) 2024-05-21 12:02:08 -04:00
users.go Added Android activity and better handling of deleted users. (#26640) 2025-02-27 14:19:15 -06:00
users_test.go Added Android activity and better handling of deleted users. (#26640) 2025-02-27 14:19:15 -06:00
vpp.go fix: don't re-use title ID from a windows app for a vpp app (#26546) 2025-02-24 17:51:12 -05:00
vpp_test.go fix: don't re-use title ID from a windows app for a vpp app (#26546) 2025-02-24 17:51:12 -05:00
vulnerabilities.go Adjust vuln host count batch size (#25957) 2025-01-31 16:49:36 -07:00
vulnerabilities_test.go Refactoring common mysql (#26367) 2025-02-18 15:28:54 -06:00
windows_updates.go
windows_updates_test.go Updating golangci-lint to 1.61.0 (#22973) 2024-10-18 12:38:26 -05:00
wstep.go
wstep_test.go