Skip to content

Commit

Permalink
fix(conftest): Do not show negative pass count (#488)
Browse files Browse the repository at this point in the history
Resolves: #483

Signed-off-by: Daniel Pacak <pacak.daniel@gmail.com>
  • Loading branch information
danielpacak committed Apr 10, 2021
1 parent 2584cad commit a7de614
Show file tree
Hide file tree
Showing 5 changed files with 310 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pkg/operator/controller/limit_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package controller

import (
"context"
"github.com/aquasecurity/starboard/pkg/starboard"

"github.com/aquasecurity/starboard/pkg/operator/etc"
"github.com/aquasecurity/starboard/pkg/starboard"
batchv1 "k8s.io/api/batch/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand Down
19 changes: 13 additions & 6 deletions pkg/plugin/conftest/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ func (p *plugin) GetScanJobSpec(ctx starboard.PluginContext, obj client.Object)

secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: p.idGenerator.GenerateID(),
Name: p.idGenerator.GenerateID(),
Namespace: ctx.GetNamespace(),
},
StringData: map[string]string{
"workload.yaml": string(workloadAsYAML),
Expand All @@ -86,13 +87,13 @@ func (p *plugin) GetScanJobSpec(ctx starboard.PluginContext, obj client.Object)

volumeItems = append(volumeItems, corev1.KeyToPath{
Key: "conftest.policy." + control,
Path: control + ".rego",
Path: control,
})

volumeMounts = append(volumeMounts, corev1.VolumeMount{
Name: "policies",
MountPath: "/project/policy/" + control + ".rego",
SubPath: control + ".rego",
MountPath: "/project/policy/" + control,
SubPath: control,
})

}
Expand Down Expand Up @@ -187,6 +188,9 @@ func (p *plugin) getPolicies(ctx starboard.PluginContext) ([]string, error) {
if !strings.HasPrefix(key, "conftest.policy.") {
continue
}
if !strings.HasSuffix(key, ".rego") {
continue
}
policyName := strings.TrimPrefix(key, "conftest.policy.")
policies = append(policies, policyName)
}
Expand All @@ -210,7 +214,10 @@ func (p *plugin) ParseConfigAuditReportData(logsReader io.ReadCloser) (v1alpha1.
var successesCount, warningCount, dangerCount int

for _, cr := range checkResults {
successesCount += cr.Successes
// Conftest reportedly returns negative count of passed tests is some cases: https://github.com/open-policy-agent/conftest/issues/464
if cr.Successes > 0 {
successesCount += cr.Successes
}

for _, warning := range cr.Warnings {
checks = append(checks, v1alpha1.Check{
Expand Down Expand Up @@ -252,7 +259,7 @@ func (p *plugin) ParseConfigAuditReportData(logsReader io.ReadCloser) (v1alpha1.
Version: version,
},
Summary: v1alpha1.ConfigAuditSummary{
PassCount: successesCount, // TODO This should be a pointer to tell 0 from nil
PassCount: successesCount,
WarningCount: warningCount,
DangerCount: dangerCount,
},
Expand Down

0 comments on commit a7de614

Please sign in to comment.