Repository navigation
Add macos custom profiles support via fleetctl apply - #9824
Conversation
…alidate payload fields
|
|
||
| ##### Default response | ||
|
|
||
| `200` // TODO: should that be 204 no content? |
There was a problem hiding this comment.
^ Any thoughts here? Is there something useful that this could return, or should it return 204? Haven't looked much into it, I'm not sure how easy it is to change the status code of a success response.
There was a problem hiding this comment.
besides the IDs of the profiles (which doesn't seem useful) I can't think of anything else to return 🤔
as for setting the status I have seen (but never used) this before:
fleet/server/service/transport.go
Lines 46 to 51 in 5f19f0b
There was a problem hiding this comment.
Thanks, I'll use that, I think StatusNoContent would be a bit nicer.
| } | ||
|
|
||
| func (svc *Service) BatchSetMDMAppleProfiles(ctx context.Context, tmID *uint, tmName *string, profiles [][]byte, dryRun bool) error { | ||
| if !svc.config.MDMApple.Enable { |
There was a problem hiding this comment.
For now I required that this was set. As commented below, I suspect this will become just a check that APNs is configured when we remove the feature flag.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #9824 +/- ##
==========================================
+ Coverage 60.58% 60.66% +0.07%
==========================================
Files 492 492
Lines 49293 49732 +439
==========================================
+ Hits 29865 30169 +304
- Misses 16641 16763 +122
- Partials 2787 2800 +13 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
roperzh
left a comment
There was a problem hiding this comment.
LGTM, I like how easy to follow BatchSetMDMAppleProfiles despite its inherent complexity.
| ` | ||
| expectedJson := `{"kind":"team","apiVersion":"v1","spec":{"team":{"id":42,"created_at":"1999-03-10T02:45:06.371Z","name":"team1","description":"team1 description","webhook_settings":{"failing_policies_webhook":{"enable_failing_policies_webhook":false,"destination_url":"","policy_ids":null,"host_batch_size":0}},"integrations":{"jira":null,"zendesk":null},"features":{"enable_host_users":true,"enable_software_inventory":true},"mdm":{"macos_updates":{"minimum_version":"","deadline":""}},"user_count":99,"host_count":42}}} | ||
| {"kind":"team","apiVersion":"v1","spec":{"team":{"id":43,"created_at":"1999-03-10T02:45:06.371Z","name":"team2","description":"team2 description","agent_options":{"config":{"foo":"bar"},"overrides":{"platforms":{"darwin":{"foo":"override"}}}},"webhook_settings":{"failing_policies_webhook":{"enable_failing_policies_webhook":false,"destination_url":"","policy_ids":null,"host_batch_size":0}},"integrations":{"jira":null,"zendesk":null},"features":{"enable_host_users":false,"enable_software_inventory":false,"additional_queries":{"foo":"bar"}},"mdm":{"macos_updates":{"minimum_version":"12.3.1","deadline":"2021-12-14"}},"user_count":87,"host_count":43}}} | ||
| expectedJson := `{"kind":"team","apiVersion":"v1","spec":{"team":{"id":42,"created_at":"1999-03-10T02:45:06.371Z","name":"team1","description":"team1 description","webhook_settings":{"failing_policies_webhook":{"enable_failing_policies_webhook":false,"destination_url":"","policy_ids":null,"host_batch_size":0}},"integrations":{"jira":null,"zendesk":null},"features":{"enable_host_users":true,"enable_software_inventory":true},"mdm":{"macos_updates":{"minimum_version":"","deadline":""}},"macos_settings":{"custom_settings":null},"user_count":99,"host_count":42}}} |
There was a problem hiding this comment.
rant: curious if this test (and others in this file) is as annoying to you as it is to me to modify. Obviously not for now! but I have seen we use golden files for other tests, I wonder if we're at the same point here.
There was a problem hiding this comment.
Yeah eventually we should make them all golden files, nicer to maintain!
|
|
||
| ##### Default response | ||
|
|
||
| `200` // TODO: should that be 204 no content? |
There was a problem hiding this comment.
besides the IDs of the profiles (which doesn't seem useful) I can't think of anything else to return 🤔
as for setting the status I have seen (but never used) this before:
fleet/server/service/transport.go
Lines 46 to 51 in 5f19f0b
| svc.authz.SkipAuthorization(ctx) // so that the error message is not replaced by "forbidden" | ||
| return ctxerr.Wrap(ctx, fleet.NewInvalidArgumentError("team_name", "cannot specify both team_id and team_name")) | ||
| } | ||
| if tmID != nil || tmName != nil { |
There was a problem hiding this comment.
my understanding is that technically we would do something on the lines of if tmID != nil || tmName != nil { return missingLicenseError } and handle all the stuff to load the team in /ee.
the underlying reason for the premium code to be isolated in /ee is just so the license can be enforced from a legal standpoint.
given the time constraint and how difficult it is to deal with separating stuff that way I'd vote to keep this as-is and revisit later. (we're doing this check in some other places either way)
There was a problem hiding this comment.
the underlying reason for the premium code to be isolated in /ee is just so the license can be enforced from a legal standpoint.
Oh I didn't know that! I did something similar to the validations of premium stuff in the modify appconfig endpoint.
I'd vote to keep this as-is and revisit later.
Yeah if that's acceptable, I'd do that too. Not quite sure how it'd go to separate just the team-loading part in ee/, it'd probably not feel super natural.
There was a problem hiding this comment.
thinking out loud: one possibility is to split this method into two service methods, one that handles loading the team and another for the proper profile stuff that receives a team as a paramete
addressing this post-mvp sounds good to me.
There was a problem hiding this comment.
Yeah that's a good idea, I'll give it a shot see if it's not too big a change, otherwise I'll leave it like that for now.
| if err := c.ApplyTeamProfiles(tmName, profs, opts); err != nil { | ||
| return fmt.Errorf("applying custom settings for team %q: %w", tmName, err) | ||
| } |
There was a problem hiding this comment.
I wonder: if this fails, should we clean the list of profiles from the team config JSON? (same for appConfig for the no-team case)
There was a problem hiding this comment.
(in the database I mean: since we have already applied the team specs)
There was a problem hiding this comment.
That's a possibility, those are two distinct, non-atomic operations so they may fail separately, but I wouldn't go out of my way to try and handle this edge case as there's no way to "win", i.e. the next call to clean the list of profiles may fail, and then what? There are many such non-atomic operations throughout the codebase - activities are created outside of the associated action and may fail separately, applying team specs apply each team separately, it may apply one and fail on the second, we don't "undo" the first applied team even though the fleetctl apply operation did fail, etc.
I'd suggest that we leave it like that, maybe to revisit later after the MDM initial release but I'd say this is a larger discussion than this specific case.
There was a problem hiding this comment.
thanks! that makes sense to me.
…more validations checked on apply teams dry run
#9587
Checklist for submitter
If some of the following don't apply, delete the relevant line.
changes/ororbit/changes/.See Changes files for more information.
SELECT *is avoided, SQL injection is prevented (using placeholders for values in statements)fleetctl applytested manually)