Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API endpoint for updating a host's labels #16767

Closed
8 tasks
dherder opened this issue Feb 13, 2024 · 19 comments
Closed
8 tasks

API endpoint for updating a host's labels #16767

dherder opened this issue Feb 13, 2024 · 19 comments
Assignees
Labels
~csa Issue was created by or deemed important by the Customer Solutions Architect. customer-rosner customer-sarahwu #g-endpoint-ops Endpoint ops product group :product Product Design department (shows up on 🦢 Drafting board) :release Ready to write code. Scheduled in a release. See "Making changes" in handbook. story A user story defining an entire feature
Milestone

Comments

@dherder
Copy link
Contributor

dherder commented Feb 13, 2024

Goal

User story
As an IT admin building a Tines automation to receive "group update" webhooks from my Identity Provider (ex. Okta),
I want to hit a Fleet API endpoint to update a host's labels
so that I can target this host with configuration profiles and scheduled queries specific to the IdP group.

Context

Here's a flow chart that describes how would user use new endpoints to add label based on IdP groups.

Changes

Product

  • REST API changes: API design: API endpoint for updating a host's manual labels #16979
    • Errors: Figma link
    • Add labels API returns success If a host already has labels that are specified in the API call
    • Remove labels API returns success if a host doesn't have labels that are specified in the API call
  • Permissions changes: Admin, Maintainer, and GitOps roles should be able to update the host's labels. Team users should be able to update labels for hosts that belong to the teams they are assigned to.
  • Outdated documentation changes: TODO: Article
  • Changes to paid features or tiers: Available for Free and Premium.

Engineering

  • Database schema migrations: TODO
  • Load testing: TODO

ℹ️  Please read this issue carefully and understand it. Pay special attention to UI wireframes, especially "dev notes".

QA

Manual labels do not have a "SQL query", they are set to hosts manually using the new API.
In 4.49.0 we added the UI to create manual labels (previously only possible via fleetctl apply): #17031.

Screenshot 2024-04-18 at 1 04 24 PM
Screenshot 2024-04-18 at 1 04 54 PM

Following are the APIs (to QA) to add/delete a manual label/s to/from a host:

curl -k -v -X POST -H "Authorization: Bearer $TEST_TOKEN" https://localhost:8080/api/latest/fleet/hosts/1/labels -d '{"labels": ["Manually Managed Example"]}'

curl -k -v -X DELETE -H "Authorization: Bearer $TEST_TOKEN" https://localhost:8080/api/latest/fleet/hosts/1/labels -d '{"labels": ["Manually Managed Example"]}'

Expected behavior and error codes are in the Figma link.

Risk assessment

  • Requires load testing: TODO
  • Risk level: Low / High TODO
  • Risk description: TODO

Manual testing steps

  1. Step 1
  2. Step 2
  3. Step 3

Testing notes

Confirmation

  1. Engineer (@____): Added comment to user story confirming successful completion of QA.
  2. QA (@____): Added comment to user story confirming successful completion of QA.
@dherder dherder added :product Product Design department (shows up on 🦢 Drafting board) ~feature fest Will be reviewed at next Feature Fest customer-rosner labels Feb 13, 2024
@noahtalerman
Copy link
Member

other solution would be to cache all the mappings to a yaml file and then apply them in a single config

@dherder this is the best practice.

More context in Slack here (internal): https://fleetdm.slack.com/archives/C02A8BRABB5/p1707832511131959?thread_ts=1707790448.922139&cid=C02A8BRABB5

Happy to chat about this during a call.

Removing this from feature fest for now. Please let me know if the best practice YAML file won't work. I could be wrong.

@noahtalerman noahtalerman removed :product Product Design department (shows up on 🦢 Drafting board) ~feature fest Will be reviewed at next Feature Fest customer-rosner labels Feb 13, 2024
@dherder dherder added customer-rosner ~feature fest Will be reviewed at next Feature Fest labels Feb 13, 2024
@dherder
Copy link
Contributor Author

dherder commented Feb 13, 2024

For purposes of rate limiting calls from Okta, it would be desirable to PATCH from an event detected in Okta to Tines (or some other automation tool), then to Fleet. @noahtalerman fyi

@noahtalerman noahtalerman added the story A user story defining an entire feature label Feb 15, 2024
@noahtalerman noahtalerman changed the title Add PATCH for updating manual labels API endpoint for updating a host's manual labels Feb 15, 2024
@noahtalerman noahtalerman added customer-sarahwu :product Product Design department (shows up on 🦢 Drafting board) and removed ~feature fest Will be reviewed at next Feature Fest labels Feb 16, 2024
@noahtalerman
Copy link
Member

Original issue description from @dherder:

Documentation for applying manual labels: https://github.com/fleetdm/fleet/blob/main/docs/Contributing/API-for-contributors.md#apply-labels

There is no way to PATCH or DELETE to an existing label, which means a CPE will have to enumerate all hosts when sync'ing IdP groups to labels. In the workflow described in #15633, updating will be mandatory.

Problem

Need to support PATCH and DELETE to https://github.com/fleetdm/fleet/blob/main/docs/Contributing/API-for-contributors.md#apply-labels

@dherder
Copy link
Contributor Author

dherder commented Feb 21, 2024

@noahtalerman and @marko-lisica do you think we would also be able to modify the labels with fields like serial_number, uuid, host_id? Feedback from prospect-rosner is that using hostname is pretty fragile, as hostnames can change quite frequently.

@marko-lisica
Copy link
Member

@noahtalerman and @marko-lisica do you think we would also be able to modify the labels with fields like serial_number, uuid, host_id? Feedback from prospect-rosner is that using hostname is pretty fragile, as hostnames can change quite frequently.

Hey @dherder, thanks for raising this. I think this is very good feedback. I discussed this with @noahtalerman, and we think this should be a separate story. Here's the feature request: #17031

@noahtalerman noahtalerman changed the title API endpoint for updating a host's manual labels API endpoint for updating a host's labels Feb 22, 2024
@noahtalerman
Copy link
Member

Hey @marko-lisica, it looks like the current Create label only supports dynamic (query based) labels.

Is that right? Is there no way to create a manual label via an endpoint in the user facing docs?

(I know we have an endpoint for fleetctl in the contributor docs)

@marko-lisica
Copy link
Member

Hey @marko-lisica, it looks like the current Create label only supports dynamic (query based) labels.

Is that right? Is there no way to create a manual label via an endpoint in the user facing docs?

(I know we have an endpoint for fleetctl in the contributor docs)

As far as I know, it's only possible to create manual label through POST /api/v1/fleet/spec/labels

@noahtalerman
Copy link
Member

Hey @marko-lisica your "New employee hired" flow makes sense to me! I think we can move this issue to "Settled."

You're right that Fleet doesn't have a webhook for this yet:
Screenshot 2024-02-27 at 6 19 57 PM

This is tracked in a feature request here: #14722

Sending webhooks at enrollment time is core to Fleet (play nice w/ other tools). We'll weigh it at the upcoming feature fest.

cc @n8felton @dherder

@noahtalerman
Copy link
Member

@marko-lisica when you get the chance, can you please add the link to the Figma page w/ your workflows?

This way, other contributors can check them out to understand the full flow.

A good spot for that could be the "Context" section of the issue.

@georgekarrv georgekarrv added the #g-mdm MDM product group label Feb 28, 2024
@georgekarrv
Copy link
Member

@sharon-fdm sharon-fdm added #g-endpoint-ops Endpoint ops product group and removed #g-mdm MDM product group labels Mar 11, 2024
@sharon-fdm sharon-fdm assigned lucasmrod and unassigned georgekarrv Mar 11, 2024
@sharon-fdm sharon-fdm added :release Ready to write code. Scheduled in a release. See "Making changes" in handbook. and removed :product Product Design department (shows up on 🦢 Drafting board) labels Mar 11, 2024
@lukeheath lukeheath added this to the 4.48.0-tentative milestone Mar 11, 2024
@noahtalerman
Copy link
Member

noahtalerman commented Apr 1, 2024

Hey @dherder, heads up, this feature won't make it into the upcoming 4.48 release.

