Skip to content

Commit

Permalink
Bugfix: Include tool versions from root org (#2913)
Browse files Browse the repository at this point in the history
In child orgs the repository delegates to the root org's repository but
tool definitions are kept in the child org's inventory. This means that
it was impossible to reset the definitions because the GUI would not
present the original versions.
  • Loading branch information
scudette authored Aug 28, 2023
1 parent d89cf7a commit 0ef0e8b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
10 changes: 8 additions & 2 deletions config/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io/ioutil"
"os"
"os/user"
"path/filepath"
"regexp"
"runtime"

Expand Down Expand Up @@ -351,9 +352,14 @@ func (self *Loader) WithEmbedded(embedded_file string) *Loader {
}

// Ensure the "me" accessor uses this file for embedded zip.
EmbeddedFile = embedded_file
full_path, err := filepath.Abs(embedded_file)
if err != nil {
return nil, err
}

EmbeddedFile = full_path

fd, err := os.Open(embedded_file)
fd, err := os.Open(full_path)
if err != nil {
return nil, err
}
Expand Down
3 changes: 3 additions & 0 deletions docs/references/vql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2694,6 +2694,9 @@
required: true
- name: version
type: string
- name: probe
type: bool
description: If specified we only probe the tool definition without materializing
category: server
metadata:
permissions: SERVER_ADMIN
Expand Down
1 change: 1 addition & 0 deletions gui/velociraptor/build/.keep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

10 changes: 9 additions & 1 deletion services/inventory/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ func (self *InventoryService) addAllVersions(
result.Versions = append(result.Versions, v)
}

// Merge the parent's versions as well.
if self.parent != nil {
parent_tool, err := self.parent.ProbeToolInfo(ctx, config_obj, tool.Name, "")
if err == nil {
result.Versions = append(result.Versions, parent_tool.Versions...)
}
}

return result
}

Expand Down Expand Up @@ -416,7 +424,7 @@ func (self *InventoryService) UpdateVersion(tool_request *artifacts_proto.Tool)
self.mu.Lock()
defer self.mu.Unlock()

// Update the list of version for this tool, replacing existing
// Update the list of versions for this tool, replacing existing
// definitions.
versions, _ := self.versions[tool_request.Name]
version_known := false
Expand Down
8 changes: 7 additions & 1 deletion vql/server/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func (self *InventoryAddFunction) Info(
type InventoryGetFunctionArgs struct {
Tool string `vfilter:"required,field=tool"`
Version string `vfilter:"optional,field=version"`
Probe bool `vfilter:"optional,field=probe,doc=If specified we only probe the tool definition without materializing"`
}

type InventoryGetFunction struct{}
Expand Down Expand Up @@ -179,7 +180,12 @@ func (self *InventoryGetFunction) Call(ctx context.Context,
return vfilter.Null{}
}

tool, err := inventory.GetToolInfo(ctx, config_obj, arg.Tool, arg.Version)
var tool *artifacts_proto.Tool
if !arg.Probe {
tool, err = inventory.GetToolInfo(ctx, config_obj, arg.Tool, arg.Version)
} else {
tool, err = inventory.ProbeToolInfo(ctx, config_obj, arg.Tool, arg.Version)
}
if err != nil {
scope.Log("inventory_get: %s", err.Error())
return vfilter.Null{}
Expand Down

0 comments on commit 0ef0e8b

Please sign in to comment.