mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 21:47:20 +00:00
For #27234. - Improved logging in orbit to help us during troubleshooting. - Added some documentation on how to grep for errors related to software package installation in orbit. - Added `took` to server request error logs (it was only present when the request succeeds). --- - [X] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/Committing-Changes.md#changes-files) for more information. - [x] A detailed QA plan exists on the associated ticket (if it isn't there, work with the product group's QA engineer to add it) - [X] Manual QA for all new/changed functionality - For Orbit and Fleet Desktop changes: - [x] Make sure fleetd is compatible with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/fleetd-development-and-release-strategy.md)). - [x] Orbit runs on macOS, Linux and Windows. Check if the orbit feature/bugfix should only apply to one platform (`runtime.GOOS`). - [x] Manual QA must be performed in the three main OSs, macOS, Windows and Linux. - [x] Auto-update manual QA, from released version of component to new version (see [tools/tuf/test](../tools/tuf/test/README.md)).
92 lines
2.6 KiB
Go
92 lines
2.6 KiB
Go
package installer_cache
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
"sync"
|
|
|
|
"github.com/fleetdm/fleet/v4/cmd/osquery-perf/osquery_perf"
|
|
"github.com/fleetdm/fleet/v4/pkg/file"
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
|
"github.com/fleetdm/fleet/v4/server/service"
|
|
)
|
|
|
|
// Metadata holds the metadata for software installers.
|
|
// To extract the metadata, we must download the file. Once the file has been downloaded once and analyzed,
|
|
// the other agents can use the cache to get the appropriate metadata.
|
|
type Metadata struct {
|
|
mu sync.Mutex
|
|
cache map[uint]*file.InstallerMetadata
|
|
Stats *osquery_perf.Stats
|
|
}
|
|
|
|
func (c *Metadata) Get(installer *fleet.SoftwareInstallDetails, orbitClient *service.OrbitClient) (meta *file.InstallerMetadata,
|
|
cacheMiss bool, err error,
|
|
) {
|
|
c.mu.Lock()
|
|
defer c.mu.Unlock()
|
|
if c.cache == nil {
|
|
c.cache = make(map[uint]*file.InstallerMetadata, 1)
|
|
}
|
|
|
|
meta, ok := c.cache[installer.InstallerID]
|
|
if !ok {
|
|
var err error
|
|
meta, err = c.populateMetadata(installer, orbitClient)
|
|
if err != nil {
|
|
return nil, false, err
|
|
}
|
|
c.cache[installer.InstallerID] = meta
|
|
cacheMiss = true
|
|
}
|
|
return meta, cacheMiss, nil
|
|
}
|
|
|
|
func (c *Metadata) populateMetadata(installer *fleet.SoftwareInstallDetails, orbitClient *service.OrbitClient) (*file.InstallerMetadata,
|
|
error,
|
|
) {
|
|
tmpDir, err := os.MkdirTemp("", "")
|
|
if err != nil {
|
|
c.Stats.IncrementOrbitErrors()
|
|
log.Println("level=error, create temp dir:", err)
|
|
return nil, err
|
|
}
|
|
defer os.RemoveAll(tmpDir)
|
|
|
|
var path string
|
|
if installer.SoftwareInstallerURL != nil {
|
|
path, err = orbitClient.DownloadSoftwareInstallerFromURL(installer.SoftwareInstallerURL.URL,
|
|
installer.SoftwareInstallerURL.Filename, tmpDir, func(n int) {
|
|
})
|
|
if err != nil {
|
|
log.Printf("level=error, msg=download software installer from URL; is CloudFront CDN configured correctly?, err=%s", err)
|
|
c.Stats.IncrementOrbitErrors()
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
if path == "" {
|
|
path, err = orbitClient.DownloadSoftwareInstaller(installer.InstallerID, tmpDir, func(n int) {
|
|
})
|
|
if err != nil {
|
|
log.Printf("level=error, msg=download software installer, err=%s", err)
|
|
c.Stats.IncrementOrbitErrors()
|
|
return nil, err
|
|
}
|
|
}
|
|
// Figure out what we're actually installing here and add it to software inventory
|
|
tfr, err := fleet.NewKeepFileReader(path)
|
|
if err != nil {
|
|
c.Stats.IncrementOrbitErrors()
|
|
log.Println("level=error, open installer:", err)
|
|
return nil, err
|
|
}
|
|
defer tfr.Close()
|
|
item, err := file.ExtractInstallerMetadata(tfr)
|
|
if err != nil {
|
|
c.Stats.IncrementOrbitErrors()
|
|
log.Println("level=error, extract installer metadata:", err)
|
|
return nil, err
|
|
}
|
|
return item, nil
|
|
}
|