Skip to content

Commit

Permalink
fix: group version, namespace, vuln counter
Browse files Browse the repository at this point in the history
- 7cf2316 broke install due to group version
- support separate namespace install for kubescape
- fix vulnerability counter
  • Loading branch information
wcrum committed Apr 8, 2024
1 parent d4bfa93 commit 62fbc75
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 12 deletions.
2 changes: 1 addition & 1 deletion api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "validation.spectrocloud.labs", Version: "v1"}
GroupVersion = schema.GroupVersion{Group: "validation.spectrocloud.labs", Version: "v1alpha1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
Expand Down
11 changes: 10 additions & 1 deletion api/v1alpha1/kubescapevalidator_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import (

// KubescapeValidatorSpec defines the desired state of KubescapeValidator
type KubescapeValidatorSpec struct {
//+kubebuilder:default=kubescape
Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
// Global Severity Limit Rule
SeverityLimitRule SeverityLimitRule `json:"severityLimitRule,omitempty" yaml:"severityLimitRule,omitempty"`
// Global Ignore CVEs
IgnoredCVERule []string `json:"ignoredCVERule,omitempty" yaml:"ignoredCVERule,omitempty"`
Expand All @@ -42,7 +45,13 @@ func (r FlaggedCVE) Name() string {

// Increase for every rule
func (s KubescapeValidatorSpec) ResultCount() int {
count := 1
count := 0
if s.SeverityLimitRule != (SeverityLimitRule{}) {
count++
}
count += len(s.IgnoredCVERule)
count += len(s.FlaggedCVERule)

return count
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ spec:
items:
type: string
type: array
namespace:
default: kubescape
type: string
severityLimitRule:
description: Global Severity Limit Rule
properties:
critical:
type: integer
Expand Down
2 changes: 1 addition & 1 deletion config/default/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Adds namespace to all resources.
namespace: validator-plugin-kubescape-system
namespace: validator

# Value of this field is prepended to the
# names of all resources, e.g. a deployment named
Expand Down
4 changes: 2 additions & 2 deletions internal/controller/kubescapevalidator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (r *KubescapeValidatorReconciler) Reconcile(ctx context.Context, req ctrl.R
ValidationRuleErrors: make([]error, 0, vr.Spec.ExpectedResults),
}

kubescape, err := kubevuln.NewAPIServerStorage("kubescape")
kubescape, err := kubevuln.NewAPIServerStorage(validator.Spec.Namespace)

if err != nil {
return ctrl.Result{RequeueAfter: time.Second * 120}, errors.New("cannot connect to kubescape api storage server, is kubescape operator installed?")
Expand Down Expand Up @@ -168,7 +168,7 @@ func buildValidationResult(validator *kubescapevalidatorv1.KubescapeValidator) *
},
Spec: vapi.ValidationResultSpec{
Plugin: constants.PluginCode,
ExpectedResults: 1,
ExpectedResults: validator.Spec.ResultCount(),
},
}
}
Expand Down
19 changes: 12 additions & 7 deletions internal/validators/kubescape.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,20 @@ func (n *KubescapeService) Manifests() ([]kubescapev1.VulnerabilityManifest, err
func (n *KubescapeService) ReconcileSeverityRule(nn ktypes.NamespacedName, rule validationv1.SeverityLimitRule, ignoredCVEs []string, manifests []kubescapev1.VulnerabilityManifest) (*types.ValidationRuleResult, error) {
vr := buildValidationResult(rule, constants.ValidationTypeSeverity)

zero := 0
critical := 0
high := 0
medium := 0
low := 0
unknown := 0
negligible := 0

foundVulns := validationv1.SeverityLimitRule{
Critical: &zero,
High: &zero,
Medium: &zero,
Low: &zero,
Unknown: &zero,
Negligible: &zero,
Critical: &critical,
High: &high,
Medium: &medium,
Low: &low,
Unknown: &unknown,
Negligible: &negligible,
}

uniqueCVEs := make(map[string]bool)
Expand Down

0 comments on commit 62fbc75

Please sign in to comment.