diff options
author | Pawel Wieczorek <p.wieczorek2@samsung.com> | 2020-01-23 12:13:44 +0100 |
---|---|---|
committer | Pawel Wieczorek <p.wieczorek2@samsung.com> | 2020-01-29 17:17:40 +0100 |
commit | 2e956f6332428d91afd683884de7dcf43aec5988 (patch) | |
tree | b66c30376fb7cae6c982ea6324a22b864f553a58 /test/security/k8s/src/check/rancher | |
parent | e15544dfe000aa6d055b5d8bc0fadfc8f0ef5648 (diff) |
k8s: Drop support for Casablanca
Casablanca release reached End of Life (EOL) stage on July 8th 2019 [1].
This patch also fixes comments for test fixtures.
This whole test subtree will be deleted upon migrating Aquasec
kube-bench [2] for CIS Benchmark [3] integrated by Orange [4] to ONAP
xtesting [5].
[1] https://wiki.onap.org/display/DW/Long+Term+Roadmap
[2] https://github.com/aquasecurity/kube-bench
[3] https://www.cisecurity.org/benchmark/kubernetes/
[4] https://gitlab.com/Orange-OpenSource/lfn/onap/integration/xtesting
[5] https://git.onap.org/integration/xtesting/
Issue-ID: SECCOM-235
Change-Id: Ifc7d9c775c27d4cfafdd1932809288530cffceff
Signed-off-by: Pawel Wieczorek <p.wieczorek2@samsung.com>
Diffstat (limited to 'test/security/k8s/src/check/rancher')
-rw-r--r-- | test/security/k8s/src/check/rancher/rancher.go | 124 |
1 files changed, 0 insertions, 124 deletions
diff --git a/test/security/k8s/src/check/rancher/rancher.go b/test/security/k8s/src/check/rancher/rancher.go deleted file mode 100644 index 2cf2fbe69..000000000 --- a/test/security/k8s/src/check/rancher/rancher.go +++ /dev/null @@ -1,124 +0,0 @@ -// Package rancher wraps Rancher commands necessary for K8s inspection. -package rancher - -import ( - "bytes" - "fmt" - "os/exec" - - "check" -) - -const ( - bin = "rancher" - paramHost = "--host" - cmdHosts = "hosts" - cmdHostsParams = "--quiet" - cmdDocker = "docker" - cmdDockerCmdPs = "ps" - cmdDockerCmdPsParams = "--no-trunc" - cmdDockerCmdPsFilter = "--filter" - cmdDockerCmdPsFilterArgs = "label=io.rancher.stack_service.name=" - cmdDockerCmdPsFormat = "--format" - cmdDockerCmdPsFormatArgs = "{{.Command}}" -) - -// Rancher implements Informer interface. -type Rancher struct { - check.Informer -} - -// GetAPIParams returns parameters of running Kubernetes API server. -// It queries default environment set in configuration file. -func (r *Rancher) GetAPIParams() ([]string, error) { - return getProcessParams(check.APIProcess, check.APIService) -} - -// GetSchedulerParams returns parameters of running Kubernetes scheduler. -// It queries default environment set in configuration file. -func (r *Rancher) GetSchedulerParams() ([]string, error) { - return getProcessParams(check.SchedulerProcess, check.SchedulerService) -} - -// GetControllerManagerParams returns parameters of running Kubernetes scheduler. -// It queries default environment set in configuration file. -func (r *Rancher) GetControllerManagerParams() ([]string, error) { - return getProcessParams(check.ControllerManagerProcess, check.ControllerManagerService) -} - -// GetEtcdParams returns parameters of running etcd. -// It queries only cluster nodes with "controlplane" role. -func (r *Rancher) GetEtcdParams() ([]string, error) { - return []string{}, check.ErrNotImplemented -} - -func getProcessParams(process check.Command, service check.Service) ([]string, error) { - hosts, err := listHosts() - if err != nil { - return []string{}, err - } - - for _, host := range hosts { - cmd, err := getPsCmdOutput(host, service) - if err != nil { - return []string{}, err - } - - cmd = trimOutput(cmd) // TODO: improve `docker ps` query format. - if len(cmd) > 0 { - i := bytes.Index(cmd, []byte(process.String())) - if i == -1 { - return []string{}, fmt.Errorf("missing %s command", process) - } - return btos(cmd[i+len(process.String()):]), nil - } - } - return []string{}, nil -} - -// listHosts lists IDs of active hosts. -// It queries default environment set in configuration file. -func listHosts() ([]string, error) { - cmd := exec.Command(bin, cmdHosts, cmdHostsParams) - out, err := cmd.Output() - if err != nil { - return nil, err - } - return btos(out), nil -} - -// getPsCmdOutput returns running Kubernetes service command with its parameters. -// It queries default environment set in configuration file. -func getPsCmdOutput(host string, service check.Service) ([]byte, error) { - // Following is equivalent to: - // $ rancher --host $HOST \ - // docker ps --no-trunc \ - // --filter "label=io.rancher.stack_service.name=$SERVICE" \ - // --format "{{.Command}}" - cmd := exec.Command(bin, paramHost, host, - cmdDocker, cmdDockerCmdPs, cmdDockerCmdPsParams, - cmdDockerCmdPsFilter, cmdDockerCmdPsFilterArgs+service.String(), - cmdDockerCmdPsFormat, cmdDockerCmdPsFormatArgs) - out, err := cmd.Output() - if err != nil { - return nil, err - } - return out, nil -} - -// trimOutput removes trailing new line and brackets from output. -func trimOutput(b []byte) []byte { - b = bytes.TrimSpace(b) - b = bytes.TrimPrefix(b, []byte("[")) - b = bytes.TrimSuffix(b, []byte("]")) - return b -} - -// btos converts slice of bytes to slice of strings split by white space characters. -func btos(in []byte) []string { - var out []string - for _, b := range bytes.Fields(in) { - out = append(out, string(b)) - } - return out -} |