From 141aa6b06bbc05e0fc66aa2c3824418c52af662a Mon Sep 17 00:00:00 2001 From: Eric Date: Mon, 13 Jan 2025 12:05:11 -0600 Subject: [PATCH 1/4] add new exit for missing installer --- .../api/controllers/software/edit-software.js | 4 ++++ .../views/pages/software/software.ejs | 1 + 2 files changed, 5 insertions(+) diff --git a/ee/bulk-operations-dashboard/api/controllers/software/edit-software.js b/ee/bulk-operations-dashboard/api/controllers/software/edit-software.js index 0e69202ee5b0..c925db48d012 100644 --- a/ee/bulk-operations-dashboard/api/controllers/software/edit-software.js +++ b/ee/bulk-operations-dashboard/api/controllers/software/edit-software.js @@ -63,6 +63,10 @@ module.exports = { description: 'The specified software could not be deleted from the Fleet instance.', statusCode: 409, }, + + softwareInstallerMissing: { + description: 'The Fleet instance returned a 404 response when a request was sent to copy an existing software installer to a new team', + }, }, diff --git a/ee/bulk-operations-dashboard/views/pages/software/software.ejs b/ee/bulk-operations-dashboard/views/pages/software/software.ejs index dcc8b823aaf1..c6833c78bcc6 100644 --- a/ee/bulk-operations-dashboard/views/pages/software/software.ejs +++ b/ee/bulk-operations-dashboard/views/pages/software/software.ejs @@ -149,6 +149,7 @@ The Fleet instance could not read version information from the provided software installer. This software has been configured to be installed as part of the macOS setup experience and cannot be removed from a team. Please remove this software from any teams you want to remove this from in the "Setup experience" tab of the Controls page on your Fleet instance and try again An error occured when transfering this software to a new team. A software installer with the same name as this software already exists on one or more of the selected teams. + An error occured when transfering this software to a new team. The software installer could not be found on the Fleet instance. Please check to see if this file can be downloaded from the connected Fleet instance.
Save From 83f924f8f105884908366877a24d82344031be40 Mon Sep 17 00:00:00 2001 From: Eric Date: Thu, 16 Jan 2025 15:39:40 -0600 Subject: [PATCH 2/4] Update software.ejs --- ee/bulk-operations-dashboard/views/pages/software/software.ejs | 1 + 1 file changed, 1 insertion(+) diff --git a/ee/bulk-operations-dashboard/views/pages/software/software.ejs b/ee/bulk-operations-dashboard/views/pages/software/software.ejs index c6833c78bcc6..8dbfded56a79 100644 --- a/ee/bulk-operations-dashboard/views/pages/software/software.ejs +++ b/ee/bulk-operations-dashboard/views/pages/software/software.ejs @@ -168,6 +168,7 @@

{{formData.software.name}} will be removed from your library.

This software has been configured to be installed as part of the macOS setup experience and cannot be deleted. Please remove this software from all teams the "Setup experience" tab of the Controls page on your Fleet instance and try again + An error occured when removing this software installer. The specified software installer could not be found on the Fleet instance. Please check to see if this file can be deleted from the connected Fleet instance.
Cancel From cf3cacb997ae25942bc96da67b741c38e3911ff3 Mon Sep 17 00:00:00 2001 From: Eric Date: Thu, 16 Jan 2025 15:40:03 -0600 Subject: [PATCH 3/4] add new exit to delete software. --- .../api/controllers/software/delete-software.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ee/bulk-operations-dashboard/api/controllers/software/delete-software.js b/ee/bulk-operations-dashboard/api/controllers/software/delete-software.js index 539d8c46761b..5172779d063a 100644 --- a/ee/bulk-operations-dashboard/api/controllers/software/delete-software.js +++ b/ee/bulk-operations-dashboard/api/controllers/software/delete-software.js @@ -19,7 +19,12 @@ module.exports = { softwareDeletionFailed: { description: 'The specified software could not be deleted from the Fleet instance.', statusCode: 409, - } + }, + + softwareInstallerMissing: { + description: 'The Fleet instance returned a 404 response when a request was sent to copy an existing software installer to a new team', + responseType: 'notFound', + }, }, @@ -38,6 +43,12 @@ module.exports = { Authorization: `Bearer ${sails.config.custom.fleetApiToken}`, } }) + .intercept({raw:{statusCode: 404}}, (error)=>{ + sails.log.warn(`When attempting to delete the installer for ${software.name} (id: ${software.fleetApid}), the Fleet instance returned a 404 response when a request was delete the installer on team_id ${team.fleetApid}. Full Error: ${require('util').inspect(error, {depth: 1})}`); + // If the Fleet instance's returns a 409 response, then the software is configured to be installed as + // part of the macOS setup experience, and must be removed before it can be deleted via API requests. + return 'softwareInstallerMissing'; + }) .intercept({raw:{statusCode: 409}}, (error)=>{ // If the Fleet instance's returns a 409 response, then the software is configured to be installed as // part of the macOS setup experience, and must be removed before it can be deleted via API requests. From 4699ddb3e31d306b7d55bbf8e359dce6a612af60 Mon Sep 17 00:00:00 2001 From: Eric Date: Thu, 16 Jan 2025 15:54:37 -0600 Subject: [PATCH 4/4] add more detailed logs for missing software installers --- .../api/controllers/software/delete-software.js | 1 - .../api/controllers/software/download-software.js | 11 +++++++++++ .../api/controllers/software/edit-software.js | 5 +++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/ee/bulk-operations-dashboard/api/controllers/software/delete-software.js b/ee/bulk-operations-dashboard/api/controllers/software/delete-software.js index 5172779d063a..5bb79bdb5973 100644 --- a/ee/bulk-operations-dashboard/api/controllers/software/delete-software.js +++ b/ee/bulk-operations-dashboard/api/controllers/software/delete-software.js @@ -23,7 +23,6 @@ module.exports = { softwareInstallerMissing: { description: 'The Fleet instance returned a 404 response when a request was sent to copy an existing software installer to a new team', - responseType: 'notFound', }, }, diff --git a/ee/bulk-operations-dashboard/api/controllers/software/download-software.js b/ee/bulk-operations-dashboard/api/controllers/software/download-software.js index c6b558f31f74..9a15ea8fa016 100644 --- a/ee/bulk-operations-dashboard/api/controllers/software/download-software.js +++ b/ee/bulk-operations-dashboard/api/controllers/software/download-software.js @@ -45,6 +45,9 @@ module.exports = { if(id){ let softwareToDownload = await UndeployedSoftware.findOne({id: id}); + if(!softwareToDownload){ + throw 'notFound'; + } downloading = await sails.startDownload(softwareToDownload.uploadFd, {bucket: sails.config.uploads.bucketWithPostfix}); this.res.type(softwareToDownload.uploadMime); this.res.attachment(softwareToDownload.name); @@ -55,6 +58,10 @@ module.exports = { headers: { Authorization: `Bearer ${sails.config.custom.fleetApiToken}`, } + }).intercept({raw: {statusCode: 404}}, (error)=>{ + // If the Fleet instance returns a 404 response, log a warning and display the notFound response page. + sails.log.warn(`When attempting to get information about a software title (id: ${fleetApid}) for team_id ${teamApid}, the Fleet instance returned a 404 response. Full Error: ${require('util').inspect(error, {depth: 1})}`); + return 'notFound'; }); let filename = packageInformation.software_title.software_package.name; // [?]: https://fleetdm.com/docs/rest-api/rest-api#download-package @@ -64,6 +71,10 @@ module.exports = { headers: { Authorization: `Bearer ${sails.config.custom.fleetApiToken}`, } + }) + .intercept({raw: {statusCode: 404}}, (error)=>{ + // If the installer is missing, throw an error with information about this software installer/title. + return new Error(`When attempting to download the installer for ${filename} (id: ${fleetApid}), the Fleet instance returned a 404 response when a request was sent to get a download stream of the installer on team_id ${teamApid}. Full Error: ${require('util').inspect(error, {depth: 1})}`); }); this.res.attachment(filename); } diff --git a/ee/bulk-operations-dashboard/api/controllers/software/edit-software.js b/ee/bulk-operations-dashboard/api/controllers/software/edit-software.js index c925db48d012..d58d7d91b02d 100644 --- a/ee/bulk-operations-dashboard/api/controllers/software/edit-software.js +++ b/ee/bulk-operations-dashboard/api/controllers/software/edit-software.js @@ -103,8 +103,9 @@ module.exports = { Authorization: `Bearer ${sails.config.custom.fleetApiToken}`, } }) - .intercept('non200Response', (error)=>{ - return new Error(`When attempting to transfer the installer for ${software.name} to a new team on the Fleet instance, the Fleet isntance returned a non-200 response when a request was sent to get a download stream of the installer on team_id ${teamIdToGetInstallerFrom}. Full Error: ${require('util').inspect(error, {depth: 1})}`); + .intercept({raw: {statusCode: 404}}, (error)=>{ + sails.log.warn(`When attempting to transfer the installer for ${software.name} (id: ${software.fleetApid}) to a new team, the Fleet instance returned a 404 resposne when a request was sent to get a download stream of the installer on team_id ${teamIdToGetInstallerFrom}. Full Error: ${require('util').inspect(error, {depth: 1})}`); + return 'softwareInstallerMissing'; }); let tempUploadedSoftware = await sails.uploadOne(softwareStream, {bucket: sails.config.uploads.bucketWithPostfix}); softwareFd = tempUploadedSoftware.fd;