Skip to content

Commit 9fd093e

Browse files
committed
fixup! test(e2e): Use trivy-operator for CIS benchmark
1 parent 1988893 commit 9fd093e

File tree

6 files changed

+57
-69
lines changed

6 files changed

+57
-69
lines changed

.github/workflows/e2e.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,15 @@ jobs:
105105
RUN_CIS_BENCHMARK: ${{ inputs.run-cis-benchmark }}
106106

107107
- name: Add job summary for CIS benchmark
108-
if: inputs.run-cis-benchmark
108+
if: failure() && inputs.run-cis-benchmark
109109
run: |
110-
echo "## CIS Benchmark" >>"${GITHUB_STEP_SUMMARY}"
111-
cat test/e2e/cis-benchmark-report.txt >>"${GITHUB_STEP_SUMMARY}"
110+
{
111+
echo '## CIS Benchmark';
112+
echo;
113+
echo '```plain';
114+
cat test/e2e/cis-benchmark-report.txt;
115+
echo '```';
116+
} >>"${GITHUB_STEP_SUMMARY}"
112117
113118
- if: success() || failure() # always run even if the previous step fails
114119
name: Publish e2e test report

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@ test/e2e/config/caren-envsubst.yaml
5050
hack/tools/fetch-images/fetch-images
5151
caren-images.txt
5252
hack/examples/release/*-cluster-class.yaml
53+
test/e2e/cis-benchmark-report.txt

devbox.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@
3131
"rsync@latest",
3232
"setup-envtest@latest",
3333
"shfmt@latest",
34-
"trivy@latest",
3534
"yamale@latest",
3635
"yamllint@latest",
3736
"yq-go@latest",
3837
"path:./hack/flakes#clusterctl-aws",
3938
"path:./hack/flakes#goprintconst",
4039
"path:./hack/flakes#helm-with-plugins",
40+
"path:./hack/flakes#kubescape",
4141
"path:./hack/flakes#release-please"
4242
],
4343
"shell": {

devbox.lock

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,54 +1720,6 @@
17201720
}
17211721
}
17221722
},
1723-
"trivy@latest": {
1724-
"last_modified": "2025-04-28T01:45:31Z",
1725-
"resolved": "github:NixOS/nixpkgs/29335f23bea5e34228349ea739f31ee79e267b88#trivy",
1726-
"source": "devbox-search",
1727-
"version": "0.61.1",
1728-
"systems": {
1729-
"aarch64-darwin": {
1730-
"outputs": [
1731-
{
1732-
"name": "out",
1733-
"path": "/nix/store/4s34i0ml8hxficr4v7csyigg4dy2pxhp-trivy-0.61.1",
1734-
"default": true
1735-
}
1736-
],
1737-
"store_path": "/nix/store/4s34i0ml8hxficr4v7csyigg4dy2pxhp-trivy-0.61.1"
1738-
},
1739-
"aarch64-linux": {
1740-
"outputs": [
1741-
{
1742-
"name": "out",
1743-
"path": "/nix/store/7ggs35rbylfxapxswngs0pvpisqj3cjz-trivy-0.61.1",
1744-
"default": true
1745-
}
1746-
],
1747-
"store_path": "/nix/store/7ggs35rbylfxapxswngs0pvpisqj3cjz-trivy-0.61.1"
1748-
},
1749-
"x86_64-darwin": {
1750-
"outputs": [
1751-
{
1752-
"name": "out",
1753-
"path": "/nix/store/fs9lzjqj925m9kqvlgvvrs4q4lq6f0ps-trivy-0.61.1",
1754-
"default": true
1755-
}
1756-
],
1757-
"store_path": "/nix/store/fs9lzjqj925m9kqvlgvvrs4q4lq6f0ps-trivy-0.61.1"
1758-
},
1759-
"x86_64-linux": {
1760-
"outputs": [
1761-
{
1762-
"name": "out",
1763-
"path": "/nix/store/vcqkzvwxzxij69i2jaxmfkx4zl0ywlv6-trivy-0.61.1",
1764-
"default": true
1765-
}
1766-
],
1767-
"store_path": "/nix/store/vcqkzvwxzxij69i2jaxmfkx4zl0ywlv6-trivy-0.61.1"
1768-
}
1769-
}
1770-
},
17711723
"yamale@latest": {
17721724
"last_modified": "2025-03-11T17:52:14Z",
17731725
"resolved": "github:NixOS/nixpkgs/0d534853a55b5d02a4ababa1d71921ce8f0aee4c#yamale",

hack/flakes/flake.nix

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,23 @@
106106
helm-schema
107107
];
108108
};
109+
110+
kubescape = buildGo124Module rec {
111+
name = "kubescape";
112+
version = "3.0.34";
113+
src = fetchFromGitHub {
114+
owner = "kubescape";
115+
repo = "kubescape";
116+
tag = "v${version}";
117+
hash = "sha256-dZPSnq2kLbgD/QxdDpYnAiIvXOXAgO2dXWWG6ijRUsQ=";
118+
fetchSubmodules = true;
119+
};
120+
doCheck = false;
121+
subPackages = [ "." ];
122+
proxyVendor = true;
123+
vendorHash = "sha256-+HMT8MnBc5N/19+hYtY8A4mw3IaXyvjx2a2+GnksV/4=";
124+
ldflags = [ "-s" "-w" "-X=github.com/kubescape/kubescape/v3/core/cautils.BuildNumber=v${version}" ];
125+
};
109126
};
110127

111128
formatter = alejandra;

test/e2e/quick_start_test.go

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"fmt"
1010
"os"
1111
"os/exec"
12-
"path/filepath"
1312
"slices"
1413
"strconv"
1514
"strings"
@@ -313,29 +312,43 @@ var _ = Describe("Quick start", func() {
313312
if os.Getenv("RUN_CIS_BENCHMARK") == "true" {
314313
By("Running CIS benchmark against workload cluster")
315314

316-
trivyCmd := exec.Command( //nolint:gosec // Only used for testing so safe here.
317-
"trivy",
318-
"k8s",
319-
"--compliance=k8s-cis-1.23",
320-
"--disable-node-collector",
321-
"--report=summary",
322-
fmt.Sprintf(
323-
"--output=%s",
324-
filepath.Join(
325-
os.Getenv("GIT_REPO_ROOT"),
326-
"cis-benchmark-report.txt",
327-
),
328-
),
315+
kubescapeInstallCmd := exec.Command( //nolint:gosec // Only used for testing so safe here.
316+
"helm",
317+
"upgrade",
318+
"--install",
319+
"kubescape",
320+
"--repo=https://kubescape.github.io/helm-charts/",
321+
"kubescape-operator",
322+
"--namespace=kubescape",
323+
"--create-namespace",
324+
"--wait",
325+
"--wait-for-jobs",
329326
fmt.Sprintf(
330327
"--kubeconfig=%s",
331328
workloadProxy.GetKubeconfigPath(),
332329
),
333330
)
331+
kubescapeInstallCmd.Stdout = GinkgoWriter
332+
kubescapeInstallCmd.Stderr = GinkgoWriter
333+
Expect(
334+
kubescapeInstallCmd.Run(),
335+
).To(Succeed(), "kubescape operator installation failed")
334336

335-
trivyCmd.Stdout = GinkgoWriter
336-
trivyCmd.Stderr = GinkgoWriter
337+
kubescapeScanCmd := exec.Command( //nolint:gosec // Only used for testing so safe here.
338+
"kubescape",
339+
"scan",
340+
"framework",
341+
"cis-v1.10.0",
342+
"--output=test/e2e/cis-benchmark-results.txt",
343+
"--kubeconfig",
344+
workloadProxy.GetKubeconfigPath(),
345+
)
346+
kubescapeScanCmd.Stdout = GinkgoWriter
347+
kubescapeScanCmd.Stderr = GinkgoWriter
337348

338-
Expect(trivyCmd.Run()).To(Succeed(), "CIS benchmark failed")
349+
Expect(
350+
kubescapeScanCmd.Run(),
351+
).To(Succeed(), "CIS benchmark scan failed")
339352
}
340353
},
341354
}

0 commit comments

Comments
 (0)