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

add premium, device authed endpoint to retrieve policies #5967

Merged
merged 10 commits into from
May 31, 2022

Conversation

roperzh
Copy link
Contributor

@roperzh roperzh commented May 30, 2022

This adds a new device authenticated endpoint, /api/_version_/fleet/device/{token}/policies to retrieve the device policies.

An example request / response looks like:

curl  https://localhost:8080/api/latest/fleet/device/1804e808-171f-4dda-9bec-f695b2f2371a/policies
{
  "policies": [
    {
      "id": 3,
      "name": "Antivirus healthy (Linux)",
      "query": "SELECT score FROM (SELECT case when COUNT(*) = 2 then 1 ELSE 0 END AS score FROM processes WHERE (name = 'clamd') OR (name = 'freshclam')) WHERE score == 1;",
      "description": "Checks that both ClamAV's daemon and its updater service (freshclam) are running.",
      "author_id": 1,
      "author_name": "Admin",
      "author_email": "[email protected]",
      "team_id": null,
      "resolution": "Ensure ClamAV and Freshclam are installed and running.",
      "platform": "darwin,windows,linux",
      "created_at": "2022-05-23T20:53:36Z",
      "updated_at": "2022-05-23T20:53:36Z",
      "response": "fail"
    }
  ]
}

Related to #5685, in another changeset I will be adding "client" endpoints so we can consume this endpoint from Fleet Desktop

Checklist for submitter

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

  • Changes file added for user-visible changes (in changes/ and/or orbit/changes/).
  • Documented any API changes (docs/Using-Fleet/REST-API.md)
  • Ensured that input data is properly validated, SQL injection is prevented (using placeholders for values in statements)
  • Added/updated tests
  • Manual QA for all new/changed functionality

@roperzh roperzh requested a review from a team as a code owner May 30, 2022 21:55
@roperzh roperzh requested a review from ksatter as a code owner May 30, 2022 21:56
@roperzh roperzh temporarily deployed to Docker Hub May 30, 2022 21:56 Inactive
docs/Using-Fleet/REST-API.md Outdated Show resolved Hide resolved
michalnicp
michalnicp previously approved these changes May 30, 2022
@codecov-commenter
Copy link

codecov-commenter commented May 30, 2022

Codecov Report

Merging #5967 (934530a) into main (9798e6a) will increase coverage by 0.09%.
The diff coverage is 76.47%.

@@            Coverage Diff             @@
##             main    #5967      +/-   ##
==========================================
+ Coverage   58.66%   58.75%   +0.09%     
==========================================
  Files         362      362              
  Lines       33690    33671      -19     
==========================================
+ Hits        19764    19785      +21     
+ Misses      11969    11927      -42     
- Partials     1957     1959       +2     
Impacted Files Coverage Δ
server/datastore/mysql/policies.go 74.05% <50.00%> (-0.63%) ⬇️
server/datastore/mysql/hosts.go 81.44% <72.22%> (+0.07%) ⬆️
...20220524102918_CleanupOrphanedPolicyMemberships.go 73.68% <73.68%> (ø)
server/service/devices.go 55.76% <80.00%> (+5.76%) ⬆️
server/datastore/mysql/software.go 83.41% <100.00%> (+0.10%) ⬆️
server/service/handler.go 82.69% <100.00%> (+0.03%) ⬆️
server/service/osquery_utils/queries.go 35.66% <0.00%> (ø)
orbit/pkg/database/database.go
server/service/osquery.go 72.60% <0.00%> (+0.14%) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6dddfbb...934530a. Read the comment docs.

juan-fdz-hawa
juan-fdz-hawa previously approved these changes May 31, 2022
Copy link
Member

@lucasmrod lucasmrod left a comment

Choose a reason for hiding this comment

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

Looks good, left one comment.

ee/server/service/devices.go Outdated Show resolved Hide resolved
@roperzh roperzh dismissed stale reviews from juan-fdz-hawa and michalnicp via 4bb35e4 May 31, 2022 13:57
@roperzh roperzh temporarily deployed to Docker Hub May 31, 2022 13:57 Inactive
@roperzh roperzh temporarily deployed to Docker Hub May 31, 2022 14:07 Inactive
@lucasmrod lucasmrod self-requested a review May 31, 2022 14:52
Copy link
Member

@lucasmrod lucasmrod left a comment

Choose a reason for hiding this comment

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

@roperzh roperzh temporarily deployed to Docker Hub May 31, 2022 17:18 Inactive
@roperzh roperzh requested a review from lucasmrod May 31, 2022 17:20
res.Body.Close()
require.Len(t, listDevicePoliciesResp.Policies, 2)
require.NoError(t, listDevicePoliciesResp.Err)
}
Copy link
Member

Choose a reason for hiding this comment

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

Great test!

@roperzh roperzh merged commit eb8defd into main May 31, 2022
@roperzh roperzh deleted the devices-policies-endpoint branch May 31, 2022 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants