Skip to content

Commit 885d6d5

Browse files
AnishShahleodido
authored andcommitted
chore(cmd): rename probeloader to kernelmoduleloader
Issue #53 Co-authored-by: Leonardo Di Donato <[email protected]> Signed-off-by: Anish Shah <[email protected]> Signed-off-by: Leonardo Di Donato <[email protected]>
1 parent b0d030c commit 885d6d5

File tree

5 files changed

+143
-143
lines changed

5 files changed

+143
-143
lines changed

cmd/install.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func Install(streams genericclioptions.IOStreams, f factory.Factory) *cobra.Comm
5252
}
5353

5454
cmd.AddCommand(InstallFalco(streams, f))
55-
cmd.AddCommand(InstallProbe(streams))
55+
cmd.AddCommand(InstallModule(streams))
5656
cmd.AddCommand(InstallTLS(streams))
5757
cmd.AddCommand(InstallRule(streams))
5858

cmd/install_probe.go renamed to cmd/install_module.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ import (
2424
"k8s.io/cli-runtime/pkg/genericclioptions"
2525
)
2626

27-
// InstallProbe creates the `install probe` command
28-
func InstallProbe(streams genericclioptions.IOStreams) *cobra.Command {
27+
// InstallModule creates the `install module` command
28+
func InstallModule(streams genericclioptions.IOStreams) *cobra.Command {
2929
cmd := &cobra.Command{
30-
Use: "probe",
30+
Use: "module",
3131
DisableFlagsInUseLine: true,
32-
Short: "Install the Falco probe locally (linux only)",
32+
Short: "Install the Falco module locally (linux only)",
3333
Long: `Download and install the Falco module locally`,
3434
RunE: func(cmd *cobra.Command, args []string) error {
3535
logger.Critical("this command only works on machines running a linux kernel")

cmd/install_module_linux.go

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/*
2+
Copyright © 2019 The Falco Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package cmd
18+
19+
import (
20+
"fmt"
21+
"os"
22+
"path"
23+
24+
"github.com/falcosecurity/falcoctl/pkg/kernelmoduleloader"
25+
"github.com/kris-nova/logger"
26+
"github.com/spf13/cobra"
27+
"github.com/spf13/viper"
28+
"k8s.io/cli-runtime/pkg/genericclioptions"
29+
)
30+
31+
// ModuleOptions represents the `install module` command options
32+
type ModuleOptions struct {
33+
genericclioptions.IOStreams
34+
falcoVersion string
35+
falcoModulePath string
36+
falcoModuleFile string
37+
falcoModuleURL string
38+
falcoModuleRepo string
39+
}
40+
41+
// Validate validates the `install module` command options
42+
func (o ModuleOptions) Validate(c *cobra.Command, args []string) error {
43+
if len(o.falcoVersion) == 0 {
44+
return fmt.Errorf("missing Falco version: specify it via FALCOCTL_FALCO_VERSION env variable or via --falco-version flag")
45+
}
46+
return nil
47+
}
48+
49+
// NewModuleOptions instantiates the `install module` command options
50+
func NewModuleOptions(streams genericclioptions.IOStreams) CommandOptions {
51+
o := &ModuleOptions{
52+
IOStreams: streams,
53+
}
54+
o.falcoVersion = viper.GetString("falco-version") // FALCOCTL_FALCO_VERSION env var
55+
o.falcoModulePath = viper.GetString("falco-module-path") // FALCOCTL_FALCO_MODULE_PATH env var
56+
if len(o.falcoModulePath) == 0 {
57+
o.falcoModulePath = "/" // default
58+
}
59+
o.falcoModuleFile = viper.GetString("falco-module-file") // FALCOCTL_FALCO_MODULE_FILE env var
60+
if len(o.falcoModuleFile) == 0 {
61+
o.falcoModuleFile = "falco-module.ko" // default
62+
}
63+
o.falcoModuleURL = viper.GetString("falco-module-url") // FALCOCTL_FALCO_MODULE_URL env var
64+
o.falcoModuleRepo = viper.GetString("falco-module-repo") // FALCOCTL_FALCO_MODULE_REPO env var
65+
if len(o.falcoModuleRepo) == 0 {
66+
o.falcoModuleRepo = "https://s3.amazonaws.com/download.draios.com/stable/sysdig-module-binaries/" // default
67+
}
68+
return o
69+
}
70+
71+
// InstallModule creates the `install module` command
72+
func InstallModule(streams genericclioptions.IOStreams) *cobra.Command {
73+
o := NewModuleOptions(streams).(*ModuleOptions)
74+
75+
cmd := &cobra.Command{
76+
Use: "module",
77+
DisableFlagsInUseLine: true,
78+
Short: "Install the Falco module locally",
79+
Long: `Download and install the Falco module locally`,
80+
PreRun: func(cmd *cobra.Command, args []string) {
81+
if err := o.Validate(cmd, args); err != nil {
82+
logger.Critical("%s", err)
83+
os.Exit(1)
84+
}
85+
},
86+
RunE: func(cmd *cobra.Command, args []string) error {
87+
falcoModuleFullpath := path.Join(o.falcoModulePath, o.falcoModuleFile)
88+
falcoConfigHash, err := kernelmoduleloader.GetKernelConfigHash()
89+
if err != nil {
90+
logger.Critical("Error getting Kernel Config Hash: %s", err)
91+
return err
92+
}
93+
falcoKernelRelease, err := kernelmoduleloader.GetKernelRelease()
94+
if err != nil {
95+
logger.Critical("Error getting Kernel Version: %s", err)
96+
return err
97+
}
98+
99+
logger.Always("FALCO_VERSION: %s", o.falcoVersion)
100+
logger.Always("FALCO_MODULE_URL: %s", o.falcoModuleURL)
101+
logger.Always("FALCO_MODULE_REPO: %s", o.falcoModuleRepo)
102+
logger.Always("KERNEL_VERSION: %s", falcoKernelRelease)
103+
logger.Always("KERNEL_CONFIG_HASH: %s", falcoConfigHash)
104+
105+
// if FALCO_MODULE_URL not set, build it
106+
if o.falcoModuleURL == "" {
107+
o.falcoModuleURL = fmt.Sprintf("%sfalco-module-%s-x86_64-%s-%s.ko", o.falcoModuleRepo, o.falcoVersion, falcoKernelRelease, falcoConfigHash)
108+
}
109+
110+
// fetch module
111+
err = kernelmoduleloader.FetchModule(o.falcoModuleURL, falcoModuleFullpath)
112+
if err != nil {
113+
logger.Critical("Error fetching module: %s", err)
114+
return err
115+
}
116+
117+
// load module
118+
// TODO(ducy): Need to implement removal of module, retry loop, and timeout
119+
err = kernelmoduleloader.LoadModule(falcoModuleFullpath)
120+
if err != nil {
121+
logger.Critical("Error loading module: %s", err)
122+
return err
123+
}
124+
125+
return nil
126+
},
127+
}
128+
129+
// TODO(fntlnz, leodido): validation
130+
cmd.Flags().StringVar(&o.falcoVersion, "falco-version", o.falcoVersion, "The falco version for which to download the module")
131+
cmd.Flags().StringVar(&o.falcoModulePath, "falco-module-path", o.falcoModulePath, "The path where to download the falco module")
132+
cmd.Flags().StringVar(&o.falcoModuleFile, "falco-module-file", o.falcoModuleFile, "The name of the falco module file")
133+
cmd.Flags().StringVar(&o.falcoModuleURL, "falco-module-url", o.falcoModuleURL, "The direct URL where to download the falco module from, alternative to the repo, not the default, this skips the search since a direct url is provided")
134+
cmd.Flags().StringVar(&o.falcoModuleRepo, "falco-module-repo", o.falcoModuleRepo, "The URL of the s3 repo where to search for the module")
135+
return cmd
136+
}

cmd/install_probe_linux.go

Lines changed: 0 additions & 136 deletions
This file was deleted.

pkg/probeloader/loader.go renamed to pkg/kernelmoduleloader/kernel_module_loader.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package probeloader
17+
package kernelmoduleloader
1818

1919
import (
2020
"bytes"
@@ -148,7 +148,7 @@ func LoadModule(path string) error {
148148
return err
149149
}
150150

151-
logger.Always("Opened probe: %s", path)
151+
logger.Always("Opened kernel module: %s", path)
152152

153153
p0, err := unix.BytePtrFromString("")
154154

0 commit comments

Comments
 (0)