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 an endpoint to get an aggregate summary of bootstrap packages #11156

Merged
merged 28 commits into from
Apr 22, 2023

Conversation

roperzh
Copy link
Contributor

@roperzh roperzh commented Apr 11, 2023

Related to #10934

Checklist for submitter

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

  • Documented any API changes (docs/Using-Fleet/REST-API.md or docs/Contributing/API-for-contributors.md)
  • Input data is properly validated, SELECT * is avoided, SQL injection is prevented (using placeholders for values in statements)
  • Added/updated tests
  • Manual QA for all new/changed functionality

@roperzh roperzh requested review from ksatter, lukeheath and a team as code owners April 11, 2023 22:31
@roperzh roperzh temporarily deployed to Docker Hub April 11, 2023 22:31 — with GitHub Actions Inactive
Comment on lines 14 to 20
CREATE TABLE host_mdm_apple_bootstrap_packages (
host_uuid varchar(127) NOT NULL,
command_uuid varchar(127) NOT NULL,

PRIMARY KEY (host_uuid, command_uuid),
FOREIGN KEY (command_uuid) REFERENCES nano_commands (command_uuid) ON DELETE CASCADE
)`)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mna @gillespi314 I'm not sure if this table is the right approach, do we want a more general "fleet commands" table? this table would still need a column with a flag/enum we can use to distinguish which commands are related to bootstrap packages.

up to you!

Copy link
Member

Choose a reason for hiding this comment

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

Hmm yeah good question, this is the only command that we need this for at the moment, right? The disk encryption profile is also treated a bit as a special case, but it does not need something like this AFAIR? Given that this is the first need for this, it could make sense to use it like you proposed, and rename it to something more general if and when we need something similar for other "special commands"?

@roperzh roperzh temporarily deployed to Docker Hub April 11, 2023 23:16 — with GitHub Actions Inactive
@roperzh roperzh temporarily deployed to Docker Hub April 11, 2023 23:16 — with GitHub Actions Inactive
docs/Using-Fleet/REST-API.md Outdated Show resolved Hide resolved
docs/Using-Fleet/REST-API.md Outdated Show resolved Hide resolved
"name": "bootstrap-package.pkg",
"team_id": 0,
"sha256": "6bebb4433322fd52837de9e4787de534b4089ac645b0692dfb74d000438da4a3",
"token": "AA598E2A-7952-46E3-B89D-526D45F7E233"
Copy link
Member

Choose a reason for hiding this comment

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

Just curious what's token in this response? Is that extracted from the package?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe it would be worth adding an explanation of token and sha256 (the hash of the package, I presume).


Download a bootstrap package.

`GET /api/v1/fleet/mdm/apple/bootstrap`
Copy link
Member

Choose a reason for hiding this comment

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

Given the path structure (GET /mdm/apple/bootstrap/{team_id}/metadata returns the metadata for the bootstrap package of that team, DELETE /mdm/apple/bootstrap/{team_id} deletes the package for that team) I would expect GET /mdm/apple/bootstrap/{team_id} to download the package for a given team? There may be a technical limitation that prevents us from doing this/requiring to use a token approach instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

deletes the package for that team) I would expect GET /mdm/apple/bootstrap/{team_id} to download the package for a given team? There may be a technical limitation that prevents us from doing this/requiring to use a token approach instead?

yes! the bootstrap package needs to be accessed without user authentication, so it's gated behind the token.

having said that, I think we could have used both? the team_id is redundant but looks more consistent: GET /mdm/apple/bootstrap/{team_id}?token={token}

we have already released that endpoint, but we're doing other breaking changes, so maybe we can add this to the list. I'll make a note to discuss with Luke when he's back.


The summary can optionally be filtered by team id.

`GET /api/v1/fleet/mdm/apple/bootstrap/summary`
Copy link
Member

Choose a reason for hiding this comment

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

Similar to the previous comment, could that be GET /mdm/apple/bootstrap/{team_id}/summary for consistency?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It makes sense, I think it was specified that way to be consistent with all the other /resource_here/summary endpoints which take a team_id as a query parameter. I'll also add this to the list to double check with Luke when he's back.

Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, I think the trend on the frontend at least has been toward using team id as a query param rather than a route param for entities that are team-related (but not teams themselves).

Comment on lines 14 to 20
CREATE TABLE host_mdm_apple_bootstrap_packages (
host_uuid varchar(127) NOT NULL,
command_uuid varchar(127) NOT NULL,

PRIMARY KEY (host_uuid, command_uuid),
FOREIGN KEY (command_uuid) REFERENCES nano_commands (command_uuid) ON DELETE CASCADE
)`)
Copy link
Member

Choose a reason for hiding this comment

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

Hmm yeah good question, this is the only command that we need this for at the moment, right? The disk encryption profile is also treated a bit as a special case, but it does not need something like this AFAIR? Given that this is the first need for this, it could make sense to use it like you proposed, and rename it to something more general if and when we need something similar for other "special commands"?

