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

Fix software-with-bundle-ID add when the same title with different/no bundle ID, add missing request timeout special case for edit package endpoint #22413

Merged
merged 7 commits into from
Sep 26, 2024
2 changes: 1 addition & 1 deletion articles/deploy-software-packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Fleet [v4.50.0](https://github.com/fleetdm/fleet/releases/tag/fleet-v4.50.0) int

* An S3 bucket [configured](https://fleetdm.com/docs/configuration/fleet-server-configuration#s-3-software-installers-bucket) to store the installers.

* Increase any load balancer timeouts to at least 5 minutes for the [Add software](https://fleetdm.com/docs/rest-api/rest-api#add-software) endpoint.
* Increase any load balancer timeouts to at least 5 minutes for the [Add package](https://fleetdm.com/docs/rest-api/rest-api#add-package) and [Modify package](https://fleetdm.com/docs/rest-api/rest-api#modify-package) endpoints.

## Step-by-step instructions

Expand Down
1 change: 1 addition & 0 deletions changes/21370-bundle-id-quickfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix "no rows" error when adding a software installer that matches an existing title's name and source but not its bundle ID
1 change: 1 addition & 0 deletions changes/software-edit-request-deadline
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Ensure request timeouts for software installer edits are just as high as for initial software installer uploads
3 changes: 2 additions & 1 deletion cmd/fleet/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,8 @@ the way that the Fleet server works.
}
}

if req.Method == http.MethodPost && strings.HasSuffix(req.URL.Path, "/fleet/software/package") {
if (req.Method == http.MethodPost && strings.HasSuffix(req.URL.Path, "/fleet/software/package")) ||
(req.Method == http.MethodPatch && strings.HasSuffix(req.URL.Path, "/package") && strings.Contains(req.URL.Path, "/fleet/software/titles/")) {
roperzh marked this conversation as resolved.
Show resolved Hide resolved
// when uploading a software installer, the file might be large so
// the read timeout (to read the full request body) must be extended.
rc := http.NewResponseController(rw)
Expand Down
5 changes: 3 additions & 2 deletions server/datastore/mysql/software_installers.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,9 @@ func (ds *Datastore) getOrGenerateSoftwareInstallerTitleID(ctx context.Context,
insertArgs := []any{payload.Title, payload.Source}

if payload.BundleIdentifier != "" {
selectStmt = `SELECT id FROM software_titles WHERE bundle_identifier = ?`
selectArgs = []any{payload.BundleIdentifier}
// match by bundle identifier first, or standard matching if we don't have a bundle identifier match
selectStmt = `SELECT id FROM software_titles WHERE bundle_identifier = ? OR (name = ? AND source = ? AND browser = '') ORDER BY bundle_identifier = ? DESC LIMIT 1`
lucasmrod marked this conversation as resolved.
Show resolved Hide resolved
lucasmrod marked this conversation as resolved.
Show resolved Hide resolved
selectArgs = []any{payload.BundleIdentifier, payload.Title, payload.Source, payload.BundleIdentifier}
insertStmt = `INSERT INTO software_titles (name, source, bundle_identifier, browser) VALUES (?, ?, ?, '')`
insertArgs = append(insertArgs, payload.BundleIdentifier)
}
Expand Down
Loading