fleetdm / fleet

Open-source platform for IT, security, and infrastructure teams. (Linux, macOS, Chrome, Windows, cloud, data center)
https://fleetdm.com
Other
3.01k stars 418 forks source link

POST /api/v1/fleet/mdm/apple/profiles/batch for Team returning HTTP-403 with Team Admin User API Token #11419

Closed jrreed closed 1 year ago

jrreed commented 1 year ago

Fleet version: 4.30.1

Operating system: macOS 12.6

Web browser: Chrome 112.0.5615.137


🧑‍💻  Expected behavior

Issuing a POST /api/v1/fleet/mdm/apple/profiles/batch API with:

should result in an HTTP-2XX response

💥  Actual behavior

API responds with an HTTP-403 and the following JSON in the response body:

{
  "message": "forbidden",
  "errors": [
    {
      "name": "base",
      "reason": "forbidden"
    }
  ],
  "uuid": "70ab5d55-45e9-4b35-b885-f8a9ac719127"
}

👣 Reproduction steps

More info

Hi!

I'm currently implementing a service to bootstrap and sync Apple MDM configuration profiles across our Fleet Team records using the Batch-apply Apple MDM custom settings API.

Our current implementation pairs each Team record with a dedicated API-only 'admin' User record. All API requests for a Team are issued using the API token from that Team's dedicated API-only 'admin' User record.

I can get a successful HTTP-2XX response from the server if I use an API token for a Global 'admin' User, but it doesn't appear to be creating the profiles because when I then attempt to retrieve the profiles I just created I get an empty list.

I'm not quite sure what I'm doing wrong...

I don't think it's a problem with the Base64 encoded profiles because I can create Apple MDM configuration profiles with the same files, but using the Add custom macOS setting API instead:

POST /api/v1/fleet/mdm/apple/profiles

I don't think it's a problem with the dedicated API-only 'admin' User record for the Team because I can make other Team specific API requests using the dedicated API-only 'admin' User API token and get receive expected successful results.

Any help would be much appreciated.

Thanks in advance!

jrreed commented 1 year ago

Sorry, I did not read the API docs correctly.

So the issue here was that I was submitting the request with the team_id as a field in the request body, which the API was just ignoring because it's supposed to be a query param.

Altering the request to submit the team_id as a query param resolved the issue, which is documented in the API correctly -- thats my fault, sorry 🤦

POST https://harmonize-stg.cloud.fleetdm.com/api/v1/fleet/mdm/apple/profiles/batch?team_id=<TEAM_ID>

The HTTP-403 was because the server thought my dedicated API-only 'admin' User for a Team was trying to create global profiles, which it was not authorized to do because it did not have global 'admin' permissions.

Perhaps a couple suggestions:

fleet-release commented 1 year ago

Forbidden no more, Profiles batched as they soar, Cloud city endures.