Skip to content

Commit

Permalink
chore: Bump up client-go to v0.19.0-alpha.3 (aquasecurity#46)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Pacak <pacak.daniel@gmail.com>
  • Loading branch information
danielpacak authored Jun 3, 2020
1 parent 55fad33 commit f5e2ad3
Show file tree
Hide file tree
Showing 46 changed files with 524 additions and 429 deletions.
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ require (
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.5.1
k8s.io/api v0.17.5
k8s.io/apiextensions-apiserver v0.17.5
k8s.io/apimachinery v0.17.5
k8s.io/cli-runtime v0.17.5
k8s.io/client-go v0.17.5
k8s.io/code-generator v0.17.5
k8s.io/api v0.19.0-alpha.3
k8s.io/apiextensions-apiserver v0.19.0-alpha.3
k8s.io/apimachinery v0.19.0-alpha.3
k8s.io/cli-runtime v0.19.0-alpha.3
k8s.io/client-go v0.19.0-alpha.3
k8s.io/code-generator v0.19.0-alpha.3
k8s.io/klog v1.0.0
k8s.io/utils v0.0.0-20191114184206-e782cd3c129f
k8s.io/utils v0.0.0-20200324210504-a9aa75ae1b89
)
161 changes: 85 additions & 76 deletions go.sum

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pkg/apis/aquasecurity/v1alpha1/cis_kube_bench_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const (
CISKubeBenchReportCRName = "ciskubebenchreports.aquasecurity.github.io"
CISKubeBenchReportCRVersion = "v1alpha1"
CISKubeBenchReportKind = "CISKubeBenchReport"
CISKubeBenchReportKindList = "CISKubeBenchReportList"
CISKubeBenchReportListKind = "CISKubeBenchReportList"
)

var (
Expand All @@ -32,7 +32,7 @@ var (
Singular: "ciskubebenchreport",
Plural: "ciskubebenchreports",
Kind: CISKubeBenchReportKind,
ListKind: CISKubeBenchReportKindList,
ListKind: CISKubeBenchReportListKind,
Categories: []string{"all"},
ShortNames: []string{"kubebench"},
},
Expand Down
6 changes: 4 additions & 2 deletions pkg/apis/aquasecurity/v1alpha1/vulnerability_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
const (
VulnerabilitiesCRName = "vulnerabilities.aquasecurity.github.io"
VulnerabilitiesCRVersion = "v1alpha1"
VulnerabilityKind = "Vulnerability"
VulnerabilityListKind = "VulnerabilityList"
)

var (
Expand All @@ -33,8 +35,8 @@ var (
Names: extv1beta1.CustomResourceDefinitionNames{
Singular: "vulnerability",
Plural: "vulnerabilities",
Kind: "Vulnerability",
ListKind: "VulnerabilityList",
Kind: VulnerabilityKind,
ListKind: VulnerabilityListKind,
Categories: []string{"all"},
ShortNames: []string{"vulns", "vuln"},
},
Expand Down
5 changes: 4 additions & 1 deletion pkg/cmd/cleanup.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cmd

import (
"context"

"github.com/aquasecurity/starboard/pkg/kube"
"github.com/spf13/cobra"
extapi "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1beta1"
Expand All @@ -13,6 +15,7 @@ func NewCleanupCmd(cf *genericclioptions.ConfigFlags) *cobra.Command {
Use: "cleanup",
Short: "Delete custom resource definitions created by starboard",
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := context.Background()
config, err := cf.ToRESTConfig()
if err != nil {
return
Expand All @@ -25,7 +28,7 @@ func NewCleanupCmd(cf *genericclioptions.ConfigFlags) *cobra.Command {
if err != nil {
return
}
err = kube.NewCRManager(clientset, clientsetext).Cleanup()
err = kube.NewCRManager(clientset, clientsetext).Cleanup(ctx)
return
},
}
Expand Down
13 changes: 8 additions & 5 deletions pkg/cmd/find_vulnerabilities.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package cmd

import (
"context"

"github.com/aquasecurity/starboard/pkg/find/vulnerabilities/crd"
"github.com/aquasecurity/starboard/pkg/find/vulnerabilities/trivy"
secapi "github.com/aquasecurity/starboard/pkg/generated/clientset/versioned"
starboardapi "github.com/aquasecurity/starboard/pkg/generated/clientset/versioned"
"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -46,6 +48,7 @@ NAME is the name of a particular Kubernetes workload.
# Scan a cronjob with the specified name
kubectl starboard find vulns cj/my-cronjob`,
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := context.Background()
ns, _, err := cf.ToRawKubeConfigLoader().Namespace()
if err != nil {
return
Expand All @@ -58,19 +61,19 @@ NAME is the name of a particular Kubernetes workload.
if err != nil {
return
}
clientset, err := kubernetes.NewForConfig(config)
kubernetesClientset, err := kubernetes.NewForConfig(config)
if err != nil {
return err
}
reports, err := trivy.NewScanner(clientset).Scan(workload)
reports, err := trivy.NewScanner(kubernetesClientset).Scan(ctx, workload)
if err != nil {
return
}
secClientset, err := secapi.NewForConfig(config)
starboardClientset, err := starboardapi.NewForConfig(config)
if err != nil {
return
}
err = crd.NewWriter(secClientset).Write(workload, reports)
err = crd.NewWriter(starboardClientset).Write(ctx, workload, reports)
return
},
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/cmd/init.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cmd

import (
"context"

"github.com/aquasecurity/starboard/pkg/kube"
"github.com/spf13/cobra"
extensionsapi "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1beta1"
Expand All @@ -13,6 +15,7 @@ func NewInitCmd(cf *genericclioptions.ConfigFlags) *cobra.Command {
Use: "init",
Short: "Create custom resource definitions used by starboard",
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := context.Background()
config, err := cf.ToRESTConfig()
if err != nil {
return
Expand All @@ -25,7 +28,7 @@ func NewInitCmd(cf *genericclioptions.ConfigFlags) *cobra.Command {
if err != nil {
return
}
err = kube.NewCRManager(clientset, clientsetext).Init()
err = kube.NewCRManager(clientset, clientsetext).Init(ctx)
return
},
}
Expand Down
7 changes: 5 additions & 2 deletions pkg/cmd/kube_bench.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cmd

import (
"context"

"github.com/aquasecurity/starboard/pkg/ext"
starboard "github.com/aquasecurity/starboard/pkg/generated/clientset/versioned"
"github.com/aquasecurity/starboard/pkg/kubebench"
Expand All @@ -15,6 +17,7 @@ func NewKubeBenchCmd(cf *genericclioptions.ConfigFlags) *cobra.Command {
Use: "kube-bench",
Short: "Run the CIS Kubernetes Benchmark https://www.cisecurity.org/benchmark/kubernetes",
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := context.Background()
config, err := cf.ToRESTConfig()
if err != nil {
return
Expand All @@ -23,15 +26,15 @@ func NewKubeBenchCmd(cf *genericclioptions.ConfigFlags) *cobra.Command {
if err != nil {
return
}
report, node, err := kubebench.NewScanner(kubernetesClientset).Scan()
report, node, err := kubebench.NewScanner(kubernetesClientset).Scan(ctx)
if err != nil {
return
}
starboardClientset, err := starboard.NewForConfig(config)
if err != nil {
return
}
err = crd.NewWriter(ext.NewSystemClock(), starboardClientset).Write(report, node)
err = crd.NewWriter(ext.NewSystemClock(), starboardClientset).Write(ctx, report, node)
return
},
}
Expand Down
12 changes: 8 additions & 4 deletions pkg/cmd/kube_hunter.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package cmd

import (
"context"

starboardapi "github.com/aquasecurity/starboard/pkg/generated/clientset/versioned"
"github.com/aquasecurity/starboard/pkg/kubehunter"
"github.com/aquasecurity/starboard/pkg/kubehunter/crd"
"github.com/spf13/cobra"
Expand All @@ -13,23 +16,24 @@ func NewKubeHunterCmd(cf *genericclioptions.ConfigFlags) *cobra.Command {
Use: "kube-hunter",
Short: "Hunt for security weaknesses",
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := context.Background()
config, err := cf.ToRESTConfig()
if err != nil {
return
}
clientset, err := kubernetes.NewForConfig(config)
kubernetesClientset, err := kubernetes.NewForConfig(config)
if err != nil {
return
}
report, err := kubehunter.NewScanner(clientset).Scan()
report, err := kubehunter.NewScanner(kubernetesClientset).Scan(ctx)
if err != nil {
return
}
writer, err := crd.NewWriter(config)
starboardClientset, err := starboardapi.NewForConfig(config)
if err != nil {
return
}
err = writer.Write(report, "cluster")
err = crd.NewWriter(starboardClientset).Write(ctx, report, "cluster")
if err != nil {
return
}
Expand Down
7 changes: 5 additions & 2 deletions pkg/cmd/polaris.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cmd

import (
"context"

starboard "github.com/aquasecurity/starboard/pkg/generated/clientset/versioned"
"github.com/aquasecurity/starboard/pkg/polaris"
"github.com/aquasecurity/starboard/pkg/polaris/crd"
Expand All @@ -14,6 +16,7 @@ func NewPolarisCmd(cf *genericclioptions.ConfigFlags) *cobra.Command {
Use: "polaris",
Short: "Run a variety of checks to ensure that Kubernetes pods and controllers are configured using best practices",
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := context.Background()
config, err := cf.ToRESTConfig()
if err != nil {
return
Expand All @@ -22,15 +25,15 @@ func NewPolarisCmd(cf *genericclioptions.ConfigFlags) *cobra.Command {
if err != nil {
return
}
reports, err := polaris.NewScanner(clientset).Scan()
reports, err := polaris.NewScanner(clientset).Scan(ctx)
if err != nil {
return
}
starboardClientset, err := starboard.NewForConfig(config)
if err != nil {
return
}
err = crd.NewWriter(starboardClientset).WriteAll(reports)
err = crd.NewWriter(starboardClientset).WriteAll(ctx, reports)
if err != nil {
return
}
Expand Down
13 changes: 7 additions & 6 deletions pkg/find/vulnerabilities/crd/writer.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package crd

import (
"context"
"fmt"

"github.com/aquasecurity/starboard/pkg/kube"

sec "github.com/aquasecurity/starboard/pkg/apis/aquasecurity/v1alpha1"
starboard "github.com/aquasecurity/starboard/pkg/apis/aquasecurity/v1alpha1"
"github.com/aquasecurity/starboard/pkg/find/vulnerabilities"
clientset "github.com/aquasecurity/starboard/pkg/generated/clientset/versioned"
"github.com/google/uuid"
Expand All @@ -22,18 +23,18 @@ func NewWriter(client clientset.Interface) vulnerabilities.Writer {
}
}

func (s *writer) Write(workload kube.Workload, reports map[string]sec.VulnerabilityReport) (err error) {
func (s *writer) Write(ctx context.Context, workload kube.Workload, reports map[string]starboard.VulnerabilityReport) (err error) {
for container, report := range reports {
err = s.createVulnerability(workload, container, report)
err = s.createVulnerability(ctx, workload, container, report)
if err != nil {
return
}
}
return
}

func (s *writer) createVulnerability(workload kube.Workload, container string, report sec.VulnerabilityReport) (err error) {
_, err = s.client.AquasecurityV1alpha1().Vulnerabilities(workload.Namespace).Create(&sec.Vulnerability{
func (s *writer) createVulnerability(ctx context.Context, workload kube.Workload, container string, report starboard.VulnerabilityReport) (err error) {
_, err = s.client.AquasecurityV1alpha1().Vulnerabilities(workload.Namespace).Create(ctx, &starboard.Vulnerability{
ObjectMeta: meta.ObjectMeta{
Name: fmt.Sprintf(uuid.New().String()),
Labels: map[string]string{
Expand All @@ -43,7 +44,7 @@ func (s *writer) createVulnerability(workload kube.Workload, container string, r
},
},
Report: report,
})
}, meta.CreateOptions{})

return err
}
5 changes: 3 additions & 2 deletions pkg/find/vulnerabilities/scanner.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package vulnerabilities

import (
"context"
sec "github.com/aquasecurity/starboard/pkg/apis/aquasecurity/v1alpha1"
"github.com/aquasecurity/starboard/pkg/kube"
core "k8s.io/api/core/v1"
)

type Scanner interface {
Scan(workload kube.Workload) (reports map[string]sec.VulnerabilityReport, err error)
ScanByPodSpec(workload kube.Workload, spec core.PodSpec) (reports map[string]sec.VulnerabilityReport, err error)
Scan(ctx context.Context, workload kube.Workload) (reports map[string]sec.VulnerabilityReport, err error)
ScanByPodSpec(ctx context.Context, workload kube.Workload, spec core.PodSpec) (reports map[string]sec.VulnerabilityReport, err error)
}
Loading

0 comments on commit f5e2ad3

Please sign in to comment.