You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR enhances the functionality of the proc os-query package, such that it would also support file system injection.
Why is it important?
This change is important for two reasons:
It lets the user expose only a part of his file system/give a relative path.
It enhances the functionality such that a developer can use an in-memory file system such as fstest
This change is required by the @elastic/cloud-posture-security, since we are using this extension and would like to write tests using fstest.
In-depth
Cloudbeat allows the user to detect and analyze his Kubernetes environment.
In order to do so, the Cloudbeat fetches all types of resources from the Kubernetes along with processes data.
The processes data is being claimed out of a procfs directory that is being mounted to the pod Cloudbeats runs on.
We would like the osquery-extension to support injecting of fs.FS so that a developer can inject his own file-system to the function (that will make our tests much much tidier).
Solution proposition
Duplicate only the function signatures.
Code example
// List returns all the processes in the proc folderfuncList(rootstring) ([]string, error) {
returnListFS(root)
}
funcListFS(sysfs fs.FS) ([]string, error) {
varpids []stringdirs, err:=fs.ReadDir(sysfs, proc)
iferr!=nil {
returnnil, err
}
for_, dir:=rangedirs {
if!dir.IsDir() {
continue
}
name:=dir.Name()
// Check if directory is number_, err:=strconv.Atoi(name)
iferr!=nil {
err=nilcontinue
}
pids=append(pids, name)
}
returnpids, nil
}
Duplicate the function code
// List returns all the processes in the proc folderfuncList(rootstring) ([]string, error) {
varpids []stringroot=filepath.Join(root, "/proc")
dirs, err:=os.ReadDir(root)
iferr!=nil {
returnnil, err
}
for_, dir:=rangedirs {
if!dir.IsDir() {
continue
}
name:=dir.Name()
// Check if directory is number_, err:=strconv.Atoi(name)
iferr!=nil {
err=nilcontinue
}
pids=append(pids, name)
}
returnpids, nil
}
funcListFS(sysfs fs.FS, rootstring) ([]string, error) {
varpids []stringroot=filepath.Join(root, "/proc")
dirs, err:=fs.ReadDir(sysfs, root)
iferr!=nil {
returnnil, err
}
for_, dir:=rangedirs {
if!dir.IsDir() {
continue
}
name:=dir.Name()
// Check if directory is number_, err:=strconv.Atoi(name)
iferr!=nil {
err=nilcontinue
}
pids=append(pids, name)
}
returnpids, nil
}
Risk assessment
As far as I understand, the DirFs doesn't support windows (it's not a cross-platform solution since windows do not have a root folder).
In addition, there is a small issue with using "/", it cannot appear as a prefix or a suffix of the input to
Motivation
This PR enhances the functionality of the proc os-query package, such that it would also support file system injection.
Why is it important?
This change is important for two reasons:
fstest
This change is required by the @elastic/cloud-posture-security, since we are using this extension and would like to write tests using
fstest
.In-depth
Cloudbeat allows the user to detect and analyze his Kubernetes environment.
In order to do so, the Cloudbeat fetches all types of resources from the Kubernetes along with processes data.
The processes data is being claimed out of a procfs directory that is being mounted to the pod Cloudbeats runs on.
The process fetcher, the fetcher responsible for collecting the procfs data, uses the osquery-extension.
We would like the
osquery-extension
to support injecting offs.FS
so that a developer can inject his own file-system to the function (that will make our tests much much tidier).Solution proposition
Code example
Risk assessment
As far as I understand, the DirFs doesn't support windows (it's not a cross-platform solution since windows do not have a root folder).
In addition, there is a small issue with using "/", it cannot appear as a prefix or a suffix of the input to
More can be found here - golang/go#44279.
Definition of done
The proc package will support the usage of an injected file system.
The text was updated successfully, but these errors were encountered: