Compare commits

...

851 Commits

Author SHA1 Message Date
Matthias Bertschy
b167435c4d Merge pull request #1941 from kubescape/semver
fix isRuleKubescapeVersionCompatible bug with version 4.0.0
2026-02-12 15:14:45 +00:00
Matthias Bertschy
9b29321a53 Enhance version testing in smoke tests to extract and validate output version
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2026-02-12 14:56:31 +01:00
Matthias Bertschy
466a11fa1c fix isRuleKubescapeVersionCompatible bug with version 4.0.0
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2026-02-12 14:08:03 +01:00
Matthias Bertschy
cfe022ff1d Use TagName directly in .krew.yaml templates 2026-02-04 18:16:34 +01:00
Matthias Bertschy
e0eeb691e6 Make version smoke test accept bytes and v-prefix 2026-02-04 17:44:39 +01:00
Matthias Bertschy
dc65bd4ccc force overridden ldflags in goreleaser
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2026-02-04 17:19:54 +01:00
Matthias Bertschy
02790da144 remove invalid build flag
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2026-02-04 11:42:11 +01:00
Matthias Bertschy
b97f50ffb5 fix version handling and injection
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2026-02-04 10:42:12 +01:00
Matthias Bertschy
0841d1d483 Merge pull request #1939 from kubescape/feat/performance-optimization-phases-1-3
feat: Optimize CPU and Memory Usage for Resource-Intensive Scans
2026-02-04 07:47:47 +00:00
Matthias Bertschy
fbef268f22 feat: optimize CPU and memory usage for resource-intensive scans
Implement Phases 1-3 of the performance optimization plan to address
issue #1793 - reduce CPU and memory consumption for system-constrained
environments.

Phase 1 - OPA Module Caching:
- Add compiledModules cache to OPAProcessor with thread-safe access
- Cache compiled OPA rules to eliminate redundant compilation
- Reuse compiled modules with double-checked locking pattern
- Expected CPU savings: 30-40%

Phase 2 - Map Pre-sizing:
- Add estimateClusterSize() to calculate resource count
- Pre-size AllResources, ResourcesResult, and related maps
- Reduce memory reallocations and GC pressure
- Expected memory savings: 10-20%

Phase 3 - Set-based Deduplication:
- Add thread-safe StringSet utility in core/pkg/utils
- Replace O(n) slices.Contains() with O(1) map operations
- Use StringSet for image scanning and related resources deduplication
- 100% test coverage for new utility
- Expected CPU savings: 5-10% for large clusters

Full optimization plan documented in optimization-plan.md

Related: #1793
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2026-02-04 08:07:54 +01:00
Matthias Bertschy
427dccadd3 Merge pull request #1934 from kubescape/krew
Add krew plugin manifest
2026-02-03 17:12:33 +00:00
Matthias Bertschy
01bb19bf6e Add krew plugin manifest
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2026-02-03 17:58:30 +01:00
Matthias Bertschy
c0d4bb45eb Merge pull request #1937 from kubescape/dependabot/go_modules/github.com/theupdateframework/go-tuf/v2-2.4.1
build(deps): Bump github.com/theupdateframework/go-tuf/v2 from 2.3.1 to 2.4.1
2026-02-03 14:50:06 +00:00
Matthias Bertschy
222c1ec866 Merge pull request #1931 from Mujib-Ahasan/readmd-update
Fix broken README table of contents anchor links
2026-02-03 14:44:36 +00:00
dependabot[bot]
dc49218c7c build(deps): Bump github.com/theupdateframework/go-tuf/v2
Bumps [github.com/theupdateframework/go-tuf/v2](https://github.com/theupdateframework/go-tuf) from 2.3.1 to 2.4.1.
- [Release notes](https://github.com/theupdateframework/go-tuf/releases)
- [Commits](https://github.com/theupdateframework/go-tuf/compare/v2.3.1...v2.4.1)

---
updated-dependencies:
- dependency-name: github.com/theupdateframework/go-tuf/v2
  dependency-version: 2.4.1
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2026-02-03 13:12:03 +01:00
Matthias Bertschy
3b4585a827 Merge pull request #1932 from kubescape/scan-images
add verbose option to scan-images
2026-02-02 19:30:00 +00:00
Matthias Bertschy
7f79bc2d1d Sort CVEs by severity then ID
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2026-02-02 17:51:43 +01:00
Matthias Bertschy
3623e55433 feat: add image column to vulnerability scanning table output
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2026-02-02 17:51:43 +01:00
Matthias Bertschy
2f7841b5a2 update policy.json testdata
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2026-02-02 17:51:43 +01:00
Matthias Bertschy
f70d81d7c4 add verbose option to scan-images
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2026-02-02 17:51:43 +01:00
Matthias Bertschy
bd49251234 Merge pull request #1936 from kubescape/lint
fix all linter errors
2026-02-02 16:50:48 +00:00
Matthias Bertschy
57addd493f fix all linter errors
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2026-02-02 17:32:08 +01:00
Matthias Bertschy
8f009d4698 Merge pull request #1935 from kubescape/run_test_from_private_repo
run system test from private repo
2026-02-02 08:35:08 +00:00
bvolovat
7c0e38072d run system test from private repo 2026-02-02 10:22:00 +02:00
bvolovat
aa9a610c4c run system test from private repo 2026-02-02 10:03:25 +02:00
Bezbran
25bd51e8b4 Replace host sensor with node agent sensing (#1916)
In this change I used both claude code and Antigravity.

---------

Signed-off-by: Bezalel Brandwine <bez@softwine.net>
2026-02-01 13:17:03 +02:00
Mujib Ahasan
2759beece5 Fix broken README anchors
Signed-off-by: Mujib Ahasan <ahasanmujib8@gmail.com>
2026-01-26 02:25:55 +05:30
Matthias Bertschy
6ce0121a03 Merge pull request #1928 from kubescape/dependabot/go_modules/github.com/sigstore/rekor-1.5.0
build(deps): Bump github.com/sigstore/rekor from 1.4.3 to 1.5.0
2026-01-22 20:24:28 +00:00
Matthias Bertschy
09aa1ab866 Merge pull request #1927 from kubescape/dependabot/go_modules/github.com/theupdateframework/go-tuf/v2-2.3.1
build(deps): Bump github.com/theupdateframework/go-tuf/v2 from 2.3.0 to 2.3.1
2026-01-22 20:24:08 +00:00
dependabot[bot]
0ec188b23d build(deps): Bump github.com/sigstore/rekor from 1.4.3 to 1.5.0
Bumps [github.com/sigstore/rekor](https://github.com/sigstore/rekor) from 1.4.3 to 1.5.0.
- [Release notes](https://github.com/sigstore/rekor/releases)
- [Changelog](https://github.com/sigstore/rekor/blob/main/CHANGELOG.md)
- [Commits](https://github.com/sigstore/rekor/compare/v1.4.3...v1.5.0)

---
updated-dependencies:
- dependency-name: github.com/sigstore/rekor
  dependency-version: 1.5.0
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2026-01-22 20:50:11 +01:00
dependabot[bot]
090820ba04 build(deps): Bump github.com/theupdateframework/go-tuf/v2
Bumps [github.com/theupdateframework/go-tuf/v2](https://github.com/theupdateframework/go-tuf) from 2.3.0 to 2.3.1.
- [Release notes](https://github.com/theupdateframework/go-tuf/releases)
- [Commits](https://github.com/theupdateframework/go-tuf/compare/v2.3.0...v2.3.1)

---
updated-dependencies:
- dependency-name: github.com/theupdateframework/go-tuf/v2
  dependency-version: 2.3.1
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2026-01-22 20:49:44 +01:00
Matthias Bertschy
0cf24d058f Merge pull request #1926 from kubescape/copilot/fix-kubescan-interface-error
Fix panic on unsafe interface{} to string type assertions
2026-01-22 19:43:25 +00:00
copilot-swe-agent[bot]
c32e665809 Final verification - all changes complete
Co-authored-by: matthyx <20683409+matthyx@users.noreply.github.com>
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2026-01-22 17:13:09 +01:00
copilot-swe-agent[bot]
82ec11b207 Fix indentation in test file
Co-authored-by: matthyx <20683409+matthyx@users.noreply.github.com>
2026-01-22 12:42:42 +00:00
copilot-swe-agent[bot]
32a15acdea Add test for CheckShortTerminalWidth with non-string values
Co-authored-by: matthyx <20683409+matthyx@users.noreply.github.com>
2026-01-22 12:41:14 +00:00
copilot-swe-agent[bot]
837a50c903 Fix unsafe interface to string type assertions to prevent panic
Co-authored-by: matthyx <20683409+matthyx@users.noreply.github.com>
2026-01-22 12:37:43 +00:00
copilot-swe-agent[bot]
bd00d153e9 Initial plan 2026-01-22 12:33:31 +00:00
Matthias Bertschy
306050046d Merge pull request #1923 from kubescape/dependabot/go_modules/github.com/sigstore/fulcio-1.8.5
build(deps): Bump github.com/sigstore/fulcio from 1.8.4 to 1.8.5
2026-01-20 07:41:16 +00:00
dependabot[bot]
413db87e85 build(deps): Bump github.com/sigstore/fulcio from 1.8.4 to 1.8.5
Bumps [github.com/sigstore/fulcio](https://github.com/sigstore/fulcio) from 1.8.4 to 1.8.5.
- [Release notes](https://github.com/sigstore/fulcio/releases)
- [Changelog](https://github.com/sigstore/fulcio/blob/main/CHANGELOG.md)
- [Commits](https://github.com/sigstore/fulcio/compare/v1.8.4...v1.8.5)

---
updated-dependencies:
- dependency-name: github.com/sigstore/fulcio
  dependency-version: 1.8.5
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2026-01-20 08:07:08 +01:00
Matthias Bertschy
4d3b3efb9a Merge pull request #1922 from kubescape/copilot/fix-kubescape-report-discrepancy
Fix workload scan to include allcontrols framework
2026-01-16 15:18:11 +00:00
copilot-swe-agent[bot]
7ca609d39f Complete fix for workload scan missing controls
Co-authored-by: matthyx <20683409+matthyx@users.noreply.github.com>
2026-01-16 15:03:01 +00:00
copilot-swe-agent[bot]
872c0c9fab Fix workload scan to include allcontrols framework
Co-authored-by: matthyx <20683409+matthyx@users.noreply.github.com>
2026-01-16 14:58:58 +00:00
copilot-swe-agent[bot]
9353eb5b54 Initial plan 2026-01-16 14:49:43 +00:00
Matthias Bertschy
aa62fbea68 Merge pull request #1921 from kubescape/buildnumber
Update build number retrieval and permissions in workflow
2026-01-16 12:21:04 +00:00
Matthias Bertschy
08d964b631 Update golangci-lint action to version 9
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2026-01-16 12:39:54 +01:00
Matthias Bertschy
75fb07efde Update build number retrieval and permissions in workflow
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2026-01-16 12:18:19 +01:00
Matthias Bertschy
9445e0aa01 Merge pull request #1920 from kubescape/dependabot/go_modules/github.com/sigstore/cosign/v3-3.0.4
build(deps): Bump github.com/sigstore/cosign/v3 from 3.0.3-0.20251208232815-901b44d65952 to 3.0.4
2026-01-16 10:45:55 +00:00
Matthias Bertschy
ea12643a3c Fix workflow YAML formatting and permissions
Reformat the 00-pr-scanner workflow for consistent indentation. Add
artifact-metadata: read to pr-scanner permissions, include GO111MODULE
in the pr-scanner inputs, and set fetch-depth/submodules on the
actions/checkout step
2026-01-16 11:42:55 +01:00
dependabot[bot]
0c42b41dcc build(deps): Bump github.com/sigstore/cosign/v3
Bumps [github.com/sigstore/cosign/v3](https://github.com/sigstore/cosign) from 3.0.3-0.20251208232815-901b44d65952 to 3.0.4.
- [Release notes](https://github.com/sigstore/cosign/releases)
- [Changelog](https://github.com/sigstore/cosign/blob/main/CHANGELOG.md)
- [Commits](https://github.com/sigstore/cosign/commits/v3.0.4)

---
updated-dependencies:
- dependency-name: github.com/sigstore/cosign/v3
  dependency-version: 3.0.4
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2026-01-16 11:31:31 +01:00
Amir Malka
351f957083 update test lists (#1919) 2026-01-11 21:50:37 +02:00
Matthias Bertschy
9d876b14e9 Merge pull request #1918 from AndrewCharlesHay/patch-1
ci: update scorecard action version
2026-01-06 14:22:11 +00:00
Andy Hay
895233630f ci: update scorecard action version
Signed-off-by: Andy Hay <39sumer3939@gmail.com>
2026-01-05 16:44:26 -05:00
Matthias Bertschy
423d9c5c1f Merge pull request #1917 from BroderPeters/master
Add SkipPersistence flag to MetricsQueryParams in metrics endpoint
2026-01-05 12:48:35 +00:00
Broder Peters
3f3681a4cd Add SkipPersistence flag to MetricsQueryParams in metrics endpoint
Signed-off-by: Broder Peters <broder.peters@protonmail.com>
2026-01-05 13:24:21 +01:00
Matthias Bertschy
d6ccc37640 Merge pull request #1915 from majiayu000/fix-1660-define-labels-to-copy-from-wor-1231-0603
feat: Define labels to copy from workloads to reports
2026-01-05 06:50:47 +00:00
Matthias Bertschy
3b6bc00b03 Merge pull request #1914 from majiayu000/fix-1617-kustomize-directory-analysis-n-1231-0603
fix: Kustomize directory analysis not working
2026-01-05 06:45:06 +00:00
Matthias Bertschy
8984f941ab Update README to include GoReleaser installation and usage instructions
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2026-01-05 07:27:39 +01:00
majiayu000
46eb266064 feat: add labels-to-copy flag to copy workload labels to reports
Add a new --labels-to-copy CLI flag that allows users to specify which
labels from Kubernetes workloads should be extracted and included in
scan reports. This makes it easier to tie scan results back to app
teams or repositories by including relevant labels like 'app', 'team',
or 'environment' in the report output.

Changes:
- Add LabelsToCopy field to ScanInfo and OPASessionObj structs
- Add --labels-to-copy flag to scan command
- Add ResourceLabels field to PostureReportWithSeverity for JSON output
- Implement extractResourceLabels function to extract specified labels
- Add unit tests for label extraction functionality

Fixes #1660

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: majiayu000 <1835304752@qq.com>
2025-12-31 06:20:29 +08:00
majiayu000
0f2125817b fix: enable kustomize overlays to load base configurations
Fixes #1617. The kustomize build was failing for overlays that reference
base configurations in parent directories (e.g., ../../base). This was
because krusty.MakeDefaultOptions() defaults to LoadRestrictionsRootOnly,
which prevents loading resources from outside the kustomize directory.

Changed LoadRestrictions to LoadRestrictionsNone to allow overlays to
properly resolve and merge base configurations during scanning.

Added tests to verify:
- Overlay directories can successfully load resources from base directories
- Base directories continue to work as before
- The merged configuration includes resources from both base and overlay

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: majiayu000 <1835304752@qq.com>
2025-12-31 06:14:10 +08:00
Matthias Bertschy
1225540590 Merge pull request #1913 from oglok/fix-typos-in-docs
Fix typos in documentation
2025-12-30 21:55:50 +01:00
Ricardo Noriega De Soto
0e4ff13276 Fix typos in documentation
Signed-off-by: Ricardo Noriega De Soto <rnoriega@redhat.com>
2025-12-30 21:03:50 +01:00
Matthias Bertschy
5fed9cc507 Enhance installation scripts for cross-platform support and improve error handling
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-12-15 08:52:05 +01:00
Matthias Bertschy
06241fce03 Refactor release workflow to simplify tagging and remove unnecessary inputs
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-12-15 08:08:07 +01:00
Matthias Bertschy
2b91023c6b Update release workflow to include tagging in arguments
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-12-15 07:59:26 +01:00
Matthias Bertschy
082edf52d9 Refactor GitHub Actions workflow for system tests and update smoke test logging
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-12-15 07:47:09 +01:00
Matthias Bertschy
be250ff090 Add debug listing and adjust JUnit report options 2025-12-12 22:50:32 +01:00
Matthias Bertschy
d74803af28 Add skip flag and collect system test results
Add workflow input skip_system_tests and make RUN_E2E respect it. Add
System Tests Report step to publish JUnit XMLs. Update
goreleaser-post-e2e.sh to add GitHub Actions log grouping, capture
per-test logs under test-results/system-tests, and copy JUnit XML
results while preserving directory structure.
2025-12-12 22:24:30 +01:00
Matthias Bertschy
893bb86035 Add production secrets to release workflow 2025-12-12 21:40:29 +01:00
Matthias Bertschy
314a74b817 Require Python 3.9 for system tests
Update CI workflow and goreleaser post-e2e script to use Python 3.9.
Rename SYSTEST_REQUIRE_PY311 to SYSTEST_REQUIRE_PY39, prefer python3.9,
and change version checks to refuse venvs created with Python 3.10+. If
python3.9 is missing or wrong, honor E2E_FAIL_ON_ERROR: either fail the
release or skip system tests and clean up.
2025-12-12 21:25:01 +01:00
Matthias Bertschy
997bc2d23b Use python3-dev in release workflow 2025-12-12 21:10:24 +01:00
Matthias Bertschy
5d1699291a Install system dependencies in release workflow
Add apt-get step to install libpq5, libpq-dev, gcc, and python3.11-dev
for system tests and clean apt lists
2025-12-12 16:16:48 +01:00
Matthias Bertschy
bfca19bf25 Remove pip cache from release workflow 2025-12-12 15:59:11 +01:00
Matthias Bertschy
1b94d27fd6 Require Python 3.11 for system tests 2025-12-12 15:56:12 +01:00
Matthias Bertschy
acf7ad04ed fix go mod tidy
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-12-12 15:36:56 +01:00
Matthias Bertschy
0f5775065e fix: prefer Python 3.11 for system-tests and update environment setup
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-12-12 15:36:37 +01:00
Matthias Bertschy
66fbca8f24 Merge pull request #1911 from kubescape/copilot/fix-local-file-path-issue
Fix: Prevent self-hosted git URLs from being treated as local file paths
2025-12-12 15:14:43 +01:00
Matthias Bertschy
1f8de23a65 fix: update post-build hook to conditionally execute script for amd64 architecture
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-12-12 14:56:03 +01:00
Matthias Bertschy
89478eabcc fix: add k8s Kind cluster creation step and clean up post-e2e script
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-12-12 14:51:43 +01:00
Matthias Bertschy
6be9aec5b0 fix: update test_command and test_scan to remove deprecated scan commands and adjust file paths
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-12-12 14:39:11 +01:00
Matthias Bertschy
32551275ba fix: correct post-build hook syntax for setting GOARCH environment variable
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-12-12 14:31:27 +01:00
Matthias Bertschy
4ee6238244 fix: update post-build hook to set GOARCH environment variable
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-12-12 14:22:07 +01:00
Matthias Bertschy
54dda8bf31 fix: enable end-to-end tests in release workflow
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-12-12 14:09:26 +01:00
Matthias Bertschy
270b3b320d fix: enhance release workflow with optional skip publish input and add system tests execution
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-12-12 13:19:52 +01:00
Matthias Bertschy
fa17ca26e1 fix: enhance release workflow with optional skip publish input and add system tests execution
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-12-12 12:47:23 +01:00
copilot-swe-agent[bot]
66e970a3dc Update go-git-url to v0.0.31 for improved URL parsing
Co-authored-by: matthyx <20683409+matthyx@users.noreply.github.com>
2025-12-11 16:59:59 +00:00
Matthias Bertschy
d10d08c02b fix: update e2e script to enforce fatal failures and improve artifact detection
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-12-11 15:22:48 +01:00
copilot-swe-agent[bot]
8d7c595a76 Address code review feedback: Extract helper function and improve comments
- Add isHTTPURL helper function for better code reusability
- Improve comments to clarify why ContextDir is returned
- Enhance error message for unrecognized git repositories

Co-authored-by: matthyx <20683409+matthyx@users.noreply.github.com>
2025-12-11 09:16:12 +00:00
copilot-swe-agent[bot]
621ffd3ead Fix: Prevent URLs from being treated as local file paths
- Add URL detection (http:// and https://) in getScanningContext
- Prevent URLs from being joined with current working directory
- Add test cases for self-hosted GitLab URLs
- Ensure proper error handling when git clone fails

Co-authored-by: matthyx <20683409+matthyx@users.noreply.github.com>
2025-12-11 09:08:12 +00:00
copilot-swe-agent[bot]
5dee6d0e4f Initial plan 2025-12-11 08:57:35 +00:00
Matthias Bertschy
f516853af8 fix: update kubescape krew configuration to skip upload
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-12-11 07:42:00 +01:00
Matthias Bertschy
0d01329683 fix: add commit author information to goreleaser configuration
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-12-11 07:12:40 +01:00
Matthias Bertschy
5a0f5f98c1 fix: update krew index pull request configuration to specify owner and name
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-12-10 22:49:11 +01:00
Matthias Bertschy
771fc4acca fix: correct kubescape repository owner in goreleaser configuration
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-12-10 22:30:54 +01:00
Matthias Bertschy
68a9d0cf60 fix: update GITHUB_TOKEN handling and correct kubescape repository owner in configuration
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-12-10 22:06:49 +01:00
Matthias Bertschy
d2bc957500 fix: update kubescape krew configuration to use repository field
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-12-10 21:52:32 +01:00
Matthias Bertschy
d20ec9e471 feat: add kubescape krew index to goreleaser configuration
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-12-10 21:47:48 +01:00
Matthias Bertschy
d3824028c5 feat: add QEMU and Docker Buildx setup steps in release workflow
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-12-10 21:30:40 +01:00
Matthias Bertschy
5013f91814 feat: add Syft setup step in release workflow
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-12-10 21:16:24 +01:00
Matthias Bertschy
41e47c3ad3 fix: update runner to ubuntu-large in release configuration
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-12-10 19:15:48 +01:00
Matthias Bertschy
acfe986863 fix: add cosign.key to .gitignore
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-12-10 18:41:39 +01:00
Matthias Bertschy
abafa9eafa fix: remove unnecessary secrets inheritance in release configuration
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-12-10 18:35:10 +01:00
Matthias Bertschy
dce1ee4dc6 cleaning up release action
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-12-10 18:31:25 +01:00
Matthias Bertschy
62a143326c Merge pull request #1816 from kubescape/goreleaser
use goreleaser for all builds and release publication
2025-12-10 07:58:52 +01:00
Matthias Bertschy
d72a6005bb use goreleaser for all builds and release publication
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-12-10 07:43:21 +01:00
Matthias Bertschy
adb9b80442 Merge pull request #1903 from Mujib-Ahasan/skip-persistence
Add `skipPersistence` query parameter to `/v1/metrics`
2025-12-09 17:46:12 +01:00
Mujib Ahasan
cb7cca7b44 fix: log added and minor fixes applied
Signed-off-by: Mujib Ahasan <ahasanmujib8@gmail.com>
2025-12-09 22:07:29 +05:30
Matthias Bertschy
f38bec9314 fix go mod tidy
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-12-09 17:29:51 +01:00
Matthias Bertschy
fff663bed4 Merge pull request #1907 from kubescape/dependabot/go_modules/github.com/containerd/containerd/v2-2.1.5
Bump github.com/containerd/containerd/v2 from 2.1.4 to 2.1.5
2025-12-09 12:29:17 +01:00
dependabot[bot]
6a72851182 Bump github.com/containerd/containerd/v2 from 2.1.4 to 2.1.5
Bumps [github.com/containerd/containerd/v2](https://github.com/containerd/containerd) from 2.1.4 to 2.1.5.
- [Release notes](https://github.com/containerd/containerd/releases)
- [Changelog](https://github.com/containerd/containerd/blob/main/RELEASES.md)
- [Commits](https://github.com/containerd/containerd/compare/v2.1.4...v2.1.5)

---
updated-dependencies:
- dependency-name: github.com/containerd/containerd/v2
  dependency-version: 2.1.5
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-12-09 12:12:46 +01:00
Matthias Bertschy
e4962fe934 Merge pull request #1906 from kubescape/cosign
Update cosign package to v3 and adjust go.mod dependencies
2025-12-09 12:11:42 +01:00
Matthias Bertschy
dac3af19a3 Update cosign package to v3 and adjust go.mod dependencies
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-12-09 11:57:01 +01:00
Matthias Bertschy
0b44e94b67 Merge pull request #1905 from kubescape/cosign
Update cosign package to v3 and adjust go.mod dependencies
2025-12-09 11:44:07 +01:00
Matthias Bertschy
df37457504 Update cosign package to v3 and adjust go.mod dependencies
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-12-09 11:24:29 +01:00
Matthias Bertschy
f88a374b6d Merge pull request #1904 from kubescape/dependabot/go_modules/github.com/sigstore/fulcio-1.8.3
Bump github.com/sigstore/fulcio from 1.6.6 to 1.8.3
2025-12-09 10:46:10 +01:00
dependabot[bot]
47442f954c Bump github.com/sigstore/fulcio from 1.6.6 to 1.8.3
Bumps [github.com/sigstore/fulcio](https://github.com/sigstore/fulcio) from 1.6.6 to 1.8.3.
- [Release notes](https://github.com/sigstore/fulcio/releases)
- [Changelog](https://github.com/sigstore/fulcio/blob/main/CHANGELOG.md)
- [Commits](https://github.com/sigstore/fulcio/compare/v1.6.6...v1.8.3)

---
updated-dependencies:
- dependency-name: github.com/sigstore/fulcio
  dependency-version: 1.8.3
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-12-09 10:32:26 +01:00
Mujib Ahasan
efbb8e8367 feature: skipPersistence request parameter added
Signed-off-by: Mujib Ahasan <ahasanmujib8@gmail.com>
2025-12-05 22:18:35 +05:30
Matthias Bertschy
60d7276de3 Merge pull request #1901 from kubescape/copilot/fix-cis-framework-metrics-export
Fix CIS framework metrics not exported to Prometheus /v1/metrics endpoint
2025-12-05 09:45:06 +01:00
copilot-swe-agent[bot]
c05427ff38 Remove KS_METRICS_FRAMEWORKS environment variable support
Co-authored-by: matthyx <20683409+matthyx@users.noreply.github.com>
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-12-05 09:43:49 +01:00
Matthias Bertschy
3e245da02b Merge pull request #1902 from kubescape/copilot/fix-air-gapped-configuration
Fix air-gapped mode network access attempts
2025-12-05 08:44:50 +01:00
copilot-swe-agent[bot]
cc7aae470f Fix typo in comment: fom -> from
Co-authored-by: matthyx <20683409+matthyx@users.noreply.github.com>
2025-12-04 13:47:52 +00:00
copilot-swe-agent[bot]
8d59a6074e Add frameworks query parameter to /v1/metrics endpoint
Co-authored-by: matthyx <20683409+matthyx@users.noreply.github.com>
2025-12-04 13:45:55 +00:00
copilot-swe-agent[bot]
1f7dd6e5f5 Fix incorrect comment about default output format
Co-authored-by: matthyx <20683409+matthyx@users.noreply.github.com>
2025-12-04 13:31:52 +00:00
copilot-swe-agent[bot]
bf5ca3c1f0 Add KS_METRICS_FRAMEWORKS env var to allow selecting specific frameworks
Co-authored-by: matthyx <20683409+matthyx@users.noreply.github.com>
2025-12-04 13:30:11 +00:00
copilot-swe-agent[bot]
a8574c61ea Fix: properly handle nil downloadReleasedPolicy in getters
Ensure getter functions handle nil downloadReleasedPolicy correctly by creating a new instance when needed, maintaining backward compatibility with existing code while supporting air-gapped mode.

Co-authored-by: matthyx <20683409+matthyx@users.noreply.github.com>
2025-12-03 21:19:39 +00:00
copilot-swe-agent[bot]
6f9c0ae85f Address code review feedback
- Fix string field checks in isAirGappedMode (use != "" instead of len() > 0)
- Use centralized isAirGappedMode function in getResourceHandler
- Improve comment clarity to reflect all air-gapped conditions

Co-authored-by: matthyx <20683409+matthyx@users.noreply.github.com>
2025-12-03 21:14:04 +00:00
copilot-swe-agent[bot]
be2c74e48a Add test for isAirGappedMode function
Add comprehensive tests to verify air-gapped mode detection logic.

Co-authored-by: matthyx <20683409+matthyx@users.noreply.github.com>
2025-12-03 21:11:18 +00:00
copilot-swe-agent[bot]
68da73855f Refactor: Extract isAirGappedMode helper function
Extract complex boolean condition into a dedicated helper function for better readability and maintainability.

Co-authored-by: matthyx <20683409+matthyx@users.noreply.github.com>
2025-12-03 21:06:52 +00:00
copilot-swe-agent[bot]
5b3f2d0ff9 Fix air-gapped mode to prevent network access
- Skip version check when --keep-local flag is set
- Skip DownloadReleasedPolicy initialization when in air-gapped mode
- Skip KSCloudAPIConnector initialization when --keep-local is set

Co-authored-by: matthyx <20683409+matthyx@users.noreply.github.com>
2025-12-03 21:03:01 +00:00
copilot-swe-agent[bot]
02637c7a8e Initial plan 2025-12-03 20:50:40 +00:00
Matthias Bertschy
7d5b374f9d Merge pull request #1900 from kubescape/copilot/fix-severity-missing-json
Add severity field to controls in JSON output
2025-12-03 21:44:49 +01:00
copilot-swe-agent[bot]
1dd6d7a1b3 Address code review feedback: nil check and trailing whitespace
Co-authored-by: matthyx <20683409+matthyx@users.noreply.github.com>
2025-12-03 16:46:11 +00:00
copilot-swe-agent[bot]
6b80b85555 Add tests for results enrichment with severity
Co-authored-by: matthyx <20683409+matthyx@users.noreply.github.com>
2025-12-03 16:42:03 +00:00
copilot-swe-agent[bot]
d88bc067e2 Add severity to controls in results section as well
Co-authored-by: matthyx <20683409+matthyx@users.noreply.github.com>
2025-12-03 16:40:48 +00:00
copilot-swe-agent[bot]
ba78527c80 Enable ScanAll for prometheus metrics to include all frameworks including CIS
Co-authored-by: matthyx <20683409+matthyx@users.noreply.github.com>
2025-12-03 16:32:43 +00:00
copilot-swe-agent[bot]
4c8692bf8c Remove test output files and update gitignore 2025-12-03 16:32:29 +00:00
copilot-swe-agent[bot]
742e3bb67f Add severity field to controls in JSON output
Co-authored-by: matthyx <20683409+matthyx@users.noreply.github.com>
2025-12-03 16:31:57 +00:00
copilot-swe-agent[bot]
a39f36c9fb Initial plan 2025-12-03 16:18:31 +00:00
copilot-swe-agent[bot]
9bc29032e1 Initial plan 2025-12-03 16:12:04 +00:00
Matthias Bertschy
a4a290a3ce Merge pull request #1898 from kubescape/dependabot/go_modules/github.com/cilium/cilium-1.16.17
Bump github.com/cilium/cilium from 1.16.9 to 1.16.17
2025-12-02 17:12:06 +01:00
dependabot[bot]
379a3fbc27 Bump github.com/cilium/cilium from 1.16.9 to 1.16.17
Bumps [github.com/cilium/cilium](https://github.com/cilium/cilium) from 1.16.9 to 1.16.17.
- [Release notes](https://github.com/cilium/cilium/releases)
- [Changelog](https://github.com/cilium/cilium/blob/1.16.17/CHANGELOG.md)
- [Commits](https://github.com/cilium/cilium/compare/1.16.9...1.16.17)

---
updated-dependencies:
- dependency-name: github.com/cilium/cilium
  dependency-version: 1.16.17
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-12-02 12:34:17 +01:00
Matthias Bertschy
a46098c034 Merge pull request #1896 from kubescape/summaries
always save WorkloadConfigurationScanResultSummaries
2025-12-01 08:05:57 +01:00
Matthias Bertschy
440f39ba3e Merge pull request #1897 from kubescape/docs
Revamp documentation
2025-11-30 11:47:23 +01:00
Matthias Bertschy
b6a4e282f9 Revamp documentation and reduce host sensor workers
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-11-30 11:47:00 +01:00
Matthias Bertschy
8deff34d12 always save WorkloadConfigurationScanResultSummaries
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-11-28 16:45:23 +01:00
Matthias Bertschy
acc9b54b2b Merge pull request #1895 from pfarikrispy/pfarikrispy-patch-1
update from Debian 12 to 13 when building container images
2025-11-26 14:52:53 +01:00
Christian Peper
1ffa29fbaa feat(security): update golang to debian trixie
build in the same env as the final image

Signed-off-by: Christian Peper <dreamszz@gmail.com>
2025-11-26 14:34:49 +01:00
Christian Peper
2ae30a8162 feat(security): update to Debian 13
Signed-off-by: Christian Peper <dreamszz@gmail.com>
2025-11-26 14:32:41 +01:00
Christian Peper
0ca5378c6b feat(security): update to Debian 13
use debian 13 as a base image

Signed-off-by: Christian Peper <dreamszz@gmail.com>
2025-11-26 14:30:46 +01:00
Matthias Bertschy
f51a1281f7 Merge pull request #1892 from kubescape/dependabot/go_modules/httphandler/golang.org/x/crypto-0.45.0
Bump golang.org/x/crypto from 0.41.0 to 0.45.0 in /httphandler
2025-11-21 20:59:38 +01:00
dependabot[bot]
5469d8bc04 Bump golang.org/x/crypto from 0.41.0 to 0.45.0
Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.41.0 to 0.45.0.
- [Commits](https://github.com/golang/crypto/compare/v0.41.0...v0.45.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-version: 0.45.0
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-11-21 17:10:28 +01:00
Matthias Bertschy
bd7c0c580e fix go mod tidy
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-11-11 17:52:55 +01:00
Matthias Bertschy
154fec1385 Allow artifact-metadata read in release workflow
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-11-11 16:14:32 +01:00
Matthias Bertschy
5c2275e32a Allow artifact-metadata read in release workflow
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-11-11 16:13:16 +01:00
Matthias Bertschy
2da4736201 fix workflow permissions
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-11-11 16:10:15 +01:00
Matthias Bertschy
aefafeae6f Merge pull request #1890 from kubescape/dependabot/go_modules/github.com/opencontainers/selinux-1.13.0
Bump github.com/opencontainers/selinux from 1.12.0 to 1.13.0
2025-11-11 14:10:59 +01:00
dependabot[bot]
1772b38b8c Bump github.com/opencontainers/selinux from 1.12.0 to 1.13.0
Bumps [github.com/opencontainers/selinux](https://github.com/opencontainers/selinux) from 1.12.0 to 1.13.0.
- [Release notes](https://github.com/opencontainers/selinux/releases)
- [Commits](https://github.com/opencontainers/selinux/compare/v1.12.0...v1.13.0)

---
updated-dependencies:
- dependency-name: github.com/opencontainers/selinux
  dependency-version: 1.13.0
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-11-11 12:44:20 +00:00
Matthias Bertschy
c844f42208 Merge pull request #1889 from kubescape/dependabot/go_modules/github.com/containerd/containerd-1.7.29
Bump github.com/containerd/containerd from 1.7.28 to 1.7.29
2025-11-07 08:44:37 +01:00
dependabot[bot]
b86d051998 Bump github.com/containerd/containerd from 1.7.28 to 1.7.29
Bumps [github.com/containerd/containerd](https://github.com/containerd/containerd) from 1.7.28 to 1.7.29.
- [Release notes](https://github.com/containerd/containerd/releases)
- [Changelog](https://github.com/containerd/containerd/blob/main/RELEASES.md)
- [Commits](https://github.com/containerd/containerd/compare/v1.7.28...v1.7.29)

---
updated-dependencies:
- dependency-name: github.com/containerd/containerd
  dependency-version: 1.7.29
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-11-07 08:32:59 +01:00
Matthias Bertschy
aaa8d1ed35 Merge pull request #1888 from kubescape/dependabot/go_modules/github.com/containerd/containerd/v2-2.0.7
Bump github.com/containerd/containerd/v2 from 2.0.5 to 2.0.7
2025-11-07 08:16:43 +01:00
dependabot[bot]
441d16aa08 Bump github.com/containerd/containerd/v2 from 2.0.5 to 2.0.7
Bumps [github.com/containerd/containerd/v2](https://github.com/containerd/containerd) from 2.0.5 to 2.0.7.
- [Release notes](https://github.com/containerd/containerd/releases)
- [Changelog](https://github.com/containerd/containerd/blob/main/RELEASES.md)
- [Commits](https://github.com/containerd/containerd/compare/v2.0.5...v2.0.7)

---
updated-dependencies:
- dependency-name: github.com/containerd/containerd/v2
  dependency-version: 2.0.7
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-11-07 08:04:26 +01:00
Matthias Bertschy
b33f1c8cc7 Merge pull request #1887 from Mujib-Ahasan/fix-print-sarif
fix: --format sarif logs as expected
2025-11-05 18:17:31 +01:00
Mujib Ahasan
4929af510e fix: --format sarif logs as expected
Signed-off-by: Mujib Ahasan <ahasanmujib8@gmail.com>
2025-11-04 20:30:10 +05:30
mandronic
f28bb11c55 removed 'procMount: Unmasked' from host-scanner daemonset definition (refs kubescape/helm-charts#711) (#1886)
Signed-off-by: Mihail Andronic <104365774+mandronic@users.noreply.github.com>
2025-11-03 13:40:14 +02:00
Matthias Bertschy
8bff4a02e1 Merge pull request #1884 from Mujib-Ahasan/fix-url
fixed "404" URL issue for command $kubescape scan.
2025-11-03 11:11:55 +01:00
Matthias Bertschy
33d1e018ec fix: update documentation links to include 'controls' path
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-11-03 07:47:37 +01:00
Mujib Ahasan
0c74599314 Test file updated
Signed-off-by: Mujib Ahasan <ahasanmujib8@gmail.com>
2025-10-30 01:14:25 +05:30
Mujib Ahasan
c23b85cc84 fixed 404 url issue in kubescape scan
Signed-off-by: Mujib Ahasan <ahasanmujib8@gmail.com>
2025-10-25 17:39:28 +05:30
Matthias Bertschy
aab10d14a2 Merge pull request #1881 from kubescape/dependabot/go_modules/github.com/nwaples/rardecode/v2-2.2.0
Bump github.com/nwaples/rardecode/v2 from 2.1.1 to 2.2.0
2025-10-21 09:45:29 +02:00
dependabot[bot]
2fcbe54e4e Bump github.com/nwaples/rardecode/v2 from 2.1.1 to 2.2.0
Bumps [github.com/nwaples/rardecode/v2](https://github.com/nwaples/rardecode) from 2.1.1 to 2.2.0.
- [Commits](https://github.com/nwaples/rardecode/compare/v2.1.1...v2.2.0)

---
updated-dependencies:
- dependency-name: github.com/nwaples/rardecode/v2
  dependency-version: 2.2.0
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-10-21 09:31:33 +02:00
Matthias Bertschy
078d154ab8 chore: update runners to use ubuntu-large for improved performance
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-10-15 10:12:24 +02:00
Matthias Bertschy
cc9dcf827e Revert "use ubuntu-latest-16-cores runner for docker build"
This reverts commit 76943d05fb.
2025-10-15 10:01:39 +02:00
Matthias Bertschy
76943d05fb use ubuntu-latest-16-cores runner for docker build
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-10-13 10:23:07 +02:00
Matthias Bertschy
621ac111cb Merge pull request #1880 from kubescape/hostagent-block
fix: improve error handling in hostscanner pod validation
2025-10-12 11:52:16 +02:00
Matthias Bertschy
3f80bce811 fix: improve error handling in hostscanner pod validation
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-10-10 16:13:43 +02:00
Matthias Bertschy
cc6895fc50 chore: update syft action to use latest version
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-10-10 15:00:35 +02:00
Matthias Bertschy
7d9d8e4b59 Merge pull request #1879 from kubescape/fix-post-release
fix: post release action does not take tag from GITHUB_REF env var
2025-10-08 15:57:44 +02:00
Amir Malka
f8d4bf515d fix: post release action does not take tag from GITHUB_REF env var
Signed-off-by: Amir Malka <amirm@armosec.io>
2025-10-08 16:18:35 +03:00
Matthias Bertschy
774ebe4a5f bump python to 3.9
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-09-29 17:44:13 +02:00
Matthias Bertschy
45a07a8046 Merge pull request #1877 from kubescape/grype
migrate to grype v0.99.1
2025-09-17 11:35:30 +02:00
Matthias Bertschy
ff96edae4d use grype v0.99.1
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-09-17 10:11:19 +02:00
Matthias Bertschy
34b82cad27 Merge pull request #1875 from kkrypt0nn/master
fix: Don't run scan in installation script
2025-09-16 15:13:31 +02:00
Matthias Bertschy
1a4c979ab8 update golangci-lint config
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-09-16 13:54:23 +02:00
Matthias Bertschy
3481af4a5b bump golangci-lint action
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-09-16 11:48:02 +02:00
Ben Hirschberg
71dc7a702c Merge pull request #1876 from cx-anjali-deore/fix/policy-binding-param
Fixed issue #1800 : Added parameterNotFoundAction in spec.paramRef while creating policy binding
2025-09-15 10:17:52 +03:00
anjali-deore
6d92389285 Fixed issue 1800
Signed-off-by: anjali-deore <200181980+cx-anjali-deore@users.noreply.github.com>
2025-09-13 18:06:37 +05:30
Krypton
bd0be45c0b fix: Don't run scan in installation script
Signed-off-by: Krypton <root@krypton.ninja>
2025-09-12 19:54:31 +02:00
Amir Malka
7ebf078d0c fix post-release workflow (#1873)
Signed-off-by: Amir Malka <amirm@armosec.io>
2025-09-02 19:51:20 +03:00
Matthias Bertschy
1bd729cf83 fix go tidy
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-09-02 14:45:12 +02:00
Matthias Bertschy
88b9b22bca Merge pull request #1857 from aadarsh-nagrath/default-matchers
feat: add default matchers option to image scanning
2025-09-02 14:25:29 +02:00
Matthias Bertschy
182162d521 gofmt
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-09-02 13:51:45 +02:00
Matthias Bertschy
1c02191bb1 Merge pull request #1866 from kubescape/tablewriter
replace olekukonko/tablewriter with jedib0t/go-pretty
2025-09-01 17:38:18 +02:00
Matthias Bertschy
ca66ccb33d replace olekukonko/tablewriter with jedib0t/go-pretty
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-09-01 16:38:42 +02:00
Matthias Bertschy
07eda20b88 Merge pull request #1869 from htsr/fix-imagescan-use-all-targets-exceptions
fix(imagescan): use all targets in exceptions
2025-09-01 16:29:04 +02:00
Matthias Bertschy
108c84d97d Merge pull request #1867 from cx-anjali-deore/feature/ListcontainerName
Issue 1817 fix: Show container name in Assisted remediation
2025-09-01 16:28:51 +02:00
Matthias Bertschy
35e7fa2b94 fix imports
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-09-01 15:49:31 +02:00
Hugo Thiessard
abb7917b29 fix(imagescan): use all targets in exceptions
Previously, kubescape only used the first target in scan image exceptions.
Added a test to verify the fix.

Signed-off-by: Hugo Thiessard <htsr@pm.me>
2025-09-01 15:05:00 +02:00
Matthias Bertschy
31ba56a0cf Merge pull request #1868 from kubescape/dependabot/go_modules/github.com/ulikunitz/xz-0.5.14
Bump github.com/ulikunitz/xz from 0.5.12 to 0.5.14
2025-09-01 09:43:12 +02:00
dependabot[bot]
b3efe4d003 Bump github.com/ulikunitz/xz from 0.5.12 to 0.5.14
Bumps [github.com/ulikunitz/xz](https://github.com/ulikunitz/xz) from 0.5.12 to 0.5.14.
- [Commits](https://github.com/ulikunitz/xz/compare/v0.5.12...v0.5.14)

---
updated-dependencies:
- dependency-name: github.com/ulikunitz/xz
  dependency-version: 0.5.14
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-09-01 05:35:18 +00:00
anjali-deore
5faade2b66 Fixed test cases
Signed-off-by: anjali-deore <200181980+cx-anjali-deore@users.noreply.github.com>
2025-08-31 17:37:32 +05:30
Matthias Bertschy
79207f66be don't read services from configmap, use file
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-08-29 15:21:25 +02:00
anjali-deore
af39f9a7ef fix removed space
Signed-off-by: anjali-deore <200181980+cx-anjali-deore@users.noreply.github.com>
2025-08-29 15:31:35 +05:30
anjali-deore
482b7c1f67 fix 1817 ,code cleanup
Signed-off-by: anjali-deore <200181980+cx-anjali-deore@users.noreply.github.com>
2025-08-29 15:20:00 +05:30
anjali-deore
82e2fd0be2 fix issue 1817,Added Container Name in control scan output
Signed-off-by: anjali-deore <200181980+cx-anjali-deore@users.noreply.github.com>
2025-08-29 15:20:00 +05:30
Matthias Bertschy
6eec751027 Merge pull request #1864 from kubescape/dependabot/go_modules/httphandler/github.com/hashicorp/go-getter-1.7.9
Bump github.com/hashicorp/go-getter from 1.7.8 to 1.7.9 in /httphandler
2025-08-21 17:48:44 +02:00
dependabot[bot]
4a6480c8b4 Bump github.com/hashicorp/go-getter from 1.7.8 to 1.7.9
Bumps [github.com/hashicorp/go-getter](https://github.com/hashicorp/go-getter) from 1.7.8 to 1.7.9.
- [Release notes](https://github.com/hashicorp/go-getter/releases)
- [Changelog](https://github.com/hashicorp/go-getter/blob/main/.goreleaser.yml)
- [Commits](https://github.com/hashicorp/go-getter/compare/v1.7.8...v1.7.9)

---
updated-dependencies:
- dependency-name: github.com/hashicorp/go-getter
  dependency-version: 1.7.9
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-08-21 17:14:35 +02:00
Matthias Bertschy
a51bfa4c3e Merge pull request #1863 from kubescape/new_fix/issue_1284
Issue 1284 fix: new approach implemented
2025-08-19 16:02:53 +02:00
Yehudah Tor
2a48af3c17 new approach of fix implemented
Signed-off-by: Yehudah Tor <yehudahtor@gmail.com>
2025-08-19 12:22:15 +03:00
Matthias Bertschy
ffeb4577e3 refactor output formatting in prettyprinter and related files
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-08-18 12:15:54 +02:00
Matthias Bertschy
b5c7422355 Merge pull request #1862 from kubescape/threshold
bump helm.sh/helm/v3 to 3.18.5
2025-08-18 11:07:42 +02:00
Matthias Bertschy
e41b5d77a0 bump helm.sh/helm/v3 to 3.18.5
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-08-18 10:28:34 +02:00
Matthias Bertschy
5afaae8847 Merge pull request #1860 from kubescape/threshold
return error on image when severity threshold exceeded
2025-08-18 10:22:19 +02:00
Matthias Bertschy
011fc0689d return error on image when severity threshold exceeded
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-08-14 14:38:59 +02:00
aadarsh-nagrath
db30020c95 feat: add default matchers option to image scanning
hey! added the default matchers option for image scanning as requested in #1838. now you can choose between stock matchers and CPE matchers when scanning images.

what's new:
- added --use-default-matchers flag to scan/image/patch commands
- true = stock matchers (default behavior)
- false = CPE matchers (more precise)

usage:
# use CPE matchers for more precise detection
kubescape scan image nginx:latest --use-default-matchers=false

# or in scan command
kubescape scan --scan-images --use-default-matchers=false

everything's backward compatible - existing code works exactly the same. just added the new option for folks who want more control over their vulnerability detection.

fixes #1838

Signed-off-by: aadarsh-nagrath <anagrath1@gmail.com>
2025-08-06 21:48:40 +05:30
Matthias Bertschy
c5341a356b fix prettyprinter test results
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-07-28 15:06:09 +02:00
Matthias Bertschy
85a7f57373 Merge pull request #1854 from kubescape/fixurls
fix docs URL in tests
2025-07-28 14:55:14 +02:00
Matthias Bertschy
cd9ebdf08f fix workflow permissions
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-07-28 14:44:36 +02:00
Matthias Bertschy
bc602a78ab fix docs URL in tests
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-07-28 14:41:25 +02:00
Matthias Bertschy
a2361fd155 Merge pull request #1853 from kubescape/dependabot/go_modules/github.com/containerd/containerd/v2-2.0.5
Bump github.com/containerd/containerd/v2 from 2.0.4 to 2.0.5
2025-07-28 14:26:07 +02:00
Matthias Bertschy
aa8d41fc2e fix workflow permissions
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-07-28 14:18:31 +02:00
dependabot[bot]
5bd4beb41f Bump github.com/containerd/containerd/v2 from 2.0.4 to 2.0.5
Bumps [github.com/containerd/containerd/v2](https://github.com/containerd/containerd) from 2.0.4 to 2.0.5.
- [Release notes](https://github.com/containerd/containerd/releases)
- [Changelog](https://github.com/containerd/containerd/blob/main/RELEASES.md)
- [Commits](https://github.com/containerd/containerd/compare/v2.0.4...v2.0.5)

---
updated-dependencies:
- dependency-name: github.com/containerd/containerd/v2
  dependency-version: 2.0.5
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-07-28 14:14:59 +02:00
Matthias Bertschy
dbf21dee37 Merge pull request #1852 from kubescape/dependabot/go_modules/helm.sh/helm/v3-3.17.4
Bump helm.sh/helm/v3 from 3.17.3 to 3.17.4
2025-07-28 14:13:32 +02:00
dependabot[bot]
be49d9b7be Bump helm.sh/helm/v3 from 3.17.3 to 3.17.4
Bumps [helm.sh/helm/v3](https://github.com/helm/helm) from 3.17.3 to 3.17.4.
- [Release notes](https://github.com/helm/helm/releases)
- [Commits](https://github.com/helm/helm/compare/v3.17.3...v3.17.4)

---
updated-dependencies:
- dependency-name: helm.sh/helm/v3
  dependency-version: 3.17.4
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-07-28 14:02:05 +02:00
Matthias Bertschy
7a5699fba3 Merge pull request #1851 from kubescape/dependabot/go_modules/github.com/cloudflare/circl-1.6.1
Bump github.com/cloudflare/circl from 1.5.0 to 1.6.1
2025-07-28 13:48:28 +02:00
dependabot[bot]
1f8afecea8 Bump github.com/cloudflare/circl from 1.5.0 to 1.6.1
Bumps [github.com/cloudflare/circl](https://github.com/cloudflare/circl) from 1.5.0 to 1.6.1.
- [Release notes](https://github.com/cloudflare/circl/releases)
- [Commits](https://github.com/cloudflare/circl/compare/v1.5.0...v1.6.1)

---
updated-dependencies:
- dependency-name: github.com/cloudflare/circl
  dependency-version: 1.6.1
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-07-28 13:33:52 +02:00
Matthias Bertschy
3ebb1d749e Merge pull request #1850 from kubescape/dependabot/go_modules/httphandler/github.com/go-viper/mapstructure/v2-2.3.0
Bump github.com/go-viper/mapstructure/v2 from 2.2.1 to 2.3.0 in /httphandler
2025-07-28 13:32:17 +02:00
dependabot[bot]
f80c9d947d Bump github.com/go-viper/mapstructure/v2 in /httphandler
Bumps [github.com/go-viper/mapstructure/v2](https://github.com/go-viper/mapstructure) from 2.2.1 to 2.3.0.
- [Release notes](https://github.com/go-viper/mapstructure/releases)
- [Changelog](https://github.com/go-viper/mapstructure/blob/main/CHANGELOG.md)
- [Commits](https://github.com/go-viper/mapstructure/compare/v2.2.1...v2.3.0)

---
updated-dependencies:
- dependency-name: github.com/go-viper/mapstructure/v2
  dependency-version: 2.3.0
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-07-28 13:18:52 +02:00
Matthias Bertschy
03b76ff4aa Merge pull request #1833 from kubescape/dependabot/go_modules/github.com/open-policy-agent/opa-1.4.0
Bump github.com/open-policy-agent/opa from 1.3.0 to 1.4.0
2025-07-28 13:06:52 +02:00
dependabot[bot]
01531b6276 Bump github.com/open-policy-agent/opa from 1.3.0 to 1.4.0
Bumps [github.com/open-policy-agent/opa](https://github.com/open-policy-agent/opa) from 1.3.0 to 1.4.0.
- [Release notes](https://github.com/open-policy-agent/opa/releases)
- [Changelog](https://github.com/open-policy-agent/opa/blob/main/CHANGELOG.md)
- [Commits](https://github.com/open-policy-agent/opa/compare/v1.3.0...v1.4.0)

---
updated-dependencies:
- dependency-name: github.com/open-policy-agent/opa
  dependency-version: 1.4.0
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-07-28 12:20:18 +02:00
Ben Hirschberg
aedfe1c4c0 Merge pull request #1849 from kubescape/fix/addon-urls
added urls hub.armo --> kubescape.io
2025-07-27 14:19:34 +03:00
Yehudah Tor
d2bedc1d2b added urls
Signed-off-by: Yehudah Tor <yehudahtor@gmail.com>
2025-07-27 13:50:47 +03:00
Ben Hirschberg
35288e7b85 Merge pull request #1846 from kubescape/fix/update-links
Fix/update links
2025-07-27 10:01:27 +03:00
Matthias Bertschy
cd046fa695 fix buildnumber test
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-07-26 11:08:43 +02:00
Matthias Bertschy
407b8be08f Merge pull request #1848 from kubescape/fixgrype
close grype DB at the very end of processing
2025-07-25 11:23:56 +02:00
Matthias Bertschy
b211fe9148 Merge pull request #1847 from kubescape/fixversion
do not fail version if update info cannot be fetched
2025-07-25 11:23:24 +02:00
Matthias Bertschy
525e51d68e close grype DB at the very end of processing
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-07-25 09:50:10 +02:00
Matthias Bertschy
daabd6c81a do not fail version if update info cannot be fetched
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-07-25 08:48:27 +02:00
Yehudah Tor
5b351d5eec Done URL ref's before problematic ones
Signed-off-by: Yehudah Tor <yehudahtor@gmail.com>
2025-07-24 12:11:31 +03:00
Yehudah Tor
a5b607ae2e All controls updated
Signed-off-by: Yehudah Tor <yehudahtor@gmail.com>
2025-07-24 11:12:18 +03:00
Yehudah Tor
fec51b00ba getting started kubescape.io control links updated
Signed-off-by: Yehudah Tor <yehudahtor@gmail.com>
2025-07-23 15:16:41 +03:00
Amir Malka
4f9809eec1 fix: control-plane node taints check (#1843)
Signed-off-by: Amir Malka <amirm@armosec.io>
2025-07-15 11:06:09 +03:00
Matthias Bertschy
c0c25c3430 Merge pull request #1841 from kubescape/submit
check scanInfo.Submit in HandleResults to not submit by default
2025-06-30 09:09:05 +02:00
Matthias Bertschy
6ed3e408be check scanInfo.Submit in HandleResults to not submit by default
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-06-30 08:16:41 +02:00
Matthias Bertschy
6042818a71 use go 1.24
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-06-24 16:31:45 +02:00
Matthias Bertschy
b37c20aed9 fix workflow permissions
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-06-24 16:01:11 +02:00
Matthias Bertschy
3de8204c43 fix workflow permissions
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-06-24 15:59:27 +02:00
Ben Hirschberg
d5bd3708b8 Merge pull request #1836 from slashben/feature/mcpserver-v1
Feature/mcpserver v1
2025-06-24 16:29:16 +03:00
Ben
2bd686131e Incorporating review
Signed-off-by: Ben <ben@armosec.io>
2025-06-10 14:32:26 +03:00
Ben
1ea4e0c304 Add configuration scan tools and resource handling
Implemented two new tools: 'list_configuration_security_scan_manifests' for listing available configuration scan manifests and 'get_configuration_security_scan_manifest' for retrieving details of a specific manifest. Added a resource template for configuration manifests and integrated these tools into the mcpserver.

Signed-off-by: Ben <ben@armosec.io>
2025-06-09 09:11:28 +03:00
Matthias Bertschy
b3251306d0 Merge pull request #1837 from ian-fox/master
Make a second sigint terminate kubescape immediately
2025-06-03 12:54:02 +02:00
Ian Fox
91ecdaba4e Make a second sigint terminate immediately
Right now, sending a sigint will start a graceful shutdown, which can take quite a while.
By calling stop() in the signal handler it unregisters the handler so that a subsequent
sigint received during a graceful shutdown will kill the process immediately.

Signed-off-by: Ian Fox <code@whatthefox.dev>
2025-06-02 19:12:45 +02:00
Matthias Bertschy
fa05dcd00d go.mod massaging
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-05-23 16:02:15 +02:00
Ben
1c2c928732 Failing build
Signed-off-by: Ben <ben@armosec.io>
2025-05-23 15:13:22 +03:00
Ben
69ac490006 Failing build
Signed-off-by: Ben <ben@armosec.io>
2025-05-23 15:13:12 +03:00
Matthias Bertschy
b67b9f3af2 Merge pull request #1835 from pixel365/cancel
Ensure context cancellation on command execution failure
2025-05-16 21:20:16 +02:00
Ruslan Semagin
628ed4a374 Ensure context cancellation on command execution failure
Signed-off-by: Ruslan Semagin <pixel.365.24@gmail.com>
2025-05-16 10:11:06 +03:00
Matthias Bertschy
a6fe34b466 add workflow_dispatch to pr scanner
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-05-02 16:36:27 +02:00
Matthias Bertschy
2e9406d96a Merge pull request #1828 from rash1411/patch-1
Update dir.go
2025-04-29 21:44:09 +02:00
Matthias Bertschy
6b1bf07f7f Merge pull request #1827 from shangchengbabaiban/master
fix: Fix stdin restoration in TestUserConfirmed
2025-04-29 21:40:30 +02:00
Matthias Bertschy
318c2c7ae6 Merge pull request #1829 from kubescape/dependabot/go_modules/golang.org/x/net-0.38.0
Bump golang.org/x/net from 0.37.0 to 0.38.0
2025-04-28 14:19:13 +02:00
dependabot[bot]
45f60b6fe0 Bump golang.org/x/net from 0.37.0 to 0.38.0
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.37.0 to 0.38.0.
- [Commits](https://github.com/golang/net/compare/v0.37.0...v0.38.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-version: 0.38.0
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-04-28 14:03:44 +02:00
rash1411
20557bc721 Update dir.go
Fix: Correct runtime.Caller usage and handle error in CurrentDir()

- Changed runtime.Caller(1) to runtime.Caller(0) to correctly fetch the current file's directory.
- Added proper check for the 'ok' value returned by runtime.Caller.
- Improved robustness by panicking if runtime information retrieval fails.


Signed-off-by: rash1411 <107741585+rash1411@users.noreply.github.com>
2025-04-27 01:29:04 +05:30
shangchengbabaiban
d8bfb27bc3 fix: Fix stdin restoration in TestUserConfirmed
Signed-off-by: shangchengbabaiban <shuang.cui@live.cn>
2025-04-19 10:51:09 +08:00
Matthias Bertschy
9776691816 Merge pull request #1824 from kubescape/dependabot/go_modules/helm.sh/helm/v3-3.17.3
Bump helm.sh/helm/v3 from 3.14.4 to 3.17.3
2025-04-15 12:41:19 +02:00
dependabot[bot]
80e419df24 Bump helm.sh/helm/v3 from 3.14.4 to 3.17.3
Bumps [helm.sh/helm/v3](https://github.com/helm/helm) from 3.14.4 to 3.17.3.
- [Release notes](https://github.com/helm/helm/releases)
- [Commits](https://github.com/helm/helm/compare/v3.14.4...v3.17.3)

---
updated-dependencies:
- dependency-name: helm.sh/helm/v3
  dependency-version: 3.17.3
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-04-15 12:22:19 +02:00
Matthias Bertschy
143f831f5b Merge pull request #1822 from kubescape/mergelabels
merge labels and annotations in RetryOnConflict
2025-04-14 16:26:47 +02:00
Matthias Bertschy
a4897304e8 merge labels and annotations in RetryOnConflict
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-04-14 15:36:34 +02:00
Matthias Bertschy
80d1165e2c Merge pull request #1820 from kubescape/opav1
upgrade open-policy-agent to 1.x
2025-04-14 14:13:23 +02:00
Matthias Bertschy
31ed7d5160 upgrade open-policy-agent to 1.x
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-04-10 17:17:08 +02:00
Matthias Bertschy
d62e9ce207 Merge pull request #1814 from pixel365/tests
test: increase test coverage
2025-04-07 09:17:27 +02:00
Ruslan Semagin
3b10443ff5 fix: goimports
Signed-off-by: Ruslan Semagin <pixel.365.24@gmail.com>
2025-04-01 12:26:15 +03:00
Ruslan Semagin
218e3914b1 test: increase test coverage
Signed-off-by: Ruslan Semagin <pixel.365.24@gmail.com>
2025-04-01 10:12:35 +03:00
Matthias Bertschy
2b07fbe782 Merge pull request #1813 from kubescape/merge
check for nil map in merge methods
2025-03-31 11:18:05 +02:00
Matthias Bertschy
0655d0496b check for nil map in merge methods
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-03-28 12:10:38 +01:00
Matthias Bertschy
02bf31fbc9 Merge pull request #1812 from kubescape/dependabot/go_modules/github.com/golang-jwt/jwt/v5-5.2.2
Bump github.com/golang-jwt/jwt/v5 from 5.2.1 to 5.2.2
2025-03-28 11:03:59 +01:00
dependabot[bot]
4d8a3f51e3 Bump github.com/golang-jwt/jwt/v5 from 5.2.1 to 5.2.2
Bumps [github.com/golang-jwt/jwt/v5](https://github.com/golang-jwt/jwt) from 5.2.1 to 5.2.2.
- [Release notes](https://github.com/golang-jwt/jwt/releases)
- [Changelog](https://github.com/golang-jwt/jwt/blob/main/VERSION_HISTORY.md)
- [Commits](https://github.com/golang-jwt/jwt/compare/v5.2.1...v5.2.2)

---
updated-dependencies:
- dependency-name: github.com/golang-jwt/jwt/v5
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-03-28 10:30:02 +01:00
Matthias Bertschy
43d29f7b8b Merge pull request #1811 from kubescape/prerequisites
feat: enhance prerequisites UI with new review-values and improved pr…
2025-03-24 12:44:42 +01:00
David Alima
ee0d4cba98 feat: enhance prerequisites UI with new review-values and improved prerequisites report
Signed-off-by: David Alima <davida@armosec.io>
2025-03-24 13:10:58 +02:00
Matthias Bertschy
d860c0234a Merge pull request #1809 from kubescape/dependabot/go_modules/golang.org/x/net-0.36.0
Bump golang.org/x/net from 0.33.0 to 0.36.0
2025-03-20 13:35:08 +01:00
Matthias Bertschy
f13ded61bf Bump github.com/containerd/containerd to 1.7.27
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-03-20 13:05:17 +01:00
dependabot[bot]
fe8fc700f4 Bump golang.org/x/net from 0.33.0 to 0.36.0
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.33.0 to 0.36.0.
- [Commits](https://github.com/golang/net/compare/v0.33.0...v0.36.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-03-20 09:59:07 +00:00
Matthias Bertschy
47b670637b Merge pull request #1808 from kubescape/prereq
updating prerequisites to support custom kubeconfig
2025-03-19 09:37:57 +01:00
Matthias Bertschy
97c83a652b updating prerequisites to support custom kubeconfig
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-03-18 10:02:17 +01:00
Matthias Bertschy
a089831720 upload everything in dist
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-03-10 10:32:00 +01:00
Matthias Bertschy
e4f1720a0c bump goreleaser action in the other file too
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-03-10 09:52:42 +01:00
Matthias Bertschy
233eb2134c bump goreleaser action
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-03-10 09:19:48 +01:00
Matthias Bertschy
06da926455 Merge pull request #1806 from kubescape/goreleaser
generate checksums for all artifacts
2025-03-10 08:56:35 +01:00
Amit Schendel
37f6193fe0 Merge pull request #1807 from kubescape/Bump-license-date
Update README.md
2025-03-09 17:08:09 +02:00
Amit Schendel
27ac036b7d Update README.md
Signed-off-by: Amit Schendel <58078857+amitschendel@users.noreply.github.com>
2025-03-09 17:04:32 +02:00
Matthias Bertschy
321d335b39 generate checksums for all artifacts
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-03-09 12:37:21 +01:00
Matthias Bertschy
91b7d8fc2b Merge pull request #1803 from kubescape/dependabot/go_modules/github.com/go-jose/go-jose/v3-3.0.4
Bump github.com/go-jose/go-jose/v3 from 3.0.3 to 3.0.4
2025-03-04 10:38:44 +01:00
dependabot[bot]
2b28911db0 Bump github.com/go-jose/go-jose/v3 from 3.0.3 to 3.0.4
Bumps [github.com/go-jose/go-jose/v3](https://github.com/go-jose/go-jose) from 3.0.3 to 3.0.4.
- [Release notes](https://github.com/go-jose/go-jose/releases)
- [Changelog](https://github.com/go-jose/go-jose/blob/main/CHANGELOG.md)
- [Commits](https://github.com/go-jose/go-jose/compare/v3.0.3...v3.0.4)

---
updated-dependencies:
- dependency-name: github.com/go-jose/go-jose/v3
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-03-04 09:28:14 +01:00
Amir Malka
667e5e8258 fix score calculation for framework with all controls in status irrelevant (#1802)
Signed-off-by: Amir Malka <amirm@armosec.io>
2025-03-03 15:20:14 +02:00
Matthias Bertschy
728b341048 Merge pull request #1797 from kubescape/prereq
update prerequisites command
2025-02-26 11:51:42 +01:00
Matthias Bertschy
75b295d579 update prerequisites command
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-02-26 11:20:33 +01:00
Matthias Bertschy
75298eabf2 Merge pull request #1796 from kubescape/dependabot/go_modules/httphandler/github.com/go-jose/go-jose/v4-4.0.5
Bump github.com/go-jose/go-jose/v4 from 4.0.2 to 4.0.5 in /httphandler
2025-02-25 08:45:31 +01:00
dependabot[bot]
2458f2ceb9 Bump github.com/go-jose/go-jose/v4 from 4.0.2 to 4.0.5
Bumps [github.com/go-jose/go-jose/v4](https://github.com/go-jose/go-jose) from 4.0.2 to 4.0.5.
- [Release notes](https://github.com/go-jose/go-jose/releases)
- [Changelog](https://github.com/go-jose/go-jose/blob/main/CHANGELOG.md)
- [Commits](https://github.com/go-jose/go-jose/compare/v4.0.2...v4.0.5)

---
updated-dependencies:
- dependency-name: github.com/go-jose/go-jose/v4
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-02-25 07:58:42 +01:00
Amir Malka
f57948ad97 deprecate control name in exception policies (#1795)
* deprecate control name in posture exception policies

Signed-off-by: Amir Malka <amirm@armosec.io>

* deprecate control name in posture exception policies

Signed-off-by: Amir Malka <amirm@armosec.io>

* deprecate control name in posture exception policies

Signed-off-by: Amir Malka <amirm@armosec.io>

* deprecate control name in posture exception policies

Signed-off-by: Amir Malka <amirm@armosec.io>

---------

Signed-off-by: Amir Malka <amirm@armosec.io>
2025-02-20 10:27:27 +02:00
Matthias Bertschy
d0befc5f16 Merge pull request #1792 from kubescape/colors
removing enable/disable colors, as not compatible with all loggers
2025-02-18 12:11:40 +01:00
Matthias Bertschy
5d4bd2e94e removing enable/disable colors, as not compatible with all loggers
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-02-18 11:38:47 +01:00
Matthias Bertschy
ae37fdc295 fix go tidy
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-02-14 16:19:42 +01:00
Matthias Bertschy
3dd95ff3a3 Merge pull request #1791 from kubescape/prereq
update prerequisites
2025-02-14 16:12:03 +01:00
Matthias Bertschy
daadb5b804 update prerequisites
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-02-14 16:10:31 +01:00
Matthias Bertschy
d250017faf Merge pull request #1790 from pixel365/err
fix: add error handling and context propagation
2025-02-12 10:56:03 +01:00
Ruslan Semagin
835bcbeb12 fix: format imports with goimports
Signed-off-by: Ruslan Semagin <pixel.365.24@gmail.com>
2025-02-12 12:15:14 +03:00
Ruslan Semagin
2e4f7c4477 fix: add error handling and context propagation
Signed-off-by: Ruslan Semagin <pixel.365.24@gmail.com>
2025-02-12 09:02:01 +03:00
Matthias Bertschy
66bf93eb0c Merge pull request #1789 from pixel365/ctx
Refactor: propagate context from main to avoid redundant context creation
2025-02-11 21:27:48 +01:00
Matthias Bertschy
3a036ed0e3 remove test resources saved by accident
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-02-11 21:26:26 +01:00
Ruslan Semagin
fe7dad4560 Refactor: propagate context from main to avoid redundant context creation
- Introduced a single context in main() to handle interrupt signals (os.Interrupt, syscall.SIGTERM).
- Removed repetitive context creation in the program by reusing the propagated context.
- Improved code readability and maintainability by centralizing context management.
- Ensured consistent handling of graceful shutdown across the program.

Signed-off-by: Ruslan Semagin <pixel.365.24@gmail.com>
2025-02-11 19:52:48 +03:00
Matthias Bertschy
fb36b09f3a remove mv kubescape arm64 binary step
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-02-11 09:49:17 +01:00
Matthias Bertschy
e71b0c75a9 fix downloaded artifacts path
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-02-11 08:55:43 +01:00
Matthias Bertschy
d615099ce1 try fixing download-artifacts action for release
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-02-11 07:42:30 +01:00
Matthias Bertschy
f265b91939 Merge pull request #1788 from kubescape/sarif
do not skip on location resolver error
2025-02-10 13:40:59 +01:00
Matthias Bertschy
825694ade1 do not skip on location resolver error
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-02-10 10:25:44 +01:00
Matthias Bertschy
979a30aea7 Merge pull request #1591 from Sanskarzz/scanapiexception
added support for exception rules in Scan API ( As a HTTP request)
2025-02-07 13:32:42 +01:00
Matthias Bertschy
39c4aa4faa Merge pull request #1568 from VaibhavMalik4187/feature-exceptions
Feature: Added exceptions flag in scan image cmd
2025-02-07 12:40:24 +01:00
Matthias Bertschy
475b672a7a add fixed grypeDB for tests
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-02-07 12:34:11 +01:00
Matthias Bertschy
815c87b532 implement reviews from DW
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-02-07 12:16:35 +01:00
Sanskarzz
82120f9d31 added support for exception rules
Signed-off-by: Sanskarzz <sanskar.gur@gmail.com>
2025-02-07 12:15:56 +01:00
VaibhavMalik4187
0545818f82 Added tests and improvements for image exceptions
Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
2025-02-07 10:26:53 +01:00
VaibhavMalik4187
046da1940c Added support for targets in image exceptions
This commit introduces the ability to specify targets in image
exceptions. Each target will have the following 4 attributes:

1. Registry
2. Organization
3. ImageName
4. ImageTag

These attributes will be used to match against the canonical image name
of the image to be scanned. The vulnerabilites and the severities
specified in the VulnerabilitiesIgnorePolicy object will be considered
only if the image to be scanned matches the targets specified for that
policy. Regular expressions can also be used to specify the image
attributes.

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
2025-02-07 10:26:53 +01:00
VaibhavMalik4187
a31154897f Added support for severity exceptions in imagescan
This commit add relevant functions to support severity exceptions during
image scan.

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
2025-02-07 10:26:53 +01:00
VaibhavMalik4187
199c57be30 WIP: Load image exceptions from file
Added initial commit to start loading image exceptions from json files.

Currently, it supports vulnerability exceptions using their CVE-IDs.

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
2025-02-07 10:26:53 +01:00
VaibhavMalik4187
7d55c79f11 Feature: Added exceptions flag in scan image cmd
This commit introduces the "exceptions" flag in the scan image command.
Users can pass a list of vulnerabilities they ignore while scanning an
image using this flag. Also added tests for the same.

Fixes: https://github.com/kubescape/kubescape/issues/1564

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
2025-02-07 10:26:53 +01:00
Matthias Bertschy
ee76364371 fix scorecard-action version
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-02-07 09:23:28 +01:00
Matthias Bertschy
4f2c7ac1de Merge pull request #1787 from kubescape/bump
bump all CI actions
2025-02-07 09:09:44 +01:00
Matthias Bertschy
00340827be bump all CI actions
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-02-07 08:00:19 +01:00
Matthias Bertschy
708fe64240 Merge pull request #1786 from Fernando-hub527/refactor/maroto-version-v2
Refactor: maroto version v2
2025-02-07 07:33:34 +01:00
Fernando-hub527
8985bbe3a9 refactor: update Maroto configuration file location
Signed-off-by: Fernando-hub527 <fernandocoelhosaraivanando@gmail.com>
2025-02-06 18:07:57 -03:00
Matthias Bertschy
1ffca5648e delete TableObject.getSeverityColor to please CI
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-02-06 07:56:07 +01:00
Fernando-hub527
76b1ecb022 refactor: create a method that returns the pdf row
Return a struct with the data for ease of use

Signed-off-by: Fernando-hub527 <fernandocoelhosaraivanando@gmail.com>
2025-02-05 21:52:50 -03:00
Fernando-hub527
fc69a3692e refactor: remove unused code
Signed-off-by: Fernando-hub527 <fernandocoelhosaraivanando@gmail.com>
2025-02-05 21:47:28 -03:00
Fernando-hub527
e159458129 test:validate creation of report pdf
Signed-off-by: Fernando-hub527 <fernandocoelhosaraivanando@gmail.com>
2025-02-05 21:45:01 -03:00
Fernando-hub527
b259f117ff refactor: create a report template with maroto/v2
Separate template creation from application logic

Signed-off-by: Fernando-hub527 <fernandocoelhosaraivanando@gmail.com>
2025-02-05 21:36:39 -03:00
Fernando-hub527
13cf34bffd refactor: update Maroto version to v2
Signed-off-by: Fernando-hub527 <fernandocoelhosaraivanando@gmail.com>
2025-02-05 21:31:22 -03:00
Matthias Bertschy
0300fee38b bump actions/download-artifact@v4
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-01-31 16:38:01 +01:00
Matthias Bertschy
d61d641e81 bump actions/upload-artifact@v4
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-01-31 16:09:16 +01:00
Matthias Bertschy
2added0f7c use go 1.23, disable cache
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-01-31 16:06:13 +01:00
Matthias Bertschy
b6f6573ed8 Merge pull request #1785 from kubescape/sarif
fix helm detection in sarif printer
2025-01-31 16:04:36 +01:00
Matthias Bertschy
4215771134 fix helm detection in sarif printer
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-01-31 15:23:15 +01:00
Amit Schendel
fd37446e1b Merge pull request #1784 from kubescape/feature/incubating-logo
Changing README of Kubescape from Sandbox to Incubating
2025-01-27 14:01:09 +02:00
Amit Schendel
351498aac5 Changing README of Kubescape from Sandbox to Incubating
Signed-off-by: Amit Schendel <amitschendel@gmail.com>
2025-01-27 13:47:16 +02:00
Eng Zer Jun
2005010568 Replace golang.org/x/exp/slices with slices from stdlib (#1783) 2025-01-17 20:51:08 +02:00
Matthias Bertschy
e16c4cc9b4 fix go.mod for httphandler
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-01-16 15:20:58 +01:00
Matthias Bertschy
544ba9831a Merge pull request #1782 from kubescape/prereq
add prerequisites command
2025-01-16 14:50:28 +01:00
Matthias Bertschy
b6c919feb1 add prerequisites command
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-01-16 14:10:40 +01:00
Matthias Bertschy
1c3b2831a2 Merge pull request #1781 from kubescape/add-trigger-indication-in-posture-report
add trigger by indication in posture report
2025-01-09 16:12:43 +01:00
Amit Schendel
8a19a73bb1 Update b-binary-build-and-e2e-tests.yaml (#1761)
Signed-off-by: Amit Schendel <58078857+amitschendel@users.noreply.github.com>
2025-01-09 17:01:51 +02:00
Amir Malka
d966b0acbc update opa-utils
Signed-off-by: Amir Malka <amirm@armosec.io>
2025-01-09 16:35:53 +02:00
Amir Malka
14ffe35437 add trigger by indication in posture report
Signed-off-by: Amir Malka <amirm@armosec.io>
2025-01-09 16:13:29 +02:00
Matthias Bertschy
985d72e5fb Merge pull request #1780 from kubescape/airgap
Airgap support
2025-01-09 14:00:50 +01:00
Matthias Bertschy
70a9380966 fix go imports
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-01-09 12:14:56 +01:00
Matthias Bertschy
f706d126f5 fix error in log about failed resource update
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-01-09 11:52:34 +01:00
Matthias Bertschy
600f19406e enable offline mode with env KS_OFFLINE
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-01-09 10:33:19 +01:00
Matthias Bertschy
d7ebf3239b include artifacts in httphandler image
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-01-09 09:44:22 +01:00
Matthias Bertschy
5e0b25b04a update go-git
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2025-01-09 09:42:36 +01:00
Ben Hirschberg
98fe2347fa Merge pull request #1779 from kubescape/roadmap-deprecation-message
Deprecation of the roadmap.md in this repo
2025-01-06 13:53:47 +02:00
Ben Hirschberg
9b22d3284e Deprecation of the roadmap.md in this repo
Signed-off-by: Ben Hirschberg <59160382+slashben@users.noreply.github.com>
2025-01-06 13:24:55 +02:00
Matthias Bertschy
9544e9cd66 Merge pull request #1778 from kubescape/bump
bump vulnerable deps
2024-12-20 17:04:20 +01:00
Matthias Bertschy
1ed1bb11f2 bump vulnerable deps
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-12-20 16:31:50 +01:00
Matthias Bertschy
b8ca1fcbce Merge pull request #1766 from Oshratn/inc_tasks
Update of README
2024-12-16 11:39:20 +01:00
Matthias Bertschy
326a3e4c63 Merge pull request #1776 from kubescape/dependabot/go_modules/golang.org/x/crypto-0.31.0
Bump golang.org/x/crypto from 0.27.0 to 0.31.0
2024-12-13 17:04:34 +01:00
dependabot[bot]
b348acd291 Bump golang.org/x/crypto from 0.27.0 to 0.31.0
Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.27.0 to 0.31.0.
- [Commits](https://github.com/golang/crypto/compare/v0.27.0...v0.31.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-12-13 15:31:42 +00:00
Matthias Bertschy
4fc3eacf7b Merge pull request #1775 from kubescape/dependabot/go_modules/httphandler/golang.org/x/crypto-0.31.0
Bump golang.org/x/crypto from 0.27.0 to 0.31.0 in /httphandler
2024-12-13 16:29:25 +01:00
dependabot[bot]
d6030a9c03 Bump golang.org/x/crypto from 0.27.0 to 0.31.0 in /httphandler
Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.27.0 to 0.31.0.
- [Commits](https://github.com/golang/crypto/compare/v0.27.0...v0.31.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-12-13 14:18:38 +00:00
Ben Hirschberg
e87bf7b723 Update maintainers in SECURITY-INSIGHTS.yml (#1774)
Signed-off-by: Ben Hirschberg <59160382+slashben@users.noreply.github.com>
2024-12-11 17:58:13 +02:00
Matthias Bertschy
4ef0b27ccf Merge pull request #1773 from kubescape/debug
add debug log on resource fetch with count
2024-12-11 09:51:58 +01:00
Matthias Bertschy
219582b92a add debug log on resource fetch with count
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-12-11 07:35:36 +01:00
Matthias Bertschy
07ed8c61f1 Merge pull request #1769 from needsure/master
chore: fix some function name in comment
2024-12-06 07:15:10 +01:00
needsure
c585abc21a chore: fix some function name in comment
Signed-off-by: needsure <qinzhipeng@outlook.com>
2024-12-06 13:41:14 +08:00
Matthias Bertschy
08696c583a Merge pull request #1767 from kubescape/statis
use distroless static for kubescape-cli image
2024-12-03 14:13:05 +01:00
Matthias Bertschy
7d94dc74bb use distroless static for kubescape-cli image
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-12-03 13:36:11 +01:00
Oshrat Nir
570369a66f Merge branch 'master' into inc_tasks
Signed-off-by: Oshrat Nir <45561829+Oshratn@users.noreply.github.com>
2024-12-02 16:50:35 +02:00
Oshrat Nir
97f24920e8 conflict resolution
Signed-off-by: Oshrat Nir <oshratn@armosec.io>
2024-12-02 16:44:58 +02:00
Oshrat Nir
f57305280f Update of README
Signed-off-by: Oshrat Nir <oshratn@armosec.io>
2024-12-02 16:27:46 +02:00
Matthias Bertschy
53c134cbc3 Merge pull request #1763 from kubescape/update-governance-files-c2834f57
Update governance files
2024-11-26 11:42:20 +01:00
Ben Hirschberg
3c3a1838e3 Update SECURITY.md
Signed-off-by: Ben Hirschberg <59160382+slashben@users.noreply.github.com>
2024-11-26 11:39:26 +02:00
Ben Hirschberg
adfd09a9d4 Update MAINTAINERS.md
Signed-off-by: Ben Hirschberg <59160382+slashben@users.noreply.github.com>
2024-11-26 11:39:24 +02:00
Ben Hirschberg
43ac47ec51 Update GOVERNANCE.md
Signed-off-by: Ben Hirschberg <59160382+slashben@users.noreply.github.com>
2024-11-26 11:39:23 +02:00
Ben Hirschberg
ec715ab68b Update CONTRIBUTING.md
Signed-off-by: Ben Hirschberg <59160382+slashben@users.noreply.github.com>
2024-11-26 11:39:21 +02:00
Ben Hirschberg
fbff5873f7 Add COMMUNITY.md
Signed-off-by: Ben Hirschberg <59160382+slashben@users.noreply.github.com>
2024-11-26 11:39:20 +02:00
Ben Hirschberg
a81eab0a1a Update CODE_OF_CONDUCT.md
Signed-off-by: Ben Hirschberg <59160382+slashben@users.noreply.github.com>
2024-11-26 11:39:18 +02:00
Ben Hirschberg
cfc52856b3 Update ADOPTERS.md
Signed-off-by: Ben Hirschberg <59160382+slashben@users.noreply.github.com>
2024-11-26 11:39:16 +02:00
Matthias Bertschy
5707d7f7e4 Merge pull request #1760 from slashben/add-reg-print
Implementing capability to print out the "print" statements of the rego
2024-11-21 09:24:22 +01:00
Ben
4f3ef49f99 Implementing capability to print out the "print" statements of the rego
Signed-off-by: Ben <ben@armosec.io>
2024-11-20 00:10:18 +02:00
Matthias Bertschy
a9ac880356 Merge pull request #1758 from kubescape/bug_fix/repo_scan
fix the repo scan got stuck bug
2024-11-19 15:42:59 +01:00
Matthias Bertschy
761d4c6ff4 gofmt and try to make linter happy
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-11-19 15:10:37 +01:00
Matthias Bertschy
bbb2aafc7e try to override GITHUB_REF for krew publisher
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-11-19 14:49:49 +01:00
jnathangreeg
7735087937 fix the repo scan get stucked bug
Signed-off-by: jnathangreeg <jonathang@armosec.io>
2024-11-19 15:13:31 +02:00
Matthias Bertschy
5b9c6491de fix mod tidy
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-11-18 10:34:28 +01:00
Matthias Bertschy
b0e3744140 Merge pull request #1756 from kubescape/bug_fix/repo_scan
bump opa-utils version to fix apiVersion check
2024-11-18 10:09:07 +01:00
Matthias Bertschy
0451cdb345 Merge pull request #1757 from kubescape/krew
bump krew publish action
2024-11-18 09:39:31 +01:00
Matthias Bertschy
4546465f4a bump krew publish action
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-11-18 09:38:22 +01:00
Matthias Bertschy
52c564b2a4 Merge pull request #1749 from craigbox/doc-updates
some easy doc fixes
2024-11-18 07:14:57 +01:00
Craig Box
0abc81003e remove git2go
Signed-off-by: Craig Box <craig.box@gmail.com>
2024-11-18 15:31:49 +13:00
Craig Box
817d4902ff fix David's Url
Signed-off-by: Craig Box <craig.box@gmail.com>
2024-11-18 15:27:46 +13:00
Craig Box
5553a1adf0 some easy doc fixes
Signed-off-by: Craig Box <craig.box@gmail.com>
2024-11-18 15:26:33 +13:00
jnathangreeg
e95352d31e switch runner
Signed-off-by: jnathangreeg <jonathang@armosec.io>
2024-11-17 13:20:02 +02:00
jnathangreeg
5655051a95 bump opa-utils version
Signed-off-by: jnathangreeg <jonathang@armosec.io>
2024-11-17 12:13:23 +02:00
Matthias Bertschy
90c359533f override docker/docker upgrade
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-11-12 14:46:29 +01:00
Matthias Bertschy
7013d83aa8 Merge pull request #1754 from kubescape/dependabot/go_modules/httphandler/github.com/golang-jwt/jwt/v4-4.5.1
Bump github.com/golang-jwt/jwt/v4 from 4.5.0 to 4.5.1 in /httphandler
2024-11-12 11:35:37 +01:00
dependabot[bot]
c4935671fe Bump github.com/golang-jwt/jwt/v4 from 4.5.0 to 4.5.1 in /httphandler
Bumps [github.com/golang-jwt/jwt/v4](https://github.com/golang-jwt/jwt) from 4.5.0 to 4.5.1.
- [Release notes](https://github.com/golang-jwt/jwt/releases)
- [Changelog](https://github.com/golang-jwt/jwt/blob/main/VERSION_HISTORY.md)
- [Commits](https://github.com/golang-jwt/jwt/compare/v4.5.0...v4.5.1)

---
updated-dependencies:
- dependency-name: github.com/golang-jwt/jwt/v4
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-11-12 10:32:57 +00:00
Matthias Bertschy
e67ef1c54d Merge pull request #1752 from kubescape/bug_fix/repo_scan
Add a second condition in getFilesFromTree to ensure we are scanning the correct path
2024-11-12 11:20:47 +01:00
Matthias Bertschy
5d6b9a5e83 Merge pull request #1753 from kubescape/dependabot/go_modules/github.com/golang-jwt/jwt/v4-4.5.1
Bump github.com/golang-jwt/jwt/v4 from 4.5.0 to 4.5.1
2024-11-12 11:03:11 +01:00
dependabot[bot]
a6752a5a6d Bump github.com/golang-jwt/jwt/v4 from 4.5.0 to 4.5.1
Bumps [github.com/golang-jwt/jwt/v4](https://github.com/golang-jwt/jwt) from 4.5.0 to 4.5.1.
- [Release notes](https://github.com/golang-jwt/jwt/releases)
- [Changelog](https://github.com/golang-jwt/jwt/blob/main/VERSION_HISTORY.md)
- [Commits](https://github.com/golang-jwt/jwt/compare/v4.5.0...v4.5.1)

---
updated-dependencies:
- dependency-name: github.com/golang-jwt/jwt/v4
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-11-12 08:33:28 +00:00
jnathangreeg
6f47f8dae0 adding a second term for getFilesFromTree for makeing sure we scaning the right path
Signed-off-by: jnathangreeg <jonathang@armosec.io>
2024-11-11 19:29:22 +02:00
Matthias Bertschy
d82e8daa25 Add CoC link to GOVERNANCE.md
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-10-28 16:34:00 +01:00
Matthias Bertschy
1cad446fe6 Merge pull request #1742 from kubescape/dependabot/go_modules/httphandler/github.com/containers/common-0.60.4
Bump github.com/containers/common from 0.59.0 to 0.60.4 in /httphandler
2024-10-03 07:57:55 +02:00
dependabot[bot]
12c6f34fe7 Bump github.com/containers/common from 0.59.0 to 0.60.4 in /httphandler
Bumps [github.com/containers/common](https://github.com/containers/common) from 0.59.0 to 0.60.4.
- [Release notes](https://github.com/containers/common/releases)
- [Commits](https://github.com/containers/common/compare/v0.59.0...v0.60.4)

---
updated-dependencies:
- dependency-name: github.com/containers/common
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-10-03 05:21:42 +00:00
Matthias Bertschy
79c2dd9a2b Merge pull request #1741 from kubescape/bump
bump opa
2024-09-30 18:00:01 +02:00
Matthias Bertschy
f64d5a03af bump opa and go-logger
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-09-30 17:40:38 +02:00
Matthias Bertschy
e27d1581f1 Merge pull request #1736 from comrumino/master
EKS Support error: failed to get cloud data
2024-09-25 08:15:58 +02:00
James Stronz
99985e3235 Bumped k8s-interface version to v0.0.174, the latest release
Signed-off-by: James Stronz <comrumino@archstrike.org>
2024-09-24 23:44:39 -05:00
comrumino
27782afeac Upgraded aws module dependencies to resolve the error failed to get cloud data. resourceKind: ClusterDescribe; error: not found, ResolveEndpointV2. This error is a known issue regarding incompatible service module versions. Refer to https://github.com/aws/aws-sdk-go-v2/issues/2370#issuecomment-1953308268 for more details.
Signed-off-by: comrumino <comrumino@archstrike.org>
2024-09-19 12:21:43 -05:00
Matthias Bertschy
0e846b2dc5 Merge pull request #1732 from kubescape/grpc
force grpc
2024-09-06 15:43:47 +02:00
Matthias Bertschy
45fb0f207e try to move post-release steps into main workflow
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-09-06 12:43:17 +02:00
Matthias Bertschy
b7c91c238d force grpc
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-09-04 21:57:00 +02:00
Matthias Bertschy
76635a0705 Merge pull request #1730 from kubescape/bump
also bump workflows to 1.23
2024-08-26 08:49:44 +02:00
Matthias Bertschy
c91d69e7fd also bump workflows to 1.23
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-08-21 13:33:02 +02:00
Matthias Bertschy
5fd7096d67 Merge pull request #1729 from kubescape/bump
update to go 1.23 and base image to debian12
2024-08-21 13:04:21 +02:00
Matthias Bertschy
f4189cb5ec update to go 1.23 and base image to debian12
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-08-21 12:49:52 +02:00
Matthias Bertschy
278ca5b8ae Merge pull request #1728 from kubescape/dependabot/go_modules/httphandler/github.com/docker/docker-26.1.5incompatible
Bump github.com/docker/docker from 26.1.4+incompatible to 26.1.5+incompatible in /httphandler
2024-08-21 12:26:07 +02:00
dependabot[bot]
729efcb8c3 Bump github.com/docker/docker in /httphandler
Bumps [github.com/docker/docker](https://github.com/docker/docker) from 26.1.4+incompatible to 26.1.5+incompatible.
- [Release notes](https://github.com/docker/docker/releases)
- [Commits](https://github.com/docker/docker/compare/v26.1.4...v26.1.5)

---
updated-dependencies:
- dependency-name: github.com/docker/docker
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-08-21 10:24:57 +00:00
Matthias Bertschy
406031d4e9 Merge pull request #1726 from kubescape/dependabot/go_modules/github.com/docker/docker-26.1.5incompatible
Bump github.com/docker/docker from 26.1.4+incompatible to 26.1.5+incompatible
2024-08-21 12:22:24 +02:00
Matthias Bertschy
9e1d0d2cd6 Merge pull request #1722 from kubescape/dependabot/go_modules/httphandler/github.com/docker/docker-26.1.4incompatible
Bump github.com/docker/docker from 26.1.0+incompatible to 26.1.4+incompatible in /httphandler
2024-08-21 12:21:35 +02:00
dependabot[bot]
f3e78f9408 Bump github.com/docker/docker
Bumps [github.com/docker/docker](https://github.com/docker/docker) from 26.1.4+incompatible to 26.1.5+incompatible.
- [Release notes](https://github.com/docker/docker/releases)
- [Commits](https://github.com/docker/docker/compare/v26.1.4...v26.1.5)

---
updated-dependencies:
- dependency-name: github.com/docker/docker
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-08-21 05:56:42 +00:00
dependabot[bot]
eea4cc0b49 Bump github.com/docker/docker in /httphandler
Bumps [github.com/docker/docker](https://github.com/docker/docker) from 26.1.0+incompatible to 26.1.4+incompatible.
- [Release notes](https://github.com/docker/docker/releases)
- [Commits](https://github.com/docker/docker/compare/v26.1.0...v26.1.4)

---
updated-dependencies:
- dependency-name: github.com/docker/docker
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-08-06 19:43:32 +00:00
Matthias Bertschy
1127f44c10 Merge pull request #1723 from kubescape/dependabot/go_modules/github.com/docker/docker-26.1.4incompatible
Bump github.com/docker/docker from 26.1.0+incompatible to 26.1.4+incompatible
2024-08-06 21:41:28 +02:00
dependabot[bot]
377509fab8 Bump github.com/docker/docker
Bumps [github.com/docker/docker](https://github.com/docker/docker) from 26.1.0+incompatible to 26.1.4+incompatible.
- [Release notes](https://github.com/docker/docker/releases)
- [Commits](https://github.com/docker/docker/compare/v26.1.0...v26.1.4)

---
updated-dependencies:
- dependency-name: github.com/docker/docker
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-08-06 15:39:44 +00:00
Matthias Bertschy
c21e2f3147 Merge pull request #1719 from maanugh/krew/release
chore: improve the publishing workflows for krew
2024-08-04 22:17:24 +02:00
Kiraat
0b4c5db939 Update .github/workflows/04-publish-krew-plugin.yaml
Co-authored-by: Matthias Bertschy <matthias.bertschy@gmail.com>
Signed-off-by: Kiraat <137809273+maanugh@users.noreply.github.com>
2024-07-26 15:28:55 +05:30
maanugh
6d490fc501 chore: improve the publishing workflows for krew
Signed-off-by: maanugh <manusin46@gmail.com>
2024-07-26 15:20:48 +05:30
Matthias Bertschy
dbb71ba066 Merge pull request #1718 from kubescape/fixfix
fix include/exclude NS for SA discovered via CRB
2024-07-24 07:36:27 +02:00
Matthias Bertschy
d5b8532e40 fix include/exclude NS for SA discovered via CRB
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-07-23 18:42:01 +02:00
Matthias Bertschy
db396b26f8 Merge pull request #1717 from kubescape/documentation_ugrades
Documentation ugrades
2024-07-15 16:49:07 +02:00
idohu
1242259331 fix png link
Signed-off-by: idohu <idoh@armosec.io>
2024-07-15 17:45:39 +03:00
idohu
ad0e50898a add architecture to README.md + fix first paragraph to bullets
Signed-off-by: idohu <idoh@armosec.io>
2024-07-15 17:43:09 +03:00
Matthias Bertschy
3cf45cffd8 Merge pull request #1716 from kubescape/fixfix
fix generated ValidatingAdmissionPolicyBinding
2024-07-15 16:35:27 +02:00
Matthias Bertschy
ac0d982531 fix generated ValidatingAdmissionPolicyBinding
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-07-15 16:05:27 +02:00
Matthias Bertschy
99e22efe7b Merge pull request #1450 from kubescape/update-docs
update docs
2024-07-15 13:03:33 +02:00
Oshrat Nir
aedeb8f9cb Update README.md
update time and relative timezone

Signed-off-by: Oshrat Nir <45561829+Oshratn@users.noreply.github.com>
2024-07-15 13:50:20 +03:00
Oshrat Nir
824e76200e Update README.md
Co-authored-by: Matthias Bertschy <matthias.bertschy@gmail.com>
Signed-off-by: Oshrat Nir <45561829+Oshratn@users.noreply.github.com>
2024-07-15 13:44:52 +03:00
Oshrat Nir
8342f96a62 Merge branch 'master' into update-docs
Signed-off-by: Oshrat Nir <45561829+Oshratn@users.noreply.github.com>
2024-07-15 13:41:25 +03:00
Oshrat Nir
b824d52345 Update README.md
Updated with runtime security, bi-weekly meetings and messaging in general.

Signed-off-by: Oshrat Nir <45561829+Oshratn@users.noreply.github.com>
2024-07-15 13:33:16 +03:00
Matthias Bertschy
11b6567db4 Merge pull request #1713 from kubescape/fixfix
use proper params in pager call
2024-07-10 12:41:04 +02:00
Matthias Bertschy
c7d3105ca5 use proper params in pager call
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-07-10 11:58:06 +02:00
Matthias Bertschy
f1c15cd2b5 Merge pull request #1710 from ttimonen/ttimonen/handler
Simplify the concurrency in http handler for scan.
2024-07-08 22:27:34 +02:00
ttimonen
7507f58306 refactor(handler) Simplify the scan http handler concurrency.
In particular,
Replace scanResponseChan struct with a reply channel in req.
This removes one chokepoint with tracking a map of channel with a mutex wrapping by not sharing data across different requests and
 makes it easier to reason about the correctness of the behavior.

Other changes are mostly cosmetic to group your operations related to
the primitives you are operating on, reducing the average lifetime of
a local variable (matters mostly for humans; compilers are very good at this nowadays).

Also this is net benefical by reducing LOCs by 45.

Signed-off-by: ttimonen <toni.timonen@iki.fi>
2024-07-07 22:44:35 +00:00
ttimonen
48ad56a2ef Implement unit-test for scan handler.
It plays wtih channels and goroutines, so having it
behave correctly is not completely trivial and test
worthy.

Signed-off-by: ttimonen <toni.timonen@iki.fi>
2024-07-07 22:40:58 +00:00
Matthias Bertschy
2fdec20b28 Merge pull request #1709 from kubescape/listitems
use pager.EachListItem to filter parented resources
2024-07-04 07:14:10 +02:00
Matthias Bertschy
2d77ea7b62 use pager.EachListItem to filter parented resources
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-07-03 16:41:12 +02:00
Yonatan Amzallag
eacd559c34 Merge pull request #1708 from kubescape/debug-disk-space-checks
Changed large-runner type for binary-build job
2024-07-03 14:01:49 +03:00
yonatanamz
c56e5799d7 Changed large-runner type for binary-build job
Signed-off-by: yonatanamz <yonatan989@gmail.com>
2024-07-03 13:58:55 +03:00
Yonatan Amzallag
ae5744f54e Merge pull request #1707 from kubescape/debug-disk-space-checks
Use large runners for binary-build job
2024-07-03 12:54:55 +03:00
yonatanamz
c649cc66a5 Use large runners for binary-build job
Signed-off-by: yonatanamz <yonatan989@gmail.com>
2024-07-03 12:30:18 +03:00
Yonatan Amzallag
7db735ade6 Merge pull request #1706 from kubescape/debug-disk-space-checks
Add disk space checks to binary-build job
2024-07-03 11:10:03 +03:00
yonatanamz
456145e240 Add disk space checks to binary-build job
Signed-off-by: yonatanamz <yonatan989@gmail.com>
2024-07-03 11:03:53 +03:00
Matthias Bertschy
382a2f03c8 Merge pull request #1705 from kubescape/dependabot/go_modules/httphandler/github.com/gorilla/schema-1.4.1
Bump github.com/gorilla/schema from 1.2.0 to 1.4.1 in /httphandler
2024-07-02 10:00:41 +02:00
Matthias Bertschy
44ebf59d76 Merge pull request #1704 from kubescape/dependabot/go_modules/httphandler/github.com/hashicorp/go-getter-1.7.5
Bump github.com/hashicorp/go-getter from 1.7.4 to 1.7.5 in /httphandler
2024-07-02 09:56:58 +02:00
dependabot[bot]
0688e3620b Bump github.com/gorilla/schema from 1.2.0 to 1.4.1 in /httphandler
Bumps [github.com/gorilla/schema](https://github.com/gorilla/schema) from 1.2.0 to 1.4.1.
- [Release notes](https://github.com/gorilla/schema/releases)
- [Commits](https://github.com/gorilla/schema/compare/v1.2.0...v1.4.1)

---
updated-dependencies:
- dependency-name: github.com/gorilla/schema
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-07-02 07:38:23 +00:00
dependabot[bot]
ab534b0346 Bump github.com/hashicorp/go-getter from 1.7.4 to 1.7.5 in /httphandler
Bumps [github.com/hashicorp/go-getter](https://github.com/hashicorp/go-getter) from 1.7.4 to 1.7.5.
- [Release notes](https://github.com/hashicorp/go-getter/releases)
- [Changelog](https://github.com/hashicorp/go-getter/blob/main/.goreleaser.yml)
- [Commits](https://github.com/hashicorp/go-getter/compare/v1.7.4...v1.7.5)

---
updated-dependencies:
- dependency-name: github.com/hashicorp/go-getter
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-07-02 07:34:16 +00:00
Matthias Bertschy
09420a41a7 Merge pull request #1703 from kubescape/dependabot/go_modules/github.com/hashicorp/go-getter-1.7.5
Bump github.com/hashicorp/go-getter from 1.7.4 to 1.7.5
2024-07-02 09:28:38 +02:00
dependabot[bot]
e93eb942a8 Bump github.com/hashicorp/go-getter from 1.7.4 to 1.7.5
Bumps [github.com/hashicorp/go-getter](https://github.com/hashicorp/go-getter) from 1.7.4 to 1.7.5.
- [Release notes](https://github.com/hashicorp/go-getter/releases)
- [Changelog](https://github.com/hashicorp/go-getter/blob/main/.goreleaser.yml)
- [Commits](https://github.com/hashicorp/go-getter/compare/v1.7.4...v1.7.5)

---
updated-dependencies:
- dependency-name: github.com/hashicorp/go-getter
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-07-01 14:43:55 +00:00
Matthias Bertschy
12f87b2710 Merge pull request #1702 from kubescape/dependabot/go_modules/httphandler/github.com/hashicorp/go-retryablehttp-0.7.7
Bump github.com/hashicorp/go-retryablehttp from 0.7.5 to 0.7.7 in /httphandler
2024-06-25 10:19:43 +02:00
dependabot[bot]
d6dc8f219c Bump github.com/hashicorp/go-retryablehttp in /httphandler
Bumps [github.com/hashicorp/go-retryablehttp](https://github.com/hashicorp/go-retryablehttp) from 0.7.5 to 0.7.7.
- [Changelog](https://github.com/hashicorp/go-retryablehttp/blob/main/CHANGELOG.md)
- [Commits](https://github.com/hashicorp/go-retryablehttp/compare/v0.7.5...v0.7.7)

---
updated-dependencies:
- dependency-name: github.com/hashicorp/go-retryablehttp
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-06-25 07:46:08 +00:00
Matthias Bertschy
fb3376d305 Merge pull request #1701 from kubescape/dependabot/go_modules/github.com/hashicorp/go-retryablehttp-0.7.7
Bump github.com/hashicorp/go-retryablehttp from 0.7.5 to 0.7.7
2024-06-25 09:44:01 +02:00
dependabot[bot]
ef2ded1933 Bump github.com/hashicorp/go-retryablehttp from 0.7.5 to 0.7.7
Bumps [github.com/hashicorp/go-retryablehttp](https://github.com/hashicorp/go-retryablehttp) from 0.7.5 to 0.7.7.
- [Changelog](https://github.com/hashicorp/go-retryablehttp/blob/main/CHANGELOG.md)
- [Commits](https://github.com/hashicorp/go-retryablehttp/compare/v0.7.5...v0.7.7)

---
updated-dependencies:
- dependency-name: github.com/hashicorp/go-retryablehttp
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-06-25 06:06:07 +00:00
Matthias Bertschy
e9f1d4085a Merge pull request #1700 from kubescape/dependabot/go_modules/httphandler/go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace-0.44.0
Bump go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace from 0.40.0 to 0.44.0 in /httphandler
2024-06-25 08:03:50 +02:00
dependabot[bot]
51a9707d24 Bump go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace
Bumps [go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace](https://github.com/open-telemetry/opentelemetry-go-contrib) from 0.40.0 to 0.44.0.
- [Release notes](https://github.com/open-telemetry/opentelemetry-go-contrib/releases)
- [Changelog](https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/CHANGELOG.md)
- [Commits](https://github.com/open-telemetry/opentelemetry-go-contrib/compare/zpages/v0.40.0...zpages/v0.44.0)

---
updated-dependencies:
- dependency-name: go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-06-25 06:02:15 +00:00
Matthias Bertschy
a4058eac62 Merge pull request #1699 from kubescape/dependabot/go_modules/go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace-0.44.0
Bump go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace from 0.40.0 to 0.44.0
2024-06-25 07:59:15 +02:00
dependabot[bot]
f2b621134c Bump go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace
Bumps [go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace](https://github.com/open-telemetry/opentelemetry-go-contrib) from 0.40.0 to 0.44.0.
- [Release notes](https://github.com/open-telemetry/opentelemetry-go-contrib/releases)
- [Changelog](https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/CHANGELOG.md)
- [Commits](https://github.com/open-telemetry/opentelemetry-go-contrib/compare/zpages/v0.40.0...zpages/v0.44.0)

---
updated-dependencies:
- dependency-name: go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-06-25 05:49:43 +00:00
Matthias Bertschy
58ce50e751 Merge pull request #1440 from anubhav06/copa-grype
change reference from anubhav06 to project-copacetic
2024-06-25 07:45:50 +02:00
Anubhav Gupta
2bbedc99dd Merge branch 'master' of ssh://github.com/kubescape/kubescape into copa-grype 2024-06-22 08:59:18 +05:30
Matthias Bertschy
78794990d7 Merge pull request #1697 from kubescape/dependabot/go_modules/httphandler/github.com/Azure/azure-sdk-for-go/sdk/azidentity-1.6.0
Bump github.com/Azure/azure-sdk-for-go/sdk/azidentity from 1.5.1 to 1.6.0 in /httphandler
2024-06-17 14:01:50 +02:00
dependabot[bot]
a7127c0b27 Bump github.com/Azure/azure-sdk-for-go/sdk/azidentity in /httphandler
Bumps [github.com/Azure/azure-sdk-for-go/sdk/azidentity](https://github.com/Azure/azure-sdk-for-go) from 1.5.1 to 1.6.0.
- [Release notes](https://github.com/Azure/azure-sdk-for-go/releases)
- [Changelog](https://github.com/Azure/azure-sdk-for-go/blob/main/documentation/release.md)
- [Commits](https://github.com/Azure/azure-sdk-for-go/compare/sdk/internal/v1.5.1...sdk/azcore/v1.6.0)

---
updated-dependencies:
- dependency-name: github.com/Azure/azure-sdk-for-go/sdk/azidentity
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-06-17 11:06:59 +00:00
Matthias Bertschy
01505406a6 Merge pull request #1696 from kubescape/dependabot/go_modules/github.com/Azure/azure-sdk-for-go/sdk/azidentity-1.6.0
Bump github.com/Azure/azure-sdk-for-go/sdk/azidentity from 1.5.1 to 1.6.0
2024-06-17 13:04:26 +02:00
dependabot[bot]
e1fe7cda50 Bump github.com/Azure/azure-sdk-for-go/sdk/azidentity
Bumps [github.com/Azure/azure-sdk-for-go/sdk/azidentity](https://github.com/Azure/azure-sdk-for-go) from 1.5.1 to 1.6.0.
- [Release notes](https://github.com/Azure/azure-sdk-for-go/releases)
- [Changelog](https://github.com/Azure/azure-sdk-for-go/blob/main/documentation/release.md)
- [Commits](https://github.com/Azure/azure-sdk-for-go/compare/sdk/internal/v1.5.1...sdk/azcore/v1.6.0)

---
updated-dependencies:
- dependency-name: github.com/Azure/azure-sdk-for-go/sdk/azidentity
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-06-13 14:09:34 +00:00
Matthias Bertschy
f0bc2845cf Merge pull request #1695 from kubescape/rulename
update exceptions docs - ruleName not supported
2024-06-11 10:41:15 +02:00
YiscahLevySilas1
c2c521b715 ruleName not supported in exceptions
Signed-off-by: YiscahLevySilas1 <yiscahls@armosec.io>
2024-06-09 09:54:09 +03:00
Matthias Bertschy
2d5ea3e789 Merge pull request #1689 from kubescape/dependabot/go_modules/httphandler/github.com/aquasecurity/trivy-0.51.2
Bump github.com/aquasecurity/trivy from 0.44.1 to 0.51.2 in /httphandler
2024-06-05 07:20:45 +02:00
dependabot[bot]
137fe81701 Bump github.com/aquasecurity/trivy from 0.44.1 to 0.51.2 in /httphandler
Bumps [github.com/aquasecurity/trivy](https://github.com/aquasecurity/trivy) from 0.44.1 to 0.51.2.
- [Release notes](https://github.com/aquasecurity/trivy/releases)
- [Changelog](https://github.com/aquasecurity/trivy/blob/main/goreleaser.yml)
- [Commits](https://github.com/aquasecurity/trivy/compare/v0.44.1...v0.51.2)

---
updated-dependencies:
- dependency-name: github.com/aquasecurity/trivy
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-06-04 21:16:10 +00:00
Matthias Bertschy
f293606f81 Merge pull request #1682 from slashben/vap-helper-features
Adding two helper functions for VAP and CEL admission library
2024-06-04 23:12:05 +02:00
Matthias Bertschy
d6d2315ad0 fixes for vap helper
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-06-04 13:41:00 +02:00
Ben
65aa28dd38 renaming command
Signed-off-by: Ben <ben@armosec.io>
2024-06-03 23:33:01 +03:00
David Wertenteil
15e55e011c Merge pull request #1688 from kubescape/fix-panic
Fix scanning unsupported clouds
2024-05-26 16:28:30 +03:00
David Wertenteil
0ee98351c0 fix scanning unsupported clouds
Signed-off-by: David Wertenteil <dwertent@armosec.io>
2024-05-26 15:45:19 +03:00
Matthias Bertschy
f52056a879 Merge pull request #1685 from kubescape/fixfix
fix yamlhandler deleting too many lines during fix
2024-05-23 10:19:02 +02:00
Matthias Bertschy
840162c865 fix yamlhandler deleting too many lines during fix
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-05-21 08:48:01 +02:00
Anubhav Gupta
160709eabf Merge branch 'master' of ssh://github.com/kubescape/kubescape into copa-grype 2024-05-17 13:37:25 +05:30
Ben Hirschberg
7f9f6d35f7 Merge pull request #1683 from kubescape/fix/mask-data
Mask all containers data
2024-05-09 20:42:28 +03:00
David Wertenteil
b2b37f6abc Mask all containers data
Signed-off-by: David Wertenteil <dwertent@armosec.io>
2024-05-09 19:08:09 +03:00
Ben
0863d845e1 Adding two helper functions for VAP and CEL admission library
Signed-off-by: Ben <ben@armosec.io>
2024-05-09 14:32:04 +03:00
David Wertenteil
da6faa3df0 Merge pull request #1680 from kubescape/fix/repo-scanning
Fix scanning repo
2024-05-07 09:16:20 +03:00
David Wertenteil
3cbd2c458d fix scanning repo
Signed-off-by: David Wertenteil <dwertent@armosec.io>
2024-05-06 16:22:38 +03:00
Matthias Bertschy
629451dd33 Merge pull request #1679 from kubescape/dependabot/go_modules/github.com/sigstore/cosign/v2-2.2.4
Bump github.com/sigstore/cosign/v2 from 2.2.3 to 2.2.4
2024-05-06 08:53:21 +02:00
dependabot[bot]
29a313e708 Bump github.com/sigstore/cosign/v2 from 2.2.3 to 2.2.4
Bumps [github.com/sigstore/cosign/v2](https://github.com/sigstore/cosign) from 2.2.3 to 2.2.4.
- [Release notes](https://github.com/sigstore/cosign/releases)
- [Changelog](https://github.com/sigstore/cosign/blob/main/CHANGELOG.md)
- [Commits](https://github.com/sigstore/cosign/compare/v2.2.3...v2.2.4)

---
updated-dependencies:
- dependency-name: github.com/sigstore/cosign/v2
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-05-06 06:18:56 +00:00
Matthias Bertschy
38896ccd24 Merge pull request #1678 from kubescape/dependabot/go_modules/httphandler/github.com/sigstore/cosign/v2-2.2.4
Bump github.com/sigstore/cosign/v2 from 2.2.3 to 2.2.4 in /httphandler
2024-05-06 08:13:09 +02:00
dependabot[bot]
834623762d Bump github.com/sigstore/cosign/v2 from 2.2.3 to 2.2.4 in /httphandler
Bumps [github.com/sigstore/cosign/v2](https://github.com/sigstore/cosign) from 2.2.3 to 2.2.4.
- [Release notes](https://github.com/sigstore/cosign/releases)
- [Changelog](https://github.com/sigstore/cosign/blob/main/CHANGELOG.md)
- [Commits](https://github.com/sigstore/cosign/compare/v2.2.3...v2.2.4)

---
updated-dependencies:
- dependency-name: github.com/sigstore/cosign/v2
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-05-06 05:40:44 +00:00
David Wertenteil
c937ed16f4 Merge pull request #1677 from kubescape/remove-tests
remove control_cluster tests
2024-05-01 10:21:42 +03:00
David Wertenteil
ea5f72af4e remove control_cluster tests
Signed-off-by: David Wertenteil <dwertent@armosec.io>
2024-05-01 10:17:22 +03:00
David Wertenteil
beb5a4d43e Merge pull request #1676 from kubescape/fix/wf-permissions
fix
2024-04-30 16:29:32 +03:00
David Wertenteil
77e21d5e94 fix
Signed-off-by: David Wertenteil <dwertent@armosec.io>
2024-04-30 16:28:19 +03:00
David Wertenteil
3fd7bf40cc Merge pull request #1675 from kubescape/fix/wf-permissions
fix
2024-04-30 16:25:48 +03:00
David Wertenteil
18e0a227e1 fix
Signed-off-by: David Wertenteil <dwertent@armosec.io>
2024-04-30 16:23:30 +03:00
David Wertenteil
060c17b480 Merge pull request #1674 from kubescape/fix/wf-permissions
Permissions
2024-04-30 16:19:40 +03:00
David Wertenteil
e67a2e9d1c permissions
Signed-off-by: David Wertenteil <dwertent@armosec.io>
2024-04-30 15:59:19 +03:00
David Wertenteil
dfa5f1037e Merge pull request #1673 from kubescape/operator-command
Fixed return status code
2024-04-30 15:55:27 +03:00
David Wertenteil
a15fc066e1 fixed return status code
Signed-off-by: David Wertenteil <dwertent@armosec.io>
2024-04-30 15:26:38 +03:00
David Wertenteil
effc57dfda Merge pull request #1672 from kubescape/bumpsyft
fix go.mod for httphandler
2024-04-30 11:16:12 +03:00
Matthias Bertschy
4b5c2dfed4 fix go.mod for httphandler
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-04-30 09:57:29 +02:00
David Wertenteil
f39d4efd62 Merge pull request #1671 from kubescape/fix/wf-permissions
update permissions
2024-04-30 10:28:22 +03:00
David Wertenteil
97ce466fbd update permissions
Signed-off-by: David Wertenteil <dwertent@armosec.io>
2024-04-30 10:27:23 +03:00
David Wertenteil
a94dc85e14 Merge pull request #1670 from kubescape/fix/wf-permissions
Adding attestations to the permissions
2024-04-30 10:23:48 +03:00
David Wertenteil
7811b0a4a6 adding attestations to the permissions
Signed-off-by: David Wertenteil <dwertent@armosec.io>
2024-04-30 10:21:35 +03:00
David Wertenteil
f9cc9b5b28 Merge pull request #1665 from kubescape/checksum
re-enable checksum generation for releases
2024-04-30 08:44:19 +03:00
David Wertenteil
2f208c0866 Merge pull request #1668 from kubescape/bump
bump opa-utils
2024-04-30 08:43:19 +03:00
David Wertenteil
97e4ca749b Merge pull request #1669 from kubescape/bumpsyft
bump syft version
2024-04-30 08:24:37 +03:00
Matthias Bertschy
9521cf1974 bump syft version
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-04-29 14:00:18 +02:00
Matthias Bertschy
8ec56976c5 bump opa-utils
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-04-25 18:48:40 +02:00
Matthias Bertschy
5993f2db3a re-enable checksum generation for releases
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-04-22 13:19:27 +02:00
David Wertenteil
d0abfb4ae7 Merge pull request #1663 from fanqiaojun/master
Fix some comments
2024-04-14 10:56:32 +03:00
fanqiaojun
bd35d521f2 Fix some comments
Signed-off-by: fanqiaojun <fanqiaojun@yeah.net>
2024-04-13 15:42:01 +08:00
Matthias Bertschy
533c0392d4 Merge pull request #1662 from maxgio92/issue/1661
chore(core/pkg/resultshandling): add control id to pdf output
2024-04-11 10:56:37 +02:00
Massimiliano Giovagnoli
e0f2944fc8 chore(core/pkg/resultshandling): add control id to pdf output
Add a new column in the PDF output to reference each control that has
been executed as control ID.

Signed-off-by: Massimiliano Giovagnoli <me@maxgio.it>
2024-04-10 17:11:30 +02:00
Anubhav Gupta
4c9cacecfe fix lint
Signed-off-by: Anubhav Gupta <mail.anubhav06@gmail.com>
2024-04-09 22:41:57 +05:30
Anubhav Gupta
6ee6a78a75 Merge branch 'master' of https://github.com/kubescape/kubescape into copa-grype 2024-04-09 21:37:46 +05:30
Anubhav Gupta
e754ecff4f fix grype name
Signed-off-by: Anubhav Gupta <mail.anubhav06@gmail.com>
2024-04-09 21:33:16 +05:30
Matthias Bertschy
bda7a17f41 Merge pull request #1658 from needsure/master
chore: fix function names in comment
2024-04-09 11:47:07 +02:00
needsure
dee6ed96f8 chore: fix function names in comment
Signed-off-by: needsure <qinzhipeng@outlook.com>
2024-04-09 16:33:24 +08:00
Matthias Bertschy
0d1de027c9 Merge pull request #1657 from kubescape/defaultbranch
remove api calls from scan repo
2024-04-09 10:15:28 +02:00
Matthias Bertschy
22c85b5e3b Merge pull request #1656 from kubescape/scorecard
fix ossf/scorecard
2024-04-09 08:47:10 +02:00
Matthias Bertschy
d27284b6f6 remove api calls from scan repo
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-04-09 07:37:58 +02:00
Matthias Bertschy
4bde684d8a fix ossf/scorecard
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-04-04 21:32:10 +02:00
Ben Hirschberg
8cf735f84c Merge pull request #1654 from slashben/master
Updates in roadmap
2024-04-03 23:55:13 +03:00
Ben
e1db7f3704 updates in roadmap
Signed-off-by: Ben <ben@armosec.io>
2024-04-03 23:45:47 +03:00
Ben Hirschberg
fd64a068aa Merge pull request #1653 from slashben/master
Evidence on public use
2024-04-03 11:51:03 +03:00
Ben Hirschberg
1945d3dfaa Evidence on public use 2024-04-03 11:42:39 +03:00
Matthias Bertschy
42670c7a9f Merge pull request #1652 from kubescape/matthyx-patch-1
Update community meeting schedule
2024-04-02 15:18:48 +02:00
Matthias Bertschy
81a9ca4254 Update community meeting schedule
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-04-02 15:17:13 +02:00
David Wertenteil
00c0a205d6 Merge pull request #1651 from kubescape/yuleib-patch-1
Update b-binary-build-and-e2e-tests.yaml
2024-04-01 13:53:31 +03:00
Yuval Leibovich
374d8be96f Update b-binary-build-and-e2e-tests.yaml
Signed-off-by: Yuval Leibovich <89763818+yuleib@users.noreply.github.com>
2024-04-01 13:34:13 +03:00
Matthias Bertschy
70daff7cec Merge pull request #1650 from kubescape/bump
bump deps for vulnerabilities
2024-03-28 12:06:56 +01:00
Matthias Bertschy
22fc14ae50 bump deps for vulnerabilities
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-03-28 10:05:38 +01:00
Matthias Bertschy
d9736d7d56 Merge pull request #1644 from kubescape/fix-panic-submitting-report
fix panic when submitting report
2024-03-27 10:54:28 +01:00
David Wertenteil
574763ccfc Merge pull request #1649 from kubescape/rego-v2
use regolibrary v2
2024-03-26 16:00:11 +02:00
YiscahLevySilas1
a8cc411945 update backend version
Signed-off-by: YiscahLevySilas1 <yiscahls@armosec.io>
2024-03-26 12:06:21 +02:00
Matthias Bertschy
0576548bbe Merge pull request #1648 from kubescape/scorecard
fix scorecard with actions/checkout v3.1.0
2024-03-26 08:41:07 +01:00
YiscahLevySilas1
0477f8cb03 use regolibrary v2
Signed-off-by: YiscahLevySilas1 <yiscahls@armosec.io>
2024-03-26 09:05:01 +02:00
Matthias Bertschy
9a2d58faa0 fix scorecard with actions/checkout v3.1.0
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-03-26 07:57:35 +01:00
Anubhav Gupta
b9fd60b395 fix
Signed-off-by: Anubhav Gupta <mail.anubhav06@gmail.com>
2024-03-26 12:06:16 +05:30
Matthias Bertschy
d975f8e64a Merge pull request #1646 from kubescape/checkout
bump actions/checkout to v4
2024-03-25 10:27:51 +01:00
Matthias Bertschy
a2bd504e36 bump actions/checkout to v4
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-03-25 08:42:47 +01:00
Amir Malka
8a671b9658 fix panic when submitting report
Signed-off-by: Amir Malka <amirm@armosec.io>
2024-03-19 11:39:26 +02:00
David Wertenteil
b7a4f82968 Merge pull request #1642 from kubescape/fix-gitlab
fix permissions
2024-03-18 11:11:12 +02:00
Matthias Bertschy
0ee121a08f fix permissions
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-03-18 10:09:42 +01:00
Matthias Bertschy
708bf4477a Fix gitlab (#1639)
* always use git token if we provide one

Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>

* bump go-git-url for gitlab fix

Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>

* fix action permissions for cosign signature

Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>

---------

Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-03-18 11:02:39 +02:00
Amir Malka
56a9d9a7f3 fix panic when error is returned from SubmitReport (#1640)
Signed-off-by: Amir Malka <amirm@armosec.io>
2024-03-17 14:08:04 +02:00
David Wertenteil
337fb96e3f Merge pull request #1638 from kubescape/skip
remove scan_with_exception_to_backend from CI
2024-03-14 18:51:33 +02:00
Matthias Bertschy
c5fa53c00f remove scan_with_exception_to_backend from CI
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-03-14 17:50:38 +01:00
David Wertenteil
e2dc7d24f9 Merge pull request #1636 from kubescape/fix-gitlab
httphandler go mod tidy
2024-03-14 11:29:31 +02:00
Matthias Bertschy
d13dd9b3a7 httphandler go mod tidy
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-03-14 10:15:57 +01:00
David Wertenteil
aa0f13e348 Merge pull request #1635 from kubescape/fix-gitlab
bump go-git-url to fix private gitlab scans
2024-03-14 10:55:09 +02:00
Matthias Bertschy
725eab67f9 bump go-git-url to fix private gitlab scans
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-03-14 08:51:56 +01:00
Matthias Bertschy
6efa37a14d Merge pull request #1634 from kubescape/riscv
add riscv64 files to release step
2024-03-13 16:55:24 +01:00
Matthias Bertschy
f05ab61421 add riscv64 files to release step
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-03-13 15:13:05 +01:00
David Wertenteil
5217ad21ec Merge pull request #1633 from kubescape/fixk8sclient
get KubernetesClient only if k8s is not nil
2024-03-13 14:20:49 +02:00
Matthias Bertschy
55e570a2b2 get KubernetesClient only if k8s is not nil
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-03-13 10:45:32 +01:00
David Wertenteil
f64617c88c Merge pull request #1632 from kubescape/speedup
speedup golangci-lint-action by skipping caches
2024-03-13 10:13:24 +02:00
Matthias Bertschy
ad4996e553 speedup golangci-lint-action by skipping caches
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-03-13 09:04:23 +01:00
David Wertenteil
46febea6d3 Merge pull request #1631 from kubescape/fixrelease
set BuildNumber and Client from env
2024-03-12 17:42:36 +02:00
Matthias Bertschy
da022a1cf0 set BuildNumber and Client from env
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-03-12 16:11:58 +01:00
David Wertenteil
9d11f2d881 Merge pull request #1630 from kubescape/risc
add risc v build target
2024-03-11 11:44:14 +02:00
Matthias Bertschy
d0521b83ae add risc v build target
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-03-11 09:15:46 +01:00
David Wertenteil
d8d6ab96df Merge pull request #1629 from kubescape/fix/sarif-fix
Remove repeating fixes
2024-03-11 09:47:42 +02:00
David Wertenteil
abefe8c21a Merge pull request #1593 from kubescape/daily
update daily report
2024-03-11 09:26:28 +02:00
David Wertenteil
0e0e1ed6fb remove repeating fixes
Signed-off-by: David Wertenteil <dwertent@armosec.io>
2024-03-11 09:22:03 +02:00
David Wertenteil
05ec28be48 Merge pull request #1628 from MMMMMMorty/fix_bug
Fix bug for no matches of yalib in one file mapping
2024-03-10 22:30:33 +02:00
mmmmmmorty
f5e110c212 Fix bug for no matches of yalib in one file mapping
Signed-off-by: mmmmmmorty <mmmmmmorty@outlook.com>
2024-03-08 10:50:39 +02:00
Matthias Bertschy
2429d2b89d move versioncheck to kubescape/backend
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-03-06 14:44:37 +01:00
David Wertenteil
cf75cc3a7a Merge pull request #1626 from kubescape/gitlab
bump go-git-url for self-hosted gitlab
2024-03-06 14:29:48 +02:00
Matthias Bertschy
f1c34efa97 bump go-git-url for self-hosted gitlab
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-03-06 11:51:36 +01:00
Anubhav Gupta
f0c3a568f0 change reference from anubhav06 to project-copacetic
Signed-off-by: Anubhav Gupta <mail.anubhav06@gmail.com>
2024-03-05 17:36:48 +01:00
David Wertenteil
7fd1396cff Fixed link (#1624)
* fixed link

Signed-off-by: David Wertenteil <dwertent@armosec.io>

* Adding unit tests to PR check

Signed-off-by: David Wertenteil <dwertent@armosec.io>

---------

Signed-off-by: David Wertenteil <dwertent@armosec.io>
2024-03-04 09:45:50 +02:00
David Wertenteil
522cc3a454 Merge pull request #1305 from hoorayman/fix/cmd-framework-redundant-code
fix(cmd/scan/framework.go): remove redundant code
2024-03-03 15:16:44 +02:00
David Wertenteil
cbdbd7433b Merge pull request #1623 from kubescape/go-sum
go sum
2024-03-01 15:22:39 +02:00
David Wertenteil
15b63401b7 go sum
Signed-off-by: David Wertenteil <dwertent@armosec.io>
2024-03-01 15:21:22 +02:00
David Wertenteil
7f5d513e6b Merge pull request #1622 from kubescape/fix/releaser-action
Release artifacts
2024-03-01 15:13:35 +02:00
David Wertenteil
e87f3399c7 fixed release artifacts
Signed-off-by: David Wertenteil <dwertent@armosec.io>
2024-03-01 15:09:25 +02:00
Alfredo Garcia
fad8f2b272 Add Vulnerability scanning report to the summaryDetails section (#1615)
* Add Vulnerability scanning report to the summaryDetails section

Signed-off-by: Alfredo Garcia <algarcia@vmware.com>

* Updating the opa-utils dependency version

Signed-off-by: Alfredo Garcia <algarcia@vmware.com>

---------

Signed-off-by: Alfredo Garcia <algarcia@vmware.com>
2024-03-01 14:59:23 +02:00
MMMMMMorty
bc33f10d0a feat: Add the debugging ability for scanning Helm chart (#1215)
* Fix issue 11552

Signed-off-by: MMMMMMorty <465346562@qq.com>

* Add helm chart mapping node for sarif printer

Signed-off-by: mmmmmmorty <mmmmmmorty@outlook.com>

* add MappingNodes to getWorkloadFromHelmChart

Signed-off-by: mmmmmmorty <mmmmmmorty@outlook.com>

* clear the code to mappingnode and parseFile

Signed-off-by: mmmmmmorty <mmmmmmorty@outlook.com>

* add input to fixPathsToString

Signed-off-by: mmmmmmorty <mmmmmmorty@outlook.com>

* add fixs for error message

Signed-off-by: mmmmmmorty <mmmmmmorty@outlook.com>

* Add solution for multiple files in one yaml helm chart file

Signed-off-by: mmmmmmorty <mmmmmmorty@outlook.com>

* Add parseFile tests

Signed-off-by: mmmmmmorty <mmmmmmorty@outlook.com>

---------

Signed-off-by: MMMMMMorty <465346562@qq.com>
Signed-off-by: mmmmmmorty <mmmmmmorty@outlook.com>
2024-03-01 14:31:51 +02:00
David Wertenteil
0033dc881e Merge pull request #1620 from MMMMMMorty/fix_action_workflow
add github action actor check for pr-scanner
2024-02-29 16:29:58 +02:00
mmmmmmorty
9549e0dcde add github action actor check for pr-scanner
Signed-off-by: mmmmmmorty <mmmmmmorty@outlook.com>
2024-02-29 15:23:27 +01:00
David Wertenteil
809146c070 Merge pull request #1619 from kubescape/fix/release
fix goreleaser
2024-02-29 13:11:20 +02:00
David Wertenteil
546b982891 fix goreleaser
Signed-off-by: David Wertenteil <dwertent@armosec.io>
2024-02-29 13:04:26 +02:00
David Wertenteil
f8ac5af31b Merge pull request #1618 from kubescape/fix/exceptions
Fixing exceptions for regovector objects
2024-02-29 09:16:12 +02:00
David Wertenteil
20babdc071 Merge pull request #1614 from kubescape/revert-1612-adopters
Revert "add PR template for adopters"
2024-02-29 08:43:38 +02:00
David Wertenteil
533edc6d05 Fixing exceptions for regovector objects
Signed-off-by: David Wertenteil <dwertent@armosec.io>
2024-02-29 08:42:32 +02:00
David Wertenteil
3362a38d09 Merge pull request #1616 from kubescape/bump-syft
image scan add schema v1 support
2024-02-28 13:16:04 +02:00
Matthias Bertschy
ac6c5ca570 image scan add schema v1 support
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-02-28 10:25:16 +01:00
David Wertenteil
ea7a8bef94 Fix/backlog (#1613)
* Many minor improvements

Signed-off-by: David Wertenteil <dwertent@armosec.io>

* Handle fw scan error

Signed-off-by: David Wertenteil <dwertent@armosec.io>

* Remove prometheus docs

Signed-off-by: David Wertenteil <dwertent@armosec.io>

* fix workload threshold

Signed-off-by: David Wertenteil <dwertent@armosec.io>

* fixed units

Signed-off-by: David Wertenteil <dwertent@armosec.io>

---------

Signed-off-by: David Wertenteil <dwertent@armosec.io>
2024-02-26 22:42:41 +02:00
David Wertenteil
e74ceec858 Revert "add PR template for adopters" 2024-02-26 17:45:19 +02:00
David Wertenteil
e6150d405e Merge pull request #1612 from kubescape/adopters
add PR template for adopters
2024-02-26 17:44:55 +02:00
Matthias Bertschy
86331c6abd add PR template for adopters
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-02-26 13:45:41 +01:00
Matthias Bertschy
3f866683a4 Merge pull request #1611 from kubescape/dependabot/go_modules/httphandler/helm.sh/helm/v3-3.14.2
Bump helm.sh/helm/v3 from 3.12.1 to 3.14.2 in /httphandler
2024-02-25 22:40:38 +01:00
dependabot[bot]
3affee539f Bump helm.sh/helm/v3 from 3.12.1 to 3.14.2 in /httphandler
Bumps [helm.sh/helm/v3](https://github.com/helm/helm) from 3.12.1 to 3.14.2.
- [Release notes](https://github.com/helm/helm/releases)
- [Commits](https://github.com/helm/helm/compare/v3.12.1...v3.14.2)

---
updated-dependencies:
- dependency-name: helm.sh/helm/v3
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-02-25 21:35:19 +00:00
Matthias Bertschy
513bfa91be Merge pull request #1610 from kubescape/dependabot/go_modules/helm.sh/helm/v3-3.14.2
Bump helm.sh/helm/v3 from 3.12.1 to 3.14.2
2024-02-25 22:32:36 +01:00
dependabot[bot]
e644b6cc74 Bump helm.sh/helm/v3 from 3.12.1 to 3.14.2
Bumps [helm.sh/helm/v3](https://github.com/helm/helm) from 3.12.1 to 3.14.2.
- [Release notes](https://github.com/helm/helm/releases)
- [Commits](https://github.com/helm/helm/compare/v3.12.1...v3.14.2)

---
updated-dependencies:
- dependency-name: helm.sh/helm/v3
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-02-25 21:29:21 +00:00
David Wertenteil
10f0a04a6e Merge pull request #1609 from kubescape/fix/eks-region-parser
Bump k8s-interface version
2024-02-25 10:20:40 +02:00
David Wertenteil
6c5c1265d5 Bump k8s-interface version
Signed-off-by: David Wertenteil <dwertent@armosec.io>
2024-02-22 18:23:48 +02:00
David Wertenteil
18df5dc5ed Merge pull request #1608 from kubescape/fix/unknown-fw
Handle unknown fw
2024-02-22 17:52:23 +02:00
David Wertenteil
05903e34ff Handle unknown fw
Signed-off-by: David Wertenteil <dwertent@armosec.io>
2024-02-22 17:05:38 +02:00
David Wertenteil
9b05fb60e4 Merge pull request #1607 from kubescape/fix/fw-list
Remove "%" from the print
2024-02-22 15:36:24 +02:00
David Wertenteil
d01a7977ae Remove "%" from the print
Signed-off-by: David Wertenteil <dwertent@armosec.io>
2024-02-22 14:26:51 +02:00
David Wertenteil
121e4ccad4 Merge pull request #1590 from kubescape/nolibgit
remove libgit files and dependencies
2024-02-21 15:29:04 +02:00
hoorayman
f1eaf09570 fix(cmd/scan/framework.go): remove redundant code
Signed-off-by: hoorayman <813458665@qq.com>
2024-02-20 10:40:17 +08:00
Matthias Bertschy
179befbcd5 Merge pull request #1599 from kubescape/dependabot/go_modules/github.com/moby/buildkit-0.12.5
Bump github.com/moby/buildkit from 0.12.1 to 0.12.5
2024-02-07 13:34:50 +01:00
dependabot[bot]
036b7e25fa Bump github.com/moby/buildkit from 0.12.1 to 0.12.5
Bumps [github.com/moby/buildkit](https://github.com/moby/buildkit) from 0.12.1 to 0.12.5.
- [Release notes](https://github.com/moby/buildkit/releases)
- [Commits](https://github.com/moby/buildkit/compare/v0.12.1...v0.12.5)

---
updated-dependencies:
- dependency-name: github.com/moby/buildkit
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-02-07 11:15:26 +00:00
Matthias Bertschy
cf8c00fb54 Merge pull request #1598 from kubescape/dependabot/go_modules/httphandler/github.com/moby/buildkit-0.12.5
Bump github.com/moby/buildkit from 0.12.1 to 0.12.5 in /httphandler
2024-02-07 12:12:54 +01:00
dependabot[bot]
5fd7529c90 Bump github.com/moby/buildkit from 0.12.1 to 0.12.5 in /httphandler
Bumps [github.com/moby/buildkit](https://github.com/moby/buildkit) from 0.12.1 to 0.12.5.
- [Release notes](https://github.com/moby/buildkit/releases)
- [Commits](https://github.com/moby/buildkit/compare/v0.12.1...v0.12.5)

---
updated-dependencies:
- dependency-name: github.com/moby/buildkit
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-02-07 09:46:39 +00:00
Matthias Bertschy
be5efbb3ef correct kubescape path in run-tests
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-01-20 22:00:49 +01:00
Matthias Bertschy
3e287db1f9 remove libgit files and dependencies
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-01-20 10:24:21 +01:00
Matthias Bertschy
71fac79876 Merge pull request #1589 from kubescape/dependabot/go_modules/github.com/cloudflare/circl-1.3.7
Bump github.com/cloudflare/circl from 1.3.3 to 1.3.7
2024-01-18 07:31:34 +01:00
dependabot[bot]
f430120ff4 Bump github.com/cloudflare/circl from 1.3.3 to 1.3.7
Bumps [github.com/cloudflare/circl](https://github.com/cloudflare/circl) from 1.3.3 to 1.3.7.
- [Release notes](https://github.com/cloudflare/circl/releases)
- [Commits](https://github.com/cloudflare/circl/compare/v1.3.3...v1.3.7)

---
updated-dependencies:
- dependency-name: github.com/cloudflare/circl
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-01-17 16:52:37 +00:00
Matthias Bertschy
8844f8144b Merge pull request #1586 from kubescape/fix-cosign
fetch Rekor before cosign validation
2024-01-16 12:39:28 +01:00
YiscahLevySilas1
1b59b6a35f fix backslashes
Signed-off-by: YiscahLevySilas1 <yiscahls@armosec.io>
2024-01-16 11:59:28 +02:00
Matthias Bertschy
6a6e4181bd fetch Rekor before cosign validation
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-01-15 14:33:39 +01:00
Matthias Bertschy
5e41d7db1e Merge pull request #1584 from kubescape/dependabot/go_modules/httphandler/github.com/cloudflare/circl-1.3.7
Bump github.com/cloudflare/circl from 1.3.3 to 1.3.7 in /httphandler
2024-01-15 11:48:02 +01:00
dependabot[bot]
5e9fbf05f1 Bump github.com/cloudflare/circl from 1.3.3 to 1.3.7 in /httphandler
Bumps [github.com/cloudflare/circl](https://github.com/cloudflare/circl) from 1.3.3 to 1.3.7.
- [Release notes](https://github.com/cloudflare/circl/releases)
- [Commits](https://github.com/cloudflare/circl/compare/v1.3.3...v1.3.7)

---
updated-dependencies:
- dependency-name: github.com/cloudflare/circl
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-01-15 07:28:16 +00:00
David Wertenteil
b4f58f3a6d Merge pull request #1581 from matoruru/patch-1
Fix markdown syntax error
2024-01-11 10:35:23 +02:00
David Wertenteil
2ec3e47f0a Merge pull request #1455 from matthyx/master
use goreleaser for builds
2024-01-11 10:35:11 +02:00
matoruru
b6030c0bc5 Fix markdown syntax
Signed-off-by: matoruru <40382980+matoruru@users.noreply.github.com>
2024-01-10 15:36:56 +09:00
Amir Malka
4b8786bcaa checking for compatible policy rules before pulling k8s resources; failing to pull some k8s resource should not fail the entire scan (#1578)
Signed-off-by: Amir Malka <amirm@armosec.io>
2024-01-09 09:44:45 +02:00
Matthias Bertschy
bdefcd2442 use goreleaser for builds
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2024-01-09 08:10:05 +01:00
David Wertenteil
4e4a642673 Fixed filepath test (#1577)
* remove unstable tests

Signed-off-by: David Wertenteil <dwertent@armosec.io>

* skip tests on windows

Signed-off-by: David Wertenteil <dwertent@armosec.io>

* temp: skip tests

Signed-off-by: David Wertenteil <dwertent@armosec.io>

---------

Signed-off-by: David Wertenteil <dwertent@armosec.io>
2024-01-08 10:29:31 +02:00
David Wertenteil
3634499e11 Fixed filepath test (#1576)
* remove unstable tests

Signed-off-by: David Wertenteil <dwertent@armosec.io>

* skip tests on windows

Signed-off-by: David Wertenteil <dwertent@armosec.io>

---------

Signed-off-by: David Wertenteil <dwertent@armosec.io>
2024-01-07 23:00:16 +02:00
David Wertenteil
9f5d4f97df Merge pull request #1575 from kubescape/fixed-filepath-test
filepath test
2024-01-07 20:37:38 +02:00
David Wertenteil
a0e6ebe0e0 filepath test
Signed-off-by: David Wertenteil <dwertent@armosec.io>
2024-01-07 18:00:45 +02:00
David Wertenteil
65a557db90 fixed test (#1573)
* fixed test

Signed-off-by: David Wertenteil <dwertent@armosec.io>

* update cosign-release version

Signed-off-by: David Wertenteil <dwertent@armosec.io>

* fixed filepath related tests

Signed-off-by: David Wertenteil <dwertent@armosec.io>

* failed windows tests

Signed-off-by: David Wertenteil <dwertent@armosec.io>

* fixed cosign version

Signed-off-by: David Wertenteil <dwertent@armosec.io>

* update go version

Signed-off-by: David Wertenteil <dwertent@armosec.io>

* fixed test

Signed-off-by: David Wertenteil <dwertent@armosec.io>

* change actor

Signed-off-by: David Wertenteil <dwertent@armosec.io>

* Cosign use secret

Signed-off-by: David Wertenteil <dwertent@armosec.io>

* update cosign

Signed-off-by: David Wertenteil <dwertent@armosec.io>

* update cosign

Signed-off-by: David Wertenteil <dwertent@armosec.io>

---------

Signed-off-by: David Wertenteil <dwertent@armosec.io>
2024-01-07 16:26:34 +02:00
David Wertenteil
d15a837139 Hotfix gitlab url (#1572)
* update pkgs

Signed-off-by: David Wertenteil <dwertent@armosec.io>

* update k8sinterface

Signed-off-by: David Wertenteil <dwertent@armosec.io>

* bump k8s-interface pkg

Signed-off-by: David Wertenteil <dwertent@armosec.io>

* update k8sinterface

Signed-off-by: David Wertenteil <dwertent@armosec.io>

* go mod

Signed-off-by: David Wertenteil <dwertent@armosec.io>

---------

Signed-off-by: David Wertenteil <dwertent@armosec.io>
2024-01-04 16:29:40 +02:00
David Wertenteil
d4cb97905e Merge pull request #1566 from kubescape/fix-naming-convention
Bump k8s-interface pkg
2024-01-04 16:05:38 +02:00
Matthias Bertschy
4208ed1ca6 Merge pull request #1456 from kubescape/fix-docker-build
Fix Docker Build for Kubescape-CLI
2024-01-03 15:52:12 +01:00
Matthias Bertschy
4adb1da4d2 Merge pull request #1556 from VaibhavMalik4187/locationresolver-tests
Added missing tests for locationresolver
2024-01-03 15:49:40 +01:00
Matthias Bertschy
3ba1e9c187 Merge pull request #1570 from kubescape/dependabot/go_modules/github.com/go-git/go-git/v5-5.11.0
Bump github.com/go-git/go-git/v5 from 5.8.1 to 5.11.0
2024-01-03 14:35:35 +01:00
dependabot[bot]
81eec99b51 Bump github.com/go-git/go-git/v5 from 5.8.1 to 5.11.0
Bumps [github.com/go-git/go-git/v5](https://github.com/go-git/go-git) from 5.8.1 to 5.11.0.
- [Release notes](https://github.com/go-git/go-git/releases)
- [Commits](https://github.com/go-git/go-git/compare/v5.8.1...v5.11.0)

---
updated-dependencies:
- dependency-name: github.com/go-git/go-git/v5
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-01-03 13:00:47 +00:00
Matthias Bertschy
3ba3af8244 Merge pull request #1569 from kubescape/dependabot/go_modules/httphandler/github.com/go-git/go-git/v5-5.11.0
Bump github.com/go-git/go-git/v5 from 5.8.1 to 5.11.0 in /httphandler
2024-01-03 13:58:31 +01:00
dependabot[bot]
8ca6f71d57 Bump github.com/go-git/go-git/v5 from 5.8.1 to 5.11.0 in /httphandler
Bumps [github.com/go-git/go-git/v5](https://github.com/go-git/go-git) from 5.8.1 to 5.11.0.
- [Release notes](https://github.com/go-git/go-git/releases)
- [Commits](https://github.com/go-git/go-git/compare/v5.8.1...v5.11.0)

---
updated-dependencies:
- dependency-name: github.com/go-git/go-git/v5
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-01-02 11:31:26 +00:00
David Wertenteil
10278a9088 bump k8s-interface pkg
Signed-off-by: David Wertenteil <dwertent@armosec.io>
2023-12-24 15:50:17 +02:00
VaibhavMalik4187
155889a479 Added missing tests for locationresolver
Wrote new tests to cover the unhandled statements in the
`NewFixPathLocationResolver` and `ResolveLocation` functions.

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
2023-12-23 17:23:07 +05:30
Yuval Leibovich
06d9c9d31c Merge pull request #1562 from kubescape/remove-control-0086
Remove control 0086
2023-12-14 18:50:37 +02:00
David Wertenteil
f309d54b08 Merge pull request #1558 from kubescape/wlid
add wlid annotation to workloadconfigurationscans and summaries
2023-12-14 13:35:48 +02:00
Yuval Leibovich
0d2a667299 Update html-format.html
Signed-off-by: Yuval Leibovich <89763818+yuleib@users.noreply.github.com>
2023-12-13 15:45:58 +02:00
Yuval Leibovich
1dd8022d6a removing control 0086
Signed-off-by: Yuval Leibovich <89763818+yuleib@users.noreply.github.com>
2023-12-13 15:42:42 +02:00
Matthias Bertschy
e29e6a5e8a add wlid annotation to workloadconfigurationscans and summaries
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2023-12-12 10:42:02 +01:00
Matthias Bertschy
e27237047e Merge pull request #1561 from kubescape/bump
patch GHSA-3f2q-6294-fmq5 by switching to chainguard's fork
2023-12-11 07:29:00 +01:00
Matthias Bertschy
1b260f60cc patch GHSA-3f2q-6294-fmq5 by switching to chainguard's fork
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2023-12-11 07:19:05 +01:00
David Wertenteil
882a8404d3 Merge pull request #1557 from kubescape/feature/slack-badge
Adding slack badge to README.md
2023-12-05 16:49:58 +02:00
Amit Schendel
b797413ef0 Adding slack badge to README.md
Signed-off-by: Amit Schendel <amitschendel@gmail.com>
2023-12-04 21:36:00 +02:00
David Wertenteil
298e30e857 Merge pull request #1489 from kubescape/oshrat_branch
update readme
2023-12-03 16:30:42 +02:00
David Wertenteil
6ba727b721 Merge pull request #1555 from kubescape/adding-start-badge
Adding stars badge
2023-12-03 16:30:12 +02:00
Matthias Bertschy
362557a964 Merge pull request #1554 from VaibhavMalik4187/scan-crash-fix
Fixed crash when running the scan command
2023-12-01 07:12:09 +01:00
Amit Schendel
c119911914 Adding starts badge
Signed-off-by: Amit Schendel <amitschendel@gmail.com>
2023-11-30 13:54:21 +02:00
VaibhavMalik4187
de2e86dc6e Fixed crash when running the scan command
Updated the `getSortPackageScores` function to fix the crash in the scan
command.

Fixes: https://github.com/kubescape/kubescape/issues/1553

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
2023-11-30 15:12:33 +05:30
Matthias Bertschy
a2aa52f4cb Merge pull request #1551 from MMMMMMorty/fix_action_workflow
Add github action actor check for binary-build
2023-11-28 15:46:50 +01:00
mmmmmmorty
a382a2c5a3 add github action actor check for binary-build
Signed-off-by: mmmmmmorty <mmmmmmorty@outlook.com>
2023-11-28 14:35:36 +01:00
Matthias Bertschy
dd5a18c8fa Merge pull request #1544 from mohaidoss/Improvement/ks-cloud-logs
Enhancement of Logging Mechanisms for KS Cloud Usage
2023-11-27 16:48:10 +01:00
Yuval Leibovich
e4e795c6dc Merge pull request #1548 from kubescape/remove-armoBuiltin
Removal of "armoBuiltin" attribute from JSON files
2023-11-27 16:17:35 +02:00
Matthias Bertschy
2c65d92d69 Merge pull request #1549 from VaibhavMalik4187/junit-tests
Addition of new tests for junit printer, version check and PDF printer
2023-11-27 15:02:17 +01:00
VaibhavMalik4187
d1b78856ca Added tests for versioncheck and printer packages
Wrote new tests for the following files:
- junit.go
- pdf.go
- versioncheck.go

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
2023-11-27 18:25:34 +05:30
Matthias Bertschy
289e055014 Merge pull request #1547 from kubescape/add-scan-source
add scan source
2023-11-27 12:38:11 +01:00
Matthias Bertschy
81ba550043 Merge pull request #1537 from VaibhavMalik4187/printer-tests-continued
Addition of Tests for the PrettyPrinter Package
2023-11-27 11:11:15 +01:00
Matthias Bertschy
8e5d8e5c96 Merge pull request #1539 from VaibhavMalik4187/prettyprinter/utils
Performance Enhancements and Test Additions in prettyprinter/utils.go
2023-11-27 11:08:16 +01:00
Matthias Bertschy
5789f1f0fa Merge pull request #1542 from VaibhavMalik4187/imageprinter-tests
Added new tests in the imagewriter package
2023-11-27 11:07:30 +01:00
Matthias Bertschy
9a523f4a01 Merge pull request #1545 from VaibhavMalik4187/configurationprinter-tests
Enhancements and Tests for Configuration Printer
2023-11-27 11:06:38 +01:00
Matthias Bertschy
fb3357fba4 Merge pull request #1546 from kubescape/set-default-format
Set default format
2023-11-27 11:02:49 +01:00
Yuval Leibovich
69362ae415 Update MITRE.json
Signed-off-by: Yuval Leibovich <89763818+yuleib@users.noreply.github.com>
2023-11-27 12:01:14 +02:00
Daniel Grunberger
de799d7b75 fix version
Signed-off-by: Daniel Grunberger <danielgrunberger@armosec.io>
2023-11-27 11:58:04 +02:00
Yuval Leibovich
bb17e1de78 Update NSA.json
Signed-off-by: Yuval Leibovich <89763818+yuleib@users.noreply.github.com>
2023-11-27 11:57:31 +02:00
Daniel Grunberger
23013d6fe6 bring back version
Signed-off-by: Daniel Grunberger <danielgrunberger@armosec.io>
2023-11-27 11:57:03 +02:00
Daniel Grunberger
27d2fe8f27 fix version
Signed-off-by: Daniel Grunberger <danielgrunberger@armosec.io>
2023-11-27 11:56:03 +02:00
Yuval Leibovich
504891f519 Update C-0001.json
Signed-off-by: Yuval Leibovich <89763818+yuleib@users.noreply.github.com>
2023-11-27 11:51:09 +02:00
Yuval Leibovich
d1606c5e39 Update processorhandler_test.go
Signed-off-by: Yuval Leibovich <89763818+yuleib@users.noreply.github.com>
2023-11-27 11:46:50 +02:00
Daniel Grunberger
952beddcc3 add scan source
Signed-off-by: Daniel Grunberger <danielgrunberger@armosec.io>
2023-11-27 11:24:25 +02:00
Daniel Grunberger
9630adc74b remove toolchain
Signed-off-by: Daniel Grunberger <danielgrunberger@armosec.io>
2023-11-27 09:53:01 +02:00
Daniel Grunberger
27c171d09c go mod for http
Signed-off-by: Daniel Grunberger <danielgrunberger@armosec.io>
2023-11-27 09:45:29 +02:00
Daniel Grunberger
bd79fe4d8d update go version
Signed-off-by: Daniel Grunberger <danielgrunberger@armosec.io>
2023-11-27 09:37:13 +02:00
Daniel Grunberger
08f3756608 fix test
Signed-off-by: Daniel Grunberger <danielgrunberger@armosec.io>
2023-11-27 09:25:07 +02:00
Daniel Grunberger
7cda7346b7 set default
Signed-off-by: Daniel Grunberger <danielgrunberger@armosec.io>
2023-11-27 08:56:33 +02:00
VaibhavMalik4187
8cd0bddf6f Enhancements and tests for configurationprinter
Wrote new tests for `categorytable` and `frameworkscan`

Refactored the `shortFormatRow` function for:
- Imporved readability
- Consistency
- Improve code modularity
- Encapsulation: The formatted string construction is encapsulated
  within the function, maintaining code modularity and separation of
  concerns.

Added the `MockISeverityCounters` mock struct to test the
`renderSeverityCountersSummary` function.

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
2023-11-27 11:35:24 +05:30
VaibhavMalik4187
8fa7fc922d Added tests for the prettyprinter package
Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
2023-11-27 03:46:45 +05:30
VaibhavMalik4187
6a2e48ac74 Performance enhancements in utils.go
Improvments:
1. filterCVEsBySeverities
  - This approach is faster than iterating over the severities slice
    for each CVE. The map is created in advance, eliminating the
    need for repeated string comparisons.

2. getSortPackageScores
  - Avoids unnecessary map lookups by creating a slice of
    imageprinter.PackageScore pointers.

3. getSortedCVEsBySeverity
  - Avoiding Map Lookups
  - Efficient Sorting
  - Optimized Output

Added tests for tableprinter/utils

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
2023-11-27 03:15:20 +05:30
Mehdi Moussaif
b68cfbed67 Added logs for when KS CLOUD is used
Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>
2023-11-26 22:26:58 +01:00
VaibhavMalik4187
0bfbb87285 Added tests in imageprinter package
Added tests for the following functions:
- `generateTable`
- `NewTableWriter`
- `PrintImageScanningTable`

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
2023-11-27 02:33:15 +05:30
Matthias Bertschy
491ed09f6c Merge pull request #1536 from VaibhavMalik4187/printer/pdf-tests
Enhancement and Test Suite for Printer Functions
2023-11-26 22:02:03 +01:00
Matthias Bertschy
658855aaee Merge pull request #1540 from mohaidoss/enhancement/yamlfile_validation
Enhancement of YAML File Validation and Corresponding Test Cases
2023-11-26 21:55:53 +01:00
Matthias Bertschy
5ed8e180b3 Merge pull request #1521 from Umair0343/fix/add-missing-test-case
Added new test cases for different shell completions in the completion package to enhance test coverage.
2023-11-26 21:52:53 +01:00
VaibhavMalik4187
e4477eaac4 Fixed invalid input bug, added tests for printers
Added tests in the jsonprinter.go, junit.go pdf.go prometheus.go files
and updated the `Score` functions to handle invalid scores.

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
2023-11-27 01:25:46 +05:30
Matthias Bertschy
64351f93be Merge pull request #1538 from mohaidoss/tests/core-pkg-resourceprioritization
Refactoring and Adding Tests for Resource Prioritization
2023-11-26 20:32:50 +01:00
Mehdi Moussaif
70a010976e Removed unused functions
Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>
2023-11-26 19:06:10 +01:00
Mehdi Moussaif
d653530ba2 Add YAML validation
Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>
2023-11-26 16:34:37 +01:00
Mehdi Moussaif
5242e8c4b0 Add test cases for loading host sensor from file
Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>
2023-11-26 16:34:26 +01:00
Mehdi Moussaif
efd2f7e77f Adding tests for core/pkg/resourcesprioritization
Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>
2023-11-26 14:56:12 +01:00
Mehdi Moussaif
16c632950d SupportedKinds refactored
Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>
2023-11-26 14:43:12 +01:00
Umair
070d8544cd Update completion_test.go
removed the package import "strings" as it was not being used in the code

Signed-off-by: Umair <58398786+Umair0343@users.noreply.github.com>
2023-11-26 16:26:21 +05:00
Yuval Leibovich
b562c1d730 Merge pull request #1499 from kubescape/armoBuildin-removal
Update loadmocks.go
2023-11-26 13:06:35 +02:00
Matthias Bertschy
fdeadda704 Merge pull request #1534 from VaibhavMalik4187/printer/prometheusutils-tests
Added Test Suite for Prometheus Utilities
2023-11-26 11:58:47 +01:00
Matthias Bertschy
5ef720bfee Merge pull request #1533 from Umair0343/patch-4
Update framework_test.go (Add Test Case for Non-Existent Framework in…
2023-11-26 11:56:25 +01:00
Matthias Bertschy
0bc2b33e99 Merge pull request #1531 from Umair0343/patch-3
Update control_test.go (Add Test Case for Non-Existent Control in Get…
2023-11-26 11:55:11 +01:00
Matthias Bertschy
b9bcb6bbbf Merge pull request #1529 from Umair0343/patch-2
Update patch_test.go (Add Test Case for Non-Existent Image in GetPatchCmd)
2023-11-26 11:54:28 +01:00
Matthias Bertschy
620f9b2717 Merge pull request #1528 from sulemaanhamza/test-suite-strutils
Enhancement and Testing of String Utilities
2023-11-26 11:51:42 +01:00
Matthias Bertschy
2ff1512ed0 Merge pull request #1527 from Umair0343/patch-1
Update set_test.go
2023-11-26 11:47:25 +01:00
Matthias Bertschy
ca57f66b8b Merge pull request #1525 from VaibhavMalik4187/printer/resourcetable-tests
Enhancement and Test Suite for ResourceTable
2023-11-26 11:45:46 +01:00
VaibhavMalik4187
770f660db5 Enhancements and Test Suite for resourcetable
Wrote new tests for the functions in the resourcetable.go file.

Enhancements:
1. `generateResourceHeader`:
  - Dynamic Header Length
  - Efficient Header Creation
  - Clearer Code Structure

2. `appendFailedPathsIfNotInPaths`:
  - Create a set to efficiently check if a failed path already exists in
    the paths slice
  - Append failed paths if they are not already present

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
2023-11-26 15:50:40 +05:30
VaibhavMalik4187
f54c2ee822 Added Test Suite for prometheusutils
Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
2023-11-26 15:00:15 +05:30
Umair
5172ce30d1 Update framework_test.go (Add Test Case for Non-Existent Framework in GetFrameworkCmd)
Description:

This pull request introduces a new test case TestGetFrameworkCmdWithNonExistentFramework in the framework_test.go file. The purpose of this test case is to verify the behavior of the getFrameworkCmd function when it's run with a non-existent framework argument.

In this test case, we:

Create a mock Kubescape interface and a ScanInfo object
Call the getFrameworkCmd function with the mock interface and ScanInfo object
Run the command with a non-existent framework argument
Check that there is an error and the error message is "bad argument: account ID must be a valid UUID"

This test case enhances the test coverage of the getFrameworkCmd function and ensures that it correctly handles non-existent framework arguments.

Signed-off-by: Umair <58398786+Umair0343@users.noreply.github.com>
2023-11-26 13:29:20 +05:00
Umair
4e24ad87dd Update control_test.go (Add Test Case for Non-Existent Control in GetControlCmd)
Description:

This pull request introduces a new test case TestGetControlCmdWithNonExistentControl in the control_test.go file. The purpose of this test case is to verify the behavior of the getControlCmd function when it's run with a non-existent control argument.

In this test case, we:

Create a mock Kubescape interface and a ScanInfo object
Call the getControlCmd function with the mock interface and ScanInfo object
Run the command with a non-existent control argument
Check that there is an error and the error message is "bad argument: account ID must be a valid UUID"

This test case enhances the test coverage of the getControlCmd function and ensures that it correctly handles non-existent control arguments.

Signed-off-by: Umair <58398786+Umair0343@users.noreply.github.com>
2023-11-26 13:20:00 +05:00
Umair
c49f9c88e2 Update patch_test.go
Title: Add Test Case for Non-Existent Image in GetPatchCmd

Description:

This pull request introduces a new test case TestGetPatchCmdWithNonExistentImage in the patch_test.go file. The purpose of this test case is to verify the behavior of the GetPatchCmd function when it's run with a non-existent image argument.

In this test case, we:

Create a mock Kubescape interface
Call the GetPatchCmd function with the mock interface
Run the command with a non-existent image argument
Check that there is an error and the error message is "image tag is required"

This test case enhances the test coverage of the GetPatchCmd function and ensures that it correctly handles non-existent image arguments.

Signed-off-by: Umair <58398786+Umair0343@users.noreply.github.com>
2023-11-26 13:06:18 +05:00
Yuval Leibovich
4bf3783677 Update a-pr-scanner.yaml
Signed-off-by: Yuval Leibovich <89763818+yuleib@users.noreply.github.com>
2023-11-26 10:03:10 +02:00
Yuval Leibovich
139a89770f Update a-pr-scanner.yaml
Signed-off-by: Yuval Leibovich <89763818+yuleib@users.noreply.github.com>
2023-11-26 09:47:59 +02:00
sulemaanhamza
c84a8a7dea Enhancements in strutils and added test-suite with edge-case test-cases
Signed-off-by: sulemaanhamza <sulemanhamza97@gmail.com>
2023-11-26 12:43:17 +05:00
Umair
2fb4efa531 Update set_test.go
Pull Request Description:

Changes Made
Added a new test case TestParseSetArgs_InvalidKey in the config package to cover scenarios where an invalid key is provided in the set command arguments.

Test Case Details
Function Tested: TestParseSetArgs_InvalidKey
Test Objective: Ensures that the parseSetArgs function correctly handles the scenario where an invalid key is provided, returning an appropriate error message.
Test Input: Command arguments with an invalid key, e.g., invalidKey=value1.
Expected Output: The function should return an error message indicating that the provided key is unknown, along with the list of supported keys.

Motivation
This new test case enhances the test coverage for the parseSetArgs function, ensuring robust handling of invalid keys during the configuration setting process. By validating that the function produces the expected error message for such cases, we contribute to the overall reliability of the codebase. This addition further strengthens the testing suite for the config package, promoting code quality and correctness.

Signed-off-by: Umair <58398786+Umair0343@users.noreply.github.com>
2023-11-26 11:04:01 +05:00
Umair
1d2993e83e Update completion_test.go
Pull Request Description:

Changes Made
Added new test cases for different shell completions in the completion package to enhance test coverage.

New Test Cases
TestGetCompletionCmd_RunBashCompletionNotExpectedOutputs: Tests that the output for Bash completion does not match the specified unexpected outputs.
TestGetCompletionCmd_RunZshCompletionNotExpectedOutputs: Tests that the output for Zsh completion does not match the specified unexpected outputs.
TestGetCompletionCmd_RunFishCompletionNotExpectedOutputs: Tests that the output for Fish completion does not match the specified unexpected outputs.
TestGetCompletionCmd_RunPowerShellCompletionNotExpectedOutputs: Tests that the output for PowerShell completion does not match the specified unexpected outputs.
Motivation
These new test cases aim to further validate the behavior of the GetCompletionCmd function for various shell completions. By ensuring that the actual output does not match the unexpected outputs, we strengthen the reliability of the completion script generation for different shells.

These test cases enhance the robustness of the codebase and provide additional validation for the autocompletion script generation functionality.

Signed-off-by: Umair <58398786+Umair0343@users.noreply.github.com>
2023-11-26 10:43:59 +05:00
Matthias Bertschy
68f5ae7ed2 Merge pull request #1516 from mohaidoss/tests/core-pkg-fixhandler
Bug Fix and Test Addition for sanitizeYaml and revertSanitizeYaml Functions
2023-11-25 22:31:39 +01:00
Mehdi Moussaif
803b8dc5a4 Adding tests core/pkg/fixhandler
Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>

Adding tests core/pkg/fixhandler

Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>
2023-11-25 22:21:45 +01:00
Matthias Bertschy
b0913b2a4f Merge pull request #1515 from mohaidoss/bugfix/pkg-imagescan
Bugfix and Tests for Image Scan Package
2023-11-25 21:50:30 +01:00
Matthias Bertschy
8f9824a426 Merge pull request #1526 from kubescape/gomod
fix go mod
2023-11-25 21:47:11 +01:00
Matthias Bertschy
28baac78fb fix go mod
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2023-11-25 21:41:35 +01:00
Mehdi Moussaif
210b5dac33 Fix: nil memory pointer when scanResults.MetadataProvider is nil
Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>
2023-11-25 21:29:15 +01:00
Matthias Bertschy
2d31472fa1 Merge pull request #1520 from mohaidoss/feature/natural_sort_policy_list
Implement Natural Sorting for Policy Listing
2023-11-25 21:20:32 +01:00
Matthias Bertschy
a3b4d60dfb Merge pull request #1517 from VaibhavMalik4187/printer-tests
Enhancement of the printer package with additional tests and refactoring
2023-11-25 21:18:36 +01:00
Matthias Bertschy
50bd74a173 Merge pull request #1514 from VaibhavMalik4187/pkg-tests
Enhancement: Added Unit Tests for Multiple Packages
2023-11-25 21:01:32 +01:00
Matthias Bertschy
9ea4b0dd93 Merge pull request #1513 from VaibhavMalik4187/cmd-tests-continued
Add Test Suite for cmd Packages and Fix Potential Crash in Image Subcommand
2023-11-25 20:56:43 +01:00
Mehdi Moussaif
ba3e416eb8 Natural sort when listing policies
Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>
2023-11-25 20:41:48 +01:00
VaibhavMalik4187
0af0f2a229 Added tests for the printer package
Wrote new tests for the printer package and refactored the CalculateMove
function to prevent potential out of bounds crash

Refactored the `addFix` function for better readability, understanding
and chaining method calls.

Used formatted string for logging.

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
2023-11-26 00:28:50 +05:30
Umair0343
bca14ea369 Add a test case to verify that the command produces the expected autocompletion scripts for each shell type.
Signed-off-by: Umair0343 <umairshahidpti@gmail.com>
2023-11-25 22:46:30 +05:00
VaibhavMalik4187
6f1919bbe2 Added Test Suite for several packages
This PR focuses on adding unit tests for multiple packages in the
project. The main changes include:

- Addition of new tests for the 'printer' package in the
  'core/pkg/resultshandling/printer' directory.
- New tests for the 'results' package in the
  'core/pkg/resultshandling' directory.
- Addition of tests for the 'config' package in the
  'httphandler/config' directory.
- New tests for the 'testutils' package in the 'internal/testutils'
  directory.
- Addition of tests for the 'imagescan' package in the
  'pkg/imagescan' directory.

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
2023-11-25 22:34:48 +05:30
Mehdi Moussaif
11401c755a Minor bug in sanitizeYaml and revertSanitizeYaml functions
Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>
2023-11-25 15:57:33 +01:00
VaibhavMalik4187
69bbf7f72e Added Test Suite for the cmd packages
Wrote new tests for the following packages
- operator
- patch
- scan

Also fixed potential crash in the RunE function of the image subcommand
in the scan package.

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
2023-11-25 16:57:14 +05:30
Matthias Bertschy
524b6f2b1d Merge pull request #1512 from VaibhavMalik4187/cmd-tests
Enhancement: Added Test Suite for cmd package and Fixed Potential Crashes
2023-11-25 10:49:59 +01:00
Matthias Bertschy
2adb72be8e Merge pull request #1509 from mohaidoss/tests/cautils-jsonutils
Adding Unit Tests and Bug Fix for core/cautils
2023-11-25 10:47:36 +01:00
Matthias Bertschy
43ba550f72 Merge pull request #1486 from cbrom/core_cautils_getter_json_tests
Adding Additional Test Cases for JSONDecoder in core/cautils/getter
2023-11-25 10:43:36 +01:00
Matthias Bertschy
3d606245f2 Merge pull request #1502 from VaibhavMalik4187/core-core-tests
Adding Test Suite for the core/core package
2023-11-25 10:41:01 +01:00
VaibhavMalik4187
85da52ebbd Added Test Suite and fixed bugs for cmd package
Wrote ne tsts for the following packages:
- completion
- config
- download
- fix
- list

Also addressed a potential crash in the compleition, download, and list
subcommands when no arguement was provided to the Args, RunE or Run
functions.

Updated `DownloadSupportCommands`, 'ListSupportActions' function to return sorted slice of
strings.

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
2023-11-25 12:26:26 +05:30
VaibhavMalik4187
9e7eb6243a Added Test Suite for the core/core package
Wrote new tests for the following files:
- download.go
- fix.go
- list.go
- scan.go

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
2023-11-25 08:41:37 +05:30
Mehdi Moussaif
9611fb631b Adding tests core/cautils/kustomizeddirectory
Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>
2023-11-24 23:43:10 +01:00
Mehdi Moussaif
44ddbc6ae5 Bug fix IsKustomizeDirectory returning parent dir
Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>
2023-11-24 23:42:17 +01:00
cbrom
f86fa99316 reverted core/cautils/getter/json.go file, as the json and init of json is necessary
Signed-off-by: cbrom <kb.cbrom@gmail.com>
2023-11-25 00:59:45 +03:00
cbrom
2603f04cfc added tests for empty and invalid string inputs to JSONDecoder
Signed-off-by: cbrom <kb.cbrom@gmail.com>

changed test input to clearly show its not a valid

Signed-off-by: cbrom <kb.cbrom@gmail.com>

added tests for valid json input to JSONDecoder function

Signed-off-by: cbrom <kb.cbrom@gmail.com>

check for specific error message instead of just error return

Signed-off-by: cbrom <kb.cbrom@gmail.com>

check for specific error message instead of just error return

Signed-off-by: cbrom <kb.cbrom@gmail.com>

package imports added

Signed-off-by: cbrom <kb.cbrom@gmail.com>

removed unnecessary mock json file

Signed-off-by: cbrom <kb.cbrom@gmail.com>

min function moved to kscloudapi.go

Signed-off-by: cbrom <kb.cbrom@gmail.com>

added necessary functions to make a post api call

Signed-off-by: cbrom <kb.cbrom@gmail.com>

getLatestVersion now uses KSCloudAPI functions

Signed-off-by: cbrom <kb.cbrom@gmail.com>

reverted moved function min back

Signed-off-by: cbrom <kb.cbrom@gmail.com>

removed unncessary functions and simplified post method

Signed-off-by: cbrom <kb.cbrom@gmail.com>

modified call to APIPostRequest

Signed-off-by: cbrom <kb.cbrom@gmail.com>

renamed HTTPPost request function and added httpClient param (for testing purposes)

Signed-off-by: cbrom <kb.cbrom@gmail.com>

changed function name call

Signed-off-by: cbrom <kb.cbrom@gmail.com>

removed HTTPPost function test

Signed-off-by: cbrom <kb.cbrom@gmail.com>

net/http imported

Signed-off-by: cbrom <kb.cbrom@gmail.com>

bytes import removed

Signed-off-by: cbrom <kb.cbrom@gmail.com>

test added for HTTPPost function

Signed-off-by: cbrom <kb.cbrom@gmail.com>

removed json decoder as it is not necessary anymore

Signed-off-by: cbrom <kb.cbrom@gmail.com>

removed HttpPost function

Signed-off-by: cbrom <kb.cbrom@gmail.com>
2023-11-25 00:00:58 +03:00
Matthias Bertschy
029b4c2677 Merge pull request #1504 from cbrom/core_pkg_containerscan_tests
Enhancement of Test Coverage and Code Improvements in Container Scan Package
2023-11-24 21:28:32 +01:00
Matthias Bertschy
84d4ff7cfe Merge pull request #1508 from VaibhavMalik4187/cmd-tests
Enhancement of Test Suite for cmd Packages
2023-11-24 21:18:42 +01:00
Matthias Bertschy
a76e02cb8a Merge pull request #1510 from sulemaanhamza/pkg-policyhandler-cache
Enhancement of TimedCache with Bug Fixes and Test Suite
2023-11-24 21:13:21 +01:00
VaibhavMalik4187
f351b3b333 Added Test Suite for the cmd packages
Wrote new tests for the following packages in the cmd package:
- completion
- config
  * In addition to tests, updated the code for the `stringKeysToSlice`
    to return the final string slice in sorted order of keys.

Added new MockIKubescape struct in the core/mocks package

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
2023-11-25 01:17:58 +05:30
Mehdi Moussaif
dfd13aea6f Add tests for krewutils
Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>
2023-11-24 18:48:04 +01:00
sulemaanhamza
660a9801a4 TimedCache - Potential bug fixes, removing possible memory leaks and test suite
1. Use time.Time for expiration to simplify expiration checks.
2. Added a stopChan and a Stop method to properly stop the invalidateTask goroutine instead of directly changing values
3. Used Ticker in invalidateTask for periodic expiration checks
4. Leak Prevention: The invalidateTask() loop checks the TTL value before continuing. If the TTL is zero, the goroutine exits gracefully, preventing a memory leak.

Signed-off-by: sulemaanhamza <sulemanhamza97@gmail.com>
2023-11-24 22:39:00 +05:00
Mehdi Moussaif
9fda098f70 Add tests for workloadmappingutils
Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>
2023-11-24 18:37:19 +01:00
Matthias Bertschy
c02c8bf7e2 Merge pull request #1507 from mohaidoss/bugfix/kubescape-update-cmd
Enhancement of 'update' command and addition of tests for version check
2023-11-24 17:51:42 +01:00
Matthias Bertschy
aa45a874b9 Merge pull request #1505 from mohaidoss/tests/cmd-shared
Adding Unit Tests for cmd/shared Package
2023-11-24 17:50:45 +01:00
Mehdi Moussaif
94f6261055 Add Test to PrettyJson
Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>
2023-11-24 17:42:43 +01:00
Mehdi Moussaif
9c38c1a090 Add tests for cmd/shared
Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>
2023-11-24 15:49:13 +01:00
Mehdi Moussaif
1d7519c3b7 Added tests for core/cautils/versioncheck
Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>
2023-11-24 15:39:06 +01:00
Mehdi Moussaif
6cf03bd679 bug resetting the var LatestReleaseVersion
Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>

enhancement of update CMD

Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>
2023-11-24 15:38:09 +01:00
cbrom
f3670ca629 coverage test for ScanResultReport AsFNVHash function
Signed-off-by: cbrom <kb.cbrom@gmail.com>
2023-11-24 15:07:11 +03:00
cbrom
3ce838e344 added tests for ElasticContainerScanSummaryResult Validate function
Signed-off-by: cbrom <kb.cbrom@gmail.com>
2023-11-24 15:07:11 +03:00
cbrom
e8228c149a added ElasticContainerScanSummaryResult Validate function doc string
Signed-off-by: cbrom <kb.cbrom@gmail.com>
2023-11-24 15:07:11 +03:00
cbrom
ef3bda9972 removed ToFlatVulnerabilities function as there is no reference anywhere
Signed-off-by: cbrom <kb.cbrom@gmail.com>
2023-11-24 15:07:11 +03:00
cbrom
66df4412b0 updated go.sum
Signed-off-by: cbrom <kb.cbrom@gmail.com>
2023-11-24 15:07:11 +03:00
cbrom
db1c4afcd6 assert instead of if else check on tests
Signed-off-by: cbrom <kb.cbrom@gmail.com>
2023-11-24 15:07:11 +03:00
cbrom
5ea09516ef tests added for ScanResultReport.Validate function
Signed-off-by: cbrom <kb.cbrom@gmail.com>
2023-11-24 15:07:11 +03:00
cbrom
a0911d8752 added doc string for exported functions in datastructuresmethods.go
Signed-off-by: cbrom <kb.cbrom@gmail.com>
2023-11-24 15:07:11 +03:00
cbrom
47d81ce721 added a basic test for GetPackagesNames
Signed-off-by: cbrom <kb.cbrom@gmail.com>
2023-11-24 15:07:11 +03:00
cbrom
6fe6dbb333 added doc comment for exported function GetPackageNames
Signed-off-by: cbrom <kb.cbrom@gmail.com>
2023-11-24 15:07:11 +03:00
cbrom
53f45e599a GetFilesByPackage function removed along with tests as it is not used anywhere except in tests
Signed-off-by: cbrom <kb.cbrom@gmail.com>
2023-11-24 15:07:11 +03:00
cbrom
6b4ef219c9 added more testcases for CalculateFixed function
Signed-off-by: cbrom <kb.cbrom@gmail.com>
2023-11-24 15:07:11 +03:00
Matthias Bertschy
d496485f75 Merge pull request #1501 from mohaidoss/tests/core-initutils
Adding tests for core/core/initutils and fixing potential bug
2023-11-24 12:13:18 +01:00
Mehdi Moussaif
d6bb70ba4a Use tenantConfig instead of KSCloudAPIConnector, Add tests for core/core/initutils
Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>

Add tests for core/core/initutils

Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>

Potential bug, Use tenantConfig instead of KSCloudAPIConnector

Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>
2023-11-24 11:35:21 +01:00
Matthias Bertschy
1f0cbad800 Merge pull request #1503 from mohaidoss/tests/core-pkg-policyhandler
Adding Test Suite for core/pkg/policyhandler
2023-11-24 09:45:36 +01:00
Mehdi Moussaif
362375a733 Adding Test Suite for core/pkg/policyhandler
Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>
2023-11-24 00:35:23 +01:00
cbrom
92d39c5abc added a generated docstring for CalculateFixed function
Signed-off-by: cbrom <kb.cbrom@gmail.com>
2023-11-23 22:33:10 +03:00
Matthias Bertschy
c4f0e6e46b Merge pull request #1500 from sulemaanhamza/bugfix-core-pkg-fixhandler-yamlhelper-edgecases
Edge-case Handling and Test Enhancements in yamlhelper
2023-11-23 17:12:44 +01:00
Matthias Bertschy
6fcfe7f4e5 Merge pull request #1497 from sulemaanhamza/bugfix-core-list-gencontrolrows
Fix for Index Out of Range Error in Malformed Policies Handling
2023-11-23 17:09:58 +01:00
Matthias Bertschy
633024f8c5 Merge pull request #1498 from kubescape/severity
add one test for imagescan to avoid coverage check failure
2023-11-23 16:45:30 +01:00
Matthias Bertschy
92a4c1f64a add one test for imagescan, delete patch_test to avoid coverage check failure
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2023-11-23 15:14:52 +01:00
sulemaanhamza
1f43de06f8 Implemented Ai suggested changes
Signed-off-by: sulemaanhamza <sulemanhamza97@gmail.com>
2023-11-23 18:40:42 +05:00
Matthias Bertschy
5d5ac5c5d5 Merge pull request #1474 from kubescape/fix-install
fix install.sh when sudo is required to delete /usr/local/bin/kubescape
2023-11-23 14:33:24 +01:00
sulemaanhamza
04b06d875b Added edge-case test cases for yamlhelper, fixed bugs cause test-cases to fail
Signed-off-by: sulemaanhamza <sulemanhamza97@gmail.com>
2023-11-23 17:21:09 +05:00
Matthias Bertschy
5d795edd31 Merge pull request #1493 from mohaidoss/fix-download-artifacts
Fix for Kubescape Reading Policies from Local File
2023-11-23 12:56:54 +01:00
Mehdi Moussaif
fd390bbd37 Bug fix where kubescape fails to read from framework local paths
Fix typo in error description

Bug fix where kubescape get policies from file

Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>

Missing '.json' extension when getting Framework Paths

Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>

Appropriate test case for FrameworksPaths

Bug fix where kubescape fails to read from frameworks local paths

Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>
2023-11-23 12:46:44 +01:00
Yuval Leibovich
3b78169f8c Update loadmocks.go
remove armobuildin obj. from regolibrary 

Signed-off-by: Yuval Leibovich <89763818+yuleib@users.noreply.github.com>
2023-11-23 13:29:27 +02:00
Matthias Bertschy
ba7317b4eb Merge pull request #1496 from VaibhavMalik4187/core-pkg-tests
Adding Unit Tests for core/pkg Package
2023-11-23 12:04:01 +01:00
Matthias Bertschy
85b8648724 fix install.sh when sudo is required to delete /usr/local/bin/kubescape
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2023-11-23 10:35:12 +01:00
VaibhavMalik4187
55162829e7 Added Test Suite for core/pkg package
Added unit tests for the following files:
- containerscan/datastructures.go
- hostsensorutils/hostsensordeploy.go
- hostsensorutils/hostsensorworkerpool.go
- hostsensorutils/utils.go
- policyhandler/handlepullpolicies.go
- policyhandler/handlepullpoliciesutils.go
- resourcehandler/filesloader.go
- resourcehandler/remotegitutils.go

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
2023-11-23 14:19:13 +05:30
Matthias Bertschy
27590f623f Merge pull request #1495 from sulemaanhamza/pkg-yamlhelper-test-suite
Adding Comprehensive Test Suite for yamlhelper Package
2023-11-23 09:24:51 +01:00
sulemaanhamza
bc2fc83599 Enhanced policies list to cover multiple edge-cases + Added new test-case with table-like structure to test pretty print of rows
Signed-off-by: sulemaanhamza <sulemanhamza97@gmail.com>
2023-11-23 13:15:31 +05:00
Matthias Bertschy
cb78723a96 Merge pull request #1494 from cbrom/core_cautils_datastructuremethods_tests
Code Improvement on isRuleKubescapeVersionCompatible function
2023-11-23 09:01:46 +01:00
sulemaanhamza
a513c27dce Possible bug fix to prevent index out of range error in case of malformed policies + test case for edge cases
Signed-off-by: sulemaanhamza <sulemanhamza97@gmail.com>
2023-11-23 12:36:54 +05:00
suleman
f814d1df19 Added Test Suite for core/pkg/fixhandler/yamlhelper
Signed-off-by: sulemaanhamza <sulemanhamza97@gmail.com>
2023-11-23 12:33:51 +05:00
Cbrom
5455855e65 Merge branch 'kubescape:master' into core_cautils_datastructuremethods_tests 2023-11-22 22:13:58 +03:00
Matthias Bertschy
eff7f36866 Merge pull request #1480 from VaibhavMalik4187/interrupt-signal-fix
Implementation of Interrupt Signal Handler
2023-11-22 17:52:41 +01:00
cbrom
12056f4cad fixed a test where it would run 1 test case twice
Signed-off-by: cbrom <kb.cbrom@gmail.com>
2023-11-22 19:28:30 +03:00
cbrom
d96ab483a4 code improvement on type assertion for useFromKubescapeVersion and useUntilKubescapeVersion
Signed-off-by: cbrom <kb.cbrom@gmail.com>
2023-11-22 19:27:52 +03:00
Matthias Bertschy
43dbb4ac70 Merge pull request #1484 from VaibhavMalik4187/core-core-tests
Added Test Suite for core/core Package
2023-11-22 17:26:31 +01:00
Matthias Bertschy
dc6c379aa2 Merge pull request #1487 from cbrom/core_cautils_datastructuremethods_tests
Adding Tests and Refactoring for ruleWithKSOpaDependency Function in cautils
2023-11-22 17:21:17 +01:00
Matthias Bertschy
8cacd4d984 Merge pull request #1472 from kubescape/bump
bump for security fixes
2023-11-22 16:58:15 +01:00
Matthias Bertschy
1342a06f43 Merge pull request #1477 from mohaidoss/master
Adding Test Suite for core/pkg/score
2023-11-22 16:36:51 +01:00
VaibhavMalik4187
55da8c1ce2 Added signal handler for the interrupt signal
- Subscribing to an interrupt signal handler allows graceful shutdown of
  the program.
- Use exit code 130 for interrupt signals.

Fixes: https://github.com/kubescape/kubescape/issues/1476

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
2023-11-22 20:51:19 +05:30
Matthias Bertschy
6adfef2a48 Merge pull request #1483 from VaibhavMalik4187/core-cautils-tests
Added Test Suite for cautils
2023-11-22 15:58:22 +01:00
VaibhavMalik4187
beb6d9535c Added tests for cautils
Wrote new tests for the following files:
- controllink.go
- display.go
- fileutils.go
- getter/getpoliciesutils.go
- getter/utils.go

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
2023-11-22 20:24:16 +05:30
Matthias Bertschy
8827434cce Merge pull request #1485 from mohaidoss/tests/go-tree
Adding Test Suite for core/pkg/resultshandling/gotree
2023-11-22 15:53:19 +01:00
VaibhavMalik4187
9845175d29 Added tests for the core/core package
Wrote tests for the following files:
- kscore.go
- list.go
- patch.go
- scan.go

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
2023-11-22 20:03:27 +05:30
Matthias Bertschy
ddf01648b4 Merge pull request #1490 from VaibhavMalik4187/binary-build-workflow-update
Run binary-build job only for kubescape/kubscape
2023-11-22 14:19:56 +01:00
VaibhavMalik4187
16f4849323 Run binary-build job only for kubescape/kubscape
Added a check before running the binary-build job to ensure that the
owner of the repository is kubescape.

Fixes: https://github.com/kubescape/kubescape/issues/1482

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
2023-11-22 15:12:36 +05:30
cbrom
4ae45cd727 added tests for non string values of useUntilKubescapeVersion and useFromKubescapeVersion
Signed-off-by: cbrom <kb.cbrom@gmail.com>
2023-11-22 11:39:36 +03:00
cbrom
b0a376aa2b safe check from and until strings before usage in isRuleKubescapeVersionCompatible function
Signed-off-by: cbrom <kb.cbrom@gmail.com>
2023-11-22 11:39:36 +03:00
cbrom
d45c97cef0 removed ruleWithKSOpaDependency function along with tests
Signed-off-by: cbrom <kb.cbrom@gmail.com>
2023-11-22 11:24:44 +03:00
Oshrat Nir
ec40320a2d update readme
Signed-off-by: Oshrat Nir <oshratn@armosec.io>
2023-11-22 09:56:14 +02:00
cbrom
7eb97fcba0 added tests for ruleWithKSOpaDependency function
Signed-off-by: cbrom <kb.cbrom@gmail.com>
2023-11-22 02:07:36 +03:00
cbrom
73d1805ce6 added tests for ruleWithKSOpaDependency function
Signed-off-by: cbrom <kb.cbrom@gmail.com>
2023-11-22 02:07:19 +03:00
Mehdi Moussaif
c7f9a6ebc4 Adding Test Suite for core/pkg/resultshandling/gotree
Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>

Additional tests for core/pkg/gotree

Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>

tests for printItem in core/pkg/gotree

Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>

Refactor printer initialization in gotree_test.go

Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>
2023-11-21 20:32:11 +01:00
Mehdi
a2f632beb4 Test suite for core/pkg/score
Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>

Use cautils for mock data

Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>

Removed test TestNewScoreWrapperWithNilOPASessionObj

Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>
2023-11-21 16:35:09 +01:00
Matthias Bertschy
567698356e Merge pull request #1481 from mohaidoss/unknown-version-fix
Fix for Empty Build Number in cmd Version
2023-11-21 15:00:54 +01:00
Mehdi Moussaif
887f6a0d0e fix(cmd version): show unknown when BuildNumber is empty
Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>

Use cobra's OutOrStdout instead of os.Stdout

Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>

Test cmd version output

Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>

Apply recommanded changes

Signed-off-by: Mehdi Moussaif <m.moussaif42@gmail.com>

Unneeded if and print statement
2023-11-21 14:04:37 +01:00
Amir Malka
0191135b10 support a backend with service discovery v2 (#1479)
Signed-off-by: Amir Malka <amirm@armosec.io>
2023-11-21 11:40:33 +02:00
Matthias Bertschy
8b596ec951 Merge pull request #1478 from VaibhavMalik4187/update-tablewriter-version
Update the tablewriter version to latest
2023-11-21 07:41:36 +01:00
VaibhavMalik4187
4863edc042 Update the tablewriter version to latest
Fixes: https://github.com/kubescape/kubescape/issues/1452

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
2023-11-21 11:23:12 +05:30
Matthias Bertschy
dc6d85bc34 bump for security fixes
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2023-11-14 09:55:53 +01:00
Matthias Bertschy
1c48636155 Merge pull request #1469 from ibidani/patch-1
Adding Cox Communications Adopters
2023-11-08 18:22:38 +01:00
Idan Bidani
bd5f8a9439 Adding Cox Communications Adopters
Signed-off-by: Idan Bidani <iplaman@gmail.com>
2023-11-08 12:20:14 -05:00
Matthias Bertschy
18850b8d41 Merge pull request #1468 from dirien/patch-1
Update ADOPTERS.md
2023-11-08 13:39:23 +01:00
Engin Diri
47bab2a9ed Update ADOPTERS.md
Add Schwarz IT to adopters list

Signed-off-by: Engin Diri <info@ediri.de>
2023-11-08 13:32:18 +01:00
Matthias Bertschy
9e8b11c34f Merge pull request #1467 from kubescape/craigbox-affiliation
Update MAINTAINERS.md
2023-11-08 00:45:54 +01:00
Craig Box
74bfb57d3a Update MAINTAINERS.md
Change my affiliation

Signed-off-by: Craig Box <craigb@armosec.io>
2023-11-08 12:34:58 +13:00
David Wertenteil
9fb56a2856 Merge pull request #1464 from kubescape/remove-config-tests
Remove deprecated tests
2023-11-06 08:12:06 -05:00
David Wertenteil
9a098c59df Merge pull request #1457 from johnfercher/master
Update maroto version from 0.42.0 to 1.0.0
2023-11-01 21:57:28 +02:00
David Wertenteil
c781bc3166 remove deprecated tests
Signed-off-by: David Wertenteil <dwertent@armosec.io>
2023-11-01 16:33:25 +02:00
John Fercher
a027a3d3d5 * Update maroto version from 0.42.0 to 1.0.0
Signed-off-by: John Fercher <johnathanfercher22@gmail.com>
2023-10-31 23:02:59 -03:00
Craig Box
ee37dc499b Merge pull request #1463 from kubescape/bump-logger 2023-11-01 09:53:00 +13:00
David Wertenteil
450df679cd bump logger version
Signed-off-by: David Wertenteil <dwertent@armosec.io>
2023-10-31 18:22:03 +02:00
Craig Box
c9ccef90f3 Pretty up the pretty-printer. (#1451)
* Pretty up the pretty-printer.

Signed-off-by: Craig Box <craigb@armosec.io>

* add some text fixes for the Operator also

Signed-off-by: Craig Box <craigb@armosec.io>

* fix another verb

Signed-off-by: Craig Box <craigb@armosec.io>

* fixed unit tests

Signed-off-by: David Wertenteil <dwertent@armosec.io>

* fixed test

Signed-off-by: David Wertenteil <dwertent@armosec.io>

---------

Signed-off-by: Craig Box <craigb@armosec.io>
Signed-off-by: David Wertenteil <dwertent@armosec.io>
Co-authored-by: David Wertenteil <dwertent@armosec.io>
2023-10-31 18:07:43 +02:00
David Wertenteil
3b2feca0dd Update flags (#1462)
* add access key flag to the scan command

Signed-off-by: David Wertenteil <dwertent@armosec.io>

* support triggering ns

Signed-off-by: David Wertenteil <dwertent@armosec.io>

* Fixed json keys

Signed-off-by: David Wertenteil <dwertent@armosec.io>

* get k8s config

Signed-off-by: David Wertenteil <dwertent@armosec.io>

---------

Signed-off-by: David Wertenteil <dwertent@armosec.io>
2023-10-31 15:41:18 +02:00
Matthias Bertschy
edfc5d5949 fix docker build for kubescape-cli
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2023-10-26 22:39:09 +02:00
David Wertenteil
e00c7722f1 Merge pull request #1454 from kubescape/update-backend-pkg
Bump backend pkg
2023-10-26 23:22:55 +03:00
David Wertenteil
fd2fc3db34 Merge pull request #1453 from kubescape/delete-dup-related
avoid adding duplicate related resource IDs
2023-10-26 23:04:16 +03:00
David Wertenteil
5111bb541a bump pkg
Signed-off-by: David Wertenteil <dwertent@armosec.io>
2023-10-26 18:10:40 +03:00
YiscahLevySilas1
1d25415c21 avoid adding duplicate related resource IDs
Signed-off-by: YiscahLevySilas1 <yiscahls@armosec.io>
2023-10-26 12:52:05 +03:00
David Wertenteil
a423b41e68 update docs
Signed-off-by: David Wertenteil <dwertent@armosec.io>
2023-10-23 09:49:57 +03:00
David Wertenteil
3e2314a269 Bump v3 (#1449)
* bump version

Signed-off-by: David Wertenteil <dwertent@armosec.io>

* change default view

Signed-off-by: David Wertenteil <dwertent@armosec.io>

* fixed tests

Signed-off-by: David Wertenteil <dwertent@armosec.io>

* fixed go mod

Signed-off-by: David Wertenteil <dwertent@armosec.io>

---------

Signed-off-by: David Wertenteil <dwertent@armosec.io>
2023-10-22 17:43:51 +03:00
David Wertenteil
c143d10130 Cloud provider detection (#1448)
* set cloud provider using nodes

* use scan metadata for scanning scope

* code cleanup

Signed-off-by: David Wertenteil <dwertent@armosec.io>

* handle error

Signed-off-by: David Wertenteil <dwertent@armosec.io>

---------

Signed-off-by: David Wertenteil <dwertent@armosec.io>
2023-10-22 15:47:57 +03:00
David Wertenteil
d5407466d5 Preparing Kubescape for v3 (#1403)
* wip: minor cli fixes

Signed-off-by: David Wertenteil <dwertent@armosec.io>

* wip: change default view

Signed-off-by: David Wertenteil <dwertent@armosec.io>

* wip: reduce default topWorkloadsNumber to 3

Signed-off-by: David Wertenteil <dwertent@armosec.io>

* update gif

Signed-off-by: David Wertenteil <dwertent@armosec.io>

* default view for controls and frameworks

---------

Signed-off-by: David Wertenteil <dwertent@armosec.io>
2023-10-22 15:39:58 +03:00
rcohencyberarmor
052c042dac Support backend access key (#1404)
Support backend access key

Signed-off-by: Amir Malka <amirm@armosec.io>
2023-10-22 15:10:08 +03:00
Daniel Grunberger
72b64127c7 Restructure img cmd (#1398)
* feat: add kubescape patch command

Signed-off-by: Anubhav Gupta <mail.anubhav06@gmail.com>

* update patch command output format

Signed-off-by: Anubhav Gupta <mail.anubhav06@gmail.com>

* fix patch command logic

Signed-off-by: Anubhav Gupta <mail.anubhav06@gmail.com>

* update docs & minor changes

Signed-off-by: Anubhav Gupta <mail.anubhav06@gmail.com>

* restructure cmd

Signed-off-by: Daniel Grunberger <danielgrunberger@armosec.io>

* fix tests

Signed-off-by: Daniel Grunberger <danielgrunberger@armosec.io>

* readme

Signed-off-by: Daniel Grunberger <danielgrunberger@armosec.io>

* fix version code

Signed-off-by: Daniel Grunberger <danielgrunberger@armosec.io>

* go mod

Signed-off-by: Daniel Grunberger <danielgrunberger@armosec.io>

---------

Signed-off-by: Anubhav Gupta <mail.anubhav06@gmail.com>
Signed-off-by: Daniel Grunberger <danielgrunberger@armosec.io>
Co-authored-by: Anubhav Gupta <mail.anubhav06@gmail.com>
Co-authored-by: Daniel Grunberger <danielgrunberger@armosec.io>
2023-10-22 14:51:39 +03:00
Matthias Bertschy
a938b3523f Merge pull request #1446 from kubescape/deps-policy
add env-dependencies-policy to security insights
2023-10-20 09:32:51 +02:00
Matthias Bertschy
915d5d993b add env-dependencies-policy to security insights
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
2023-10-20 09:30:41 +02:00
rcohencyberarmor
e2044338c8 print result to stdout when format argument specified (#1438)
* print result to stdout when format argument specified

Signed-off-by: rcohencyberarmor <rcohen@armosec.io>

* print pretty format to stdout if format is not specified

Signed-off-by: rcohencyberarmor <rcohen@armosec.io>

* remove not relevant log

Signed-off-by: rcohencyberarmor <rcohen@armosec.io>

---------

Signed-off-by: rcohencyberarmor <rcohen@armosec.io>
Co-authored-by: rcohencyberarmor <rcohen@armosec.io>
2023-10-19 13:07:58 +03:00
415 changed files with 109127 additions and 30201 deletions

View File

@@ -1,68 +1,243 @@
name: 00-pr_scanner
permissions: read-all
on:
pull_request:
types: [opened, reopened, synchronize, ready_for_review]
paths-ignore:
- '**.yaml'
- '**.yml'
- '**.md'
- '**.sh'
- 'website/*'
- 'examples/*'
- 'docs/*'
- 'build/*'
- '.github/*'
workflow_dispatch: {}
pull_request:
types: [opened, reopened, synchronize, ready_for_review]
paths-ignore:
- "**.yaml"
- "**.yml"
- "**.md"
- "**.sh"
- "website/*"
- "examples/*"
- "docs/*"
- "build/*"
- ".github/*"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
pr-scanner:
permissions:
actions: read
checks: read
contents: read
deployments: read
id-token: write
issues: read
discussions: read
packages: read
pages: read
pull-requests: write
repository-projects: read
security-events: read
statuses: read
uses: ./.github/workflows/a-pr-scanner.yaml
with:
RELEASE: ""
CLIENT: test
secrets: inherit
pr-scanner:
permissions:
actions: read
artifact-metadata: read
attestations: read
checks: read
contents: write
deployments: read
discussions: read
id-token: write
issues: read
models: read
packages: read
pages: read
pull-requests: write
repository-projects: read
security-events: read
statuses: read
uses: ./.github/workflows/a-pr-scanner.yaml
with:
RELEASE: ""
CLIENT: test
CGO_ENABLED: 0
GO111MODULE: ""
secrets: inherit
binary-build:
permissions:
actions: read
checks: read
contents: read
deployments: read
discussions: read
id-token: write
issues: read
packages: write
pages: read
pull-requests: read
repository-projects: read
security-events: read
statuses: read
uses: ./.github/workflows/b-binary-build-and-e2e-tests.yaml
with:
COMPONENT_NAME: kubescape
CGO_ENABLED: 1
GO111MODULE: ""
GO_VERSION: "1.20"
RELEASE: "latest"
CLIENT: test
ARCH_MATRIX: '[ "" ]'
OS_MATRIX: '[ "ubuntu-20.04" ]'
secrets: inherit
wf-preparation:
name: secret-validator
runs-on: ubuntu-latest
outputs:
is-secret-set: ${{ steps.check-secret-set.outputs.is-secret-set }}
steps:
- name: check if the necessary secrets are set in github secrets
id: check-secret-set
env:
CUSTOMER: ${{ secrets.CUSTOMER }}
USERNAME: ${{ secrets.USERNAME }}
PASSWORD: ${{ secrets.PASSWORD }}
CLIENT_ID: ${{ secrets.CLIENT_ID_PROD }}
SECRET_KEY: ${{ secrets.SECRET_KEY_PROD }}
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
run: "echo \"is-secret-set=${{ env.CUSTOMER != '' && env.USERNAME != '' && env.PASSWORD != '' && env.CLIENT_ID != '' && env.SECRET_KEY != '' && env.REGISTRY_USERNAME != '' && env.REGISTRY_PASSWORD != '' }}\" >> $GITHUB_OUTPUT\n"
run-system-tests:
needs: [wf-preparation, pr-scanner]
if: ${{ (needs.wf-preparation.outputs.is-secret-set == 'true') && (always() && (contains(needs.*.result, 'success') || contains(needs.*.result, 'skipped')) && !(contains(needs.*.result, 'failure')) && !(contains(needs.*.result, 'cancelled'))) }}
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
pull-requests: write
steps:
- name: Set dispatch info
id: dispatch-info
run: |
# Correlation ID WITHOUT attempt - so re-runs can find the original run
CORRELATION_ID="${GITHUB_REPOSITORY##*/}-${{ github.run_id }}"
echo "correlation_id=${CORRELATION_ID}" >> "$GITHUB_OUTPUT"
echo "Correlation ID: ${CORRELATION_ID}, Attempt: ${{ github.run_attempt }}"
- name: Generate GitHub App token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.E2E_DISPATCH_APP_ID }}
private-key: ${{ secrets.E2E_DISPATCH_APP_PRIVATE_KEY }}
owner: armosec
repositories: shared-workflows
- name: Dispatch system tests to private repo
if: ${{ github.run_attempt == 1 }}
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
CORRELATION_ID: ${{ steps.dispatch-info.outputs.correlation_id }}
KS_BRANCH: ${{ github.head_ref || github.ref_name }}
run: |
echo "Dispatching E2E tests with correlation_id: ${CORRELATION_ID}"
echo "Using test group: KUBESCAPE_CLI_E2E"
gh api "repos/armosec/shared-workflows/dispatches" \
-f event_type="e2e-test-trigger" \
-f "client_payload[correlation_id]=${CORRELATION_ID}" \
-f "client_payload[github_repository]=${GITHUB_REPOSITORY}" \
-f "client_payload[environment]=production" \
-f "client_payload[tests_groups]=KUBESCAPE_CLI_E2E" \
-f "client_payload[systests_branch]=master" \
-f "client_payload[ks_branch]=${KS_BRANCH}"
echo "Dispatch completed"
- name: Find E2E workflow run
id: find-run
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
CORRELATION_ID: ${{ steps.dispatch-info.outputs.correlation_id }}
run: |
for i in {1..15}; do
run_id=$(gh api "repos/armosec/shared-workflows/actions/runs?event=repository_dispatch&per_page=30" \
--jq '.workflow_runs | map(select(.name | contains("'"$CORRELATION_ID"'"))) | first | .id // empty')
if [ -n "$run_id" ]; then
echo "run_id=${run_id}" >> "$GITHUB_OUTPUT"
gh api "repos/armosec/shared-workflows/actions/runs/${run_id}" --jq '"url=" + .html_url' >> "$GITHUB_OUTPUT"
exit 0
fi
echo "Attempt $i: waiting for run..."
sleep $((i < 5 ? 10 : 30))
done
echo "::error::Could not find workflow run"
exit 1
- name: Re-run failed jobs in private repo
id: rerun
if: ${{ github.run_attempt > 1 }}
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
RUN_ID: ${{ steps.find-run.outputs.run_id }}
run: |
conclusion=$(gh api "repos/armosec/shared-workflows/actions/runs/${RUN_ID}" --jq '.conclusion')
echo "Previous conclusion: $conclusion"
if [ "$conclusion" = "success" ]; then
echo "Previous run passed. Nothing to re-run."
echo "skip=true" >> "$GITHUB_OUTPUT"
exit 0
fi
# Full rerun if cancelled, partial if failed
if [ "$conclusion" = "cancelled" ]; then
echo "Run was cancelled - triggering full re-run"
gh api --method POST "repos/armosec/shared-workflows/actions/runs/${RUN_ID}/rerun"
else
echo "Re-running failed jobs only"
gh api --method POST "repos/armosec/shared-workflows/actions/runs/${RUN_ID}/rerun-failed-jobs"
fi
# Wait for status to flip from 'completed'
for i in {1..30}; do
[ "$(gh api "repos/armosec/shared-workflows/actions/runs/${RUN_ID}" --jq '.status')" != "completed" ] && break
sleep 2
done
- name: Wait for E2E tests to complete
if: ${{ steps.rerun.outputs.skip != 'true' }}
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
RUN_ID: ${{ steps.find-run.outputs.run_id }}
URL: ${{ steps.find-run.outputs.url }}
run: |
echo "Monitoring: ${URL}"
for i in {1..60}; do # 60 iterations × 60s = 1 hour max
read status conclusion < <(gh api "repos/armosec/shared-workflows/actions/runs/${RUN_ID}" \
--jq '[.status, .conclusion // "null"] | @tsv')
echo "Status: ${status} | Conclusion: ${conclusion}"
if [ "$status" = "completed" ]; then
if [ "$conclusion" = "success" ]; then
echo "E2E tests passed!"
exit 0
fi
echo "::error::E2E tests failed: ${conclusion}"
echo ""
# Get failed job IDs to a file first
gh api "repos/armosec/shared-workflows/actions/runs/${RUN_ID}/jobs" \
--jq '.jobs[] | select(.conclusion == "failure") | [.id, .name, (.steps[] | select(.conclusion == "failure") | .name)] | @tsv' > /tmp/failed_jobs.txt
# Process each failed job
while IFS=$'\t' read -r job_id job_name step_name; do
# Extract test name: "run-helm-e2e / ST (relevancy_python)" → "relevancy_python"
test_name=$(echo "$job_name" | sed 's/.*(\(.*\))/\1/')
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "${job_name}"
echo " Step: ${step_name}"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# Fetch logs to temp file
gh api "repos/armosec/shared-workflows/actions/jobs/${job_id}/logs" 2>/dev/null > /tmp/job_logs.txt
# Show summary in console
grep -E "(ERROR|FAILURE)" /tmp/job_logs.txt | tail -10
echo ""
# Save to separate file per test
log_file="failed_${test_name}.txt"
echo "════════════════════════════════════════" > "$log_file"
echo "${job_name}" >> "$log_file"
echo " Step: ${step_name}" >> "$log_file"
echo "════════════════════════════════════════" >> "$log_file"
last_endgroup=$(grep -n "##\\[endgroup\\]" /tmp/job_logs.txt | tail -1 | cut -d: -f1)
if [ -n "$last_endgroup" ]; then
tail -n +$((last_endgroup + 1)) /tmp/job_logs.txt >> "$log_file"
else
tail -500 /tmp/job_logs.txt >> "$log_file"
fi
done < /tmp/failed_jobs.txt
echo "View full logs: ${URL}"
exit 1
fi
sleep 60
done
echo "::error::Timeout waiting for tests"
exit 1
- name: Upload failed step logs
if: failure()
uses: actions/upload-artifact@v4
with:
name: failed-e2e-logs-attempt-${{ github.run_attempt }}
path: failed_*.txt
retention-days: 7

View File

@@ -3,44 +3,16 @@ permissions: read-all
on:
push:
tags:
- 'v*.*.*-rc.*'
- "v[0-9]+.[0-9]+.[0-9]+"
workflow_dispatch:
inputs:
skip_publish:
description: "Skip publishing artifacts"
required: false
default: true
type: boolean
jobs:
retag:
outputs:
NEW_TAG: ${{ steps.tag-calculator.outputs.NEW_TAG }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # ratchet:actions/checkout@v3
- id: tag-calculator
uses: ./.github/actions/tag-action
with:
SUB_STRING: "-rc"
binary-build:
permissions:
actions: read
checks: read
contents: read
deployments: read
discussions: read
id-token: write
issues: read
packages: write
pages: read
pull-requests: read
repository-projects: read
security-events: read
statuses: read
needs: [retag]
uses: ./.github/workflows/b-binary-build-and-e2e-tests.yaml
with:
COMPONENT_NAME: kubescape
CGO_ENABLED: 1
GO111MODULE: ""
GO_VERSION: "1.20"
RELEASE: ${{ needs.retag.outputs.NEW_TAG }}
CLIENT: release
secrets: inherit
create-release:
release:
permissions:
actions: read
checks: read
@@ -49,40 +21,105 @@ jobs:
discussions: read
id-token: write
issues: read
packages: read
pages: read
pull-requests: read
repository-projects: read
statuses: read
security-events: read
needs: [retag, binary-build]
uses: ./.github/workflows/c-create-release.yaml
with:
RELEASE_NAME: "Release ${{ needs.retag.outputs.NEW_TAG }}"
TAG: ${{ needs.retag.outputs.NEW_TAG }}
DRAFT: false
secrets: inherit
publish-image:
permissions:
actions: read
checks: read
contents: read
deployments: read
discussions: read
id-token: write
issues: read
models: read
packages: write
pages: read
pull-requests: read
repository-projects: read
security-events: read
statuses: read
uses: ./.github/workflows/d-publish-image.yaml
needs: [create-release, retag]
with:
client: "image-release"
image_name: "quay.io/${{ github.repository_owner }}/kubescape-cli"
image_tag: ${{ needs.retag.outputs.NEW_TAG }}
support_platforms: true
cosign: true
secrets: inherit
security-events: read
attestations: read
artifact-metadata: read
runs-on: ubuntu-large
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version: "1.25"
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.9"
- name: Install system dependencies for system-tests
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
libpq5 \
libpq-dev \
gcc \
python3-dev
sudo rm -rf /var/lib/apt/lists/*
- name: Install Cosign
uses: sigstore/cosign-installer@v3.5.0
- name: Create Cosign Key
run: echo "${{ secrets.COSIGN_PRIVATE_KEY_V1 }}" > cosign.key
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Quay.io
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ secrets.QUAYIO_REGISTRY_USERNAME }}
password: ${{ secrets.QUAYIO_REGISTRY_PASSWORD }}
- uses: anchore/sbom-action/download-syft@v0
name: Setup Syft
- name: Create k8s Kind Cluster
uses: helm/kind-action@v1.10.0
with:
cluster_name: kubescape-e2e
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: latest
args: release --clean ${{ inputs.skip_publish == true && '--skip=publish' || '' }}
env:
GITHUB_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN || secrets.GITHUB_TOKEN }}
COSIGN_PWD: ${{ secrets.COSIGN_PRIVATE_KEY_V1_PASSWORD }}
RELEASE: ${{ github.ref_name }}
CLIENT: release
RUN_E2E: "true"
KUBESCAPE_SKIP_UPDATE_CHECK: "true"
CUSTOMER: ${{ secrets.CUSTOMER }}
USERNAME: ${{ secrets.USERNAME }}
PASSWORD: ${{ secrets.PASSWORD }}
CLIENT_ID: ${{ secrets.CLIENT_ID_PROD }}
SECRET_KEY: ${{ secrets.SECRET_KEY_PROD }}
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
- name: Update new version in krew-index
if: github.event_name != 'workflow_dispatch' || inputs.skip_publish != true
uses: rajatjindal/krew-release-bot@v0.0.47
with:
krew_template_file: .krew.yaml
- name: List collected system-test results (debug)
if: always()
run: |
echo "Listing test-results/system-tests (if any):"
ls -laR test-results/system-tests || true
- name: System Tests Report
uses: mikepenz/action-junit-report@v5
if: always()
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
report_paths: "test-results/system-tests/**/results_xml_format/**.xml"
annotate_only: true
job_summary: true

View File

@@ -1,42 +0,0 @@
name: 03-post_release
permissions: read-all
on:
release:
types: [published]
branches:
- 'master'
- 'main'
jobs:
post_release:
name: Post release jobs
runs-on: ubuntu-latest
steps:
- name: Digest
uses: MCJack123/ghaction-generate-release-hashes@c03f3111b39432dde3edebe401c5a8d1ffbbf917 # ratchet:MCJack123/ghaction-generate-release-hashes@v1
with:
hash-type: sha1
file-name: kubescape-release-digests
- name: Invoke workflow to update packaging
uses: benc-uk/workflow-dispatch@v1
if: github.repository_owner == 'kubescape'
with:
workflow: release.yml
repo: kubescape/packaging
ref: refs/heads/main
token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
- name: Invoke workflow to update homebrew tap
uses: benc-uk/workflow-dispatch@v1
if: github.repository_owner == 'kubescape'
with:
workflow: release.yml
repo: kubescape/homebrew-tap
ref: refs/heads/main
token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
- name: Invoke workflow to update github action
uses: benc-uk/workflow-dispatch@v1
if: github.repository_owner == 'kubescape'
with:
workflow: release.yaml
repo: kubescape/github-action
ref: refs/heads/main
token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}

View File

@@ -1,17 +0,0 @@
name: 04-publish_krew_plugin
permissions: read-all
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
jobs:
publish_krew_plugin:
name: Publish Krew plugin
runs-on: ubuntu-latest
if: github.repository_owner == 'kubescape'
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # ratchet:actions/checkout@v3
with:
submodules: recursive
- name: Update new version in krew-index
uses: rajatjindal/krew-release-bot@92da038bbf995803124a8e50ebd438b2f37bbbb0 # ratchet:rajatjindal/krew-release-bot@v0.0.43

View File

@@ -15,76 +15,62 @@ on:
required: false
type: string
default: "./..."
GO111MODULE:
required: true
type: string
CGO_ENABLED:
type: number
default: 1
jobs:
scanners:
unit-tests:
if: ${{ github.actor != 'kubescape' }}
name: Create cross-platform build
env:
GITGUARDIAN_API_KEY: ${{ secrets.GITGUARDIAN_API_KEY }}
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
name: PR Scanner
runs-on: ubuntu-latest
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
runs-on: ubuntu-large
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # ratchet:actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive
- uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # Install go because go-licenses use it ratchet:actions/setup-go@v3
- uses: actions/setup-go@v4
name: Installing go
with:
go-version: '1.20'
cache: true
- name: Scanning - Forbidden Licenses (go-licenses)
id: licenses-scan
continue-on-error: true
run: |
echo "## Installing go-licenses tool"
go install github.com/google/go-licenses@latest
echo "## Scanning for forbiden licenses ##"
go-licenses check .
- name: Scanning - Credentials (GitGuardian)
if: ${{ env.GITGUARDIAN_API_KEY }}
continue-on-error: true
id: credentials-scan
uses: GitGuardian/ggshield-action@4ab2994172fadab959240525e6b833d9ae3aca61 # ratchet:GitGuardian/ggshield-action@master
go-version: ${{ inputs.GO_VERSION }}
- name: Test core pkg
run: ${{ env.DOCKER_CMD }} go test -v ./...
if: startsWith(github.ref, 'refs/tags')
- name: Test httphandler pkg
run: ${{ env.DOCKER_CMD }} sh -c 'cd httphandler && go test -v ./...'
if: startsWith(github.ref, 'refs/tags')
- uses: anchore/sbom-action/download-syft@v0
name: Setup Syft
- uses: goreleaser/goreleaser-action@v6
name: Build
with:
args: -v --all-policies
distribution: goreleaser
version: latest
args: build --clean --snapshot --single-target
env:
GITHUB_PUSH_BEFORE_SHA: ${{ github.event.before }}
GITHUB_PUSH_BASE_SHA: ${{ github.event.base }}
GITHUB_PULL_BASE_SHA: ${{ github.event.pull_request.base.sha }}
GITHUB_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
GITGUARDIAN_API_KEY: ${{ secrets.GITGUARDIAN_API_KEY }}
- name: Scanning - Vulnerabilities (Snyk)
if: ${{ env.SNYK_TOKEN }}
id: vulnerabilities-scan
continue-on-error: true
uses: snyk/actions/golang@806182742461562b67788a64410098c9d9b96adb # ratchet:snyk/actions/golang@master
with:
command: test --all-projects
RELEASE: ${{ inputs.RELEASE }}
CLIENT: ${{ inputs.CLIENT }}
CGO_ENABLED: ${{ inputs.CGO_ENABLED }}
- name: Smoke Testing
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
RELEASE: ${{ inputs.RELEASE }}
KUBESCAPE_SKIP_UPDATE_CHECK: "true"
run: ${{ env.DOCKER_CMD }} python3 smoke_testing/init.py ${PWD}/dist/cli_linux_amd64_v1/kubescape
- name: Test coverage
id: unit-test
run: go test -v ${{ inputs.UNIT_TESTS_PATH }} -covermode=count -coverprofile=coverage.out
- name: Convert coverage count to lcov format
uses: jandelgado/gcov2lcov-action@v1
- name: Submit coverage tests to Coveralls
continue-on-error: true
uses: coverallsapp/github-action@v1
- name: golangci-lint
continue-on-error: false
uses: golangci/golangci-lint-action@v9
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: coverage.lcov
- name: Comment results to PR
continue-on-error: true # Warning: This might break opening PRs from forks
uses: peter-evans/create-or-update-comment@5adcb0bb0f9fb3f95ef05400558bdb3f329ee808 # ratchet:peter-evans/create-or-update-comment@v2.1.0
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
Scan results:
- License scan: ${{ steps.licenses-scan.outcome }}
- Credentials scan: ${{ steps.credentials-scan.outcome }}
- Vulnerabilities scan: ${{ steps.vulnerabilities-scan.outcome }}
reactions: 'eyes'
args: --timeout 10m
only-new-issues: true

View File

@@ -1,387 +0,0 @@
name: b-binary-build-and-e2e-tests
permissions: read-all
on:
workflow_dispatch:
inputs:
COMPONENT_NAME:
required: false
type: string
default: "kubescape"
RELEASE:
required: false
type: string
default: ""
CLIENT:
required: false
type: string
default: "test"
GO_VERSION:
required: false
type: string
default: "1.20"
GO111MODULE:
required: false
type: string
default: ""
CGO_ENABLED:
type: number
default: 1
required: false
OS_MATRIX:
type: string
required: false
default: '[ "ubuntu-20.04", "macos-latest", "windows-latest"]'
ARCH_MATRIX:
type: string
required: false
default: '[ "", "arm64"]'
BINARY_TESTS:
type: string
required: false
default: '[ "scan_nsa", "scan_mitre", "scan_with_exceptions", "scan_repository", "scan_local_file", "scan_local_glob_files", "scan_local_list_of_files", "scan_nsa_and_submit_to_backend", "scan_mitre_and_submit_to_backend", "scan_local_repository_and_submit_to_backend", "scan_repository_from_url_and_submit_to_backend", "scan_with_exception_to_backend", "scan_with_custom_framework", "scan_customer_configuration", "host_scanner", "scan_compliance_score", "control_cluster_from_CLI_config_scan_exclude_namespaces", "control_cluster_from_CLI_config_scan_include_namespaces", "control_cluster_from_CLI_config_scan_host_scanner_enabled", "control_cluster_from_CLI_config_scan_MITRE_framework", "control_cluster_from_CLI_vulnerabilities_scan_default", "control_cluster_from_CLI_vulnerabilities_scan_include_namespaces" ]'
workflow_call:
inputs:
COMPONENT_NAME:
required: true
type: string
RELEASE:
required: true
type: string
CLIENT:
required: true
type: string
GO_VERSION:
type: string
default: "1.20"
GO111MODULE:
required: true
type: string
CGO_ENABLED:
type: number
default: 1
BINARY_TESTS:
type: string
default: '[ "scan_nsa", "scan_mitre", "scan_with_exceptions", "scan_repository", "scan_local_file", "scan_local_glob_files", "scan_local_list_of_files", "scan_nsa_and_submit_to_backend", "scan_mitre_and_submit_to_backend", "scan_local_repository_and_submit_to_backend", "scan_repository_from_url_and_submit_to_backend", "scan_with_exception_to_backend", "scan_with_custom_framework", "scan_customer_configuration", "host_scanner", "scan_compliance_score", "scan_custom_framework_scanning_file_scope_testing", "scan_custom_framework_scanning_cluster_scope_testing", "scan_custom_framework_scanning_cluster_and_file_scope_testing", "unified_configuration_config_view", "unified_configuration_config_set", "unified_configuration_config_delete" ]'
OS_MATRIX:
type: string
required: false
default: '[ "ubuntu-20.04", "macos-latest", "windows-latest"]'
ARCH_MATRIX:
type: string
required: false
default: '[ "", "arm64"]'
jobs:
wf-preparation:
name: secret-validator
runs-on: ubuntu-latest
outputs:
TEST_NAMES: ${{ steps.export_tests_to_env.outputs.TEST_NAMES }}
OS_MATRIX: ${{ steps.export_os_to_env.outputs.OS_MATRIX }}
ARCH_MATRIX: ${{ steps.export_arch_to_env.outputs.ARCH_MATRIX }}
is-secret-set: ${{ steps.check-secret-set.outputs.is-secret-set }}
steps:
- name: check if the necessary secrets are set in github secrets
id: check-secret-set
env:
CUSTOMER: ${{ secrets.CUSTOMER }}
USERNAME: ${{ secrets.USERNAME }}
PASSWORD: ${{ secrets.PASSWORD }}
CLIENT_ID: ${{ secrets.CLIENT_ID_PROD }}
SECRET_KEY: ${{ secrets.SECRET_KEY_PROD }}
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
run: "echo \"is-secret-set=${{ env.CUSTOMER != '' && \n env.USERNAME != '' &&\n env.PASSWORD != '' &&\n env.CLIENT_ID != '' &&\n env.SECRET_KEY != '' &&\n env.REGISTRY_USERNAME != '' &&\n env.REGISTRY_PASSWORD != ''\n }}\" >> $GITHUB_OUTPUT\n"
- id: export_os_to_env
name: set test name
run: |
echo "OS_MATRIX=$input" >> $GITHUB_OUTPUT
env:
input: ${{ inputs.OS_MATRIX }}
- id: export_tests_to_env
name: set test name
run: |
echo "TEST_NAMES=$input" >> $GITHUB_OUTPUT
env:
input: ${{ inputs.BINARY_TESTS }}
- id: export_arch_to_env
name: set test name
run: |
echo "ARCH_MATRIX=$input" >> $GITHUB_OUTPUT
env:
input: ${{ inputs.ARCH_MATRIX }}
check-secret:
name: check if QUAYIO_REGISTRY_USERNAME & QUAYIO_REGISTRY_PASSWORD is set in github secrets
runs-on: ubuntu-latest
outputs:
is-secret-set: ${{ steps.check-secret-set.outputs.is-secret-set }}
steps:
- name: check if QUAYIO_REGISTRY_USERNAME & QUAYIO_REGISTRY_PASSWORD is set in github secrets
id: check-secret-set
env:
QUAYIO_REGISTRY_USERNAME: ${{ secrets.QUAYIO_REGISTRY_USERNAME }}
QUAYIO_REGISTRY_PASSWORD: ${{ secrets.QUAYIO_REGISTRY_PASSWORD }}
run: |
echo "is-secret-set=${{ env.QUAYIO_REGISTRY_USERNAME != '' && env.QUAYIO_REGISTRY_PASSWORD != '' }}" >> $GITHUB_OUTPUT
binary-build:
name: Create cross-platform build
needs: wf-preparation
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GOARCH: ${{ matrix.arch }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ${{ fromJson(needs.wf-preparation.outputs.OS_MATRIX) }}
arch: ${{ fromJson(needs.wf-preparation.outputs.ARCH_MATRIX) }}
exclude:
- os: windows-latest
arch: arm64
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # ratchet:actions/checkout@v3
with:
fetch-depth: 0
submodules: recursive
- name: Cache Go modules (Linux)
if: matrix.os == 'ubuntu-20.04'
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 # ratchet:actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Cache Go modules (macOS)
if: matrix.os == 'macos-latest'
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 # ratchet:actions/cache@v3
with:
path: |
~/Library/Caches/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Cache Go modules (Windows)
if: matrix.os == 'windows-latest'
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 # ratchet:actions/cache@v3
with:
path: |
~\AppData\Local\go-build
~\go\pkg\mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # ratchet:actions/setup-go@v3
name: Installing go
with:
go-version: ${{ inputs.GO_VERSION }}
cache: true
- name: start ${{ matrix.arch }} environment in container
run: |
sudo apt-get update
sudo apt-get install -y binfmt-support qemu-user-static
sudo docker run --platform linux/${{ matrix.arch }} -e RELEASE=${{ inputs.RELEASE }} \
-e CLIENT=${{ inputs.CLIENT }} -e CGO_ENABLED=${{ inputs.CGO_ENABLED }} \
-e KUBESCAPE_SKIP_UPDATE_CHECK=true -e GOARCH=${{ matrix.arch }} -v ${PWD}:/work \
-w /work -v ~/go/pkg/mod:/root/go/pkg/mod -v ~/.cache/go-build:/root/.cache/go-build \
-d --name build golang:${{ inputs.GO_VERSION }}-bullseye sleep 21600
sudo docker ps
DOCKER_CMD="sudo docker exec build"
${DOCKER_CMD} apt update
${DOCKER_CMD} apt install -y cmake python3
${DOCKER_CMD} git config --global --add safe.directory '*'
echo "DOCKER_CMD=${DOCKER_CMD}" >> $GITHUB_ENV;
if: matrix.os == 'ubuntu-20.04' && matrix.arch != ''
- name: Install pkg-config (macOS)
run: brew install pkg-config
if: matrix.os == 'macos-latest'
- name: Install libgit2 (Linux/macOS)
run: ${{ env.DOCKER_CMD }} make libgit2${{ matrix.arch }}
if: matrix.os != 'windows-latest'
- name: Test core pkg
run: ${{ env.DOCKER_CMD }} go test -v ./...
if: "!startsWith(github.ref, 'refs/tags') && matrix.os == 'ubuntu-20.04' && matrix.arch == '' || startsWith(github.ref, 'refs/tags') && (matrix.os != 'macos-latest' || matrix.arch != 'arm64')"
- name: Test httphandler pkg
run: ${{ env.DOCKER_CMD }} sh -c 'cd httphandler && go test -v ./...'
if: "!startsWith(github.ref, 'refs/tags') && matrix.os == 'ubuntu-20.04' && matrix.arch == '' || startsWith(github.ref, 'refs/tags') && (matrix.os != 'macos-latest' || matrix.arch != 'arm64')"
- name: Build
env:
RELEASE: ${{ inputs.RELEASE }}
CLIENT: ${{ inputs.CLIENT }}
CGO_ENABLED: ${{ inputs.CGO_ENABLED }}
run: ${{ env.DOCKER_CMD }} python3 --version && ${{ env.DOCKER_CMD }} python3 build.py
- name: Smoke Testing (Windows / MacOS)
env:
RELEASE: ${{ inputs.RELEASE }}
KUBESCAPE_SKIP_UPDATE_CHECK: "true"
run: python3 smoke_testing/init.py ${PWD}/build/kubescape-${{ matrix.os }}
if: startsWith(github.ref, 'refs/tags') && matrix.os != 'ubuntu-20.04' && matrix.arch == ''
- name: Smoke Testing (Linux amd64)
env:
RELEASE: ${{ inputs.RELEASE }}
KUBESCAPE_SKIP_UPDATE_CHECK: "true"
run: ${{ env.DOCKER_CMD }} python3 smoke_testing/init.py ${PWD}/build/kubescape-ubuntu-latest
if: matrix.os == 'ubuntu-20.04' && matrix.arch == ''
- name: Smoke Testing (Linux ${{ matrix.arch }})
env:
RELEASE: ${{ inputs.RELEASE }}
KUBESCAPE_SKIP_UPDATE_CHECK: "true"
run: ${{ env.DOCKER_CMD }} python3 smoke_testing/init.py ./build/kubescape-${{ matrix.arch }}-ubuntu-latest
if: startsWith(github.ref, 'refs/tags') && matrix.os == 'ubuntu-20.04' && matrix.arch != ''
- name: golangci-lint
if: matrix.os == 'ubuntu-20.04'
continue-on-error: true
uses: golangci/golangci-lint-action@08e2f20817b15149a52b5b3ebe7de50aff2ba8c5 # ratchet:golangci/golangci-lint-action@v3
with:
version: latest
args: --timeout 10m --build-tags=static
only-new-issues: true
- uses: actions/upload-artifact@83fd05a356d7e2593de66fc9913b3002723633cb # ratchet:actions/upload-artifact@v3.1.1
name: Upload artifact (Linux)
if: matrix.os == 'ubuntu-20.04'
with:
name: kubescape${{ matrix.arch }}-ubuntu-latest
path: build/
if-no-files-found: error
- uses: actions/upload-artifact@83fd05a356d7e2593de66fc9913b3002723633cb # ratchet:actions/upload-artifact@v3.1.1
name: Upload artifact (MacOS, Win)
if: matrix.os != 'ubuntu-20.04'
with:
name: kubescape${{ matrix.arch }}-${{ matrix.os }}
path: build/
if-no-files-found: error
build-http-image:
permissions:
contents: read
id-token: write
packages: write
pull-requests: read
needs: [check-secret]
uses: kubescape/workflows/.github/workflows/incluster-comp-pr-merged.yaml@main
with:
IMAGE_NAME: quay.io/${{ github.repository_owner }}/kubescape
IMAGE_TAG: ${{ inputs.RELEASE }}
COMPONENT_NAME: kubescape
CGO_ENABLED: 0
GO111MODULE: "on"
BUILD_PLATFORM: linux/amd64,linux/arm64
GO_VERSION: "1.20"
REQUIRED_TESTS: '[
"ks_microservice_create_2_cronjob_mitre_and_nsa_proxy",
"ks_microservice_triggering_with_cron_job",
"ks_microservice_update_cronjob_schedule",
"ks_microservice_delete_cronjob",
"ks_microservice_create_2_cronjob_mitre_and_nsa",
"ks_microservice_ns_creation",
"ks_microservice_on_demand",
"ks_microservice_mitre_framework_on_demand",
"ks_microservice_nsa_and_mitre_framework_demand",
"scan_compliance_score"
]'
COSIGN: true
HELM_E2E_TEST: true
FORCE: true
secrets: inherit
run-tests:
strategy:
fail-fast: false
matrix:
TEST: ${{ fromJson(needs.wf-preparation.outputs.TEST_NAMES) }}
needs: [wf-preparation, binary-build]
if: ${{ (needs.wf-preparation.outputs.is-secret-set == 'true') && (always() && (contains(needs.*.result, 'success') || contains(needs.*.result, 'skipped')) && !(contains(needs.*.result, 'failure')) && !(contains(needs.*.result, 'cancelled'))) }}
runs-on: ubuntu-latest # This cannot change
steps:
- uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # ratchet:actions/download-artifact@v3.0.2
id: download-artifact
with:
name: kubescape-ubuntu-latest
path: "~"
- run: ls -laR
- name: chmod +x
run: chmod +x -R ${{steps.download-artifact.outputs.download-path}}/kubescape-ubuntu-latest
- name: Checkout systests repo
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # ratchet:actions/checkout@v3
with:
repository: armosec/system-tests
path: .
- uses: actions/setup-python@d27e3f3d7c64b4bbf8e4abfb9b63b83e846e0435 # ratchet:actions/setup-python@v4
with:
python-version: '3.8.13'
cache: 'pip'
- name: create env
run: ./create_env.sh
- name: Generate uuid
id: uuid
run: |
echo "RANDOM_UUID=$(uuidgen)" >> $GITHUB_OUTPUT
- name: Create k8s Kind Cluster
id: kind-cluster-install
uses: helm/kind-action@d08cf6ff1575077dee99962540d77ce91c62387d # ratchet:helm/kind-action@v1.3.0
with:
cluster_name: ${{ steps.uuid.outputs.RANDOM_UUID }}
- name: run-tests-on-local-built-kubescape
env:
CUSTOMER: ${{ secrets.CUSTOMER }}
USERNAME: ${{ secrets.USERNAME }}
PASSWORD: ${{ secrets.PASSWORD }}
CLIENT_ID: ${{ secrets.CLIENT_ID_PROD }}
SECRET_KEY: ${{ secrets.SECRET_KEY_PROD }}
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
run: |
echo "Test history:"
echo " ${{ matrix.TEST }} " >/tmp/testhistory
cat /tmp/testhistory
source systests_python_env/bin/activate
python3 systest-cli.py \
-t ${{ matrix.TEST }} \
-b production \
-c CyberArmorTests \
--duration 3 \
--logger DEBUG \
--kwargs kubescape=${{steps.download-artifact.outputs.download-path}}/kubescape-ubuntu-latest
deactivate
- name: Test Report
uses: mikepenz/action-junit-report@6e9933f4a97f4d2b99acef4d7b97924466037882 # ratchet:mikepenz/action-junit-report@v3.6.1
if: always() # always run even if the previous step fails
with:
report_paths: '**/results_xml_format/**.xml'
commit: ${{github.event.workflow_run.head_sha}}

View File

@@ -1,41 +0,0 @@
name: build-image
permissions: read-all
on:
workflow_dispatch:
inputs:
CLIENT:
required: false
type: string
default: "test"
IMAGE_TAG:
required: true
type: string
CO_SIGN:
type: boolean
required: false
default: false
PLATFORMS:
type: boolean
required: false
default: false
jobs:
build-http-image:
permissions:
id-token: write
packages: write
contents: read
pull-requests: read
uses: kubescape/workflows/.github/workflows/incluster-comp-pr-merged.yaml@main
with:
IMAGE_NAME: quay.io/${{ github.repository_owner }}/kubescape
IMAGE_TAG: ${{ inputs.IMAGE_TAG }}
COMPONENT_NAME: kubescape
CGO_ENABLED: 0
GO111MODULE: "on"
BUILD_PLATFORM: ${{ inputs.PLATFORMS && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
GO_VERSION: "1.20"
REQUIRED_TESTS: '[]'
COSIGN: ${{ inputs.CO_SIGN }}
HELM_E2E_TEST: false
FORCE: true
secrets: inherit

View File

@@ -1,73 +0,0 @@
name: c-create_release
permissions: read-all
on:
workflow_call:
inputs:
RELEASE_NAME:
description: 'Release name'
required: true
type: string
TAG:
description: 'Tag name'
required: true
type: string
DRAFT:
description: 'Create draft release'
required: false
type: boolean
default: false
jobs:
create-release:
name: create-release
runs-on: ubuntu-latest
env:
MAC_OS: macos-latest
UBUNTU_OS: ubuntu-latest
WINDOWS_OS: windows-latest
# permissions:
# contents: write
steps:
- uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # ratchet:actions/download-artifact@v3.0.2
id: download-artifact
with:
path: .
# TODO: kubescape-windows-latest is deprecated and should be removed
- name: Get kubescape.exe from kubescape-windows-latest
run: cp ./kubescape-${{ env.WINDOWS_OS }}/kubescape-${{ env.WINDOWS_OS }} ./kubescape-${{ env.WINDOWS_OS }}/kubescape.exe
- name: Set release token
run: |
if [ "${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}" != "" ]; then
echo "TOKEN=${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}" >> $GITHUB_ENV;
else
echo "TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV;
fi
- name: Release
uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 # ratchet:softprops/action-gh-release@v1
with:
token: ${{ env.TOKEN }}
name: ${{ inputs.RELEASE_NAME }}
tag_name: ${{ inputs.TAG }}
body: ${{ github.event.pull_request.body }}
draft: ${{ inputs.DRAFT }}
fail_on_unmatched_files: true
prerelease: false
# TODO: kubescape-windows-latest is deprecated and should be removed
files: |
./kubescape-${{ env.WINDOWS_OS }}/kubescape-${{ env.WINDOWS_OS }}
./kubescape-${{ env.MAC_OS }}/kubescape-${{ env.MAC_OS }}
./kubescape-${{ env.MAC_OS }}/kubescape-${{ env.MAC_OS }}.sha256
./kubescape-${{ env.MAC_OS }}/kubescape-${{ env.MAC_OS }}.tar.gz
./kubescape-${{ env.UBUNTU_OS }}/kubescape-${{ env.UBUNTU_OS }}
./kubescape-${{ env.UBUNTU_OS }}/kubescape-${{ env.UBUNTU_OS }}.sha256
./kubescape-${{ env.UBUNTU_OS }}/kubescape-${{ env.UBUNTU_OS }}.tar.gz
./kubescape-${{ env.WINDOWS_OS }}/kubescape.exe
./kubescape-${{ env.WINDOWS_OS }}/kubescape-${{ env.WINDOWS_OS }}.sha256
./kubescape-${{ env.WINDOWS_OS }}/kubescape-${{ env.WINDOWS_OS }}.tar.gz
./kubescapearm64-${{ env.MAC_OS }}/kubescape-arm64-${{ env.MAC_OS }}
./kubescapearm64-${{ env.MAC_OS }}/kubescape-arm64-${{ env.MAC_OS }}.sha256
./kubescapearm64-${{ env.MAC_OS }}/kubescape-arm64-${{ env.MAC_OS }}.tar.gz
./kubescapearm64-${{ env.UBUNTU_OS }}/kubescape-arm64-${{ env.UBUNTU_OS }}
./kubescapearm64-${{ env.UBUNTU_OS }}/kubescape-arm64-${{ env.UBUNTU_OS }}.sha256
./kubescapearm64-${{ env.UBUNTU_OS }}/kubescape-arm64-${{ env.UBUNTU_OS }}.tar.gz

View File

@@ -1,80 +0,0 @@
name: d-publish-image
permissions: read-all
on:
workflow_call:
inputs:
client:
description: 'client name'
required: true
type: string
image_tag:
description: 'image tag'
required: true
type: string
image_name:
description: 'image registry and name'
required: true
type: string
cosign:
required: false
default: false
type: boolean
description: 'run cosign on released image'
support_platforms:
required: false
default: true
type: boolean
description: 'support amd64/arm64'
jobs:
check-secret:
name: check if QUAYIO_REGISTRY_USERNAME & QUAYIO_REGISTRY_PASSWORD is set in github secrets
runs-on: ubuntu-latest
outputs:
is-secret-set: ${{ steps.check-secret-set.outputs.is-secret-set }}
steps:
- name: check if QUAYIO_REGISTRY_USERNAME & QUAYIO_REGISTRY_PASSWORD is set in github secrets
id: check-secret-set
env:
QUAYIO_REGISTRY_USERNAME: ${{ secrets.QUAYIO_REGISTRY_USERNAME }}
QUAYIO_REGISTRY_PASSWORD: ${{ secrets.QUAYIO_REGISTRY_PASSWORD }}
run: |
echo "is-secret-set=${{ env.QUAYIO_REGISTRY_USERNAME != '' && env.QUAYIO_REGISTRY_PASSWORD != '' }}" >> $GITHUB_OUTPUT
build-cli-image:
needs: [check-secret]
if: needs.check-secret.outputs.is-secret-set == 'true'
name: Build image and upload to registry
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # ratchet:actions/checkout@v3
with:
submodules: recursive
- name: Set up QEMU
uses: docker/setup-qemu-action@e81a89b1732b9c48d79cd809d8d81d79c4647a18 # ratchet:docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f03ac48505955848960e80bbb68046aa35c7b9e7 # ratchet:docker/setup-buildx-action@v2
- name: Login to Quay.io
env:
QUAY_PASSWORD: ${{ secrets.QUAYIO_REGISTRY_PASSWORD }}
QUAY_USERNAME: ${{ secrets.QUAYIO_REGISTRY_USERNAME }}
run: docker login -u="${QUAY_USERNAME}" -p="${QUAY_PASSWORD}" quay.io
- uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # ratchet:actions/download-artifact@v3.0.2
id: download-artifact
with:
path: .
- name: chmod +x
run: chmod +x -v kubescape-*/kubescape-*
- name: Build and push image for linux/amd64
run: docker buildx build . --file build/kubescape-cli.Dockerfile --tag ${{ inputs.image_name }}:${{ inputs.image_tag }} --tag ${{ inputs.image_name }}:latest --build-arg image_version=${{ inputs.image_tag }} --build-arg client=${{ inputs.client }} --build-arg ks_binary=kubescape-ubuntu-latest/kubescape-ubuntu-latest --push --platform linux/amd64
- name: Build and push image for linux/arm64
run: docker buildx build . --file build/kubescape-cli.Dockerfile --tag ${{ inputs.image_name }}:${{ inputs.image_tag }} --tag ${{ inputs.image_name }}:latest --build-arg image_version=${{ inputs.image_tag }} --build-arg client=${{ inputs.client }} --build-arg ks_binary=kubescape-arm64-ubuntu-latest/kubescape-arm64-ubuntu-latest --push --platform linux/arm64
- name: Install cosign
uses: sigstore/cosign-installer@4079ad3567a89f68395480299c77e40170430341 # ratchet:sigstore/cosign-installer@main
with:
cosign-release: 'v1.12.0'
- name: sign kubescape container image
if: ${{ inputs.cosign }}
env:
COSIGN_EXPERIMENTAL: "true"
run: |
cosign sign --force ${{ inputs.image_name }}

View File

@@ -32,12 +32,12 @@ jobs:
steps:
- name: "Checkout code"
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
uses: actions/checkout@v4
with:
persist-credentials: false
- name: "Run analysis"
uses: ossf/scorecard-action@e38b1902ae4f44df626f11ba0734b14fb91f8f86 # v2.1.2
uses: ossf/scorecard-action@v2.4.3
with:
results_file: results.sarif
results_format: sarif
@@ -59,7 +59,7 @@ jobs:
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
# format to the repository Actions tab.
- name: "Upload artifact"
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3.1.0
uses: actions/upload-artifact@v4
with:
name: SARIF file
path: results.sarif
@@ -67,6 +67,6 @@ jobs:
# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@17573ee1cc1b9d061760f3a006fc4aac4f944fd5 # v2.2.4
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: results.sarif

View File

@@ -1,20 +0,0 @@
permissions: read-all
on:
issues:
types: [opened, labeled]
jobs:
open_PR_message:
if: github.event.label.name == 'typo'
runs-on: ubuntu-latest
steps:
- uses: ben-z/actions-comment-on-issue@10be23f9c43ac792663043420fda29dde07e2f0f # ratchet:ben-z/actions-comment-on-issue@1.0.2
with:
message: "Hello! :wave:\n\nThis issue is being automatically closed, Please open a PR with a relevant fix."
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
auto_close_issues:
runs-on: ubuntu-latest
steps:
- uses: lee-dohm/close-matching-issues@e9e43aad2fa6f06a058cedfd8fb975fd93b56d8f # ratchet:lee-dohm/close-matching-issues@v2
with:
query: 'label:typo'
token: ${{ secrets.GITHUB_TOKEN }}

7
.gitignore vendored
View File

@@ -9,3 +9,10 @@
ca.srl
*.out
ks
cosign.key
dist/
# Test output files
customFilename.pdf
customFilename.xml

3
.gitmodules vendored
View File

@@ -1,3 +0,0 @@
[submodule "git2go"]
path = git2go
url = https://github.com/libgit2/git2go.git

View File

@@ -1,57 +1,57 @@
linters-settings:
govet:
check-shadowing: true
dupl:
threshold: 200
goconst:
min-len: 3
min-occurrences: 2
gocognit:
min-complexity: 65
version: "2"
linters:
enable:
- gosec
- staticcheck
- nolintlint
- gofmt
- unused
- govet
- bodyclose
- typecheck
- goimports
- ineffassign
- gosimple
- gosec
- nolintlint
disable:
# temporarily disabled
- varcheck
- errcheck
- dupl
- gocritic
- errcheck
- gochecknoglobals
- gochecknoinits
- gocognit
- gocritic
- lll
- nakedret
- revive
- stylecheck
- unconvert
- unparam
#- forbidigo # <- see later
# should remain disabled
- deadcode # deprecated linter
- maligned
- lll
- gochecknoinits
- gochecknoglobals
issues:
exclude-rules:
- linters:
- revive
text: "var-naming"
- linters:
- revive
text: "type name will be used as (.+?) by other packages, and that stutters"
- linters:
- stylecheck
text: "ST1003"
run:
skip-dirs:
- git2go
settings:
dupl:
threshold: 200
gocognit:
min-complexity: 65
goconst:
min-len: 3
min-occurrences: 2
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- linters:
- revive
text: var-naming
- linters:
- revive
text: type name will be used as (.+?) by other packages, and that stutters
- linters:
- staticcheck
text: ST1003
paths:
- third_party$
- builtin$
- examples$
formatters:
enable:
- gofmt
- goimports
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$

148
.goreleaser.yaml Normal file
View File

@@ -0,0 +1,148 @@
# Make sure to check the documentation at https://goreleaser.com
# The lines below are called `modelines`. See `:help modeline`
# Feel free to remove those if you don't want/need to use them.
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
version: 2
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
- go test -v ./...
- go -C httphandler test -v ./...
archives:
- id: cli
ids:
- cli
formats:
- binary
- tar.gz
builds:
- id: cli
binary: kubescape
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
- windows
goarch:
- amd64
- arm64
ldflags:
- -X main.version={{.Version}}
- -X main.commit={{.Commit}}
- -X main.date={{.Date}}
- -X github.com/kubescape/backend/pkg/versioncheck.Client={{.Env.CLIENT}}
hooks:
post:
- cmd: >
{{ if eq .Arch "amd64" }}
/bin/sh -lc 'sh build/goreleaser-post-e2e.sh'
{{ end }}
- id: downloader
dir: downloader
binary: downloader
env:
- CGO_ENABLED=0
goos:
- linux
goarch:
- amd64
- arm64
- id: http
dir: httphandler
binary: ksserver
env:
- CGO_ENABLED=0
goos:
- linux
goarch:
- amd64
- arm64
nfpms:
- id: cli
package_name: kubescape
ids:
- cli
vendor: Kubescape
homepage: https://kubescape.io/
maintainer: matthiasb@kubescape.io
formats:
- apk
- deb
- rpm
bindir: /usr/bin
docker_signs:
- stdin: "{{ .Env.COSIGN_PWD }}"
dockers_v2:
- id: cli
images:
- "quay.io/kubescape/kubescape-cli"
tags:
- "{{ .Tag }}"
labels:
"org.opencontainers.image.description": "Kubescape CLI"
"org.opencontainers.image.created": "{{.Date}}"
"org.opencontainers.image.name": "{{.ProjectName}}"
"org.opencontainers.image.revision": "{{.FullCommit}}"
"org.opencontainers.image.version": "{{.Version}}"
"org.opencontainers.image.source": "{{.GitURL}}"
ids:
- cli
dockerfile: build/kubescape-cli.Dockerfile
- id: http
images:
- "quay.io/kubescape/kubescape"
tags:
- "{{ .Tag }}"
labels:
"org.opencontainers.image.description": "Kubescape microservice"
"org.opencontainers.image.created": "{{.Date}}"
"org.opencontainers.image.name": "{{.ProjectName}}"
"org.opencontainers.image.revision": "{{.FullCommit}}"
"org.opencontainers.image.version": "{{.Version}}"
"org.opencontainers.image.source": "{{.GitURL}}"
ids:
- downloader
- http
dockerfile: build/Dockerfile
changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
checksum:
name_template: "checksums.sha256"
sboms:
- artifacts: binary
krews:
- name: kubescape
ids:
- cli
skip_upload: true
homepage: https://kubescape.io/
description: It includes risk analysis, security compliance, and misconfiguration scanning with an easy-to-use CLI interface, flexible output formats, and automated scanning capabilities.
short_description: Scan resources and cluster configs against security frameworks.
release:
draft: false
footer: >-
---
Released by [GoReleaser](https://github.com/goreleaser/goreleaser).

View File

@@ -3,40 +3,58 @@ kind: Plugin
metadata:
name: kubescape
spec:
homepage: https://github.com/kubescape/kubescape/
shortDescription: Scan resources and cluster configs against security frameworks.
version: {{ .TagName }}
description: |
It includes risk analysis, security compliance, and misconfiguration scanning
with an easy-to-use CLI interface, flexible output formats, and automated scanning capabilities.
platforms:
- selector:
matchLabels:
os: darwin
arch: amd64
{{ addURIAndSha "https://github.com/kubescape/kubescape/releases/download/{{ .TagName }}/kubescape-macos-latest.tar.gz" .TagName }}
bin: kubescape
- selector:
matchLabels:
os: darwin
arch: arm64
{{ addURIAndSha "https://github.com/kubescape/kubescape/releases/download/{{ .TagName }}/kubescape-arm64-macos-latest.tar.gz" .TagName }}
bin: kubescape
- selector:
matchLabels:
os: linux
arch: amd64
{{ addURIAndSha "https://github.com/kubescape/kubescape/releases/download/{{ .TagName }}/kubescape-ubuntu-latest.tar.gz" .TagName }}
{{ addURIAndSha "https://github.com/kubescape/kubescape/releases/download/" .TagName (printf "kubescape_%s_linux_amd64.tar.gz" .TagName) .TagName }}
bin: kubescape
- selector:
matchLabels:
os: linux
arch: arm64
{{ addURIAndSha "https://github.com/kubescape/kubescape/releases/download/{{ .TagName }}/kubescape-arm64-ubuntu-latest.tar.gz" .TagName }}
{{ addURIAndSha "https://github.com/kubescape/kubescape/releases/download/" .TagName (printf "kubescape_%s_linux_arm64.tar.gz" .TagName) .TagName }}
bin: kubescape
- selector:
matchLabels:
os: darwin
arch: amd64
{{ addURIAndSha "https://github.com/kubescape/kubescape/releases/download/" .TagName (printf "kubescape_%s_darwin_amd64.tar.gz" .TagName) .TagName }}
bin: kubescape
- selector:
matchLabels:
os: darwin
arch: arm64
{{ addURIAndSha "https://github.com/kubescape/kubescape/releases/download/" .TagName (printf "kubescape_%s_darwin_arm64.tar.gz" .TagName) .TagName }}
bin: kubescape
- selector:
matchLabels:
os: windows
arch: amd64
{{ addURIAndSha "https://github.com/kubescape/kubescape/releases/download/{{ .TagName }}/kubescape-windows-latest.tar.gz" .TagName }}
{{ addURIAndSha "https://github.com/kubescape/kubescape/releases/download/" .TagName (printf "kubescape_%s_windows_amd64.tar.gz" .TagName) .TagName }}
bin: kubescape.exe
- selector:
matchLabels:
os: windows
arch: arm64
{{ addURIAndSha "https://github.com/kubescape/kubescape/releases/download/" .TagName (printf "kubescape_%s_windows_arm64.tar.gz" .TagName) .TagName }}
bin: kubescape.exe
shortDescription: Scan resources and cluster configs against security frameworks.
description: |
Kubescape is the first tool for testing if Kubernetes is deployed securely
according to mitigations and best practices. It includes risk analysis,
security compliance, and misconfiguration scanning with an easy-to-use
CLI interface, flexible output formats, and automated scanning capabilities.
Features:
- Risk analysis: Identify vulnerabilities and security risks in your cluster
- Security compliance: Check your cluster against multiple security frameworks
- Misconfiguration scanning: Detect security misconfigurations in your workloads
- Flexible output: Results in JSON, SARIF, HTML, JUnit, and Prometheus formats
- CI/CD integration: Easily integrate into your CI/CD pipeline
homepage: https://kubescape.io/
caveats: |
Requires kubectl and basic knowledge of Kubernetes.
Run 'kubescape scan' to scan your Kubernetes cluster or manifests.

View File

@@ -1,23 +1,5 @@
# Adopters
# Well-known companies
Well-known companies who are using and/or contributing to Kubescape are (in alphabetical order):
* Accenture
* Amazon.com
* IBM
* Intel
* Meetup
* RedHat
* Scaleway
# Users
If you want to be listed here and share with others your experience, open a PR and add the bellow table:
| Name | Company | Use case | Contact for questions (optional) |
| ---- | ------- | -------- | -------------------------------- |
| Yonathan Amzallag | ARMO | Vulnerability monitoring | yonatana@armosec.io |
The Kubescape project manages this document in the central project repository.
Go to the [centralized ADOPTERS.md](https://github.com/kubescape/project-governance/blob/main/ADOPTERS.md)

View File

@@ -1,3 +1,5 @@
## Code of Conduct
# Code of Conduct
The Kubescape project follows the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md).
The Kubescape project manages this document in the central project repository.
Go to the [centralized CODE_OF_CONDUCT.md](https://github.com/kubescape/project-governance/blob/main/CODE_OF_CONDUCT.md)

5
COMMUNITY.md Normal file
View File

@@ -0,0 +1,5 @@
# Community
The Kubescape project manages this document in the central project repository.
Go to the [centralized COMMUNITY.md](https://github.com/kubescape/project-governance/blob/main/COMMUNITY.md)

View File

@@ -1,98 +1,5 @@
# Contributing
First, it is awesome that you are considering contributing to Kubescape! Contributing is important and fun and we welcome your efforts.
The Kubescape project manages this document in the central project repository.
When contributing, we categorize contributions into two:
* Small code changes or fixes, whose scope is limited to a single or two files
* Complex features and improvements, with potentially unlimited scope
If you have a small change, feel free to fire up a Pull Request.
When planning a bigger change, please first discuss the change you wish to make via an issue,
so the maintainers are able to help guide you and let you know if you are going in the right direction.
## Code of Conduct
Please follow our [code of conduct](CODE_OF_CONDUCT.md) in all of your interactions within the project.
## Build and test locally
Please follow the [instructions here](https://github.com/kubescape/kubescape/wiki/Building).
## Pull Request Process
1. Ensure any install or build dependencies are removed before the end of the layer when doing a
build.
2. Update the README.md with details of changes to the interface, this includes new environment
variables, exposed ports, useful file locations and container parameters.
3. Open Pull Request to the `master` branch.
4. We will merge the Pull Request once you have the sign-off.
## Developer Certificate of Origin
All commits to the project must be "signed off", which states that you agree to the terms of the [Developer Certificate of Origin](https://developercertificate.org/). This is done by adding a "Signed-off-by:" line in the commit message, with your name and email address.
Commits made through the GitHub web application are automatically signed off.
### Configuring Git to sign off commits
First, configure your name and email address in Git global settings:
```
$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com
```
You can now sign off per-commit, or configure Git to always sign off commits per repository.
### Sign off per-commit
Add [`-s`](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt--s) to your Git command line. For example:
```git commit -s -m "Fix issue 64738"```
This is tedious, and if you forget, you'll have to [amend your commit](#fixing-a-commit-where-the-dco-failed).
### Configure a repository to always include sign off
There are many ways to achieve this with Git hooks, but the simplest is to do the following:
```
cd your-repo
curl -Ls https://gist.githubusercontent.com/dixudx/7d7edea35b4d91e1a2a8fbf41d0954fa/raw/prepare-commit-msg -o .git/hooks/prepare-commit-msg
chmod +x .git/hooks/prepare-commit-msg
```
### Use semantic commit messages (optional)
When contributing, you could consider using [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/), in order to improve logs readability and help us to automatically generate `CHANGELOG`s.
Format: `<type>(<scope>): <subject>`
`<scope>` is optional
#### Example
```
feat(cmd): add kubectl plugin
^--^ ^-^ ^----------------^
| | |
| | +-> subject: summary in present tense.
| |
| +-------> scope: point of interest
|
+-------> type: chore, docs, feat, fix, refactor, style, or test.
```
More Examples:
* `feat`: new feature for the user, not a new feature for build script
* `fix`: bug fix for the user, not a fix to a build script
* `docs`: changes to the documentation
* `style`: formatting, missing semi colons, etc; no production code change
* `refactor`: refactoring production code, eg. renaming a variable
* `test`: adding missing tests, refactoring tests; no production code change
* `chore`: updating grunt tasks etc; no production code change
## Fixing a commit where the DCO failed
Check out [this guide](https://github.com/src-d/guide/blob/master/developer-community/fix-DCO.md).
Go to the [centralized CONTRIBUTING.md](https://github.com/kubescape/project-governance/blob/main/CONTRIBUTING.md)

View File

@@ -1,65 +1,5 @@
# Governance of Kubescape
# Governance
## Overview
The Kubescape project manages this document in the central project repository.
The Kubescape project is an open-source initiative dedicated to improve security and best practices in Kubernetes environments. This document outlines the governance structure of the Kubescape project and provides guidance for its community contributors.
## Decision Making
### Maintainers
- Maintainers are responsible for the smooth operation of the project.
- They review and merge pull requests, manage releases, and ensure the quality and stability of the codebase.
- Maintainers are chosen based on their ongoing contributions and their demonstrated commitment to the project.
- Everyone who had at least 5 code contribution in the last 12 month can submit her/himself for joining the maintainer team
- Maintainers who are not taken part in the project work (code, reviews, discussions) for 12 month are automaticaly removed from the maintainer team
### Committers
- Committers are contributors who have made significant and consistent contributions to the project.
- They have the ability to merge minor pull requests if assigned by maintainers.
- A contributor can be proposed as a committer by any existing maintainer. The proposal will be reviewed and voted on by the existing maintainers.
### Community Members
- Anyone can become a community member by contributing to the project. This can be in the form of code contributions, documentation, or any other form of project support.
## Processes
### Proposing Changes
1. Open an issue on the project repository to discuss the proposed change.
2. Once there is consensus around the proposed change, create a pull request.
3. Pull requests will be reviewed by committers and/or maintainers.
4. Once the pull request has received approval, it can be merged into the main codebase.
### Conflict Resolution
1. In case of any conflicts, it is primarily the responsibility of the parties involved to resolve it.
2. If the conflict cannot be resolved, it will be escalated to the maintainers for resolution.
3. Maintainers' decision will be final in case of unresolved conflicts.
## Roles and Responsibilities
### Maintainers
- Ensure the quality and stability of the project.
- Resolve conflicts.
- Provide direction and set priorities for the project.
### Committers
- Review and merge minor pull requests.
- Assist maintainers in project tasks.
- Promote best practices within the community.
### Community Members
- Contribute to the project in any form.
- Participate in discussions and provide feedback.
- Respect the code of conduct and governance of the project.
## Changes to the Governance Document
Proposed changes to this governance document should follow the same process as any other code change to the Kubescape project (see "Proposing Changes").
Go to the [centralized GOVERNANCE.md](https://github.com/kubescape/project-governance/blob/main/GOVERNANCE.md)

273
KREW_RELEASE.md Normal file
View File

@@ -0,0 +1,273 @@
# Krew Release Automation Guide
This document explains how kubescape automates publishing to the Kubernetes plugin package manager, krew.
## What is Krew?
Krew is a plugin manager for `kubectl`. It allows users to discover and install `kubectl` plugins easily. You can learn more about krew at [https://krew.sigs.k8s.io/](https://krew.sigs.k8s.io/).
## How kubescape publishes to krew
We use the [krew-release-bot](https://github.com/rajatjindal/krew-release-bot) to automatically create pull requests to the [kubernetes-sigs/krew-index](https://github.com/kubernetes-sigs/krew-index) repository whenever a new release of kubescape is published.
### Setup Overview
The automation consists of three components:
1. **`.krew.yaml`** - A template file that the bot uses to generate the krew plugin manifest
2. **`.github/workflows/02-release.yaml`** - GitHub Actions workflow that runs the krew-release-bot after a successful release
3. **`.goreleaser.yaml`** - GoReleaser configuration that defines the krew manifest (though upload is skipped)
### Why Use krew-release-bot Instead of GoReleaser's Built-in Krew Support?
You might have noticed that **GoReleaser has built-in krew support** in its `krews` section. However, almost all projects (including stern) use `skip_upload: true` and rely on **krew-release-bot** instead. Here's why:
#### Problems with GoReleaser's Built-in Krew Publishing
To use GoReleaser's direct krew publishing, you would need to:
```yaml
krews:
- name: kubescape
skip_upload: false # Instead of true
repository:
owner: kubernetes-sigs
name: krew-index
token: "{{ .Env.KREW_INDEX_TOKEN }}" # Required!
pull_request:
enabled: true # Requires GoReleaser Pro for cross-repo PRs
```
This approach has several critical issues:
1. **Permission Barrier**: Almost no one has write access to `kubernetes-sigs/krew-index`. You would need special permissions from the Krew maintainers, which is rarely granted.
2. **Security Risk**: You'd need to store a GitHub personal access token with write access to the krew-index in your repository secrets. This token could be compromised and used to make unauthorized changes to the krew-index.
3. **GoReleaser Pro Required**: To create pull requests to a different repository (cross-repository), you need GoReleaser Pro, which is a paid product.
4. **Manual Work**: Even if you had access, you'd need to manually configure and maintain the repository settings, tokens, and potentially deal with rate limits and authentication issues.
#### Why krew-release-bot is the Right Solution
The **krew-release-bot** was created by the Kubernetes community (in collaboration with the Krew team) specifically to solve these problems:
- **No Repository Access Required**: The bot acts as an intermediary with pre-configured access to krew-index. You don't need write permissions.
- **No Tokens Needed**: It uses GitHub's `GITHUB_TOKEN` (automatically available in GitHub Actions) via webhooks and events. No personal access tokens required.
- **Designed for Krew**: It's specifically built for the krew-index workflow and integrates with Krew's automation.
- **Automatic Merging**: The Krew team has configured their CI to automatically test and merge PRs from krew-release-bot (usually within 5-10 minutes).
- **Officially Recommended**: The Krew team explicitly recommends this approach in their documentation as the standard way to automate plugin updates.
- **Free and Open Source**: No paid subscriptions required.
#### The Real-World Evidence
Looking at recent pull requests to `kubernetes-sigs/krew-index`, **almost all automated plugin updates are created by krew-release-bot**. You'll see patterns like:
```
Author: krew-release-bot
Title: "release new version v0.6.11 of radar"
```
This demonstrates that the entire Kubernetes ecosystem has standardized on krew-release-bot, not GoReleaser's built-in publishing.
#### Summary
While GoReleaser's built-in krew support exists in the code, it's **practically unusable for the krew-index repository** due to permission and security constraints. The krew-release-bot is the de facto standard because:
- It works without special permissions
- It's more secure
- It integrates with Krew's automation
- It's free and recommended by the Krew team
This is why we use `skip_upload: true` in GoReleaser and let krew-release-bot handle the actual publishing.
### The Template File
The `.krew.yaml` file in the repository root is a Go template that contains placeholders for dynamic values:
```yaml
apiVersion: krew.googlecontainertools.github.com/v1alpha2
kind: Plugin
metadata:
name: kubescape
spec:
version: {{ .TagName }}
platforms:
- selector:
matchLabels:
os: linux
arch: amd64
{{ $version := trimPrefix "v" .TagName }}{{ addURIAndSha "https://github.com/kubescape/kubescape/releases/download/" .TagName (printf "kubescape_%s_linux_amd64.tar.gz" $version) .TagName }}
bin: kubescape
- selector:
matchLabels:
os: linux
arch: arm64
{{ $version := trimPrefix "v" .TagName }}{{ addURIAndSha "https://github.com/kubescape/kubescape/releases/download/" .TagName (printf "kubescape_%s_linux_arm64.tar.gz" $version) .TagName }}
bin: kubescape
- selector:
matchLabels:
os: darwin
arch: amd64
{{ $version := trimPrefix "v" .TagName }}{{ addURIAndSha "https://github.com/kubescape/kubescape/releases/download/" .TagName (printf "kubescape_%s_darwin_amd64.tar.gz" $version) .TagName }}
bin: kubescape
- selector:
matchLabels:
os: darwin
arch: arm64
{{ $version := trimPrefix "v" .TagName }}{{ addURIAndSha "https://github.com/kubescape/kubescape/releases/download/" .TagName (printf "kubescape_%s_darwin_arm64.tar.gz" $version) .TagName }}
bin: kubescape
- selector:
matchLabels:
os: windows
arch: amd64
{{ $version := trimPrefix "v" .TagName }}{{ addURIAndSha "https://github.com/kubescape/kubescape/releases/download/" .TagName (printf "kubescape_%s_windows_amd64.tar.gz" $version) .TagName }}
bin: kubescape.exe
- selector:
matchLabels:
os: windows
arch: arm64
{{ $version := trimPrefix "v" .TagName }}{{ addURIAndSha "https://github.com/kubescape/kubescape/releases/download/" .TagName (printf "kubescape_%s_windows_arm64.tar.gz" $version) .TagName }}
bin: kubescape.exe
shortDescription: Scan resources and cluster configs against security frameworks.
description: |
Kubescape is the first tool for testing if Kubernetes is deployed securely
according to mitigations and best practices. It includes risk analysis,
security compliance, and misconfiguration scanning with an easy-to-use
CLI interface, flexible output formats, and automated scanning capabilities.
Features:
- Risk analysis: Identify vulnerabilities and security risks in your cluster
- Security compliance: Check your cluster against multiple security frameworks
- Misconfiguration scanning: Detect security misconfigurations in your workloads
- Flexible output: Results in JSON, SARIF, HTML, JUnit, and Prometheus formats
- CI/CD integration: Easily integrate into your CI/CD pipeline
homepage: https://kubescape.io/
caveats: |
Requires kubectl and basic knowledge of Kubernetes.
Run 'kubescape scan' to scan your Kubernetes cluster or manifests.
```
The `{{ .TagName }}` is replaced with the release tag (e.g., `v3.0.0`), `{{ trimPrefix "v" .TagName }}` removes the version prefix, and `{{ addURIAndSha ... }}` calculates the SHA256 checksum for the binary archive.
### Release Workflow
The release workflow (`.github/workflows/02-release.yaml`) can be triggered in two ways:
1. **Automatic**: When a new tag matching the pattern `v[0-9]+.[0-9]+.[0-9]+` is pushed to the repository
2. **Manual**: Via `workflow_dispatch` with an optional `skip_publish` input
When the workflow is triggered:
1. GoReleaser builds and publishes the release artifacts (unless `skip_publish=true` is set)
2. The krew-release-bot step runs conditionally:
- It **runs** when triggered by a tag push OR by `workflow_dispatch` with `skip_publish=false`
- It **skips** when triggered by `workflow_dispatch` with `skip_publish=true` (default)
3. When it runs, the bot:
- Reads the `.krew.yaml` template
- Fills in the template with release information
- Creates a pull request to the `kubernetes-sigs/krew-index` repository
- The PR is automatically tested and merged by krew's infrastructure
### Workflow Permissions
The release job has the following permissions:
```yaml
permissions:
actions: read
checks: read
contents: write
deployments: read
discussions: read
id-token: write
issues: read
models: read
packages: write
pages: read
pull-requests: read
repository-projects: read
statuses: read
security-events: read
attestations: read
artifact-metadata: read
```
These permissions are necessary for GoReleaser to create releases and upload artifacts.
### Testing the Template
Before committing changes to `.krew.yaml`, you can test how the template will be rendered using Docker:
```bash
docker run -v $(pwd)/.krew.yaml:/tmp/.krew.yaml ghcr.io/rajatjindal/krew-release-bot:v0.0.47 \
krew-release-bot template --tag v3.0.0 --template-file /tmp/.krew.yaml
```
This will output the generated krew manifest file, allowing you to verify:
- The version field is correct
- All download URLs are properly formatted
- The SHA256 checksum will be calculated correctly
### Why skip_upload in GoReleaser?
In `.goreleaser.yaml`, the `krews` section has `skip_upload: true`:
```yaml
krews:
- name: kubescape
ids:
- cli
skip_upload: true # We use krew-release-bot instead
homepage: https://kubescape.io/
description: It includes risk analysis, security compliance, and misconfiguration scanning with an easy-to-use CLI interface, flexible output formats, and automated scanning capabilities.
short_description: Scan resources and cluster configs against security frameworks.
```
This is intentional because:
- GoReleaser generates the manifest but doesn't have built-in support for submitting PRs to krew-index
- krew-release-bot is the recommended tool for krew automation by the Krew team
- Using krew-release-bot provides automatic testing and merging of version bump PRs
### Manual Release Testing
You can test the release workflow manually without publishing to krew by using `workflow_dispatch`:
1. Go to Actions tab in GitHub
2. Select "02-create_release" workflow
3. Click "Run workflow"
4. The `skip_publish` input defaults to `true` (publishing will be skipped)
5. Set `skip_publish` to `false` if you want to test the full release process including krew indexing
### Making Changes to the Template
If you need to update the krew manifest (e.g., change the description, add platforms, or update the binary location):
1. Edit the `.krew.yaml` file
2. Test your changes with the Docker command shown above
3. Commit and push the changes
4. The next release will use the updated template
### Installing kubescape via krew
Once the plugin is indexed in krew, users can install it with:
```bash
kubectl krew install kubernetes-sigs/kubescape
```
Or after index update:
```bash
kubectl krew install kubescape
```
### Further Reading
- [Krew official documentation](https://krew.sigs.k8s.io/docs/developer-guide/)
- [krew-release-bot repository](https://github.com/rajatjindal/krew-release-bot)
- [Krew plugin submission guide](https://krew.sigs.k8s.io/docs/developer-guide/develop/plugins/)

View File

@@ -1,12 +1,5 @@
# Maintainers
The following table lists the Kubescape project core maintainers:
| Name | GitHub | Organization | Added/Renewed On |
| --- | --- | --- | --- |
| [Matthias Bertschy](https://www.linkedin.com/in/matthias-bertschy-b427b815/) | [@matthyx](https://github.com/matthyx) | [ARMO](https://www.armosec.io/) | 2023-01-01 |
| [Craig Box](https://www.linkedin.com/in/crbnz/) | [@craigbox](https://github.com/craigbox) | [ARMO](https://www.armosec.io/) | 2022-10-31 |
| [Ben Hirschberg](https://www.linkedin.com/in/benyamin-ben-hirschberg-66141890) | [@slashben](https://github.com/slashben) | [ARMO](https://www.armosec.io/) | 2021-09-01 |
| [Rotem Refael](https://www.linkedin.com/in/rotem-refael) | [@rotemamsa](https://github.com/rotemamsa) | [ARMO](https://www.armosec.io/) | 2021-10-11 |
| [David Wertenteil](https://www.linkedin.com/in/david-wertenteil-0ba277b9) | [@dwertent](https://github.com/dwertent) | [ARMO](https://www.armosec.io/) | 2021-09-01 |
The Kubescape project manages this document in the central project repository.
Go to the [centralized MAINTAINERS.md](https://github.com/kubescape/project-governance/blob/main/MAINTAINERS.md)

View File

@@ -1,28 +1,12 @@
.PHONY: test all build libgit2
.PHONY: test all build
# default task invoked while running make
all: libgit2 build
all: build
export CGO_ENABLED=1
# build and install libgit2
libgit2:
-git submodule update --init --recursive
cd git2go; make install-static
# build and install libgit2 for macOS m1
libgit2arm64:
git submodule update --init --recursive
if [ "$(shell uname -s)" = "Darwin" ]; then \
sed -i '' 's/cmake -D/cmake -DCMAKE_OSX_ARCHITECTURES="arm64" -D/' git2go/script/build-libgit2.sh; \
fi
cd git2go; make install-static
# go build tags
TAGS = "gitenabled,static"
export CGO_ENABLED=0
build:
go build -v -tags=$(TAGS) .
go build -v .
test:
go test -v -tags=$(TAGS) ./...
go test -v ./...

482
README.md
View File

@@ -3,12 +3,15 @@
[![Go Report Card](https://goreportcard.com/badge/github.com/kubescape/kubescape)](https://goreportcard.com/report/github.com/kubescape/kubescape)
[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/kubescape/kubescape)
[![GitHub](https://img.shields.io/github/license/kubescape/kubescape)](https://github.com/kubescape/kubescape/blob/master/LICENSE)
[![CNCF](https://shields.io/badge/CNCF-Sandbox%20project-blue?logo=linux-foundation&style=flat)](https://landscape.cncf.io/card-mode?project=sandbox&selected=kubescape)
[![CNCF](https://shields.io/badge/CNCF-Incubating%20project-blue?logo=linux-foundation&style=flat)](https://landscape.cncf.io/?item=provisioning--security-compliance--kubescape)
[![Artifact HUB](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/kubescape)](https://artifacthub.io/packages/search?repo=kubescape)
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fkubescape%2Fkubescape.svg?type=shield&issueType=license)](https://app.fossa.com/projects/git%2Bgithub.com%2Fkubescape%2Fkubescape?ref=badge_shield&issueType=license)
[![OpenSSF Best Practices](https://www.bestpractices.dev/projects/6944/badge)](https://www.bestpractices.dev/projects/6944)
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/kubescape/kubescape/badge)](https://securityscorecards.dev/viewer/?uri=github.com/kubescape/kubescape)
[![Docs](https://img.shields.io/badge/docs-latest-brightgreen?logo=gitbook)](https://kubescape.io/docs/)
[![Stars](https://img.shields.io/github/stars/kubescape/kubescape?style=social)](https://github.com/kubescape/kubescape/stargazers)
[![Twitter Follow](https://img.shields.io/twitter/follow/kubescape?style=social)](https://twitter.com/kubescape)
[![Slack](https://img.shields.io/badge/slack-kubescape-blueviolet?logo=slack)](https://cloud-native.slack.com/archives/C04EY3ZF9GE)
# Kubescape
@@ -18,89 +21,480 @@
<img alt="Kubescape logo" align="right" src="https://raw.githubusercontent.com/cncf/artwork/master/projects/kubescape/stacked/color/kubescape-stacked-color.svg" width="150">
</picture>
_An open-source Kubernetes security platform for your IDE, CI/CD pipelines, and clusters_
_Comprehensive Kubernetes Security from Development to Runtime_
Kubescape is an open-source Kubernetes security platform. It includes risk analysis, security compliance, and misconfiguration scanning. Targeted at the DevSecOps practitioner or platform engineer, it offers an easy-to-use CLI interface, flexible output formats, and automated scanning capabilities. It saves Kubernetes users and admins precious time, effort, and resources.
Kubescape is an open-source Kubernetes security platform that provides comprehensive security coverage, from left to right across the entire development and deployment lifecycle. It offers hardening, posture management, and runtime security capabilities to ensure robust protection for Kubernetes environments.
Kubescape scans clusters, YAML files, and Helm charts. It detects misconfigurations according to multiple frameworks (including [NSA-CISA](https://www.armosec.io/blog/kubernetes-hardening-guidance-summary-by-armo/?utm_source=github&utm_medium=repository), [MITRE ATT&CK®](https://www.microsoft.com/security/blog/2021/03/23/secure-containerized-environments-with-updated-threat-matrix-for-kubernetes/) and the [CIS Benchmark](https://www.armosec.io/blog/cis-kubernetes-benchmark-framework-scanning-tools-comparison/?utm_source=github&utm_medium=repository)).
Kubescape was created by [ARMO](https://www.armosec.io/?utm_source=github&utm_medium=repository) and is a [Cloud Native Computing Foundation (CNCF) incubating project](https://www.cncf.io/projects/).
Kubescape was created by [ARMO](https://www.armosec.io/?utm_source=github&utm_medium=repository) and is a [Cloud Native Computing Foundation (CNCF) sandbox project](https://www.cncf.io/sandbox-projects/).
_Please [star ⭐](https://github.com/kubescape/kubescape/stargazers) the repo if you want us to continue developing and improving Kubescape!_
## Demo
<img src="docs/img/demo.gif">
---
_Please [star ⭐](https://github.com/kubescape/kubescape/stargazers) the repo if you want us to continue developing and improving Kubescape! 😀_
## 📑 Table of Contents
## Getting started
- [Features](#-features)
- [Demo](#-demo)
- [Quick Start](#-quick-start)
- [Installation](#-installation)
- [CLI Commands](#%EF%B8%8F-cli-commands)
- [Usage Examples](#-usage-examples)
- [Architecture](#%EF%B8%8F-architecture)
- [In-Cluster Operator](#%EF%B8%8F-in-cluster-operator)
- [Integrations](#-integrations)
- [Community](#-community)
- [Changelog](#changelog)
- [License](#license)
Experimenting with Kubescape is as easy as:
---
## ✨ Features
| Feature | Description |
|---------|-------------|
| 🔍 **Misconfiguration Scanning** | Scan clusters, YAML files, and Helm charts against NSA-CISA, MITRE ATT&CK®, and CIS Benchmarks |
| 🐳 **Image Vulnerability Scanning** | Detect CVEs in container images using [Grype](https://github.com/anchore/grype) |
| 🩹 **Image Patching** | Automatically patch vulnerable images using [Copacetic](https://github.com/project-copacetic/copacetic) |
| 🔧 **Auto-Remediation** | Automatically fix misconfigurations in Kubernetes manifests |
| 🛡️ **Admission Control** | Enforce security policies with Validating Admission Policies (VAP) |
| 📊 **Runtime Security** | eBPF-based runtime monitoring via [Inspektor Gadget](https://github.com/inspektor-gadget) |
| 🤖 **AI Integration** | MCP server for AI assistant integration |
---
## 🎬 Demo
<img src="docs/img/demo-v3.gif" alt="Kubescape CLI demo">
---
## 🚀 Quick Start
### 1. Install Kubescape
```sh
curl -s https://raw.githubusercontent.com/kubescape/kubescape/master/install.sh | /bin/bash
```
Learn more about:
> 💡 See [Installation](#-installation) for more options (Homebrew, Krew, Windows, etc.)
* [Installing Kubescape](docs/installation.md)
* [Running your first scan](docs/getting-started.md#run-your-first-scan)
* [Usage](docs/getting-started.md#examples)
* [Architecture](docs/architecture.md)
* [Building Kubescape from source](https://github.com/kubescape/kubescape/wiki/Building)
### 2. Run Your First Scan
_Did you know you can use Kubescape in all these places?_
```sh
# Scan your current cluster
kubescape scan
# Scan a specific YAML file or directory
kubescape scan /path/to/manifests/
# Scan a container image for vulnerabilities
kubescape scan image nginx:latest
```
### 3. Explore the Results
Kubescape provides a detailed security posture overview including:
- Control plane security status
- Access control risks
- Workload misconfigurations
- Network policy gaps
- Compliance scores (MITRE, NSA)
---
## 📦 Installation
### One-Line Install (Linux/macOS)
```bash
curl -s https://raw.githubusercontent.com/kubescape/kubescape/master/install.sh | /bin/bash
```
### Package Managers
| Platform | Command |
|----------|---------|
| **Homebrew** | `brew install kubescape` |
| **Krew** | `kubectl krew install kubescape` |
| **Arch Linux** | `yay -S kubescape` |
| **Ubuntu** | `sudo add-apt-repository ppa:kubescape/kubescape && sudo apt install kubescape` |
| **NixOS** | `nix-shell -p kubescape` |
| **Chocolatey** | `choco install kubescape` |
| **Scoop** | `scoop install kubescape` |
### Windows (PowerShell)
```powershell
iwr -useb https://raw.githubusercontent.com/kubescape/kubescape/master/install.ps1 | iex
```
📖 **[Full Installation Guide →](docs/installation.md)**
---
## 🛠️ CLI Commands
Kubescape provides a comprehensive CLI with the following commands:
| Command | Description |
|---------|-------------|
| [`kubescape scan`](#scanning) | Scan cluster, files, or images for security issues |
| [`kubescape scan image`](#image-scanning) | Scan container images for vulnerabilities |
| [`kubescape fix`](#auto-fix) | Auto-fix misconfigurations in manifest files |
| [`kubescape patch`](#image-patching) | Patch container images to fix vulnerabilities |
| [`kubescape list`](#list-frameworks-and-controls) | List available frameworks and controls |
| [`kubescape download`](#offline-support) | Download artifacts for offline/air-gapped use |
| [`kubescape config`](#configuration) | Manage cached configurations |
| [`kubescape operator`](#operator-commands) | Interact with in-cluster Kubescape operator |
| [`kubescape vap`](#validating-admission-policies) | Manage Validating Admission Policies |
| [`kubescape mcpserver`](#mcp-server) | Start MCP server for AI assistant integration |
| `kubescape completion` | Generate shell completion scripts |
| `kubescape version` | Display version information |
---
## 📖 Usage Examples
### Scanning
#### Scan a Running Cluster
```bash
# Default scan (all frameworks)
kubescape scan
# Scan with a specific framework
kubescape scan framework nsa
kubescape scan framework mitre
kubescape scan framework cis-v1.23-t1.0.1
# Scan a specific control
kubescape scan control C-0005 -v
```
#### Scan Files and Repositories
```bash
# Scan local YAML files
kubescape scan /path/to/manifests/
# Scan a Helm chart
kubescape scan /path/to/helm/chart/
# Scan a Git repository
kubescape scan https://github.com/kubescape/kubescape
# Scan with Kustomize
kubescape scan /path/to/kustomize/directory/
```
#### Scan Options
```bash
# Include/exclude namespaces
kubescape scan --include-namespaces production,staging
kubescape scan --exclude-namespaces kube-system,kube-public
# Use alternative kubeconfig
kubescape scan --kubeconfig /path/to/kubeconfig
# Set compliance threshold (exit code 1 if below threshold)
kubescape scan --compliance-threshold 80
# Set severity threshold
kubescape scan --severity-threshold high
```
#### Output Formats
```bash
# JSON output
kubescape scan --format json --output results.json
# JUnit XML (for CI/CD)
kubescape scan --format junit --output results.xml
# SARIF (for GitHub Code Scanning)
kubescape scan --format sarif --output results.sarif
# HTML report
kubescape scan --format html --output report.html
# PDF report
kubescape scan --format pdf --output report.pdf
```
### Image Scanning
```bash
# Scan a public image
kubescape scan image nginx:1.21
# Scan with verbose output
kubescape scan image nginx:1.21 -v
# Scan a private registry image
kubescape scan image myregistry/myimage:tag --username user --password pass
```
### Auto-Fix
Automatically fix misconfigurations in your manifest files:
```bash
# First, scan and save results to JSON
kubescape scan /path/to/manifests --format json --output results.json
# Then apply fixes
kubescape fix results.json
# Dry run (preview changes without applying)
kubescape fix results.json --dry-run
# Apply fixes without confirmation prompts
kubescape fix results.json --no-confirm
```
### Image Patching
Patch container images to fix OS-level vulnerabilities:
```bash
# Start buildkitd (required)
sudo buildkitd &
# Patch an image
sudo kubescape patch --image docker.io/library/nginx:1.22
# Specify custom output tag
sudo kubescape patch --image nginx:1.22 --tag nginx:1.22-patched
# See detailed vulnerability report
sudo kubescape patch --image nginx:1.22 -v
```
📖 **[Full Patch Command Documentation →](cmd/patch/README.md)**
### List Frameworks and Controls
```bash
# List available frameworks
kubescape list frameworks
# List all controls
kubescape list controls
# Output as JSON
kubescape list controls --format json
```
### Offline Support
Download artifacts for air-gapped environments:
```bash
# Download all artifacts
kubescape download artifacts --output /path/to/offline/dir
# Download a specific framework
kubescape download framework nsa --output /path/to/nsa.json
# Scan using downloaded artifacts
kubescape scan --use-artifacts-from /path/to/offline/dir
```
### Configuration
```bash
# View current configuration
kubescape config view
# Set account ID
kubescape config set accountID <your-account-id>
# Delete cached configuration
kubescape config delete
```
### Operator Commands
Interact with the in-cluster Kubescape operator:
```bash
# Trigger a configuration scan
kubescape operator scan configurations
# Trigger a vulnerability scan
kubescape operator scan vulnerabilities
```
### Validating Admission Policies
Manage Kubernetes Validating Admission Policies:
```bash
# Deploy the Kubescape CEL admission policy library
kubescape vap deploy-library | kubectl apply -f -
# Create a policy binding
kubescape vap create-policy-binding \
--name my-policy-binding \
--policy c-0016 \
--namespace my-namespace | kubectl apply -f -
```
### MCP Server
Start an MCP (Model Context Protocol) server for AI assistant integration:
```bash
kubescape mcpserver
```
The MCP server exposes Kubescape's vulnerability and configuration scan data to AI assistants, enabling natural language queries about your cluster's security posture.
**Available MCP Tools:**
- `list_vulnerability_manifests` - Discover vulnerability manifests
- `list_vulnerabilities_in_manifest` - List CVEs in a manifest
- `list_vulnerability_matches_for_cve` - Get details for a specific CVE
- `list_configuration_security_scan_manifests` - List configuration scan results
- `get_configuration_security_scan_manifest` - Get configuration scan details
---
## 🏗️ Architecture
Kubescape can run in two modes:
### CLI Mode
The CLI is a standalone tool that scans clusters, files, and images on-demand.
<div align="center">
<img src="docs/img/ksfromcodetodeploy.png" alt="Places you can use Kubescape: in your IDE, CI, CD, or against a running cluster.">
<img src="docs/img/ks-cli-arch.png" width="600" alt="CLI Architecture">
</div>
## Under the hood
**Key Components:**
- **[Open Policy Agent (OPA)](https://github.com/open-policy-agent/opa)** - Policy evaluation engine
- **[Regolibrary](https://github.com/kubescape/regolibrary)** - Library of security controls
- **[Grype](https://github.com/anchore/grype)** - Image vulnerability scanning
- **[Copacetic](https://github.com/project-copacetic/copacetic)** - Image patching
Kubescape uses [Open Policy Agent](https://github.com/open-policy-agent/opa) to verify Kubernetes objects against [a library of posture controls](https://github.com/kubescape/regolibrary).
### Operator Mode (In-Cluster)
By default, the results are printed in a console-friendly manner, but they can be:
For continuous monitoring, deploy the Kubescape operator via Helm.
* exported to JSON or junit XML
* rendered to HTML or PDF
* submitted to a [cloud service](docs/providers.md)
<div align="center">
<img src="docs/img/ks-operator-arch.png" width="600" alt="Operator Architecture">
</div>
It retrieves Kubernetes objects from the API server and runs a set of [Rego snippets](https://www.openpolicyagent.org/docs/latest/policy-language/) developed by [ARMO](https://www.armosec.io?utm_source=github&utm_medium=repository).
**Additional Capabilities:**
- Continuous configuration scanning
- Image vulnerability scanning
- Runtime analysis with eBPF
- Network policy generation
## Community
📖 **[Full Architecture Documentation →](docs/architecture.md)**
Kubescape is an open source project, we welcome your feedback and ideas for improvement. We are part of the Kubernetes community and are building more tests and controls as the ecosystem develops.
---
We hold [community meetings](https://zoom.us/j/95174063585) on Zoom, on the first Tuesday of every month, at 14:00 GMT. ([See that in your local time zone](https://time.is/compare/1400_in_GMT)).
## ☸️ In-Cluster Operator
The Kubescape project follows the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md).
The Kubescape operator provides continuous security monitoring in your cluster:
### Adopters
```bash
# Add the Kubescape Helm repository
helm repo add kubescape https://kubescape.github.io/helm-charts/
See [here](ADOPTERS.md) a list of adopters.
# Install the operator
helm upgrade --install kubescape kubescape/kubescape-operator \
--namespace kubescape \
--create-namespace
```
## Contributions
**Operator Features:**
- 🔄 Continuous misconfiguration scanning
- 🐳 Image vulnerability scanning for all workloads
- 🔍 Runtime threat detection (eBPF-based)
- 🌐 Network policy generation
- 📈 Prometheus metrics integration
Thanks to all our contributors! Check out our [CONTRIBUTING](CONTRIBUTING.md) file to learn how to join them.
📖 **[Operator Installation Guide →](https://kubescape.io/docs/operator/)**
* Feel free to pick a task from the [issues](https://github.com/kubescape/kubescape/issues?q=is%3Aissue+is%3Aopen+label%3A%22open+for+contribution%22), [roadmap](docs/roadmap.md) or suggest a feature of your own.
* [Open an issue](https://github.com/kubescape/kubescape/issues/new/choose): we aim to respond to all issues within 48 hours.
* [Join the CNCF Slack](https://slack.cncf.io/) and then our [users](https://cloud-native.slack.com/archives/C04EY3ZF9GE) or [developers](https://cloud-native.slack.com/archives/C04GY6H082K) channel.
---
<br>
## 🔌 Integrations
<a href = "https://github.com/kubescape/kubescape/graphs/contributors">
<img src = "https://contrib.rocks/image?repo=kubescape/kubescape"/>
### CI/CD
| Platform | Integration |
|----------|-------------|
| **GitHub Actions** | [kubescape/github-action](https://github.com/marketplace/actions/kubescape) |
| **GitLab CI** | [Documentation](https://kubescape.io/docs/integrations/gitlab/) |
| **Jenkins** | [Documentation](https://kubescape.io/docs/integrations/jenkins/) |
### IDE Extensions
| IDE | Extension |
|-----|-----------|
| **VS Code** | [Kubescape Extension](https://marketplace.visualstudio.com/items?itemName=kubescape.kubescape) |
| **Lens** | [Kubescape Lens Extension](https://github.com/armosec/lens-kubescape) |
### Where You Can Use Kubescape
<div align="center">
<img src="docs/img/ksfromcodetodeploy.png" alt="Kubescape integration points: IDE, CI, CD, Runtime">
</div>
---
## 👥 Community
Kubescape is a CNCF incubating project with an active community.
### Get Involved
- 💬 **[Slack - Users Channel](https://cloud-native.slack.com/archives/C04EY3ZF9GE)** - Ask questions, get help
- 💬 **[Slack - Developers Channel](https://cloud-native.slack.com/archives/C04GY6H082K)** - Contribute to development
- 🐛 **[GitHub Issues](https://github.com/kubescape/kubescape/issues)** - Report bugs and request features
- 📋 **[Project Board](https://github.com/orgs/kubescape/projects/4)** - See what we're working on
- 🗺️ **[Roadmap](https://github.com/kubescape/project-governance/blob/main/ROADMAP.md)** - Future plans
### Contributing
We welcome contributions! Please see our:
- **[Contributing Guide](https://github.com/kubescape/project-governance/blob/main/CONTRIBUTING.md)**
- **[Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md)**
### Community Resources
- **[Community Info](https://github.com/kubescape/project-governance/blob/main/COMMUNITY.md)**
- **[Governance](https://github.com/kubescape/project-governance/blob/main/GOVERNANCE.md)**
- **[Security Policy](https://github.com/kubescape/project-governance/blob/main/SECURITY.md)**
- **[Maintainers](https://github.com/kubescape/project-governance/blob/main/MAINTAINERS.md)**
### Contributors
<a href="https://github.com/kubescape/kubescape/graphs/contributors">
<img src="https://contrib.rocks/image?repo=kubescape/kubescape"/>
</a>
---
## Changelog
Kubescape changes are tracked on the [release](https://github.com/kubescape/kubescape/releases) page
Kubescape changes are tracked on the [releases page](https://github.com/kubescape/kubescape/releases).
---
## License
Copyright 2021-2023, the Kubescape Authors. All rights reserved. Kubescape is released under the Apache 2.0 license. See the [LICENSE](LICENSE) file for details.
Copyright 2021-2025, the Kubescape Authors. All rights reserved.
Kubescape is a [Cloud Native Computing Foundation (CNCF) sandbox project](https://www.cncf.io/sandbox-projects/) and was contributed by [ARMO](https://www.armosec.io/?utm_source=github&utm_medium=repository).
Kubescape is released under the [Apache 2.0 license](LICENSE).
Kubescape is a [Cloud Native Computing Foundation (CNCF) incubating project](https://www.cncf.io/projects/kubescape/) and was contributed by [ARMO](https://www.armosec.io/?utm_source=github&utm_medium=repository).
<div align="center">
<img src="https://raw.githubusercontent.com/cncf/artwork/master/other/cncf-sandbox/horizontal/color/cncf-sandbox-horizontal-color.svg" width="300" alt="CNCF Sandbox Project">
</div>
<img src="https://raw.githubusercontent.com/cncf/artwork/refs/heads/main/other/cncf-member/incubating/color/cncf-incubating-color.svg" width="300" alt="CNCF Incubating Project">
</div>

View File

@@ -4,19 +4,30 @@ header:
last-reviewed: '2023-10-12'
expiration-date: '2024-10-12T01:00:00.000Z'
project-url: https://github.com/kubescape/kubescape/
project-release: '1.0.0'
project-release: 1.0.0
project-lifecycle:
status: active
bug-fixes-only: false
core-maintainers:
- github:slashben
- github:amirmalka
- github:amitschendel
- github:bezbran
- github:craigbox
- github:matthyx
- github:dwertent
- github:matthyx
- github:rotemamsa
- github:slashben
contribution-policy:
accepts-pull-requests: true
accepts-automated-pull-requests: false
code-of-conduct: https://github.com/kubescape/kubescape/blob/master/CODE_OF_CONDUCT.md
dependencies:
third-party-packages: true
dependencies-lists:
- https://github.com/kubescape/kubescape/blob/master/go.mod
- https://github.com/kubescape/kubescape/blob/master/httphandler/go.mod
env-dependencies-policy:
policy-url: https://github.com/kubescape/kubescape/blob/master/docs/environment-dependencies-policy.md
documentation:
- https://github.com/kubescape/kubescape/tree/master/docs
distribution-points:

View File

@@ -1,7 +1,5 @@
# Reporting Security Issues
# Security
To report a security issue or vulnerability, submit a [private vulnerability report via GitHub](https://github.com/kubescape/kubescape/security/advisories/new) to the repository maintainers with a description of the issue, the steps you took to create the issue, affected versions, and, if known, mitigations for the issue.
The Kubescape project manages this document in the central project repository.
The maintainers will respond within 7 working days of your report. If the issue is confirmed as a vulnerability, we will open a Security Advisory and acknowledge your contributions as part of it. This project follows a 90 day disclosure timeline.
Other contacts: cncf-kubescape-maintainers@lists.cncf.io
Go to the [centralized SECURITY.md](https://github.com/kubescape/project-governance/blob/main/SECURITY.md)

View File

@@ -1,78 +0,0 @@
# Defining input params
param (
[string]$mode = "error"
)
# Function to install MSYS
function Install {
Write-Host "Starting install..." -ForegroundColor Cyan
# Check to see if already installed
if (Test-Path "C:\MSYS64\") {
Write-Host "MSYS2 already installed" -ForegroundColor Green
} else {
# Create a temp directory
New-Item -Path "$PSScriptRoot\temp_install" -ItemType Directory > $null
# Download MSYS
Write-Host "Downloading MSYS2..." -ForegroundColor Cyan
$bitsJobObj = Start-BitsTransfer "https://github.com/msys2/msys2-installer/releases/download/2022-06-03/msys2-x86_64-20220603.exe" -Destination "$PSScriptRoot\temp_install\msys2-x86_64-20220603.exe"
switch ($bitsJobObj.JobState) {
"Transferred" {
Complete-BitsTransfer -BitsJob $bitsJobObj
break
}
"Error" {
throw "Error downloading"
}
}
Write-Host "MSYS2 download complete" -ForegroundColor Green
# Install MSYS
Write-Host "Installing MSYS2..." -ForegroundColor Cyan
Start-Process -Filepath "$PSScriptRoot\temp_install\msys2-x86_64-20220603.exe" -ArgumentList @("install", "--root", "C:\MSYS64", "--confirm-command") -Wait
Write-Host "MSYS2 install complete" -ForegroundColor Green
# Remove temp directory
Remove-Item "$PSScriptRoot\temp_install" -Recurse
}
# Set PATH
$env:Path = "C:\MSYS64\mingw64\bin;C:\MSYS64\usr\bin;" + $env:Path
# Install MSYS packages
Write-Host "Installing MSYS2 packages..." -ForegroundColor Cyan
Start-Process -Filepath "pacman" -ArgumentList @("-S", "--needed", "--noconfirm", "make") -Wait
Start-Process -Filepath "pacman" -ArgumentList @("-S", "--needed", "--noconfirm", "mingw-w64-x86_64-cmake") -Wait
Start-Process -Filepath "pacman" -ArgumentList @("-S", "--needed", "--noconfirm", "mingw-w64-x86_64-gcc") -Wait
Start-Process -Filepath "pacman" -ArgumentList @("-S", "--needed", "--noconfirm", "mingw-w64-x86_64-pkg-config") -Wait
Start-Process -Filepath "pacman" -ArgumentList @("-S", "--needed", "--noconfirm", "msys2-w32api-runtime") -Wait
Write-Host "MSYS2 packages install complete" -ForegroundColor Green
Write-Host "Install complete" -ForegroundColor Green
}
# Function to build libgit2
function Build {
Write-Host "Starting build..." -ForegroundColor Cyan
# Set PATH
$env:Path = "C:\MSYS64\mingw64\bin;C:\MSYS64\usr\bin;" + $env:Path
# Build
Start-Process -Filepath "make" -ArgumentList @("libgit2") -Wait -NoNewWindow
Write-Host "Build complete" -ForegroundColor Green
}
# Check user call mode
if ($mode -eq "all") {
Install
Build
} elseif ($mode -eq "install") {
Install
} elseif ($mode -eq "build") {
Build
} else {
Write-Host "Error: -mode should be one of (all|install|build)" -ForegroundColor Red
}

View File

@@ -1,97 +0,0 @@
import os
import sys
import hashlib
import platform
import subprocess
import tarfile
BASE_GETTER_CONST = "github.com/kubescape/kubescape/v2/core/cautils/getter"
CURRENT_PLATFORM = platform.system()
platformSuffixes = {
"Windows": "windows-latest",
"Linux": "ubuntu-latest",
"Darwin": "macos-latest",
}
def check_status(status, msg):
if status != 0:
sys.stderr.write(msg)
exit(status)
def get_build_dir():
return "build"
def get_package_name():
if CURRENT_PLATFORM not in platformSuffixes: raise OSError("Platform %s is not supported!" % (CURRENT_PLATFORM))
# # TODO: kubescape-windows-latest is deprecated and should be removed
# if CURRENT_PLATFORM == "Windows": return "kubescape.exe"
package_name = "kubescape-"
if os.getenv("GOARCH"):
package_name += os.getenv("GOARCH") + "-"
return package_name + platformSuffixes[CURRENT_PLATFORM]
def main():
print("Building Kubescape")
# Set some variables
package_name = get_package_name()
build_url = "github.com/kubescape/kubescape/v2/core/cautils.BuildNumber"
release_version = os.getenv("RELEASE")
client_var = "github.com/kubescape/kubescape/v2/core/cautils.Client"
client_name = os.getenv("CLIENT")
# Create build directory
build_dir = get_build_dir()
ks_file = os.path.join(build_dir, package_name)
hash_file = ks_file + ".sha256"
tar_file = ks_file + ".tar.gz"
if not os.path.isdir(build_dir):
os.makedirs(build_dir)
# Build kubescape
ldflags = "-w -s"
if release_version:
ldflags += " -X {}={}".format(build_url, release_version)
if client_name:
ldflags += " -X {}={}".format(client_var, client_name)
build_command = ["go", "build", "-buildmode=pie", "-tags=static,gitenabled", "-o", ks_file, "-ldflags" ,ldflags]
if CURRENT_PLATFORM == "Windows":
os.putenv("CGO_ENABLED", "0")
build_command = ["go", "build", "-o", ks_file, "-ldflags", ldflags]
print("Building kubescape and saving here: {}".format(ks_file))
print("Build command: {}".format(" ".join(build_command)))
status = subprocess.call(build_command)
check_status(status, "Failed to build kubescape")
sha256 = hashlib.sha256()
with open(ks_file, "rb") as kube:
sha256.update(kube.read())
with open(hash_file, "w") as kube_sha:
hash = sha256.hexdigest()
print("kubescape hash: {}, file: {}".format(hash, hash_file))
kube_sha.write(sha256.hexdigest())
with tarfile.open(tar_file, 'w:gz') as archive:
name = "kubescape"
if CURRENT_PLATFORM == "Windows":
name += ".exe"
archive.add(ks_file, name)
archive.add("LICENSE", "LICENSE")
print("Build Done")
if __name__ == "__main__":
main()

View File

@@ -1,20 +1,12 @@
FROM --platform=$BUILDPLATFORM golang:1.20-bullseye as builder
ENV GO111MODULE=on CGO_ENABLED=0
WORKDIR /work
ARG TARGETOS TARGETARCH
RUN --mount=target=. \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
cd httphandler && GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o /out/ksserver .
FROM gcr.io/distroless/static-debian11:nonroot
FROM gcr.io/distroless/static-debian13:nonroot
USER nonroot
WORKDIR /home/nonroot/
COPY --from=builder /out/ksserver /usr/bin/ksserver
ARG TARGETPLATFORM
COPY $TARGETPLATFORM/downloader /usr/bin/downloader
RUN ["downloader"]
COPY $TARGETPLATFORM/ksserver /usr/bin/ksserver
ARG image_version client
ENV RELEASE=$image_version CLIENT=$client

View File

@@ -1,3 +1,2 @@
.git
git2go
kubescape*

View File

@@ -1,19 +1,241 @@
## Docker Build
# Building Kubescape
### Build your own Docker image
This guide covers how to build Kubescape from source.
1. Clone Project
```
git clone https://github.com/kubescape/kubescape.git kubescape && cd "$_"
## Table of Contents
- [Prerequisites](#prerequisites)
- [Building the CLI](#building-the-cli)
- [Building Docker Images](#building-docker-images)
- [Build Options](#build-options)
- [Development Setup](#development-setup)
- [Troubleshooting](#troubleshooting)
---
## Prerequisites
### Required
- **Go 1.23+** - [Installation Guide](https://golang.org/doc/install)
- **Git** - For cloning the repository
- **Make** - For running build commands
### Optional (for Docker builds)
- **Docker** - [Installation Guide](https://docs.docker.com/get-docker/)
- **Docker Buildx** - For multi-platform builds (included with Docker Desktop)
- **GoReleaser** - [Installation Guide](https://goreleaser.com/install/)
### Verify Prerequisites
```bash
go version # Should be 1.23 or higher
git --version
make --version
docker --version # Optional
goreleaser --version # Optional
```
2. Build kubescape CLI Docker image
```
make all
docker buildx build -t kubescape-cli -f build/kubescape-cli.Dockerfile --build-arg="ks_binary=kubescape" --load .
---
## Building the CLI
### Clone the Repository
```bash
git clone https://github.com/kubescape/kubescape.git
cd kubescape
```
3. Build kubescape Docker image
### Build with Make
```bash
# Build for your current platform
make build
# The binary will be at ./kubescape
./kubescape version
```
docker buildx build -t kubescape -f build/Dockerfile --load .
### Build Directly with Go
```bash
go build -o kubescape .
```
### Build with GoReleaser
```bash
# Build for your current platform
RELEASE=v0.0.1 CLIENT=local goreleaser build --snapshot --clean --single-target
```
### Cross-Compilation
Build for different platforms:
```bash
# Linux (amd64)
GOOS=linux GOARCH=amd64 go build -o kubescape-linux-amd64 .
# Linux (arm64)
GOOS=linux GOARCH=arm64 go build -o kubescape-linux-arm64 .
# macOS (amd64)
GOOS=darwin GOARCH=amd64 go build -o kubescape-darwin-amd64 .
# macOS (arm64 / Apple Silicon)
GOOS=darwin GOARCH=arm64 go build -o kubescape-darwin-arm64 .
# Windows (amd64)
GOOS=windows GOARCH=amd64 go build -o kubescape-windows-amd64.exe .
```
---
## Building Docker Images
Kubescape uses [GoReleaser](https://goreleaser.com/) to build its Docker images. The Dockerfiles are specifically designed to work with GoReleaser's build pipeline, which handles cross-compilation and places binaries in the expected directory structure.
### Build with GoReleaser
The recommended way to build Docker images locally is using GoReleaser. Note that `RELEASE`, `CLIENT`, and `RUN_E2E` environment variables are required:
```bash
# Build all artifacts and Docker images locally without publishing
# --skip=before,krew,nfpm,sbom skips unnecessary steps for faster local builds
RELEASE=v0.0.1 CLIENT=local RUN_E2E=false goreleaser release --snapshot --clean --skip=before,nfpm,sbom
```
Please read the [GoReleaser documentation](https://goreleaser.com/customization/dockers_v2/#testing-locally) for more details on using it for local testing.
---
## Build Options
### Make Targets
| Target | Description |
|--------|-------------|
| `make build` | Build the Kubescape binary |
| `make test` | Run unit tests |
| `make all` | Build everything |
| `make clean` | Remove build artifacts |
### Build Tags
You can use Go build tags to customize the build:
```bash
# Example with build tags
go build -tags "netgo" -o kubescape .
```
### Version Information
To embed version information in the build:
```bash
VERSION=$(git describe --tags --always)
BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
COMMIT=$(git rev-parse HEAD)
go build -ldflags "-X main.version=$VERSION -X main.buildDate=$BUILD_DATE -X main.commit=$COMMIT" -o kubescape .
```
---
## Development Setup
### Install Development Dependencies
```bash
# Install golangci-lint for linting
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
# Install other tools as needed
go mod download
```
### Run Tests
```bash
# Run all tests
make test
# Run tests with coverage
go test -cover ./...
# Run specific package tests
go test ./core/...
```
### Run Linter
```bash
golangci-lint run
```
### Code Formatting
```bash
go fmt ./...
```
---
## Troubleshooting
### Build Fails with "module not found"
```bash
# Update dependencies
go mod tidy
go mod download
```
### CGO-related Errors
If you encounter CGO errors, try building with CGO disabled:
```bash
CGO_ENABLED=0 go build -o kubescape .
```
### Docker Build Fails
Ensure Docker daemon is running and you have sufficient permissions.
If you encounter an error like `failed to calculate checksum ... "/linux/amd64/kubescape": not found`, it usually means you are trying to run `docker build` manually. Because the Dockerfiles are optimized for GoReleaser, you should use the `goreleaser release --snapshot` command described in the [Building Docker Images](#building-docker-images) section instead.
```bash
# Check Docker status
docker info
```
### Out of Memory During Build
For systems with limited memory:
```bash
# Limit Go's memory usage
GOGC=50 go build -o kubescape .
```
---
## Dockerfiles
| File | Description |
|------|-------------|
| `build/Dockerfile` | Full Kubescape image with HTTP handler |
| `build/kubescape-cli.Dockerfile` | Minimal CLI-only image |
---
## Related Documentation
- [Contributing Guide](https://github.com/kubescape/project-governance/blob/main/CONTRIBUTING.md)
- [Architecture](../docs/architecture.md)
- [Getting Started](../docs/getting-started.md)

View File

@@ -0,0 +1,151 @@
#!/usr/bin/env sh
#
# goreleaser-post-e2e.sh
#
# A small, robust POSIX shell script intended to be called from the goreleaser
# `builds[].hooks.post` entry. It is responsible for optionally running the
# repository smoke tests against the artifact produced in `dist/`.
#
# Usage:
# RUN_E2E=true -> enable running smoke tests
# E2E_FAIL_ON_ERROR=1 -> (default) treat test failures as fatal (exit non-zero)
# E2E_FAIL_ON_ERROR=0 -> treat test failures as non-fatal (log, but exit 0)
#
# The script is written to be defensive and to work under /bin/sh on CI runners.
# Use POSIX-safe flags only.
set -eu
# Helper for logging
_now() {
date --iso-8601=seconds 2>/dev/null || date
}
log() {
printf '%s [goreleaser-post-e2e] %s\n' "$(_now)" "$*"
}
# GitHub Actions log grouping helpers (no-op outside Actions)
gha_group_start() {
if [ "${GITHUB_ACTIONS:-}" = "true" ]; then
# Titles must be on a single line
printf '::group::%s\n' "$*"
fi
}
gha_group_end() {
if [ "${GITHUB_ACTIONS:-}" = "true" ]; then
printf '::endgroup::\n'
fi
}
# Small helper to interpret various truthy forms (1/true/yes/y)
is_true() {
case "${1:-}" in
1|true|TRUE|yes|YES|y|Y) return 0 ;;
*) return 1 ;;
esac
}
# Determine repo root relative to this script (script is expected to live in kubescape/build/)
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
: "${RUN_E2E:=false}"
# Default to fatal E2E failures.
: "${E2E_FAIL_ON_ERROR:=1}"
log "Starting goreleaser post-build e2e script"
log "RUN_E2E=${RUN_E2E}"
log "E2E_FAIL_ON_ERROR=${E2E_FAIL_ON_ERROR}"
# Only run on linux/amd64 to avoid running multiple times (once per build)
# and to ensure we can run the binary on the current host (assuming host is amd64).
if [ -n "${GOARCH:-}" ] && [ "${GOARCH}" != "amd64" ]; then
log "Skipping smoke tests for non-amd64 build (GOARCH=${GOARCH})."
exit 0
fi
if ! is_true "${RUN_E2E}"; then
log "RUN_E2E is not enabled. Skipping smoke tests. (RUN_E2E=${RUN_E2E})"
exit 0
fi
# Locate the amd64 artifact in dist/.
# Goreleaser v2 puts binaries in dist/<id>_<os>_<arch>_<version>/<binary>
# Example: dist/cli_linux_amd64_v1/kubescape
ART_PATH=""
if [ -d "$REPO_ROOT/dist" ]; then
# Find any file named 'kubescape' inside a directory containing 'linux_amd64' inside 'dist'
# We use 'find' for robustness against varying directory names
ART_PATH=$(find "$REPO_ROOT/dist" -type f -name "kubescape" -path "*linux_amd64*" | head -n 1)
fi
if [ -z "$ART_PATH" ] || [ ! -f "$ART_PATH" ]; then
log "No kubescape artifact found in dist/ matching *linux_amd64*/kubescape. Skipping smoke tests."
# If we are supposed to run E2E, not finding the artifact is probably an error.
if is_true "${E2E_FAIL_ON_ERROR}"; then
log "E2E_FAIL_ON_ERROR enabled -> failing because artifact was not found."
exit 1
fi
exit 0
fi
log "Using artifact: $ART_PATH"
# Make binary executable if it is a binary
chmod +x "$ART_PATH" >/dev/null 2>&1 || true
# Locate python runner
PYTHON=""
if command -v python3 >/dev/null 2>&1; then
PYTHON=python3
elif command -v python >/dev/null 2>&1; then
PYTHON=python
fi
if [ -z "$PYTHON" ]; then
log "python3 (or python) not found in PATH."
if is_true "${E2E_FAIL_ON_ERROR}"; then
log "E2E_FAIL_ON_ERROR enabled -> failing the release because python is missing."
exit 2
else
log "E2E_FAIL_ON_ERROR disabled -> continuing without running tests."
exit 0
fi
fi
# Check for smoke test runner
SMOKE_RUNNER="$REPO_ROOT/smoke_testing/init.py"
if [ ! -f "$SMOKE_RUNNER" ]; then
log "Smoke test runner not found at $SMOKE_RUNNER"
if is_true "${E2E_FAIL_ON_ERROR}"; then
log "E2E_FAIL_ON_ERROR enabled -> failing the release because smoke runner is missing."
exit 3
else
log "E2E_FAIL_ON_ERROR disabled -> continuing without running tests."
exit 0
fi
fi
gha_group_start "Smoke tests"
log "Running smoke tests with $PYTHON $SMOKE_RUNNER \"$ART_PATH\""
# Run the test runner, propagate exit code
set +e
RELEASE="${RELEASE:-}" "$PYTHON" "$SMOKE_RUNNER" "$ART_PATH"
rc=$?
set -e
if [ $rc -eq 0 ]; then
log "Smoke tests passed (exit code 0)."
fi
log "Smoke tests exited with code: $rc"
gha_group_end
if [ $rc -ne 0 ]; then
if is_true "${E2E_FAIL_ON_ERROR}"; then
log "E2E_FAIL_ON_ERROR enabled -> failing the release (exit code $rc)."
exit $rc
else
log "E2E_FAIL_ON_ERROR disabled -> continuing despite test failures."
fi
fi
exit 0

View File

@@ -1,12 +1,13 @@
FROM gcr.io/distroless/base-debian11:debug-nonroot
FROM gcr.io/distroless/static-debian13:debug-nonroot
USER nonroot
WORKDIR /home/nonroot/
ARG image_version client ks_binary
ARG image_version client TARGETARCH
ENV RELEASE=$image_version CLIENT=$client
COPY $ks_binary /usr/bin/kubescape
ARG TARGETPLATFORM
COPY $TARGETPLATFORM/kubescape /usr/bin/kubescape
RUN ["kubescape", "download", "artifacts"]
ENTRYPOINT ["kubescape"]

View File

@@ -1,2 +1 @@
.git
git2go

View File

@@ -5,7 +5,7 @@ import (
"os"
"strings"
"github.com/kubescape/kubescape/v2/core/cautils"
"github.com/kubescape/kubescape/v3/core/cautils"
"github.com/spf13/cobra"
)
@@ -29,6 +29,12 @@ func GetCompletionCmd() *cobra.Command {
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
Run: func(cmd *cobra.Command, args []string) {
// Check if args array is not empty
if len(args) == 0 {
fmt.Println("No arguements provided.")
return
}
switch strings.ToLower(args[0]) {
case "bash":
cmd.Root().GenBashCompletion(os.Stdout)
@@ -38,6 +44,8 @@ func GetCompletionCmd() *cobra.Command {
cmd.Root().GenFishCompletion(os.Stdout, true)
case "powershell":
cmd.Root().GenPowerShellCompletionWithDesc(os.Stdout)
default:
fmt.Printf("Invalid arguement %s", args[0])
}
},
}

View File

@@ -0,0 +1,187 @@
package completion
import (
"io"
"os"
"testing"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
)
// Generates autocompletion script for valid shell types
func TestGetCompletionCmd(t *testing.T) {
// Arrange
completionCmd := GetCompletionCmd()
assert.Equal(t, "completion [bash|zsh|fish|powershell]", completionCmd.Use)
assert.Equal(t, "Generate autocompletion script", completionCmd.Short)
assert.Equal(t, "To load completions", completionCmd.Long)
assert.Equal(t, completionCmdExamples, completionCmd.Example)
assert.Equal(t, true, completionCmd.DisableFlagsInUseLine)
assert.Equal(t, []string{"bash", "zsh", "fish", "powershell"}, completionCmd.ValidArgs)
}
func TestGetCompletionCmd_RunExpectedOutputs(t *testing.T) {
tests := []struct {
name string
args []string
want string
}{
{
name: "Unknown completion",
args: []string{"unknown"},
want: "Invalid arguement unknown",
},
{
name: "Empty arguements",
args: []string{},
want: "No arguements provided.\n",
},
}
completionCmd := GetCompletionCmd()
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Redirect stdout to a buffer
rescueStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
completionCmd.Run(&cobra.Command{}, tt.args)
w.Close()
got, _ := io.ReadAll(r)
os.Stdout = rescueStdout
assert.Equal(t, tt.want, string(got))
})
}
}
func TestGetCompletionCmd_RunNotExpectedOutputs(t *testing.T) {
notExpectedOutput1 := "No arguments provided."
notExpectedOutput2 := "No arguments provided."
tests := []struct {
name string
args []string
}{
{
name: "Bash completion",
args: []string{"bash"},
},
{
name: "Zsh completion",
args: []string{"zsh"},
},
{
name: "Fish completion",
args: []string{"fish"},
},
{
name: "PowerShell completion",
args: []string{"powershell"},
},
}
completionCmd := GetCompletionCmd()
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Redirect stdout to a buffer
rescueStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
completionCmd.Run(&cobra.Command{}, tt.args)
w.Close()
got, _ := io.ReadAll(r)
os.Stdout = rescueStdout
assert.NotEqual(t, notExpectedOutput1, string(got))
assert.NotEqual(t, notExpectedOutput2, string(got))
})
}
}
func TestGetCompletionCmd_RunBashCompletionNotExpectedOutputs(t *testing.T) {
notExpectedOutput1 := "Unexpected output for bash completion test 1."
notExpectedOutput2 := "Unexpected output for bash completion test 2."
// Redirect stdout to a buffer
rescueStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
completionCmd := GetCompletionCmd()
completionCmd.Run(&cobra.Command{}, []string{"bash"})
w.Close()
got, _ := io.ReadAll(r)
os.Stdout = rescueStdout
assert.NotEqual(t, notExpectedOutput1, string(got))
assert.NotEqual(t, notExpectedOutput2, string(got))
}
func TestGetCompletionCmd_RunZshCompletionNotExpectedOutputs(t *testing.T) {
notExpectedOutput1 := "Unexpected output for zsh completion test 1."
notExpectedOutput2 := "Unexpected output for zsh completion test 2."
// Redirect stdout to a buffer
rescueStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
completionCmd := GetCompletionCmd()
completionCmd.Run(&cobra.Command{}, []string{"zsh"})
w.Close()
got, _ := io.ReadAll(r)
os.Stdout = rescueStdout
assert.NotEqual(t, notExpectedOutput1, string(got))
assert.NotEqual(t, notExpectedOutput2, string(got))
}
func TestGetCompletionCmd_RunFishCompletionNotExpectedOutputs(t *testing.T) {
notExpectedOutput1 := "Unexpected output for fish completion test 1."
notExpectedOutput2 := "Unexpected output for fish completion test 2."
// Redirect stdout to a buffer
rescueStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
completionCmd := GetCompletionCmd()
completionCmd.Run(&cobra.Command{}, []string{"fish"})
w.Close()
got, _ := io.ReadAll(r)
os.Stdout = rescueStdout
assert.NotEqual(t, notExpectedOutput1, string(got))
assert.NotEqual(t, notExpectedOutput2, string(got))
}
func TestGetCompletionCmd_RunPowerShellCompletionNotExpectedOutputs(t *testing.T) {
notExpectedOutput1 := "Unexpected output for powershell completion test 1."
notExpectedOutput2 := "Unexpected output for powershell completion test 2."
// Redirect stdout to a buffer
rescueStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
completionCmd := GetCompletionCmd()
completionCmd.Run(&cobra.Command{}, []string{"powershell"})
w.Close()
got, _ := io.ReadAll(r)
os.Stdout = rescueStdout
assert.NotEqual(t, notExpectedOutput1, string(got))
assert.NotEqual(t, notExpectedOutput2, string(got))
}

View File

@@ -3,8 +3,8 @@ package config
import (
"fmt"
"github.com/kubescape/kubescape/v2/core/cautils"
"github.com/kubescape/kubescape/v2/core/meta"
"github.com/kubescape/kubescape/v3/core/cautils"
"github.com/kubescape/kubescape/v3/core/meta"
"github.com/spf13/cobra"
)

44
cmd/config/config_test.go Normal file
View File

@@ -0,0 +1,44 @@
package config
import (
"strings"
"testing"
"github.com/kubescape/kubescape/v3/core/mocks"
"github.com/stretchr/testify/assert"
)
func TestGetConfigCmd(t *testing.T) {
// Create a mock Kubescape interface
mockKubescape := &mocks.MockIKubescape{}
// Call the GetConfigCmd function
configCmd := GetConfigCmd(mockKubescape)
// Verify the command name and short description
assert.Equal(t, "config", configCmd.Use)
assert.Equal(t, "Handle cached configurations", configCmd.Short)
assert.Equal(t, configExample, configCmd.Example)
// Verify that the subcommands are added correctly
assert.Equal(t, 3, len(configCmd.Commands()))
for _, subcmd := range configCmd.Commands() {
switch subcmd.Name() {
case "delete":
// Verify that the delete subcommand is added correctly
assert.Equal(t, "delete", subcmd.Use)
assert.Equal(t, "Delete cached configurations", subcmd.Short)
case "set":
// Verify that the set subcommand is added correctly
assert.Equal(t, "set", subcmd.Use)
assert.Equal(t, "Set configurations, supported: "+strings.Join(stringKeysToSlice(supportConfigSet), "/"), subcmd.Short)
case "view":
// Verify that the view subcommand is added correctly
assert.Equal(t, "view", subcmd.Use)
assert.Equal(t, "View cached configurations", subcmd.Short)
default:
t.Errorf("Unexpected subcommand name: %s", subcmd.Name())
}
}
}

View File

@@ -1,11 +1,9 @@
package config
import (
"context"
logger "github.com/kubescape/go-logger"
"github.com/kubescape/kubescape/v2/core/meta"
v1 "github.com/kubescape/kubescape/v2/core/meta/datastructures/v1"
"github.com/kubescape/go-logger"
"github.com/kubescape/kubescape/v3/core/meta"
v1 "github.com/kubescape/kubescape/v3/core/meta/datastructures/v1"
"github.com/spf13/cobra"
)
@@ -15,7 +13,7 @@ func getDeleteCmd(ks meta.IKubescape) *cobra.Command {
Short: "Delete cached configurations",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
if err := ks.DeleteCachedConfig(context.TODO(), &v1.DeleteConfig{}); err != nil {
if err := ks.DeleteCachedConfig(&v1.DeleteConfig{}); err != nil {
logger.L().Fatal(err.Error())
}
},

21
cmd/config/delete_test.go Normal file
View File

@@ -0,0 +1,21 @@
package config
import (
"testing"
"github.com/kubescape/kubescape/v3/core/mocks"
"github.com/stretchr/testify/assert"
)
func TestGetDeleteCmd(t *testing.T) {
// Create a mock Kubescape interface
mockKubescape := &mocks.MockIKubescape{}
// Call the GetConfigCmd function
configCmd := getDeleteCmd(mockKubescape)
// Verify the command name and short description
assert.Equal(t, "delete", configCmd.Use)
assert.Equal(t, "Delete cached configurations", configCmd.Short)
assert.Equal(t, "", configCmd.Long)
}

View File

@@ -2,11 +2,12 @@ package config
import (
"fmt"
"sort"
"strings"
logger "github.com/kubescape/go-logger"
"github.com/kubescape/kubescape/v2/core/meta"
metav1 "github.com/kubescape/kubescape/v2/core/meta/datastructures/v1"
"github.com/kubescape/go-logger"
"github.com/kubescape/kubescape/v3/core/meta"
metav1 "github.com/kubescape/kubescape/v3/core/meta/datastructures/v1"
"github.com/spf13/cobra"
)
@@ -33,16 +34,23 @@ func getSetCmd(ks meta.IKubescape) *cobra.Command {
}
var supportConfigSet = map[string]func(*metav1.SetConfig, string){
"accessKey": func(s *metav1.SetConfig, accessKey string) { s.AccessKey = accessKey },
"accountID": func(s *metav1.SetConfig, account string) { s.Account = account },
"cloudAPIURL": func(s *metav1.SetConfig, cloudAPIURL string) { s.CloudAPIURL = cloudAPIURL },
"cloudReportURL": func(s *metav1.SetConfig, cloudReportURL string) { s.CloudReportURL = cloudReportURL },
}
func stringKeysToSlice(m map[string]func(*metav1.SetConfig, string)) []string {
l := []string{}
for i := range m {
l = append(l, i)
keys := []string{}
for key := range m {
keys = append(keys, key)
}
// Sort the keys of the map
sort.Strings(keys)
l := []string{}
l = append(l, keys...)
return l
}

81
cmd/config/set_test.go Normal file
View File

@@ -0,0 +1,81 @@
package config
import (
"fmt"
"strings"
"testing"
metav1 "github.com/kubescape/kubescape/v3/core/meta/datastructures/v1"
"github.com/kubescape/kubescape/v3/core/mocks"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
)
func TestGetSetCmd(t *testing.T) {
// Create a mock Kubescape interface
mockKubescape := &mocks.MockIKubescape{}
// Call the GetConfigCmd function
configSetCmd := getSetCmd(mockKubescape)
// Verify the command name and short description
assert.Equal(t, "set", configSetCmd.Use)
assert.Equal(t, "Set configurations, supported: "+strings.Join(stringKeysToSlice(supportConfigSet), "/"), configSetCmd.Short)
assert.Equal(t, setConfigExample, configSetCmd.Example)
assert.Equal(t, stringKeysToSlice(supportConfigSet), configSetCmd.ValidArgs)
err := configSetCmd.RunE(&cobra.Command{}, []string{"accountID=value1"})
assert.Nil(t, err)
err = configSetCmd.RunE(&cobra.Command{}, []string{})
expectedErrorMessage := "key '' unknown . supported: accessKey/accountID/cloudAPIURL/cloudReportURL"
assert.Equal(t, expectedErrorMessage, err.Error())
}
// Should return a slice of keys when given a non-empty map
func TestStringKeysToSlice(t *testing.T) {
m := map[string]func(*metav1.SetConfig, string){
"key1": nil,
"key2": nil,
"key3": nil,
}
result := stringKeysToSlice(m)
expected := []string{"key1", "key2", "key3"}
assert.ElementsMatch(t, expected, result)
}
func TestParseSetArgs_InvalidFormat(t *testing.T) {
args := []string{"key"}
setConfig, err := parseSetArgs(args)
assert.Equal(t, "", setConfig.Account)
assert.Equal(t, "", setConfig.AccessKey)
assert.Equal(t, "", setConfig.CloudReportURL)
assert.Equal(t, "", setConfig.CloudAPIURL)
expectedErrorMessage := fmt.Sprintf("key '' unknown . supported: %s", strings.Join(stringKeysToSlice(supportConfigSet), "/"))
assert.Equal(t, expectedErrorMessage, err.Error())
}
func TestParseSetArgs_AccessKey(t *testing.T) {
args := []string{"accessKey", "value1"}
setConfig, _ := parseSetArgs(args)
assert.Equal(t, "", setConfig.Account)
assert.Equal(t, "value1", setConfig.AccessKey)
assert.Equal(t, "", setConfig.CloudReportURL)
assert.Equal(t, "", setConfig.CloudAPIURL)
}
func TestParseSetArgs_Single(t *testing.T) {
args := []string{"accountID=value1"}
setConfig, _ := parseSetArgs(args)
assert.Equal(t, "value1", setConfig.Account)
assert.Equal(t, "", setConfig.AccessKey)
assert.Equal(t, "", setConfig.CloudReportURL)
assert.Equal(t, "", setConfig.CloudAPIURL)
}
func TestParseSetArgs_InvalidKey(t *testing.T) {
args := []string{"invalidKey=value1"}
_, err := parseSetArgs(args)
assert.Equal(t, "key 'invalidKey' unknown . supported: accessKey/accountID/cloudAPIURL/cloudReportURL", err.Error())
}

View File

@@ -3,9 +3,9 @@ package config
import (
"os"
logger "github.com/kubescape/go-logger"
"github.com/kubescape/kubescape/v2/core/meta"
v1 "github.com/kubescape/kubescape/v2/core/meta/datastructures/v1"
"github.com/kubescape/go-logger"
"github.com/kubescape/kubescape/v3/core/meta"
v1 "github.com/kubescape/kubescape/v3/core/meta/datastructures/v1"
"github.com/spf13/cobra"
)

21
cmd/config/view_test.go Normal file
View File

@@ -0,0 +1,21 @@
package config
import (
"testing"
"github.com/kubescape/kubescape/v3/core/mocks"
"github.com/stretchr/testify/assert"
)
func TestGetViewCmd(t *testing.T) {
// Create a mock Kubescape interface
mockKubescape := &mocks.MockIKubescape{}
// Call the GetConfigCmd function
configCmd := getViewCmd(mockKubescape)
// Verify the command name and short description
assert.Equal(t, "view", configCmd.Use)
assert.Equal(t, "View cached configurations", configCmd.Short)
assert.Equal(t, "", configCmd.Long)
}

View File

@@ -1,18 +1,17 @@
package download
import (
"context"
"fmt"
"path/filepath"
"slices"
"strings"
logger "github.com/kubescape/go-logger"
"github.com/kubescape/kubescape/v2/core/cautils"
"github.com/kubescape/kubescape/v2/core/core"
"github.com/kubescape/kubescape/v2/core/meta"
v1 "github.com/kubescape/kubescape/v2/core/meta/datastructures/v1"
"github.com/kubescape/go-logger"
"github.com/kubescape/kubescape/v3/core/cautils"
"github.com/kubescape/kubescape/v3/core/core"
"github.com/kubescape/kubescape/v3/core/meta"
v1 "github.com/kubescape/kubescape/v3/core/meta/datastructures/v1"
"github.com/spf13/cobra"
"golang.org/x/exp/slices"
)
var (
@@ -37,9 +36,6 @@ var (
# Download the configured controls-inputs
%[1]s download controls-inputs
# Download the attack tracks
%[1]s download attack-tracks
`, cautils.ExecName())
)
@@ -70,13 +66,16 @@ func GetDownloadCmd(ks meta.IKubescape) *cobra.Command {
if filepath.Ext(downloadInfo.Path) == ".json" {
downloadInfo.Path, downloadInfo.FileName = filepath.Split(downloadInfo.Path)
}
if len(args) == 0 {
return fmt.Errorf("no arguements provided")
}
downloadInfo.Target = args[0]
if len(args) >= 2 {
downloadInfo.Identifier = args[1]
}
if err := ks.Download(context.TODO(), &downloadInfo); err != nil {
if err := ks.Download(&downloadInfo); err != nil {
logger.L().Fatal(err.Error())
}
return nil
@@ -84,8 +83,7 @@ func GetDownloadCmd(ks meta.IKubescape) *cobra.Command {
}
downloadCmd.PersistentFlags().StringVarP(&downloadInfo.AccountID, "account", "", "", "Kubescape SaaS account ID. Default will load account ID from cache")
downloadCmd.PersistentFlags().MarkDeprecated("client-id", "Client ID is no longer supported. Feel free to contact the Kubescape maintainers for more information.")
downloadCmd.PersistentFlags().MarkDeprecated("secret-key", "Secret Key is no longer supported. Feel free to contact the Kubescape maintainers for more information.")
downloadCmd.PersistentFlags().StringVarP(&downloadInfo.AccessKey, "access-key", "", "", "Kubescape SaaS access key. Default will load access key from cache")
downloadCmd.Flags().StringVarP(&downloadInfo.Path, "output", "o", "", "Output file. If not specified, will save in `~/.kubescape/<policy name>.json`")
return downloadCmd

View File

@@ -0,0 +1,102 @@
package download
import (
"fmt"
"strings"
"testing"
"github.com/kubescape/kubescape/v3/core/core"
v1 "github.com/kubescape/kubescape/v3/core/meta/datastructures/v1"
"github.com/kubescape/kubescape/v3/core/mocks"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
)
func TestGetViewCmd(t *testing.T) {
// Create a mock Kubescape interface
mockKubescape := &mocks.MockIKubescape{}
// Call the GetConfigCmd function
configCmd := GetDownloadCmd(mockKubescape)
// Verify the command name and short description
assert.Equal(t, "download <policy> <policy name>", configCmd.Use)
assert.Equal(t, fmt.Sprintf("Download %s", strings.Join(core.DownloadSupportCommands(), ",")), configCmd.Short)
assert.Equal(t, "", configCmd.Long)
assert.Equal(t, downloadExample, configCmd.Example)
}
func TestGetViewCmd_Args(t *testing.T) {
// Create a mock Kubescape interface
mockKubescape := &mocks.MockIKubescape{}
// Call the GetConfigCmd function
downloadCmd := GetDownloadCmd(mockKubescape)
// Verify the command name and short description
assert.Equal(t, "download <policy> <policy name>", downloadCmd.Use)
assert.Equal(t, fmt.Sprintf("Download %s", strings.Join(core.DownloadSupportCommands(), ",")), downloadCmd.Short)
assert.Equal(t, "", downloadCmd.Long)
assert.Equal(t, downloadExample, downloadCmd.Example)
err := downloadCmd.RunE(&cobra.Command{}, []string{})
expectedErrorMessage := "no arguements provided"
assert.Equal(t, expectedErrorMessage, err.Error())
err = downloadCmd.RunE(&cobra.Command{}, []string{"config"})
assert.Nil(t, err)
err = downloadCmd.Args(&cobra.Command{}, []string{})
expectedErrorMessage = "policy type required, supported: artifacts,attack-tracks,control,controls-inputs,exceptions,framework"
assert.Equal(t, expectedErrorMessage, err.Error())
err = downloadCmd.Args(&cobra.Command{}, []string{"invalid"})
expectedErrorMessage = "invalid parameter 'invalid'. Supported parameters: artifacts,attack-tracks,control,controls-inputs,exceptions,framework"
assert.Equal(t, expectedErrorMessage, err.Error())
err = downloadCmd.Args(&cobra.Command{}, []string{"attack-tracks"})
assert.Nil(t, err)
err = downloadCmd.Args(&cobra.Command{}, []string{"control", "random.json"})
assert.Nil(t, err)
err = downloadCmd.Args(&cobra.Command{}, []string{"control", "C-0001"})
assert.Nil(t, err)
err = downloadCmd.Args(&cobra.Command{}, []string{"control", "C-0001", "C-0002"})
assert.Nil(t, err)
err = downloadCmd.RunE(&cobra.Command{}, []string{"control", "C-0001", "C-0002"})
assert.Nil(t, err)
}
func TestFlagValidationDownload_NoError(t *testing.T) {
downloadInfo := v1.DownloadInfo{
AccessKey: "",
AccountID: "",
}
assert.Equal(t, nil, flagValidationDownload(&downloadInfo))
}
func TestFlagValidationDownload_Error(t *testing.T) {
tests := []struct {
downloadInfo v1.DownloadInfo
}{
{
downloadInfo: v1.DownloadInfo{
AccountID: "12345678",
},
},
{
downloadInfo: v1.DownloadInfo{
AccountID: "New",
},
},
}
want := "bad argument: accound ID must be a valid UUID"
for _, tt := range tests {
t.Run(tt.downloadInfo.AccountID, func(t *testing.T) {
assert.Equal(t, want, flagValidationDownload(&tt.downloadInfo).Error())
})
}
}

View File

@@ -1,14 +1,12 @@
package fix
import (
"context"
"errors"
"fmt"
"github.com/kubescape/kubescape/v2/core/cautils"
"github.com/kubescape/kubescape/v2/core/meta"
metav1 "github.com/kubescape/kubescape/v2/core/meta/datastructures/v1"
"github.com/kubescape/kubescape/v3/core/cautils"
"github.com/kubescape/kubescape/v3/core/meta"
metav1 "github.com/kubescape/kubescape/v3/core/meta/datastructures/v1"
"github.com/spf13/cobra"
)
@@ -36,7 +34,7 @@ func GetFixCmd(ks meta.IKubescape) *cobra.Command {
}
fixInfo.ReportFile = args[0]
return ks.Fix(context.TODO(), &fixInfo)
return ks.Fix(&fixInfo)
},
}

30
cmd/fix/fix_test.go Normal file
View File

@@ -0,0 +1,30 @@
package fix
import (
"testing"
"github.com/kubescape/kubescape/v3/core/mocks"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
)
func TestGetFixCmd(t *testing.T) {
// Create a mock Kubescape interface
mockKubescape := &mocks.MockIKubescape{}
// Call the GetFixCmd function
fixCmd := GetFixCmd(mockKubescape)
// Verify the command name and short description
assert.Equal(t, "fix <report output file>", fixCmd.Use)
assert.Equal(t, "Propose a fix for the misconfiguration found when scanning Kubernetes manifest files", fixCmd.Short)
assert.Equal(t, "", fixCmd.Long)
assert.Equal(t, fixCmdExamples, fixCmd.Example)
err := fixCmd.RunE(&cobra.Command{}, []string{})
expectedErrorMessage := "report output file is required"
assert.Equal(t, expectedErrorMessage, err.Error())
err = fixCmd.RunE(&cobra.Command{}, []string{"random-file.json"})
assert.Nil(t, err)
}

View File

@@ -1,17 +1,17 @@
package list
import (
"context"
"errors"
"fmt"
"slices"
"strings"
logger "github.com/kubescape/go-logger"
"github.com/kubescape/kubescape/v2/core/cautils"
"github.com/kubescape/kubescape/v2/core/core"
"github.com/kubescape/kubescape/v2/core/meta"
v1 "github.com/kubescape/kubescape/v2/core/meta/datastructures/v1"
"github.com/kubescape/go-logger"
"github.com/kubescape/kubescape/v3/core/cautils"
"github.com/kubescape/kubescape/v3/core/core"
"github.com/kubescape/kubescape/v3/core/meta"
v1 "github.com/kubescape/kubescape/v3/core/meta/datastructures/v1"
"github.com/spf13/cobra"
"golang.org/x/exp/slices"
)
var (
@@ -26,7 +26,7 @@ var (
%[1]s list controls
Control documentation:
https://hub.armosec.io/docs/controls
https://kubescape.io/docs/controls/
`, cautils.ExecName())
)
@@ -55,15 +55,20 @@ func GetListCmd(ks meta.IKubescape) *cobra.Command {
return err
}
if len(args) < 1 {
return errors.New("no arguements provided")
}
listPolicies.Target = args[0]
if err := ks.List(context.TODO(), &listPolicies); err != nil {
if err := ks.List(&listPolicies); err != nil {
logger.L().Fatal(err.Error())
}
return nil
},
}
listCmd.PersistentFlags().StringVarP(&listPolicies.AccountID, "account", "", "", "Kubescape SaaS account ID. Default will load account ID from cache")
listCmd.PersistentFlags().StringVarP(&listPolicies.AccessKey, "access-key", "", "", "Kubescape SaaS access key. Default will load access key from cache")
listCmd.PersistentFlags().StringVar(&listPolicies.Format, "format", "pretty-print", "output format. supported: 'pretty-print'/'json'")
listCmd.PersistentFlags().MarkDeprecated("id", "Control ID's are included in list outputs")

44
cmd/list/list_test.go Normal file
View File

@@ -0,0 +1,44 @@
package list
import (
"strings"
"testing"
"github.com/kubescape/kubescape/v3/core/core"
"github.com/kubescape/kubescape/v3/core/mocks"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
)
func TestGetListCmd(t *testing.T) {
// Create a mock Kubescape interface
mockKubescape := &mocks.MockIKubescape{}
// Call the GetListCmd function
listCmd := GetListCmd(mockKubescape)
// Verify the command name and short description
assert.Equal(t, "list <policy> [flags]", listCmd.Use)
assert.Equal(t, "List frameworks/controls will list the supported frameworks and controls", listCmd.Short)
assert.Equal(t, "", listCmd.Long)
assert.Equal(t, listExample, listCmd.Example)
supported := strings.Join(core.ListSupportActions(), ",")
err := listCmd.Args(&cobra.Command{}, []string{})
expectedErrorMessage := "policy type requeued, supported: " + supported
assert.Equal(t, expectedErrorMessage, err.Error())
err = listCmd.Args(&cobra.Command{}, []string{"not-frameworks"})
expectedErrorMessage = "invalid parameter 'not-frameworks'. Supported parameters: " + supported
assert.Equal(t, expectedErrorMessage, err.Error())
err = listCmd.Args(&cobra.Command{}, []string{"frameworks"})
assert.Nil(t, err)
err = listCmd.RunE(&cobra.Command{}, []string{})
expectedErrorMessage = "no arguements provided"
assert.Equal(t, expectedErrorMessage, err.Error())
err = listCmd.RunE(&cobra.Command{}, []string{"some-value"})
assert.Nil(t, err)
}

499
cmd/mcpserver/mcpserver.go Normal file
View File

@@ -0,0 +1,499 @@
package mcpserver
import (
"context"
"encoding/json"
"fmt"
"log"
"strings"
"time"
"github.com/kubescape/go-logger"
helpersv1 "github.com/kubescape/k8s-interface/instanceidhandler/v1/helpers"
"github.com/kubescape/storage/pkg/apis/softwarecomposition/v1beta1"
spdxv1beta1 "github.com/kubescape/storage/pkg/generated/clientset/versioned/typed/softwarecomposition/v1beta1"
"github.com/mark3labs/mcp-go/mcp"
"github.com/mark3labs/mcp-go/server"
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
type KubescapeMcpserver struct {
s *server.MCPServer
ksClient spdxv1beta1.SpdxV1beta1Interface
}
func createVulnerabilityToolsAndResources(ksServer *KubescapeMcpserver) {
// Tool to list vulnerability manifests
listManifestsTool := mcp.NewTool(
"list_vulnerability_manifests",
mcp.WithDescription("Discover available vulnerability manifests at image and workload levels"),
mcp.WithString("namespace",
mcp.Description("Filter by namespace (optional)"),
),
mcp.WithString("level",
mcp.Description("Type of vulnerability manifests to list"),
mcp.Enum("image", "workload", "both"),
),
)
ksServer.s.AddTool(listManifestsTool, func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
return ksServer.CallTool("list_vulnerability_manifests", request.Params.Arguments.(map[string]interface{}))
})
listVulnerabilitiesTool := mcp.NewTool(
"list_vulnerabilities_in_manifest",
mcp.WithDescription("List all vulnerabilities in a given manifest"),
mcp.WithString("namespace",
mcp.Description("Filter by namespace (optional)"),
),
mcp.WithString("manifest_name",
mcp.Required(),
mcp.Description("Name of the manifest to list vulnerabilities from"),
),
)
ksServer.s.AddTool(listVulnerabilitiesTool, func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
return ksServer.CallTool("list_vulnerabilities_in_manifest", request.Params.Arguments.(map[string]interface{}))
})
listVulnerabilityMatchesForCVE := mcp.NewTool(
"list_vulnerability_matches_for_cve",
mcp.WithDescription("List all vulnerability matches for a given CVE in a given manifest"),
mcp.WithString("namespace",
mcp.Description("Filter by namespace (optional)"),
),
mcp.WithString("manifest_name",
mcp.Required(),
mcp.Description("Name of the manifest to list vulnerabilities from"),
),
mcp.WithString("cve_id",
mcp.Required(),
mcp.Description("ID of the CVE to list matches for"),
),
)
ksServer.s.AddTool(listVulnerabilityMatchesForCVE, func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
return ksServer.CallTool("list_vulnerability_matches_for_cve", request.Params.Arguments.(map[string]interface{}))
})
vulnerabilityManifestTemplate := mcp.NewResourceTemplate(
"kubescape://vulnerability-manifests/{namespace}/{manifest_name}",
"Vulnerability Manifest",
mcp.WithTemplateDescription("Complete vulnerability manifest either for a specific workload or image. Use 'list_vulnerability_manifests' tool to discover available manifests."),
mcp.WithTemplateMIMEType("application/json"),
)
ksServer.s.AddResourceTemplate(vulnerabilityManifestTemplate, ksServer.ReadResource)
}
func createConfigurationsToolsAndResources(ksServer *KubescapeMcpserver) {
// Tool to list configuration manifests
listConfigsTool := mcp.NewTool(
"list_configuration_security_scan_manifests",
mcp.WithDescription("Discover available security configuration scan results at workload level (this returns a list of manifests, not the scan results themselves, to get the scan results, use the get_configuration_security_scan_manifest tool)"),
mcp.WithString("namespace",
mcp.Description("Filter by namespace (optional)"),
),
)
ksServer.s.AddTool(listConfigsTool, func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
return ksServer.CallTool("list_configuration_security_scan_manifests", request.Params.Arguments.(map[string]interface{}))
})
getConfigDetailsTool := mcp.NewTool(
"get_configuration_security_scan_manifest",
mcp.WithDescription("Get details of a specific security configuration scan result"),
mcp.WithString("namespace",
mcp.Description("Namespace of the manifest (optional, defaults to 'kubescape')"),
),
mcp.WithString("manifest_name",
mcp.Required(),
mcp.Description("Name of the configuration manifest to get details for (get this from the list_configuration_security_scan_manifests tool)"),
),
)
ksServer.s.AddTool(getConfigDetailsTool, func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
return ksServer.CallTool("get_configuration_security_scan_manifest", request.Params.Arguments.(map[string]interface{}))
})
configManifestTemplate := mcp.NewResourceTemplate(
"kubescape://configuration-manifests/{namespace}/{manifest_name}",
"Configuration Security Scan Manifest",
mcp.WithTemplateDescription("Complete configuration scan manifest for a specific workload. Use 'list_configuration_security_scan_manifests' tool to discover available manifests."),
mcp.WithTemplateMIMEType("application/json"),
)
ksServer.s.AddResourceTemplate(configManifestTemplate, ksServer.ReadConfigurationResource)
}
func (ksServer *KubescapeMcpserver) ReadResource(ctx context.Context, request mcp.ReadResourceRequest) ([]mcp.ResourceContents, error) {
uri := request.Params.URI
// Validate the URI and check if it starts with kubescape://vulnerability-manifests/
if !strings.HasPrefix(uri, "kubescape://vulnerability-manifests/") {
return nil, fmt.Errorf("invalid URI: %s", uri)
}
// Verify that the URI is either the CVE list or CVE details
if !strings.HasSuffix(uri, "/cve_list") && !strings.Contains(uri, "/cve_details/") {
return nil, fmt.Errorf("invalid URI: %s", uri)
}
// Split the URI into namespace and manifest name
parts := strings.Split(uri, "/")
if len(parts) != 4 && len(parts) != 5 {
return nil, fmt.Errorf("invalid URI: %s", uri)
}
namespace := parts[1]
manifestName := parts[2]
cveID := ""
if len(parts) == 5 {
cveID = parts[3]
}
// Get the vulnerability manifest
manifest, err := ksServer.ksClient.VulnerabilityManifests(namespace).Get(ctx, manifestName, metav1.GetOptions{})
if err != nil {
return nil, fmt.Errorf("failed to get vulnerability manifest: %s", err)
}
var responseJson []byte
if cveID == "" {
// CVE list
var cveList []v1beta1.Vulnerability
for _, match := range manifest.Spec.Payload.Matches {
cveList = append(cveList, match.Vulnerability)
}
responseJson, err = json.Marshal(cveList)
if err != nil {
return nil, fmt.Errorf("failed to marshal cve list: %s", err)
}
} else {
// CVE details
var match []v1beta1.Match
for _, m := range manifest.Spec.Payload.Matches {
if m.Vulnerability.ID == cveID {
match = append(match, m)
}
}
responseJson, err = json.Marshal(match)
if err != nil {
return nil, fmt.Errorf("failed to marshal cve details: %s", err)
}
}
return []mcp.ResourceContents{mcp.TextResourceContents{
URI: uri,
Text: string(responseJson),
}}, nil
}
func (ksServer *KubescapeMcpserver) ReadConfigurationResource(ctx context.Context, request mcp.ReadResourceRequest) ([]mcp.ResourceContents, error) {
uri := request.Params.URI
if !strings.HasPrefix(uri, "kubescape://configuration-manifests/") {
return nil, fmt.Errorf("invalid URI: %s", uri)
}
parts := strings.Split(uri[len("kubescape://configuration-manifests/"):], "/")
if len(parts) != 2 {
return nil, fmt.Errorf("invalid URI: %s", uri)
}
namespace := parts[0]
manifestName := parts[1]
manifest, err := ksServer.ksClient.WorkloadConfigurationScans(namespace).Get(ctx, manifestName, metav1.GetOptions{})
if err != nil {
return nil, fmt.Errorf("failed to get configuration manifest: %s", err)
}
responseJson, err := json.Marshal(manifest)
if err != nil {
return nil, fmt.Errorf("failed to marshal configuration manifest: %s", err)
}
return []mcp.ResourceContents{mcp.TextResourceContents{
URI: uri,
Text: string(responseJson),
}}, nil
}
func (ksServer *KubescapeMcpserver) CallTool(name string, arguments map[string]interface{}) (*mcp.CallToolResult, error) {
switch name {
case "list_vulnerability_manifests":
//namespace, ok := arguments["namespace"]
//if !ok {
// namespace = ""
//}
level, ok := arguments["level"]
if !ok {
level = "both"
}
result := map[string]interface{}{
"vulnerability_manifests": map[string]interface{}{},
}
// Get workload-level manifests
labelSelector := ""
switch level {
case "workload":
labelSelector = "kubescape.io/context=filtered"
case "image":
labelSelector = "kubescape.io/context=non-filtered"
}
var manifests *v1beta1.VulnerabilityManifestList
var err error
if labelSelector == "" {
manifests, err = ksServer.ksClient.VulnerabilityManifests(metav1.NamespaceAll).List(context.Background(), metav1.ListOptions{})
} else {
manifests, err = ksServer.ksClient.VulnerabilityManifests(metav1.NamespaceAll).List(context.Background(), metav1.ListOptions{
LabelSelector: labelSelector,
})
}
if err != nil {
return nil, err
}
log.Printf("Found %d manifests", len(manifests.Items))
vulnerabilityManifests := []map[string]interface{}{}
for _, manifest := range manifests.Items {
isImageLevel := manifest.Annotations[helpersv1.WlidMetadataKey] == ""
manifestMap := map[string]interface{}{
"type": "workload",
"namespace": manifest.Namespace,
"manifest_name": manifest.Name,
"image-level": isImageLevel,
"workload-level": !isImageLevel,
"image-id": manifest.Annotations[helpersv1.ImageIDMetadataKey],
"image-tag": manifest.Annotations[helpersv1.ImageTagMetadataKey],
"workload-id": manifest.Annotations[helpersv1.WlidMetadataKey],
"workload-container-name": manifest.Annotations[helpersv1.ContainerNameMetadataKey],
"resource_uri": fmt.Sprintf("kubescape://vulnerability-manifests/%s/%s",
manifest.Namespace, manifest.Name),
}
vulnerabilityManifests = append(vulnerabilityManifests, manifestMap)
}
result["vulnerability_manifests"].(map[string]interface{})["manifests"] = vulnerabilityManifests
// Add template information
result["available_templates"] = map[string]string{
"vulnerability_manifest_cve_list": "kubescape://vulnerability-manifests/{namespace}/{manifest_name}/cve_list",
"vulnerability_manifest_cve_details": "kubescape://vulnerability-manifests/{namespace}/{manifest_name}/cve_details/{cve_id}",
}
content, _ := json.Marshal(result)
return &mcp.CallToolResult{
Content: []mcp.Content{
mcp.TextContent{
Type: "text",
Text: string(content),
},
},
}, nil
case "list_vulnerabilities_in_manifest":
namespace, ok := arguments["namespace"]
if !ok {
namespace = "kubescape"
}
namespaceStr, ok := namespace.(string)
if !ok {
return nil, fmt.Errorf("namespace must be a string")
}
manifestName, ok := arguments["manifest_name"]
if !ok {
return nil, fmt.Errorf("manifest_name is required")
}
manifestNameStr, ok := manifestName.(string)
if !ok {
return nil, fmt.Errorf("manifest_name must be a string")
}
manifest, err := ksServer.ksClient.VulnerabilityManifests(namespaceStr).Get(context.Background(), manifestNameStr, metav1.GetOptions{})
if err != nil {
return nil, fmt.Errorf("failed to get vulnerability manifest: %s", err)
}
var cveList []v1beta1.Vulnerability
for _, match := range manifest.Spec.Payload.Matches {
cveList = append(cveList, match.Vulnerability)
}
responseJson, err := json.Marshal(cveList)
if err != nil {
return nil, fmt.Errorf("failed to marshal cve list: %s", err)
}
return &mcp.CallToolResult{
Content: []mcp.Content{
mcp.TextContent{
Type: "text",
Text: string(responseJson),
},
},
}, nil
case "list_vulnerability_matches_for_cve":
namespace, ok := arguments["namespace"]
if !ok {
namespace = "kubescape"
}
namespaceStr, ok := namespace.(string)
if !ok {
return nil, fmt.Errorf("namespace must be a string")
}
manifestName, ok := arguments["manifest_name"]
if !ok {
return nil, fmt.Errorf("manifest_name is required")
}
manifestNameStr, ok := manifestName.(string)
if !ok {
return nil, fmt.Errorf("manifest_name must be a string")
}
cveID, ok := arguments["cve_id"]
if !ok {
return nil, fmt.Errorf("cve_id is required")
}
cveIDStr, ok := cveID.(string)
if !ok {
return nil, fmt.Errorf("cve_id must be a string")
}
manifest, err := ksServer.ksClient.VulnerabilityManifests(namespaceStr).Get(context.Background(), manifestNameStr, metav1.GetOptions{})
if err != nil {
return nil, fmt.Errorf("failed to get vulnerability manifest: %s", err)
}
var match []v1beta1.Match
for _, m := range manifest.Spec.Payload.Matches {
if m.Vulnerability.ID == cveIDStr {
match = append(match, m)
}
}
responseJson, err := json.Marshal(match)
if err != nil {
return nil, fmt.Errorf("failed to marshal cve details: %s", err)
}
return &mcp.CallToolResult{
Content: []mcp.Content{
mcp.TextContent{
Type: "text",
Text: string(responseJson),
},
},
}, nil
case "list_configuration_security_scan_manifests":
namespace, ok := arguments["namespace"]
if !ok {
namespace = "kubescape"
}
namespaceStr, ok := namespace.(string)
if !ok {
return nil, fmt.Errorf("namespace must be a string")
}
manifests, err := ksServer.ksClient.WorkloadConfigurationScans(namespaceStr).List(context.Background(), metav1.ListOptions{})
if err != nil {
return nil, err
}
log.Printf("Found %d configuration manifests", len(manifests.Items))
configManifests := []map[string]interface{}{}
for _, manifest := range manifests.Items {
item := map[string]interface{}{
"namespace": manifest.Namespace,
"manifest_name": manifest.Name,
"resource_uri": fmt.Sprintf("kubescape://configuration-manifests/%s/%s", manifest.Namespace, manifest.Name),
}
configManifests = append(configManifests, item)
}
result := map[string]interface{}{
"configuration_manifests": map[string]interface{}{
"manifests": configManifests,
},
"available_templates": map[string]string{
"configuration_manifest_details": "kubescape://configuration-manifests/{namespace}/{manifest_name}",
},
}
content, _ := json.Marshal(result)
return &mcp.CallToolResult{
Content: []mcp.Content{
mcp.TextContent{
Type: "text",
Text: string(content),
},
},
}, nil
case "get_configuration_security_scan_manifest":
namespace, ok := arguments["namespace"]
if !ok {
namespace = "kubescape"
}
namespaceStr, ok := namespace.(string)
if !ok {
return nil, fmt.Errorf("namespace must be a string")
}
manifestName, ok := arguments["manifest_name"]
if !ok {
return nil, fmt.Errorf("manifest_name is required")
}
manifestNameStr, ok := manifestName.(string)
if !ok {
return nil, fmt.Errorf("manifest_name must be a string")
}
manifest, err := ksServer.ksClient.WorkloadConfigurationScans(namespaceStr).Get(context.Background(), manifestNameStr, metav1.GetOptions{})
if err != nil {
return nil, fmt.Errorf("failed to get configuration manifest: %s", err)
}
responseJson, err := json.Marshal(manifest)
if err != nil {
return nil, fmt.Errorf("failed to marshal configuration manifest: %s", err)
}
return &mcp.CallToolResult{
Content: []mcp.Content{
mcp.TextContent{
Type: "text",
Text: string(responseJson),
},
},
}, nil
default:
return nil, fmt.Errorf("unknown tool: %s", name)
}
}
func mcpServerEntrypoint() error {
logger.L().Info("Starting MCP server...")
// Create a kubernetes client and verify it's working
client, err := CreateKsObjectConnection("default", 10*time.Second)
if err != nil {
return fmt.Errorf("failed to create kubernetes client: %v", err)
}
// Create a new MCP server
s := server.NewMCPServer(
"Kubescape MCP Server",
"0.0.1",
server.WithToolCapabilities(false),
server.WithRecovery(),
)
ksServer := &KubescapeMcpserver{
s: s,
ksClient: client,
}
// Creating Kubescape tools and resources
createVulnerabilityToolsAndResources(ksServer)
createConfigurationsToolsAndResources(ksServer)
// Start the server
if err := server.ServeStdio(s); err != nil {
return fmt.Errorf("server error: %v", err)
}
return nil
}
func GetMCPServerCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "mcpserver",
Short: "Start the Kubescape MCP server",
Long: `Start the Kubescape MCP server`,
RunE: func(cmd *cobra.Command, args []string) error {
return mcpServerEntrypoint()
},
}
return cmd
}

14
cmd/mcpserver/storage.go Normal file
View File

@@ -0,0 +1,14 @@
package mcpserver
import (
"time"
"github.com/kubescape/kubescape/v3/pkg/ksinit"
spdxv1beta1 "github.com/kubescape/storage/pkg/generated/clientset/versioned/typed/softwarecomposition/v1beta1"
)
// CreateKsObjectConnection delegates to the shared ksinit package
func CreateKsObjectConnection(namespace string, maxElapsedTime time.Duration) (spdxv1beta1.SpdxV1beta1Interface, error) {
return ksinit.CreateKsObjectConnection(namespace, maxElapsedTime)
}

View File

@@ -5,9 +5,9 @@ import (
"github.com/kubescape/go-logger"
"github.com/kubescape/go-logger/helpers"
"github.com/kubescape/kubescape/v2/core/cautils"
"github.com/kubescape/kubescape/v2/core/core"
"github.com/kubescape/kubescape/v2/core/meta"
"github.com/kubescape/kubescape/v3/core/cautils"
"github.com/kubescape/kubescape/v3/core/core"
"github.com/kubescape/kubescape/v3/core/meta"
"github.com/spf13/cobra"
)
@@ -21,7 +21,7 @@ var operatorScanConfigExamples = fmt.Sprintf(`
func getOperatorScanConfigCmd(ks meta.IKubescape, operatorInfo cautils.OperatorInfo) *cobra.Command {
configCmd := &cobra.Command{
Use: "configurations",
Short: "Trigger configuration scanning from the Kubescape-Operator microservice",
Short: "Trigger configuration scanning from the Kubescape Operator microservice",
Long: ``,
Example: operatorScanConfigExamples,
Args: func(cmd *cobra.Command, args []string) error {
@@ -29,17 +29,17 @@ func getOperatorScanConfigCmd(ks meta.IKubescape, operatorInfo cautils.OperatorI
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
operatorAdapter, err := core.NewOperatorAdapter(operatorInfo.OperatorScanInfo)
operatorAdapter, err := core.NewOperatorAdapter(operatorInfo.OperatorScanInfo, operatorInfo.Namespace)
if err != nil {
return err
}
logger.L().Start("Kubescape-Operator Triggering for configuration scanning")
logger.L().Start("Kubescape Operator Triggering for configuration scanning")
_, err = operatorAdapter.OperatorScan()
if err != nil {
logger.L().StopError("Failed to triggering Kubescape-Operator for configuration scanning", helpers.Error(err))
logger.L().StopError("Failed to triggering Kubescape Operator for configuration scanning", helpers.Error(err))
return err
}
logger.L().StopSuccess("Triggered Kubescape-Operator for configuration scanning")
logger.L().StopSuccess("Triggered Kubescape Operator for configuration scanning")
return nil
},
}

View File

@@ -0,0 +1,32 @@
package operator
import (
"testing"
"github.com/kubescape/kubescape/v3/core/cautils"
"github.com/kubescape/kubescape/v3/core/mocks"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
)
func TestGetOperatorScanConfigCmd(t *testing.T) {
// Create a mock Kubescape interface
mockKubescape := &mocks.MockIKubescape{}
operatorInfo := cautils.OperatorInfo{
Namespace: "namespace",
}
cmd := getOperatorScanConfigCmd(mockKubescape, operatorInfo)
// Verify the command name and short description
assert.Equal(t, "configurations", cmd.Use)
assert.Equal(t, "Trigger configuration scanning from the Kubescape Operator microservice", cmd.Short)
assert.Equal(t, "", cmd.Long)
assert.Equal(t, operatorScanConfigExamples, cmd.Example)
err := cmd.Args(&cobra.Command{}, []string{})
assert.Nil(t, err)
err = cmd.Args(&cobra.Command{}, []string{"configurations"})
assert.Nil(t, err)
}

View File

@@ -4,9 +4,8 @@ import (
"errors"
"fmt"
"github.com/kubescape/kubescape/v2/core/cautils"
"github.com/kubescape/kubescape/v2/core/meta"
"github.com/kubescape/kubescape/v3/core/cautils"
"github.com/kubescape/kubescape/v3/core/meta"
"github.com/spf13/cobra"
)
@@ -15,7 +14,7 @@ const (
)
var operatorExamples = fmt.Sprintf(`
# Trigger a configuration scan
%[1]s operator scan configurations
@@ -29,22 +28,22 @@ func GetOperatorCmd(ks meta.IKubescape) *cobra.Command {
operatorCmd := &cobra.Command{
Use: "operator",
Short: "The operator is used to communicate with the Kubescape-Operator within the cluster components.",
Short: "The operator is used to communicate with the Kubescape Operator within the cluster components.",
Long: ``,
Example: operatorExamples,
Args: func(cmd *cobra.Command, args []string) error {
operatorInfo.Subcommands = append(operatorInfo.Subcommands, "operator")
if len(args) < 2 {
return errors.New("For the operator sub-command, you need to provide at least one additional sub-command. Refer to the examples above.")
return errors.New("for the operator sub-command, you need to provide at least one additional sub-command. Refer to the examples above")
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 2 {
return errors.New("For the operator sub-command, you need to provide at least one additional sub-command. Refer to the examples above.")
return errors.New("for the operator sub-command, you need to provide at least one additional sub-command. Refer to the examples above")
}
if args[0] != scanSubCommand {
return errors.New(fmt.Sprintf("For the operator sub-command, only %s is supported. Refer to the examples above.", scanSubCommand))
return fmt.Errorf("for the operator sub-command, only %s is supported. Refer to the examples above", scanSubCommand)
}
return nil
},

View File

@@ -0,0 +1,42 @@
package operator
import (
"testing"
"github.com/kubescape/kubescape/v3/core/mocks"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
)
func TestGetOperatorCmd(t *testing.T) {
// Create a mock Kubescape interface
mockKubescape := &mocks.MockIKubescape{}
cmd := GetOperatorCmd(mockKubescape)
// Verify the command name and short description
assert.Equal(t, "operator", cmd.Use)
assert.Equal(t, "The operator is used to communicate with the Kubescape Operator within the cluster components.", cmd.Short)
assert.Equal(t, "", cmd.Long)
assert.Equal(t, operatorExamples, cmd.Example)
err := cmd.Args(&cobra.Command{}, []string{})
expectedErrorMessage := "for the operator sub-command, you need to provide at least one additional sub-command. Refer to the examples above"
assert.Equal(t, expectedErrorMessage, err.Error())
err = cmd.Args(&cobra.Command{}, []string{"scan", "configurations"})
assert.Nil(t, err)
err = cmd.RunE(&cobra.Command{}, []string{})
assert.Equal(t, expectedErrorMessage, err.Error())
err = cmd.RunE(&cobra.Command{}, []string{"scan", "configurations"})
assert.Nil(t, err)
err = cmd.RunE(&cobra.Command{}, []string{"scan"})
assert.Equal(t, expectedErrorMessage, err.Error())
err = cmd.RunE(&cobra.Command{}, []string{"random-subcommand", "random-config"})
expectedErrorMessage = "for the operator sub-command, only " + scanSubCommand + " is supported. Refer to the examples above"
assert.Equal(t, expectedErrorMessage, err.Error())
}

View File

@@ -4,8 +4,8 @@ import (
"errors"
"fmt"
"github.com/kubescape/kubescape/v2/core/cautils"
"github.com/kubescape/kubescape/v2/core/meta"
"github.com/kubescape/kubescape/v3/core/cautils"
"github.com/kubescape/kubescape/v3/core/meta"
"github.com/spf13/cobra"
)
@@ -32,12 +32,13 @@ func getOperatorScanCmd(ks meta.IKubescape, operatorInfo cautils.OperatorInfo) *
return errors.New("for operator scan sub command, you must pass at least 1 more sub commands, see above examples")
}
if (args[0] != vulnerabilitiesSubCommand) && (args[0] != configurationsSubCommand) {
return errors.New(fmt.Sprintf("For the operator sub-command, only %s and %s are supported. Refer to the examples above.", vulnerabilitiesSubCommand, configurationsSubCommand))
return fmt.Errorf("for the operator sub-command, only %s and %s are supported. Refer to the examples above", vulnerabilitiesSubCommand, configurationsSubCommand)
}
return nil
},
}
operatorCmd.PersistentFlags().StringVar(&operatorInfo.Namespace, "namespace", "kubescape", "namespace of the Kubescape Operator")
operatorCmd.AddCommand(getOperatorScanConfigCmd(ks, operatorInfo))
operatorCmd.AddCommand(getOperatorScanVulnerabilitiesCmd(ks, operatorInfo))

46
cmd/operator/scan_test.go Normal file
View File

@@ -0,0 +1,46 @@
package operator
import (
"testing"
"github.com/kubescape/kubescape/v3/core/cautils"
"github.com/kubescape/kubescape/v3/core/mocks"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
)
func TestGetOperatorScanCmd(t *testing.T) {
// Create a mock Kubescape interface
mockKubescape := &mocks.MockIKubescape{}
operatorInfo := cautils.OperatorInfo{
Namespace: "namespace",
}
cmd := getOperatorScanCmd(mockKubescape, operatorInfo)
// Verify the command name and short description
assert.Equal(t, "scan", cmd.Use)
assert.Equal(t, "Scan your cluster using the Kubescape-operator within the cluster components", cmd.Short)
assert.Equal(t, "", cmd.Long)
assert.Equal(t, operatorExamples, cmd.Example)
err := cmd.Args(&cobra.Command{}, []string{})
expectedErrorMessage := "for operator scan sub command, you must pass at least 1 more sub commands, see above examples"
assert.Equal(t, expectedErrorMessage, err.Error())
err = cmd.Args(&cobra.Command{}, []string{"operator"})
assert.Nil(t, err)
err = cmd.RunE(&cobra.Command{}, []string{})
assert.Equal(t, expectedErrorMessage, err.Error())
err = cmd.RunE(&cobra.Command{}, []string{"configurations"})
assert.Nil(t, err)
err = cmd.RunE(&cobra.Command{}, []string{"vulnerabilities"})
assert.Nil(t, err)
err = cmd.RunE(&cobra.Command{}, []string{"random"})
expectedErrorMessage = "for the operator sub-command, only " + vulnerabilitiesSubCommand + " and " + configurationsSubCommand + " are supported. Refer to the examples above"
assert.Equal(t, expectedErrorMessage, err.Error())
}

View File

@@ -6,9 +6,9 @@ import (
"github.com/kubescape/go-logger"
"github.com/kubescape/go-logger/helpers"
"github.com/kubescape/k8s-interface/k8sinterface"
"github.com/kubescape/kubescape/v2/core/cautils"
"github.com/kubescape/kubescape/v2/core/core"
"github.com/kubescape/kubescape/v2/core/meta"
"github.com/kubescape/kubescape/v3/core/cautils"
"github.com/kubescape/kubescape/v3/core/core"
"github.com/kubescape/kubescape/v3/core/meta"
"github.com/spf13/cobra"
)
@@ -30,17 +30,17 @@ func getOperatorScanVulnerabilitiesCmd(ks meta.IKubescape, operatorInfo cautils.
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
operatorAdapter, err := core.NewOperatorAdapter(operatorInfo.OperatorScanInfo)
operatorAdapter, err := core.NewOperatorAdapter(operatorInfo.OperatorScanInfo, operatorInfo.Namespace)
if err != nil {
return err
}
logger.L().Start("Triggering the Kubescape-Operator for vulnerability scanning")
logger.L().Start("Triggering the Kubescape Operator for vulnerability scanning")
_, err = operatorAdapter.OperatorScan()
if err != nil {
logger.L().StopError("Failed to trigger the Kubescape-Operator for vulnerability scanning", helpers.Error(err))
logger.L().StopError("Failed to trigger the Kubescape Operator for vulnerability scanning", helpers.Error(err))
return err
}
logger.L().StopSuccess("Triggered Kubescape-Operator for vulnerability scanning. View the scanning results once they are ready using the following command: \"kubectl get vulnerabilitysummaries\"")
logger.L().StopSuccess("Triggered Kubescape Operator for vulnerability scanning. View the scanning results once they are ready using the following command: \"kubectl get vulnerabilitysummaries\"")
return err
},
}

View File

@@ -0,0 +1,29 @@
package operator
import (
"testing"
"github.com/kubescape/kubescape/v3/core/cautils"
"github.com/kubescape/kubescape/v3/core/mocks"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
)
func TestGetOperatorScanVulnerabilitiesCmd(t *testing.T) {
// Create a mock Kubescape interface
mockKubescape := &mocks.MockIKubescape{}
operatorInfo := cautils.OperatorInfo{
Namespace: "namespace",
}
cmd := getOperatorScanVulnerabilitiesCmd(mockKubescape, operatorInfo)
// Verify the command name and short description
assert.Equal(t, "vulnerabilities", cmd.Use)
assert.Equal(t, "Vulnerabilities use for scan your cluster vulnerabilities using Kubescape operator in the in cluster components", cmd.Short)
assert.Equal(t, "", cmd.Long)
assert.Equal(t, operatorScanVulnerabilitiesExamples, cmd.Example)
err := cmd.Args(&cobra.Command{}, []string{"random-arg"})
assert.Nil(t, err)
}

142
cmd/patch/README.md Normal file
View File

@@ -0,0 +1,142 @@
# Patch Command
The patch command is used for patching container images with vulnerabilities.
It uses [copa](https://github.com/project-copacetic/copacetic) and [buildkit](https://github.com/moby/buildkit) under the hood for patching the container images, and [grype](https://github.com/anchore/grype) as the engine for scanning the images (at the moment).
## Usage
```bash
kubescape patch --image <image-name> [flags]
```
The patch command can be run in 2 ways:
1. **With sudo privileges**
You will need to start `buildkitd` if it is not already running
```bash
sudo buildkitd &
sudo kubescape patch --image <image-name>
```
2. **Without sudo privileges**
```bash
export BUILDKIT_VERSION=v0.11.4
export BUILDKIT_PORT=8888
docker run \
--detach \
--rm \
--privileged \
-p 127.0.0.1:$BUILDKIT_PORT:$BUILDKIT_PORT/tcp \
--name buildkitd \
--entrypoint buildkitd \
"moby/buildkit:$BUILDKIT_VERSION" \
--addr tcp://0.0.0.0:$BUILDKIT_PORT
kubescape patch \
-i <image-name> \
-a tcp://0.0.0.0:$BUILDKIT_PORT
```
### Flags
| Flag | Description | Required | Default |
| -------------- | ------------------------------------------------------ | -------- | ----------------------------------- |
| -i, --image | Image name to be patched (should be in canonical form) | Yes | |
| -a, --addr | Address of the buildkitd service | No | unix:///run/buildkit/buildkitd.sock |
| -t, --tag | Tag of the resultant patched image | No | image_name-patched |
| --timeout | Timeout for the patching process | No | 5m |
| --ignore-errors| Ignore errors during patching | No | false |
| -u, --username | Username for the image registry login | No | |
| -p, --password | Password for the image registry login | No | |
| -f, --format | Output file format. | No | |
| -o, --output | Output file. Print output to file and not stdout | No | |
| -v, --verbose | Display full report. Default to false | No | |
| -h, --help | help for patch | No | |
## Example
We will demonstrate how to use the patch command with an example of [nginx](https://www.nginx.com/) image.
### Pre-requisites
- [docker](https://docs.docker.com/desktop/install/linux-install/#generic-installation-steps) daemon must be installed and running.
- [buildkit](https://github.com/moby/buildkit) daemon must be installed
### Steps
1. Run `buildkitd` service:
```bash
sudo buildkitd
```
2. In a separate terminal, run the `kubescape patch` command:
```bash
sudo kubescape patch --image docker.io/library/nginx:1.22
```
3. You will get an output like below:
```bash
✅ Successfully scanned image: docker.io/library/nginx:1.22
✅ Patched image successfully. Loaded image: nginx:1.22-patched
✅ Successfully re-scanned image: nginx:1.22-patched
| Severity | Vulnerability | Component | Version | Fixed In |
| -------- | -------------- | ------------- | ----------------------- | -------- |
| Critical | CVE-2023-23914 | curl | 7.74.0-1.3+deb11u7 | wont-fix |
| Critical | CVE-2019-8457 | libdb5.3 | 5.3.28+dfsg1-0.8 | wont-fix |
| High | CVE-2022-42916 | libcurl4 | 7.74.0-1.3+deb11u7 | wont-fix |
| High | CVE-2022-1304 | libext2fs2 | 1.46.2-2 | wont-fix |
| High | CVE-2022-42916 | curl | 7.74.0-1.3+deb11u7 | wont-fix |
| High | CVE-2022-1304 | e2fsprogs | 1.46.2-2 | wont-fix |
| High | CVE-2022-1304 | libcom-err2 | 1.46.2-2 | wont-fix |
| High | CVE-2023-27533 | curl | 7.74.0-1.3+deb11u7 | wont-fix |
| High | CVE-2023-27534 | libcurl4 | 7.74.0-1.3+deb11u7 | wont-fix |
| High | CVE-2023-27533 | libcurl4 | 7.74.0-1.3+deb11u7 | wont-fix |
| High | CVE-2022-43551 | libcurl4 | 7.74.0-1.3+deb11u7 | wont-fix |
| High | CVE-2022-3715 | bash | 5.1-2+deb11u1 | wont-fix |
| High | CVE-2023-27534 | curl | 7.74.0-1.3+deb11u7 | wont-fix |
| High | CVE-2022-43551 | curl | 7.74.0-1.3+deb11u7 | wont-fix |
| High | CVE-2021-33560 | libgcrypt20 | 1.8.7-6 | wont-fix |
| High | CVE-2023-2953 | libldap-2.4-2 | 2.4.57+dfsg-3+deb11u1 | wont-fix |
| High | CVE-2022-1304 | libss2 | 1.46.2-2 | wont-fix |
| High | CVE-2020-22218 | libssh2-1 | 1.9.0-2 | wont-fix |
| High | CVE-2023-29491 | libtinfo6 | 6.2+20201114-2+deb11u1 | wont-fix |
| High | CVE-2022-2309 | libxml2 | 2.9.10+dfsg-6.7+deb11u4 | wont-fix |
| High | CVE-2022-4899 | libzstd1 | 1.4.8+dfsg-2.1 | wont-fix |
| High | CVE-2022-1304 | logsave | 1.46.2-2 | wont-fix |
| High | CVE-2023-29491 | ncurses-base | 6.2+20201114-2+deb11u1 | wont-fix |
| High | CVE-2023-29491 | ncurses-bin | 6.2+20201114-2+deb11u1 | wont-fix |
| High | CVE-2023-31484 | perl-base | 5.32.1-4+deb11u2 | wont-fix |
| High | CVE-2020-16156 | perl-base | 5.32.1-4+deb11u2 | wont-fix |
Vulnerability summary - 161 vulnerabilities found:
Image: nginx:1.22-patched
* 3 Critical
* 24 High
* 31 Medium
* 103 Other
Most vulnerable components:
* curl (7.74.0-1.3+deb11u7) - 1 Critical, 4 High, 5 Medium, 1 Low, 3 Negligible
* libcurl4 (7.74.0-1.3+deb11u7) - 1 Critical, 4 High, 5 Medium, 1 Low, 3 Negligible
* libtiff5 (4.2.0-1+deb11u4) - 7 Medium, 10 Negligible, 2 Unknown
* libxml2 (2.9.10+dfsg-6.7+deb11u4) - 1 High, 2 Medium
* perl-base (5.32.1-4+deb11u2) - 2 High, 2 Negligible
What now?
─────────
* Run with '--verbose'/'-v' flag for detailed vulnerabilities view
* Install Kubescape in your cluster for continuous monitoring and a full vulnerability report: https://github.com/kubescape/helm-charts/tree/main/charts/kubescape-cloud-operator
```
## Limitations
- The patch command can only fix OS-level vulnerability. It cannot fix application-level vulnerabilities. This is a limitation of copa. The reason behind this is that application level vulnerabilities are best suited to be fixed by the developers of the application.
Hence, this is not really a limitation but a design decision.
- No support for windows containers given the dependency on buildkit.

145
cmd/patch/patch.go Normal file
View File

@@ -0,0 +1,145 @@
package patch
import (
"errors"
"fmt"
"strings"
"time"
"github.com/distribution/reference"
"github.com/kubescape/go-logger"
"github.com/kubescape/kubescape/v3/cmd/shared"
"github.com/kubescape/kubescape/v3/core/cautils"
"github.com/kubescape/kubescape/v3/core/meta"
metav1 "github.com/kubescape/kubescape/v3/core/meta/datastructures/v1"
"github.com/spf13/cobra"
)
var patchCmdExamples = fmt.Sprintf(`
# Patch the nginx:1.22 image
1) sudo buildkitd # start buildkitd service, run in seperate terminal
2) sudo %[1]s patch --image docker.io/library/nginx:1.22 # patch the image
# The patch command can also be run without sudo privileges
# Documentation: https://github.com/kubescape/kubescape/tree/master/cmd/patch
`, cautils.ExecName())
func GetPatchCmd(ks meta.IKubescape) *cobra.Command {
var patchInfo metav1.PatchInfo
var scanInfo cautils.ScanInfo
var useDefaultMatchers bool
patchCmd := &cobra.Command{
Use: "patch --image <image>:<tag> [flags]",
Short: "Patch container images with vulnerabilities",
Long: `Patch command is for automatically patching images with vulnerabilities.`,
Example: patchCmdExamples,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) != 0 {
return fmt.Errorf("the command takes no arguments")
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
if err := shared.ValidateImageScanInfo(&scanInfo); err != nil {
return err
}
if err := validateImagePatchInfo(&patchInfo); err != nil {
return err
}
// Set the UseDefaultMatchers field in scanInfo
scanInfo.UseDefaultMatchers = useDefaultMatchers
exceedsSeverityThreshold, err := ks.Patch(&patchInfo, &scanInfo)
if err != nil {
return err
}
if exceedsSeverityThreshold {
shared.TerminateOnExceedingSeverity(&scanInfo, logger.L())
}
return nil
},
}
patchCmd.PersistentFlags().StringVarP(&patchInfo.Image, "image", "i", "", "Application image name and tag to patch")
patchCmd.PersistentFlags().StringVarP(&patchInfo.PatchedImageTag, "tag", "t", "", "Tag for the patched image. Defaults to '<image-tag>-patched' ")
patchCmd.PersistentFlags().StringVarP(&patchInfo.BuildkitAddress, "address", "a", "unix:///run/buildkit/buildkitd.sock", "Address of buildkitd service, defaults to local buildkitd.sock")
patchCmd.PersistentFlags().DurationVar(&patchInfo.Timeout, "timeout", 5*time.Minute, "Timeout for the operation, defaults to '5m'")
patchCmd.PersistentFlags().BoolVar(&patchInfo.IgnoreError, "ignore-errors", false, "Ignore errors and continue patching other images. Default to false")
patchCmd.PersistentFlags().StringVarP(&patchInfo.Username, "username", "u", "", "Username for registry login")
patchCmd.PersistentFlags().StringVarP(&patchInfo.Password, "password", "p", "", "Password for registry login")
patchCmd.PersistentFlags().StringVarP(&scanInfo.Format, "format", "f", "", `Output file format. Supported formats: "pretty-printer", "json", "sarif"`)
patchCmd.PersistentFlags().StringVarP(&scanInfo.Output, "output", "o", "", "Output file. Print output to file and not stdout")
patchCmd.PersistentFlags().BoolVarP(&scanInfo.VerboseMode, "verbose", "v", false, "Display full report. Default to false")
patchCmd.PersistentFlags().StringVarP(&scanInfo.FailThresholdSeverity, "severity-threshold", "s", "", "Severity threshold is the severity of a vulnerability at which the command fails and returns exit code 1")
patchCmd.PersistentFlags().BoolVarP(&useDefaultMatchers, "use-default-matchers", "", true, "Use default matchers (true) or CPE matchers (false) for image scanning")
return patchCmd
}
// validateImagePatchInfo validates the image patch info for the `patch` command
func validateImagePatchInfo(patchInfo *metav1.PatchInfo) error {
if patchInfo.Image == "" {
return errors.New("image tag is required")
}
// Convert image to canonical format (required by copacetic for patching images)
patchInfoImage, err := cautils.NormalizeImageName(patchInfo.Image)
if err != nil {
return nil
}
// Parse the image full name to get image name and tag
named, err := reference.ParseNamed(patchInfoImage)
if err != nil {
return err
}
// If no tag or digest is provided, default to 'latest'
if reference.IsNameOnly(named) {
logger.L().Warning("Image name has no tag or digest, using latest as tag")
named = reference.TagNameOnly(named)
}
patchInfo.Image = named.String()
// If no patched image tag is provided, default to '<image-tag>-patched'
if patchInfo.PatchedImageTag == "" {
taggedName, ok := named.(reference.Tagged)
if !ok {
return errors.New("unexpected error while parsing image tag")
}
patchInfo.ImageTag = taggedName.Tag()
if patchInfo.ImageTag == "" {
logger.L().Warning("No tag provided, defaulting to 'patched'")
patchInfo.PatchedImageTag = "patched"
} else {
patchInfo.PatchedImageTag = fmt.Sprintf("%s-%s", patchInfo.ImageTag, "patched")
}
}
// Extract the "image" name from the canonical Image URL
// If it's an official docker image, we store just the "image-name". Else if a docker repo then we store as "repo/image". Else complete URL
ref, _ := reference.ParseNormalizedNamed(patchInfo.Image)
imageName := named.Name()
if strings.Contains(imageName, "docker.io/library/") {
imageName = reference.Path(ref)
imageName = imageName[strings.LastIndex(imageName, "/")+1:]
} else if strings.Contains(imageName, "docker.io/") {
imageName = reference.Path(ref)
}
patchInfo.ImageName = imageName
return nil
}

69
cmd/patch/patch_test.go Normal file
View File

@@ -0,0 +1,69 @@
package patch
import (
"testing"
metav1 "github.com/kubescape/kubescape/v3/core/meta/datastructures/v1"
"github.com/kubescape/kubescape/v3/core/mocks"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
)
func TestGetPatchCmd(t *testing.T) {
// Create a mock Kubescape interface
mockKubescape := &mocks.MockIKubescape{}
cmd := GetPatchCmd(mockKubescape)
// Verify the command name and short description
assert.Equal(t, "patch --image <image>:<tag> [flags]", cmd.Use)
assert.Equal(t, "Patch container images with vulnerabilities", cmd.Short)
assert.Equal(t, "Patch command is for automatically patching images with vulnerabilities.", cmd.Long)
assert.Equal(t, patchCmdExamples, cmd.Example)
err := cmd.Args(&cobra.Command{}, []string{})
assert.Nil(t, err)
err = cmd.Args(&cobra.Command{}, []string{"test"})
expectedErrorMessage := "the command takes no arguments"
assert.Equal(t, expectedErrorMessage, err.Error())
err = cmd.RunE(&cobra.Command{}, []string{})
expectedErrorMessage = "image tag is required"
assert.Equal(t, expectedErrorMessage, err.Error())
err = cmd.RunE(&cobra.Command{}, []string{"patch", "--image", "docker.io/library/nginx:1.22"})
assert.Equal(t, expectedErrorMessage, err.Error())
}
func TestGetPatchCmdWithNonExistentImage(t *testing.T) {
// Create a mock Kubescape interface
mockKubescape := &mocks.MockIKubescape{}
// Call the GetPatchCmd function
cmd := GetPatchCmd(mockKubescape)
// Run the command with a non-existent image argument
err := cmd.RunE(&cobra.Command{}, []string{"patch", "--image", "non-existent-image"})
// Check that there is an error and the error message is as expected
expectedErrorMessage := "image tag is required"
assert.Error(t, err)
assert.Equal(t, expectedErrorMessage, err.Error())
}
func Test_validateImagePatchInfo_EmptyImage(t *testing.T) {
patchInfo := &metav1.PatchInfo{}
err := validateImagePatchInfo(patchInfo)
assert.NotNil(t, err)
assert.Equal(t, "image tag is required", err.Error())
}
func Test_validateImagePatchInfo_Image(t *testing.T) {
patchInfo := &metav1.PatchInfo{
Image: "testing",
}
err := validateImagePatchInfo(patchInfo)
assert.Nil(t, err)
}

View File

@@ -0,0 +1,51 @@
package prerequisites
import (
"github.com/kubescape/go-logger"
"github.com/kubescape/go-logger/helpers"
"github.com/kubescape/kubescape/v3/core/meta"
"github.com/kubescape/sizing-checker/pkg/checks/connectivitycheck"
"github.com/kubescape/sizing-checker/pkg/checks/ebpfcheck"
"github.com/kubescape/sizing-checker/pkg/checks/pvcheck"
"github.com/kubescape/sizing-checker/pkg/checks/sizing"
"github.com/kubescape/sizing-checker/pkg/common"
"github.com/spf13/cobra"
)
func GetPreReqCmd(ks meta.IKubescape) *cobra.Command {
var kubeconfigPath *string
// preReqCmd represents the prerequisites command
preReqCmd := &cobra.Command{
Use: "prerequisites",
Short: "Check prerequisites for installing Kubescape Operator",
Run: func(cmd *cobra.Command, args []string) {
clientSet, inCluster := common.BuildKubeClient(*kubeconfigPath)
if clientSet == nil {
logger.L().Fatal("Could not create kube client. Exiting.")
}
// 1) Collect cluster data
clusterData, err := common.CollectClusterData(ks.Context(), clientSet)
if err != nil {
logger.L().Error("Failed to collect cluster data", helpers.Error(err))
}
// 2) Run checks
sizingResult := sizing.RunSizingChecker(clusterData)
pvResult := pvcheck.RunPVProvisioningCheck(ks.Context(), clientSet, clusterData, inCluster)
connectivityResult := connectivitycheck.RunConnectivityChecks(ks.Context(), clientSet, clusterData, inCluster)
ebpfResult := ebpfcheck.RunEbpfCheck(ks.Context(), clientSet, clusterData, inCluster)
// 3) Build and export the final ReportData
finalReport := common.BuildReportData(clusterData, sizingResult, pvResult, connectivityResult, ebpfResult)
finalReport.InCluster = inCluster
common.GenerateOutput(finalReport, inCluster)
},
}
kubeconfigPath = preReqCmd.PersistentFlags().String("kubeconfig", "", "Path to the kubeconfig file. If not set, in-cluster config is used or $HOME/.kube/config if outside a cluster.")
return preReqCmd
}

View File

@@ -1,26 +1,30 @@
package cmd
import (
"context"
"fmt"
"strings"
logger "github.com/kubescape/go-logger"
"github.com/kubescape/go-logger"
"github.com/kubescape/go-logger/helpers"
"github.com/kubescape/k8s-interface/k8sinterface"
"github.com/kubescape/kubescape/v2/cmd/completion"
"github.com/kubescape/kubescape/v2/cmd/config"
"github.com/kubescape/kubescape/v2/cmd/download"
"github.com/kubescape/kubescape/v2/cmd/fix"
"github.com/kubescape/kubescape/v2/cmd/list"
"github.com/kubescape/kubescape/v2/cmd/operator"
"github.com/kubescape/kubescape/v2/cmd/scan"
"github.com/kubescape/kubescape/v2/cmd/update"
"github.com/kubescape/kubescape/v2/cmd/version"
"github.com/kubescape/kubescape/v2/core/cautils"
"github.com/kubescape/kubescape/v2/core/cautils/getter"
"github.com/kubescape/kubescape/v2/core/core"
"github.com/kubescape/kubescape/v2/core/meta"
"github.com/kubescape/kubescape/v3/cmd/completion"
"github.com/kubescape/kubescape/v3/cmd/config"
"github.com/kubescape/kubescape/v3/cmd/download"
"github.com/kubescape/kubescape/v3/cmd/fix"
"github.com/kubescape/kubescape/v3/cmd/list"
"github.com/kubescape/kubescape/v3/cmd/mcpserver"
"github.com/kubescape/kubescape/v3/cmd/operator"
"github.com/kubescape/kubescape/v3/cmd/patch"
"github.com/kubescape/kubescape/v3/cmd/prerequisites"
"github.com/kubescape/kubescape/v3/cmd/scan"
"github.com/kubescape/kubescape/v3/cmd/update"
"github.com/kubescape/kubescape/v3/cmd/vap"
"github.com/kubescape/kubescape/v3/cmd/version"
"github.com/kubescape/kubescape/v3/core/cautils"
"github.com/kubescape/kubescape/v3/core/cautils/getter"
"github.com/kubescape/kubescape/v3/core/core"
"github.com/kubescape/kubescape/v3/core/meta"
"github.com/spf13/cobra"
)
@@ -40,16 +44,16 @@ var ksExamples = fmt.Sprintf(`
%[1]s config view
`, cautils.ExecName())
func NewDefaultKubescapeCommand() *cobra.Command {
ks := core.NewKubescape()
return getRootCmd(ks)
func NewDefaultKubescapeCommand(ctx context.Context, ksVersion, ksCommit, ksDate string) *cobra.Command {
ks := core.NewKubescape(ctx)
return getRootCmd(ks, ksVersion, ksCommit, ksDate)
}
func getRootCmd(ks meta.IKubescape) *cobra.Command {
func getRootCmd(ks meta.IKubescape, ksVersion, ksCommit, ksDate string) *cobra.Command {
rootCmd := &cobra.Command{
Use: "kubescape",
Short: "Kubescape is a tool for testing Kubernetes security posture. Docs: https://hub.armosec.io/docs",
Short: "Kubescape is a tool for testing Kubernetes security posture. Docs: https://kubescape.io/docs/",
Example: ksExamples,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
k8sinterface.SetClusterContextName(rootInfo.KubeContext)
@@ -82,8 +86,6 @@ func getRootCmd(ks meta.IKubescape) *cobra.Command {
rootCmd.PersistentFlags().StringVarP(&rootInfo.Logger, "logger", "l", helpers.InfoLevel.String(), fmt.Sprintf("Logger level. Supported: %s [$KS_LOGGER]", strings.Join(helpers.SupportedLevels(), "/")))
rootCmd.PersistentFlags().StringVar(&rootInfo.CacheDir, "cache-dir", getter.DefaultLocalStore, "Cache directory [$KS_CACHE_DIR]")
rootCmd.PersistentFlags().BoolVarP(&rootInfo.DisableColor, "disable-color", "", false, "Disable color output for logging")
rootCmd.PersistentFlags().BoolVarP(&rootInfo.EnableColor, "enable-color", "", false, "Force enable color output for logging")
rootCmd.PersistentFlags().StringVarP(&rootInfo.KubeContext, "kube-context", "", "", "Kube context. Default will use the current-context")
// Supported commands
@@ -91,11 +93,15 @@ func getRootCmd(ks meta.IKubescape) *cobra.Command {
rootCmd.AddCommand(download.GetDownloadCmd(ks))
rootCmd.AddCommand(list.GetListCmd(ks))
rootCmd.AddCommand(completion.GetCompletionCmd())
rootCmd.AddCommand(version.GetVersionCmd())
rootCmd.AddCommand(version.GetVersionCmd(ks, ksVersion, ksCommit, ksDate))
rootCmd.AddCommand(config.GetConfigCmd(ks))
rootCmd.AddCommand(update.GetUpdateCmd())
rootCmd.AddCommand(update.GetUpdateCmd(ks))
rootCmd.AddCommand(fix.GetFixCmd(ks))
rootCmd.AddCommand(patch.GetPatchCmd(ks))
rootCmd.AddCommand(vap.GetVapHelperCmd())
rootCmd.AddCommand(operator.GetOperatorCmd(ks))
rootCmd.AddCommand(prerequisites.GetPreReqCmd(ks))
rootCmd.AddCommand(mcpserver.GetMCPServerCmd())
// deprecated commands
rootCmd.AddCommand(&cobra.Command{
@@ -110,7 +116,7 @@ func getRootCmd(ks meta.IKubescape) *cobra.Command {
return rootCmd
}
func Execute() error {
ks := NewDefaultKubescapeCommand()
func Execute(ctx context.Context, ksVersion, ksCommit, ksDate string) error {
ks := NewDefaultKubescapeCommand(ctx, ksVersion, ksCommit, ksDate)
return ks.Execute()
}
}

24
cmd/root_test.go Normal file
View File

@@ -0,0 +1,24 @@
package cmd
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewDefaultKubescapeCommand(t *testing.T) {
t.Run("NewDefaultKubescapeCommand", func(t *testing.T) {
cmd := NewDefaultKubescapeCommand(context.Background(), "", "", "")
assert.NotNil(t, cmd)
})
}
func TestExecute(t *testing.T) {
t.Run("Execute", func(t *testing.T) {
err := Execute(context.Background(), "", "", "")
if err != nil {
assert.EqualErrorf(t, err, "unknown command \"^\\\\QTestExecute\\\\E$\" for \"kubescape\"", err.Error())
}
})
}

View File

@@ -7,21 +7,17 @@ import (
v1 "github.com/kubescape/backend/pkg/client/v1"
"github.com/kubescape/backend/pkg/servicediscovery"
sdClientV1 "github.com/kubescape/backend/pkg/servicediscovery/v1"
logger "github.com/kubescape/go-logger"
sdClientV2 "github.com/kubescape/backend/pkg/servicediscovery/v2"
"github.com/kubescape/go-logger"
"github.com/kubescape/go-logger/helpers"
"github.com/kubescape/go-logger/iconlogger"
"github.com/kubescape/go-logger/zaplogger"
"github.com/kubescape/kubescape/v2/core/cautils"
"github.com/kubescape/kubescape/v2/core/cautils/getter"
"github.com/kubescape/kubescape/v3/core/cautils"
"github.com/kubescape/kubescape/v3/core/cautils/getter"
"github.com/mattn/go-isatty"
)
func initLogger() {
logger.DisableColor(rootInfo.DisableColor)
logger.EnableColor(rootInfo.EnableColor)
if rootInfo.LoggerName == "" {
if l := os.Getenv("KS_LOGGER_NAME"); l != "" {
rootInfo.LoggerName = l
@@ -35,8 +31,8 @@ func initLogger() {
}
logger.InitLogger(rootInfo.LoggerName)
}
func initLoggerLevel() {
if rootInfo.Logger == helpers.InfoLevel.String() {
} else if l := os.Getenv("KS_LOGGER"); l != "" {
@@ -66,7 +62,7 @@ func initEnvironment() {
logger.L().Debug("fetching URLs from service discovery server", helpers.String("server", rootInfo.DiscoveryServerURL))
client, err := sdClientV1.NewServiceDiscoveryClientV1(rootInfo.DiscoveryServerURL)
client, err := sdClientV2.NewServiceDiscoveryClientV2(rootInfo.DiscoveryServerURL)
if err != nil {
logger.L().Fatal("failed to create service discovery client", helpers.Error(err), helpers.String("server", rootInfo.DiscoveryServerURL))
return
@@ -77,13 +73,13 @@ func initEnvironment() {
)
if err != nil {
logger.L().Fatal("failed to to get services from server", helpers.Error(err), helpers.String("server", rootInfo.DiscoveryServerURL))
logger.L().Fatal("failed to get services from server", helpers.Error(err), helpers.String("server", rootInfo.DiscoveryServerURL))
return
}
logger.L().Debug("configuring service discovery URLs", helpers.String("cloudAPIURL", services.GetApiServerUrl()), helpers.String("cloudReportURL", services.GetReportReceiverHttpUrl()))
tenant := cautils.GetTenantConfig("", "", "", nil)
tenant := cautils.GetTenantConfig("", "", "", "", nil)
if services.GetApiServerUrl() != "" {
tenant.GetConfigObj().CloudAPIURL = services.GetApiServerUrl()
}
@@ -99,6 +95,7 @@ func initEnvironment() {
services.GetApiServerUrl(),
services.GetReportReceiverHttpUrl(),
"",
"",
)
if err != nil {
logger.L().Fatal("failed to create KS Cloud client", helpers.Error(err))

View File

@@ -1,19 +1,17 @@
package scan
import (
"context"
"fmt"
"io"
"os"
"strings"
apisv1 "github.com/kubescape/opa-utils/httpserver/apis/v1"
logger "github.com/kubescape/go-logger"
"github.com/kubescape/go-logger"
"github.com/kubescape/go-logger/helpers"
"github.com/kubescape/kubescape/v2/core/cautils"
"github.com/kubescape/kubescape/v2/core/meta"
"github.com/kubescape/kubescape/v3/cmd/shared"
"github.com/kubescape/kubescape/v3/core/cautils"
"github.com/kubescape/kubescape/v3/core/meta"
apisv1 "github.com/kubescape/opa-utils/httpserver/apis/v1"
"github.com/spf13/cobra"
)
@@ -31,7 +29,7 @@ var (
Run '%[1]s list controls' for the list of supported controls
Control documentation:
https://hub.armosec.io/docs/controls
https://kubescape.io/docs/controls/
`, cautils.ExecName())
)
@@ -97,12 +95,11 @@ func getControlCmd(ks meta.IKubescape, scanInfo *cautils.ScanInfo) *cobra.Comman
return err
}
ctx := context.TODO()
results, err := ks.Scan(ctx, scanInfo)
results, err := ks.Scan(scanInfo)
if err != nil {
logger.L().Fatal(err.Error())
}
if err := results.HandleResults(ctx); err != nil {
if err := results.HandleResults(ks.Context(), scanInfo); err != nil {
logger.L().Fatal(err.Error())
}
if !scanInfo.VerboseMode {
@@ -129,7 +126,7 @@ func validateControlScanInfo(scanInfo *cautils.ScanInfo) error {
return fmt.Errorf("you can use `omit-raw-resources` or `submit`, but not both")
}
if err := validateSeverity(severity); severity != "" && err != nil {
if err := shared.ValidateSeverity(severity); severity != "" && err != nil {
return err
}
return nil

60
cmd/scan/control_test.go Normal file
View File

@@ -0,0 +1,60 @@
package scan
import (
"fmt"
"testing"
"github.com/kubescape/kubescape/v3/core/cautils"
"github.com/kubescape/kubescape/v3/core/mocks"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
)
func TestGetControlCmd(t *testing.T) {
// Create a mock Kubescape interface
mockKubescape := &mocks.MockIKubescape{}
scanInfo := cautils.ScanInfo{
AccountID: "new",
}
cmd := getControlCmd(mockKubescape, &scanInfo)
// Verify the command name and short description
assert.Equal(t, "control <control names list>/<control ids list>", cmd.Use)
assert.Equal(t, fmt.Sprintf("The controls you wish to use. Run '%[1]s list controls' for the list of supported controls", cautils.ExecName()), cmd.Short)
assert.Equal(t, controlExample, cmd.Example)
err := cmd.Args(&cobra.Command{}, []string{})
expectedErrorMessage := "requires at least one control name"
assert.Equal(t, expectedErrorMessage, err.Error())
err = cmd.Args(&cobra.Command{}, []string{"C-0001,C-0002"})
assert.Nil(t, err)
err = cmd.Args(&cobra.Command{}, []string{"C-0001,C-0002,"})
expectedErrorMessage = "usage: <control-0>,<control-1>"
assert.Equal(t, expectedErrorMessage, err.Error())
err = cmd.RunE(&cobra.Command{}, []string{})
expectedErrorMessage = "bad argument: accound ID must be a valid UUID"
assert.Equal(t, expectedErrorMessage, err.Error())
}
func TestGetControlCmdWithNonExistentControl(t *testing.T) {
// Create a mock Kubescape interface
mockKubescape := &mocks.MockIKubescape{}
scanInfo := cautils.ScanInfo{
AccountID: "new",
}
// Call the GetControlCmd function
cmd := getControlCmd(mockKubescape, &scanInfo)
// Run the command with a non-existent control argument
err := cmd.RunE(&cobra.Command{}, []string{"control", "C-0001,C-0002"})
// Check that there is an error and the error message is as expected
expectedErrorMessage := "bad argument: accound ID must be a valid UUID"
assert.Error(t, err)
assert.Equal(t, expectedErrorMessage, err.Error())
}

View File

@@ -1,24 +1,22 @@
package scan
import (
"context"
"errors"
"fmt"
"io"
"os"
"slices"
"strings"
"github.com/kubescape/go-logger"
"github.com/kubescape/go-logger/helpers"
"github.com/kubescape/kubescape/v3/cmd/shared"
"github.com/kubescape/kubescape/v3/core/cautils"
"github.com/kubescape/kubescape/v3/core/cautils/getter"
"github.com/kubescape/kubescape/v3/core/meta"
apisv1 "github.com/kubescape/opa-utils/httpserver/apis/v1"
reporthandlingapis "github.com/kubescape/opa-utils/reporthandling/apis"
"github.com/kubescape/opa-utils/reporthandling/results/v1/reportsummary"
"golang.org/x/exp/slices"
logger "github.com/kubescape/go-logger"
"github.com/kubescape/go-logger/helpers"
"github.com/kubescape/kubescape/v2/core/cautils"
"github.com/kubescape/kubescape/v2/core/cautils/getter"
"github.com/kubescape/kubescape/v2/core/meta"
"github.com/spf13/cobra"
)
@@ -42,7 +40,6 @@ var (
Run '%[1]s list frameworks' for the list of supported frameworks
`, cautils.ExecName())
ErrUnknownSeverity = errors.New("unknown severity")
ErrSecurityViewNotSupported = errors.New("security view is not supported for framework scan")
ErrBadThreshold = errors.New("bad argument: out of range threshold")
ErrKeepLocalOrSubmit = errors.New("you can use `keep-local` or `submit`, but not both")
@@ -94,7 +91,7 @@ func getFrameworkCmd(ks meta.IKubescape, scanInfo *cautils.ScanInfo) *cobra.Comm
}
if len(args) > 1 {
if len(args[1:]) == 0 || args[1] != "-" {
if args[1] != "-" {
scanInfo.InputPatterns = args[1:]
logger.L().Debug("List of input files", helpers.Interface("patterns", scanInfo.InputPatterns))
} else { // store stdin to file - do NOT move to separate function !!
@@ -112,23 +109,18 @@ func getFrameworkCmd(ks meta.IKubescape, scanInfo *cautils.ScanInfo) *cobra.Comm
}
}
scanInfo.SetScanType(cautils.ScanTypeFramework)
scanInfo.FrameworkScan = true
scanInfo.SetPolicyIdentifiers(frameworks, apisv1.KindFramework)
ctx := context.TODO()
results, err := ks.Scan(ctx, scanInfo)
results, err := ks.Scan(scanInfo)
if err != nil {
logger.L().Fatal(err.Error())
}
if err = results.HandleResults(ctx); err != nil {
if err = results.HandleResults(ks.Context(), scanInfo); err != nil {
logger.L().Fatal(err.Error())
}
if !scanInfo.VerboseMode && scanInfo.ScanType == cautils.ScanTypeFramework {
logger.L().Info("Run with '--verbose'/'-v' flag for detailed resources view\n")
}
if results.GetRiskScore() > float32(scanInfo.FailThreshold) {
logger.L().Fatal("scan risk-score is above permitted threshold", helpers.String("risk-score", fmt.Sprintf("%.2f", results.GetRiskScore())), helpers.String("fail-threshold", fmt.Sprintf("%.2f", scanInfo.FailThreshold)))
}
@@ -140,12 +132,13 @@ func getFrameworkCmd(ks meta.IKubescape, scanInfo *cautils.ScanInfo) *cobra.Comm
return nil
},
}
}
// countersExceedSeverityThreshold returns true if severity of failed controls exceed the set severity threshold, else returns false
func countersExceedSeverityThreshold(severityCounters reportsummary.ISeverityCounters, scanInfo *cautils.ScanInfo) (bool, error) {
targetSeverity := scanInfo.FailThresholdSeverity
if err := validateSeverity(targetSeverity); err != nil {
if err := shared.ValidateSeverity(targetSeverity); err != nil {
return false, err
}
@@ -180,7 +173,7 @@ func countersExceedSeverityThreshold(severityCounters reportsummary.ISeverityCou
// terminateOnExceedingSeverity terminates the application on exceeding severity
func terminateOnExceedingSeverity(scanInfo *cautils.ScanInfo, l helpers.ILogger) {
l.Fatal("result exceeds severity threshold", helpers.String("set severity threshold", scanInfo.FailThresholdSeverity))
l.Fatal("compliance result exceeds severity threshold", helpers.String("set severity threshold", scanInfo.FailThresholdSeverity))
}
// enforceSeverityThresholds ensures that the scan results are below the defined severity threshold
@@ -199,21 +192,10 @@ func enforceSeverityThresholds(severityCounters reportsummary.ISeverityCounters,
}
}
// validateSeverity returns an error if a given severity is not known, nil otherwise
func validateSeverity(severity string) error {
for _, val := range reporthandlingapis.GetSupportedSeverities() {
if strings.EqualFold(severity, val) {
return nil
}
}
return ErrUnknownSeverity
}
// validateFrameworkScanInfo validates the scan info struct for the `scan framework` command
func validateFrameworkScanInfo(scanInfo *cautils.ScanInfo) error {
if scanInfo.View == string(cautils.SecurityViewType) {
return ErrSecurityViewNotSupported
scanInfo.View = string(cautils.ResourceViewType)
}
if scanInfo.Submit && scanInfo.Local {
@@ -229,7 +211,7 @@ func validateFrameworkScanInfo(scanInfo *cautils.ScanInfo) error {
return ErrOmitRawResourcesOrSubmit
}
severity := scanInfo.FailThresholdSeverity
if err := validateSeverity(severity); severity != "" && err != nil {
if err := shared.ValidateSeverity(severity); severity != "" && err != nil {
return err
}

View File

@@ -0,0 +1,60 @@
package scan
import (
"fmt"
"testing"
"github.com/kubescape/kubescape/v3/core/cautils"
"github.com/kubescape/kubescape/v3/core/mocks"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
)
func TestGetFrameworkCmd(t *testing.T) {
// Create a mock Kubescape interface
mockKubescape := &mocks.MockIKubescape{}
scanInfo := cautils.ScanInfo{
AccountID: "new",
}
cmd := getFrameworkCmd(mockKubescape, &scanInfo)
// Verify the command name and short description
assert.Equal(t, "framework <framework names list> [`<glob pattern>`/`-`] [flags]", cmd.Use)
assert.Equal(t, fmt.Sprintf("The framework you wish to use. Run '%[1]s list frameworks' for the list of supported frameworks", cautils.ExecName()), cmd.Short)
assert.Equal(t, frameworkExample, cmd.Example)
err := cmd.Args(&cobra.Command{}, []string{})
expectedErrorMessage := "requires at least one framework name"
assert.Equal(t, expectedErrorMessage, err.Error())
err = cmd.Args(&cobra.Command{}, []string{"nsa,mitre"})
assert.Nil(t, err)
err = cmd.Args(&cobra.Command{}, []string{"nsa,mitre,"})
expectedErrorMessage = "usage: <framework-0>,<framework-1>"
assert.Equal(t, expectedErrorMessage, err.Error())
err = cmd.RunE(&cobra.Command{}, []string{})
expectedErrorMessage = "bad argument: accound ID must be a valid UUID"
assert.Equal(t, expectedErrorMessage, err.Error())
}
func TestGetFrameworkCmdWithNonExistentFramework(t *testing.T) {
// Create a mock Kubescape interface
mockKubescape := &mocks.MockIKubescape{}
scanInfo := cautils.ScanInfo{
AccountID: "new",
}
// Call the GetFrameworkCmd function
cmd := getFrameworkCmd(mockKubescape, &scanInfo)
// Run the command with a non-existent framework argument
err := cmd.RunE(&cobra.Command{}, []string{"framework", "nsa,mitre"})
// Check that there is an error and the error message is as expected
expectedErrorMessage := "bad argument: accound ID must be a valid UUID"
assert.Error(t, err)
assert.Equal(t, expectedErrorMessage, err.Error())
}

View File

@@ -1,43 +1,41 @@
package scan
import (
"context"
"fmt"
logger "github.com/kubescape/go-logger"
"github.com/kubescape/kubescape/v2/core/cautils"
"github.com/kubescape/kubescape/v2/core/core"
"github.com/kubescape/kubescape/v2/core/meta"
"github.com/kubescape/kubescape/v2/core/pkg/resultshandling"
"github.com/kubescape/kubescape/v2/pkg/imagescan"
"github.com/kubescape/go-logger"
"github.com/kubescape/kubescape/v3/cmd/shared"
"github.com/kubescape/kubescape/v3/core/cautils"
"github.com/kubescape/kubescape/v3/core/meta"
metav1 "github.com/kubescape/kubescape/v3/core/meta/datastructures/v1"
"github.com/spf13/cobra"
)
type imageScanInfo struct {
Username string
Password string
}
// TODO(vladklokun): document image scanning on the Kubescape Docs Hub?
var (
imageExample = fmt.Sprintf(`
This command is still in BETA. Feel free to contact the Kubescape maintainers for more information.
Scan an image for vulnerabilities.
# Scan the 'nginx' image
%[1]s scan image "nginx"
# Image scan documentation:
# https://hub.armosec.io/docs/images
# Scan the 'nginx' image and see the full report
%[1]s scan image "nginx" -v
# Scan the 'nginx' image and use exceptions
%[1]s scan image "nginx" --exceptions exceptions.json
`, cautils.ExecName())
)
// imageCmd represents the image command
func getImageCmd(ks meta.IKubescape, scanInfo *cautils.ScanInfo, imgScanInfo *imageScanInfo) *cobra.Command {
// getImageCmd returns the scan image command
func getImageCmd(ks meta.IKubescape, scanInfo *cautils.ScanInfo) *cobra.Command {
var imgCredentials shared.ImageCredentials
var exceptions string
var useDefaultMatchers bool
cmd := &cobra.Command{
Use: "image <IMAGE_NAME>",
Use: "image <image>:<tag> [flags]",
Short: "Scan an image for vulnerabilities",
Example: imageExample,
Args: func(cmd *cobra.Command, args []string) error {
@@ -47,68 +45,40 @@ func getImageCmd(ks meta.IKubescape, scanInfo *cautils.ScanInfo, imgScanInfo *im
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
if err := validateImageScanInfo(scanInfo); err != nil {
if len(args) != 1 {
return fmt.Errorf("the command takes exactly one image name as an argument")
}
if err := shared.ValidateImageScanInfo(scanInfo); err != nil {
return err
}
failOnSeverity := imagescan.ParseSeverity(scanInfo.FailThresholdSeverity)
ctx := context.Background()
dbCfg, _ := imagescan.NewDefaultDBConfig()
svc := imagescan.NewScanService(dbCfg)
creds := imagescan.RegistryCredentials{
Username: imgScanInfo.Username,
Password: imgScanInfo.Password,
imgScanInfo := &metav1.ImageScanInfo{
Image: args[0],
Username: imgCredentials.Username,
Password: imgCredentials.Password,
Exceptions: exceptions,
UseDefaultMatchers: useDefaultMatchers,
}
userInput := args[0]
logger.L().Start(fmt.Sprintf("Scanning image: %s", userInput))
scanResults, err := svc.Scan(ctx, userInput, creds)
exceedsSeverityThreshold, err := ks.ScanImage(imgScanInfo, scanInfo)
if err != nil {
logger.L().StopError(fmt.Sprintf("Failed to scan image: %s", userInput))
return err
}
logger.L().StopSuccess(fmt.Sprintf("Successfully scanned image: %s", userInput))
scanInfo.SetScanType(cautils.ScanTypeImage)
outputPrinters := core.GetOutputPrinters(scanInfo, ctx, "")
uiPrinter := core.GetUIPrinter(ctx, scanInfo, "")
resultsHandler := resultshandling.NewResultsHandler(nil, outputPrinters, uiPrinter)
resultsHandler.ImageScanData = []cautils.ImageScanData{
{
PresenterConfig: scanResults,
Image: userInput,
},
if exceedsSeverityThreshold {
shared.TerminateOnExceedingSeverity(scanInfo, logger.L())
}
resultsHandler.HandleResults(ctx)
if imagescan.ExceedsSeverityThreshold(scanResults, failOnSeverity) {
terminateOnExceedingSeverity(scanInfo, logger.L())
}
return err
return nil
},
}
cmd.PersistentFlags().StringVarP(&imgScanInfo.Username, "username", "u", "", "Username for registry login")
cmd.PersistentFlags().StringVarP(&imgScanInfo.Password, "password", "p", "", "Password for registry login")
// The exceptions flag
cmd.PersistentFlags().StringVarP(&exceptions, "exceptions", "", "", "Path to the exceptions file")
cmd.PersistentFlags().StringVarP(&imgCredentials.Username, "username", "u", "", "Username for registry login")
cmd.PersistentFlags().StringVarP(&imgCredentials.Password, "password", "p", "", "Password for registry login")
cmd.PersistentFlags().BoolVarP(&useDefaultMatchers, "use-default-matchers", "", true, "Use default matchers (true) or CPE matchers (false)")
return cmd
}
// validateImageScanInfo validates the ScanInfo struct for the `image` command
func validateImageScanInfo(scanInfo *cautils.ScanInfo) error {
severity := scanInfo.FailThresholdSeverity
if err := validateSeverity(severity); severity != "" && err != nil {
return err
}
return nil
}

35
cmd/scan/image_test.go Normal file
View File

@@ -0,0 +1,35 @@
package scan
import (
"testing"
"github.com/kubescape/kubescape/v3/core/cautils"
"github.com/kubescape/kubescape/v3/core/mocks"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
)
func TestGetImageCmd(t *testing.T) {
// Create a mock Kubescape interface
mockKubescape := &mocks.MockIKubescape{}
scanInfo := cautils.ScanInfo{
AccountID: "new",
}
cmd := getImageCmd(mockKubescape, &scanInfo)
// Verify the command name and short description
assert.Equal(t, "image <image>:<tag> [flags]", cmd.Use)
assert.Equal(t, "Scan an image for vulnerabilities", cmd.Short)
assert.Equal(t, imageExample, cmd.Example)
err := cmd.Args(&cobra.Command{}, []string{})
expectedErrorMessage := "the command takes exactly one image name as an argument"
assert.Equal(t, expectedErrorMessage, err.Error())
err = cmd.Args(&cobra.Command{}, []string{"nginx"})
assert.Nil(t, err)
err = cmd.RunE(&cobra.Command{}, []string{})
assert.Equal(t, expectedErrorMessage, err.Error())
}

View File

@@ -1,25 +1,25 @@
package scan
import (
"context"
"flag"
"fmt"
"strings"
"github.com/kubescape/kubescape/v2/core/cautils"
"github.com/kubescape/kubescape/v2/core/cautils/getter"
"github.com/kubescape/kubescape/v2/core/meta"
"github.com/kubescape/go-logger"
"github.com/kubescape/kubescape/v3/core/cautils"
"github.com/kubescape/kubescape/v3/core/cautils/getter"
"github.com/kubescape/kubescape/v3/core/meta"
v1 "github.com/kubescape/opa-utils/httpserver/apis/v1"
"github.com/spf13/cobra"
)
var scanCmdExamples = fmt.Sprintf(`
Scan command is for scanning an existing cluster or kubernetes manifest files based on pre-defined frameworks
Scan command is for scanning an existing cluster or kubernetes manifest files based on pre-defined frameworks
# Scan current cluster
%[1]s scan
# Scan kubernetes manifest files
# Scan kubernetes manifest files
%[1]s scan .
# Scan and save the results in the JSON format
@@ -28,7 +28,7 @@ var scanCmdExamples = fmt.Sprintf(`
# Display all resources
%[1]s scan --verbose
# Scan different clusters from the kubectl context
# Scan different clusters from the kubectl context
%[1]s scan --kube-context <kubernetes context>
`, cautils.ExecName())
@@ -45,12 +45,17 @@ func GetScanCommand(ks meta.IKubescape) *cobra.Command {
if scanInfo.View == string(cautils.SecurityViewType) {
setSecurityViewScanInfo(args, &scanInfo)
return securityScan(scanInfo, ks)
if err := securityScan(scanInfo, ks); err != nil {
logger.L().Fatal(err.Error())
}
} else if len(args) == 0 || (args[0] != "framework" && args[0] != "control") {
if err := getFrameworkCmd(ks, &scanInfo).RunE(cmd, append([]string{strings.Join(getter.NativeFrameworks, ",")}, args...)); err != nil {
logger.L().Fatal(err.Error())
}
} else {
return fmt.Errorf("kubescape did not do anything")
}
if len(args) == 0 || (args[0] != "framework" && args[0] != "control") {
return getFrameworkCmd(ks, &scanInfo).RunE(cmd, append([]string{strings.Join(getter.NativeFrameworks, ",")}, args...))
}
return nil
},
PostRun: func(cmd *cobra.Command, args []string) {
@@ -58,7 +63,10 @@ func GetScanCommand(ks meta.IKubescape) *cobra.Command {
},
}
scanInfo.TriggeredByCLI = true
scanCmd.PersistentFlags().StringVarP(&scanInfo.AccountID, "account", "", "", "Kubescape SaaS account ID. Default will load account ID from cache")
scanCmd.PersistentFlags().StringVarP(&scanInfo.AccessKey, "access-key", "", "", "Kubescape SaaS access key. Default will load access key from cache")
scanCmd.PersistentFlags().StringVar(&scanInfo.ControlsInputs, "controls-config", "", "Path to an controls-config obj. If not set will download controls-config from ARMO management portal")
scanCmd.PersistentFlags().StringVar(&scanInfo.UseExceptions, "exceptions", "", "Path to an exceptions obj. If not set will download exceptions from ARMO management portal")
scanCmd.PersistentFlags().StringVar(&scanInfo.UseArtifactsFrom, "use-artifacts-from", "", "Load artifacts from local directory. If not used will download them")
@@ -68,12 +76,12 @@ func GetScanCommand(ks meta.IKubescape) *cobra.Command {
scanCmd.PersistentFlags().Float32VarP(&scanInfo.ComplianceThreshold, "compliance-threshold", "", 0, "Compliance threshold is the percent below which the command fails and returns exit code 1")
scanCmd.PersistentFlags().StringVar(&scanInfo.FailThresholdSeverity, "severity-threshold", "", "Severity threshold is the severity of failed controls at which the command fails and returns exit code 1")
scanCmd.PersistentFlags().StringVarP(&scanInfo.Format, "format", "f", "", `Output file format. Supported formats: "pretty-printer", "json", "junit", "prometheus", "pdf", "html", "sarif"`)
scanCmd.PersistentFlags().StringVarP(&scanInfo.Format, "format", "f", "pretty-printer", `Output file format. Supported formats: "pretty-printer", "json", "junit", "prometheus", "pdf", "html", "sarif"`)
scanCmd.PersistentFlags().StringVar(&scanInfo.IncludeNamespaces, "include-namespaces", "", "scan specific namespaces. e.g: --include-namespaces ns-a,ns-b")
scanCmd.PersistentFlags().BoolVarP(&scanInfo.Local, "keep-local", "", false, "If you do not want your Kubescape results reported to configured backend.")
scanCmd.PersistentFlags().StringVarP(&scanInfo.Output, "output", "o", "", "Output file. Print output to file and not stdout")
scanCmd.PersistentFlags().BoolVarP(&scanInfo.VerboseMode, "verbose", "v", false, "Display all of the input resources and not only failed resources")
scanCmd.PersistentFlags().StringVar(&scanInfo.View, "view", string(cautils.ResourceViewType), fmt.Sprintf("View results based on the %s/%s/%s. default is --view=%s", cautils.ResourceViewType, cautils.ControlViewType, cautils.SecurityViewType, cautils.ResourceViewType))
scanCmd.PersistentFlags().StringVar(&scanInfo.View, "view", string(cautils.SecurityViewType), fmt.Sprintf("View results based on the %s/%s/%s. default is --view=%s", cautils.ResourceViewType, cautils.ControlViewType, cautils.SecurityViewType, cautils.SecurityViewType))
scanCmd.PersistentFlags().BoolVar(&scanInfo.UseDefault, "use-default", false, "Load local policy object from default path. If not used will download latest")
scanCmd.PersistentFlags().StringSliceVar(&scanInfo.UseFrom, "use-from", nil, "Load local policy object from specified path. If not used will download latest")
scanCmd.PersistentFlags().StringVar(&scanInfo.HostSensorYamlPath, "host-scan-yaml", "", "Override default host scanner DaemonSet. Use this flag cautiously")
@@ -82,18 +90,18 @@ func GetScanCommand(ks meta.IKubescape) *cobra.Command {
scanCmd.PersistentFlags().BoolVarP(&scanInfo.Submit, "submit", "", false, "Submit the scan results to Kubescape SaaS where you can see the results in a user-friendly UI, choose your preferred compliance framework, check risk results history and trends, manage exceptions, get remediation recommendations and much more. By default the results are not submitted")
scanCmd.PersistentFlags().BoolVarP(&scanInfo.OmitRawResources, "omit-raw-resources", "", false, "Omit raw resources from the output. By default the raw resources are included in the output")
scanCmd.PersistentFlags().BoolVarP(&scanInfo.PrintAttackTree, "print-attack-tree", "", false, "Print attack tree")
scanCmd.PersistentFlags().BoolVarP(&scanInfo.EnableRegoPrint, "enable-rego-prints", "", false, "Enable sending to rego prints to the logs (use with debug log level: -l debug)")
scanCmd.PersistentFlags().BoolVarP(&scanInfo.ScanImages, "scan-images", "", false, "Scan resources images")
scanCmd.PersistentFlags().BoolVarP(&scanInfo.UseDefaultMatchers, "use-default-matchers", "", true, "Use default matchers (true) or CPE matchers (false) for image scanning")
scanCmd.PersistentFlags().StringSliceVar(&scanInfo.LabelsToCopy, "labels-to-copy", nil, "Labels to copy from workloads to scan reports for easy identification. e.g: --labels-to-copy=app,team,environment")
scanCmd.PersistentFlags().MarkDeprecated("silent", "use '--logger' flag instead. Flag will be removed at 1.May.2022")
scanCmd.PersistentFlags().MarkDeprecated("fail-threshold", "use '--compliance-threshold' flag instead. Flag will be removed at 1.Dec.2023")
scanCmd.PersistentFlags().MarkDeprecated("client-id", "Client ID is no longer supported. Feel free to contact the Kubescape maintainers for more information.")
scanCmd.PersistentFlags().MarkDeprecated("create-account", "Create account is no longer supported. In case of a missing Account ID and a configured backend server, a new account id will be generated automatically by Kubescape. Feel free to contact the Kubescape maintainers for more information.")
scanCmd.PersistentFlags().MarkDeprecated("secret-key", "Secret Key is no longer supported. Feel free to contact the Kubescape maintainers for more information.")
// hidden flags
scanCmd.PersistentFlags().MarkHidden("omit-raw-resources")
scanCmd.PersistentFlags().MarkHidden("print-attack-tree")
scanCmd.PersistentFlags().MarkHidden("format-version")
// Retrieve --kubeconfig flag from https://github.com/kubernetes/kubectl/blob/master/pkg/cmd/cmd.go
scanCmd.PersistentFlags().AddGoFlag(flag.Lookup("kubeconfig"))
@@ -111,8 +119,7 @@ func GetScanCommand(ks meta.IKubescape) *cobra.Command {
scanCmd.AddCommand(getFrameworkCmd(ks, &scanInfo))
scanCmd.AddCommand(getWorkloadCmd(ks, &scanInfo))
isi := &imageScanInfo{}
scanCmd.AddCommand(getImageCmd(ks, &scanInfo, isi))
scanCmd.AddCommand(getImageCmd(ks, &scanInfo))
return scanCmd
}
@@ -121,22 +128,20 @@ func setSecurityViewScanInfo(args []string, scanInfo *cautils.ScanInfo) {
if len(args) > 0 {
scanInfo.SetScanType(cautils.ScanTypeRepo)
scanInfo.InputPatterns = args
scanInfo.SetPolicyIdentifiers([]string{"workloadscan", "allcontrols"}, v1.KindFramework)
} else {
scanInfo.SetScanType(cautils.ScanTypeCluster)
scanInfo.SetPolicyIdentifiers([]string{"clusterscan", "mitre", "nsa"}, v1.KindFramework)
}
scanInfo.SetPolicyIdentifiers([]string{"clusterscan", "mitre", "nsa"}, v1.KindFramework)
}
func securityScan(scanInfo cautils.ScanInfo, ks meta.IKubescape) error {
ctx := context.TODO()
results, err := ks.Scan(ctx, &scanInfo)
results, err := ks.Scan(&scanInfo)
if err != nil {
return err
}
if err = results.HandleResults(ctx); err != nil {
if err = results.HandleResults(ks.Context(), &scanInfo); err != nil {
return err
}

View File

@@ -2,17 +2,19 @@ package scan
import (
"context"
"github.com/kubescape/go-logger/helpers"
"github.com/kubescape/kubescape/v2/core/cautils"
v1 "github.com/kubescape/opa-utils/httpserver/apis/v1"
"github.com/kubescape/opa-utils/reporthandling/apis"
"github.com/kubescape/opa-utils/reporthandling/results/v1/reportsummary"
"os"
"reflect"
"testing"
"time"
"github.com/kubescape/go-logger/helpers"
"github.com/kubescape/kubescape/v3/cmd/shared"
"github.com/kubescape/kubescape/v3/core/cautils"
"github.com/kubescape/kubescape/v3/core/mocks"
v1 "github.com/kubescape/opa-utils/httpserver/apis/v1"
"github.com/kubescape/opa-utils/reporthandling/apis"
"github.com/kubescape/opa-utils/reporthandling/results/v1/reportsummary"
"github.com/stretchr/testify/assert"
)
func TestExceedsSeverity(t *testing.T) {
@@ -112,7 +114,7 @@ func TestExceedsSeverity(t *testing.T) {
ScanInfo: &cautils.ScanInfo{FailThresholdSeverity: "unknown"},
SeverityCounters: &reportsummary.SeverityCounters{LowSeverityCounter: 1},
Want: false,
Error: ErrUnknownSeverity,
Error: shared.ErrUnknownSeverity,
},
}
@@ -185,20 +187,23 @@ type spyLogger struct {
setItems []spyLogMessage
}
func (l *spyLogger) Error(msg string, details ...helpers.IDetails) {}
func (l *spyLogger) Success(msg string, details ...helpers.IDetails) {}
func (l *spyLogger) Warning(msg string, details ...helpers.IDetails) {}
func (l *spyLogger) Info(msg string, details ...helpers.IDetails) {}
func (l *spyLogger) Debug(msg string, details ...helpers.IDetails) {}
func (l *spyLogger) SetLevel(level string) error { return nil }
func (l *spyLogger) GetLevel() string { return "" }
func (l *spyLogger) SetWriter(w *os.File) {}
func (l *spyLogger) GetWriter() *os.File { return &os.File{} }
func (l *spyLogger) LoggerName() string { return "" }
func (l *spyLogger) Ctx(_ context.Context) helpers.ILogger { return l }
func (l *spyLogger) Start(msg string, details ...helpers.IDetails) {}
func (l *spyLogger) StopSuccess(msg string, details ...helpers.IDetails) {}
func (l *spyLogger) StopError(msg string, details ...helpers.IDetails) {}
var _ helpers.ILogger = &spyLogger{}
func (l *spyLogger) Error(msg string, details ...helpers.IDetails) {}
func (l *spyLogger) Success(msg string, details ...helpers.IDetails) {}
func (l *spyLogger) Warning(msg string, details ...helpers.IDetails) {}
func (l *spyLogger) Info(msg string, details ...helpers.IDetails) {}
func (l *spyLogger) Debug(msg string, details ...helpers.IDetails) {}
func (l *spyLogger) SetLevel(level string) error { return nil }
func (l *spyLogger) GetLevel() string { return "" }
func (l *spyLogger) SetWriter(w *os.File) {}
func (l *spyLogger) GetWriter() *os.File { return &os.File{} }
func (l *spyLogger) LoggerName() string { return "" }
func (l *spyLogger) Ctx(_ context.Context) helpers.ILogger { return l }
func (l *spyLogger) Start(msg string, details ...helpers.IDetails) {}
func (l *spyLogger) StopSuccess(msg string, details ...helpers.IDetails) {}
func (l *spyLogger) StopError(msg string, details ...helpers.IDetails) {}
func (l *spyLogger) TimedWrapper(funcName string, timeout time.Duration, task func()) {}
func (l *spyLogger) Fatal(msg string, details ...helpers.IDetails) {
firstDetail := details[0]
@@ -213,7 +218,7 @@ func (l *spyLogger) GetSpiedItems() []spyLogMessage {
}
func Test_terminateOnExceedingSeverity(t *testing.T) {
expectedMessage := "result exceeds severity threshold"
expectedMessage := "compliance result exceeds severity threshold"
expectedKey := "set severity threshold"
testCases := []struct {
@@ -302,15 +307,11 @@ func TestSetSecurityViewScanInfo(t *testing.T) {
PolicyIdentifier: []cautils.PolicyIdentifier{
{
Kind: v1.KindFramework,
Identifier: "clusterscan",
Identifier: "workloadscan",
},
{
Kind: v1.KindFramework,
Identifier: "mitre",
},
{
Kind: v1.KindFramework,
Identifier: "nsa",
Identifier: "allcontrols",
},
},
},
@@ -361,3 +362,16 @@ func TestSetSecurityViewScanInfo(t *testing.T) {
}
}
func TestGetScanCommand(t *testing.T) {
// Create a mock Kubescape interface
mockKubescape := &mocks.MockIKubescape{}
cmd := GetScanCommand(mockKubescape)
// Verify the command name and short description
assert.Equal(t, "scan", cmd.Use)
assert.Equal(t, "Scan a Kubernetes cluster or YAML files for image vulnerabilities and misconfigurations", cmd.Short)
assert.Equal(t, "The action you want to perform", cmd.Long)
assert.Equal(t, scanCmdExamples, cmd.Example)
}

View File

@@ -3,7 +3,8 @@ package scan
import (
"testing"
"github.com/kubescape/kubescape/v2/core/cautils"
"github.com/kubescape/kubescape/v3/cmd/shared"
"github.com/kubescape/kubescape/v3/core/cautils"
)
// Test_validateControlScanInfo tests how scan info is validated for the `scan control` command
@@ -26,7 +27,7 @@ func Test_validateControlScanInfo(t *testing.T) {
{
"Unknown severity should be invalid for scan info",
&cautils.ScanInfo{FailThresholdSeverity: "Unknown"},
ErrUnknownSeverity,
shared.ErrUnknownSeverity,
},
}
@@ -34,7 +35,7 @@ func Test_validateControlScanInfo(t *testing.T) {
t.Run(
tc.Description,
func(t *testing.T) {
var want error = tc.Want
var want = tc.Want
got := validateControlScanInfo(tc.ScanInfo)
@@ -66,12 +67,12 @@ func Test_validateFrameworkScanInfo(t *testing.T) {
{
"Unknown severity should be invalid for scan info",
&cautils.ScanInfo{FailThresholdSeverity: "Unknown"},
ErrUnknownSeverity,
shared.ErrUnknownSeverity,
},
{
"Security view should be invalid for scan info",
&cautils.ScanInfo{View: string(cautils.SecurityViewType)},
ErrSecurityViewNotSupported,
nil,
},
{
"Empty view should be valid for scan info",
@@ -84,7 +85,7 @@ func Test_validateFrameworkScanInfo(t *testing.T) {
t.Run(
tc.Description,
func(t *testing.T) {
var want error = tc.Want
var want = tc.Want
got := validateFrameworkScanInfo(tc.ScanInfo)
@@ -96,35 +97,6 @@ func Test_validateFrameworkScanInfo(t *testing.T) {
}
}
func Test_validateSeverity(t *testing.T) {
testCases := []struct {
Description string
Input string
Want error
}{
{"low should be a valid severity", "low", nil},
{"Low should be a valid severity", "Low", nil},
{"medium should be a valid severity", "medium", nil},
{"Medium should be a valid severity", "Medium", nil},
{"high should be a valid severity", "high", nil},
{"Critical should be a valid severity", "Critical", nil},
{"critical should be a valid severity", "critical", nil},
{"Unknown should be an invalid severity", "Unknown", ErrUnknownSeverity},
}
for _, testCase := range testCases {
t.Run(testCase.Description, func(t *testing.T) {
input := testCase.Input
want := testCase.Want
got := validateSeverity(input)
if got != want {
t.Errorf("got: %v, want: %v", got, want)
}
})
}
}
func Test_validateWorkloadIdentifier(t *testing.T) {
testCases := []struct {
Description string

View File

@@ -1,24 +1,20 @@
package scan
import (
"context"
"errors"
"fmt"
"strings"
logger "github.com/kubescape/go-logger"
"github.com/kubescape/kubescape/v2/core/cautils"
"github.com/kubescape/kubescape/v2/core/meta"
"github.com/kubescape/go-logger"
"github.com/kubescape/kubescape/v3/core/cautils"
"github.com/kubescape/kubescape/v3/core/meta"
v1 "github.com/kubescape/opa-utils/httpserver/apis/v1"
"github.com/kubescape/opa-utils/objectsenvelopes"
"github.com/spf13/cobra"
)
var (
workloadExample = fmt.Sprintf(`
This command is still in BETA. Feel free to contact the Kubescape maintainers for more information.
Scan a workload for misconfigurations and image vulnerabilities.
# Scan an workload
@@ -52,6 +48,7 @@ func getWorkloadCmd(ks meta.IKubescape, scanInfo *cautils.ScanInfo) *cobra.Comma
return fmt.Errorf("usage: <kind>/<name> [`<glob pattern>`/`-`] [flags]")
}
// Looks strange, a bug maybe????
if scanInfo.ChartPath != "" && scanInfo.FilePath == "" {
return fmt.Errorf("usage: --chart-path <chart path> --file-path <file path>")
}
@@ -68,16 +65,17 @@ func getWorkloadCmd(ks meta.IKubescape, scanInfo *cautils.ScanInfo) *cobra.Comma
setWorkloadScanInfo(scanInfo, kind, name)
// todo: add api version if provided
ctx := context.TODO()
results, err := ks.Scan(ctx, scanInfo)
results, err := ks.Scan(scanInfo)
if err != nil {
logger.L().Fatal(err.Error())
}
if err = results.HandleResults(ctx); err != nil {
if err = results.HandleResults(ks.Context(), scanInfo); err != nil {
logger.L().Fatal(err.Error())
}
enforceSeverityThresholds(results.GetData().Report.SummaryDetails.GetResourcesSeverityCounters(), scanInfo, terminateOnExceedingSeverity)
return nil
},
}
@@ -97,7 +95,7 @@ func setWorkloadScanInfo(scanInfo *cautils.ScanInfo, kind string, name string) {
scanInfo.ScanObject.SetKind(kind)
scanInfo.ScanObject.SetName(name)
scanInfo.SetPolicyIdentifiers([]string{"workloadscan"}, v1.KindFramework)
scanInfo.SetPolicyIdentifiers([]string{"workloadscan", "allcontrols"}, v1.KindFramework)
if scanInfo.FilePath != "" {
scanInfo.InputPatterns = []string{scanInfo.FilePath}

View File

@@ -3,9 +3,12 @@ package scan
import (
"testing"
"github.com/kubescape/kubescape/v2/core/cautils"
"github.com/kubescape/kubescape/v3/core/cautils"
"github.com/kubescape/kubescape/v3/core/mocks"
v1 "github.com/kubescape/opa-utils/httpserver/apis/v1"
"github.com/kubescape/opa-utils/objectsenvelopes"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
)
func TestSetWorkloadScanInfo(t *testing.T) {
@@ -25,6 +28,10 @@ func TestSetWorkloadScanInfo(t *testing.T) {
Identifier: "workloadscan",
Kind: v1.KindFramework,
},
{
Identifier: "allcontrols",
Kind: v1.KindFramework,
},
},
ScanType: cautils.ScanTypeWorkload,
ScanObject: &objectsenvelopes.ScanObject{
@@ -56,14 +63,59 @@ func TestSetWorkloadScanInfo(t *testing.T) {
t.Errorf("got: %v, want: %v", scanInfo.ScanObject.Metadata.Name, tc.want.ScanObject.Metadata.Name)
}
if len(scanInfo.PolicyIdentifier) != 1 {
t.Errorf("got: %v, want: %v", len(scanInfo.PolicyIdentifier), 1)
if len(scanInfo.PolicyIdentifier) != len(tc.want.PolicyIdentifier) {
t.Errorf("got: %v policy identifiers, want: %v", len(scanInfo.PolicyIdentifier), len(tc.want.PolicyIdentifier))
}
if scanInfo.PolicyIdentifier[0].Identifier != tc.want.PolicyIdentifier[0].Identifier {
t.Errorf("got: %v, want: %v", scanInfo.PolicyIdentifier[0].Identifier, tc.want.PolicyIdentifier[0].Identifier)
for i, wantPolicy := range tc.want.PolicyIdentifier {
if i < len(scanInfo.PolicyIdentifier) {
if scanInfo.PolicyIdentifier[i].Identifier != wantPolicy.Identifier {
t.Errorf("got: %v, want: %v", scanInfo.PolicyIdentifier[i].Identifier, wantPolicy.Identifier)
}
if scanInfo.PolicyIdentifier[i].Kind != wantPolicy.Kind {
t.Errorf("got: %v, want: %v", scanInfo.PolicyIdentifier[i].Kind, wantPolicy.Kind)
}
}
}
},
)
}
}
func TestGetWorkloadCmd_ChartPathAndFilePathEmpty(t *testing.T) {
// Create a mock Kubescape interface
mockKubescape := &mocks.MockIKubescape{}
scanInfo := cautils.ScanInfo{
ChartPath: "temp",
FilePath: "",
}
cmd := getWorkloadCmd(mockKubescape, &scanInfo)
// Verify the command name and short description
assert.Equal(t, "workload <kind>/<name> [`<glob pattern>`/`-`] [flags]", cmd.Use)
assert.Equal(t, "Scan a workload for misconfigurations and image vulnerabilities", cmd.Short)
assert.Equal(t, workloadExample, cmd.Example)
err := cmd.Args(&cobra.Command{}, []string{})
expectedErrorMessage := "usage: <kind>/<name> [`<glob pattern>`/`-`] [flags]"
assert.Equal(t, expectedErrorMessage, err.Error())
err = cmd.Args(&cobra.Command{}, []string{"nginx"})
expectedErrorMessage = "invalid workload identifier"
assert.Equal(t, expectedErrorMessage, err.Error())
}
func Test_parseWorkloadIdentifierString_Empty(t *testing.T) {
t.Run("empty identifier", func(t *testing.T) {
_, _, err := parseWorkloadIdentifierString("")
assert.Error(t, err)
})
}
func Test_parseWorkloadIdentifierString_NoError(t *testing.T) {
t.Run("valid identifier", func(t *testing.T) {
_, _, err := parseWorkloadIdentifierString("default/Deployment")
assert.NoError(t, err)
})
}

18
cmd/shared/image_scan.go Normal file
View File

@@ -0,0 +1,18 @@
package shared
import "github.com/kubescape/kubescape/v3/core/cautils"
type ImageCredentials struct {
Username string
Password string
}
// ValidateImageScanInfo validates the ScanInfo struct for image scanning commands
func ValidateImageScanInfo(scanInfo *cautils.ScanInfo) error {
severity := scanInfo.FailThresholdSeverity
if err := ValidateSeverity(severity); severity != "" && err != nil {
return err
}
return nil
}

View File

@@ -0,0 +1,61 @@
package shared
import (
"testing"
"github.com/kubescape/kubescape/v3/core/cautils"
"github.com/stretchr/testify/assert"
)
// Validate a scanInfo struct with a valid fail threshold severity
func TestValidateImageScanInfo(t *testing.T) {
testCases := []struct {
Description string
ScanInfo *cautils.ScanInfo
Want error
}{
{
"Empty scanInfo is valid",
&cautils.ScanInfo{},
nil,
},
{
"Empty severity is valid",
&cautils.ScanInfo{FailThresholdSeverity: ""},
nil,
},
{
"High severity is valid",
&cautils.ScanInfo{FailThresholdSeverity: "High"},
nil,
},
{
"HIGH severity is valid",
&cautils.ScanInfo{FailThresholdSeverity: "HIGH"},
nil,
},
{
"high severity is valid",
&cautils.ScanInfo{FailThresholdSeverity: "high"},
nil,
},
{
"Unknown severity is invalid",
&cautils.ScanInfo{FailThresholdSeverity: "unknown"},
ErrUnknownSeverity,
},
}
for _, tc := range testCases {
t.Run(
tc.Description,
func(t *testing.T) {
var want = tc.Want
got := ValidateImageScanInfo(tc.ScanInfo)
assert.Equal(t, want, got)
},
)
}
}

28
cmd/shared/scan.go Normal file
View File

@@ -0,0 +1,28 @@
package shared
import (
"fmt"
"strings"
"github.com/kubescape/go-logger/helpers"
"github.com/kubescape/kubescape/v3/core/cautils"
reporthandlingapis "github.com/kubescape/opa-utils/reporthandling/apis"
)
var ErrUnknownSeverity = fmt.Errorf("unknown severity. Supported severities are: %s", strings.Join(reporthandlingapis.GetSupportedSeverities(), ", "))
// ValidateSeverity returns an error if a given severity is not known, nil otherwise
func ValidateSeverity(severity string) error {
for _, val := range reporthandlingapis.GetSupportedSeverities() {
if strings.EqualFold(severity, val) {
return nil
}
}
return ErrUnknownSeverity
}
// TerminateOnExceedingSeverity terminates the program if the result exceeds the severity threshold
func TerminateOnExceedingSeverity(scanInfo *cautils.ScanInfo, l helpers.ILogger) {
l.Fatal("result exceeds severity threshold", helpers.String("Set severity threshold", scanInfo.FailThresholdSeverity))
}

128
cmd/shared/scan_test.go Normal file
View File

@@ -0,0 +1,128 @@
package shared
import (
"context"
"os"
"reflect"
"testing"
"time"
"github.com/kubescape/go-logger/helpers"
"github.com/kubescape/kubescape/v3/core/cautils"
"github.com/kubescape/opa-utils/reporthandling/apis"
)
type spyLogMessage struct {
Message string
Details map[string]string
}
type spyLogger struct {
setItems []spyLogMessage
}
var _ helpers.ILogger = &spyLogger{}
func (l *spyLogger) Error(msg string, details ...helpers.IDetails) {}
func (l *spyLogger) Success(msg string, details ...helpers.IDetails) {}
func (l *spyLogger) Warning(msg string, details ...helpers.IDetails) {}
func (l *spyLogger) Info(msg string, details ...helpers.IDetails) {}
func (l *spyLogger) Debug(msg string, details ...helpers.IDetails) {}
func (l *spyLogger) SetLevel(level string) error { return nil }
func (l *spyLogger) GetLevel() string { return "" }
func (l *spyLogger) SetWriter(w *os.File) {}
func (l *spyLogger) GetWriter() *os.File { return &os.File{} }
func (l *spyLogger) LoggerName() string { return "" }
func (l *spyLogger) Ctx(_ context.Context) helpers.ILogger { return l }
func (l *spyLogger) Start(msg string, details ...helpers.IDetails) {}
func (l *spyLogger) StopSuccess(msg string, details ...helpers.IDetails) {}
func (l *spyLogger) StopError(msg string, details ...helpers.IDetails) {}
func (l *spyLogger) TimedWrapper(funcName string, timeout time.Duration, task func()) {}
func (l *spyLogger) Fatal(msg string, details ...helpers.IDetails) {
firstDetail := details[0]
detailsMap := map[string]string{firstDetail.Key(): firstDetail.Value().(string)}
newMsg := spyLogMessage{msg, detailsMap}
l.setItems = append(l.setItems, newMsg)
}
func (l *spyLogger) GetSpiedItems() []spyLogMessage {
return l.setItems
}
func TestTerminateOnExceedingSeverity(t *testing.T) {
expectedMessage := "result exceeds severity threshold"
expectedKey := "Set severity threshold"
testCases := []struct {
Description string
ExpectedMessage string
ExpectedKey string
ExpectedValue string
Logger *spyLogger
}{
{
"Should log the Critical threshold that was set in scan info",
expectedMessage,
expectedKey,
apis.SeverityCriticalString,
&spyLogger{},
},
{
"Should log the High threshold that was set in scan info",
expectedMessage,
expectedKey,
apis.SeverityHighString,
&spyLogger{},
},
}
for _, tc := range testCases {
t.Run(
tc.Description,
func(t *testing.T) {
want := []spyLogMessage{
{tc.ExpectedMessage, map[string]string{tc.ExpectedKey: tc.ExpectedValue}},
}
scanInfo := &cautils.ScanInfo{FailThresholdSeverity: tc.ExpectedValue}
TerminateOnExceedingSeverity(scanInfo, tc.Logger)
got := tc.Logger.GetSpiedItems()
if !reflect.DeepEqual(got, want) {
t.Errorf("got: %v, want: %v", got, want)
}
},
)
}
}
func TestValidateSeverity(t *testing.T) {
testCases := []struct {
Description string
Input string
Want error
}{
{"low should be a valid severity", "low", nil},
{"Low should be a valid severity", "Low", nil},
{"medium should be a valid severity", "medium", nil},
{"Medium should be a valid severity", "Medium", nil},
{"high should be a valid severity", "high", nil},
{"Critical should be a valid severity", "Critical", nil},
{"critical should be a valid severity", "critical", nil},
{"Unknown should be an invalid severity", "Unknown", ErrUnknownSeverity},
}
for _, testCase := range testCases {
t.Run(testCase.Description, func(t *testing.T) {
input := testCase.Input
want := testCase.Want
got := ValidateSeverity(input)
if got != want {
t.Errorf("got: %v, want: %v", got, want)
}
})
}
}

View File

@@ -6,15 +6,19 @@ package update
import (
"fmt"
"strings"
logger "github.com/kubescape/go-logger"
"github.com/kubescape/kubescape/v3/core/meta"
"github.com/kubescape/backend/pkg/versioncheck"
"github.com/kubescape/go-logger"
"github.com/kubescape/go-logger/helpers"
"github.com/kubescape/kubescape/v2/core/cautils"
"github.com/kubescape/kubescape/v3/core/cautils"
"github.com/spf13/cobra"
)
const (
installationLink string = "https://github.com/kubescape/kubescape/blob/master/docs/installation.md"
installationLink string = "https://kubescape.io/docs/install-cli/"
)
var updateCmdExamples = fmt.Sprintf(`
@@ -22,19 +26,31 @@ var updateCmdExamples = fmt.Sprintf(`
%[1]s update
`, cautils.ExecName())
func GetUpdateCmd() *cobra.Command {
func GetUpdateCmd(ks meta.IKubescape) *cobra.Command {
updateCmd := &cobra.Command{
Use: "update",
Short: "Update to latest release version",
Long: ``,
Example: updateCmdExamples,
RunE: func(_ *cobra.Command, args []string) error {
v := versioncheck.NewVersionCheckHandler()
versionCheckRequest := versioncheck.NewVersionCheckRequest("", versioncheck.BuildNumber, "", "", "update", nil)
if err := v.CheckLatestVersion(ks.Context(), versionCheckRequest); err != nil {
return err
}
//Checking the user's version of kubescape to the latest release
if cautils.BuildNumber == cautils.LatestReleaseVersion {
if versioncheck.BuildNumber == "" || strings.Contains(versioncheck.BuildNumber, "rc") {
//your version is unknown
fmt.Printf("Nothing to update: you are running the development version\n")
} else if versioncheck.LatestReleaseVersion == "" {
//Failed to check for updates
logger.L().Info("Failed to check for updates")
} else if versioncheck.BuildNumber == versioncheck.LatestReleaseVersion {
//your version == latest version
logger.L().Info(("Nothing to update, you are running the latest version"), helpers.String("Version", cautils.BuildNumber))
logger.L().Info("Nothing to update: you are running the latest version", helpers.String("Version", versioncheck.BuildNumber))
} else {
fmt.Printf("Please refer to our installation docs in the following link: %s\n", installationLink)
fmt.Printf("Version %s is available. Please refer to our installation documentation: %s\n", versioncheck.LatestReleaseVersion, installationLink)
}
return nil
},

18
cmd/update/update_test.go Normal file
View File

@@ -0,0 +1,18 @@
package update
import (
"context"
"testing"
"github.com/kubescape/kubescape/v3/core/core"
"github.com/stretchr/testify/assert"
)
func TestGetUpdateCmd(t *testing.T) {
ks := core.NewKubescape(context.TODO())
cmd := GetUpdateCmd(ks)
assert.NotNil(t, cmd)
err := cmd.RunE(cmd, []string{})
assert.Nil(t, err)
}

237
cmd/vap/vap.go Normal file
View File

@@ -0,0 +1,237 @@
package vap
import (
"errors"
"fmt"
"io"
"net/http"
"regexp"
"github.com/kubescape/go-logger"
"github.com/kubescape/kubescape/v3/core/cautils"
"github.com/spf13/cobra"
admissionv1 "k8s.io/api/admissionregistration/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/yaml"
)
var vapHelperCmdExamples = fmt.Sprintf(`
vap command can be used for managing Validating Admission Policies in a Kubernetes cluster.
This is an experimental feature and it might change.
Examples:
# Install Kubescape CEL admission policy library
%[1]s vap deploy-library | kubectl apply -f -
# Create a policy binding
%[1]s vap create-policy-binding --name my-policy-binding --policy c-0016 --namespace=my-namespace | kubectl apply -f -
`, cautils.ExecName())
func GetVapHelperCmd() *cobra.Command {
vapHelperCmd := &cobra.Command{
Use: "vap",
Short: "Helper commands for managing Validating Admission Policies in a Kubernetes cluster",
Long: ``,
Example: vapHelperCmdExamples,
}
// Create subcommands
vapHelperCmd.AddCommand(getDeployLibraryCmd())
vapHelperCmd.AddCommand(getCreatePolicyBindingCmd())
return vapHelperCmd
}
func getDeployLibraryCmd() *cobra.Command {
return &cobra.Command{
Use: "deploy-library",
Short: "Install Kubescape CEL admission policy library",
Long: ``,
RunE: func(cmd *cobra.Command, args []string) error {
return deployLibrary()
},
}
}
func getCreatePolicyBindingCmd() *cobra.Command {
var policyBindingName string
var policyName string
var namespaceArr []string
var labelArr []string
var action string
var parameterReference string
createPolicyBindingCmd := &cobra.Command{
Use: "create-policy-binding",
Short: "Create a policy binding",
Long: ``,
RunE: func(cmd *cobra.Command, args []string) error {
// Validate the inputs
if err := isValidK8sObjectName(policyBindingName); err != nil {
return fmt.Errorf("invalid policy binding name %s: %w", policyBindingName, err)
}
if err := isValidK8sObjectName(policyName); err != nil {
return fmt.Errorf("invalid policy name %s: %w", policyName, err)
}
for _, namespace := range namespaceArr {
if err := isValidK8sObjectName(namespace); err != nil {
return fmt.Errorf("invalid namespace %s: %w", namespace, err)
}
}
for _, label := range labelArr {
// Label selector must be in the format key=value
if !regexp.MustCompile(`^[a-zA-Z0-9]+=[a-zA-Z0-9]+$`).MatchString(label) {
return fmt.Errorf("invalid label selector: %s", label)
}
}
if action != "Deny" && action != "Audit" && action != "Warn" {
return fmt.Errorf("invalid action: %s", action)
}
if parameterReference != "" {
if err := isValidK8sObjectName(parameterReference); err != nil {
return fmt.Errorf("invalid parameter reference %s: %w", parameterReference, err)
}
}
return createPolicyBinding(policyBindingName, policyName, action, parameterReference, namespaceArr, labelArr)
},
}
// Must specify the name of the policy binding
createPolicyBindingCmd.Flags().StringVarP(&policyBindingName, "name", "n", "", "Name of the policy binding")
createPolicyBindingCmd.MarkFlagRequired("name")
createPolicyBindingCmd.Flags().StringVarP(&policyName, "policy", "p", "", "Name of the policy to bind the resources to")
createPolicyBindingCmd.MarkFlagRequired("policy")
createPolicyBindingCmd.Flags().StringSliceVar(&namespaceArr, "namespace", []string{}, "Resource namespace selector")
createPolicyBindingCmd.Flags().StringSliceVar(&labelArr, "label", []string{}, "Resource label selector")
createPolicyBindingCmd.Flags().StringVarP(&action, "action", "a", "Deny", "Action to take when policy fails")
createPolicyBindingCmd.Flags().StringVarP(&parameterReference, "parameter-reference", "r", "", "Parameter reference object name")
return createPolicyBindingCmd
}
// Implementation of the VAP helper commands
// deploy-library
func deployLibrary() error {
logger.L().Info("Downloading the Kubescape CEL admission policy library")
// Download the policy-configuration-definition.yaml from the latest release URL
policyConfigurationDefinitionURL := "https://github.com/kubescape/cel-admission-library/releases/latest/download/policy-configuration-definition.yaml"
policyConfigurationDefinition, err := downloadFileToString(policyConfigurationDefinitionURL)
if err != nil {
return err
}
// Download the basic-control-configuration.yaml from the latest release URL
basicControlConfigurationURL := "https://github.com/kubescape/cel-admission-library/releases/latest/download/basic-control-configuration.yaml"
basicControlConfiguration, err := downloadFileToString(basicControlConfigurationURL)
if err != nil {
return err
}
// Download the kubescape-validating-admission-policies.yaml from the latest release URL
kubescapeValidatingAdmissionPoliciesURL := "https://github.com/kubescape/cel-admission-library/releases/latest/download/kubescape-validating-admission-policies.yaml"
kubescapeValidatingAdmissionPolicies, err := downloadFileToString(kubescapeValidatingAdmissionPoliciesURL)
if err != nil {
return err
}
logger.L().Info("Successfully downloaded admission policy library")
// Print the downloaded files to the STDOUT for the user to apply connecting them to a single YAML with ---
fmt.Println(policyConfigurationDefinition)
fmt.Println("---")
fmt.Println(basicControlConfiguration)
fmt.Println("---")
fmt.Println(kubescapeValidatingAdmissionPolicies)
return nil
}
func downloadFileToString(url string) (string, error) {
// Send an HTTP GET request to the URL
response, err := http.Get(url) //nolint:gosec
if err != nil {
return "", err // Return an empty string and the error if the request fails
}
defer response.Body.Close()
// Check for a successful response (HTTP 200 OK)
if response.StatusCode != http.StatusOK {
return "", fmt.Errorf("failed to download file: %s", response.Status)
}
// Read the response body
bodyBytes, err := io.ReadAll(response.Body)
if err != nil {
return "", err // Return an empty string and the error if reading fails
}
// Convert the byte slice to a string
bodyString := string(bodyBytes)
return bodyString, nil
}
func isValidK8sObjectName(name string) error {
// Kubernetes object names must consist of lower case alphanumeric characters, '-' or '.',
// and must start and end with an alphanumeric character (e.g., 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?')
// Max length of 63 characters.
if len(name) > 63 {
return errors.New("name should be less than 63 characters")
}
regex := regexp.MustCompile(`^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`)
if !regex.MatchString(name) {
return errors.New("name should consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character")
}
return nil
}
// Create a policy binding
func createPolicyBinding(bindingName string, policyName string, action string, paramRefName string, namespaceArr []string, labelMatch []string) error {
// Create a policy binding struct
policyBinding := &admissionv1.ValidatingAdmissionPolicyBinding{}
// Print the policy binding after marshalling it to YAML to the STDOUT
// The user can apply the output to the cluster
policyBinding.APIVersion = "admissionregistration.k8s.io/v1"
policyBinding.Name = bindingName
policyBinding.Kind = "ValidatingAdmissionPolicyBinding"
policyBinding.Spec.PolicyName = policyName
policyBinding.Spec.MatchResources = &admissionv1.MatchResources{}
if len(namespaceArr) > 0 {
policyBinding.Spec.MatchResources.NamespaceSelector = &metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{
{
Key: "kubernetes.io/metadata.name",
Operator: metav1.LabelSelectorOpIn,
Values: namespaceArr,
},
},
}
}
if len(labelMatch) > 0 {
policyBinding.Spec.MatchResources.ObjectSelector = &metav1.LabelSelector{}
policyBinding.Spec.MatchResources.ObjectSelector.MatchLabels = make(map[string]string)
for _, label := range labelMatch {
labelParts := regexp.MustCompile(`=`).Split(label, 2)
policyBinding.Spec.MatchResources.ObjectSelector.MatchLabels[labelParts[0]] = labelParts[1]
}
}
policyBinding.Spec.ValidationActions = []admissionv1.ValidationAction{admissionv1.ValidationAction(action)}
paramAction := admissionv1.DenyAction
if paramRefName != "" {
policyBinding.Spec.ParamRef = &admissionv1.ParamRef{
Name: paramRefName,
ParameterNotFoundAction: &paramAction,
}
}
// Marshal the policy binding to YAML
out, err := yaml.Marshal(policyBinding)
if err != nil {
return err
}
fmt.Println(string(out))
return nil
}

10
cmd/vap/vap_test.go Normal file
View File

@@ -0,0 +1,10 @@
package vap
import (
"testing"
)
func TestGetVapHelperCmd(t *testing.T) {
// Call the GetFixCmd function
_ = GetVapHelperCmd()
}

View File

@@ -1,7 +0,0 @@
//go:build !gitenabled
package version
func isGitEnabled() bool {
return false
}

View File

@@ -1,7 +0,0 @@
//go:build gitenabled
package version
func isGitEnabled() bool {
return true
}

View File

@@ -1,31 +1,37 @@
package version
import (
"context"
"fmt"
"os"
"github.com/kubescape/go-logger"
"github.com/kubescape/kubescape/v2/core/cautils"
"github.com/kubescape/kubescape/v3/core/meta"
"github.com/kubescape/backend/pkg/versioncheck"
"github.com/spf13/cobra"
)
func GetVersionCmd() *cobra.Command {
func GetVersionCmd(ks meta.IKubescape, version, commit, date string) *cobra.Command {
versionCmd := &cobra.Command{
Use: "version",
Short: "Get current version",
Long: ``,
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.TODO()
v := cautils.NewIVersionCheckHandler(ctx)
v.CheckLatestVersion(ctx, cautils.NewVersionCheckRequest(cautils.BuildNumber, "", "", "version"))
fmt.Fprintf(os.Stdout,
v := versioncheck.NewIVersionCheckHandler(ks.Context())
_ = v.CheckLatestVersion(ks.Context(), versioncheck.NewVersionCheckRequest("", version, "", "", "version", nil))
_, _ = fmt.Fprintf(cmd.OutOrStdout(),
"Your current version is: %s\n",
cautils.BuildNumber,
version,
)
_, _ = fmt.Fprintf(cmd.OutOrStdout(),
"Build commit: %s\n",
commit,
)
_, _ = fmt.Fprintf(cmd.OutOrStdout(),
"Build date: %s\n",
date,
)
logger.L().Debug(fmt.Sprintf("git enabled in build: %t", isGitEnabled()))
return nil
},
}
return versionCmd
}
}

View File

@@ -0,0 +1,49 @@
package version
import (
"bytes"
"context"
"io"
"testing"
"github.com/kubescape/kubescape/v3/core/core"
"github.com/kubescape/backend/pkg/versioncheck"
"github.com/stretchr/testify/assert"
)
func TestGetVersionCmd(t *testing.T) {
tests := []struct {
name string
buildNumber string
want string
}{
{
name: "Undefined Build Number",
buildNumber: "unknown",
want: "Your current version is: unknown\nBuild commit: \nBuild date: \n",
},
{
name: "Defined Build Number: v3.0.1",
buildNumber: "v3.0.1",
want: "Your current version is: v3.0.1\nBuild commit: \nBuild date: \n",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
versioncheck.BuildNumber = tt.buildNumber
ks := core.NewKubescape(context.TODO())
if cmd := GetVersionCmd(ks, tt.buildNumber, "", ""); cmd != nil {
buf := bytes.NewBufferString("")
cmd.SetOut(buf)
cmd.Execute()
out, err := io.ReadAll(buf)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, tt.want, string(out))
}
})
}
}

View File

@@ -1,14 +1,248 @@
# Kubescape core package
# Kubescape Core Package
The `core` package provides the main Kubescape scanning engine as a Go library, allowing you to integrate Kubescape security scanning directly into your applications.
## Table of Contents
- [Installation](#installation)
- [Quick Start](#quick-start)
- [API Reference](#api-reference)
- [Examples](#examples)
- [Configuration Options](#configuration-options)
---
## Installation
```bash
go get github.com/kubescape/kubescape/v3/core
```
---
## Quick Start
```go
package main
// initialize kubescape
ks := core.NewKubescape()
import (
"context"
"fmt"
"log"
// scan cluster
results, err := ks.Scan(&cautils.ScanInfo{})
"github.com/kubescape/kubescape/v3/core"
"github.com/kubescape/kubescape/v3/core/cautils"
)
// convert scan results to json
jsonRes, err := results.ToJson()
func main() {
ctx := context.Background()
```
// Initialize Kubescape
ks := core.NewKubescape(ctx)
// Configure scan
scanInfo := &cautils.ScanInfo{
// Scan the current cluster
ScanAll: true,
}
// Run scan
results, err := ks.Scan(scanInfo)
if err != nil {
log.Fatalf("Scan failed: %v", err)
}
// Convert results to JSON
jsonRes, err := results.ToJson()
if err != nil {
log.Fatalf("Failed to convert results: %v", err)
}
fmt.Println(string(jsonRes))
}
```
---
## API Reference
### Creating a Kubescape Instance
```go
// Create with context
ks := core.NewKubescape(ctx)
```
### Scanning
```go
// Scan with configuration
results, err := ks.Scan(scanInfo)
```
### Listing Frameworks and Controls
```go
// List available policies
err := ks.List(listPolicies)
```
### Downloading Artifacts
```go
// Download for offline use
err := ks.Download(downloadInfo)
```
### Image Scanning
```go
// Scan container image
exceedsSeverity, err := ks.ScanImage(imgScanInfo, scanInfo)
```
### Fixing Misconfigurations
```go
// Apply fixes to manifests
err := ks.Fix(fixInfo)
```
---
## Examples
### Scan a Specific Framework
```go
scanInfo := &cautils.ScanInfo{}
scanInfo.SetPolicyIdentifiers([]string{"nsa"}, "framework")
results, err := ks.Scan(scanInfo)
```
### Scan Specific Namespaces
```go
scanInfo := &cautils.ScanInfo{
IncludeNamespaces: "production,staging",
}
results, err := ks.Scan(scanInfo)
```
### Scan Local YAML Files
```go
scanInfo := &cautils.ScanInfo{
InputPatterns: []string{"/path/to/manifests"},
}
scanInfo.SetScanType(cautils.ScanTypeRepo)
results, err := ks.Scan(scanInfo)
```
### Export Results to Different Formats
```go
results, _ := ks.Scan(scanInfo)
// JSON
jsonData, _ := results.ToJson()
// Get summary
summary := results.GetData().Report.SummaryDetails
fmt.Printf("Compliance Score: %.2f%%\n", summary.ComplianceScore)
```
### Scan with Compliance Threshold
```go
scanInfo := &cautils.ScanInfo{
ComplianceThreshold: 80.0, // Fail if below 80%
}
results, err := ks.Scan(scanInfo)
if err != nil {
// Handle scan failure
}
// Check if threshold was exceeded
if results.GetData().Report.SummaryDetails.ComplianceScore < scanInfo.ComplianceThreshold {
log.Fatal("Compliance score below threshold")
}
```
---
## Configuration Options
### ScanInfo Fields
| Field | Type | Description |
|-------|------|-------------|
| `AccountID` | string | Kubescape SaaS account ID |
| `AccessKey` | string | Kubescape SaaS access key |
| `InputPatterns` | []string | Paths to scan (files, directories, URLs) |
| `ExcludedNamespaces` | string | Comma-separated namespaces to exclude |
| `IncludeNamespaces` | string | Comma-separated namespaces to include |
| `Format` | string | Output format (json, junit, sarif, etc.) |
| `Output` | string | Output file path |
| `VerboseMode` | bool | Show all resources in output |
| `FailThreshold` | float32 | Fail threshold percentage |
| `ComplianceThreshold` | float32 | Compliance threshold percentage |
| `UseExceptions` | string | Path to exceptions file |
| `UseArtifactsFrom` | string | Path to offline artifacts |
| `Submit` | bool | Submit results to SaaS |
| `Local` | bool | Keep results local (don't submit) |
---
## Error Handling
```go
results, err := ks.Scan(scanInfo)
if err != nil {
switch {
case errors.Is(err, context.DeadlineExceeded):
log.Fatal("Scan timed out")
case errors.Is(err, context.Canceled):
log.Fatal("Scan was canceled")
default:
log.Fatalf("Scan error: %v", err)
}
}
```
---
## Thread Safety
The Kubescape instance is safe for concurrent use. You can run multiple scans in parallel:
```go
var wg sync.WaitGroup
for _, ns := range namespaces {
wg.Add(1)
go func(namespace string) {
defer wg.Done()
scanInfo := &cautils.ScanInfo{
IncludeNamespaces: namespace,
}
results, _ := ks.Scan(scanInfo)
// Process results...
}(ns)
}
wg.Wait()
```
---
## Related Documentation
- [CLI Reference](../docs/cli-reference.md)
- [Getting Started Guide](../docs/getting-started.md)
- [Architecture](../docs/architecture.md)

View File

@@ -0,0 +1,53 @@
package cautils
import (
"testing"
)
// Returns a valid URL when given a valid control ID.
func TestGetControlLink_ValidControlID(t *testing.T) {
controlID := "cis-1.1.3"
expectedURL := "https://hub.armosec.io/docs/cis-1-1-3"
result := GetControlLink(controlID)
if result != expectedURL {
t.Errorf("Expected URL: %s, but got: %s", expectedURL, result)
}
}
// Replaces dots with hyphens in the control ID to generate the correct documentation link.
func TestGetControlLink_DotsInControlID(t *testing.T) {
controlID := "cis.1.1.3"
expectedURL := "https://hub.armosec.io/docs/cis-1-1-3"
result := GetControlLink(controlID)
if result != expectedURL {
t.Errorf("Expected URL: %s, but got: %s", expectedURL, result)
}
}
// Returns a lowercase URL.
func TestGetControlLink_LowercaseURL(t *testing.T) {
controlID := "CIS-1.1.3"
expectedURL := "https://hub.armosec.io/docs/cis-1-1-3"
result := GetControlLink(controlID)
if result != expectedURL {
t.Errorf("Expected URL: %s, but got: %s", expectedURL, result)
}
}
// Returns URL to armosec docs when given an empty control ID.
func TestGetControlLink_EmptyControlID(t *testing.T) {
controlID := ""
expectedURL := "https://hub.armosec.io/docs/"
result := GetControlLink(controlID)
if result != expectedURL {
t.Errorf("Expected URL: %s, but got: %s", expectedURL, result)
}
}

View File

@@ -7,33 +7,34 @@ import (
"path/filepath"
"regexp"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/google/uuid"
v1 "github.com/kubescape/backend/pkg/client/v1"
"github.com/kubescape/backend/pkg/servicediscovery"
servicediscoveryv1 "github.com/kubescape/backend/pkg/servicediscovery/v1"
logger "github.com/kubescape/go-logger"
servicediscoveryv2 "github.com/kubescape/backend/pkg/servicediscovery/v2"
"github.com/kubescape/go-logger"
"github.com/kubescape/go-logger/helpers"
"github.com/kubescape/k8s-interface/k8sinterface"
"github.com/kubescape/kubescape/v2/core/cautils/getter"
"github.com/kubescape/kubescape/v3/core/cautils/getter"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
const (
configFileName string = "config"
kubescapeNamespace string = "kubescape"
kubescapeConfigMapName string = "kubescape-config"
kubescapeCloudConfigMapName string = "ks-cloud-config"
configFileName string = "config"
kubescapeNamespace string = "kubescape"
kubescapeConfigMapName string = "kubescape-config" // deprecated - for backward compatibility
cloudConfigMapLabelSelector string = "kubescape.io/infra=config"
credsLabelSelectors string = "kubescape.io/infra=credentials" //nolint:gosec
// env vars
defaultConfigMapNameEnvVar string = "KS_DEFAULT_CONFIGMAP_NAME"
defaultCloudConfigMapNameEnvVar string = "KS_DEFAULT_CLOUD_CONFIGMAP_NAME"
defaultConfigMapNamespaceEnvVar string = "KS_DEFAULT_CONFIGMAP_NAMESPACE"
accountIdEnvVar string = "KS_ACCOUNT_ID"
accessKeyEnvVar string = "KS_ACCESS_KEY"
cloudApiUrlEnvVar string = "KS_CLOUD_API_URL"
cloudReportUrlEnvVar string = "KS_CLOUD_REPORT_URL"
storageEnabledEnvVar string = "KS_STORAGE_ENABLED"
)
func ConfigFileFullPath() string { return getter.GetDefaultPath(configFileName + ".json") }
@@ -47,7 +48,7 @@ type ConfigObj struct {
ClusterName string `json:"clusterName,omitempty"`
CloudReportURL string `json:"cloudReportURL,omitempty"`
CloudAPIURL string `json:"cloudAPIURL,omitempty"`
StorageEnabled bool `json:"storageEnabled,omitempty"`
AccessKey string `json:"accessKey,omitempty"`
}
// Config - convert ConfigObj to config file
@@ -92,15 +93,15 @@ type ITenantConfig interface {
UpdateCachedConfig() error
DeleteCachedConfig(ctx context.Context) error
GenerateAccountID() (string, error)
DeleteAccountID() error
DeleteCredentials() error
// getters
GetContextName() string
GetAccountID() string
GetAccessKey() string
GetConfigObj() *ConfigObj
GetCloudReportURL() string
GetCloudAPIURL() string
IsStorageEnabled() bool
}
// ======================================================================================
@@ -114,7 +115,7 @@ type LocalConfig struct {
configObj *ConfigObj
}
func NewLocalConfig(accountID, clusterName string, customClusterName string) *LocalConfig {
func NewLocalConfig(accountID, accessKey, clusterName, customClusterName string) *LocalConfig {
lc := &LocalConfig{
configObj: &ConfigObj{},
}
@@ -123,9 +124,8 @@ func NewLocalConfig(accountID, clusterName string, customClusterName string) *Lo
loadConfigFromFile(lc.configObj)
}
updateAccountID(lc.configObj, accountID)
updateCredentials(lc.configObj, accountID, accessKey)
updateCloudURLs(lc.configObj)
updateStorageEnabled(lc.configObj)
// If a custom cluster name is provided then set that name, else use the cluster's original name
if customClusterName != "" {
@@ -134,8 +134,7 @@ func NewLocalConfig(accountID, clusterName string, customClusterName string) *Lo
lc.configObj.ClusterName = AdoptClusterName(clusterName) // override config clusterName
}
updatedKsCloud := initializeCloudAPI(lc)
logger.L().Debug("Kubescape Cloud URLs", helpers.String("api", updatedKsCloud.GetCloudAPIURL()), helpers.String("report", updatedKsCloud.GetCloudReportURL()))
initializeCloudAPI(lc)
return lc
}
@@ -145,7 +144,7 @@ func (lc *LocalConfig) GetAccountID() string { return lc.configObj.AccountI
func (lc *LocalConfig) GetContextName() string { return lc.configObj.ClusterName }
func (lc *LocalConfig) GetCloudReportURL() string { return lc.configObj.CloudReportURL }
func (lc *LocalConfig) GetCloudAPIURL() string { return lc.configObj.CloudAPIURL }
func (lc *LocalConfig) IsStorageEnabled() bool { return lc.configObj.StorageEnabled }
func (lc *LocalConfig) GetAccessKey() string { return lc.configObj.AccessKey }
func (lc *LocalConfig) GenerateAccountID() (string, error) {
lc.configObj.AccountID = uuid.NewString()
@@ -153,7 +152,8 @@ func (lc *LocalConfig) GenerateAccountID() (string, error) {
return lc.configObj.AccountID, err
}
func (lc *LocalConfig) DeleteAccountID() error {
func (lc *LocalConfig) DeleteCredentials() error {
lc.configObj.AccessKey = ""
lc.configObj.AccountID = ""
return lc.UpdateCachedConfig()
}
@@ -189,20 +189,16 @@ KS_CACHE // path to cached files
var _ ITenantConfig = &ClusterConfig{}
type ClusterConfig struct {
k8s *k8sinterface.KubernetesApi
configObj *ConfigObj
configMapNamespace string
ksConfigMapName string
ksCloudConfigMapName string
k8s *k8sinterface.KubernetesApi
configObj *ConfigObj
configMapNamespace string
}
func NewClusterConfig(k8s *k8sinterface.KubernetesApi, accountID, clusterName string, customClusterName string) *ClusterConfig {
func NewClusterConfig(k8s *k8sinterface.KubernetesApi, accountID, accessKey, clusterName, customClusterName string) *ClusterConfig {
c := &ClusterConfig{
k8s: k8s,
configObj: &ConfigObj{},
ksConfigMapName: getKubescapeConfigMapName(),
ksCloudConfigMapName: getKubescapeCloudConfigMapName(),
configMapNamespace: GetConfigMapNamespace(),
k8s: k8s,
configObj: &ConfigObj{},
configMapNamespace: GetConfigMapNamespace(),
}
// first, load from file
@@ -210,19 +206,16 @@ func NewClusterConfig(k8s *k8sinterface.KubernetesApi, accountID, clusterName st
loadConfigFromFile(c.configObj)
}
// second, load from configMap
if c.existsConfigMap(c.ksConfigMapName) {
c.updateConfigEmptyFieldsFromKubescapeConfigMap()
}
loadUrlsFromFile(c.configObj)
// third, load urls from cloudConfigMap
if c.existsConfigMap(c.ksCloudConfigMapName) {
c.updateConfigEmptyFieldsFromKubescapeCloudConfigMap()
}
// second, load urls from config map
c.updateConfigEmptyFieldsFromKubescapeConfigMap()
updateAccountID(c.configObj, accountID)
// third, credentials from secret
c.updateConfigEmptyFieldsFromCredentialsSecret()
updateCredentials(c.configObj, accountID, accessKey)
updateCloudURLs(c.configObj)
updateStorageEnabled(c.configObj)
// If a custom cluster name is provided then set that name, else use the cluster's original name
if customClusterName != "" {
@@ -236,8 +229,7 @@ func NewClusterConfig(k8s *k8sinterface.KubernetesApi, accountID, clusterName st
} else { // override the cluster name if it has unwanted characters
c.configObj.ClusterName = AdoptClusterName(c.configObj.ClusterName)
}
updatedKsCloud := initializeCloudAPI(c)
logger.L().Debug("Kubescape Cloud URLs", helpers.String("api", updatedKsCloud.GetCloudAPIURL()), helpers.String("report", updatedKsCloud.GetCloudReportURL()))
initializeCloudAPI(c)
return c
}
@@ -246,7 +238,7 @@ func (c *ClusterConfig) GetDefaultNS() string { return c.configMapNamespace
func (c *ClusterConfig) GetAccountID() string { return c.configObj.AccountID }
func (c *ClusterConfig) GetCloudReportURL() string { return c.configObj.CloudReportURL }
func (c *ClusterConfig) GetCloudAPIURL() string { return c.configObj.CloudAPIURL }
func (c *ClusterConfig) IsStorageEnabled() bool { return c.configObj.StorageEnabled }
func (c *ClusterConfig) GetAccessKey() string { return c.configObj.AccessKey }
func (c *ClusterConfig) UpdateCachedConfig() error {
logger.L().Debug("updating cached config", helpers.Interface("configObj", c.configObj))
@@ -272,42 +264,57 @@ func (c *ClusterConfig) ToMapString() map[string]interface{} {
}
func (c *ClusterConfig) updateConfigEmptyFieldsFromKubescapeConfigMap() error {
configMap, err := c.k8s.KubernetesClient.CoreV1().ConfigMaps(c.configMapNamespace).Get(context.Background(), c.ksConfigMapName, metav1.GetOptions{})
configMaps, err := c.k8s.KubernetesClient.CoreV1().ConfigMaps(c.configMapNamespace).List(context.Background(), metav1.ListOptions{
LabelSelector: cloudConfigMapLabelSelector,
})
if err != nil {
return err
}
tempCO := ConfigObj{}
if jsonConf, ok := configMap.Data["config.json"]; ok {
if err = json.Unmarshal([]byte(jsonConf), &tempCO); err != nil {
return err
}
return c.configObj.updateEmptyFields(&tempCO)
var ksConfigMap *corev1.ConfigMap
if len(configMaps.Items) == 0 {
// try to find configmaps by name (for backward compatibility)
ksConfigMap, _ = c.k8s.KubernetesClient.CoreV1().ConfigMaps(c.configMapNamespace).Get(context.Background(), kubescapeConfigMapName, metav1.GetOptions{})
} else {
// use the first configmap with the label
ksConfigMap = &configMaps.Items[0]
}
if ksConfigMap != nil {
if jsonConf, ok := ksConfigMap.Data["clusterData"]; ok {
tempCO := ConfigObj{}
if err = json.Unmarshal([]byte(jsonConf), &tempCO); err != nil {
return err
}
c.configObj.updateEmptyFields(&tempCO)
}
}
return err
}
func (c *ClusterConfig) updateConfigEmptyFieldsFromKubescapeCloudConfigMap() error {
configMap, err := c.k8s.KubernetesClient.CoreV1().ConfigMaps(c.configMapNamespace).Get(context.Background(), c.ksCloudConfigMapName, metav1.GetOptions{})
func (c *ClusterConfig) updateConfigEmptyFieldsFromCredentialsSecret() error {
secrets, err := c.k8s.KubernetesClient.CoreV1().Secrets(c.configMapNamespace).List(context.Background(),
metav1.ListOptions{LabelSelector: credsLabelSelectors})
if err != nil {
return err
}
if jsonConf, ok := configMap.Data["services"]; ok {
services, err := servicediscovery.GetServices(
servicediscoveryv1.NewServiceDiscoveryStreamV1([]byte(jsonConf)),
)
if err != nil {
return err
}
if len(secrets.Items) == 0 {
return nil
}
if services.GetApiServerUrl() != "" {
c.configObj.CloudAPIURL = services.GetApiServerUrl()
}
if services.GetReportReceiverHttpUrl() != "" {
c.configObj.CloudReportURL = services.GetReportReceiverHttpUrl()
if jsonConf, ok := secrets.Items[0].Data["account"]; ok {
if account := string(jsonConf); account != "" {
c.configObj.AccountID = account
}
}
if jsonConf, ok := secrets.Items[0].Data["accessKey"]; ok {
if accessKey := string(jsonConf); accessKey != "" {
c.configObj.AccessKey = accessKey
}
}
return nil
}
@@ -323,11 +330,6 @@ func loadConfigFromData(co *ConfigObj, data map[string]string) error {
return e
}
func (c *ClusterConfig) existsConfigMap(name string) bool {
_, err := c.k8s.KubernetesClient.CoreV1().ConfigMaps(c.configMapNamespace).Get(context.Background(), name, metav1.GetOptions{})
return err == nil
}
func existsConfigFile() bool {
_, err := os.ReadFile(ConfigFileFullPath())
return err == nil
@@ -349,8 +351,9 @@ func (c *ClusterConfig) GenerateAccountID() (string, error) {
return c.configObj.AccountID, err
}
func (c *ClusterConfig) DeleteAccountID() error {
func (c *ClusterConfig) DeleteCredentials() error {
c.configObj.AccountID = ""
c.configObj.AccessKey = ""
return c.UpdateCachedConfig()
}
@@ -368,7 +371,7 @@ func (c *ClusterConfig) updateConfigData(configMap *corev1.ConfigMap) {
func loadConfigFromFile(configObj *ConfigObj) error {
dat, err := os.ReadFile(ConfigFileFullPath())
if err != nil {
return err
return nil // no config file
}
return readConfig(dat, configObj)
}
@@ -384,6 +387,32 @@ func readConfig(dat []byte, configObj *ConfigObj) error {
return nil
}
func loadUrlsFromFile(obj *ConfigObj) error {
dat, err := os.ReadFile("/etc/config/services.json")
if err != nil {
return nil // no config file
}
services, err := servicediscovery.GetServices(
servicediscoveryv2.NewServiceDiscoveryStreamV2(dat),
)
if err != nil {
// try to parse as v1
services, err = servicediscovery.GetServices(
servicediscoveryv1.NewServiceDiscoveryStreamV1(dat),
)
if err != nil {
return err
}
}
if services.GetApiServerUrl() != "" {
obj.CloudAPIURL = services.GetApiServerUrl()
}
if services.GetReportReceiverHttpUrl() != "" {
obj.CloudReportURL = services.GetReportReceiverHttpUrl()
}
return nil
}
func DeleteConfigFile() error {
return os.Remove(ConfigFileFullPath())
}
@@ -396,21 +425,6 @@ func AdoptClusterName(clusterName string) string {
return re.ReplaceAllString(clusterName, "-")
}
func getKubescapeConfigMapName() string {
if n := os.Getenv(defaultConfigMapNameEnvVar); n != "" {
return n
}
return kubescapeConfigMapName
}
func getKubescapeCloudConfigMapName() string {
if n := os.Getenv(defaultCloudConfigMapNameEnvVar); n != "" {
return n
}
return kubescapeCloudConfigMapName
}
// GetConfigMapNamespace returns the namespace of the cluster config, which is the same for all in-cluster components
func GetConfigMapNamespace() string {
if n := os.Getenv(defaultConfigMapNamespaceEnvVar); n != "" {
@@ -419,7 +433,15 @@ func GetConfigMapNamespace() string {
return kubescapeNamespace
}
func updateAccountID(configObj *ConfigObj, accountID string) {
func updateCredentials(configObj *ConfigObj, accountID, accessKey string) {
if accessKey != "" {
configObj.AccessKey = accessKey
}
if envAccessKey := os.Getenv(accessKeyEnvVar); envAccessKey != "" {
configObj.AccessKey = envAccessKey
}
if accountID != "" {
configObj.AccountID = accountID
}
@@ -429,10 +451,6 @@ func updateAccountID(configObj *ConfigObj, accountID string) {
}
}
func updateStorageEnabled(configObj *ConfigObj) {
configObj.StorageEnabled, _ = ParseBoolEnvVar(storageEnabledEnvVar, configObj.StorageEnabled)
}
func getCloudURLsFromEnv(cloudURLs *CloudURLs) {
// load from env
if cloudAPIURL := os.Getenv(cloudApiUrlEnvVar); cloudAPIURL != "" {
@@ -460,18 +478,46 @@ func updateCloudURLs(configObj *ConfigObj) {
}
func initializeCloudAPI(c ITenantConfig) *v1.KSCloudAPI {
logger.L().Debug("initializing KS Cloud API from config", helpers.String("accountID", c.GetAccountID()), helpers.String("cloudAPIURL", c.GetCloudAPIURL()), helpers.String("cloudReportURL", c.GetCloudReportURL()))
cloud, err := v1.NewKSCloudAPI(c.GetCloudAPIURL(), c.GetCloudReportURL(), c.GetAccountID())
if err != nil {
logger.L().Fatal("failed to create KS Cloud client", helpers.Error(err))
if ksCloud := getter.GetKSCloudAPIConnector(); ksCloud != nil {
if val := c.GetCloudAPIURL(); val != "" && val != ksCloud.GetCloudAPIURL() {
logger.L().Debug("updating KS Cloud API from config", helpers.String("old", ksCloud.GetCloudAPIURL()), helpers.String("new", val))
ksCloud.SetCloudAPIURL(val)
}
if val := c.GetCloudReportURL(); val != "" && val != ksCloud.GetCloudReportURL() {
logger.L().Debug("updating KS Cloud Report from config", helpers.String("old", ksCloud.GetCloudReportURL()), helpers.String("new", val))
ksCloud.SetCloudReportURL(val)
}
if val := c.GetAccountID(); val != "" && val != ksCloud.GetAccountID() {
logger.L().Debug("updating Account ID from config", helpers.String("old", ksCloud.GetAccountID()), helpers.String("new", val))
ksCloud.SetAccountID(val)
}
if val := c.GetAccessKey(); val != "" && val != ksCloud.GetAccessKey() {
logger.L().Debug("updating Access Key from config", helpers.Int("old (len)", len(ksCloud.GetAccessKey())), helpers.Int("new (len)", len(val)))
ksCloud.SetAccessKey(val)
}
getter.SetKSCloudAPIConnector(ksCloud)
} else {
logger.L().Debug("initializing KS Cloud API from config", helpers.String("accountID", c.GetAccountID()), helpers.String("cloudAPIURL", c.GetCloudAPIURL()), helpers.String("cloudReportURL", c.GetCloudReportURL()))
cloud, err := v1.NewKSCloudAPI(
c.GetCloudAPIURL(),
c.GetCloudReportURL(),
c.GetAccountID(),
c.GetAccessKey())
if err != nil {
logger.L().Fatal("failed to create KS Cloud client", helpers.Error(err))
}
getter.SetKSCloudAPIConnector(cloud)
}
getter.SetKSCloudAPIConnector(cloud)
return getter.GetKSCloudAPIConnector()
}
func GetTenantConfig(accountID, clusterName, customClusterName string, k8s *k8sinterface.KubernetesApi) ITenantConfig {
func GetTenantConfig(accountID, accessKey, clusterName, customClusterName string, k8s *k8sinterface.KubernetesApi) ITenantConfig {
if !k8sinterface.IsConnectedToCluster() || k8s == nil {
return NewLocalConfig(accountID, clusterName, customClusterName)
return NewLocalConfig(accountID, accessKey, clusterName, customClusterName)
}
return NewClusterConfig(k8s, accountID, clusterName, customClusterName)
return NewClusterConfig(k8s, accountID, accessKey, clusterName, customClusterName)
}
// firstNonEmpty returns the first non-empty string

View File

@@ -5,7 +5,7 @@ import (
"os"
"testing"
"github.com/kubescape/kubescape/v2/core/cautils/getter"
"github.com/kubescape/kubescape/v3/core/cautils/getter"
"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
)

View File

@@ -4,7 +4,10 @@ import (
"context"
"sort"
"github.com/anchore/grype/grype/presenter/models"
"github.com/anchore/grype/grype/match"
"github.com/anchore/grype/grype/pkg"
"github.com/anchore/grype/grype/vulnerability"
"github.com/anchore/syft/syft/sbom"
"github.com/armosec/armoapi-go/armotypes"
"github.com/kubescape/k8s-interface/workloadinterface"
"github.com/kubescape/opa-utils/reporthandling"
@@ -20,14 +23,20 @@ type K8SResources map[string][]string
type ExternalResources map[string][]string
type ImageScanData struct {
PresenterConfig *models.PresenterConfig
Image string
Context pkg.Context
IgnoredMatches []match.IgnoredMatch
Image string
Matches match.Matches
Packages []pkg.Package
RemainingMatches *match.Matches
SBOM *sbom.SBOM
VulnerabilityProvider vulnerability.Provider
}
type ScanTypes string
const (
TopWorkloadsNumber = 5
TopWorkloadsNumber = 3
ScanTypeCluster ScanTypes = "cluster"
ScanTypeRepo ScanTypes = "repo"
ScanTypeImage ScanTypes = "image"
@@ -58,25 +67,44 @@ type OPASessionObj struct {
OmitRawResources bool // omit raw resources from output
SingleResourceScan workloadinterface.IWorkload // single resource scan
TopWorkloadsByScore []reporthandling.IResource
TemplateMapping map[string]MappingNodes // Map chart obj to template (only for rendering from path)
TriggeredByCLI bool
LabelsToCopy []string // Labels to copy from workloads to scan reports
}
func NewOPASessionObj(ctx context.Context, frameworks []reporthandling.Framework, k8sResources K8SResources, scanInfo *ScanInfo) *OPASessionObj {
clusterSize := estimateClusterSize(k8sResources)
if clusterSize < 100 {
clusterSize = 100
}
return &OPASessionObj{
Report: &reporthandlingv2.PostureReport{},
Policies: frameworks,
K8SResources: k8sResources,
AllResources: make(map[string]workloadinterface.IMetadata),
ResourcesResult: make(map[string]resourcesresults.Result),
ResourcesPrioritized: make(map[string]prioritization.PrioritizedResource),
InfoMap: make(map[string]apis.StatusInfo),
ResourceToControlsMap: make(map[string][]string),
ResourceSource: make(map[string]reporthandling.Source),
AllResources: make(map[string]workloadinterface.IMetadata, clusterSize),
ResourcesResult: make(map[string]resourcesresults.Result, clusterSize),
ResourcesPrioritized: make(map[string]prioritization.PrioritizedResource, clusterSize/10),
InfoMap: make(map[string]apis.StatusInfo, clusterSize/10),
ResourceToControlsMap: make(map[string][]string, clusterSize/2),
ResourceSource: make(map[string]reporthandling.Source, clusterSize),
SessionID: scanInfo.ScanID,
Metadata: scanInfoToScanMetadata(ctx, scanInfo),
OmitRawResources: scanInfo.OmitRawResources,
TriggeredByCLI: scanInfo.TriggeredByCLI,
TemplateMapping: make(map[string]MappingNodes, clusterSize/10),
LabelsToCopy: scanInfo.LabelsToCopy,
}
}
func estimateClusterSize(k8sResources K8SResources) int {
total := 0
for _, resourceIDs := range k8sResources {
total += len(resourceIDs)
}
return total
}
// SetTopWorkloads sets the top workloads by score
func (sessionObj *OPASessionObj) SetTopWorkloads() {
count := 0

View File

@@ -1,12 +1,11 @@
package cautils
import (
"golang.org/x/mod/semver"
"github.com/armosec/utils-go/boolutils"
cloudsupport "github.com/kubescape/k8s-interface/cloudsupport/v1"
"github.com/kubescape/backend/pkg/versioncheck"
"github.com/kubescape/opa-utils/reporthandling"
"github.com/kubescape/opa-utils/reporthandling/apis"
reporthandlingv2 "github.com/kubescape/opa-utils/reporthandling/v2"
"golang.org/x/mod/semver"
)
func NewPolicies() *Policies {
@@ -16,7 +15,7 @@ func NewPolicies() *Policies {
}
}
func (policies *Policies) Set(frameworks []reporthandling.Framework, version string, excludedRules map[string]bool, scanningScope reporthandling.ScanningScopeType) {
func (policies *Policies) Set(frameworks []reporthandling.Framework, excludedRules map[string]bool, scanningScope reporthandling.ScanningScopeType) {
for i := range frameworks {
if !isFrameworkFitToScanScope(frameworks[i], scanningScope) {
continue
@@ -34,9 +33,12 @@ func (policies *Policies) Set(frameworks []reporthandling.Framework, version str
}
}
if !ruleWithKSOpaDependency(frameworks[i].Controls[j].Rules[r].Attributes) && isRuleKubescapeVersionCompatible(frameworks[i].Controls[j].Rules[r].Attributes, version) && isControlFitToScanScope(frameworks[i].Controls[j], scanningScope) {
compatibleRules = append(compatibleRules, frameworks[i].Controls[j].Rules[r])
if ShouldSkipRule(frameworks[i].Controls[j], frameworks[i].Controls[j].Rules[r], scanningScope) {
continue
}
// if isRuleKubescapeVersionCompatible(frameworks[i].Controls[j].Rules[r].Attributes, version) && isControlFitToScanScope(frameworks[i].Controls[j], scanningScope) {
compatibleRules = append(compatibleRules, frameworks[i].Controls[j].Rules[r])
// }
}
if len(compatibleRules) > 0 {
frameworks[i].Controls[j].Rules = compatibleRules
@@ -56,12 +58,16 @@ func (policies *Policies) Set(frameworks []reporthandling.Framework, version str
}
}
func ruleWithKSOpaDependency(attributes map[string]interface{}) bool {
if attributes == nil {
return false
// ShouldSkipRule checks if the rule should be skipped
// It checks the following:
// 1. Rule is compatible with the current kubescape version
// 2. Rule fits the current scanning scope
func ShouldSkipRule(control reporthandling.Control, rule reporthandling.PolicyRule, scanningScope reporthandling.ScanningScopeType) bool {
if !isRuleKubescapeVersionCompatible(rule.Attributes, versioncheck.BuildNumber) {
return true
}
if s, ok := attributes["armoOpa"]; ok { // TODO - make global
return boolutils.StringToBool(s.(string))
if !isControlFitToScanScope(control, scanningScope) {
return true
}
return false
}
@@ -70,50 +76,35 @@ func ruleWithKSOpaDependency(attributes map[string]interface{}) bool {
// In local build (BuildNumber = ""):
// returns true only if rule doesn't have the "until" attribute
func isRuleKubescapeVersionCompatible(attributes map[string]interface{}, version string) bool {
normalizedVersion := version
if version != "" && !semver.IsValid(version) {
normalizedVersion = "v" + version
}
if from, ok := attributes["useFromKubescapeVersion"]; ok && from != nil {
if version != "" {
if semver.Compare(version, from.(string)) == -1 {
switch sfrom := from.(type) {
case string:
if normalizedVersion != "" && semver.IsValid(normalizedVersion) && semver.Compare(normalizedVersion, sfrom) == -1 {
return false
}
}
}
if until, ok := attributes["useUntilKubescapeVersion"]; ok && until != nil {
if version == "" {
default:
return false
}
if semver.Compare(version, until.(string)) >= 0 {
}
if until, ok := attributes["useUntilKubescapeVersion"]; ok && until != nil {
switch suntil := until.(type) {
case string:
if normalizedVersion == "" || (semver.IsValid(normalizedVersion) && semver.Compare(normalizedVersion, suntil) >= 0) {
return false
}
default:
return false
}
}
return true
}
func getCloudProvider(scanInfo *ScanInfo) reporthandling.ScanningScopeType {
if cloudsupport.IsAKS() {
return reporthandling.ScopeCloudAKS
}
if cloudsupport.IsEKS() {
return reporthandling.ScopeCloudEKS
}
if cloudsupport.IsGKE() {
return reporthandling.ScopeCloudGKE
}
return ""
}
func GetScanningScope(scanInfo *ScanInfo) reporthandling.ScanningScopeType {
switch scanInfo.GetScanningContext() {
case ContextCluster:
if cloudProvider := getCloudProvider(scanInfo); cloudProvider != "" {
return cloudProvider
}
return reporthandling.ScopeCluster
default:
return reporthandling.ScopeFile
}
}
func isScanningScopeMatchToControlScope(scanScope reporthandling.ScanningScopeType, controlScope reporthandling.ScanningScopeType) bool {
switch controlScope {
@@ -165,3 +156,13 @@ func isFrameworkFitToScanScope(framework reporthandling.Framework, scanScopeMatc
}
return false
}
func GetScanningScope(ContextMetadata reporthandlingv2.ContextMetadata) reporthandling.ScanningScopeType {
if ContextMetadata.ClusterContextMetadata != nil {
if ContextMetadata.ClusterContextMetadata.CloudMetadata != nil && ContextMetadata.ClusterContextMetadata.CloudMetadata.CloudProvider != "" {
return reporthandling.ScanningScopeType(ContextMetadata.ClusterContextMetadata.CloudMetadata.CloudProvider)
}
return reporthandling.ScopeCluster
}
return reporthandling.ScopeFile
}

View File

@@ -9,99 +9,6 @@ import (
"github.com/stretchr/testify/assert"
)
func TestIsControlFitToScanScope(t *testing.T) {
tests := []struct {
scanInfo *ScanInfo
Control reporthandling.Control
expected_res bool
}{
{
scanInfo: &ScanInfo{
InputPatterns: []string{
"./testdata/any_file_for_test.json",
},
},
Control: reporthandling.Control{
ScanningScope: &reporthandling.ScanningScope{
Matches: []reporthandling.ScanningScopeType{
reporthandling.ScopeFile,
},
},
},
expected_res: true,
},
{
scanInfo: &ScanInfo{
InputPatterns: []string{
"./testdata/any_file_for_test.json",
},
},
Control: reporthandling.Control{
ScanningScope: &reporthandling.ScanningScope{
Matches: []reporthandling.ScanningScopeType{
reporthandling.ScopeCluster,
reporthandling.ScopeFile,
},
},
},
expected_res: true,
},
{
scanInfo: &ScanInfo{},
Control: reporthandling.Control{
ScanningScope: &reporthandling.ScanningScope{
Matches: []reporthandling.ScanningScopeType{
reporthandling.ScopeCluster,
},
},
},
expected_res: true,
},
{
scanInfo: &ScanInfo{
InputPatterns: []string{
"./testdata/any_file_for_test.json",
},
},
Control: reporthandling.Control{
ScanningScope: &reporthandling.ScanningScope{
Matches: []reporthandling.ScanningScopeType{
reporthandling.ScopeCloudGKE,
},
},
},
expected_res: false,
},
{
scanInfo: &ScanInfo{},
Control: reporthandling.Control{
ScanningScope: &reporthandling.ScanningScope{
Matches: []reporthandling.ScanningScopeType{
reporthandling.ScopeCloudEKS,
},
},
},
expected_res: false,
},
{
scanInfo: &ScanInfo{},
Control: reporthandling.Control{
ScanningScope: &reporthandling.ScanningScope{
Matches: []reporthandling.ScanningScopeType{
reporthandling.ScopeCloud,
},
},
},
expected_res: false,
}}
for i := range tests {
assert.Equal(t, tests[i].expected_res, isControlFitToScanScope(tests[i].Control, GetScanningScope(tests[i].scanInfo)), fmt.Sprintf("tests_true index %d", i))
}
}
func TestIsScanningScopeMatchToControlScope(t *testing.T) {
tests := []struct {
scanScope reporthandling.ScanningScopeType
@@ -332,3 +239,59 @@ func TestIsFrameworkFitToScanScope(t *testing.T) {
})
}
}
var rule_v1_0_131 = &reporthandling.PolicyRule{PortalBase: armotypes.PortalBase{
Attributes: map[string]interface{}{"useUntilKubescapeVersion": "v1.0.132"}}}
var rule_v1_0_132 = &reporthandling.PolicyRule{PortalBase: armotypes.PortalBase{
Attributes: map[string]interface{}{"useFromKubescapeVersion": "v1.0.132", "useUntilKubescapeVersion": "v1.0.133"}}}
var rule_v1_0_133 = &reporthandling.PolicyRule{PortalBase: armotypes.PortalBase{
Attributes: map[string]interface{}{"useFromKubescapeVersion": "v1.0.133", "useUntilKubescapeVersion": "v1.0.134"}}}
var rule_v1_0_134 = &reporthandling.PolicyRule{PortalBase: armotypes.PortalBase{
Attributes: map[string]interface{}{"useFromKubescapeVersion": "v1.0.134"}}}
var rule_invalid_from = &reporthandling.PolicyRule{PortalBase: armotypes.PortalBase{
Attributes: map[string]interface{}{"useFromKubescapeVersion": 1.0135, "useUntilKubescapeVersion": "v1.0.135"}}}
var rule_invalid_until = &reporthandling.PolicyRule{PortalBase: armotypes.PortalBase{
Attributes: map[string]interface{}{"useFromKubescapeVersion": "v1.0.135", "useUntilKubescapeVersion": 1.0135}}}
func TestIsRuleKubescapeVersionCompatible(t *testing.T) {
// local build- no build number
// should not crash when the value of useUntilKubescapeVersion is not a string
buildNumberMock := "v1.0.135"
assert.False(t, isRuleKubescapeVersionCompatible(rule_invalid_from.Attributes, buildNumberMock))
assert.False(t, isRuleKubescapeVersionCompatible(rule_invalid_until.Attributes, buildNumberMock))
// should use only rules that don't have "until"
buildNumberMock = ""
assert.False(t, isRuleKubescapeVersionCompatible(rule_v1_0_131.Attributes, buildNumberMock))
assert.False(t, isRuleKubescapeVersionCompatible(rule_v1_0_132.Attributes, buildNumberMock))
assert.False(t, isRuleKubescapeVersionCompatible(rule_v1_0_133.Attributes, buildNumberMock))
assert.True(t, isRuleKubescapeVersionCompatible(rule_v1_0_134.Attributes, buildNumberMock))
// should only use rules that version is in range of use
buildNumberMock = "v1.0.130"
assert.True(t, isRuleKubescapeVersionCompatible(rule_v1_0_131.Attributes, buildNumberMock))
assert.False(t, isRuleKubescapeVersionCompatible(rule_v1_0_132.Attributes, buildNumberMock))
assert.False(t, isRuleKubescapeVersionCompatible(rule_v1_0_133.Attributes, buildNumberMock))
assert.False(t, isRuleKubescapeVersionCompatible(rule_v1_0_134.Attributes, buildNumberMock))
// should only use rules that version is in range of use
buildNumberMock = "v1.0.132"
assert.False(t, isRuleKubescapeVersionCompatible(rule_v1_0_131.Attributes, buildNumberMock))
assert.True(t, isRuleKubescapeVersionCompatible(rule_v1_0_132.Attributes, buildNumberMock))
assert.False(t, isRuleKubescapeVersionCompatible(rule_v1_0_133.Attributes, buildNumberMock))
assert.False(t, isRuleKubescapeVersionCompatible(rule_v1_0_134.Attributes, buildNumberMock))
// should only use rules that version is in range of use
buildNumberMock = "v1.0.133"
assert.False(t, isRuleKubescapeVersionCompatible(rule_v1_0_131.Attributes, buildNumberMock))
assert.False(t, isRuleKubescapeVersionCompatible(rule_v1_0_132.Attributes, buildNumberMock))
assert.True(t, isRuleKubescapeVersionCompatible(rule_v1_0_133.Attributes, buildNumberMock))
assert.False(t, isRuleKubescapeVersionCompatible(rule_v1_0_134.Attributes, buildNumberMock))
// should only use rules that version is in range of use
buildNumberMock = "v1.0.135"
assert.False(t, isRuleKubescapeVersionCompatible(rule_v1_0_131.Attributes, buildNumberMock))
assert.False(t, isRuleKubescapeVersionCompatible(rule_v1_0_132.Attributes, buildNumberMock))
assert.False(t, isRuleKubescapeVersionCompatible(rule_v1_0_133.Attributes, buildNumberMock))
assert.True(t, isRuleKubescapeVersionCompatible(rule_v1_0_134.Attributes, buildNumberMock))
}

View File

@@ -4,11 +4,12 @@ import (
"fmt"
"io"
"os"
"strings"
"time"
spinnerpkg "github.com/briandowns/spinner"
"github.com/jwalton/gchalk"
logger "github.com/kubescape/go-logger"
"github.com/kubescape/go-logger"
"github.com/kubescape/go-logger/helpers"
"github.com/mattn/go-isatty"
"github.com/schollz/progressbar/v3"
@@ -27,7 +28,7 @@ func FailureTextDisplay(w io.Writer, format string, a ...interface{}) {
}
func InfoDisplay(w io.Writer, format string, a ...interface{}) {
fmt.Fprintf(w, gchalk.WithCyan().Bold(format), a...)
fmt.Fprintf(w, gchalk.WithBrightWhite().Bold(format), a...)
}
func InfoTextDisplay(w io.Writer, format string, a ...interface{}) {
@@ -50,6 +51,20 @@ func BoldDisplay(w io.Writer, format string, a ...interface{}) {
fmt.Fprintf(w, gchalk.Bold(format), a...)
}
func LineDisplay(w io.Writer, format string, a ...interface{}) {
fmt.Fprintf(w, gchalk.WithAnsi256(238).Bold(format), a...)
}
func SectionHeadingDisplay(w io.Writer, format string, a ...interface{}) {
fmt.Fprintf(w, "\n"+
gchalk.WithBrightWhite().Bold(format)+
gchalk.WithAnsi256(238).Bold(fmt.Sprintf("\n%s\n\n", strings.Repeat("─", len(format)))), a...)
}
func StarDisplay(w io.Writer, format string, a ...interface{}) {
fmt.Fprintf(w, gchalk.WithAnsi256(238).Bold("* ")+gchalk.White(format), a...)
}
var spinner *spinnerpkg.Spinner
func StartSpinner() {

View File

@@ -1,9 +1,12 @@
package cautils
import (
"io"
"os"
"testing"
"github.com/kubescape/go-logger"
"github.com/stretchr/testify/assert"
)
func TestStartSpinner(t *testing.T) {
@@ -30,3 +33,422 @@ func TestStartSpinner(t *testing.T) {
})
}
}
func TestFailureDisplay(t *testing.T) {
tests := []struct {
text string
want string
}{
{
text: "Test",
want: "Test",
},
{
text: "",
want: "",
},
}
for _, tt := range tests {
t.Run(tt.text, func(t *testing.T) {
// Redirect stdout to a buffer
rescueStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
FailureDisplay(os.Stdout, tt.text)
w.Close()
got, _ := io.ReadAll(r)
os.Stdout = rescueStdout
assert.Equal(t, tt.want, string(got))
})
}
}
func TestWarningDisplay(t *testing.T) {
tests := []struct {
text string
want string
}{
{
text: "Test",
want: "Test",
},
{
text: "",
want: "",
},
}
for _, tt := range tests {
t.Run(tt.text, func(t *testing.T) {
// Redirect stdout to a buffer
rescueStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
WarningDisplay(os.Stdout, tt.text)
w.Close()
got, _ := io.ReadAll(r)
os.Stdout = rescueStdout
assert.Equal(t, tt.want, string(got))
})
}
}
func TestFailureTextDisplay(t *testing.T) {
tests := []struct {
text string
want string
}{
{
text: "Test",
want: "Test",
},
{
text: "",
want: "",
},
}
for _, tt := range tests {
t.Run(tt.text, func(t *testing.T) {
// Redirect stdout to a buffer
rescueStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
FailureTextDisplay(os.Stdout, tt.text)
w.Close()
got, _ := io.ReadAll(r)
os.Stdout = rescueStdout
assert.Equal(t, tt.want, string(got))
})
}
}
func TestInfoDisplay(t *testing.T) {
tests := []struct {
text string
want string
}{
{
text: "Test",
want: "Test",
},
{
text: "",
want: "",
},
}
for _, tt := range tests {
t.Run(tt.text, func(t *testing.T) {
// Redirect stdout to a buffer
rescueStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
InfoDisplay(os.Stdout, tt.text)
w.Close()
got, _ := io.ReadAll(r)
os.Stdout = rescueStdout
assert.Equal(t, tt.want, string(got))
})
}
}
func TestInfoTextDisplay(t *testing.T) {
tests := []struct {
text string
want string
}{
{
text: "Test",
want: "Test",
},
{
text: "",
want: "",
},
}
for _, tt := range tests {
t.Run(tt.text, func(t *testing.T) {
// Redirect stdout to a buffer
rescueStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
InfoTextDisplay(os.Stdout, tt.text)
w.Close()
got, _ := io.ReadAll(r)
os.Stdout = rescueStdout
assert.Equal(t, tt.want, string(got))
})
}
}
func TestSimpleDisplay(t *testing.T) {
tests := []struct {
text string
want string
}{
{
text: "Test",
want: "Test",
},
{
text: "",
want: "",
},
}
for _, tt := range tests {
t.Run(tt.text, func(t *testing.T) {
// Redirect stdout to a buffer
rescueStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
SimpleDisplay(os.Stdout, tt.text)
w.Close()
got, _ := io.ReadAll(r)
os.Stdout = rescueStdout
assert.Equal(t, tt.want, string(got))
})
}
}
func TestSuccessDisplay(t *testing.T) {
tests := []struct {
text string
want string
}{
{
text: "Test",
want: "Test",
},
{
text: "",
want: "",
},
}
for _, tt := range tests {
t.Run(tt.text, func(t *testing.T) {
// Redirect stdout to a buffer
rescueStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
SuccessDisplay(os.Stdout, tt.text)
w.Close()
got, _ := io.ReadAll(r)
os.Stdout = rescueStdout
assert.Equal(t, tt.want, string(got))
})
}
}
func TestDescriptionDisplay(t *testing.T) {
tests := []struct {
text string
want string
}{
{
text: "Test",
want: "Test",
},
{
text: "",
want: "",
},
}
for _, tt := range tests {
t.Run(tt.text, func(t *testing.T) {
// Redirect stdout to a buffer
rescueStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
DescriptionDisplay(os.Stdout, tt.text)
w.Close()
got, _ := io.ReadAll(r)
os.Stdout = rescueStdout
assert.Equal(t, tt.want, string(got))
})
}
}
func TestBoldDisplay(t *testing.T) {
tests := []struct {
text string
want string
}{
{
text: "Test",
want: "Test",
},
{
text: "",
want: "",
},
}
for _, tt := range tests {
t.Run(tt.text, func(t *testing.T) {
// Redirect stdout to a buffer
rescueStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
BoldDisplay(os.Stdout, tt.text)
w.Close()
got, _ := io.ReadAll(r)
os.Stdout = rescueStdout
assert.Equal(t, tt.want, string(got))
})
}
}
func TestLineDisplay(t *testing.T) {
tests := []struct {
text string
want string
}{
{
text: "Test",
want: "Test",
},
{
text: "",
want: "",
},
}
for _, tt := range tests {
t.Run(tt.text, func(t *testing.T) {
// Redirect stdout to a buffer
rescueStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
LineDisplay(os.Stdout, tt.text)
w.Close()
got, _ := io.ReadAll(r)
os.Stdout = rescueStdout
assert.Equal(t, tt.want, string(got))
})
}
}
func TestSectionHeadingDisplay(t *testing.T) {
tests := []struct {
text string
want string
}{
{
text: "Test Section",
want: "\nTest Section\n────────────\n\n",
},
{
text: "",
want: "\n\n\n\n",
},
}
for _, tt := range tests {
t.Run(tt.text, func(t *testing.T) {
// Redirect stdout to a buffer
rescueStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
SectionHeadingDisplay(os.Stdout, tt.text)
w.Close()
got, _ := io.ReadAll(r)
os.Stdout = rescueStdout
assert.Equal(t, tt.want, string(got))
})
}
}
func TestStarDisplay(t *testing.T) {
tests := []struct {
text string
want string
}{
{
text: "Test",
want: "* Test",
},
{
text: "",
want: "* ",
},
}
for _, tt := range tests {
t.Run(tt.text, func(t *testing.T) {
// Redirect stdout to a buffer
rescueStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
StarDisplay(os.Stdout, tt.text)
w.Close()
got, _ := io.ReadAll(r)
os.Stdout = rescueStdout
assert.Equal(t, tt.want, string(got))
})
}
}
// Returns a new instance of ProgressHandler with the given title.
func TestNewProgressHandler_(t *testing.T) {
tests := []struct {
title string
}{
{
title: "Test title",
},
{
title: "",
},
}
for _, tt := range tests {
t.Run(tt.title, func(t *testing.T) {
progressHandler := NewProgressHandler(tt.title)
assert.NotNil(t, progressHandler)
assert.Equal(t, tt.title, progressHandler.title)
})
}
}

Some files were not shown because too many files have changed in this diff Show More