server/fleet/datastore.go Outdated Show resolved Hide resolved
server/fleet/service.go Outdated Show resolved Hide resolved
server/datastore/mysql/apple_mdm.go Show resolved Hide resolved
server/service/integration_mdm_test.go Outdated Show resolved Hide resolved
Co-authored-by: Martin Angers <martin.n.angers@gmail.com>
@gillespi314 gillespi314 temporarily deployed to Docker Hub April 13, 2023 15:36 — with GitHub Actions Inactive
@gillespi314 gillespi314 temporarily deployed to Docker Hub April 13, 2023 15:36 — with GitHub Actions Inactive
@codecov
Copy link

codecov bot commented Apr 13, 2023

Codecov Report

Patch coverage: 27.38% and project coverage change: -0.57 ⚠️

Comparison is base (ddb5894) 60.92% compared to head (56f0665) 60.35%.

❗ Current head 56f0665 differs from pull request most recent head 6f9fa95. Consider uploading reports for the commit 6f9fa95 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #11156      +/-   ##
==========================================
- Coverage   60.92%   60.35%   -0.57%     
==========================================
  Files         525      529       +4     
  Lines       54573    55360     +787     
==========================================
+ Hits        33246    33411     +165     
- Misses      18369    18962     +593     
- Partials     2958     2987      +29     
Impacted Files Coverage Δ
ee/server/service/mdm.go 24.17% <0.00%> (+13.78%) ⬆️
server/fleet/apple_mdm.go 40.38% <ø> (ø)
server/fleet/datastore.go 0.00% <ø> (ø)
server/datastore/mysql/apple_mdm.go 70.85% <7.14%> (-2.77%) ⬇️
server/service/apple_mdm.go 58.35% <36.84%> (-1.84%) ⬇️
...20230411102858_CreateHostBootstrapPackagesTable.go 72.22% <72.22%> (ø)
server/service/handler.go 87.08% <100.00%> (+0.03%) ⬆️

... and 26 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@gillespi314 gillespi314 temporarily deployed to Docker Hub April 13, 2023 19:09 — with GitHub Actions Inactive
@gillespi314 gillespi314 temporarily deployed to Docker Hub April 13, 2023 19:09 — with GitHub Actions Inactive
@gillespi314 gillespi314 temporarily deployed to Docker Hub April 13, 2023 20:07 — with GitHub Actions Inactive
@gillespi314 gillespi314 temporarily deployed to Docker Hub April 13, 2023 20:07 — with GitHub Actions Inactive
@gillespi314 gillespi314 temporarily deployed to Docker Hub April 15, 2023 16:20 — with GitHub Actions Inactive
@roperzh roperzh temporarily deployed to Docker Hub April 20, 2023 13:09 — with GitHub Actions Inactive
@roperzh roperzh temporarily deployed to Docker Hub April 20, 2023 13:09 — with GitHub Actions Inactive
@gillespi314 gillespi314 temporarily deployed to Docker Hub April 20, 2023 20:31 — with GitHub Actions Inactive
@gillespi314 gillespi314 temporarily deployed to Docker Hub April 20, 2023 20:31 — with GitHub Actions Inactive
@@ -141,3 +143,15 @@ func secureRandInt(min, max int64) (int, error) {
}
return random, nil
}

func FmtErrorChain(chain []mdm.ErrorChain) string {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this seems to be the exact same function as *MDMAppleCheckinAndCommandService.fmtErrorChain, can we completely replace the struct function in favor of this?

@gillespi314 gillespi314 temporarily deployed to Docker Hub April 21, 2023 14:35 — with GitHub Actions Inactive
@gillespi314 gillespi314 temporarily deployed to Docker Hub April 21, 2023 14:35 — with GitHub Actions Inactive
@gillespi314 gillespi314 temporarily deployed to Docker Hub April 21, 2023 14:59 — with GitHub Actions Inactive
@gillespi314 gillespi314 temporarily deployed to Docker Hub April 21, 2023 15:01 — with GitHub Actions Inactive
@gillespi314 gillespi314 temporarily deployed to Docker Hub April 21, 2023 15:01 — with GitHub Actions Inactive
@roperzh
Copy link
Contributor Author

roperzh commented Apr 21, 2023

LGTM!

@gillespi314 gillespi314 temporarily deployed to Docker Hub April 21, 2023 18:11 — with GitHub Actions Inactive
@gillespi314 gillespi314 temporarily deployed to Docker Hub April 21, 2023 18:11 — with GitHub Actions Inactive
@gillespi314 gillespi314 temporarily deployed to Docker Hub April 21, 2023 20:02 — with GitHub Actions Inactive
@gillespi314 gillespi314 temporarily deployed to Docker Hub April 21, 2023 20:02 — with GitHub Actions Inactive
@gillespi314 gillespi314 temporarily deployed to Docker Hub April 21, 2023 21:25 — with GitHub Actions Inactive
@gillespi314 gillespi314 temporarily deployed to Docker Hub April 21, 2023 21:25 — with GitHub Actions Inactive
@gillespi314 gillespi314 merged commit 5c48789 into main Apr 22, 2023
@gillespi314 gillespi314 deleted the 10934-bp-endpoints branch April 22, 2023 15:23
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.

4 participants