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

Display ingested software on host details page. #19576

Merged
merged 8 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added exclude_software option.
  • Loading branch information
getvictor committed Jun 11, 2024
commit d4d2889c217b00ed43c6ed90ee0dfb2c6a880cfe
4 changes: 2 additions & 2 deletions server/datastore/mysql/schema.sql

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions server/datastore/mysql/software_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2862,6 +2862,7 @@ func TestReconcileSoftwareTitles(t *testing.T) {
}

swTitles, err := getTitles()
require.NoError(t, err)
for _, swt := range swTitles {
if _, ok := expectedTitlesByNSB[swt.Name+swt.Source+swt.Browser]; ok {
expectedTitlesByNSB[swt.Name+swt.Source+swt.Browser] = swt
Expand Down
1 change: 1 addition & 0 deletions server/fleet/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,7 @@ type OSVersion struct {
type HostDetailOptions struct {
IncludeCVEScores bool
IncludePolicies bool
ExcludeSoftware bool
}

// EnrollHostLimiter defines the methods to support enforcement of enrolled
Expand Down
12 changes: 8 additions & 4 deletions server/service/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,8 @@ func (svc *Service) SearchHosts(ctx context.Context, matchQuery string, queryID
/////////////////////////////////////////////////////////////////////////////////

type getHostRequest struct {
ID uint `url:"id"`
ID uint `url:"id"`
ExcludeSoftware bool `query:"exclude_software,optional"`
}

type getHostResponse struct {
Expand All @@ -493,7 +494,8 @@ func getHostEndpoint(ctx context.Context, request interface{}, svc fleet.Service
req := request.(*getHostRequest)
opts := fleet.HostDetailOptions{
IncludeCVEScores: false,
IncludePolicies: true, // intentionally true to preserve existing behavior
IncludePolicies: true, // intentionally true to preserve existing behavior,
ExcludeSoftware: req.ExcludeSoftware,
getvictor marked this conversation as resolved.
Show resolved Hide resolved
}
host, err := svc.GetHost(ctx, req.ID, opts)
if err != nil {
Expand Down Expand Up @@ -1009,8 +1011,10 @@ func (svc *Service) RefetchHost(ctx context.Context, id uint) error {
}

func (svc *Service) getHostDetails(ctx context.Context, host *fleet.Host, opts fleet.HostDetailOptions) (*fleet.HostDetail, error) {
if err := svc.ds.LoadHostSoftware(ctx, host, opts.IncludeCVEScores); err != nil {
return nil, ctxerr.Wrap(ctx, err, "load host software")
if !opts.ExcludeSoftware {
if err := svc.ds.LoadHostSoftware(ctx, host, opts.IncludeCVEScores); err != nil {
return nil, ctxerr.Wrap(ctx, err, "load host software")
}
}

labels, err := svc.ds.ListLabelsForHost(ctx, host.ID)
Expand Down
6 changes: 6 additions & 0 deletions server/service/integration_core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7911,6 +7911,12 @@ func (s *integrationTestSuite) TestGetHostSoftwareUpdatedAt() {
require.Equal(t, host.ID, getHostResp.Host.ID)
require.Len(t, getHostResp.Host.Software, len(software))
require.Greater(t, getHostResp.Host.SoftwareUpdatedAt, getHostResp.Host.CreatedAt)

getHostResp = getHostResponse{}
s.DoJSON("GET", fmt.Sprintf("/api/latest/fleet/hosts/%d", host.ID), nil, http.StatusOK, &getHostResp, "exclude_software", "true")
require.Equal(t, host.ID, getHostResp.Host.ID)
require.Empty(t, getHostResp.Host.Software)
require.Greater(t, getHostResp.Host.SoftwareUpdatedAt, getHostResp.Host.CreatedAt)
}

func (s *integrationTestSuite) TestHostsReportDownload() {
Expand Down