Plan is to ship this in the 4.49 release.

cc @georgekarrv Whoops meant to tag @sharon-fdm

@noahtalerman
Copy link
Member

FYI @Patagonia121 ^

@noahtalerman
Copy link
Member

this feature won't make it into the upcoming 4.48 release.

Plan is to ship this in the 4.49 release.

Also, FYI @spokanemac for the release article.

@georgekarrv
Copy link
Member

#18268 This is the ticket we have for MDM this sprint, did we duplicate work needlessly?

@georgekarrv
Copy link
Member

On the surface they sounds the same. I could be wrong though

lucasmrod added a commit that referenced this issue Apr 16, 2024
#16767

To create a manual label:
```sh
cat labels.yml
---
apiVersion: v1
kind: label
spec:
  name: Manually Managed Example
  label_membership_type: manual
  hosts:
    - lucass-macbook-pro.local
```

To add/delete a manual label to/from a host:
```
curl -k -v -X POST -H "Authorization: Bearer $TEST_TOKEN" https://localhost:8080/api/latest/fleet/hosts/1/labels -d '{"labels": ["Manually Managed Example"]}'

curl -k -v -X DELETE -H "Authorization: Bearer $TEST_TOKEN" https://localhost:8080/api/latest/fleet/hosts/1/labels -d '{"labels": ["Manually Managed Example"]}'
```

API draft changes: https://github.com/fleetdm/fleet/pull/16979/files
Figma with error strings:
https://www.figma.com/file/JiWoAiuHlkt76s3o3Uyz6h/%2316767-API-endpoint-for-updating-a-host's-manual-labels?type=design&node-id=2-130&mode=design&t=pxRPhrn6E1bOCrEd-0

- [X] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [X] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
~- [ ] Added support on fleet's osquery simulator `cmd/osquery-perf` for
new osquery data ingestion features.~
- [X] Added/updated tests
- ~[ ] If database migrations are included, checked table schema to
confirm autoupdate~
- ~For database migrations:~
- ~[ ] Checked schema for all modified table for columns that will
auto-update timestamps during migration.~
- ~[ ] Confirmed that updating the timestamps is acceptable, and will
not cause unwanted side effects.~
- ~[ ] Ensured the correct collation is explicitly set for character
columns (`COLLATE utf8mb4_unicode_ci`).~
- [x] Manual QA for all new/changed functionality
  - ~For Orbit and Fleet Desktop changes:~
- ~[ ] Manual QA must be performed in the three main OSs, macOS, Windows
and Linux.~
- ~[ ] Auto-update manual QA, from released version of component to new
version (see [tools/tuf/test](../tools/tuf/test/README.md)).~
@lucasmrod
Copy link
Member

@xpkoala I've added QA notes to the description.

@nonpunctual nonpunctual added ~csa Issue was created by or deemed important by the Customer Solutions Architect. ~feature fest Will be reviewed at next Feature Fest labels Apr 22, 2024
@lukeheath lukeheath added :product Product Design department (shows up on 🦢 Drafting board) #g-endpoint-ops Endpoint ops product group and removed ~feature fest Will be reviewed at next Feature Fest #g-endpoint-ops Endpoint ops product group labels Apr 24, 2024
@rachaelshaw
Copy link
Member

@dherder @Patagonia121 this was shipped in v4.49.0

@rachaelshaw
Copy link
Member

PR to the docs is here: #16979

rachaelshaw added a commit that referenced this issue Apr 25, 2024
API design for: 
- #16767

---------

Co-authored-by: Rachael Shaw <r@rachael.wtf>
@fleet-release
Copy link
Contributor

API endpoint blooms,
Labels adjust with ease, like
Clouds in glass cities.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
~csa Issue was created by or deemed important by the Customer Solutions Architect. customer-rosner customer-sarahwu #g-endpoint-ops Endpoint ops product group :product Product Design department (shows up on 🦢 Drafting board) :release Ready to write code. Scheduled in a release. See "Making changes" in handbook. story A user story defining an entire feature
Projects
None yet
Development

No branches or pull requests

10 participants