Compare commits

...

943 Commits

Author SHA1 Message Date
Vlad Klokun
c717a9233b Merge pull request #1046 from fredbi/fix/1040-empty-framework-name
fix ListFrameworks (could return an empty element)
2023-01-20 17:16:31 +02:00
Frédéric BIDON
e37f47de3a fix ListFrameworks (could return an empty element)
Signed-off-by: Frédéric BIDON <fredbi@yahoo.com>
2023-01-20 14:06:51 +01:00
David Wertenteil
2ce37bd66e Merge pull request #1036 from kubescape/update-logs
Update logs
2023-01-13 14:11:49 +02:00
David Wertenteil
13c760c116 Merge branch 'master' into dev 2023-01-13 14:06:54 +02:00
David Wertenteil
c6261e45a8 Merge pull request #1026 from kubescape/fix-command-indentation
Fix command indentation
2023-01-13 13:40:46 +02:00
David Wertenteil
0c06b6c3e6 enable --create-account flag 2023-01-13 13:27:05 +02:00
David Wertenteil
18a9ac3d6e adding debug logs 2023-01-13 13:26:36 +02:00
David Wertenteil
2bfe2a590c Merge pull request #1034 from matthyx/1032
only attempt to print existing attack graphs
2023-01-13 13:24:08 +02:00
David Wertenteil
fb54f4e6cf Merge pull request #945 from suhasgumma/fix-command1
Add support for fixing Individual Files using "fix" command
2023-01-13 13:23:37 +02:00
Vlad Klokun
9025ba5537 chore: reword unsupported scanning target error message 2023-01-13 12:47:07 +02:00
Vlad Klokun
0c23579db7 docs: clarify the comment adjusting the repoRoot 2023-01-13 12:47:07 +02:00
suhasgumma
a755f365df Fixed: Fix not working when multiple individual files are passed 2023-01-13 12:47:07 +02:00
suhasgumma
15f7b9f954 Add Comment 2023-01-13 12:47:07 +02:00
suhasgumma
92a2704fa6 Fix RelSource for Files 2023-01-13 12:47:07 +02:00
Vlad Klokun
a3defe3025 chore: keep CRLF in fixhandler test data file 2023-01-13 12:03:12 +02:00
David Wertenteil
2be0ef48d8 Merge pull request #1007 from matthyx/bitbucket
add support for Bitbucket scanning
2023-01-13 09:51:57 +02:00
Matthias Bertschy
c97513e4e8 only attempt to print existing attack graphs 2023-01-13 08:38:29 +01:00
Matthias Bertschy
1757c891aa add support for Bitbucket scanning 2023-01-13 07:35:07 +01:00
Vlad Klokun
b02410184e fix: follow newline conventions of the autofixed file
This change makes the autofix handler use the newline separator defined
in the fixed file for writing its changes.
2023-01-12 19:25:39 +02:00
David Wertenteil
b4a6a18a56 Merge pull request #1030 from dwertent/master
Update github workflows and temapltes
2023-01-12 14:14:03 +02:00
David Wertenteil
13ca0027a2 upgrade templates 2023-01-12 14:06:04 +02:00
Moshe Rappaport
93b626bb1e Merge pull request #1029 from dwertent/update-workflow
golangci-lint will setup go version 1.19
2023-01-12 13:48:53 +02:00
David Wertenteil
6b4310cd88 golangci-lint - continue-on-error 2023-01-12 13:46:12 +02:00
David Wertenteil
c883a297b3 do not run GH WF on none code dirs 2023-01-12 13:45:10 +02:00
David Wertenteil
3af351d91f Remove new pr welcome bot 2023-01-12 13:40:34 +02:00
David Wertenteil
93cde0f1a0 golangci-lint will setup go version 1.19 2023-01-12 13:38:29 +02:00
David Wertenteil
0a5715393c Merge pull request #1027 from kubescape/hot-fix-v2.0.181
setCloudMetadata only when scanning a cluster
2023-01-11 23:19:28 +02:00
David Wertenteil
9a1cc33efa setCloudMetadata only when scanning a cluster 2023-01-11 23:03:56 +02:00
Vlad Klokun
02720d32dd tests: extend test cases for autofix inserts
This change re-organizes the test cases for inserts performed by the
autofixing feature.
2023-01-11 20:21:22 +02:00
Vlad Klokun
ebada00cf1 tests: show diffs when comparing autofixes
This change refactors the TestApplyFixKeepsFormatting test to use
assert.Equalf so it will display a convenient diff between the expected
and actual fixing result.
2023-01-11 20:21:22 +02:00
Vlad Klokun
3b68fc94d1 tests: test fixing close to newline-separated keys in hybrid scenarios 2023-01-11 20:21:22 +02:00
Vlad Klokun
10d534b5bf tests: test autofixing files with comments between fields 2023-01-11 20:21:22 +02:00
Vlad Klokun
2d740fbf4f tests: test autofixing indented lists in hybrid scenarios 2023-01-11 20:21:22 +02:00
Vlad Klokun
d0728676ee tests: re-organize autofixing unit tests
This change:
- Changes test data naming convention to be lexicographically sortable
  and have input and expected data side-by-side.
- Executes each test case in a separate run.
2023-01-11 20:21:22 +02:00
suhasgumma
8856c84a17 fix: keep user formatting when autofixing 2023-01-11 20:21:12 +02:00
Amir Malka
0c87ff6843 Initial implementation of fix command (#898)
* Fix command initial implementation
2023-01-11 20:18:37 +02:00
David Wertenteil
a48d9be386 Merge pull request #1013 from fredbi/test/more-getter-tests
Refactored LoadPolicy getter, with unit tests
2023-01-11 13:46:08 +02:00
David Wertenteil
3c93c2c45c Merge pull request #1004 from darkweaver87/fix/panic
🐛 fix/panic
2023-01-11 12:06:01 +02:00
David Wertenteil
77e0a04c99 fixed unit test 2023-01-11 11:31:30 +02:00
David Wertenteil
b8762b924c Merge branch 'dev' into test/more-getter-tests 2023-01-11 11:21:43 +02:00
David Wertenteil
025e75213a Merge pull request #1017 from matthyx/remotes
fix: branchRef.Remote can be a gitUrl
2023-01-11 09:01:31 +02:00
Craig Box
c39683872e Initial documentation update upon joining the CNCF (#1020)
* Initial refactor

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

* Initial refactor.

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

* Now how did that get in there?

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

* small fixes

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

* Use GitHub note and warning syntax

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

* second guessing thing with no docs

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

* Final changes

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

Signed-off-by: Craig Box <craigb@armosec.io>
2023-01-11 08:53:55 +02:00
Matthias Bertschy
1a3a58a309 fix: branchRef.Remote can be a gitUrl 2023-01-11 07:48:31 +01:00
Matthias Bertschy
19438e6143 Merge pull request #1012 from anubhav06/azure-scanning
added Azure repo scanning support
2023-01-11 07:21:11 +01:00
Anubhav Gupta
284c8c737b Merge branch 'dev' of https://github.com/anubhav06/kubescape into azure-scanning 2023-01-10 23:30:11 +05:30
Anubhav Gupta
3441a65290 added Azure repo scanning support
Signed-off-by: Anubhav Gupta <mail.anubhav06@gmail.com>
2023-01-10 23:29:35 +05:30
Frederic BIDON
773e43b1e1 refact(getter): refactored loadpolicy
* feat: added support for ListControls and GetFrameworks
* perf: introduced jsoniter unmarshalling for faster decoding
* introduced stricted error handling & predefined errors:
  * suppressed edge cases when a flaky value is returned instead of an error
* added full unit tests of LoadPolicy

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
2023-01-09 14:48:18 +01:00
David Wertenteil
ddc0b2daf2 Merge pull request #1009 from fdingiit/v2.0.180-fix
bug fix for cannot read local artifacts
2023-01-09 13:15:59 +02:00
David Wertenteil
596686602c Merge pull request #1010 from fredbi/chore/slightly-more-linting
Chore/slightly more linting
2023-01-09 13:12:07 +02:00
Rémi BUISSON
5bb0c97f8f fix: panic on non-cluster scan 2023-01-09 10:34:08 +01:00
Rémi BUISSON
256db4abfb Revert "🐛 fix panic"
This reverts commit 08b8ae45432ddab5137b18347190b505f28e8389.
2023-01-09 08:56:48 +01:00
Rémi BUISSON
3546961a5e 🐛 fix panic 2023-01-09 08:56:48 +01:00
Frederic BIDON
e6dc7c2367 added unit tests to load policy getter
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
2023-01-06 12:56:40 +01:00
dingfei
07fa3b4589 bug fix of cannot read local artifacts 2023-01-06 17:28:36 +08:00
Frederic BIDON
d6ed4b1aca finished added linters for this round
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
2023-01-06 09:32:19 +01:00
Frederic BIDON
69846bb4c0 refactored load policy getter for Frameworks
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
2023-01-06 09:32:18 +01:00
Frederic BIDON
2e5ad85fe0 simplified trivial expressions (gosimple)
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
2023-01-06 09:32:18 +01:00
Frederic BIDON
1025431d64 fixed ineffectual assigns
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
2023-01-06 09:32:18 +01:00
Frederic BIDON
1a863473e7 fixed goimports
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
2023-01-06 09:32:17 +01:00
Frederic BIDON
28a44ac531 fixed leaking body on http response (bodyclose)
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
2023-01-06 09:32:17 +01:00
Frederic BIDON
cf484c328b fixed issues reported by gover (e.g. shadowed variables)
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
2023-01-06 09:32:17 +01:00
Frederic BIDON
668514e08d commented currently unused code
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
2023-01-06 09:32:17 +01:00
Frederic BIDON
dc45efb6ef ensured gofmt
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
2023-01-06 09:32:16 +01:00
Frederic BIDON
6d3844f187 follow-up on review following initial relinting
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
2023-01-06 09:32:16 +01:00
Matthias Bertschy
4d6e85d4c7 Merge pull request #969 from fredbi/fix/conditional-build-for-git-support
Fix/conditional build for git support
2023-01-06 09:11:07 +01:00
Frederic BIDON
d336f4484c build(git): added build tag control over native git functionality
* fixes #964

* adapted build and ci to use build tag
* fixup error messages
* report git scan skipped warning & version
* fixed CI on windows: powershell parsing args...
* fixup leftover comment
* fixup typo in test message
* resolved merge conflicts on unit tests
* fix: added gitenabled tag to Makefile target

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
2023-01-05 17:46:51 +01:00
David Wertenteil
bf263d8d51 Merge pull request #1006 from vladklokun/fix-missing-upstream-panic
Fix missing upstream panic
2023-01-05 13:35:03 +02:00
Vlad Klokun
cc3cf1932c style: go fmt the project 2023-01-05 12:49:19 +02:00
Vlad Klokun
6a4dc79689 fix: don’t panic when branch is missing remote and fallback
This change fixes the case in which Kubescape would panic when scanning
a local Git repository that:
- has the current branch that does not have an upstream set
- does not have an `origin` branch to fall back on

The panic happened because we did not check if the `origin` key exists
in the map of upstreams. This change adds a test for this scenario and
makes it pass by checking if the key exists. If it does not, it returns
an error.

Fixes #1005
2023-01-05 12:47:23 +02:00
David Wertenteil
8c189f6e3c Merge pull request #716 from pwnb0y/master
install.ps1 is modified to increase downloading speed as well as show progress bar
2023-01-05 08:28:47 +02:00
David Wertenteil
f1514d6e76 Merge pull request #1002 from kubescape/hot-fix-windows-url
update opa-utils pkg with URL parsing fixed
2023-01-03 22:39:07 +02:00
David Wertenteil
3a038c9a0e update opa-utils pkg with URL parsing fixed 2023-01-03 22:24:37 +02:00
David Wertenteil
b4bdf4d860 Release (#1000)
* fixed flaky loop(cautils): loadpolicy getter

We should not inject pointers to the variable iterated over by the
"range" operator.

Signed-off-by: Frédéric BIDON <fredbi@yahoo.com>

* fixed more flaky pointers in loops (registryadaptors, opaprocessor)

Signed-off-by: Frédéric BIDON <fredbi@yahoo.com>

* fixed more flaky pointers in loops (resultshandling)

Signed-off-by: Frédéric BIDON <fredbi@yahoo.com>

* enabled golangci linter in CI

Signed-off-by: Frédéric BIDON <fredbi@yahoo.com>

* fixed linting issues with minimal linters config

Signed-off-by: Frédéric BIDON <fredbi@yahoo.com>

* bump go version to 1.19

* English and typos

* Support AKS parser (#994)

* support GKE parser

* update go mod

* support GKE parser

* update go mod

* update k8s-interface pkg

* Added KS desgin.drawio

* revert k8s.io to v0.25.3

* ran go mod tidy

* update sign-up url

* [wip] Adding CreateAccount support

* revert to docs URL

* update opa-utils pkg

* Print attack tree (optional, with argument) (#997)

* Print attack tree with the argument


Signed-off-by: Frédéric BIDON <fredbi@yahoo.com>
Co-authored-by: Frédéric BIDON <frederic@oneconcern.com>
Co-authored-by: Frédéric BIDON <fredbi@yahoo.com>
Co-authored-by: Oshrat Nir <45561829+Oshratn@users.noreply.github.com>
Co-authored-by: Amir Malka <amirm@armosec.io>
Co-authored-by: David Wertenteil <dwertent@armosec.io>
2023-01-03 11:30:09 +02:00
Amir Malka
b309cfca7a Print attack tree (optional, with argument) (#997)
* Print attack tree with argument

* fix
2023-01-03 08:46:50 +02:00
David Wertenteil
c4b3ef5b80 Support AKS parser (#994)
* support GKE parser

* update go mod

* Added KS desgin.drawio

* update k8s-interface pkg

* Added KS desgin.drawio

* support GKE parser

* update go mod

* update k8s-interface pkg

* Added KS desgin.drawio

* revert k8s.io to v0.25.3

* ran go mod tidy

* update sign-up url

* [wip] Adding CreateAccount support

* revert to docs URL

* update opa-utils pkg

* update opa-utils pkg
2023-01-03 08:44:29 +02:00
David Wertenteil
aba978e94a Merge pull request #996 from dwertent/bump-go-19
Bump go version to 1.19
2023-01-03 07:35:39 +02:00
David Wertenteil
a49781e9a8 Merge pull request #998 from Oshratn/patch-1
English and typos
2023-01-02 15:10:08 +02:00
Oshrat Nir
3ba19f55f1 English and typos 2023-01-02 14:55:27 +02:00
David Wertenteil
40a9b9406d Merge pull request #984 from fredbi/chore/introduce-linting
Chore/introduce linting
2023-01-02 08:48:14 +02:00
David Wertenteil
d6b8f5862f bump go version to 1.19 2022-12-28 23:18:03 +02:00
Frédéric BIDON
09f13c05e1 fixed linting issues with minimal linters config
Signed-off-by: Frédéric BIDON <fredbi@yahoo.com>
2022-12-26 17:47:10 +01:00
Frédéric BIDON
b1c8872a29 enabled golangci linter in CI
Signed-off-by: Frédéric BIDON <fredbi@yahoo.com>
2022-12-26 17:47:10 +01:00
Frédéric BIDON
22052f5869 fixed more flaky pointers in loops (resultshandling)
Signed-off-by: Frédéric BIDON <fredbi@yahoo.com>
2022-12-26 17:47:10 +01:00
Frédéric BIDON
afce43add6 fixed more flaky pointers in loops (registryadaptors, opaprocessor)
Signed-off-by: Frédéric BIDON <fredbi@yahoo.com>
2022-12-26 17:47:10 +01:00
Frédéric BIDON
4752364699 fixed flaky loop(cautils): loadpolicy getter
We should not inject pointers to the variable iterated over by the
"range" operator.

Signed-off-by: Frédéric BIDON <fredbi@yahoo.com>
2022-12-26 17:47:08 +01:00
David Wertenteil
08e7108dc0 Merge pull request #991 from kubescape/dev
Release
2022-12-22 18:12:37 +02:00
David Wertenteil
108a2d6dd8 Merge pull request #962 from anubhav06/gitlab-scan
added GitLab repo scanning support
2022-12-22 17:29:57 +02:00
David Wertenteil
2c28286bb1 update httphandler go mod 2022-12-22 17:07:47 +02:00
David Wertenteil
79858b7ed7 Merge pull request #975 from kooomix/dev
control scan and download only by id
2022-12-22 16:56:40 +02:00
David Wertenteil
bb2e83eb3b update go-git pkg 2022-12-22 16:55:11 +02:00
David Wertenteil
282a29b971 Merge pull request #990 from dwertent/cloud-name-breakdown
update config scanning path
2022-12-22 16:37:27 +02:00
David Wertenteil
60b9edc463 update config scanning path 2022-12-22 16:14:44 +02:00
David Wertenteil
0f9a5e3127 Merge pull request #989 from dwertent/cloud-name-breakdown
Breakdown cloud-cluster name
2022-12-22 16:03:31 +02:00
David Wertenteil
7c79c14363 Update core/pkg/resultshandling/results.go 2022-12-22 15:00:59 +02:00
Vlad Klokun
fe84225252 feat: notify about writing to an output file in PrettyPrinter 2022-12-22 15:00:59 +02:00
Vlad Klokun
56da8d8d92 style: tidy up the PDFPrinter
- Shorten receiver names
- Modify comments to follow Go Doc convention
2022-12-22 15:00:59 +02:00
Vlad Klokun
f135e95d2c style: shorten receiver names in JUnitPrinter 2022-12-22 15:00:59 +02:00
Vlad Klokun
db34183fc1 style: shorten receiver names in JSONPrinter 2022-12-22 15:00:59 +02:00
Vlad Klokun
8f3af71c84 style: shorten receiver names in HTML Printer 2022-12-22 15:00:59 +02:00
Vlad Klokun
116aee0c9c style: shorten receiver names in PrettyPrinter 2022-12-22 15:00:59 +02:00
Vlad Klokun
e5d44f741d docs: clarify new meaning of the --format CLI flag 2022-12-22 15:00:59 +02:00
Vlad Klokun
f005cb7f80 feat: always print to (T)UI using PrettyPrinter
Prior to this change, `pretty-printer` was a special type of Printer
that wrote output to `Stdout`, unless explicitly asked to write to a
given file. Kubescape used `pretty-printer` as an output format by
default. This behavior created the following inconsistencies:
- When invoked as `kubescape scan`, Kubescape would use `pretty-printer`
  by default, and it would output the scan resluts in the
  `pretty-printer` format to `Stdout`.
- When invoked as `kubescape scan --format=pretty-printer`, the behavior
  would be as above.
- When invoked as `kubescape scan --format=FORMAT`, where `FORMAT` is any
  format except for `pretty-printer`, Kubescape would write the results
  to a sensible default file for the selected format. This is in
  contrast to how `--format=pretty-printer` would still output to
  `os.Stdout`, and not an output file.
- When invoked as `kubescape scan --format=ANY_FORMAT --output=FILENAME`, where
  `ANY_FORMAT` is any format, including `pretty-printer`, Kubescape
  would write the results to the provided `FILENAME` in the given
  `ANY_FORMAT`, and not write any results to `Stdout`.

The aforementioned situation complicates life for users running
Kubescape in CI, where Kubescape would skip writing the results to
`Stdout` and only write to the provided output file.

Moreover, with the addition of support for multiple output formats and,
hence, files, this introduces the following ambiguity:
- When invoked as `kubescape scan --format=json,pdf,pretty-printer
  --output=FILENAME`, should Kubescape treat `pretty-printer` as a
  format for the output file, or just an instruction to also print the
  results to `Stdout`?

To fix these inconsistencies and ambiguities, this commit introduces the
following changes:

- Kubescape will always print results to `Stdout` using the
  PrettyPrinter format.

- The `--format` CLI flag will control the format(s) in which the results
  will be written to one or many *output* files. This breaks the
  previous behavior that running `kubescape scan
  --format=pretty-printer` would not produce an output file, and only
  write to `Stdout`. After this change, the same invocation will still
  write to `Stdout`, but also produce a `report.txt` file in the
  PrettyPrinter format.
2022-12-22 15:00:59 +02:00
Vlad Klokun
9ae9d35ccb style: GetFormatsFormats 2022-12-22 15:00:59 +02:00
Vlad Klokun
cb38a4e8a1 style: go fmt the project
- Fixes style inside the project with `go fmt`
2022-12-22 15:00:59 +02:00
Vlad Klokun
eb6d39be42 style: shorten receiver names in ResultsHandler 2022-12-22 15:00:59 +02:00
Vlad Klokun
3160d74c42 style: shorten receiver names for Prometheus printer 2022-12-22 15:00:59 +02:00
Vlad Klokun
5076c38482 refactor: tidy up printing to multiple outputs
This change:

- Simplifies printing to multiple outputs.
- Adds a comment on why we keep the Print → Score → Submit order when
  outputting results.
2022-12-22 15:00:59 +02:00
Vlad Klokun
73c55fe253 fix: revert the overriden ScanningTarget when submitting reports
Before this change, we used to override a scan info `ScanningTarget` to
submit a result that is compatible with the backend for Kubescape.
However, previously we forgot to change back to the original value.

When printing scan results, if the correct order of events (Print →
Score → Submit) was not enforced, this broke the SARIF printer so that
it did not output results due to incorrect `basePath` for the results.

This change reverts to the original `ScanningTarget` value after
submitting the results and fixes the SARIF printer.
2022-12-22 15:00:59 +02:00
suhasgumma
f48f81c0b5 Add logs for some formats 2022-12-22 15:00:59 +02:00
Suhas Gumma
81c1c29b7c Update core/pkg/resultshandling/printer/printresults.go
Co-authored-by: Vlad Klokun <vladklokun@users.noreply.github.com>
2022-12-22 15:00:59 +02:00
suhasgumma
874aa38f68 Handle Output Extensions Gracefully 2022-12-22 15:00:59 +02:00
suhasgumma
b9caaf5025 Add logs for some formats 2022-12-22 15:00:59 +02:00
suhasgumma
61c120de0e Support getting outputs in multiple formats 2022-12-22 15:00:59 +02:00
kooomix
de3408bf57 minor fix 2022-12-22 14:09:27 +02:00
David Wertenteil
8d32032ec1 Merge branch 'cloud-name-breakdown' of github.com:dwertent/kubescape into cloud-name-breakdown 2022-12-22 13:33:23 +02:00
David Wertenteil
42ed787f7b update go mod in httphandler 2022-12-22 13:32:27 +02:00
David Wertenteil
ccdba85b3c Merge branch 'dev' into cloud-name-breakdown 2022-12-22 11:57:47 +02:00
David Wertenteil
c59f7691dc Breakdown cloud-cluster name 2022-12-22 11:43:45 +02:00
kooomix
cf87c2d30b Fixed test 2022-12-21 19:25:22 +02:00
kooomix
b547814dec DownloadInfo, PolicyIdentifier add Identity, remove ID and Name 2022-12-21 19:17:29 +02:00
kooomix
b476a72e04 Merge branch 'dev' of github.com:kooomix/kubescape into dev 2022-12-21 17:02:24 +02:00
kooomix
4f6f85710a Merge pull request #988 from kooomix/opa_utils-v.0.0.216
opa-utils v0.0.216
2022-12-21 16:06:34 +02:00
kooomix
47c23de160 opa-utils v0.0.216 2022-12-21 15:46:53 +02:00
kooomix
bc85844ec0 Merge branch 'kubescape:dev' into dev 2022-12-21 15:31:07 +02:00
kooomix
134d854722 opa-utils v0.0.216 2022-12-21 15:29:58 +02:00
David Wertenteil
e3522c19cc Merge pull request #986 from dwertent/master
Cosmetic changes
2022-12-20 10:33:21 +02:00
David Wertenteil
967fc3fe81 ignore resource if it is not found 2022-12-19 19:00:21 +02:00
David Wertenteil
896a0699ec remove image vuln warning 2022-12-18 13:45:43 +02:00
David Wertenteil
a53375204e remove --verbose flag from default 2022-12-18 13:44:12 +02:00
David Wertenteil
b1392361f8 remove emoji from display 2022-12-18 13:42:58 +02:00
David Wertenteil
7b4fbffae2 Merge pull request #976 from mkilchhofer/explicit_allowPrivilegeEscalation
chore: Explicit set allowPrivilegeEscalation=true
2022-12-18 08:09:35 +02:00
David Wertenteil
34e7b9f2ad Merge pull request #978 from kubescape/maintainers
Update maintainers
2022-12-18 08:08:20 +02:00
David Wertenteil
f0080bdeae Merge pull request #979 from craigbox/code-of-conduct
Adopt CNCF Code of Conduct.
2022-12-18 08:07:39 +02:00
Craig Box
0eb27389da Adopt CNCF Code of Conduct.
Signed-off-by: Craig Box <craigb@armosec.io>
2022-12-16 21:46:31 +13:00
craigbox
2c5eed9ee2 Update maintainers
- Add self
- Remove e-mail addresses & job roles
2022-12-16 21:19:02 +13:00
David Wertenteil
2c1a5bd032 Merge pull request #977 from kubescape/revert-973-dev
Revert "Excluding controlPlaneInfo from error message in case no data recieved."
2022-12-15 17:48:32 +02:00
David Wertenteil
298f8346e9 validate downloaded framework 2022-12-15 17:13:14 +02:00
kooomix
1897c5a4ba Revert "Excluding controlPlaneInfo from error message in case no data recieved." 2022-12-15 16:17:39 +02:00
Marco Kilchhofer
57e435271e chore: Explicit set allowPrivilegeEscalation=true
The value of allowPrivilegeEscalation followed implicit default of Kubernetes:
> AllowPrivilegeEscalation is true always when the container is:
> 1) run as Privileged
> 2) has CAP_SYS_ADMIN

For users still using PodSecurityPolicy (or a follow-up product like OPA Gatekeeper or
Kyverno), there might be mutating admission controllers which defaults this field to
`false` if unset. A value of `false` would then conflict with `privileged: true`.

Signed-off-by: Marco Kilchhofer <mkilchhofer@users.noreply.github.com>
2022-12-14 22:27:05 +01:00
kooomix
7e9b430347 test fix 2022-12-14 14:22:46 +02:00
kooomix
ca5b3e626b test fix 2022-12-14 14:08:32 +02:00
kooomix
3a404f29fa control scan by id 2022-12-14 13:42:52 +02:00
kooomix
16073d6872 download control only by id 2022-12-14 13:06:04 +02:00
Rotem Refael
dce563d2f5 Merge pull request #973 from kooomix/dev
Excluding controlPlaneInfo from error message in case no data recieved.
2022-12-14 11:02:55 +02:00
kooomix
8d556a5b84 minor 2022-12-14 10:48:01 +02:00
kooomix
a61063e5b8 revert opa-utils version 2022-12-14 10:45:24 +02:00
kooomix
94973867db Merge branch 'kubescape:dev' into dev 2022-12-14 10:23:11 +02:00
kooomix
214c2dcae8 patch to filter out "controlPlaneInfo" from error messages in case no data 2022-12-14 10:19:24 +02:00
David Wertenteil
72b36bf012 Merge pull request #968 from fredbi/chore/package-name
chore(style): renamed versioned packages to stick to idiomatic conventions
2022-12-13 16:52:57 +02:00
Frederic BIDON
4335e6ceac chore(style): renamed versioned packages to stick to idiomatic conventions
* fixes: #967

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
2022-12-13 14:27:21 +01:00
kooomix
b5f92a7d54 go mod tidy 2022-12-13 11:32:23 +02:00
kooomix
41ec75d264 update opa-utils v0.0.209 2022-12-13 11:20:17 +02:00
kooomix
6d6ad1f487 Merge pull request #963 from kooomix/outputs_to_get_controls_only_by_ids
All prints and outputs to get data only by control ID
2022-12-13 08:32:01 +02:00
kooomix
3ac33d21ac All prints and outputs to get data by control ID 2022-12-12 15:20:48 +02:00
Anubhav Gupta
04e4b37f6f added GitLab repo scanning support
Signed-off-by: Anubhav Gupta <mail.anubhav06@gmail.com>
2022-12-11 21:39:28 +05:30
David Wertenteil
3e5903de6a Merge pull request #961 from kubescape/dev
change linux runner to 20.04 instead of ubuntu-latest (#960)
2022-12-11 15:02:04 +02:00
Moshe Rappaport
04ea0fe524 change linux runner to 20.04 instead of ubuntu-latest (#960)
Co-authored-by: Amir Malka <amirm@armosec.io>
2022-12-11 14:20:28 +02:00
David Wertenteil
955d6751a9 Merge pull request #956 from kubescape/dev
Enhance `host-scanner`
2022-12-08 22:51:26 +02:00
David Wertenteil
30c43bff10 Merge pull request #958 from Moshe-Rappaport-CA/dev
Fix Junit format
2022-12-08 19:41:31 +02:00
Moshe-Rappaport-CA
e009244566 Fix Junit format 2022-12-08 17:56:16 +02:00
David Wertenteil
3d3cd2c2d8 Added Kubescape flow.drawio 2022-12-06 15:44:34 +02:00
David Wertenteil
f5498371ec Merge pull request #942 from kooomix/eran-dev
new host-scanner endpoint - cloudProviderInfo
2022-12-06 15:20:24 +02:00
David Wertenteil
c3b95bed8c Merge branch 'dev' into eran-dev 2022-12-06 14:17:49 +02:00
David Wertenteil
8ce7d6c0f6 Merge pull request #930 from JusteenR/issue929
Issue929
2022-12-06 14:15:35 +02:00
David Wertenteil
e875f429a9 Merge pull request #948 from YiscahLevySilas1/dev
Print host scanner version
2022-12-06 14:13:47 +02:00
David Wertenteil
b6beff0488 Merge pull request #946 from suhasgumma/dev
Fixed: CIS control link not working for html output format
2022-12-06 14:13:06 +02:00
David Wertenteil
60c69ac3f0 Merge pull request #950 from fredbi/fix-789
fix(giturlparse): fixes panic on unexpected gitlab remote URL
2022-12-06 14:12:25 +02:00
David Wertenteil
1fb9320421 Merge pull request #941 from dwertent/master
Updating examples
2022-12-06 14:11:07 +02:00
David Wertenteil
9a176f6667 remove tag latest 2022-12-06 11:42:34 +02:00
David Wertenteil
96ea9a9e42 fixed scanning example 2022-12-06 11:41:12 +02:00
David Wertenteil
e39fca0c11 do not build dev images 2022-12-06 11:05:21 +02:00
David Wertenteil
2ec035005d fixed echo command 2022-12-04 15:45:23 +02:00
Frederic BIDON
b734b3aef0 go mod tidy ancillary modules manifest
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
2022-12-04 12:39:34 +01:00
yiscah
0f5635f42d move parsing of version to GetVersion 2022-12-04 12:17:04 +02:00
Frederic BIDON
8557075b7c fix(giturlparse): fixes panic on unexpected gitlab remote URL
* replaced dependencies to github.com/armosec/go-git-url by
github.com/kubescape/go-git-url
* fixes #789

NOTE: this requires kubescape/go-git-url#2 to be merged, a new release
of that repo to be cut, in order to finalize the dependency update.

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
2022-12-02 16:09:25 +01:00
David Wertenteil
bc0f0e7087 Merge branch 'master' of github.com:dwertent/kubescape 2022-12-02 02:31:14 +02:00
David Wertenteil
8ce5f9aea3 fixed typo 2022-12-02 02:30:35 +02:00
David Wertenteil
050f9d3a4e Update cmd/scan/framework.go
Co-authored-by: craigbox <craig.box@gmail.com>
2022-12-02 02:16:43 +02:00
David Wertenteil
a81bf0deb4 deprecate set-output 2022-12-02 01:43:45 +02:00
David Wertenteil
2059324c27 testing release 2022-12-02 01:35:57 +02:00
David Wertenteil
a09a0a1bca Merge pull request #9 from dwertent/fix-dev-image
run build only if secret is set
2022-12-02 01:32:26 +02:00
David Wertenteil
83712bb9f5 run build only if secret is set 2022-12-02 01:30:24 +02:00
David Wertenteil
728ae47b9a Merge pull request #8 from dwertent/fix-dev-image
Fix dev image
2022-12-02 00:56:12 +02:00
David Wertenteil
2a9b272a14 tagging only main image as latest 2022-12-02 00:54:03 +02:00
David Wertenteil
8662deac43 update repository scanning URL 2022-12-02 00:42:28 +02:00
yiscah
e42644bbd8 update hostscanner version 2022-12-01 08:57:58 +02:00
YiscahLevySilas1
07d30b6272 Merge branch 'kubescape:dev' into dev 2022-11-30 20:52:48 +02:00
yiscah
2a4f8543cc added logs of host scanner version 2022-11-30 20:51:45 +02:00
suhasgumma
186b293cce fix link for cis controls in html output 2022-11-30 01:23:45 +05:30
David Wertenteil
2bfe72f39d Merge pull request #944 from kooomix/dev
opa-utils adjustments + dataControlInputs support
2022-11-29 19:11:49 +02:00
kooomix
f99f955223 go mod tidy 2022-11-29 15:26:30 +02:00
kooomix
ec56e69a3c minor fix 2022-11-29 14:55:30 +02:00
kooomix
3942583b1d Merge pull request #1 from kooomix/dataControlInputs
update opa-utils functions
2022-11-29 14:35:08 +02:00
kooomix
a10b15ba4b update opa-utils functions 2022-11-29 14:29:33 +02:00
David Wertenteil
5003cbd7a8 Merge pull request #943 from suhasgumma/invalidformat
Handle Invalid Formats
2022-11-28 17:39:14 +02:00
kooomix
481a137c23 Update host-scanner image version to v1.0.38 2022-11-28 16:46:32 +02:00
suhasgumma
c3f7f0938d Handle Invalid Formats 2022-11-28 19:56:27 +05:30
kooomix
b1925fa38d Support in new host-scanner endpoint - cloudProviderInfo 2022-11-28 09:18:43 +02:00
David Wertenteil
d9f8a7a46f Merge pull request #918 from suhasgumma/dev1
Store Git Repo's root path as localRootPath
2022-11-27 16:25:24 +02:00
David Wertenteil
846a072bf9 Merge pull request #917 from suhasgumma/dev
Fixed: Wrong Relative Path When scanning Local Directory
2022-11-27 16:24:19 +02:00
kooomix
5dd7bbd8a7 Merge pull request #938 from kooomix/eran-dev
Added cloudProvider to postureControlInputs
2022-11-27 09:06:56 +02:00
kooomix
e1773acf24 Getting cloud provider from gitversion of discovered API version 2022-11-25 09:27:27 +02:00
kooomix
03a0f97669 Getting cluster name from context 2022-11-24 16:09:05 +02:00
David Wertenteil
917a3f41e8 Merge pull request #925 from amirmalka/dev
Omit raw resources flag in json output
2022-11-24 14:47:14 +02:00
David Wertenteil
3c8da1b299 supporting client type from env 2022-11-24 11:09:30 +02:00
David Wertenteil
c61c7edbd0 update examples 2022-11-24 11:06:37 +02:00
kooomix
53402d9a1c Added "CloudProvider" to postureControlInputs 2022-11-23 11:57:36 +02:00
David Wertenteil
de9278b388 Merge pull request #935 from mkilchhofer/bugfix/use_correct_directory
fix: filepath.Dir requires trailing slash
2022-11-23 10:49:16 +02:00
Marco Kilchhofer
4fef6200f8 fix: filepath.Dir requires trailing slash
Signed-off-by: Marco Kilchhofer <mkilchhofer@users.noreply.github.com>
2022-11-22 21:26:37 +01:00
JusteenR
81771b7bd7 Adding frameworks column to control command 2022-11-20 15:42:13 -08:00
Moshe Rappaport
2fee77c42c Merge pull request #928 from Moshe-Rappaport-CA/PER-633-support-loading-exceptions-from-cache-kubescape
PER-633 support loading exceptions from cache
2022-11-20 14:09:30 +02:00
Moshe-Rappaport-CA
968ecdb31d PER-633 support loading exceptions from cache 2022-11-20 12:22:15 +02:00
David Wertenteil
af7b36a88b Merge pull request #927 from Moshe-Rappaport-CA/PER-550-support-loading-attack-tracks-from-cache-kubescape
Per 550 support loading attack tracks from cache kubescape
2022-11-20 11:24:38 +02:00
Moshe-Rappaport-CA
6ad58d38e2 PER-550 Support loading attack tracks from cache 2022-11-17 16:31:51 +02:00
Moshe-Rappaport-CA
681b4ce155 stash 2022-11-17 10:49:36 +02:00
Moshe Rappaport
9d21ac1b16 Merge pull request #924 from Moshe-Rappaport-CA/dev
revert change in Junit format
2022-11-16 15:36:48 +02:00
Amir Malka
2b3fcca7e8 omit raw resources flag in json output 2022-11-16 12:15:17 +02:00
David Wertenteil
af8e786ab5 Merge pull request #914 from kubescape/dev
Closing issues
2022-11-16 10:59:59 +02:00
Moshe-Rappaport-CA
c8df1b8f1f Merge remote-tracking branch 'armo/dev' into dev 2022-11-15 17:34:45 +02:00
Moshe-Rappaport-CA
4f921ddf6f Revert PR #802 to the old junit format 2022-11-15 16:59:37 +02:00
David Wertenteil
4f5839870b Merge pull request #920 from amirmalka/dev
Fixed docker build to support ARM #919
2022-11-15 14:53:20 +02:00
Amir Malka
c0d7f51d6c test build flow 2022-11-15 13:29:35 +02:00
Amir Malka
a81d770360 fixed docker build to support arm 2022-11-15 10:57:29 +02:00
suhasgumma
f64d5eab50 Fix RootDir Info 2022-11-15 12:38:57 +05:30
suhasgumma
d773397fe9 replace src with RelSrc 2022-11-15 10:34:36 +05:30
suhasgumma
2e30995bfc Relative Path When scanning Local Repos 2022-11-15 10:22:04 +05:30
David Wertenteil
17a2547f18 Merge pull request #915 from kubescape/change-test-control-name
replace control 0006 by 0048
2022-11-14 14:56:34 +02:00
David Wertenteil
87a5cd66c8 replace control 0006 by 0048 2022-11-14 14:36:37 +02:00
David Wertenteil
9436ace64f continue when resource not found 2022-11-14 13:52:46 +02:00
David Wertenteil
fde00f6bd8 Merge pull request #909 from suhasgumma/dev
pretty-print Controls format  made Pretty
2022-11-13 17:04:46 +02:00
David Wertenteil
04a72a069a Merge pull request #913 from dwertent/ignore-missing-resource
Do not exit on error
2022-11-13 16:04:15 +02:00
David Wertenteil
e2dcb5bc15 Merge pull request #912 from dwertent/dep-rbac-submit
Deprecate rbac submit
2022-11-13 16:03:51 +02:00
suhasgumma
c7040a257c Pretty Print frameworks and exceptions 2022-11-13 19:29:26 +05:30
suhasgumma
602dc00c65 Shift GetControlLink to cautils 2022-11-13 19:09:30 +05:30
David Wertenteil
0339691571 Merge pull request #911 from dwertent/adding-remidiation
Adding remediation
2022-11-13 15:12:21 +02:00
David Wertenteil
9e1f3ec131 remove from smoke test 2022-11-13 15:10:05 +02:00
David Wertenteil
b8589819dc Do not exit on error 2022-11-13 15:06:32 +02:00
David Wertenteil
a3e87f4c01 Updating json v1 deprecation message 2022-11-13 15:03:22 +02:00
David Wertenteil
21ab5a602e Deprecate rbac submit 2022-11-13 15:01:32 +02:00
David Wertenteil
5d97d7b4b2 adding Remediation to message 2022-11-13 14:55:52 +02:00
suhasgumma
d8d7d0b372 Updated and Used GetControlLink 2022-11-13 17:56:39 +05:30
suhasgumma
b8323d41fc Modified Link Convention for CIS Controls 2022-11-13 17:22:37 +05:30
suhasgumma
d0b5314201 Improve Code Quality 2022-11-13 15:39:04 +05:30
suhasgumma
547e36e73f Pretty Print Controls made Pretty 2022-11-13 14:29:30 +05:30
David Wertenteil
e593a772cb Merge pull request #908 from Moshe-Rappaport-CA/update-k8s-interface-version
Update k8s-interface version and rbac-utils
2022-11-13 09:31:00 +02:00
Moshe-Rappaport-CA
4da09529b6 Update rbac-utils tag 2022-11-10 18:56:28 +02:00
Moshe-Rappaport-CA
de375992e8 Fix go.mod in httphandler 2022-11-10 17:54:44 +02:00
Moshe-Rappaport-CA
0bc4a29881 Update k8s-interface version 2022-11-10 17:38:32 +02:00
David Wertenteil
9575c92713 Merge pull request #906 from suhasgumma/dev
Fixed: Empty Lines before printing Controls and Added Invalid Format Error
2022-11-10 11:27:22 +02:00
David Wertenteil
cf277874eb Merge pull request #907 from matthyx/ioutil
remove deprecated ioutil package
2022-11-10 11:23:10 +02:00
Matthias Bertschy
746e060402 remove deprecated ioutil package 2022-11-10 09:58:07 +01:00
suhasgumma
dd3a7c816e Invalid Format Error 2022-11-10 11:57:57 +05:30
suhasgumma
814bc3ab2c Solved: Empty Lines before printing Controls 2022-11-10 11:17:48 +05:30
David Wertenteil
dbaf6761df Merge pull request #905 from matthyx/900
900
2022-11-10 06:52:34 +02:00
Matthias Bertschy
580e45827d add IDs to controls list, deprecate id flag 2022-11-09 22:08:04 +01:00
David Wertenteil
f3b8de9d1f fixing readme (#899) 2022-11-08 12:02:52 +02:00
David Wertenteil
fb1c728b12 Merge pull request #897 from Moshe-Rappaport-CA/fix-use-artifact-from
Fix reading frameworks from local file
2022-11-06 17:34:44 +02:00
Moshe-Rappaport-CA
6964ca0d18 Fix reading frameworks from local file 2022-11-06 17:06:27 +02:00
David Wertenteil
6e9a2f55fd Merge pull request #894 from kubescape/dev
Enhancing CLI capabilities and SARIF output
2022-11-06 15:40:00 +02:00
David Wertenteil
691fa61362 Merge pull request #896 from kubescape/revert-submit-dep
Revert submit deprecation
2022-11-06 15:06:49 +02:00
David Wertenteil
0c1eda0d08 retrieve submit flag 2022-11-03 20:33:10 +02:00
David Wertenteil
767eac2fa6 fixed indentation 2022-11-03 20:31:59 +02:00
David Wertenteil
6f651fa2d0 Merge pull request #893 from amirmalka/dev
Added line and column information when using the SARIF format
2022-11-03 15:38:33 +02:00
Amir Malka
e3362c2e3d updated go.mod 2022-11-03 14:38:07 +02:00
Amir Malka
08b8b68f9a added line and column information when using the sarif format 2022-11-03 14:08:53 +02:00
Amir Malka
daf9ca9e7f Merge pull request #825 from AvineshTripathi/feature
added adaptor
2022-11-03 12:48:23 +02:00
Amir Malka
d1024359c9 fix dependencies 2022-11-03 12:15:13 +02:00
Amir Malka
ed6070aff9 fix go.sum 2022-11-03 12:10:34 +02:00
Amir Malka
e4dbfa3534 Merge branch 'dev' into feature 2022-11-03 11:05:10 +02:00
Avinesh Tripathi
ddd2b707c0 updated go.mod 2022-11-03 14:17:53 +05:30
David Wertenteil
cd4f1077c2 Merge pull request #892 from Moshe-Rappaport-CA/dev
Add support to exceptions on repo (files) scan
2022-11-03 10:07:10 +02:00
Moshe-Rappaport-CA
b472d1cb9d Remove irrelevant code 2022-11-03 09:52:36 +02:00
David Wertenteil
922e2548f4 Merge pull request #888 from suhasgumma/dev
Inform User if something is wrong with "controls-inputs" file they provided
2022-11-03 09:38:27 +02:00
suhasgumma
45caa7c120 Adding Log in Caller Function 2022-11-03 07:35:52 +05:30
Moshe-Rappaport-CA
670ae45d62 remove --submit from msg when not submitted 2022-11-02 16:27:40 +02:00
Moshe-Rappaport-CA
05bcf018d1 Merge remote-tracking branch 'armo/dev' into dev 2022-11-02 15:02:30 +02:00
David Wertenteil
0af5d2e0bb Merge pull request #876 from Moshe-Rappaport-CA/PER-335-removing-support-for-submitting-results-without-accountid
Per 335 removing support for submitting results without accountid
2022-11-02 12:55:20 +02:00
Moshe-Rappaport-CA
eaf05fe9be Add support to exceptions on repo (files) scan 2022-11-02 12:49:14 +02:00
David Wertenteil
e97b23f345 remove platforms build 2022-11-02 12:45:18 +02:00
David Wertenteil
83a00ded3d removed log 2022-11-02 12:43:03 +02:00
Avinesh Tripathi
78f81cc968 Merge branch 'dev' into feature 2022-10-31 21:56:13 +05:30
Avinesh Tripathi
5d3347b4fe Added Path variables for credentials 2022-10-31 21:54:10 +05:30
David Wertenteil
64d2ef8170 Merge pull request #887 from Moshe-Rappaport-CA/dev
Support downloading system-exception from GitHub
2022-10-30 12:57:49 +02:00
suhasgumma
7c1e360b9a Error Info Added 2022-10-28 18:25:10 +05:30
Moshe Rappaport
575d36dcde Update core/core/initutils.go
Co-authored-by: David Wertenteil <dwertent@armosec.io>
2022-10-27 18:30:06 +03:00
Moshe-Rappaport-CA
8dba8f7491 Add go sum 2022-10-27 18:25:46 +03:00
Moshe-Rappaport-CA
cc39e5b905 Fix go mod and go sum 2022-10-27 18:18:26 +03:00
Moshe-Rappaport-CA
0be7e6018f Support downloading system-exception from GitHub 2022-10-27 17:59:41 +03:00
David Wertenteil
7697e3f0c4 Merge pull request #884 from Moshe-Rappaport-CA/dev
Scanning with include or exclude namespace, is only scan namespaced scope
2022-10-26 19:04:02 +03:00
David Wertenteil
379800c49f Merge pull request #885 from vladklokun/per-519-add-sarif-printer
feat: support the SARIF output format
2022-10-26 19:02:21 +03:00
Vlad Klokun
79e2515807 feat: support the SARIF output format 2022-10-26 18:13:37 +03:00
Moshe-Rappaport-CA
342f5743e2 Fix when running with include or exclude namespace
scanning only namespaced scope
2022-10-26 16:29:55 +03:00
David Wertenteil
0e81870b85 Merge pull request #799 from itsCheithanya/master
Add update command for kubescape
2022-10-26 15:46:03 +03:00
David Wertenteil
dd7a8fd0c1 Merge pull request #883 from kubescape/dev
Minor changes
2022-10-26 13:31:04 +03:00
David Wertenteil
4277331ee2 Merge pull request #882 from dwertent/master
Update README links
2022-10-26 13:04:00 +03:00
David Wertenteil
53561a728f Merge pull request #872 from BhairaviSanskriti/dev
Added tutorial for scanning container image registry
2022-10-26 13:00:45 +03:00
David Wertenteil
d0fd8c4fe4 Merge pull request #869 from shm12/master
APIServerInfo resource added to the scan
2022-10-26 12:59:51 +03:00
David Wertenteil
398989510b Merge pull request #881 from YiscahLevySilas1/dev
update hostsensor version
2022-10-26 12:56:55 +03:00
Amir Malka
f8e3ad5685 Merge pull request #845 from mrueg/Yamlv3
Upgrade to gopkg.in/yaml.v3
2022-10-26 12:56:31 +03:00
Moshe-Rappaport-CA
fbea7ef874 Merge remote-tracking branch 'armo/dev' into dev 2022-10-26 12:11:42 +03:00
YiscahLevySilas1
dc2c6f8a21 update hostsensor version 2022-10-26 11:40:28 +03:00
Amir Malka
5ee08583b6 Merge pull request #880 from amirmalka/dev
commented out tests which made actual http calls
2022-10-25 18:45:38 +03:00
Amir Malka
bfbd278e7c commented out tests which made actual http calls 2022-10-25 18:26:07 +03:00
David Wertenteil
4c6e5903e3 Adding links to readme 2022-10-25 09:49:43 +03:00
David Wertenteil
a7cd5672c1 Merge remote-tracking branch 'armosec/dev' 2022-10-24 17:23:41 +03:00
David Wertenteil
3373b728b7 Merge pull request #877 from kubescape/dev
Enhance configuration usage
2022-10-24 12:00:27 +03:00
David Wertenteil
22521b7159 use os path join in build file 2022-10-24 11:39:37 +03:00
David Wertenteil
e5fb14138e adding github token 2022-10-23 20:48:36 +03:00
David Wertenteil
1b2242330c comment out image release 2022-10-23 20:35:13 +03:00
David Wertenteil
356958cc55 Merge branch 'dev' of https://github.com/kubescape/kubescape into dev 2022-10-23 20:30:18 +03:00
Moshe Rappaport
8f1da32001 Store default URLs in cache (#875) 2022-10-23 20:29:25 +03:00
Moshe-Rappaport-CA
686352a397 PER-335 Fix comments 2022-10-23 16:54:16 +03:00
Moshe-Rappaport-CA
ef79c42ebc PER-335 Add comment 2022-10-23 16:25:47 +03:00
Moshe-Rappaport-CA
c8fc5378c1 PER-335 Remove submit option from kubescape docs 2022-10-23 16:19:38 +03:00
David Wertenteil
c296666d8e removed path from dockerfile 2022-10-23 16:00:10 +03:00
Moshe-Rappaport-CA
f193e260b0 Store default URLs in cache 2022-10-23 15:56:49 +03:00
Moshe-Rappaport-CA
82981a9a54 PER-335 Removing support for submitting results without accountID 2022-10-23 13:48:50 +03:00
David Wertenteil
3be54ca484 fixed typo 2022-10-23 12:35:54 +03:00
shm12
2f2c177674 Merge pull request #873 from shm12/dev
Fixed host-sensor control plane info collecting
2022-10-23 11:12:07 +03:00
shm12
1f47223918 Fixed host-sensor control plane info collecting 2022-10-23 10:46:44 +03:00
Sanskriti
eb646696a3 Update README.md
This is a video tutorial by Kunal Kushwaha on how to scan a container image registry.
2022-10-21 10:42:02 +05:30
Moshe Rappaport
7cfe5160d5 Merge pull request #871 from Moshe-Rappaport-CA/dev
Support for getting backend URLs from ENV
2022-10-20 10:44:32 +03:00
Moshe-Rappaport-CA
95135c4379 following review 2022-10-19 18:52:32 +03:00
Moshe-Rappaport-CA
7e604d6a5b Merge remote-tracking branch 'armo/dev' into dev 2022-10-19 13:29:09 +03:00
Moshe-Rappaport-CA
64ac2666f9 Support for getting backend URLs from ENV 2022-10-19 13:28:44 +03:00
Avinesh Tripathi
05b3459342 Merge branch 'dev' into feature 2022-10-19 13:44:27 +05:30
shm12
92ad5f2407 Merge pull request #868 from shm12/dev
New host sensor endpoint `controlPlaneInfo` and OPA upgrade
2022-10-18 16:14:36 +03:00
shm12
e3c60e3202 APIServerInfo resource added to the scan 2022-10-12 22:52:42 +03:00
shm12
7b5bcb05b1 Upgrade opa dependency 2022-10-12 20:51:50 +03:00
shm12
154f94a0af Added controlPlaneInfo host-sensor endpoint 2022-10-12 20:51:06 +03:00
David Wertenteil
063d3ee313 Adopt custom cluster name (#862)
* change user to ks

* update logs

* host scanner with fixed version

* testing gh actions

* testing gh actions

* Workflow call testing (#7)

* testing gh actions

* testing gh actions

* remove deps

* build multi platforms

* workflow_call testing

* adding workflow-call-testing branch name

* specify URL

* adding org name

* adding workflows

* cleaning from unused branches

* Adopt custom cluster name
2022-10-06 11:04:05 +03:00
David Wertenteil
79859d05c0 Merge remote-tracking branch 'armosec/dev' 2022-10-06 08:16:27 +03:00
David Wertenteil
acd3a94c46 Adopt custom cluster name 2022-10-06 08:15:58 +03:00
Alessio Greggi
13f09315e7 feat: add --kubeconfig flag (#858)
* feat: add --kubeconfig flag

* docs: add kubeconfig flag example
2022-10-06 08:11:42 +03:00
Manuel Rüger
890528bf14 Update go.mod 2022-10-03 21:21:31 +02:00
Manuel Rüger
e4aafcf81e Migrate to yaml.v3 2022-10-03 21:20:15 +02:00
David Wertenteil
81c3c34ab8 Use workflow_call (#859)
* change user to ks

* update logs

* host scanner with fixed version

* testing gh actions

* testing gh actions

* Workflow call testing (#7)

* testing gh actions

* testing gh actions

* remove deps

* build multi platforms

* workflow_call testing

* adding workflow-call-testing branch name

* specify URL

* adding org name

* adding workflows

* cleaning from unused branches
2022-10-03 14:36:44 +03:00
David Wertenteil
b7b83b26b5 cleaning from unused branches 2022-10-03 14:35:07 +03:00
David Wertenteil
639cd3dfae Merge branch 'master' of github.com:dwertent/kubescape 2022-10-03 13:52:44 +03:00
David Wertenteil
7cf1302e8a Workflow call testing (#7)
* testing gh actions

* testing gh actions

* remove deps

* build multi platforms

* workflow_call testing

* adding workflow-call-testing branch name

* specify URL

* adding org name

* adding workflows
2022-10-03 13:48:50 +03:00
David Wertenteil
dd5dd53a38 testing gh actions 2022-10-03 09:10:08 +03:00
David Wertenteil
7275b8eac7 testing gh actions 2022-10-03 09:09:50 +03:00
David Wertenteil
408c6fc998 Merge branch 'master' of github.com:dwertent/kubescape 2022-10-03 09:02:19 +03:00
David Wertenteil
5ce638572f update path env var 2022-10-02 23:09:24 +03:00
Cheithanya
4b98490ff9 update cmd functionality added 2022-10-02 23:29:21 +05:30
Cheithanya
6ea18ec75b update cmd functionality added 2022-10-02 23:27:39 +05:30
Ben Hirschberg
56e2ffec5c Add arch diagrams (#857)
* Publishing community meetings

* Adding architecture diagrams

* fix type

* resize diagrams

* Changing the operator diagram

Co-authored-by: Benyamin Hirschberg <59160382+BenHirschbergCa@users.noreply.github.com>
2022-10-02 20:36:59 +03:00
David Wertenteil
fa204a208a Merge branch 'dev' 2022-10-02 20:32:09 +03:00
David Wertenteil
9ab0fc593f Update python build file 2022-10-02 20:27:38 +03:00
Moshe-Rappaport-CA
3b9c454245 Merge remote-tracking branch 'armo/dev' into dev 2022-09-29 18:07:29 +03:00
David Wertenteil
a6fc7a0da0 Update logs (#854)
* change user to ks

* update logs

* host scanner with fixed version
2022-09-29 12:18:05 +03:00
David Wertenteil
53ae57e478 host scanner with fixed version 2022-09-29 11:19:24 +03:00
David Wertenteil
1d3401e3b4 Merge remote-tracking branch 'armosec/dev' 2022-09-29 10:47:27 +03:00
Dipankar Das
634198df06 Addition of Cosign for image signing (#826)
- github action (uncommented)

Signed-off-by: Dipankar Das <dipankardas0115@gmail.com>

Signed-off-by: Dipankar Das <dipankardas0115@gmail.com>
2022-09-29 10:46:55 +03:00
David Wertenteil
cffc3953ea Merge remote-tracking branch 'armosec/dev' 2022-09-29 10:37:09 +03:00
David Wertenteil
ea768602fb update logs 2022-09-29 10:36:27 +03:00
David Wertenteil
b4fc6dddd3 change user to ks 2022-09-29 10:35:54 +03:00
Asutosh Panda
96d90c217e Fix typos, linting errors of markdown file, modify the content to make it more concise (#820) 2022-09-29 09:12:43 +03:00
Zoomhawk
a2f1722455 Correcting Punctuation (#849)
* Correcting Punctuation

* Recorrect
2022-09-29 08:57:53 +03:00
Dipankar Das
400b51df1c Refactoring of Code Base (#853)
* Refactoring of switch to if statement

* Edited the core/pkg/score/score.go

Signed-off-by: Dipankar Das <dipankardas0115@gmail.com>

* Changes to function comments
* core/pkg/registryadaptors/registryvulnerabilities/interfaces.go

Signed-off-by: Dipankar Das <dipankardas0115@gmail.com>

Signed-off-by: Dipankar Das <dipankardas0115@gmail.com>
2022-09-29 08:57:12 +03:00
David Wertenteil
0f3ce6917e Release (#844)
* Fix issue for scanning list obj

* Fix go mod in httphandler pkg

* Broken links fix in roadmap.md 

Planning, backlog, and wishlist links were not taking to the required section.

* override infoMap only if it's not nil

* improved icon of kubescape in readme

* Support scanning several files

* gramatical improvements

* docs(readme): Star → star

* Fix issues according to review

* Handle with issues  caused by updating opa-utils

* Fix scanning ListObj following reviews

* Update core/pkg/resourcehandler/filesloader.go

Co-authored-by: Vlad Klokun <vladklokun@users.noreply.github.com>

* Update completion.go

* Added fixed control input

* update go.mod

* Print chart name log when fail to generate

* Change formatting to %s

* Added resource prioritization information, raw resource will be sent on the result object

* Merging typo fixes from master (#772)

* greetings

* Update aws.sh

simplified the comment

* typo: In the title and h1 element

Their was a typo in index.html file.

* punctuation changes

* docs : added gitpod badge in readme.md

* fixed typos

* ƒ some grammar mistake is corrected inPULL_REQUEST_TEMPLATE.md file

* Updated README.md file

Added link to CONTRIBUTING.md file in a line in README.

* Added link to code of conduct file

I have added link to the code of conduct file and fixed some problems in the Readme file.

* Fixed readme

* Added alpine tag

Adding alpine tag instead of latest and removing repeating commands

* roadmap.md file is modified

* Automatically Close "Typo" labelled Issue

* build.py is modified

* modified PR template

* Fixed some typos in feature_request.md

"." at the end of the headings were missing and all the text were in same line.
Now this gives a clear and concise view of the texts.

* fixed the typo in docs/index.html

Found and fixed typo in the 'alt' attribute of img tag

* Update PULL_REQUEST_TEMPLATE.md

Co-authored-by: Krishna Agarwal <dmkrishna.agarwal@gmail.com>
Co-authored-by: Saswata Senapati <74651639+saswat16@users.noreply.github.com>
Co-authored-by: Rahul Singh <110548934+rahuldhirendersingh@users.noreply.github.com>
Co-authored-by: deepuyadav004 <deepuyadavze@gmail.com>
Co-authored-by: kartik <97971066+kartikgajjar7@users.noreply.github.com>
Co-authored-by: Rounak-28 <95576871+Rounak-28@users.noreply.github.com>
Co-authored-by: pwnb0y <vickykr07@yahoo.com>
Co-authored-by: Ben Hirschberg <59160382+slashben@users.noreply.github.com>
Co-authored-by: Saptarshi Sarkar <saptarshi.programmer@gmail.com>
Co-authored-by: Rahul Surwade <93492791+RahulSurwade08@users.noreply.github.com>
Co-authored-by: Suhas Gumma <43647369+suhasgumma@users.noreply.github.com>
Co-authored-by: Kamal Nayan <95926324+legendarykamal@users.noreply.github.com>
Co-authored-by: TarangVerma <90996971+TarangVerma@users.noreply.github.com>
Co-authored-by: avikittu <65793296+avikittu@users.noreply.github.com>

* update logger version

* update logger version (#773)

* Fixed: Kubescape fails to authenticate remote private Github repo (#721)

* grammar error fixer in CONTRIBUTING.md

* scanning private git repository is available

* giturl to gitapi

* NO TOKEN error functionality added

* Used GetToken method of giturl.IGitAPPI for auth

Co-authored-by: satyam kale <satyamkale271@gmail.com>
Co-authored-by: Ben Hirschberg <59160382+slashben@users.noreply.github.com>

* bump opa-utils to 181

* Option to force enable color output (closes #560) (#767)

* Option to force enable color output (closes #560)

(cherry picked from commit 4f951781ee8dd6bb451ac7d159787f47e4b07379)

* Update go.mod

* update scanner image

* Update host scanner image  (#774)

* update logger version

* update scanner image

* remove windows exe extension

* Remove windows extension build (#775)

* update logger version

* update scanner image

* remove windows exe extension

* commened out prioritization logic

* Edit Junit output (#802)

* Edit Junit output

* Update go sum

* Following review

* update AdoptClusterName

* Print line separator only if some controls failed (#813)

* removed the extra 'download' word from the example (#810)

it was confusing to understand the download command because there was an extra 'download' mentioned

* Prioritization (#815)

* removed commented out code

* Added attack tracks information to prioritization algorithm

* bump opa-utils

* go mod tidy

* go mod tidy

* CR changes

* Issue 613 cluster name (#783)

* added --clusterName flag (#613)

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

* update flag name to --cluster-name

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

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

* Per 307 fail on severity counters (#831)

* feat: fail on exceeding severity thresholds (#830)

- Add support for severity counters
- Add support for CLI flags that set severity thresholds
- Terminate Kubescape with an exit code 1 if scan results exceed the
  severity thresholds

* Update opa-utils pkg version

Co-authored-by: Vlad Klokun <vladklokun@users.noreply.github.com>

* Fix merge conflict

* typo in .gitignore file (#833)

* remove unsupported installation method

* fixed welcome message

* fixed merge

* fixed attack tracks loading logic

* add flag validation for --account-id (#605) (#793)

* add flag validation for --account-id (#605)

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

* add flag validation for --client-id & --secret-key

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

* Validation method should be a member function

* Adding unit tests for credentials validate

Signed-off-by: Anubhav Gupta <mail.anubhav06@gmail.com>
Co-authored-by: David Wertenteil <dwertent@armosec.io>

* Scan Kustomize Directory (#795)

* Scan Kustomize Files

* update 'scam Kustomize Directory' documentation in  Readme.md

* go get

* go get inside httphandler

* SourceTypeKustomizeDirectory

* Added Scan for Kustomization File

Co-authored-by: David Wertenteil <dwertent@armosec.io>

* feat: unify severity threshold into one CLI flag (#838)

* feat: unify severity threshold into one CLI flag

Before this commit, severity threshold flags were separated by severity.
This commit unifies these thresholds into one flag that forces Kubescape
to terminate with an exit code 1 if there was at least one failed
control at the specified severity threshold or above.

* chore: update opa utils version

* chore: update opa-utils in httphandler

* feat: dont enforce severity by default

Previous iteration of supporting the severity threshold enforced it even
if the severity threshold was not explicitly specified.
This change enforces the severity threshold only if it has been
explicitly set.

* refactor: clarify flagValidationFramework func name

This change clarifies the meaning of the function that validates the
scan info for the `scan framework` command.
It achieves this by renaming the `flagValidationFramework` function to
`validateFrameworkScanInfo`.

* Merge branch 'master' into dev

Signed-off-by: Anubhav Gupta <mail.anubhav06@gmail.com>
Co-authored-by: Moshe-Rappaport-CA <moshep@armosec.io>
Co-authored-by: Moshe Rappaport <89577611+Moshe-Rappaport-CA@users.noreply.github.com>
Co-authored-by: Om Raut <33827410+om2137@users.noreply.github.com>
Co-authored-by: Kamal Nayan <95926324+legendarykamal@users.noreply.github.com>
Co-authored-by: Vlad Klokun <vladklokun@users.noreply.github.com>
Co-authored-by: Chirag Arora <84070677+Chirag8023@users.noreply.github.com>
Co-authored-by: shm12 <shmuelb@armosec.io>
Co-authored-by: Amir Malka <amirm@armosec.io>
Co-authored-by: Krishna Agarwal <dmkrishna.agarwal@gmail.com>
Co-authored-by: Saswata Senapati <74651639+saswat16@users.noreply.github.com>
Co-authored-by: Rahul Singh <110548934+rahuldhirendersingh@users.noreply.github.com>
Co-authored-by: deepuyadav004 <deepuyadavze@gmail.com>
Co-authored-by: kartik <97971066+kartikgajjar7@users.noreply.github.com>
Co-authored-by: Rounak-28 <95576871+Rounak-28@users.noreply.github.com>
Co-authored-by: pwnb0y <vickykr07@yahoo.com>
Co-authored-by: Ben Hirschberg <59160382+slashben@users.noreply.github.com>
Co-authored-by: Saptarshi Sarkar <saptarshi.programmer@gmail.com>
Co-authored-by: Rahul Surwade <93492791+RahulSurwade08@users.noreply.github.com>
Co-authored-by: Suhas Gumma <43647369+suhasgumma@users.noreply.github.com>
Co-authored-by: TarangVerma <90996971+TarangVerma@users.noreply.github.com>
Co-authored-by: avikittu <65793296+avikittu@users.noreply.github.com>
Co-authored-by: satyam kale <satyamkale271@gmail.com>
Co-authored-by: Aditya Pratap Singh <adityapratapsingh51@gmail.com>
Co-authored-by: Ashray Shetty <ashrayshetty1999@gmail.com>
Co-authored-by: Anubhav Gupta <mail.anubhav06@gmail.com>
Co-authored-by: Meyazhagan <meyazhagan.ofcl@gmail.com>
2022-09-29 08:48:09 +03:00
David Wertenteil
11e57fe7ad Merge branch 'master' into dev 2022-09-22 17:34:52 +03:00
David Wertenteil
2ddce8723d Merge branch 'master' into dev 2022-09-22 17:06:44 +03:00
Suhas Gumma
291668647c build killercoda playground added (#843) 2022-09-22 15:59:08 +03:00
Vlad Klokun
d3c41f2492 feat: unify severity threshold into one CLI flag (#838)
* feat: unify severity threshold into one CLI flag

Before this commit, severity threshold flags were separated by severity.
This commit unifies these thresholds into one flag that forces Kubescape
to terminate with an exit code 1 if there was at least one failed
control at the specified severity threshold or above.

* chore: update opa utils version

* chore: update opa-utils in httphandler

* feat: dont enforce severity by default

Previous iteration of supporting the severity threshold enforced it even
if the severity threshold was not explicitly specified.
This change enforces the severity threshold only if it has been
explicitly set.

* refactor: clarify flagValidationFramework func name

This change clarifies the meaning of the function that validates the
scan info for the `scan framework` command.
It achieves this by renaming the `flagValidationFramework` function to
`validateFrameworkScanInfo`.
2022-09-22 15:56:30 +03:00
Avinesh Tripathi
10fa3cb27d Merge branch 'dev' into feature 2022-09-21 23:37:55 +05:30
Avinesh Tripathi
d8f95edff5 removed getLastScanId function 2022-09-21 23:37:08 +05:30
Avinesh Tripathi
37ffe86d8b changed name and added readme 2022-09-21 23:32:16 +05:30
Avinesh Tripathi
87fdbfdcc5 fixed 2022-09-20 18:50:19 +05:30
Cheithanya
424a218860 Added the required changes 2022-09-20 17:09:02 +05:30
Suhas Gumma
faf0ae6bdc Scan Kustomize Directory (#795)
* Scan Kustomize Files

* update 'scam Kustomize Directory' documentation in  Readme.md

* go get

* go get inside httphandler

* SourceTypeKustomizeDirectory

* Added Scan for Kustomization File

Co-authored-by: David Wertenteil <dwertent@armosec.io>
2022-09-20 10:28:50 +03:00
Anubhav Gupta
e46c42554b add flag validation for --account-id (#605) (#793)
* add flag validation for --account-id (#605)

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

* add flag validation for --client-id & --secret-key

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

* Validation method should be a member function

* Adding unit tests for credentials validate

Signed-off-by: Anubhav Gupta <mail.anubhav06@gmail.com>
Co-authored-by: David Wertenteil <dwertent@armosec.io>
2022-09-20 10:22:35 +03:00
David Wertenteil
eb16440ba6 Enhancing CLI flags (#835)
* Fix issue for scanning list obj

* Fix go mod in httphandler pkg

* Broken links fix in roadmap.md 

Planning, backlog, and wishlist links were not taking to the required section.

* override infoMap only if it's not nil

* improved icon of kubescape in readme

* Support scanning several files

* gramatical improvements

* docs(readme): Star → star

* Fix issues according to review

* Handle with issues  caused by updating opa-utils

* Fix scanning ListObj following reviews

* Update core/pkg/resourcehandler/filesloader.go

Co-authored-by: Vlad Klokun <vladklokun@users.noreply.github.com>

* Update completion.go

* Added fixed control input

* update go.mod

* Print chart name log when fail to generate

* Change formatting to %s

* Added resource prioritization information, raw resource will be sent on the result object

* Merging typo fixes from master (#772)

* greetings

* Update aws.sh

simplified the comment

* typo: In the title and h1 element

Their was a typo in index.html file.

* punctuation changes

* docs : added gitpod badge in readme.md

* fixed typos

* ƒ some grammar mistake is corrected inPULL_REQUEST_TEMPLATE.md file

* Updated README.md file

Added link to CONTRIBUTING.md file in a line in README.

* Added link to code of conduct file

I have added link to the code of conduct file and fixed some problems in the Readme file.

* Fixed readme

* Added alpine tag

Adding alpine tag instead of latest and removing repeating commands

* roadmap.md file is modified

* Automatically Close "Typo" labelled Issue

* build.py is modified

* modified PR template

* Fixed some typos in feature_request.md

"." at the end of the headings were missing and all the text were in same line.
Now this gives a clear and concise view of the texts.

* fixed the typo in docs/index.html

Found and fixed typo in the 'alt' attribute of img tag

* Update PULL_REQUEST_TEMPLATE.md

Co-authored-by: Krishna Agarwal <dmkrishna.agarwal@gmail.com>
Co-authored-by: Saswata Senapati <74651639+saswat16@users.noreply.github.com>
Co-authored-by: Rahul Singh <110548934+rahuldhirendersingh@users.noreply.github.com>
Co-authored-by: deepuyadav004 <deepuyadavze@gmail.com>
Co-authored-by: kartik <97971066+kartikgajjar7@users.noreply.github.com>
Co-authored-by: Rounak-28 <95576871+Rounak-28@users.noreply.github.com>
Co-authored-by: pwnb0y <vickykr07@yahoo.com>
Co-authored-by: Ben Hirschberg <59160382+slashben@users.noreply.github.com>
Co-authored-by: Saptarshi Sarkar <saptarshi.programmer@gmail.com>
Co-authored-by: Rahul Surwade <93492791+RahulSurwade08@users.noreply.github.com>
Co-authored-by: Suhas Gumma <43647369+suhasgumma@users.noreply.github.com>
Co-authored-by: Kamal Nayan <95926324+legendarykamal@users.noreply.github.com>
Co-authored-by: TarangVerma <90996971+TarangVerma@users.noreply.github.com>
Co-authored-by: avikittu <65793296+avikittu@users.noreply.github.com>

* update logger version

* update logger version (#773)

* Fixed: Kubescape fails to authenticate remote private Github repo (#721)

* grammar error fixer in CONTRIBUTING.md

* scanning private git repository is available

* giturl to gitapi

* NO TOKEN error functionality added

* Used GetToken method of giturl.IGitAPPI for auth

Co-authored-by: satyam kale <satyamkale271@gmail.com>
Co-authored-by: Ben Hirschberg <59160382+slashben@users.noreply.github.com>

* bump opa-utils to 181

* Option to force enable color output (closes #560) (#767)

* Option to force enable color output (closes #560)

(cherry picked from commit 4f951781ee8dd6bb451ac7d159787f47e4b07379)

* Update go.mod

* update scanner image

* Update host scanner image  (#774)

* update logger version

* update scanner image

* remove windows exe extension

* Remove windows extension build (#775)

* update logger version

* update scanner image

* remove windows exe extension

* commened out prioritization logic

* Edit Junit output (#802)

* Edit Junit output

* Update go sum

* Following review

* update AdoptClusterName

* Print line separator only if some controls failed (#813)

* removed the extra 'download' word from the example (#810)

it was confusing to understand the download command because there was an extra 'download' mentioned

* Prioritization (#815)

* removed commented out code

* Added attack tracks information to prioritization algorithm

* bump opa-utils

* go mod tidy

* go mod tidy

* CR changes

* Issue 613 cluster name (#783)

* added --clusterName flag (#613)

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

* update flag name to --cluster-name

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

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

* Per 307 fail on severity counters (#831)

* feat: fail on exceeding severity thresholds (#830)

- Add support for severity counters
- Add support for CLI flags that set severity thresholds
- Terminate Kubescape with an exit code 1 if scan results exceed the
  severity thresholds

* Update opa-utils pkg version

Co-authored-by: Vlad Klokun <vladklokun@users.noreply.github.com>

* Fix merge conflict

* typo in .gitignore file (#833)

* remove unsupported installation method

* fixed welcome message

* fixed merge

* fixed attack tracks loading logic

Signed-off-by: Anubhav Gupta <mail.anubhav06@gmail.com>
Co-authored-by: Moshe-Rappaport-CA <moshep@armosec.io>
Co-authored-by: Moshe Rappaport <89577611+Moshe-Rappaport-CA@users.noreply.github.com>
Co-authored-by: Om Raut <33827410+om2137@users.noreply.github.com>
Co-authored-by: Kamal Nayan <95926324+legendarykamal@users.noreply.github.com>
Co-authored-by: Vlad Klokun <vladklokun@users.noreply.github.com>
Co-authored-by: Chirag Arora <84070677+Chirag8023@users.noreply.github.com>
Co-authored-by: shm12 <shmuelb@armosec.io>
Co-authored-by: Amir Malka <amirm@armosec.io>
Co-authored-by: Krishna Agarwal <dmkrishna.agarwal@gmail.com>
Co-authored-by: Saswata Senapati <74651639+saswat16@users.noreply.github.com>
Co-authored-by: Rahul Singh <110548934+rahuldhirendersingh@users.noreply.github.com>
Co-authored-by: deepuyadav004 <deepuyadavze@gmail.com>
Co-authored-by: kartik <97971066+kartikgajjar7@users.noreply.github.com>
Co-authored-by: Rounak-28 <95576871+Rounak-28@users.noreply.github.com>
Co-authored-by: pwnb0y <vickykr07@yahoo.com>
Co-authored-by: Ben Hirschberg <59160382+slashben@users.noreply.github.com>
Co-authored-by: Saptarshi Sarkar <saptarshi.programmer@gmail.com>
Co-authored-by: Rahul Surwade <93492791+RahulSurwade08@users.noreply.github.com>
Co-authored-by: Suhas Gumma <43647369+suhasgumma@users.noreply.github.com>
Co-authored-by: TarangVerma <90996971+TarangVerma@users.noreply.github.com>
Co-authored-by: avikittu <65793296+avikittu@users.noreply.github.com>
Co-authored-by: satyam kale <satyamkale271@gmail.com>
Co-authored-by: Aditya Pratap Singh <adityapratapsingh51@gmail.com>
Co-authored-by: Ashray Shetty <ashrayshetty1999@gmail.com>
Co-authored-by: Anubhav Gupta <mail.anubhav06@gmail.com>
Co-authored-by: Meyazhagan <meyazhagan.ofcl@gmail.com>
2022-09-19 08:41:40 +03:00
Cheithanya
12f81353e0 Made the required changes 2022-09-19 00:30:26 +05:30
Amir Malka
fd33a8acd1 fixed attack tracks loading logic 2022-09-18 17:48:13 +03:00
David Wertenteil
374e268a4f fixed merge 2022-09-18 17:26:29 +03:00
David Wertenteil
405bfbf9ba Merge branch 'dev' of https://github.com/kubescape/kubescape into dev 2022-09-18 16:59:22 +03:00
David Wertenteil
304227200f fixed welcome message 2022-09-18 16:59:08 +03:00
David Wertenteil
dc10125380 Merge branch 'master' into dev 2022-09-18 15:48:48 +03:00
David Wertenteil
51c417ebc3 Merge branch 'master' of https://github.com/kubescape/kubescape 2022-09-18 15:37:52 +03:00
David Wertenteil
862230f58a Merge branch 'dev' of https://github.com/kubescape/kubescape into dev 2022-09-18 13:44:52 +03:00
David Wertenteil
6416fc56d7 remove unsupported installation method 2022-09-18 13:44:45 +03:00
Rutvikk :D
a8ad8e5f5a Update README.md (#827) 2022-09-18 13:33:07 +03:00
Meyazhagan
d5edf29554 typo in .gitignore file (#833) 2022-09-18 13:32:17 +03:00
David Wertenteil
4351099e79 Fix merge conflict 2022-09-18 11:41:28 +03:00
David Wertenteil
196d07edc6 Per 307 fail on severity counters (#831)
* feat: fail on exceeding severity thresholds (#830)

- Add support for severity counters
- Add support for CLI flags that set severity thresholds
- Terminate Kubescape with an exit code 1 if scan results exceed the
  severity thresholds

* Update opa-utils pkg version

Co-authored-by: Vlad Klokun <vladklokun@users.noreply.github.com>
2022-09-18 10:34:34 +03:00
Anubhav Gupta
f4bb03039a Issue 613 cluster name (#783)
* added --clusterName flag (#613)

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

* update flag name to --cluster-name

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

Signed-off-by: Anubhav Gupta <mail.anubhav06@gmail.com>
2022-09-18 10:27:52 +03:00
Avinesh Tripathi
d6427f0fc8 Merge branch 'dev' into feature 2022-09-16 10:34:51 +05:30
Avinesh Tripathi
f33a6d7634 added adaptor 2022-09-16 10:20:44 +05:30
Amir Malka
2b931fb3f0 Prioritization (#815)
* removed commented out code

* Added attack tracks information to prioritization algorithm

* bump opa-utils

* go mod tidy

* go mod tidy

* CR changes
2022-09-15 16:16:54 +03:00
Arvindh
bb586892ba Fixed typos on multiple files (#808) 2022-09-15 15:53:32 +03:00
Ashray Shetty
cb18f60f82 removed the extra 'download' word from the example (#810)
it was confusing to understand the download command because there was an extra 'download' mentioned
2022-09-15 15:48:11 +03:00
Moshe Rappaport
e5023943e5 Print line separator only if some controls failed (#813) 2022-09-15 15:47:39 +03:00
Amir Malka
c565dc5af7 Merge pull request #816 from dwertent/master
Fix cluster name adoption
2022-09-15 15:40:14 +03:00
David Wertenteil
5634903aa0 update AdoptClusterName 2022-09-15 14:53:55 +03:00
David Wertenteil
ce81a9cb22 Merge remote-tracking branch 'armosec/dev' 2022-09-15 14:14:27 +03:00
Moshe-Rappaport-CA
5a01a1a30a Print line separator only if some controls failed 2022-09-14 19:22:08 +03:00
Moshe Rappaport
cb704cb1e7 Edit Junit output (#802)
* Edit Junit output

* Update go sum

* Following review
2022-09-14 08:59:39 +03:00
Jatin Agarwal
6e2dda7993 Fixed typos in roadmap.md (#800) 2022-09-13 10:39:28 +03:00
itsCheithanya
15e1d6d1a2 Update README.md (#804)
* Update README.md

* Create kubeconfig

* Delete kubeconfig

* Create kubeconfig

* Rename kubeconfig to kubeconfig.go

* Delete kubeconfig.go

* Update root.go

* Update rootinfo.go

* Added the update command for kubescape

* auto pick the OS of the usersystem

* added the html format desc

* a branch without update command added

* rolled back to prev

* added the html format documentation
2022-09-13 10:23:04 +03:00
Cheithanya
ba588b9eef Added the comments for update command 2022-09-12 21:28:55 +05:30
Cheithanya
f48b848eb6 auto pick the OS of the usersystem 2022-09-11 23:48:14 +05:30
Cheithanya
f81fd74aa3 Added the update command for kubescape 2022-09-11 18:22:18 +05:30
itsCheithanya
ad608b08e0 Merge branch 'kubescape:master' into master 2022-09-07 14:24:55 +05:30
itsCheithanya
f9e80b709a Update rootinfo.go 2022-09-07 13:42:35 +05:30
itsCheithanya
f75b62e62c Update root.go 2022-09-07 13:39:29 +05:30
itsCheithanya
1c24a55d4b Delete kubeconfig.go 2022-09-07 13:37:32 +05:30
Vicky Aryan
43dbb55d50 fixed some typo mistakes (#786) 2022-09-07 11:01:21 +03:00
Vicky Aryan
6ec974f996 Merge branch 'kubescape:master' into master 2022-09-06 20:39:21 +05:30
itsCheithanya
03418299b8 Rename kubeconfig to kubeconfig.go 2022-09-06 18:32:27 +05:30
itsCheithanya
f5bd86593c Create kubeconfig 2022-09-06 18:32:00 +05:30
itsCheithanya
2af78eaab2 Delete kubeconfig 2022-09-06 18:30:16 +05:30
itsCheithanya
67cd003afe Create kubeconfig 2022-09-06 18:18:08 +05:30
Krishna Agarwal
f7f11abfc2 fixed typos (#777)
* fixed typos

* Update container-image-vulnerability-adaptor.md
2022-09-06 09:41:18 +03:00
TarangVerma
52aa5f02e2 Fixed typos in contribute.md (#779)
Fixed some spellings as well as grammar so that reader gets clear and concise view of the text.
2022-09-06 09:40:47 +03:00
itsCheithanya
ce8175be61 Update README.md (#782) 2022-09-06 09:39:25 +03:00
itsCheithanya
0bc542f851 Update README.md 2022-09-05 22:23:40 +05:30
Ben Hirschberg
8e4f88ce5b Publishing community meetings (#781) 2022-09-05 19:41:19 +03:00
David Wertenteil
d1c759f04f Hot fix - Revert report structure (#776)
* Fix issue for scanning list obj

* Fix go mod in httphandler pkg

* Broken links fix in roadmap.md 

Planning, backlog, and wishlist links were not taking to the required section.

* override infoMap only if it's not nil

* improved icon of kubescape in readme

* Support scanning several files

* gramatical improvements

* docs(readme): Star → star

* Fix issues according to review

* Handle with issues  caused by updating opa-utils

* Fix scanning ListObj following reviews

* Update core/pkg/resourcehandler/filesloader.go

Co-authored-by: Vlad Klokun <vladklokun@users.noreply.github.com>

* Update completion.go

* Added fixed control input

* update go.mod

* Print chart name log when fail to generate

* Change formatting to %s

* Added resource prioritization information, raw resource will be sent on the result object

* Merging typo fixes from master (#772)

* greetings

* Update aws.sh

simplified the comment

* typo: In the title and h1 element

Their was a typo in index.html file.

* punctuation changes

* docs : added gitpod badge in readme.md

* fixed typos

* ƒ some grammar mistake is corrected inPULL_REQUEST_TEMPLATE.md file

* Updated README.md file

Added link to CONTRIBUTING.md file in a line in README.

* Added link to code of conduct file

I have added link to the code of conduct file and fixed some problems in the Readme file.

* Fixed readme

* Added alpine tag

Adding alpine tag instead of latest and removing repeating commands

* roadmap.md file is modified

* Automatically Close "Typo" labelled Issue

* build.py is modified

* modified PR template

* Fixed some typos in feature_request.md

"." at the end of the headings were missing and all the text were in same line.
Now this gives a clear and concise view of the texts.

* fixed the typo in docs/index.html

Found and fixed typo in the 'alt' attribute of img tag

* Update PULL_REQUEST_TEMPLATE.md

Co-authored-by: Krishna Agarwal <dmkrishna.agarwal@gmail.com>
Co-authored-by: Saswata Senapati <74651639+saswat16@users.noreply.github.com>
Co-authored-by: Rahul Singh <110548934+rahuldhirendersingh@users.noreply.github.com>
Co-authored-by: deepuyadav004 <deepuyadavze@gmail.com>
Co-authored-by: kartik <97971066+kartikgajjar7@users.noreply.github.com>
Co-authored-by: Rounak-28 <95576871+Rounak-28@users.noreply.github.com>
Co-authored-by: pwnb0y <vickykr07@yahoo.com>
Co-authored-by: Ben Hirschberg <59160382+slashben@users.noreply.github.com>
Co-authored-by: Saptarshi Sarkar <saptarshi.programmer@gmail.com>
Co-authored-by: Rahul Surwade <93492791+RahulSurwade08@users.noreply.github.com>
Co-authored-by: Suhas Gumma <43647369+suhasgumma@users.noreply.github.com>
Co-authored-by: Kamal Nayan <95926324+legendarykamal@users.noreply.github.com>
Co-authored-by: TarangVerma <90996971+TarangVerma@users.noreply.github.com>
Co-authored-by: avikittu <65793296+avikittu@users.noreply.github.com>

* update logger version (#773)

* Fixed: Kubescape fails to authenticate remote private Github repo (#721)

* grammar error fixer in CONTRIBUTING.md

* scanning private git repository is available

* giturl to gitapi

* NO TOKEN error functionality added

* Used GetToken method of giturl.IGitAPPI for auth

Co-authored-by: satyam kale <satyamkale271@gmail.com>
Co-authored-by: Ben Hirschberg <59160382+slashben@users.noreply.github.com>

* bump opa-utils to 181

* Option to force enable color output (closes #560) (#767)

* Option to force enable color output (closes #560)

(cherry picked from commit 4f951781ee8dd6bb451ac7d159787f47e4b07379)

* Update go.mod

* Update host scanner image  (#774)

* update logger version

* update scanner image

* Remove windows extension build (#775)

* update logger version

* update scanner image

* remove windows exe extension

* commened out prioritization logic

Co-authored-by: Moshe-Rappaport-CA <moshep@armosec.io>
Co-authored-by: Moshe Rappaport <89577611+Moshe-Rappaport-CA@users.noreply.github.com>
Co-authored-by: Om Raut <33827410+om2137@users.noreply.github.com>
Co-authored-by: Kamal Nayan <95926324+legendarykamal@users.noreply.github.com>
Co-authored-by: Vlad Klokun <vladklokun@users.noreply.github.com>
Co-authored-by: Chirag Arora <84070677+Chirag8023@users.noreply.github.com>
Co-authored-by: shm12 <shmuelb@armosec.io>
Co-authored-by: Amir Malka <amirm@armosec.io>
Co-authored-by: Krishna Agarwal <dmkrishna.agarwal@gmail.com>
Co-authored-by: Saswata Senapati <74651639+saswat16@users.noreply.github.com>
Co-authored-by: Rahul Singh <110548934+rahuldhirendersingh@users.noreply.github.com>
Co-authored-by: deepuyadav004 <deepuyadavze@gmail.com>
Co-authored-by: kartik <97971066+kartikgajjar7@users.noreply.github.com>
Co-authored-by: Rounak-28 <95576871+Rounak-28@users.noreply.github.com>
Co-authored-by: pwnb0y <vickykr07@yahoo.com>
Co-authored-by: Ben Hirschberg <59160382+slashben@users.noreply.github.com>
Co-authored-by: Saptarshi Sarkar <saptarshi.programmer@gmail.com>
Co-authored-by: Rahul Surwade <93492791+RahulSurwade08@users.noreply.github.com>
Co-authored-by: Suhas Gumma <43647369+suhasgumma@users.noreply.github.com>
Co-authored-by: TarangVerma <90996971+TarangVerma@users.noreply.github.com>
Co-authored-by: avikittu <65793296+avikittu@users.noreply.github.com>
Co-authored-by: satyam kale <satyamkale271@gmail.com>
Co-authored-by: Aditya Pratap Singh <adityapratapsingh51@gmail.com>
2022-09-05 12:08:19 +03:00
David Wertenteil
362ea83549 Merge branch 'dev' of https://github.com/kubescape/kubescape into dev 2022-09-05 11:50:40 +03:00
David Wertenteil
4cb7b999ad Merge branch 'master' into dev 2022-09-05 11:49:05 +03:00
Amir Malka
81482b7421 commened out prioritization logic 2022-09-05 11:46:59 +03:00
David Wertenteil
2b7807f300 Merge branch 'master' of https://github.com/kubescape/kubescape 2022-09-05 11:46:21 +03:00
David Wertenteil
ef23d022ee Merge remote-tracking branch 'armosec/dev' 2022-09-05 11:44:53 +03:00
David Wertenteil
02d7fdc4f9 Remove windows extension build (#775)
* update logger version

* update scanner image

* remove windows exe extension
2022-09-05 11:37:56 +03:00
David Wertenteil
ccb3351607 remove windows exe extension 2022-09-05 11:35:08 +03:00
David Wertenteil
72f9c6d81b Fixed InfoMap usage (#680)
* Fix issue for scanning list obj

* Fix go mod in httphandler pkg

* Broken links fix in roadmap.md 

Planning, backlog, and wishlist links were not taking to the required section.

* override infoMap only if it's not nil

* improved icon of kubescape in readme

* Support scanning several files

* gramatical improvements

* docs(readme): Star → star

* Fix issues according to review

* Handle with issues  caused by updating opa-utils

* Fix scanning ListObj following reviews

* Update core/pkg/resourcehandler/filesloader.go

Co-authored-by: Vlad Klokun <vladklokun@users.noreply.github.com>

* Update completion.go

* Added fixed control input

* update go.mod

* Print chart name log when fail to generate

* Change formatting to %s

* Added resource prioritization information, raw resource will be sent on the result object

* Merging typo fixes from master (#772)

* greetings

* Update aws.sh

simplified the comment

* typo: In the title and h1 element

Their was a typo in index.html file.

* punctuation changes

* docs : added gitpod badge in readme.md

* fixed typos

* ƒ some grammar mistake is corrected inPULL_REQUEST_TEMPLATE.md file

* Updated README.md file

Added link to CONTRIBUTING.md file in a line in README.

* Added link to code of conduct file

I have added link to the code of conduct file and fixed some problems in the Readme file.

* Fixed readme

* Added alpine tag

Adding alpine tag instead of latest and removing repeating commands

* roadmap.md file is modified

* Automatically Close "Typo" labelled Issue

* build.py is modified

* modified PR template

* Fixed some typos in feature_request.md

"." at the end of the headings were missing and all the text were in same line.
Now this gives a clear and concise view of the texts.

* fixed the typo in docs/index.html

Found and fixed typo in the 'alt' attribute of img tag

* Update PULL_REQUEST_TEMPLATE.md

Co-authored-by: Krishna Agarwal <dmkrishna.agarwal@gmail.com>
Co-authored-by: Saswata Senapati <74651639+saswat16@users.noreply.github.com>
Co-authored-by: Rahul Singh <110548934+rahuldhirendersingh@users.noreply.github.com>
Co-authored-by: deepuyadav004 <deepuyadavze@gmail.com>
Co-authored-by: kartik <97971066+kartikgajjar7@users.noreply.github.com>
Co-authored-by: Rounak-28 <95576871+Rounak-28@users.noreply.github.com>
Co-authored-by: pwnb0y <vickykr07@yahoo.com>
Co-authored-by: Ben Hirschberg <59160382+slashben@users.noreply.github.com>
Co-authored-by: Saptarshi Sarkar <saptarshi.programmer@gmail.com>
Co-authored-by: Rahul Surwade <93492791+RahulSurwade08@users.noreply.github.com>
Co-authored-by: Suhas Gumma <43647369+suhasgumma@users.noreply.github.com>
Co-authored-by: Kamal Nayan <95926324+legendarykamal@users.noreply.github.com>
Co-authored-by: TarangVerma <90996971+TarangVerma@users.noreply.github.com>
Co-authored-by: avikittu <65793296+avikittu@users.noreply.github.com>

* update logger version (#773)

* Fixed: Kubescape fails to authenticate remote private Github repo (#721)

* grammar error fixer in CONTRIBUTING.md

* scanning private git repository is available

* giturl to gitapi

* NO TOKEN error functionality added

* Used GetToken method of giturl.IGitAPPI for auth

Co-authored-by: satyam kale <satyamkale271@gmail.com>
Co-authored-by: Ben Hirschberg <59160382+slashben@users.noreply.github.com>

* bump opa-utils to 181

* Option to force enable color output (closes #560) (#767)

* Option to force enable color output (closes #560)

(cherry picked from commit 4f951781ee8dd6bb451ac7d159787f47e4b07379)

* Update go.mod

* Update host scanner image  (#774)

* update logger version

* update scanner image

Co-authored-by: Moshe-Rappaport-CA <moshep@armosec.io>
Co-authored-by: Moshe Rappaport <89577611+Moshe-Rappaport-CA@users.noreply.github.com>
Co-authored-by: Om Raut <33827410+om2137@users.noreply.github.com>
Co-authored-by: Kamal Nayan <95926324+legendarykamal@users.noreply.github.com>
Co-authored-by: Vlad Klokun <vladklokun@users.noreply.github.com>
Co-authored-by: Chirag Arora <84070677+Chirag8023@users.noreply.github.com>
Co-authored-by: shm12 <shmuelb@armosec.io>
Co-authored-by: Amir Malka <amirm@armosec.io>
Co-authored-by: Krishna Agarwal <dmkrishna.agarwal@gmail.com>
Co-authored-by: Saswata Senapati <74651639+saswat16@users.noreply.github.com>
Co-authored-by: Rahul Singh <110548934+rahuldhirendersingh@users.noreply.github.com>
Co-authored-by: deepuyadav004 <deepuyadavze@gmail.com>
Co-authored-by: kartik <97971066+kartikgajjar7@users.noreply.github.com>
Co-authored-by: Rounak-28 <95576871+Rounak-28@users.noreply.github.com>
Co-authored-by: pwnb0y <vickykr07@yahoo.com>
Co-authored-by: Ben Hirschberg <59160382+slashben@users.noreply.github.com>
Co-authored-by: Saptarshi Sarkar <saptarshi.programmer@gmail.com>
Co-authored-by: Rahul Surwade <93492791+RahulSurwade08@users.noreply.github.com>
Co-authored-by: Suhas Gumma <43647369+suhasgumma@users.noreply.github.com>
Co-authored-by: TarangVerma <90996971+TarangVerma@users.noreply.github.com>
Co-authored-by: avikittu <65793296+avikittu@users.noreply.github.com>
Co-authored-by: satyam kale <satyamkale271@gmail.com>
Co-authored-by: Aditya Pratap Singh <adityapratapsingh51@gmail.com>
2022-09-05 10:49:37 +03:00
David Wertenteil
bba70b4c46 Update host scanner image (#774)
* update logger version

* update scanner image
2022-09-05 10:15:56 +03:00
David Wertenteil
46073e0a6c update scanner image 2022-09-05 10:12:28 +03:00
David Wertenteil
93a44f494d Merge remote-tracking branch 'armosec/dev' 2022-09-05 09:33:59 +03:00
Aditya Pratap Singh
5c96f877ed Option to force enable color output (closes #560) (#767)
* Option to force enable color output (closes #560)

(cherry picked from commit 4f951781ee8dd6bb451ac7d159787f47e4b07379)

* Update go.mod
2022-09-05 09:03:38 +03:00
Amir Malka
23ea7e0511 bump opa-utils to 181 2022-09-04 15:32:42 +03:00
Suhas Gumma
137b3d7b5d Fixed: Kubescape fails to authenticate remote private Github repo (#721)
* grammar error fixer in CONTRIBUTING.md

* scanning private git repository is available

* giturl to gitapi

* NO TOKEN error functionality added

* Used GetToken method of giturl.IGitAPPI for auth

Co-authored-by: satyam kale <satyamkale271@gmail.com>
Co-authored-by: Ben Hirschberg <59160382+slashben@users.noreply.github.com>
2022-09-04 15:17:15 +03:00
David Wertenteil
13ffd92210 update logger version (#773) 2022-09-04 15:13:16 +03:00
David Wertenteil
4725f8b3ca update logger version 2022-09-04 15:02:04 +03:00
David Wertenteil
6d65a90de9 Merging typo fixes from master (#772)
* greetings

* Update aws.sh

simplified the comment

* typo: In the title and h1 element

Their was a typo in index.html file.

* punctuation changes

* docs : added gitpod badge in readme.md

* fixed typos

* ƒ some grammar mistake is corrected inPULL_REQUEST_TEMPLATE.md file

* Updated README.md file

Added link to CONTRIBUTING.md file in a line in README.

* Added link to code of conduct file

I have added link to the code of conduct file and fixed some problems in the Readme file.

* Fixed readme

* Added alpine tag

Adding alpine tag instead of latest and removing repeating commands

* roadmap.md file is modified

* Automatically Close "Typo" labelled Issue

* build.py is modified

* modified PR template

* Fixed some typos in feature_request.md

"." at the end of the headings were missing and all the text were in same line.
Now this gives a clear and concise view of the texts.

* fixed the typo in docs/index.html

Found and fixed typo in the 'alt' attribute of img tag

* Update PULL_REQUEST_TEMPLATE.md

Co-authored-by: Krishna Agarwal <dmkrishna.agarwal@gmail.com>
Co-authored-by: Saswata Senapati <74651639+saswat16@users.noreply.github.com>
Co-authored-by: Rahul Singh <110548934+rahuldhirendersingh@users.noreply.github.com>
Co-authored-by: deepuyadav004 <deepuyadavze@gmail.com>
Co-authored-by: kartik <97971066+kartikgajjar7@users.noreply.github.com>
Co-authored-by: Rounak-28 <95576871+Rounak-28@users.noreply.github.com>
Co-authored-by: pwnb0y <vickykr07@yahoo.com>
Co-authored-by: Ben Hirschberg <59160382+slashben@users.noreply.github.com>
Co-authored-by: Saptarshi Sarkar <saptarshi.programmer@gmail.com>
Co-authored-by: Rahul Surwade <93492791+RahulSurwade08@users.noreply.github.com>
Co-authored-by: Suhas Gumma <43647369+suhasgumma@users.noreply.github.com>
Co-authored-by: Kamal Nayan <95926324+legendarykamal@users.noreply.github.com>
Co-authored-by: TarangVerma <90996971+TarangVerma@users.noreply.github.com>
Co-authored-by: avikittu <65793296+avikittu@users.noreply.github.com>
2022-09-04 14:50:22 +03:00
David Wertenteil
faf928527d Merge pull request #770 from amirmalka/dev
Resources Prioritization
2022-09-04 14:17:19 +03:00
Amir Malka
18c6e80c3c Added resource prioritization information, raw resource will be sent on the result object 2022-09-04 13:38:48 +03:00
David Wertenteil
83045c743a Merge pull request #748 from RahulSurwade08/master
Updated Dockerfile
2022-09-04 13:05:39 +03:00
David Wertenteil
4940912784 Merge pull request #750 from pwnb0y/doc-1
roadmap.md file is modified
2022-09-04 13:03:24 +03:00
David Wertenteil
a7fd2bd058 Merge pull request #724 from Rounak-28/patch-2
fixed typos
2022-09-04 13:02:51 +03:00
David Wertenteil
aa1f61a4f8 Merge pull request #755 from suhasgumma/workflow
Fixed: Misconfiguration in "close-typos-issues.yaml" GITHUB Actions file
2022-09-04 13:00:57 +03:00
David Wertenteil
b103e817ed Merge pull request #745 from Moshe-Rappaport-CA/dev
Print chart name log when fail to generate
2022-09-04 12:59:30 +03:00
David Wertenteil
55045badce Merge pull request #764 from legendarykamal/patch-1
Modified PR template
2022-09-04 12:58:05 +03:00
David Wertenteil
e951e23bc4 Update PULL_REQUEST_TEMPLATE.md 2022-09-04 12:57:49 +03:00
David Wertenteil
d467f159ad Merge pull request #759 from pwnb0y/python-patch1
build.py is modified
2022-09-04 12:55:39 +03:00
David Wertenteil
bb2a7b8d6c Merge pull request #766 from TarangVerma/patch-1
Fixed some typos in feature_request.md
2022-09-04 12:48:17 +03:00
David Wertenteil
23bb8ec482 Merge pull request #769 from avikittu/patch-1
fixed the typo in docs/index.html
2022-09-04 12:43:07 +03:00
avikittu
6c50fe1011 fixed the typo in docs/index.html
Found and fixed typo in the 'alt' attribute of img tag
2022-09-04 14:17:09 +05:30
TarangVerma
4268cb31c3 Fixed some typos in feature_request.md
"." at the end of the headings were missing and all the text were in same line.
Now this gives a clear and concise view of the texts.
2022-09-04 09:39:15 +05:30
Kamal Nayan
3b37d56427 modified PR template 2022-09-03 14:29:13 +05:30
pwnb0y
f239075c26 build.py is modified 2022-09-02 20:25:16 +00:00
Suhas Gumma
b0c8c42c85 Automatically Close "Typo" labelled Issue 2022-09-02 15:23:41 +05:30
pwnb0y
ea777b67ec roadmap.md file is modified 2022-09-01 10:45:14 -04:00
Vicky Aryan
ebf1486a7d Merge branch 'kubescape:master' into master 2022-09-01 17:53:52 +05:30
Moshe Rappaport
2db2f55d16 Change formatting to %s 2022-09-01 14:28:18 +03:00
David Wertenteil
cf9f34c0be Merge pull request #705 from deepuyadav004/dcs
punctuation changes
2022-09-01 09:04:09 +03:00
David Wertenteil
4d4bec95f2 Merge pull request #679 from saswat16/patch-2
Update aws.sh
2022-09-01 08:57:53 +03:00
David Wertenteil
f3a5ce75d5 Merge pull request #732 from pwnb0y/docs
grammatical mistake is corrected in PULL_REQUEST_TEMPLATE.md file
2022-09-01 08:47:09 +03:00
David Wertenteil
b38ce5e812 Merge pull request #734 from Chirag8023/patch-3
Patch 3
2022-09-01 08:44:26 +03:00
David Wertenteil
e4733fa02c Merge pull request #746 from SaptarshiSarkar12/patch-3
Updated README.md file
2022-09-01 08:43:12 +03:00
David Wertenteil
39ea443f81 Merge pull request #709 from kartikgajjar7/patch-2
docs : added gitpod badge in readme.md
2022-09-01 08:42:05 +03:00
David Wertenteil
d03806aea2 Merge pull request #738 from shm12/dev
Adding fixed control input
2022-09-01 08:32:26 +03:00
Rahul Surwade
576c281150 Added alpine tag
Adding alpine tag instead of latest and removing repeating commands
2022-08-31 17:16:31 -04:00
Saptarshi Sarkar
dfabcd691a Fixed readme 2022-09-01 00:03:15 +05:30
Saptarshi Sarkar
e2698e71a3 Added link to code of conduct file
I have added link to the code of conduct file and fixed some problems in the Readme file.
2022-08-31 23:47:56 +05:30
Saptarshi Sarkar
6901628b5a Updated README.md file
Added link to CONTRIBUTING.md file in a line in README.
2022-08-31 23:39:39 +05:30
Moshe-Rappaport-CA
fc3912ca7d Print chart name log when fail to generate 2022-08-31 15:26:24 +03:00
Ben Hirschberg
c83cb4496d Merge pull request #687 from rahuldhirendersingh/patch-2
typo: In the title and h1 element
2022-08-30 13:28:27 +03:00
shm12
a76228c1e1 update go.mod 2022-08-30 11:39:54 +03:00
shm12
9447f2933a Added fixed control input 2022-08-30 11:33:19 +03:00
David Wertenteil
26d4664cc5 Merge pull request #694 from Moshe-Rappaport-CA/support-scanning-several-files
Support scanning several files
2022-08-30 10:01:44 +03:00
Ben Hirschberg
05fa9d887d Merge pull request #672 from MrKrishnaAgarwal/patch-2
greetings
2022-08-30 08:03:28 +03:00
Chirag Arora
acdad028a3 Update completion.go 2022-08-30 00:59:00 +05:30
pwnb0y
890ababe0a ƒ some grammar mistake is corrected inPULL_REQUEST_TEMPLATE.md file 2022-08-30 00:28:49 +05:30
Moshe Rappaport
de78615038 Update core/pkg/resourcehandler/filesloader.go
Co-authored-by: Vlad Klokun <vladklokun@users.noreply.github.com>
2022-08-29 18:10:21 +03:00
Rounak-28
db35670432 fixed typos 2022-08-29 18:33:35 +05:30
Vicky Aryan
4d954b2ab0 Merge branch 'kubescape:master' into master 2022-08-29 17:29:26 +05:30
David Wertenteil
1c215c36af Merge pull request #682 from MaruthiKo/patch-1
Fixed Typos in examples/exceptions/README.md
2022-08-29 14:53:49 +03:00
David Wertenteil
2e8f64b20a Merge pull request #675 from MrKrishnaAgarwal/patch-3
fix typos
2022-08-29 14:53:16 +03:00
Moshe-Rappaport-CA
9c764c90e3 Fix scanning ListObj following reviews 2022-08-29 10:29:25 +03:00
Moshe-Rappaport-CA
95a4c19dc6 Handle with issues caused by updating opa-utils 2022-08-29 10:17:31 +03:00
pwnb0y
4d155a6b4f install.ps1 is modified 2022-08-29 11:25:29 +05:30
Moshe-Rappaport-CA
e3352f90e1 Merge remote-tracking branch 'armo/dev' into support-scanning-several-files 2022-08-28 12:03:09 +03:00
Moshe-Rappaport-CA
677a9da80a Fix issues according to review 2022-08-28 12:02:21 +03:00
Krishna Agarwal
83e53c09eb Merge branch 'kubescape:master' into patch-2 2022-08-28 12:37:37 +05:30
Ben Hirschberg
c7e1e251ba Merge pull request #693 from satyamkale27/Gramma-Mistakes
grammar error fixer in CONTRIBUTING.md
2022-08-28 09:41:03 +03:00
kartik
aff7af5159 docs : added gitpod badge in readme.md 2022-08-27 16:56:44 +05:30
deepuyadav004
7bd77d666d punctuation changes 2022-08-26 23:05:30 +05:30
Vlad Klokun
9a7eb4b9a5 Merge pull request #690 from legendarykamal/master
docs: center the icon, reword starring call to action
2022-08-26 14:47:24 +03:00
Vlad Klokun
903b5f39df docs(readme): Star → star 2022-08-25 23:00:10 +03:00
Kamal Nayan
55f0ca3e9e gramatical improvements 2022-08-26 00:57:56 +05:30
David Wertenteil
3387e677ba Merge pull request #636 from Moshe-Rappaport-CA/dev
Fix scanning list obj
2022-08-25 17:33:38 +03:00
Moshe-Rappaport-CA
5774acfc81 Merge remote-tracking branch 'armo/dev' into support-scanning-several-files 2022-08-25 15:25:58 +03:00
Moshe-Rappaport-CA
0eee2d1d0a Support scanning several files 2022-08-25 15:20:26 +03:00
satyam kale
0c624cc576 grammar error fixer in CONTRIBUTING.md 2022-08-25 15:21:51 +05:30
Kamal Nayan
aade1008c4 improved icon of kubescape in readme 2022-08-25 14:54:03 +05:30
Rahul Singh
c58b099230 typo: In the title and h1 element
Their was a typo in index.html file.
2022-08-25 02:57:31 +05:30
Konjeti Maruthi
786092bdaf Fixed Typos in examples/exceptions/README.md
Fixed a few typos and grammatical mistakes in the readme.md
2022-08-24 22:12:57 +05:30
David Wertenteil
80adf03926 Merge branch 'master' into dev 2022-08-24 17:23:28 +03:00
David Wertenteil
4b9c35d53b Merge branch 'master' of https://github.com/kubescape/kubescape 2022-08-24 17:23:10 +03:00
David Wertenteil
f3623dccf6 Merge pull request #678 from RohitYandigeri/patch-5
Update container-image-vulnerability-adaptor.md

Resolves #673
2022-08-24 17:20:28 +03:00
Saswata Senapati
b0db1e3d40 Update aws.sh
simplified the comment
2022-08-24 19:41:40 +05:30
David Wertenteil
b936c3f857 Merge branch 'master' into dev 2022-08-24 17:11:38 +03:00
David Wertenteil
600b9a6fb0 Merge branch 'master' of https://github.com/kubescape/kubescape 2022-08-24 17:11:13 +03:00
David Wertenteil
3bec2ef0b7 override infoMap only if it's not nil 2022-08-24 17:10:18 +03:00
Rohit Yandigeri
3d8344f23c Update container-image-vulnerability-adaptor.md 2022-08-24 19:07:54 +05:30
Krishna Agarwal
d87836d0a9 fix typos 2022-08-24 18:25:06 +05:30
Krishna Agarwal
42908ceb6f greetings 2022-08-24 18:15:00 +05:30
David Wertenteil
70288c94c3 Merge pull request #665 from rahuldhirendersingh/patch-1
Fixed typo: for better code readability
2022-08-24 15:39:24 +03:00
David Wertenteil
2bc63c2ab6 Merge pull request #659 from RohitYandigeri/patch-4
Update README.md
2022-08-24 15:35:21 +03:00
David Wertenteil
609cbff2da Merge pull request #655 from om2137/om2
Broken links fix in roadmap.md
2022-08-24 15:29:50 +03:00
David Wertenteil
3cf0931fb8 Merge pull request #652 from Polokghosh53/patch-2
Update CONTRIBUTING.md
2022-08-24 15:28:46 +03:00
David Wertenteil
a42d2452fd Merge branch 'master' into patch-2 2022-08-24 15:28:32 +03:00
David Wertenteil
7dd79874cc Merge pull request #645 from Hirdey-1999/patch-2
Updated roadmap.md : Typo Error
2022-08-24 15:21:50 +03:00
David Wertenteil
d1a75f076e Merge pull request #640 from Yh010/patch-3
Corrected grammatical errors
2022-08-24 15:20:42 +03:00
David Wertenteil
08fa833f82 Merge branch 'master' into patch-3 2022-08-24 15:20:34 +03:00
David Wertenteil
45e869e0d6 Merge pull request #634 from asim-bhatta/document
Edited few words
2022-08-24 15:15:28 +03:00
David Wertenteil
46cfc882c2 Merge pull request #667 from dwertent/master
Adding close `typo` issues workflow
2022-08-24 14:40:16 +03:00
Ben Hirschberg
10583a4b9b Merge pull request #661 from slashben/master
Updates to roadmap and readme
2022-08-24 14:12:47 +03:00
Ben Hirschberg
da2adf3059 Update close-typos-issues.yaml 2022-08-24 14:01:43 +03:00
David Wertenteil
da24c9164a auto close typo issues 2022-08-24 13:27:24 +03:00
Rahul Singh
8ac41533b6 typo correction: for better code readability
There was some spelling mistakes at multiple places, so I've made those changes to increase the better code readability
2022-08-24 14:07:49 +05:30
David Wertenteil
76958f285c Merge branch 'master' into master 2022-08-24 11:06:05 +03:00
David Wertenteil
93f6f3aecf Update README.md 2022-08-24 11:04:17 +03:00
Benyamin Hirschberg
971f0c06e7 Adding "open for contribution" tickets in the team intro section 2022-08-24 09:36:12 +03:00
Benyamin Hirschberg
bd4e0483d4 small reame changes 2022-08-24 09:31:16 +03:00
Ben Hirschberg
838eff3037 Merge pull request #637 from kubescape/dev
Replacing `armosec` by `kubescape`
2022-08-24 09:28:09 +03:00
Benyamin Hirschberg
1ee1c11700 removing ARMO from Kubescape logo 2022-08-24 09:15:33 +03:00
Benyamin Hirschberg
daa6db164a Updating high level roadmap 2022-08-24 09:11:01 +03:00
Rohit Yandigeri
eb33542e4a Update README.md 2022-08-24 10:40:48 +05:30
Om Raut
a03b0c94c4 Broken links fix in roadmap.md
Planning, backlog, and wishlist links were not taking to the required section.
2022-08-24 02:18:56 +05:30
David Wertenteil
402aea1493 Merge remote-tracking branch 'armosec/dev' 2022-08-23 22:34:03 +03:00
David Wertenteil
26c0baefe7 Fixing building section links 2022-08-23 22:33:04 +03:00
David Wertenteil
057d22adc1 Merge branch 'master' into dev 2022-08-23 22:29:24 +03:00
Polok-Ghosh
77f3806abf Update CONTRIBUTING.md
Some minute changes in the contributing.md
2022-08-24 00:38:31 +05:30
David Wertenteil
5f6689adc1 Merge pull request #651 from dwertent/master
Fixed links in readme
2022-08-23 21:48:31 +03:00
David Wertenteil
051ec71263 Merge remote-tracking branch 'armosec/dev' 2022-08-23 21:43:43 +03:00
David Wertenteil
c3434814c1 Fixed readme links 2022-08-23 21:43:02 +03:00
Hirdey-1999
38325c5af4 Update roadmap.md 2022-08-23 21:33:05 +05:30
Moshe-Rappaport-CA
589d0545cb Merge branch 'dev' of github.com:Moshe-Rappaport-CA/kubescape into dev 2022-08-23 17:41:01 +03:00
Moshe-Rappaport-CA
32b74608bf Merge remote-tracking branch 'armo/dev' into dev 2022-08-23 17:02:15 +03:00
Yash Hegde
98c0be147b Corrected grammatical errors 2022-08-23 19:07:36 +05:30
David Wertenteil
6442e8c891 fixed test deps pkg 2022-08-23 16:31:19 +03:00
Moshe-Rappaport-CA
9454924b9f Merge remote-tracking branch 'armo/dev' into dev 2022-08-23 16:11:07 +03:00
Moshe Rappaport
7233f00c32 Merge branch 'dev' into dev 2022-08-23 15:51:57 +03:00
Moshe-Rappaport-CA
905db42625 Fix go mod in httphandler pkg 2022-08-23 15:49:06 +03:00
David Wertenteil
40e02899bb Merge pull request #604 from kubescape/send-num-of-resources
Send num of resources
2022-08-23 15:26:23 +03:00
Asim Bhatta
bfdf24afb4 Edited few words 2022-08-23 18:02:38 +05:45
Asim Bhatta
588269f1a0 Merge branch 'document' of https://github.com/asim-bhatta/kubescape into document 2022-08-23 17:57:38 +05:45
David Wertenteil
040b965be2 Merge pull request #633 from dwertent/master
Replacing `armo` organization by `kubescape` organization
2022-08-23 15:10:16 +03:00
Daniel-GrunbergerCA
363951eb94 pr fixes 2022-08-23 15:07:51 +03:00
Asim Bhatta
a45283b128 Edited here as well 2022-08-23 17:39:43 +05:45
Moshe-Rappaport-CA
05d5ad47f2 Merge remote-tracking branch 'armo/dev' into dev 2022-08-23 14:42:38 +03:00
Moshe-Rappaport-CA
5ccb858d7f Fix issue for scanning list obj 2022-08-23 14:42:12 +03:00
Asim Bhatta
c49c808730 Merge branch 'kubescape:master' into document 2022-08-23 17:16:59 +05:45
Asim Bhatta
23d44aef7e Edited few words 2022-08-23 16:22:06 +05:45
David Wertenteil
657beea858 Merge pull request #632 from SaptarshiSarkar12/patch-2
Fixed typo
2022-08-23 13:29:06 +03:00
David Wertenteil
4becfc6b88 Update PULL_REQUEST_TEMPLATE.md 2022-08-23 13:28:40 +03:00
Saptarshi Sarkar
b2763b1f4f Fixed typo 2022-08-23 15:54:22 +05:30
David Wertenteil
cbd4fc1a80 replace armo by kubescape mentioned in urls 2022-08-23 12:33:48 +03:00
David Wertenteil
6a17eb1e86 Merge pull request #631 from slashben/dev
Removing mention of ARMO in the initi log print
2022-08-23 12:29:38 +03:00
Ben Hirschberg
4e847b4293 Removing mention of ARMO in the initi log print 2022-08-23 11:25:28 +03:00
Daniel-GrunbergerCA
e81d8ffa3c use setters 2022-08-23 10:34:05 +03:00
David Wertenteil
2e1de8a48f Merge pull request #622 from OmAximani0/pr-template
Added simple PR template
2022-08-23 08:29:10 +03:00
David Wertenteil
240971172d Requesting PRs should be opened against the dev branch 2022-08-23 08:28:04 +03:00
David Wertenteil
1b54f3b87c Merge pull request #628 from rakshitgondwal/changes
Update README.md
2022-08-23 08:21:10 +03:00
David Wertenteil
cf6ae51f76 Update README.md 2022-08-23 08:20:15 +03:00
David Wertenteil
12619f4f3b Update README.md 2022-08-23 08:19:01 +03:00
Rakshit Gondwal
4b96ce4a54 Update README.md 2022-08-23 02:36:21 +05:30
David Wertenteil
86c1f57128 Merge pull request #626 from Yh010/patch-2
Correction of grammatical errors
2022-08-22 23:47:17 +03:00
Yash Hegde
7a51b46178 Correction of grammatical errors 2022-08-23 00:29:18 +05:30
OmAxiani0
eeb1d8bff7 Added simple PR template 2022-08-22 22:05:43 +05:30
David Wertenteil
04f757913a Merge pull request #616 from NirmitSawant/patch-2
Updated the correct link on the discord button
2022-08-22 19:18:55 +03:00
NirmitSawant
307b7be28d Updated the correct link on the discord button 2022-08-22 21:06:26 +05:30
David Wertenteil
c3d188bde4 Merge pull request #615 from prajapatiomkar/master
Made changes in README file by adding discord link correctly
2022-08-22 18:27:09 +03:00
Prajapati omkar
52c2b4e854 Made changes in Readme file by adding discord link 2022-08-22 20:53:31 +05:30
David Wertenteil
bd970eff83 update to kubescape org 2022-08-22 18:22:28 +03:00
David Wertenteil
7bba5fafe0 Merge pull request #607 from vladklokun/template-bug-report
chore: Add a Bug Report issue template
2022-08-22 17:32:32 +03:00
David Wertenteil
d25c69abbf Merge pull request #606 from vladklokun/feature-request-template
Add a feature request template
2022-08-22 17:30:23 +03:00
vladklokun
22e1e8a82f chore: Add a Bug Report issue template 2022-08-22 17:28:56 +03:00
vladklokun
c8c3ab76d6 Add a feature request template 2022-08-22 17:19:45 +03:00
Daniel-GrunbergerCA
ad1c39a7e5 go mod tidy 2022-08-22 16:03:10 +03:00
Daniel-GrunbergerCA
e6398872cd change if order 2022-08-22 15:58:09 +03:00
Daniel-GrunbergerCA
811d27529c log error 2022-08-22 15:56:25 +03:00
Daniel-GrunbergerCA
a1efafc871 send mapNamespace to nuimber of resources in report 2022-08-22 15:51:53 +03:00
David Wertenteil
7f2a4bdfd8 use ks namespace 2022-08-21 10:20:29 +03:00
David Wertenteil
8381b2d348 Merge pull request #602 from dwertent/master
Updated dependencies packages
2022-08-18 22:44:51 +03:00
David Wertenteil
a95c2ec42b removing unused function 2022-08-18 22:41:00 +03:00
David Wertenteil
ad91178ef7 updated dependencies pkgs 2022-08-18 17:41:03 +03:00
David Wertenteil
db179d7b67 Merge pull request #601 from vladklokun/refactor-rename-entities
refactor: Rename branded entities to Kubescape
2022-08-18 16:35:21 +03:00
Vlad Klokun
f6e2651f88 refactor!: httphandler: use Kubescape’s updated exported functions 2022-08-18 15:19:36 +03:00
Vlad Klokun
6a52945e5a chore: summeryhelpers.go → summaryhelpers.go
Fixed a typo in filename (summEry → summAry)
2022-08-18 15:19:29 +03:00
Vlad Klokun
f8a66b0f9b refactor!: resourcehandler: rename armoResources to ksResources 2022-08-18 15:19:27 +03:00
Vlad Klokun
bfc3b0cc43 refactor!: resourcehandler: rename armoResources to ksResources 2022-08-18 15:19:25 +03:00
Vlad Klokun
2432378a57 refactor!: resourcehandler: rename armoResources to ksResources 2022-08-18 15:19:22 +03:00
Vlad Klokun
2f1ae9418a chore!: registryadaptors: rename armosec/v1 Go files 2022-08-18 15:19:19 +03:00
Vlad Klokun
619eeb3f02 refactor!: registryadaptors: rename adaptor Armo to KS 2022-08-18 15:19:16 +03:00
Vlad Klokun
ed1862cf72 refactor!: policyhandler/handlenotification.go: rename armoResources to ksResources 2022-08-18 15:19:12 +03:00
Vlad Klokun
40d5b08f39 refactor!: opaprocessor/processorhandlerutils.go: rename getArmoObjects to getKSObjects 2022-08-18 15:19:10 +03:00
Vlad Klokun
fcfccd18dc refactor!: core/submit.go: rename armoAPI to ksCloudAPI 2022-08-18 15:19:07 +03:00
Vlad Klokun
0be1acfe72 refactor!: core/list: rename armoAPI to ksCloudAPI 2022-08-18 15:19:04 +03:00
Vlad Klokun
7407cbb4fb refactor!: core/initutils.go: rename Armo to Kubescape Cloud 2022-08-18 15:19:02 +03:00
Vlad Klokun
79158aa3e5 refactor!: core/delete.go: rename Armo to Kubescape 2022-08-18 15:19:00 +03:00
Vlad Klokun
e7d212fb8c style: format ArmoResource comment 2022-08-18 15:18:56 +03:00
Vlad Klokun
4d6f75a65a refactor!: rename MapArmoResource to MapKSResource 2022-08-18 15:18:54 +03:00
Vlad Klokun
17445ee8b9 refactor!: rename "ArmoResources" to "KSResources" 2022-08-18 15:18:51 +03:00
Vlad Klokun
2de950cce7 chore!: scaninfo_test.go: remove commented out code 2022-08-18 15:18:48 +03:00
Vlad Klokun
326dd096fd docs!: scaninfo.go: remove Armo mentions 2022-08-18 15:18:46 +03:00
Vlad Klokun
416b5e691e chore!: remove commented out code from reportv2tov1 2022-08-18 15:18:45 +03:00
Vlad Klokun
f7d91f1b48 docs: rename CA in comments to Kubescape Cloud 2022-08-18 15:18:43 +03:00
Vlad Klokun
46f823eb89 refactor!: rename "ruleWithArmoOpaDependency" to "ruleWithKSOpaDependency" 2022-08-18 15:18:41 +03:00
Vlad Klokun
e54bfec4c1 refactor!: rename "ArmoResources" to "KSCloudResources" 2022-08-18 15:18:39 +03:00
Vlad Klokun
e95a09dbff docs: "armo" to "kubescape cloud" in customerloader comments 2022-08-18 15:18:35 +03:00
Vlad Klokun
e1f01f963f chore!: rename "armoapi.go" to "kscloudapi.go" 2022-08-18 15:18:32 +03:00
Vlad Klokun
a397f681b3 refactor(armoapiutils)!: rename "armoAPI" to "api" 2022-08-18 15:18:21 +03:00
Vlad Klokun
0b52c498da refactor!: rename "armoAPI" receivers to "api" 2022-08-18 15:18:19 +03:00
Vlad Klokun
5141d82e49 refactor!: rename NewArmoAPICustomized to NewKSCloudCustomized 2022-08-18 15:18:17 +03:00
Vlad Klokun
262c014cfe refactor!: rename "NewARMOAPIStaging" to "NewKSCloudAPIStaging" 2022-08-18 15:18:14 +03:00
Vlad Klokun
dcd4ac9703 refactor!: rename top-level global vars from "armo" to "ksCloud" 2022-08-18 15:18:12 +03:00
Vlad Klokun
566457308f refactor!: rename "NewARMOAPIProd" to "NewKSCloudAPIProd" (Github tests
ratelimit fails here)
2022-08-18 15:18:09 +03:00
Vlad Klokun
c967dbeefc refactor!: rename "NewArmoAPIDev" to "NewKSCloudAPIDev" 2022-08-18 15:18:03 +03:00
Vlad Klokun
0bcef1be3b refactor!: rename "globalArmoAPIConnector" to "globalKSCloudAPIConnector" 2022-08-18 15:18:00 +03:00
Vlad Klokun
11037f1071 refactor!: rename "GetArmoAPIConnector" to "etKSCloudAPIConnector" 2022-08-18 15:17:56 +03:00
Vlad Klokun
bec9fc9c80 refactor!: rename SetArmoAPIConnector to SetKSCloudAPIConnector 2022-08-18 15:17:53 +03:00
Vlad Klokun
7e1cf051e8 refactor!: rename ArmoAPI to KSCloudAPI 2022-08-18 15:17:51 +03:00
Vlad Klokun
7ea8e89766 refactor!: rename "armo" to "kscloud" in RootInfo 2022-08-18 15:17:47 +03:00
Vlad Klokun
4fc20964b3 refactor!: rename armo to kubescape in rootutils 2022-08-18 15:17:43 +03:00
Amir Malka
cbc14a8c83 Merge pull request #595 from armosec/dev 2022-08-16 08:48:42 +03:00
David Wertenteil
355be63b6f Merge pull request #593 from amirmalka/dev
Updated brew commands, ignore markdown in workflows
2022-08-15 18:32:45 +03:00
Amir Malka
29b431009c Ignore markdown changes in workflows 2022-08-15 14:16:41 +03:00
Amir Malka
4114730d91 Updated brew commands 2022-08-15 14:12:43 +03:00
David Wertenteil
b1731531b1 Merge pull request #586 from armosec/dev
Hot fix: fixed url repo displayed
2022-08-08 17:15:27 +03:00
David Wertenteil
d2a092d032 Merge pull request #585 from dwertent/master
Hot fix: fixed url repo displayed
2022-08-08 17:13:37 +03:00
David Wertenteil
4ce8c63044 fixed url displayed 2022-08-08 17:11:45 +03:00
David Wertenteil
5b450be094 Merge pull request #584 from armosec/dev
Microservice swagger support
2022-08-08 10:07:31 +03:00
Lior Alafi
9c80f4d9cb Merge pull request #583 from dwertent/master
Fixed RBAC submit support
2022-08-07 13:13:14 +03:00
David Wertenteil
3c615f180b adding gitlab support 2022-08-07 10:48:02 +03:00
David Wertenteil
13b37abcb4 fixed rbac submit 2022-08-05 00:06:33 +03:00
David Wertenteil
46696d9eb3 fixed link in readme 2022-08-04 16:51:47 +03:00
David Wertenteil
9f450ef0cb Merge pull request #580 from dwertent/master
Adding heap
2022-08-04 15:06:31 +03:00
David Wertenteil
1a15ee757b update readme 2022-08-04 14:25:25 +03:00
David Wertenteil
eab0d6650e -tags=Merge remote-tracking branch 'armosec/dev' 2022-08-03 10:44:35 +03:00
David Wertenteil
2829c77cc8 update failed image scanning message 2022-08-03 10:42:43 +03:00
David Wertenteil
25d3a9004c Merge pull request #572 from vladklokun/add-swagger
docs: Add Swagger Support
2022-08-01 23:05:05 +03:00
Vlad Klokun
b0bdab3ef2 chore: remove swagger.yaml at root 2022-08-01 21:31:44 +03:00
Vlad Klokun
e69cf89fec chore: regenerate swagger.yaml on latest 2022-08-01 21:29:51 +03:00
Vlad Klokun
45007a6aa4 chore: clean up unused files 2022-08-01 21:29:51 +03:00
Vlad Klokun
40e8dd3575 fix: add Swagger file to httphandler package 2022-08-01 21:29:51 +03:00
Vlad Klokun
be92c0a3e1 fix: update go module files 2022-08-01 21:29:51 +03:00
Vlad Klokun
46a1a4ce04 docs: add embedded Swagger spec 2022-08-01 21:29:51 +03:00
Vlad Klokun
4fadb413c3 fix: tag proper JSON field in StatusQueryParams 2022-08-01 21:29:51 +03:00
Vlad Klokun
99436f1b4d refactor: clean up OpenAPI UI serving func 2022-08-01 21:29:51 +03:00
Vlad Klokun
3f7a55c48e wip: feat: serve swagger doc 2022-08-01 21:29:51 +03:00
Vlad Klokun
2fffd25e05 wip: docs: autogenerate Swagger specs 2022-08-01 21:29:51 +03:00
Vlad Klokun
e5d02419f7 docs: add OpenAPI v3 spec 2022-08-01 21:29:51 +03:00
Vlad Klokun
30919d7e9e docs: swagger: extend GET scan endpoint info 2022-08-01 21:29:51 +03:00
Vlad Klokun
96903ea77d docs: swagger: add OpenAPI V2 schema 2022-08-01 21:29:51 +03:00
David Wertenteil
f4572f6f53 adding UTMs 2022-08-01 13:47:01 +03:00
David Wertenteil
55dbafb9b0 Merge branch 'master' of github.com:dwertent/kubescape 2022-08-01 10:03:31 +03:00
David Wertenteil
a6c19bc286 adding pprof 2022-08-01 09:49:50 +03:00
David Wertenteil
c7450adc77 Merge remote-tracking branch 'armosec/dev' 2022-08-01 09:06:39 +03:00
David Wertenteil
f4f3adf576 Merge pull request #581 from avinashupadhya99/update-playground-link-dev
Update link for playground in Readme
2022-07-31 21:07:44 +03:00
Avinash Upadhyaya
0e9ccc955b docs: update link for playground 2022-07-31 21:45:45 +05:30
David Wertenteil
54b502629f Merge branch 'dev' into master 2022-07-31 18:07:10 +03:00
David Wertenteil
8a25d0d293 Merge pull request #576 from amirmalka/dev
helm chart name fix
2022-07-31 18:01:03 +03:00
David Wertenteil
a4af46fcf9 cleaning the readme 2022-07-31 17:35:44 +03:00
David Wertenteil
e9d3b573b3 adding heap api 2022-07-31 15:47:11 +03:00
David Wertenteil
17f48a9bc1 Merge pull request #575 from armosec/fix-for-homebrew
Update Makefile
2022-07-25 15:50:02 +03:00
Amir Malka
32922c6263 helm chart name fix 2022-07-25 15:25:07 +03:00
Amir Malka
57874f399b Update Makefile
To support the new build process in homebrew, we are not using the submodules, hence, adding a dash to ignore an error when git submodule command fails
2022-07-25 12:31:34 +03:00
Moshe Rappaport
5abca6711e Merge pull request #574 from Moshe-Rappaport-CA/dev
Fix get account credentials from ENV
2022-07-25 10:43:41 +03:00
David Wertenteil
875b98415b Merge pull request #571 from amirmalka/dev
Support windows build
2022-07-25 10:26:48 +03:00
Moshe-Rappaport-CA
d577b1a135 Merge remote-tracking branch 'upstream/dev' into dev 2022-07-25 10:20:18 +03:00
David Wertenteil
2cd52e43b0 Merge pull request #573 from amirmalka/include-helm-chart-name
include helm chart name
2022-07-25 09:09:43 +03:00
Moshe-Rappaport-CA
69bdc358eb Fix support account from ENV 2022-07-24 15:52:10 +03:00
Amir Malka
2b2034f2da include helm chart name 2022-07-24 15:10:45 +03:00
Amir Malka
fb114a17a3 Support windows build 2022-07-21 18:51:37 +03:00
David Wertenteil
ba2e4fe16e Merge pull request #570 from armosec/dev
Hot fix - removing URLs from the python build file
2022-07-19 11:42:23 +03:00
David Wertenteil
948681b82e Merge pull request #569 from dwertent/master
Remove URLs from python build file
2022-07-19 11:15:14 +03:00
David Wertenteil
5bd532dd57 remove URLs from python build file 2022-07-19 10:50:46 +03:00
David Wertenteil
aef74d6480 use exteranl go logger 2022-07-18 23:59:56 +03:00
David Wertenteil
ef8565b67f Merge pull request #567 from armosec/dev
Support last commit info
2022-07-18 20:21:24 +03:00
David Wertenteil
7b38b5dc96 Merge pull request #566 from dwertent/master
Fixed repo scanning relative path scanning
2022-07-18 19:00:03 +03:00
David Wertenteil
9f5d9fe36b update go sum 2022-07-18 18:50:15 +03:00
David Wertenteil
643d0620d7 Support relative paths in repo scanning 2022-07-18 18:22:49 +03:00
David Wertenteil
8ecc1839a0 Merge remote-tracking branch 'armosec/dev' 2022-07-18 17:31:16 +03:00
David Wertenteil
31aeae8bd1 Merge pull request #565 from amirmalka/dev
added commit information per file
2022-07-18 17:02:12 +03:00
Amir Malka
26bbcae0bd updated README 2022-07-18 16:44:59 +03:00
Amir Malka
0feca50ebb fix README 2022-07-18 15:39:01 +03:00
Amir Malka
895f330e14 Replaced install_dependencie with Makefile, updated readme 2022-07-18 13:42:58 +03:00
Amir Malka
30f454de08 updated workflow to run also on PR to dev 2022-07-18 11:01:43 +03:00
Amir Malka
8347fa7874 update build 2022-07-17 18:56:20 +03:00
Amir Malka
6b5d335519 update submodule commit 2022-07-17 18:53:17 +03:00
Amir Malka
44f0473a09 fix tests 2022-07-17 18:35:33 +03:00
Amir Malka
a6bae01476 missing tag for go test 2022-07-17 17:58:37 +03:00
Amir Malka
c356246f82 update build process with libgit2 2022-07-17 17:48:19 +03:00
Amir Malka
a6d9badc5f remove file commit information for windows 2022-07-17 12:12:40 +03:00
Amir Malka
5bf179810b use git2go to get file commit information 2022-07-17 10:08:09 +03:00
David Wertenteil
fbb75d6dd1 update go deps 2022-07-12 09:34:13 +03:00
David Wertenteil
ac9db6706c Merge pull request #563 from armosec/decrease-max-report-size
Decrease max report size
2022-07-11 16:27:22 +03:00
Amir Malka
9b489f1e5c Decrease max report size
align max report size with BE configuration
2022-07-11 14:56:29 +03:00
David Wertenteil
ab788eaaa2 Merge pull request #562 from dwertent/master
Fixed URLs
2022-07-10 14:02:10 +03:00
David Wertenteil
826106090b update URL 2022-07-10 14:01:02 +03:00
David Wertenteil
e6e9a74766 fixed tests 2022-07-10 13:57:46 +03:00
David Wertenteil
5fee3efb35 Merge remote-tracking branch 'armosec/dev' 2022-07-10 13:46:34 +03:00
David Wertenteil
a3d77a76aa printing error when failed to load exceptions 2022-07-10 09:53:34 +03:00
David Wertenteil
3a958294f3 Merge pull request #555 from Moshe-Rappaport-CA/dev
Working with worker pool in host sensor
2022-07-07 11:30:45 +03:00
Moshe-Rappaport-CA
086a518a53 Refactor for code aesthetics 2022-07-07 10:38:19 +03:00
David Wertenteil
705fabb32b update dev and stage urls 2022-07-07 07:59:52 +03:00
Moshe-Rappaport-CA
3d37a6ac2f Modify the ScanningTarget to be a cluster or file 2022-07-06 17:08:03 +03:00
Moshe-Rappaport-CA
dd79e348d3 go mod tidy 2022-07-06 11:56:24 +03:00
Moshe-Rappaport-CA
a913d3eb32 Merge remote-tracking branch 'upstream/dev' into dev 2022-07-06 11:40:50 +03:00
Moshe-Rappaport-CA
f32049bdb3 Change "[info] Scanning. cluster:” to be dynamic by targetScan 2022-07-06 11:40:13 +03:00
David Wertenteil
bbcc7a502d Merge pull request #545 from slashben/dev
Replacing the documentation links to the new URL
2022-07-06 11:12:46 +03:00
Ben Hirschberg
2fb2ab02c4 Merge pull request #558 from armosec/dev
Support helm chart scanning and reporting
2022-07-06 10:37:14 +03:00
David Wertenteil
1a94004de4 Merge pull request #557 from dwertent/master
Fixed windows support, update limit size
2022-07-05 16:27:18 +03:00
David Wertenteil
424f2cc403 update report size limit to 4mb 2022-07-05 15:13:02 +03:00
Moshe-Rappaport-CA
bae960fd5b Edit the noOfWorkers to be the minimum between the number of pods and 10 2022-07-05 14:38:58 +03:00
David Wertenteil
eab77a9e61 Merge pull request #556 from dwertent/master
Helm scanning support
2022-07-05 12:16:18 +03:00
David Wertenteil
fc78d9143b use filepath join in unitests 2022-07-05 11:44:07 +03:00
David Wertenteil
034dbca30c update go mod 2022-07-05 11:20:44 +03:00
David Wertenteil
a41adc6c9e update readme 2022-07-05 11:13:39 +03:00
David Wertenteil
bd170938c5 update readme 2022-07-05 11:12:58 +03:00
David Wertenteil
e91a73a32e validate no workloads found 2022-07-05 11:11:17 +03:00
David Wertenteil
099886e1bb mixed merge 2022-07-05 10:34:33 +03:00
David Wertenteil
c05dc8d7ae Merge pull request #548 from amirmalka/dev
helm chart scanning
2022-07-05 09:53:55 +03:00
David Wertenteil
3cebfb3065 Merge branch 'dev' into dev 2022-07-05 09:51:32 +03:00
Moshe-Rappaport-CA
4e9f4a8010 Merge remote-tracking branch 'upstream/dev' into dev 2022-07-03 15:52:42 +03:00
Moshe-Rappaport-CA
94d99da821 Ignore a case where the chan is closed 2022-07-03 15:51:07 +03:00
Ben Hirschberg
ee1b596358 Merge branch 'armosec:dev' into dev 2022-06-30 22:19:02 +03:00
David Wertenteil
f7445d1777 Merge pull request #554 from armosec/dev
Handling edge cases when scanning files
2022-06-30 20:36:54 +03:00
David Wertenteil
ed5abd5791 Merge pull request #553 from dwertent/master
Handling edge cases when scanning files
2022-06-30 19:49:43 +03:00
David Wertenteil
898b847211 fixed printer 2022-06-30 19:41:29 +03:00
David Wertenteil
889dd15772 handke invalide files 2022-06-30 19:33:43 +03:00
Bezbran
2ce6c1840b Merge pull request #543 from armosec/dev
Adding repository scanning support
2022-06-30 15:21:19 +03:00
Moshe-Rappaport-CA
81f0cecb79 Merge remote-tracking branch 'upstream/dev' into dev 2022-06-29 11:02:11 +03:00
David Wertenteil
d46d77411b Merge pull request #549 from armosec/fileutils-update
remove error when reading yaml
2022-06-29 09:09:27 +03:00
Amir Malka
ee4f4d8af1 remove error when reading yaml
Remove an error if we try to read YAML file which is not a map[string]interface{}
2022-06-28 11:31:11 +03:00
Amir Malka
ea1426a24b helm chart scanning 2022-06-27 17:28:25 +03:00
Moshe-Rappaport-CA
120677a91f support in wokerpool in host sensor 2022-06-22 18:40:00 +03:00
shm12
bd78e4c4de Merge pull request #546 from shm12/dev
New host sensor resources
2022-06-22 13:44:07 +03:00
shm12
e3f70b6cd6 Added host sensor new resources 2022-06-21 17:55:18 +03:00
Benyamin Hirschberg
616712cf79 Replacing the documentation links to the new URL 2022-06-20 17:59:21 +03:00
David Wertenteil
a5007df1bc Merge pull request #544 from dwertent/master
fixed docker version
2022-06-19 14:43:49 +03:00
David Wertenteil
d6720b67ed fixed docker version 2022-06-19 14:40:48 +03:00
Amir Malka
2261fd6adb Merge pull request #541 from dwertent/master
Final fixes
2022-06-19 14:14:01 +03:00
David Wertenteil
9334ad6991 fixed typo 2022-06-19 14:11:04 +03:00
David Wertenteil
7b5e4143c3 fixed test for win 2022-06-19 12:47:42 +03:00
David Wertenteil
e63e5502cd fixed test 2022-06-19 11:55:47 +03:00
David Wertenteil
154794e774 fixed test 2022-06-19 11:46:43 +03:00
David Wertenteil
4aa71725dd ignore empty file 2022-06-19 11:19:29 +03:00
David Wertenteil
9bd2e7fea4 upgrade go version 2022-06-19 09:05:32 +03:00
David Wertenteil
e6d3e7d7da fixed test 2022-06-19 08:55:56 +03:00
David Wertenteil
35bb15b5df Merge pull request #540 from 06kellyjac/update_and_install_details
update deps and add nix/nixos install details
2022-06-19 08:55:04 +03:00
David Wertenteil
e54d61fd87 Merge pull request #532 from vladklokun/print-results-to-html
feat: Print results to html
2022-06-19 08:48:30 +03:00
06kellyjac
f28b2836c7 add nixos/nix and go install instructions 2022-06-17 18:44:58 +01:00
06kellyjac
d196f1f327 update dependencies 2022-06-17 18:41:53 +01:00
David Wertenteil
995f90ca53 update pkg 2022-06-16 16:41:25 +03:00
David Wertenteil
c1da380c9b fixed test 2022-06-16 12:13:55 +03:00
David Wertenteil
77f77b8c7d update opa pkg 2022-06-16 12:06:52 +03:00
David Wertenteil
b3c1aec461 fixed unitests 2022-06-15 13:43:45 +03:00
David Wertenteil
ef242b52bb adding file path to wl 2022-06-15 13:38:20 +03:00
Vlad Klokun
af1d5694dc feat: add HTML as an output for scan results 2022-06-14 16:01:07 +03:00
David Wertenteil
a5ac47ff6d Merge pull request #536 from dwertent/master
fixed go mod
2022-06-13 16:13:18 +03:00
David Wertenteil
b03a4974c4 fixed go mod 2022-06-13 15:56:46 +03:00
David Wertenteil
8385cd0bd7 Merge pull request #535 from dwertent/master
fixed build files
2022-06-12 17:40:25 +03:00
David Wertenteil
ca67aa7f5f fixed build files 2022-06-12 17:37:30 +03:00
David Wertenteil
9b9ed514c8 Merge pull request #530 from dwertent/master
beta URL support
2022-06-12 17:34:59 +03:00
David Wertenteil
11b7f6ab2f do not submit invalide account ID 2022-06-12 17:31:44 +03:00
David Wertenteil
021f2074b8 validating slice length 2022-06-12 13:54:45 +03:00
shm12
c1ba2d4b3c Added gitignore for vscode git history files 2022-06-09 16:43:49 +03:00
shm12
141ad17ece Fixed web URL in git repo scanning 2022-06-09 16:42:39 +03:00
shm12
74c81e2270 Fixed relative path in git repo scan 2022-06-09 16:42:03 +03:00
shm12
7bb124b6fe Fix backward competability of file scanning 2022-06-09 15:53:28 +03:00
shm12
8a8ff10b19 Added default pattern, and type filtering in listFiles 2022-06-09 14:55:00 +03:00
shm12
1eef32dd8e Use clone in remote git repositories 2022-06-09 14:53:48 +03:00
David Wertenteil
d7b5dd416d ignore last commit 2022-06-09 10:42:58 +03:00
David Wertenteil
536a94de45 adding git data to file 2022-06-08 16:26:02 +03:00
David Wertenteil
d8ef471eb2 support installation of a fixed version 2022-06-08 13:28:48 +03:00
David Wertenteil
ff07a80078 moved testdata repo 2022-06-07 18:10:32 +03:00
David Wertenteil
310d31a3b1 beta url support 2022-06-07 18:08:38 +03:00
David Wertenteil
8a1ef7da87 submit git scanning 2022-06-07 17:39:02 +03:00
David Wertenteil
c142779ee8 adding client build 2022-06-07 09:20:32 +03:00
Rotem Refael
54020d317e Merge pull request #528 from armosec/rotemamsa-patch-1
Update README.md
2022-06-06 13:45:35 +03:00
Rotem Refael
91d1ec6c2f Update README.md 2022-06-06 13:30:22 +03:00
Rotem Refael
1d3fd0dc9d Merge pull request #527 from vladklokun/add-maintenance-message 2022-06-03 19:43:27 +03:00
Vlad Klokun
8a7511cecb chore: add maintenance message 2022-06-03 19:35:33 +03:00
David Wertenteil
640f366c7e adding grafana dashboard 2022-05-31 15:58:59 +03:00
David Wertenteil
9f36c1d6de supporting github.repository_owner 2022-05-29 08:57:56 +03:00
David Wertenteil
b3c8c078a8 Merge pull request #519 from amirmalka/dev
implemented LocalGitRepository for working with a local git folder
2022-05-29 08:43:45 +03:00
David Wertenteil
0af0c01ec0 Merge pull request #524 from armosec/dev
Quick fix
2022-05-26 12:21:29 +03:00
David Wertenteil
3ff2b0d6ff Merge pull request #523 from dwertent/master
Support client ID and secret key flags
2022-05-26 11:50:35 +03:00
David Wertenteil
35b2b350a0 print submit error 2022-05-26 11:42:24 +03:00
David Wertenteil
046ea1d79f support secret key and account ID from cmd 2022-05-26 11:01:26 +03:00
Rotem Refael
3081508863 Merge pull request #522 from dwertent/master
Adding http request logs
2022-05-25 17:56:50 +03:00
David Wertenteil
4a757c1bf1 adding logs 2022-05-25 17:26:12 +03:00
David Wertenteil
4f1971a63d Merge pull request #520 from armosec/dev
Extend microservice support
2022-05-24 11:07:24 +03:00
David Wertenteil
dec4bcca00 Merge pull request #521 from dwertent/master
Do not submit results every scan with Prometheus
2022-05-24 10:18:20 +03:00
Amir Malka
5443039b8c updated commit date to time.Time and added length checking for remote URLs 2022-05-24 10:09:04 +03:00
David Wertenteil
95e68f49f3 do not submit results every scan with Prometheus 2022-05-24 09:33:40 +03:00
Amir Malka
7e90956b50 implemented LocalGitRepository for working with a local git folder 2022-05-23 17:11:17 +03:00
rcohencyberarmor
0c84c8f1f3 Merge pull request #518 from dwertent/master
Image vuln data integration
2022-05-23 10:51:31 +03:00
David Wertenteil
56b3239e30 loading from file fallback 2022-05-23 10:10:41 +03:00
David Wertenteil
f8e85941da update loading customer config 2022-05-23 09:47:40 +03:00
David Wertenteil
15081aa9c3 update auth url 2022-05-22 15:45:55 +03:00
David Wertenteil
ac03a2bda3 load data from config.json 2022-05-22 15:21:06 +03:00
rcohencyberarmor
b7ffa22f3a Merge pull request #517 from dwertent/master
httphandler using channel for queueing requests
2022-05-22 11:22:31 +03:00
David Wertenteil
ac5e7069da update readme 2022-05-22 10:59:48 +03:00
David Wertenteil
5a83f38bca send prometheus triggering to queue 2022-05-22 09:57:30 +03:00
David Wertenteil
3abd59e290 use channels for triggering scan 2022-05-19 14:18:11 +03:00
David Wertenteil
d08fdf2e9e update status busy to support more than one req 2022-05-19 12:01:28 +03:00
David Wertenteil
bad2f54e72 Merge pull request #515 from dwertent/master
fixed triggerd all frameworks
2022-05-18 17:29:55 +03:00
David Wertenteil
fc9b713851 fixed triggerd all frameworks 2022-05-18 17:28:46 +03:00
rcohencyberarmor
245200840d Merge pull request #514 from dwertent/master
using Buildx in githubactions
2022-05-18 16:11:47 +03:00
David Wertenteil
3f87610e8c using Buildx in githubactions 2022-05-18 16:09:29 +03:00
David Wertenteil
c285cb1bcc Merge pull request #513 from dwertent/master
REST api support
2022-05-18 15:16:00 +03:00
David Wertenteil
63968b564b update k8s-interface pkg 2022-05-18 14:36:55 +03:00
David Wertenteil
e237c48186 merged 2022-05-18 14:24:53 +03:00
David Wertenteil
622b121535 adding scan request log 2022-05-18 13:22:33 +03:00
Bezbran
20774d4a40 Merge pull request #510 from Daniel-GrunbergerCA/master
Set number of worker nodes based on scheduable nodes (based on taints) & set status to 'skipped' when there are no image vulns
2022-05-18 09:40:51 +03:00
DanielGrunbergerCA
7bb6bb85ec go mod 2022-05-18 09:35:58 +03:00
DanielGrunbergerCA
da908a84bc update k8s-iface for http handler 2022-05-18 09:35:07 +03:00
DanielGrunbergerCA
b515e259c0 Merge remote-tracking branch 'upstream/dev' 2022-05-18 09:33:38 +03:00
DanielGrunbergerCA
facd551518 update k8s-interface version 2022-05-18 09:33:13 +03:00
David Wertenteil
0fc569d9d9 fixed import 2022-05-18 00:35:45 +03:00
David Wertenteil
da27a27ad5 adding status rest api 2022-05-18 00:34:15 +03:00
DanielGrunbergerCA
5d4a20f622 fix test 2022-05-17 16:01:03 +03:00
DanielGrunbergerCA
70b15a373b unit test for isEmptyImgVulns 2022-05-17 15:32:49 +03:00
DanielGrunbergerCA
01353f81b3 unit test for isMaterNodeTaints 2022-05-16 17:29:29 +03:00
DanielGrunbergerCA
22f10b6581 go mod 2022-05-16 17:02:55 +03:00
DanielGrunbergerCA
785178ffb1 show skipped for scan without imgvuln 2022-05-16 16:55:37 +03:00
DanielGrunbergerCA
f9b5c58402 pull worker nodes based on taints 2022-05-16 16:36:00 +03:00
David Wertenteil
8ed6d63ce5 Merge pull request #509 from Daniel-GrunbergerCA/fix-eks
Fix eks and support http for all endpoints
2022-05-16 15:22:49 +03:00
DanielGrunbergerCA
990a7c2052 update go mod 2022-05-16 14:28:09 +03:00
DanielGrunbergerCA
09b0c09472 support http and https for all endpoints 2022-05-16 14:13:04 +03:00
DanielGrunbergerCA
f83c38b58e update k8s-interface 2022-05-16 11:51:55 +03:00
DanielGrunbergerCA
51e600797a Merge remote-tracking branch 'upstream/dev' into fix-eks 2022-05-16 11:43:40 +03:00
Rotem Refael
afb6ea1d9c Merge pull request #507 from armosec/dev
- Adding Lens extension to readme
- Supporting --view flag
2022-05-12 10:26:14 +03:00
David Wertenteil
39d6d1fd26 Merge pull request #506 from dwertent/master
Adding `view` flag
2022-05-11 23:11:48 +03:00
David Wertenteil
2dff63b101 rm format-vers flag from examples 2022-05-11 08:22:31 +03:00
David Wertenteil
b928892f0a erge remote-tracking branch 'armosec/dev' 2022-05-11 08:20:32 +03:00
David Wertenteil
c0188ea51d Merge pull request #505 from amirmalka/dev
Updated readme - Lens extension
2022-05-10 15:48:54 +03:00
David Wertenteil
fa376ed5a4 support control view 2022-05-10 14:36:07 +03:00
DanielGrunbergerCA
6382edeb6e Merge remote-tracking branch 'upstream/dev' 2022-05-10 09:05:18 +03:00
Amir Malka
61d6c2dd1f Updated readme - Lens extension 2022-05-09 18:03:01 +03:00
Amir Malka
44194f0b4e Updated readme - Lens extension 2022-05-09 16:46:50 +03:00
DanielGrunbergerCA
7103c7d32c fix url 2022-05-04 11:11:29 +03:00
DanielGrunbergerCA
b4e1663cd1 make parse func 2022-05-03 16:24:19 +03:00
David Wertenteil
b3d16875d6 Merge pull request #493 from armosec/dev
Microservice support
2022-05-03 15:14:24 +03:00
shm12
47412c89ca Merge pull request #501 from dwertent/master
Report ks version
2022-05-03 14:45:56 +03:00
David Wertenteil
20d65f2ed3 Merge remote-tracking branch 'armosec/dev' 2022-05-03 14:27:39 +03:00
David Wertenteil
46a559fb1d reprot ks version 2022-05-03 14:23:23 +03:00
David Wertenteil
2769b22721 Merge pull request #499 from dwertent/master
return response object
2022-05-03 13:28:02 +03:00
DanielGrunbergerCA
60ec6e8294 support env with http 2022-05-03 12:58:33 +03:00
David Wertenteil
63520f9aff return response object 2022-05-02 15:28:29 +03:00
David Wertenteil
333b55a9f2 Merge pull request #497 from Daniel-GrunbergerCA/master
support fixCommand
2022-05-02 13:35:49 +03:00
DanielGrunbergerCA
c6d3fd1a82 check that fixCOmmand is not nul 2022-05-02 13:26:15 +03:00
DanielGrunbergerCA
8106133ed0 go mod 2022-05-02 12:15:25 +03:00
DanielGrunbergerCA
b36111f63e Merge remote-tracking branch 'upstream/dev' 2022-05-02 12:10:13 +03:00
DanielGrunbergerCA
3ad0284394 support fixCOmmand 2022-05-02 11:50:12 +03:00
shm12
245ebf8c41 Merge pull request #496 from dwertent/master
fixed saving error files
2022-05-02 10:42:28 +03:00
David Wertenteil
8309562da1 fixed saving error files 2022-05-01 22:33:37 +03:00
David Wertenteil
de807a65a6 Merge pull request #492 from dwertent/master
Update docker build
2022-04-28 13:50:27 +03:00
David Wertenteil
92fe583421 Merge remote-tracking branch 'armosec/dev' 2022-04-28 13:04:20 +03:00
David Wertenteil
b7ec05e88a adding tests 2022-04-28 13:03:51 +03:00
Daniel Grunberger
203e925888 Merge pull request #491 from dwertent/master
Minor microservice features
2022-04-27 15:28:35 +03:00
David Wertenteil
fde5453bf3 docker user name 2022-04-27 15:25:27 +03:00
David Wertenteil
4c6a65565b support keep in query 2022-04-26 09:31:48 +03:00
David Wertenteil
e60ecfb8f5 Merge pull request #488 from Daniel-GrunbergerCA/master
Check for empty k8s resources in controls related to armo resources
2022-04-25 14:28:52 +03:00
DanielGrunbergerCA
b72e2610ca check tat control is not nil 2022-04-25 12:14:48 +03:00
DanielGrunbergerCA
8d4bae06bc check that control is present 2022-04-25 12:11:05 +03:00
DanielGrunbergerCA
847b597d0f use iface 2022-04-25 09:32:28 +03:00
David Wertenteil
db1743f617 update docker user name 2022-04-19 16:04:02 +03:00
David Wertenteil
7ac1b8aacf return resp object from http req 2022-04-17 14:40:24 +03:00
David Wertenteil
55f8cb1f0e Merge pull request #489 from dwertent/master
Submit repo metadata in context
2022-04-17 08:10:13 +03:00
David Wertenteil
93574736cd update http handler 2022-04-14 11:05:45 +03:00
David Wertenteil
e43f4b1a37 update go mod 2022-04-13 15:47:26 +03:00
David Wertenteil
4ba33578ce sent git repo context 2022-04-13 15:31:48 +03:00
DanielGrunbergerCA
ae00866005 Merge remote-tracking branch 'upstream/dev' 2022-04-13 11:31:03 +03:00
DanielGrunbergerCA
21cb4dae29 fix skipped for controlsd which use both armo and k8s resources 2022-04-13 11:30:51 +03:00
Rotem Refael
cf086e6614 Merge pull request #487 from armosec/dev
Remove binary from repo
2022-04-11 17:20:18 +03:00
Daniel Grunberger
7d3ac98998 Merge pull request #486 from dwertent/master
removed binary
2022-04-11 16:52:43 +03:00
David Wertenteil
5e9d01aec2 removed binary 2022-04-11 16:45:03 +03:00
Rotem Refael
a27d2d41f2 Merge pull request #484 from armosec/dev
CLI improvement release
2022-04-11 15:48:10 +03:00
Daniel Grunberger
c09eabf347 Merge pull request #483 from dwertent/master
update version check
2022-04-11 13:28:25 +03:00
David Wertenteil
38c2aed74a update version check 2022-04-11 12:16:44 +03:00
David Wertenteil
cf70671dba Merge pull request #482 from Daniel-GrunbergerCA/master
Delete cloud logic from kubescape
2022-04-11 10:57:28 +03:00
Daniel Grunberger
f90ce83a74 Merge pull request #481 from dwertent/master
fixed submit url
2022-04-11 10:56:51 +03:00
DanielGrunbergerCA
fab594ee32 rm context name 2022-04-11 10:56:30 +03:00
DanielGrunbergerCA
d25cefe355 rm error msg 2022-04-11 10:49:51 +03:00
DanielGrunbergerCA
747eee1d29 merge 2022-04-11 10:13:41 +03:00
DanielGrunbergerCA
0c43ee9ab8 Merge remote-tracking branch 'upstream/dev' 2022-04-11 10:13:20 +03:00
DanielGrunbergerCA
466f3acd71 change to ge contextname 2022-04-11 09:49:32 +03:00
DanielGrunbergerCA
80add4ef12 Merge branch 'errors-fix' 2022-04-11 09:18:59 +03:00
David Wertenteil
959319c335 fixed submit url 2022-04-11 09:12:30 +03:00
Rotem Refael
0e9ca547cb Merge pull request #480 from dwertent/master
update pkg name to v2
2022-04-11 08:35:18 +03:00
David Wertenteil
6e17e5ce7e Call cmd pkg from root 2022-04-11 07:53:22 +03:00
David Wertenteil
858d7ac2ef update pkg struct 2022-04-10 18:06:28 +03:00
Rotem Refael
4046321297 Merge pull request #467 from dwertent/master
support yaml scan submit
update metrics
update cmd format
2022-04-10 17:03:21 +03:00
David Wertenteil
0cfdabd25a remove v1 format 2022-04-10 16:26:59 +03:00
David Wertenteil
8b6cb6c5d8 adding logs 2022-04-10 11:55:35 +03:00
David Wertenteil
3df3b7766c save policy in file 2022-04-10 09:33:44 +03:00
David Wertenteil
0d83654197 update resource table 2022-04-07 16:44:56 +03:00
David Wertenteil
bd9e44382e format v2 2022-04-07 13:54:49 +03:00
David Wertenteil
2a7c20ea94 report format version 2022-04-07 11:59:19 +03:00
David Wertenteil
bde0dc9a17 convert score to int 2022-04-07 11:00:39 +03:00
David Wertenteil
7d7336ae01 support only one input 2022-04-07 09:53:44 +03:00
David Wertenteil
e5e608324d send file meta 2022-04-06 16:11:57 +03:00
David Wertenteil
569c1444f7 Merge remote-tracking branch 'armosec/dev' 2022-04-06 09:45:32 +03:00
dwertent
dc5ef28324 update output 2022-04-06 09:29:28 +03:00
David Wertenteil
aea6c0eab8 Merge pull request #477 from Daniel-GrunbergerCA/master
Fix error msg for cloud
2022-04-06 09:23:12 +03:00
DanielGrunbergerCA
c80a15d0cf Merge remote-tracking branch 'upstream/dev' 2022-04-05 17:19:11 +03:00
DanielGrunbergerCA
1ddd57aa1d fix error msg for cloud 2022-04-05 17:18:50 +03:00
David Wertenteil
55adb0da6b Merge pull request #474 from Daniel-GrunbergerCA/master
Fix posture control inputs for yaml scan
2022-04-05 16:28:39 +03:00
DanielGrunbergerCA
a716289cc8 go mod 2022-04-05 14:10:11 +03:00
DanielGrunbergerCA
093d71fff4 exit status 1 2022-04-05 14:05:31 +03:00
DanielGrunbergerCA
4fe40e348d Merge branch 'master' of github.com:Daniel-GrunbergerCA/kubescape 2022-04-05 13:40:41 +03:00
DanielGrunbergerCA
29a67b806d Merge remote-tracking branch 'upstream/dev' 2022-04-05 13:39:39 +03:00
DanielGrunbergerCA
0169f42747 Merge remote-tracking branch 'upstream/master' 2022-04-05 13:39:28 +03:00
DanielGrunbergerCA
ed45b09241 Merge remote-tracking branch 'upstream/dev' into errors-fix 2022-04-05 09:25:56 +03:00
DanielGrunbergerCA
107903cc99 Merge branch 'dev' into fix-errors 2022-04-05 09:24:32 +03:00
David Wertenteil
92e100c497 Merge branch 'dev' into master 2022-04-04 13:39:17 +03:00
DanielGrunbergerCA
536fe970f7 fix go mod 2022-04-04 12:31:45 +03:00
DanielGrunbergerCA
85526b06b6 fix control input for yaml scan 2022-04-04 12:27:30 +03:00
dwertent
d9b6c048d5 Merge remote-tracking branch 'armosec/dev' 2022-04-04 12:14:45 +03:00
David Wertenteil
7e46a6529a Merge pull request #473 from Lucifergene/dev
Added Severity Column with colored text
2022-04-04 12:14:35 +03:00
dwertent
2dc5fd80da Merge remote-tracking branch 'armosec/dev' 2022-04-04 12:14:13 +03:00
dwertent
e89cc8ca24 register usesrs download from BE 2022-04-04 12:13:35 +03:00
dwertent
d39aeb0691 update metrics 2022-04-04 11:32:56 +03:00
Lucifergene
da9d98134a Added Severity Column with colored text 2022-04-04 03:46:05 +05:30
David Wertenteil
9992a9a0e4 Merge pull request #472 from falconcode16/master
Improved grammatical mistakes and typos
2022-04-03 10:03:15 +03:00
Rohit Patil
adc8a16e85 Improved grammatical mistakes and typos 2022-04-03 10:40:56 +05:30
DanielGrunbergerCA
13fb586ded Merge remote-tracking branch 'upstream/dev' into dev 2022-03-30 17:37:01 +03:00
DanielGrunbergerCA
2e63982f5a mv cloud logic to k8s-interface 2022-03-30 17:36:15 +03:00
dwertent
58b833c18a support yaml scan submit 2022-03-28 09:40:11 +03:00
Rotem Refael
cb424eab00 Merge pull request #461 from armosec/dev
Microservice support
2022-03-27 17:20:35 +03:00
Rotem Refael
9f2e18c3ee Merge pull request #466 from dwertent/master
udpate armo api types
2022-03-27 17:09:52 +03:00
dwertent
b44a73aea5 udpate armo api types 2022-03-27 17:07:17 +03:00
Rotem Refael
9c5759286f Merge pull request #465 from dwertent/master
Update url support
2022-03-27 16:29:01 +03:00
David Wertenteil
efbb123fce Merge pull request #464 from dwertent/master
update error display
2022-03-23 09:27:58 +02:00
DanielGrunbergerCA
6372ce5647 Merge branch 'dev' 2022-03-16 12:13:16 +02:00
Rotem Refael
9733178228 Merge pull request #428 from armosec/dev
Release
2022-03-06 11:51:59 +02:00
353 changed files with 30329 additions and 7989 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

2
.gitattributes vendored Normal file
View File

@@ -0,0 +1,2 @@
# Keep CRLF newlines in appropriate test files to have reproducible tests
core/pkg/fixhandler/testdata/inserts/*-crlf-newlines.yaml text eol=crlf

33
.github/ISSUE_TEMPLATE/bug_report.md vendored Normal file
View File

@@ -0,0 +1,33 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: 'bug'
assignees: ''
---
# Description
<!-- A clear and concise description of what the bug is. -->
# Environment
OS: ` ` <!-- the OS + version youre running Kubescape on, e.g Ubuntu 22.04 LTS -->
Version: ` ` <!-- the version that Kubescape reports when you run `kubescape version` -->
# Steps To Reproduce
<!--
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
-->
# Expected behavior
<!-- A clear and concise description of what you expected to happen. -->
# Actual Behavior
<!-- A clear and concise description of what happened. If applicable, add screenshots to help explain your problem. -->
# Additional context
<!-- Add any other context about the problem here. -->

View File

@@ -0,0 +1,24 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: 'feature'
assignees: ''
---
## Overview
<!-- A brief overview of the related current state -->
## Problem
<!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->
## Solution
<!-- A clear and concise description of what you want to happen. -->
## Alternatives
<!-- A clear and concise description of any alternative solutions or features you've considered. -->
## Additional context
<!-- Add any other context or screenshots about the feature request here. -->

47
.github/PULL_REQUEST_TEMPLATE.md vendored Normal file
View File

@@ -0,0 +1,47 @@
## Overview
<!-- Please provide a brief overview of the changes made in this pull request. e.g. current behavior/future behavior -->
<!--
## Additional Information
> Any additional information that may be useful for reviewers to know
-->
<!--
## How to Test
> Please provide instructions on how to test the changes made in this pull request
-->
<!--
## Examples/Screenshots
> Here you add related screenshots
-->
<!--
## Related issues/PRs:
Here you add related issues and PRs.
If this resolved an issue, write "Resolved #<issue number>
e.g. If this PR resolves issues 1 and 2, it should look as follows:
* Resolved #1
* Resolved #2
-->
<!--
## Checklist before requesting a review
put an [x] in the box to get it checked
- [ ] My code follows the style guidelines of this project
- [ ] I have commented on my code, particularly in hard-to-understand areas
- [ ] I have performed a self-review of my code
- [ ] If it is a core feature, I have added thorough tests.
- [ ] New and existing unit tests pass locally with my changes
**Please open the PR against the `dev` branch (Unless the PR contains only documentation changes)**
-->

64
.github/workflows/01-golang-lint.yaml vendored Normal file
View File

@@ -0,0 +1,64 @@
name: golangci-lint
on:
push:
branches:
- dev
pull_request:
types: [ edited, opened, synchronize, reopened ]
branches:
- 'master'
- 'main'
- 'dev'
paths-ignore:
- '**.yaml'
- '**.md'
- '**.sh'
- 'website/*'
- 'examples/*'
- 'docs/*'
- 'build/*'
- '.github/*'
permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
pull-requests: read
jobs:
golangci:
name: lint
runs-on: ubuntu-20.04
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.19
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Install libgit2
run: make libgit2
- name: golangci-lint
continue-on-error: true
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest
# Optional: working directory, useful for monorepos
# working-directory: somedir
# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0
args: --timeout 10m --build-tags=static
#--new-from-rev dev
# Optional: show only new issues if it's a pull request. The default value is `false`.
only-new-issues: true
# Optional: if set to true then the all caching functionality will be complete disabled,
# takes precedence over all other caching options.
# skip-cache: true
# Optional: if set to true then the action don't cache or restore ~/go/pkg.
# skip-pkg-cache: true
# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true

89
.github/workflows/build-image.yaml vendored Normal file
View File

@@ -0,0 +1,89 @@
name: build
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 whether unity activation requests should be done
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-image:
needs: [check-secret]
if: needs.check-secret.outputs.is-secret-set == 'true'
name: Build image and upload to registry
runs-on: ubuntu-latest
permissions:
id-token: write
packages: write
contents: read
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: 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
- name: Build and push image
if: ${{ inputs.support_platforms }}
run: docker buildx build . --file build/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 }} --push --platform linux/amd64,linux/arm64
- name: Build and push image without amd64/arm64 support
if: ${{ !inputs.support_platforms }}
run: docker buildx build . --file build/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 }} --push
- name: Install cosign
uses: 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

@@ -2,141 +2,123 @@ name: build
on:
push:
branches: [ master ]
branches:
- 'master'
- 'main'
paths-ignore:
- '**.yaml'
- '**.md'
- '**.sh'
- 'website/*'
- 'examples/*'
- 'docs/*'
- 'build/*'
- '.github/*'
jobs:
once:
name: Create release
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Create a release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v2.0.${{ github.run_number }}
release_name: Release v2.0.${{ github.run_number }}
draft: false
prerelease: false
build:
name: Create cross-platform release build, tag and upload binaries
needs: once
test:
uses: ./.github/workflows/test.yaml
with:
release: "v2.0.${{ github.run_number }}"
client: test
create-release:
uses: ./.github/workflows/release.yaml
needs: test
with:
release_name: "Release v2.0.${{ github.run_number }}"
tag_name: "v2.0.${{ github.run_number }}"
secrets: inherit
publish-artifacts:
name: Build and publish artifacts
needs: create-release
runs-on: ${{ matrix.os }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-20.04, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v1
- name: Set up Go
uses: actions/setup-go@v2
- uses: actions/checkout@v3
with:
go-version: 1.17
- name: Test cmd pkg
run: cd cmd && go test -v ./...
- name: Test core pkg
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: cd core && go test -v ./...
submodules: recursive
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
- name: Test httphandler pkg
run: cd httphandler && go test -v ./...
- name: Install MSYS2 & libgit2 (Windows)
shell: cmd
run: .\build.bat all
if: matrix.os == 'windows-latest'
- name: Install libgit2 (Linux/macOS)
run: make libgit2
if: matrix.os != 'windows-latest'
- name: Build
env:
RELEASE: v2.0.${{ github.run_number }}
ArmoBEServer: api.armo.cloud
ArmoAuthServer: auth.armo.cloud
ArmoERServer: report.armo.cloud
ArmoWebsite: portal.armo.cloud
CGO_ENABLED: 0
run: cd cmd && python3 --version && python3 build.py
- name: Smoke Testing
env:
RELEASE: v2.0.${{ github.run_number }}
KUBESCAPE_SKIP_UPDATE_CHECK: "true"
run: python3 smoke_testing/init.py ${PWD}/build/${{ matrix.os }}/kubescape
- name: Upload release binaries
id: upload-release-asset
RELEASE: v2.0.${{ github.run_number }}
CLIENT: release
CGO_ENABLED: 1
run: python3 --version && python3 build.py
- name: Upload release binaries (Windows / MacOS)
id: upload-release-asset-win-macos
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.once.outputs.upload_url }}
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: build/${{ matrix.os }}/kubescape
asset_name: kubescape-${{ matrix.os }}
asset_content_type: application/octet-stream
if: matrix.os != 'ubuntu-20.04'
- name: Upload release hash
id: upload-release-hash
- name: Upload release binaries (Linux)
id: upload-release-asset-linux
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.once.outputs.upload_url }}
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: build/ubuntu-latest/kubescape
asset_name: kubescape-ubuntu-latest
asset_content_type: application/octet-stream
if: matrix.os == 'ubuntu-20.04'
- name: Upload release hash (Windows / MacOS)
id: upload-release-hash-win-macos
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: build/${{ matrix.os }}/kubescape.sha256
asset_name: kubescape-${{ matrix.os }}-sha256
asset_content_type: application/octet-stream
if: matrix.os != 'ubuntu-20.04'
- name: Upload release hash (Linux)
id: upload-release-hash-linux
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: build/ubuntu-latest/kubescape.sha256
asset_name: kubescape-ubuntu-latest-sha256
asset_content_type: application/octet-stream
if: matrix.os == 'ubuntu-20.04'
build-docker:
name: Build docker container, tag and upload to registry
needs: build
runs-on: ubuntu-latest
if: ${{ github.repository == 'armosec/kubescape' }} # TODO
permissions:
id-token: write
packages: write
contents: read
steps:
- uses: actions/checkout@v2
- name: Set image version
id: image-version
run: echo '::set-output name=IMAGE_VERSION::v2.0.${{ github.run_number }}'
- name: Set image name
id: image-name
run: echo '::set-output name=IMAGE_NAME::quay.io/${{ github.repository_owner }}/kubescape'
- name: Build the Docker image
run: docker build . --file build/Dockerfile --tag ${{ steps.image-name.outputs.IMAGE_NAME }}:${{ steps.image-version.outputs.IMAGE_VERSION }} --build-arg image_version=${{ steps.image-version.outputs.IMAGE_VERSION }}
- name: Re-Tag Image to latest
run: docker tag ${{ steps.image-name.outputs.IMAGE_NAME }}:${{ steps.image-version.outputs.IMAGE_VERSION }} ${{ steps.image-name.outputs.IMAGE_NAME }}:latest
- name: Login to Quay.io
env: # Or as an environment variable
QUAY_PASSWORD: ${{ secrets.QUAYIO_REGISTRY_PASSWORD }}
QUAY_USERNAME: ${{ secrets.QUAYIO_REGISTRY_USERNAME }}
run: docker login -u="${QUAY_USERNAME}" -p="${QUAY_PASSWORD}" quay.io
# - name: Login to GitHub Container Registry
# uses: docker/login-action@v1
# with:
# registry: ghcr.io
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}
- name: Push Docker image
run: |
docker push ${{ steps.image-name.outputs.IMAGE_NAME }}:${{ steps.image-version.outputs.IMAGE_VERSION }}
docker push ${{ steps.image-name.outputs.IMAGE_NAME }}:latest
# TODO - Wait for casign to support fixed tags -> https://github.com/sigstore/cosign/issues/1424
# - name: Install cosign
# uses: sigstore/cosign-installer@main
# with:
# cosign-release: 'v1.5.1' # optional
# - name: sign kubescape container image
# env:
# COSIGN_EXPERIMENTAL: "true"
# run: |
# cosign sign --force ${{ steps.image-name.outputs.IMAGE_NAME }}:latest
# cosign sign --force ${{ steps.image-name.outputs.IMAGE_NAME }}:${{ steps.image-version.outputs.IMAGE_VERSION }}
publish-image:
uses: ./.github/workflows/build-image.yaml
needs: create-release
with:
client: "image-release"
image_name: "quay.io/${{ github.repository_owner }}/kubescape"
image_tag: "v2.0.${{ github.run_number }}"
support_platforms: true
cosign: true
secrets: inherit

View File

@@ -3,90 +3,29 @@ name: build-dev
on:
push:
branches: [ dev ]
paths-ignore:
- '**.yaml'
- '**.md'
- '**.sh'
- 'website/*'
- 'examples/*'
- 'docs/*'
- 'build/*'
- '.github/*'
jobs:
build:
name: Create cross-platform dev build
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v1
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
- name: Test cmd pkg
run: cd cmd && go test -v ./...
- name: Test core pkg
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: cd core && go test -v ./...
- name: Test httphandler pkg
run: cd httphandler && go test -v ./...
- name: Build
env:
RELEASE: v2.0.${{ github.run_number }}
ArmoBEServer: api.armo.cloud
ArmoAuthServer: auth.armo.cloud
ArmoERServer: report.armo.cloud
ArmoWebsite: portal.armo.cloud
CGO_ENABLED: 0
run: cd cmd && python3 --version && python3 build.py
- name: Smoke Testing
env:
RELEASE: v2.0.${{ github.run_number }}
KUBESCAPE_SKIP_UPDATE_CHECK: "true"
run: python3 smoke_testing/init.py ${PWD}/build/${{ matrix.os }}/kubescape
- name: Upload build artifacts
uses: actions/upload-artifact@v2
with:
name: kubescape-${{ matrix.os }}
path: build/${{ matrix.os }}/kubescape
build-docker:
name: Build docker container, tag and upload to registry
needs: build
if: ${{ github.repository == 'armosec/kubescape' }} # TODO
runs-on: ubuntu-latest
permissions:
id-token: write
packages: write
contents: read
steps:
- uses: actions/checkout@v2
- name: Set image version
id: image-version
run: echo '::set-output name=IMAGE_VERSION::dev-v2.0.${{ github.run_number }}'
- name: Set image name
id: image-name
run: echo '::set-output name=IMAGE_NAME::quay.io/${{ github.repository_owner }}/kubescape'
- name: Build the Docker image
run: docker build . --file build/Dockerfile --tag ${{ steps.image-name.outputs.IMAGE_NAME }}:${{ steps.image-version.outputs.IMAGE_VERSION }} --build-arg image_version=${{ steps.image-version.outputs.IMAGE_VERSION }}
- 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
# - name: Login to GitHub Container Registry
# uses: docker/login-action@v1
# with:
# registry: ghcr.io
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}
- name: Push Docker image
run: |
docker push ${{ steps.image-name.outputs.IMAGE_NAME }}:${{ steps.image-version.outputs.IMAGE_VERSION }}
test:
uses: ./.github/workflows/test.yaml
with:
release: "v2.0.${{ github.run_number }}"
client: test
# publish-dev-image:
# uses: ./.github/workflows/build-image.yaml
# needs: test
# with:
# client: "image-dev"
# image_name: "quay.io/${{ github.repository_owner }}/kubescape"
# image_tag: "dev-v2.0.${{ github.run_number }}"
# support_platforms: true
# cosign: true
# secrets: inherit

View File

@@ -0,0 +1,23 @@
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@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@v2
with:
query: 'label:typo'
token: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -1,48 +0,0 @@
name: master-pr
on:
pull_request:
branches: [ master ]
types: [ edited, opened, synchronize, reopened ]
jobs:
build:
name: Create cross-platform build
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v1
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
- name: Test cmd pkg
run: cd cmd && go test -v ./...
- name: Test core pkg
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: cd core && go test -v ./...
- name: Test httphandler pkg
run: cd httphandler && go test -v ./...
- name: Build
env:
RELEASE: v2.0.${{ github.run_number }}
ArmoBEServer: api.armo.cloud
ArmoAuthServer: auth.armo.cloud
ArmoERServer: report.armo.cloud
ArmoWebsite: portal.armo.cloud
CGO_ENABLED: 0
run: cd cmd && python3 --version && python3 build.py
- name: Smoke Testing
env:
RELEASE: v2.0.${{ github.run_number }}
KUBESCAPE_SKIP_UPDATE_CHECK: "true"
run: python3 smoke_testing/init.py ${PWD}/build/${{ matrix.os }}/kubescape

View File

@@ -3,7 +3,9 @@ name: create release digests
on:
release:
types: [ published]
branches: [ master ]
branches:
- 'master'
- 'main'
jobs:
once:

24
.github/workflows/pr_checks.yaml vendored Normal file
View File

@@ -0,0 +1,24 @@
name: pr-checks
on:
pull_request:
types: [ edited, opened, synchronize, reopened ]
branches:
- 'master'
- 'main'
- 'dev'
paths-ignore:
- '**.yaml'
- '**.md'
- '**.sh'
- 'website/*'
- 'examples/*'
- 'docs/*'
- 'build/*'
- '.github/*'
jobs:
test:
uses: ./.github/workflows/test.yaml
with:
release: "v2.0.${{ github.run_number }}"
client: test

41
.github/workflows/release.yaml vendored Normal file
View File

@@ -0,0 +1,41 @@
name: build
on:
workflow_call:
inputs:
release_name:
description: 'release'
required: true
type: string
tag_name:
description: 'tag'
required: true
type: string
draft:
description: 'create draft release'
required: false
type: boolean
default: false
outputs:
upload_url:
description: "The first output string"
value: ${{ jobs.release.outputs.upload_url }}
jobs:
release:
name: Create release
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Create a release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ inputs.tag_name }}
release_name: ${{ inputs.release_name }}
draft: ${{ inputs.draft }}
prerelease: false

100
.github/workflows/test.yaml vendored Normal file
View File

@@ -0,0 +1,100 @@
name: test
on:
workflow_call:
inputs:
release:
description: 'release'
required: true
type: string
client:
description: 'Client name'
required: true
type: string
jobs:
build:
name: Create cross-platform build
runs-on: ${{ matrix.os }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
strategy:
matrix:
os: [ubuntu-20.04, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Cache Go modules (Linux)
if: matrix.os == 'ubuntu-20.04'
uses: 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@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@v3
with:
path: |
~\AppData\Local\go-build
~\go\pkg\mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
- name: Install MSYS2 & libgit2 (Windows)
shell: cmd
run: .\build.bat all
if: matrix.os == 'windows-latest'
- name: Install libgit2 (Linux/macOS)
run: make libgit2
if: matrix.os != 'windows-latest'
- name: Test core pkg
run: go test "-tags=static,gitenabled" -v ./...
- name: Test httphandler pkg
run: cd httphandler && go test "-tags=static,gitenabled" -v ./...
- name: Build
env:
RELEASE: ${{ inputs.release }}
CLIENT: test
CGO_ENABLED: 1
run: python3 --version && 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/${{ matrix.os }}/kubescape
if: matrix.os != 'ubuntu-20.04'
- name: Smoke Testing (Linux)
env:
RELEASE: ${{ inputs.release }}
KUBESCAPE_SKIP_UPDATE_CHECK: "true"
run: python3 smoke_testing/init.py ${PWD}/build/ubuntu-latest/kubescape
if: matrix.os == 'ubuntu-20.04'

6
.gitignore vendored
View File

@@ -1,7 +1,9 @@
*.vs*
*kubescape*
*debug*
*vender*
*vendor*
*.pyc*
.idea
ca.srl
.history
ca.srl
*.out

3
.gitmodules vendored Normal file
View File

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

57
.golangci.yml Normal file
View File

@@ -0,0 +1,57 @@
linters-settings:
govet:
check-shadowing: true
dupl:
threshold: 200
goconst:
min-len: 3
min-occurrences: 2
gocognit:
min-complexity: 65
linters:
enable:
- gosec
- staticcheck
- nolintlint
- gofmt
- unused
- govet
- bodyclose
- typecheck
- goimports
- ineffassign
- gosimple
disable:
# temporarily disabled
- varcheck
- errcheck
- dupl
- gocritic
- gocognit
- 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

View File

@@ -1,127 +1,3 @@
# Contributor Covenant Code of Conduct
## Code of Conduct
## Our Pledge
We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, religion, or sexual identity
and orientation.
We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.
## Our Standards
Examples of behavior that contributes to a positive environment for our
community include:
* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the
overall community
Examples of unacceptable behavior include:
* The use of sexualized language or imagery, and sexual attention or
advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email
address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Enforcement Responsibilities
Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.
Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.
## Scope
This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.
Examples of representing our community include using an official e-mail address,
posting via an official social media account, or acting as an appointed
representative at an online or offline event.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement [here](mailto:ben@armosec.io).
All complaints will be reviewed and investigated promptly and fairly.
All community leaders are obligated to respect the privacy and security of the
reporter of any incident.
## Enforcement Guidelines
Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:
### 1. Correction
**Community Impact**: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.
**Consequence**: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.
### 2. Warning
**Community Impact**: A violation through a single incident or series
of actions.
**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or
permanent ban.
### 3. Temporary Ban
**Community Impact**: A serious violation of community standards, including
sustained inappropriate behavior.
**Consequence**: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.
### 4. Permanent Ban
**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.
**Consequence**: A permanent ban from any sort of public interaction within
the community.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.0, available at
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
Community Impact Guidelines were inspired by [Mozilla's code of conduct
enforcement ladder](https://github.com/mozilla/diversity).
[homepage]: https://www.contributor-covenant.org
For answers to common questions about this code of conduct, see the FAQ at
https://www.contributor-covenant.org/faq. Translations are available at
https://www.contributor-covenant.org/translations.
The Kubescape project follows the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md).

View File

@@ -3,15 +3,17 @@
First, it is awesome that you are considering contributing to Kubescape! Contributing is important and fun and we welcome your efforts.
When contributing, we categorize contributions into two:
* Small code changes or fixes, whose scope are limited to a single or two files
* Complex features and improvements, whose are not limited
* 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 issue,
email, or any other method with the owners of this repository before making a change. Most likely your changes or features are great, but sometimes we might already going to this direction (or the exact opposite ;-) ) and we don't want to waste your time.
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.
Please note we have a code of conduct, please follow it in all your interactions with the project.
## Code of Conduct
Please follow our [code of conduct](CODE_OF_CONDUCT.md) in all of your interactions within the project.
## Pull Request Process
@@ -20,81 +22,43 @@ Please note we have a code of conduct, please follow it in all your interactions
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 `dev` branch - we test the component before merging into the `master` branch
4. We will merge the Pull Request in once you have the sign-off.
4. We will merge the Pull Request once you have the sign-off.
## Code of Conduct
## Developer Certificate of Origin
### Our Pledge
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.
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.
Commits made through the GitHub web application are automatically signed off.
### Our Standards
### Configuring Git to sign off commits
Examples of behavior that contributes to creating a positive environment
include:
First, configure your name and email address in Git global settings:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
```
$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com
```
Examples of unacceptable behavior by participants include:
You can now sign off per-commit, or configure Git to always sign off commits per repository.
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
### Sign off per-commit
We will distance those who are constantly adhere to unacceptable behavior.
Add [`-s`](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt--s) to your Git command line. For example:
### Our Responsibilities
```git commit -s -m "Fix issue 64738"```
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
This is tedious, and if you forget, you'll have to [amend your commit](#f)
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
### Configure a repository to always include sign off
### Scope
There are many ways to achieve this with Git hooks, but the simplest is to do the following:
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.
```
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
```
### Enforcement
## Fixing a commit where the DCO failed
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [INSERT EMAIL ADDRESS]. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
### Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [http://contributor-covenant.org/version/1/4][version]
[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
Check out [this guide](https://github.com/src-d/guide/blob/master/developer-community/fix-DCO.md).

View File

@@ -1,10 +1,11 @@
# Maintainers
The following table lists Kubescape project maintainers
The following table lists the Kubescape project maintainers:
| Name | GitHub | Email | Organization | Role | Added/Renewed On |
| --- | --- | --- | --- | --- | --- |
| [Ben Hirschberg](https://www.linkedin.com/in/benyamin-ben-hirschberg-66141890) | [@slashben](https://github.com/slashben) | ben@armosec.io | [ARMO](https://www.armosec.io/) | VP R&D | 2021-09-01 |
| [Rotem Refael](https://www.linkedin.com/in/rotem-refael) | [@rotemamsa](https://github.com/rotemamsa) | rrefael@armosec.io | [ARMO](https://www.armosec.io/) | Team Leader | 2021-10-11 |
| [David Wertenteil](https://www.linkedin.com/in/david-wertenteil-0ba277b9) | [@dwertent](https://github.com/dwertent) | dwertent@armosec.io | [ARMO](https://www.armosec.io/) | Kubescape CLI Developer | 2021-09-01 |
| [Bezalel Brandwine](https://www.linkedin.com/in/bezalel-brandwine) | [@Bezbran](https://github.com/Bezbran) | bbrandwine@armosec.io | [ARMO](https://www.armosec.io/) | Kubescape SaaS Developer | 2021-09-01 |
| Name | GitHub | Organization | Added/Renewed On |
| --- | --- | --- | --- |
| [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 |
| [Bezalel Brandwine](https://www.linkedin.com/in/bezalel-brandwine) | [@Bezbran](https://github.com/Bezbran) | [ARMO](https://www.armosec.io/) | 2021-09-01 |
| [Craig Box](https://www.linkedin.com/in/crbnz/) | [@craigbox](https://github.com/craigbox) | [ARMO](https://www.armosec.io/) | 2022-10-31 |

20
Makefile Normal file
View File

@@ -0,0 +1,20 @@
.PHONY: test all build libgit2
# default task invoked while running make
all: libgit2 build
export CGO_ENABLED=1
# build and install libgit2
libgit2:
-git submodule update --init --recursive
cd git2go; make install-static
# go build tags
TAGS = "gitenabled,static"
build:
go build -v -tags=$(TAGS) .
test:
go test -v -tags=$(TAGS) ./...

325
README.md
View File

@@ -1,295 +1,94 @@
<img src="docs/kubescape.png" width="300" alt="logo" align="center">
[![Version](https://img.shields.io/github/v/release/kubescape/kubescape)](releases)
[![build](https://github.com/kubescape/kubescape/actions/workflows/build.yaml/badge.svg)](https://github.com/kubescape/kubescape/actions/workflows/build.yaml)
[![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)
[![Twitter Follow](https://img.shields.io/twitter/follow/kubescape?style=social)](https://twitter.com/kubescape)
[![build](https://github.com/armosec/kubescape/actions/workflows/build.yaml/badge.svg)](https://github.com/armosec/kubescape/actions/workflows/build.yaml)
[![Go Report Card](https://goreportcard.com/badge/github.com/armosec/kubescape)](https://goreportcard.com/report/github.com/armosec/kubescape)
# Kubescape
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/cncf/artwork/master/projects/kubescape/stacked/white/kubescape-stacked-white.svg" width="150">
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/cncf/artwork/master/projects/kubescape/stacked/color/kubescape-stacked-color.svg" width="150">
<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_
Kubescape is a K8s open-source tool providing a multi-cloud K8s single pane of glass, including risk analysis, security compliance, RBAC visualizer and image vulnerabilities scanning.
Kubescape scans K8s clusters, YAML files, and HELM charts, detecting misconfigurations according to multiple frameworks (such as the [NSA-CISA](https://www.armosec.io/blog/kubernetes-hardening-guidance-summary-by-armo) , [MITRE ATT&CK®](https://www.microsoft.com/security/blog/2021/03/23/secure-containerized-environments-with-updated-threat-matrix-for-kubernetes/)), software vulnerabilities, and RBAC (role-based-access-control) violations at early stages of the CI/CD pipeline, calculates risk score instantly and shows risk trends over time.
It became one of the fastest-growing Kubernetes tools among developers due to its easy-to-use CLI interface, flexible output formats, and automated scanning capabilities, saving Kubernetes users and admins precious time, effort, and resources.
Kubescape integrates natively with other DevOps tools, including Jenkins, CircleCI, Github workflows, Prometheus, and Slack, and supports multi-cloud K8s deployments like EKS, GKE, and AKS.
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.
</br>
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 Coverage
<img src="docs/ksfromcodetodeploy.png">
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/).
</br> -->
## 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! 😀_
# Kubescape CLI:
<img src="docs/demo.gif">
## Getting started
</br>
Experimenting with Kubescape is as easy as:
<!-- # Kubescape overview:
<img src="docs/ARMO-header-2022.gif"> -->
# TL;DR
## Install:
```
curl -s https://raw.githubusercontent.com/armosec/kubescape/master/install.sh | /bin/bash
```sh
curl -s https://raw.githubusercontent.com/kubescape/kubescape/master/install.sh | /bin/bash
```
[Install on windows](#install-on-windows)
Learn more about:
[Install on macOS](#install-on-macos)
* [Installing Kubescape](docs/getting-started.md#install-kubescape)
* [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](docs/building.md)
## Run:
```
kubescape scan --submit --enable-host-scan
```
_Did you know you can use Kubescape in all these places?_
<img src="docs/summary.png">
<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.">
</div>
</br>
## Under the hood
> Kubescape is an open source project, we welcome your feedback and ideas for improvement. Were also aiming to collaborate with the Kubernetes community to help make the tests themselves more robust and complete as Kubernetes develops.
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).
</br>
By default, the results are printed in a console-friendly manner, but they can be:
### Click [👍](https://github.com/armosec/kubescape/stargazers) if you want us to continue to develop and improve Kubescape 😀
* exported to JSON or junit XML
* rendered to HTML or PDF
* submitted to a [cloud service](docs/providers.md)
</br>
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).
## Community
# Being part of the team
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 invite you to our team! We are excited about this project and want to return the love we get.
We hold [community meetings](https://us02web.zoom.us/j/84020231442) on Zoom, on the first Tuesday of every month, at 14:00 GMT.
Want to contribute? Want to discuss something? Have an issue?
The Kubescape project follows the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md).
* Feel free to pick a task from the [roadmap](docs/roadmap.md) or suggest a feature of your own. [Contact us](MAINTAINERS.md) directly for more information :)
* Open a issue, we are trying to respond within 48 hours
* [Join us](https://armosec.github.io/kubescape/) in a discussion on our discord server!
## Contributions
[<img src="docs/discord-banner.png" width="100" alt="logo" align="center">](https://armosec.github.io/kubescape/)
![discord](https://img.shields.io/discord/893048809884643379)
Thanks to all our contributors! Check out our [CONTRIBUTING](CONTRIBUTING.md) file to learn how to join them.
* 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.
# Options and examples
<br>
[Kubescape docs](https://hub.armo.cloud/docs)
## Playground
* [Kubescape playground](https://www.katacoda.com/pathaksaiyam/scenarios/kubescape)
## Tutorials
* [Overview](https://youtu.be/wdBkt_0Qhbg)
* [How To Secure Kubernetes Clusters With Kubescape And Armo](https://youtu.be/ZATGiDIDBQk)
* [Scan Kubernetes YAML files](https://youtu.be/Ox6DaR7_4ZI)
* [Scan Kubescape on an air-gapped environment (offline support)](https://youtu.be/IGXL9s37smM)
* [Managing exceptions in the Kubescape SaaS version](https://youtu.be/OzpvxGmCR80)
* [Configure and run customized frameworks](https://youtu.be/12Sanq_rEhs)
* Customize controls configurations. [Kubescape CLI](https://youtu.be/955psg6TVu4), [Kubescape SaaS](https://youtu.be/lIMVSVhH33o)
## Install on Windows
**Requires powershell v5.0+**
``` powershell
iwr -useb https://raw.githubusercontent.com/armosec/kubescape/master/install.ps1 | iex
```
Note: if you get an error you might need to change the execution policy (i.e. enable Powershell) with
``` powershell
Set-ExecutionPolicy RemoteSigned -scope CurrentUser
```
## Install on macOS
1. ```
brew tap armosec/kubescape
```
2. ```
brew install kubescape
```
## Usage & Examples
### Examples
#### Scan a running Kubernetes cluster and submit results to the [Kubescape SaaS version](https://portal.armo.cloud/)
```
kubescape scan --submit --enable-host-scan
```
> Read [here](https://hub.armo.cloud/docs/host-sensor) more about the `enable-host-scan` flag
#### Scan a running Kubernetes cluster with [`nsa`](https://www.nsa.gov/Press-Room/News-Highlights/Article/Article/2716980/nsa-cisa-release-kubernetes-hardening-guidance/) framework and submit results to the [Kubescape SaaS version](https://portal.armo.cloud/)
```
kubescape scan framework nsa --submit
```
#### Scan a running Kubernetes cluster with [`MITRE ATT&CK®`](https://www.microsoft.com/security/blog/2021/03/23/secure-containerized-environments-with-updated-threat-matrix-for-kubernetes/) framework and submit results to the [Kubescape SaaS version](https://portal.armo.cloud/)
```
kubescape scan framework mitre --submit
```
#### Scan a running Kubernetes cluster with a specific control using the control name or control ID. [List of controls](https://hub.armo.cloud/docs/controls)
```
kubescape scan control "Privileged container"
```
#### Scan specific namespaces
```
kubescape scan --include-namespaces development,staging,production
```
#### Scan cluster and exclude some namespaces
```
kubescape scan --exclude-namespaces kube-system,kube-public
```
#### Scan local `yaml`/`json` files before deploying. [Take a look at the demonstration](https://youtu.be/Ox6DaR7_4ZI)
```
kubescape scan *.yaml
```
#### Scan kubernetes manifest files from a public github repository
```
kubescape scan https://github.com/armosec/kubescape
```
#### Display all scanned resources (including the resources who passed)
```
kubescape scan --verbose
```
#### Output in `json` format
> Add the `--format-version v2` flag
```
kubescape scan --format json --format-version v2 --output results.json
```
#### Output in `junit xml` format
```
kubescape scan --format junit --output results.xml
```
#### Output in `pdf` format - Contributed by [@alegrey91](https://github.com/alegrey91)
```
kubescape scan --format pdf --output results.pdf
```
#### Output in `prometheus` metrics format - Contributed by [@Joibel](https://github.com/Joibel)
```
kubescape scan --format prometheus
```
#### Scan with exceptions, objects with exceptions will be presented as `exclude` and not `fail`
[Full documentation](examples/exceptions/README.md)
```
kubescape scan --exceptions examples/exceptions/exclude-kube-namespaces.json
```
#### Scan Helm charts - Render the helm chart using [`helm template`](https://helm.sh/docs/helm/helm_template/) and pass to stdout
```
helm template [NAME] [CHART] [flags] --dry-run | kubescape scan -
```
e.g.
```
helm template bitnami/mysql --generate-name --dry-run | kubescape scan -
```
### Offline/Air-gaped Environment Support
[Video tutorial](https://youtu.be/IGXL9s37smM)
It is possible to run Kubescape offline!
#### Download all artifacts
1. Download and save in local directory, if path not specified, will save all in `~/.kubescape`
```
kubescape download artifacts --output path/to/local/dir
```
2. Copy the downloaded artifacts to the air-gaped/offline environment
3. Scan using the downloaded artifacts
```
kubescape scan --use-artifacts-from path/to/local/dir
```
#### Download a single artifacts
You can also download a single artifacts and scan with the `--use-from` flag
1. Download and save in file, if file name not specified, will save in `~/.kubescape/<framework name>.json`
```
kubescape download framework nsa --output /path/nsa.json
```
2. Copy the downloaded artifacts to the air-gaped/offline environment
3. Scan using the downloaded framework
```
kubescape scan framework nsa --use-from /path/nsa.json
```
## Scan Periodically using Helm - Contributed by [@yonahd](https://github.com/yonahd)
[Please follow the instructions here](https://hub.armo.cloud/docs/installation-of-armo-in-cluster)
[helm chart repo](https://github.com/armosec/armo-helm)
## Scan using docker image
Official Docker image `quay.io/armosec/kubescape`
```
docker run -v "$(pwd)/example.yaml:/app/example.yaml quay.io/armosec/kubescape scan /app/example.yaml
```
If you wish, you can [build the docker image on your own](build/README.md)
# Submit data manually
Use the `submit` command if you wish to submit data manually
## Submit scan results manually
> Support forward compatibility by using the `--format-version v2` flag
First, scan your cluster using the `json` format flag: `kubescape scan framework <name> --format json --format-version v2 --output path/to/results.json`.
Now you can submit the results to the Kubescape SaaS version -
```
kubescape submit results path/to/results.json
```
# Integrations
## VS Code Extension
![Visual Studio Marketplace Downloads](https://img.shields.io/visual-studio-marketplace/d/kubescape.kubescape?label=VScode) ![Open VSX](https://img.shields.io/open-vsx/dt/kubescape/kubescape?label=openVSX&color=yellowgreen)
Scan the YAML files while writing them using the [vs code extension](https://github.com/armosec/vscode-kubescape/blob/master/README.md)
# Under the hood
## Technology
Kubescape based on OPA engine: https://github.com/open-policy-agent/opa and ARMO's posture controls.
The tools retrieves Kubernetes objects from the API server and runs a set of [rego's snippets](https://www.openpolicyagent.org/docs/latest/policy-language/) developed by [ARMO](https://www.armosec.io/).
The results by default printed in a pretty "console friendly" manner, but they can be retrieved in JSON format for further processing.
Kubescape is an open source project, we welcome your feedback and ideas for improvement. Were also aiming to collaborate with the Kubernetes community to help make the tests themselves more robust and complete as Kubernetes develops.
## Thanks to all the contributors ❤️
<a href = "https://github.com/armosec/kubescape/graphs/contributors">
<img src = "https://contrib.rocks/image?repo=armosec/kubescape"/>
<a href = "https://github.com/kubescape/kubescape/graphs/contributors">
<img src = "https://contrib.rocks/image?repo=kubescape/kubescape"/>
</a>
## 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.
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).
<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>

51
build.bat Normal file
View File

@@ -0,0 +1,51 @@
@ECHO OFF
IF "%1"=="install" goto Install
IF "%1"=="build" goto Build
IF "%1"=="all" goto All
IF "%1"=="" goto Error ELSE goto Error
:Install
if exist C:\MSYS64\ (
echo "MSYS2 already installed"
) else (
mkdir temp_install & cd temp_install
echo "Downloading MSYS2..."
curl -L https://github.com/msys2/msys2-installer/releases/download/2022-06-03/msys2-x86_64-20220603.exe > msys2-x86_64-20220603.exe
echo "Installing MSYS2..."
msys2-x86_64-20220603.exe install --root C:\MSYS64 --confirm-command
cd .. && rmdir /s /q temp_install
)
echo "Adding MSYS2 to path..."
SET "PATH=C:\MSYS64\mingw64\bin;C:\MSYS64\usr\bin;%PATH%"
echo %PATH%
echo "Installing MSYS2 packages..."
pacman -S --needed --noconfirm make
pacman -S --needed --noconfirm mingw-w64-x86_64-cmake
pacman -S --needed --noconfirm mingw-w64-x86_64-gcc
pacman -S --needed --noconfirm mingw-w64-x86_64-pkg-config
pacman -S --needed --noconfirm msys2-w32api-runtime
IF "%1"=="all" GOTO Build
GOTO End
:Build
SET "PATH=C:\MSYS2\mingw64\bin;C:\MSYS2\usr\bin;%PATH%"
make libgit2
GOTO End
:All
GOTO Install
:Error
echo "Error: Unknown option"
GOTO End
:End

80
build.py Normal file
View File

@@ -0,0 +1,80 @@
import os
import sys
import hashlib
import platform
import subprocess
BASE_GETTER_CONST = "github.com/kubescape/kubescape/v2/core/cautils/getter"
def check_status(status, msg):
if status != 0:
sys.stderr.write(msg)
exit(status)
def get_build_dir():
current_platform = platform.system()
build_dir = ""
if current_platform == "Windows": build_dir = "windows-latest"
elif current_platform == "Linux": build_dir = "ubuntu-latest"
elif current_platform == "Darwin": build_dir = "macos-latest"
else: raise OSError("Platform %s is not supported!" % (current_platform))
return os.path.join("build", build_dir)
def get_package_name():
package_name = "kubescape"
return package_name
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"
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]
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())
print("Build Done")
if __name__ == "__main__":
main()

View File

@@ -1,44 +1,51 @@
FROM golang:1.17-alpine as builder
#ENV GOPROXY=https://goproxy.io,direct
FROM golang:1.19-alpine as builder
ARG image_version
ARG client
ENV RELEASE=$image_version
ENV CLIENT=$client
ENV GO111MODULE=
ENV CGO_ENABLED=0
ENV CGO_ENABLED=1
# Install required python/pip
ENV PYTHONUNBUFFERED=1
RUN apk add --update --no-cache python3 && ln -sf python3 /usr/bin/python
RUN apk add --update --no-cache python3 gcc make git libc-dev binutils-gold cmake pkgconfig && ln -sf python3 /usr/bin/python
RUN python3 -m ensurepip
RUN pip3 install --no-cache --upgrade pip setuptools
WORKDIR /work
ADD . .
# install libgit2
RUN rm -rf git2go && make libgit2
# build kubescape server
WORKDIR /work/httphandler
RUN python build.py
RUN ls -ltr build/ubuntu-latest
# build kubescape cmd
WORKDIR /work/cmd
WORKDIR /work
RUN python build.py
RUN /work/build/ubuntu-latest/kubescape download artifacts -o /work/artifacts
FROM alpine
FROM alpine:3.16.2
RUN addgroup -S ks && adduser -S ks -G ks
COPY --from=builder /work/artifacts/ /home/ks/.kubescape
RUN chown -R ks:ks /home/ks/.kubescape
USER ks
WORKDIR /home/ks/
WORKDIR /home/ks
COPY --from=builder /work/httphandler/build/ubuntu-latest/kubescape /usr/bin/ksserver
COPY --from=builder /work/build/ubuntu-latest/kubescape /usr/bin/kubescape
RUN mkdir /home/ks/.kubescape && chmod 777 -R /home/ks/.kubescape
COPY --from=builder /work/artifacts/ /home/ks/.kubescape
ENTRYPOINT ["ksserver"]

View File

@@ -4,7 +4,7 @@
1. Clone Project
```
git clone https://github.com/armosec/kubescape.git kubescape && cd "$_"
git clone https://github.com/kubescape/kubescape.git kubescape && cd "$_"
```
2. Build

View File

@@ -1,19 +0,0 @@
# Kubescape CLI Package
## Commands
* [Completion](#completion): Generate autocompletion script
* [Config](#config): Handle cached configurations
* [Delete](#delete): Delete configurations in Kubescape SaaS version
* [Download](#download): Download controls-inputs,exceptions,control,framework,artifacts
* [Help](#help): Help about any command
* [List](#list): List frameworks/controls will list the supported frameworks and controls
* [Scan](#scan): Scan the current running cluster or yaml files
* [Submit](#submit): Submit an object to the Kubescape SaaS version
* [Version](#version): Get kubescape version
## Global Flags
--cache-dir string Cache directory [$KS_CACHE_DIR] (default "/home/david/.kubescape")
-l, --logger string Logger level. Supported: debug/info/success/warning/error/fatal [$KS_LOGGER] (default "info")
### Completion

View File

@@ -1,94 +0,0 @@
import os
import sys
import hashlib
import platform
import subprocess
BASE_GETTER_CONST = "github.com/armosec/kubescape/core/cautils/getter"
BE_SERVER_CONST = BASE_GETTER_CONST + ".ArmoBEURL"
ER_SERVER_CONST = BASE_GETTER_CONST + ".ArmoERURL"
WEBSITE_CONST = BASE_GETTER_CONST + ".ArmoFEURL"
AUTH_SERVER_CONST = BASE_GETTER_CONST + ".armoAUTHURL"
def checkStatus(status, msg):
if status != 0:
sys.stderr.write(msg)
exit(status)
def getBuildDir():
currentPlatform = platform.system()
buildDir = "../build/"
if currentPlatform == "Windows": buildDir += "windows-latest"
elif currentPlatform == "Linux": buildDir += "ubuntu-latest"
elif currentPlatform == "Darwin": buildDir += "macos-latest"
else: raise OSError("Platform %s is not supported!" % (currentPlatform))
return buildDir
def getPackageName():
packageName = "kubescape"
# if platform.system() == "Windows": packageName += ".exe"
return packageName
def main():
print("Building Kubescape")
# print environment variables
# print(os.environ)
# Set some variables
packageName = getPackageName()
buildUrl = "github.com/armosec/kubescape/core/cautils.BuildNumber"
releaseVersion = os.getenv("RELEASE")
ArmoBEServer = os.getenv("ArmoBEServer")
ArmoERServer = os.getenv("ArmoERServer")
ArmoWebsite = os.getenv("ArmoWebsite")
ArmoAuthServer = os.getenv("ArmoAuthServer")
# Create build directory
buildDir = getBuildDir()
ks_file = os.path.join(buildDir, packageName)
hash_file = ks_file + ".sha256"
if not os.path.isdir(buildDir):
os.makedirs(buildDir)
# Build kubescape
ldflags = "-w -s"
if releaseVersion:
ldflags += " -X {}={}".format(buildUrl, releaseVersion)
if ArmoBEServer:
ldflags += " -X {}={}".format(BE_SERVER_CONST, ArmoBEServer)
if ArmoERServer:
ldflags += " -X {}={}".format(ER_SERVER_CONST, ArmoERServer)
if ArmoWebsite:
ldflags += " -X {}={}".format(WEBSITE_CONST, ArmoWebsite)
if ArmoAuthServer:
ldflags += " -X {}={}".format(AUTH_SERVER_CONST, ArmoAuthServer)
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)
checkStatus(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())
print("Build Done")
if __name__ == "__main__":
main()

View File

@@ -9,11 +9,11 @@ import (
var completionCmdExamples = `
# Enable BASH shell autocompletion
$ source <(kubescape completion bash)
# Enable BASH shell autocompletion
$ source <(kubescape completion bash)
$ echo 'source <(kubescape completion bash)' >> ~/.bashrc
# Enable ZSH shell autocompletion
# Enable ZSH shell autocompletion
$ source <(kubectl completion zsh)
$ echo 'source <(kubectl completion zsh)' >> "${fpath[1]}/_kubectl"
@@ -27,7 +27,7 @@ func GetCompletionCmd() *cobra.Command {
Example: completionCmdExamples,
DisableFlagsInUseLine: true,
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
Args: cobra.ExactValidArgs(1),
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
Run: func(cmd *cobra.Command, args []string) {
switch strings.ToLower(args[0]) {
case "bash":
@@ -43,7 +43,3 @@ func GetCompletionCmd() *cobra.Command {
}
return completionCmd
}
// func init() {
// rootCmd.AddCommand(completionCmd)
// }

View File

@@ -1,7 +1,7 @@
package config
import (
"github.com/armosec/kubescape/core/meta"
"github.com/kubescape/kubescape/v2/core/meta"
"github.com/spf13/cobra"
)
@@ -25,6 +25,9 @@ var (
# Set access key
kubescape config set secretKey <access key>
# Set cloudAPIURL
kubescape config set cloudAPIURL <cloud API URL>
`
)

View File

@@ -1,9 +1,9 @@
package config
import (
"github.com/armosec/kubescape/core/cautils/logger"
"github.com/armosec/kubescape/core/meta"
v1 "github.com/armosec/kubescape/core/meta/datastructures/v1"
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/spf13/cobra"
)

View File

@@ -4,9 +4,9 @@ import (
"fmt"
"strings"
"github.com/armosec/kubescape/core/cautils/logger"
"github.com/armosec/kubescape/core/meta"
metav1 "github.com/armosec/kubescape/core/meta/datastructures/v1"
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/spf13/cobra"
)
@@ -33,9 +33,13 @@ func getSetCmd(ks meta.IKubescape) *cobra.Command {
}
var supportConfigSet = map[string]func(*metav1.SetConfig, string){
"accountID": func(s *metav1.SetConfig, account string) { s.Account = account },
"clientID": func(s *metav1.SetConfig, clientID string) { s.ClientID = clientID },
"secretKey": func(s *metav1.SetConfig, secretKey string) { s.SecretKey = secretKey },
"accountID": func(s *metav1.SetConfig, account string) { s.Account = account },
"clientID": func(s *metav1.SetConfig, clientID string) { s.ClientID = clientID },
"secretKey": func(s *metav1.SetConfig, secretKey string) { s.SecretKey = secretKey },
"cloudAPIURL": func(s *metav1.SetConfig, cloudAPIURL string) { s.CloudAPIURL = cloudAPIURL },
"cloudAuthURL": func(s *metav1.SetConfig, cloudAuthURL string) { s.CloudAuthURL = cloudAuthURL },
"cloudReportURL": func(s *metav1.SetConfig, cloudReportURL string) { s.CloudReportURL = cloudReportURL },
"cloudUIURL": func(s *metav1.SetConfig, cloudUIURL string) { s.CloudUIURL = cloudUIURL },
}
func stringKeysToSlice(m map[string]func(*metav1.SetConfig, string)) []string {

View File

@@ -3,9 +3,9 @@ package config
import (
"os"
"github.com/armosec/kubescape/core/cautils/logger"
"github.com/armosec/kubescape/core/meta"
v1 "github.com/armosec/kubescape/core/meta/datastructures/v1"
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/spf13/cobra"
)

View File

@@ -1,8 +1,8 @@
package delete
import (
"github.com/armosec/kubescape/core/meta"
v1 "github.com/armosec/kubescape/core/meta/datastructures/v1"
"github.com/kubescape/kubescape/v2/core/meta"
v1 "github.com/kubescape/kubescape/v2/core/meta/datastructures/v1"
"github.com/spf13/cobra"
)
@@ -24,7 +24,9 @@ func GetDeleteCmd(ks meta.IKubescape) *cobra.Command {
Run: func(cmd *cobra.Command, args []string) {
},
}
deleteCmd.PersistentFlags().StringVarP(&deleteInfo.Account, "account", "", "", "Armo portal account ID. Default will load account ID from configMap or config file")
deleteCmd.PersistentFlags().StringVarP(&deleteInfo.Credentials.Account, "account", "", "", "Kubescape SaaS account ID. Default will load account ID from cache")
deleteCmd.PersistentFlags().StringVarP(&deleteInfo.Credentials.ClientID, "client-id", "", "", "Kubescape SaaS client ID. Default will load client ID from cache, read more - https://hub.armosec.io/docs/authentication")
deleteCmd.PersistentFlags().StringVarP(&deleteInfo.Credentials.SecretKey, "secret-key", "", "", "Kubescape SaaS secret key. Default will load secret key from cache, read more - https://hub.armosec.io/docs/authentication")
deleteCmd.AddCommand(getExceptionsCmd(ks, &deleteInfo))

View File

@@ -4,9 +4,9 @@ import (
"fmt"
"strings"
"github.com/armosec/kubescape/core/cautils/logger"
"github.com/armosec/kubescape/core/meta"
v1 "github.com/armosec/kubescape/core/meta/datastructures/v1"
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/spf13/cobra"
)
@@ -22,13 +22,25 @@ func getExceptionsCmd(ks meta.IKubescape, deleteInfo *v1.Delete) *cobra.Command
return nil
},
Run: func(cmd *cobra.Command, args []string) {
if err := flagValidationDelete(deleteInfo); err != nil {
logger.L().Fatal(err.Error())
}
exceptionsNames := strings.Split(args[0], ";")
if len(exceptionsNames) == 0 {
logger.L().Fatal("missing exceptions names")
}
if err := ks.DeleteExceptions(&v1.DeleteExceptions{Account: deleteInfo.Account, Exceptions: exceptionsNames}); err != nil {
if err := ks.DeleteExceptions(&v1.DeleteExceptions{Credentials: deleteInfo.Credentials, Exceptions: exceptionsNames}); err != nil {
logger.L().Fatal(err.Error())
}
},
}
}
// Check if the flag entered are valid
func flagValidationDelete(deleteInfo *v1.Delete) error {
// Validate the user's credentials
return deleteInfo.Credentials.Validate()
}

View File

@@ -5,11 +5,11 @@ import (
"path/filepath"
"strings"
"github.com/armosec/kubescape/core/cautils"
"github.com/armosec/kubescape/core/cautils/logger"
"github.com/armosec/kubescape/core/core"
"github.com/armosec/kubescape/core/meta"
v1 "github.com/armosec/kubescape/core/meta/datastructures/v1"
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/spf13/cobra"
)
@@ -17,15 +17,15 @@ var (
downloadExample = `
# Download all artifacts and save them in the default path (~/.kubescape)
kubescape download artifacts
download
# Download all artifacts and save them in /tmp path
kubescape download artifacts --output /tmp
# Download the NSA framework. Run 'kubescape list frameworks' for all frameworks names
kubescape download framework nsa
# Download the "Allowed hostPath" control. Run 'kubescape list controls' for all controls names
kubescape download control "Allowed hostPath"
# Download the "C-0001" control. Run 'kubescape list controls --id' for all controls ids
kubescape download control "C-0001"
# Download the "C-0001" control. Run 'kubescape list controls --id' for all controls ids
kubescape download control C-0001
@@ -36,6 +36,8 @@ var (
# Download the configured controls-inputs
kubescape download controls-inputs
# Download the attack tracks
kubescape download attack-tracks
`
)
@@ -59,12 +61,18 @@ func GeDownloadCmd(ks meta.IKubescape) *cobra.Command {
},
RunE: func(cmd *cobra.Command, args []string) error {
if err := flagValidationDownload(&downloadInfo); err != nil {
return err
}
if filepath.Ext(downloadInfo.Path) == ".json" {
downloadInfo.Path, downloadInfo.FileName = filepath.Split(downloadInfo.Path)
}
downloadInfo.Target = args[0]
if len(args) >= 2 {
downloadInfo.Name = args[1]
downloadInfo.Identifier = args[1]
}
if err := ks.Download(&downloadInfo); err != nil {
logger.L().Fatal(err.Error())
@@ -72,8 +80,18 @@ func GeDownloadCmd(ks meta.IKubescape) *cobra.Command {
return nil
},
}
downloadCmd.PersistentFlags().StringVarP(&downloadInfo.Account, "account", "", "", "Armo portal account ID. Default will load account ID from configMap or config file")
downloadCmd.PersistentFlags().StringVarP(&downloadInfo.Credentials.Account, "account", "", "", "Kubescape SaaS account ID. Default will load account ID from cache")
downloadCmd.PersistentFlags().StringVarP(&downloadInfo.Credentials.ClientID, "client-id", "", "", "Kubescape SaaS client ID. Default will load client ID from cache, read more - https://hub.armosec.io/docs/authentication")
downloadCmd.PersistentFlags().StringVarP(&downloadInfo.Credentials.SecretKey, "secret-key", "", "", "Kubescape SaaS secret key. Default will load secret key from cache, read more - https://hub.armosec.io/docs/authentication")
downloadCmd.Flags().StringVarP(&downloadInfo.Path, "output", "o", "", "Output file. If not specified, will save in `~/.kubescape/<policy name>.json`")
return downloadCmd
}
// Check if the flag entered are valid
func flagValidationDownload(downloadInfo *v1.DownloadInfo) error {
// Validate the user's credentials
return downloadInfo.Credentials.Validate()
}

45
cmd/fix/fix.go Normal file
View File

@@ -0,0 +1,45 @@
package fix
import (
"errors"
"github.com/kubescape/kubescape/v2/core/meta"
metav1 "github.com/kubescape/kubescape/v2/core/meta/datastructures/v1"
"github.com/spf13/cobra"
)
var fixCmdExamples = `
Fix command is for fixing kubernetes manifest files based on a scan command output.
Use with caution, this command will change your files in-place.
# Fix kubernetes YAML manifest files based on a scan command output (output.json)
1) kubescape scan --format json --format-version v2 --output output.json
2) kubescape fix output.json
`
func GetFixCmd(ks meta.IKubescape) *cobra.Command {
var fixInfo metav1.FixInfo
fixCmd := &cobra.Command{
Use: "fix <report output file>",
Short: "Fix misconfiguration in files",
Long: ``,
Example: fixCmdExamples,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return errors.New("report output file is required")
}
fixInfo.ReportFile = args[0]
return ks.Fix(&fixInfo)
},
}
fixCmd.PersistentFlags().BoolVar(&fixInfo.NoConfirm, "no-confirm", false, "No confirmation will be given to the user before applying the fix (default false)")
fixCmd.PersistentFlags().BoolVar(&fixInfo.DryRun, "dry-run", false, "No changes will be applied (default false)")
fixCmd.PersistentFlags().BoolVar(&fixInfo.SkipUserValues, "skip-user-values", true, "Changes which involve user-defined values will be skipped")
return fixCmd
}

View File

@@ -1,127 +0,0 @@
module github.com/armosec/kubescape/cmd
go 1.17
replace github.com/armosec/kubescape/core => ../core
require (
github.com/armosec/k8s-interface v0.0.68
github.com/armosec/kubescape/core v0.0.0-00010101000000-000000000000
github.com/armosec/opa-utils v0.0.127
github.com/armosec/rbac-utils v0.0.14
github.com/google/uuid v1.3.0
github.com/mattn/go-isatty v0.0.14
github.com/spf13/cobra v1.4.0
)
require (
cloud.google.com/go v0.99.0 // indirect
cloud.google.com/go/container v1.0.0 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest v0.11.18 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.13 // indirect
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
github.com/Azure/go-autorest/logger v0.2.1 // indirect
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
github.com/OneOfOne/xxhash v1.2.8 // indirect
github.com/armosec/armoapi-go v0.0.58 // indirect
github.com/armosec/utils-go v0.0.3 // indirect
github.com/armosec/utils-k8s-go v0.0.3 // indirect
github.com/aws/aws-sdk-go v1.41.11 // indirect
github.com/aws/aws-sdk-go-v2 v1.12.0 // indirect
github.com/aws/aws-sdk-go-v2/config v1.12.0 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.7.0 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.9.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.3 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.1.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.3 // indirect
github.com/aws/aws-sdk-go-v2/service/eks v1.17.0 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.6.0 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.8.0 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.13.0 // indirect
github.com/aws/smithy-go v1.9.1 // indirect
github.com/boombuler/barcode v1.0.0 // indirect
github.com/briandowns/spinner v1.18.1 // indirect
github.com/census-instrumentation/opencensus-proto v0.3.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4 // indirect
github.com/cncf/xds/go v0.0.0-20211130200136-a8f946100490 // indirect
github.com/coreos/go-oidc v2.2.1+incompatible // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/docker v20.10.9+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/enescakir/emoji v1.0.0 // indirect
github.com/envoyproxy/go-control-plane v0.10.1 // indirect
github.com/envoyproxy/protoc-gen-validate v0.6.2 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/form3tech-oss/jwt-go v3.2.3+incompatible // indirect
github.com/francoispqt/gojay v1.2.13 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-gota/gota v0.12.0 // indirect
github.com/go-logr/logr v1.2.2 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.0.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.7 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/googleapis/gax-go/v2 v2.1.1 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/johnfercher/maroto v0.34.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/jung-kurt/gofpdf v1.4.2 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/open-policy-agent/opa v0.38.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pquerna/cachecontrol v0.1.0 // indirect
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 // indirect
github.com/ruudk/golang-pdf417 v0.0.0-20181029194003-1af4ab5afa58 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/whilp/git-urls v1.0.0 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/yashtewari/glob-intersection v0.0.0-20180916065949-5c77d914dd0b // indirect
go.opencensus.io v0.23.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
golang.org/x/mod v0.5.1 // indirect
golang.org/x/net v0.0.0-20211209124913-491a49abca63 // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
gonum.org/v1/gonum v0.9.1 // indirect
google.golang.org/api v0.62.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa // indirect
google.golang.org/grpc v1.44.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/api v0.23.4 // indirect
k8s.io/apimachinery v0.23.4 // indirect
k8s.io/client-go v0.23.4 // indirect
k8s.io/klog/v2 v2.30.0 // indirect
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 // indirect
k8s.io/utils v0.0.0-20211116205334-6203023598ed // indirect
sigs.k8s.io/controller-runtime v0.11.1 // indirect
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

View File

@@ -4,11 +4,11 @@ import (
"fmt"
"strings"
"github.com/armosec/kubescape/core/cautils"
"github.com/armosec/kubescape/core/cautils/logger"
"github.com/armosec/kubescape/core/core"
"github.com/armosec/kubescape/core/meta"
v1 "github.com/armosec/kubescape/core/meta/datastructures/v1"
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/spf13/cobra"
)
@@ -20,14 +20,11 @@ var (
# List all supported frameworks names
kubescape list frameworks --account <account id>
# List all supported controls names
# List all supported controls names with ids
kubescape list controls
# List all supported controls ids
kubescape list controls --id
Control documentation:
https://hub.armo.cloud/docs/controls
https://hub.armosec.io/docs/controls
`
)
@@ -51,6 +48,11 @@ func GetListCmd(ks meta.IKubescape) *cobra.Command {
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
if err := flagValidationList(&listPolicies); err != nil {
return err
}
listPolicies.Target = args[0]
if err := ks.List(&listPolicies); err != nil {
@@ -59,9 +61,18 @@ func GetListCmd(ks meta.IKubescape) *cobra.Command {
return nil
},
}
listCmd.PersistentFlags().StringVar(&listPolicies.Account, "account", "", "Armo portal account ID. Default will load account ID from configMap or config file")
listCmd.PersistentFlags().StringVar(&listPolicies.Format, "format", "pretty-print", "output format. supported: 'pretty-printer'/'json'")
listCmd.PersistentFlags().BoolVarP(&listPolicies.ListIDs, "id", "", false, "List control ID's instead of controls names")
listCmd.PersistentFlags().StringVarP(&listPolicies.Credentials.Account, "account", "", "", "Kubescape SaaS account ID. Default will load account ID from cache")
listCmd.PersistentFlags().StringVarP(&listPolicies.Credentials.ClientID, "client-id", "", "", "Kubescape SaaS client ID. Default will load client ID from cache, read more - https://hub.armosec.io/docs/authentication")
listCmd.PersistentFlags().StringVarP(&listPolicies.Credentials.SecretKey, "secret-key", "", "", "Kubescape SaaS secret key. Default will load secret key from cache, read more - https://hub.armosec.io/docs/authentication")
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 outpus")
return listCmd
}
// Check if the flag entered are valid
func flagValidationList(listPolicies *v1.ListPolicies) error {
// Validate the user's credentials
return listPolicies.Credentials.Validate()
}

View File

@@ -1,23 +1,25 @@
package main
package cmd
import (
"fmt"
"strings"
"github.com/armosec/kubescape/cmd/completion"
"github.com/armosec/kubescape/cmd/config"
"github.com/armosec/kubescape/cmd/delete"
"github.com/armosec/kubescape/cmd/download"
"github.com/armosec/kubescape/cmd/list"
"github.com/armosec/kubescape/cmd/scan"
"github.com/armosec/kubescape/cmd/submit"
"github.com/armosec/kubescape/cmd/version"
"github.com/armosec/kubescape/core/cautils"
"github.com/armosec/kubescape/core/cautils/getter"
"github.com/armosec/kubescape/core/cautils/logger"
"github.com/armosec/kubescape/core/cautils/logger/helpers"
"github.com/armosec/kubescape/core/core"
"github.com/armosec/kubescape/core/meta"
logger "github.com/kubescape/go-logger"
"github.com/kubescape/go-logger/helpers"
"github.com/kubescape/kubescape/v2/cmd/completion"
"github.com/kubescape/kubescape/v2/cmd/config"
"github.com/kubescape/kubescape/v2/cmd/delete"
"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/scan"
"github.com/kubescape/kubescape/v2/cmd/submit"
"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/spf13/cobra"
)
@@ -26,7 +28,7 @@ var rootInfo cautils.RootInfo
var ksExamples = `
# Scan command
kubescape scan --submit
kubescape scan
# List supported frameworks
kubescape list frameworks
@@ -40,7 +42,6 @@ var ksExamples = `
func NewDefaultKubescapeCommand() *cobra.Command {
ks := core.NewKubescape()
return getRootCmd(ks)
}
@@ -48,14 +49,12 @@ func getRootCmd(ks meta.IKubescape) *cobra.Command {
rootCmd := &cobra.Command{
Use: "kubescape",
Version: cautils.BuildNumber,
Short: "Kubescape is a tool for testing Kubernetes security posture",
Long: `Based on NSA \ MITRE ATT&CK® and other frameworks specifications`,
Short: "Kubescape is a tool for testing Kubernetes security posture. Docs: https://hub.armosec.io/docs",
Example: ksExamples,
}
rootCmd.PersistentFlags().StringVar(&rootInfo.ArmoBEURLsDep, "environment", "", envFlagUsage)
rootCmd.PersistentFlags().StringVar(&rootInfo.ArmoBEURLs, "env", "", envFlagUsage)
rootCmd.PersistentFlags().StringVar(&rootInfo.KSCloudBEURLsDep, "environment", "", envFlagUsage)
rootCmd.PersistentFlags().StringVar(&rootInfo.KSCloudBEURLs, "env", "", envFlagUsage)
rootCmd.PersistentFlags().MarkDeprecated("environment", "use 'env' instead")
rootCmd.PersistentFlags().MarkHidden("environment")
rootCmd.PersistentFlags().MarkHidden("env")
@@ -66,6 +65,7 @@ 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")
cobra.OnInitialize(initLogger, initLoggerLevel, initEnvironment, initCacheDir)
@@ -78,11 +78,13 @@ func getRootCmd(ks meta.IKubescape) *cobra.Command {
rootCmd.AddCommand(completion.GetCompletionCmd())
rootCmd.AddCommand(version.GetVersionCmd())
rootCmd.AddCommand(config.GetConfigCmd(ks))
rootCmd.AddCommand(update.GetUpdateCmd())
rootCmd.AddCommand(fix.GetFixCmd(ks))
return rootCmd
}
func main() {
func Execute() error {
ks := NewDefaultKubescapeCommand()
ks.Execute()
return ks.Execute()
}

View File

@@ -1,13 +1,13 @@
package main
package cmd
import (
"fmt"
"os"
"strings"
"github.com/armosec/kubescape/core/cautils/getter"
"github.com/armosec/kubescape/core/cautils/logger"
"github.com/armosec/kubescape/core/cautils/logger/helpers"
logger "github.com/kubescape/go-logger"
"github.com/kubescape/go-logger/helpers"
"github.com/kubescape/kubescape/v2/core/cautils/getter"
"github.com/mattn/go-isatty"
)
@@ -16,6 +16,7 @@ const envFlagUsage = "Send report results to specific URL. Format:<ReportReceive
func initLogger() {
logger.DisableColor(rootInfo.DisableColor)
logger.EnableColor(rootInfo.EnableColor)
if rootInfo.LoggerName == "" {
if l := os.Getenv("KS_LOGGER_NAME"); l != "" {
@@ -55,10 +56,10 @@ func initCacheDir() {
logger.L().Debug("cache dir updated", helpers.String("path", getter.DefaultLocalStore))
}
func initEnvironment() {
if rootInfo.ArmoBEURLs == "" {
rootInfo.ArmoBEURLs = rootInfo.ArmoBEURLsDep
if rootInfo.KSCloudBEURLs == "" {
rootInfo.KSCloudBEURLs = rootInfo.KSCloudBEURLsDep
}
urlSlices := strings.Split(rootInfo.ArmoBEURLs, ",")
urlSlices := strings.Split(rootInfo.KSCloudBEURLs, ",")
if len(urlSlices) != 1 && len(urlSlices) < 3 {
logger.L().Fatal("expected at least 3 URLs (report, api, frontend, auth)")
}
@@ -66,24 +67,24 @@ func initEnvironment() {
case 1:
switch urlSlices[0] {
case "dev", "development":
getter.SetARMOAPIConnector(getter.NewARMOAPIDev())
getter.SetKSCloudAPIConnector(getter.NewKSCloudAPIDev())
case "stage", "staging":
getter.SetARMOAPIConnector(getter.NewARMOAPIStaging())
getter.SetKSCloudAPIConnector(getter.NewKSCloudAPIStaging())
case "":
getter.SetARMOAPIConnector(getter.NewARMOAPIProd())
getter.SetKSCloudAPIConnector(getter.NewKSCloudAPIProd())
default:
logger.L().Fatal("--environment flag usage: " + envFlagUsage)
}
case 2:
logger.L().Fatal("--environment flag usage: " + envFlagUsage)
case 3, 4:
var armoAUTHURL string
armoERURL := urlSlices[0] // mandatory
armoBEURL := urlSlices[1] // mandatory
armoFEURL := urlSlices[2] // mandatory
var ksAuthURL string
ksEventReceiverURL := urlSlices[0] // mandatory
ksBackendURL := urlSlices[1] // mandatory
ksFrontendURL := urlSlices[2] // mandatory
if len(urlSlices) >= 4 {
armoAUTHURL = urlSlices[3]
ksAuthURL = urlSlices[3]
}
getter.SetARMOAPIConnector(getter.NewARMOAPICustomized(armoERURL, armoBEURL, armoFEURL, armoAUTHURL))
getter.SetKSCloudAPIConnector(getter.NewKSCloudAPICustomized(ksEventReceiverURL, ksBackendURL, ksFrontendURL, ksAuthURL))
}
}

View File

@@ -6,10 +6,14 @@ import (
"os"
"strings"
"github.com/armosec/kubescape/core/cautils"
"github.com/armosec/kubescape/core/cautils/logger"
"github.com/armosec/kubescape/core/meta"
"github.com/armosec/opa-utils/reporthandling"
apisv1 "github.com/kubescape/opa-utils/httpserver/apis/v1"
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/enescakir/emoji"
"github.com/spf13/cobra"
)
@@ -19,7 +23,7 @@ var (
kubescape scan control "privileged container"
# Scan list of controls separated with a comma
kubescape scan control "privileged container","allowed hostpath"
kubescape scan control "privileged container","HostPath mount"
# Scan list of controls using the control ID separated with a comma
kubescape scan control C-0058,C-0057
@@ -27,7 +31,7 @@ var (
Run 'kubescape list controls' for the list of supported controls
Control documentation:
https://hub.armo.cloud/docs/controls
https://hub.armosec.io/docs/controls
`
)
@@ -54,15 +58,19 @@ func getControlCmd(ks meta.IKubescape, scanInfo *cautils.ScanInfo) *cobra.Comman
},
RunE: func(cmd *cobra.Command, args []string) error {
if err := validateFrameworkScanInfo(scanInfo); err != nil {
return err
}
// flagValidationControl(scanInfo)
scanInfo.PolicyIdentifier = []reporthandling.PolicyIdentifier{}
scanInfo.PolicyIdentifier = []cautils.PolicyIdentifier{}
if len(args) == 0 {
scanInfo.ScanAll = true
} else { // expected control or list of control sepparated by ","
// Read controls from input args
scanInfo.SetPolicyIdentifiers(strings.Split(args[0], ","), reporthandling.KindControl)
scanInfo.SetPolicyIdentifiers(strings.Split(args[0], ","), apisv1.KindControl)
if len(args) > 1 {
if len(args[1:]) == 0 || args[1] != "-" {
@@ -84,40 +92,40 @@ func getControlCmd(ks meta.IKubescape, scanInfo *cautils.ScanInfo) *cobra.Comman
scanInfo.FrameworkScan = false
if err := validateControlScanInfo(scanInfo); err != nil {
return err
}
results, err := ks.Scan(scanInfo)
if err != nil {
logger.L().Fatal(err.Error())
}
results.HandleResults()
if results.GetRiskScore() > float32(scanInfo.FailThreshold) {
return fmt.Errorf("scan risk-score %.2f is above permitted threshold %.2f", results.GetRiskScore(), scanInfo.FailThreshold)
if err := results.HandleResults(); err != nil {
logger.L().Fatal(err.Error())
}
if !scanInfo.VerboseMode {
cautils.SimpleDisplay(os.Stderr, "%s Run with '--verbose'/'-v' flag for detailed resources view\n\n", emoji.Detective)
}
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)))
}
enforceSeverityThresholds(results.GetResults().SummaryDetails.GetResourcesSeverityCounters(), scanInfo, terminateOnExceedingSeverity)
return nil
},
}
}
// func flagValidationControl() {
// if 100 < scanInfo.FailThreshold {
// logger.L().Fatal("bad argument: out of range threshold")
// }
// }
// validateControlScanInfo validates the ScanInfo struct for the `control` command
func validateControlScanInfo(scanInfo *cautils.ScanInfo) error {
severity := scanInfo.FailThresholdSeverity
// func setScanForFirstControl(scanInfo, controls []string) []reporthandling.PolicyIdentifier {
// newPolicy := reporthandling.PolicyIdentifier{}
// newPolicy.Kind = reporthandling.KindControl
// newPolicy.Name = controls[0]
// scanInfo.PolicyIdentifier = append(scanInfo.PolicyIdentifier, newPolicy)
// return scanInfo.PolicyIdentifier
// }
if scanInfo.Submit && scanInfo.OmitRawResources {
return fmt.Errorf("you can use `omit-raw-resources` or `submit`, but not both")
}
// func SetScanForGivenControls(scanInfo, controls []string) []reporthandling.PolicyIdentifier {
// for _, control := range controls {
// control := strings.TrimLeft(control, " ")
// newPolicy := reporthandling.PolicyIdentifier{}
// newPolicy.Kind = reporthandling.KindControl
// newPolicy.Name = control
// scanInfo.PolicyIdentifier = append(scanInfo.PolicyIdentifier, newPolicy)
// }
// return scanInfo.PolicyIdentifier
// }
if err := validateSeverity(severity); severity != "" && err != nil {
return err
}
return nil
}

View File

@@ -1,22 +1,28 @@
package scan
import (
"errors"
"fmt"
"io"
"os"
"strings"
"github.com/armosec/kubescape/core/cautils"
"github.com/armosec/kubescape/core/cautils/logger"
"github.com/armosec/kubescape/core/meta"
"github.com/armosec/opa-utils/reporthandling"
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"
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/spf13/cobra"
)
var (
frameworkExample = `
# Scan all frameworks and submit the results
kubescape scan framework all --submit
# Scan all frameworks
kubescape scan framework all
# Scan the NSA framework
kubescape scan framework nsa
@@ -27,11 +33,13 @@ var (
# Scan all frameworks
kubescape scan framework all
# Scan kubernetes YAML manifest files
kubescape scan framework nsa *.yaml
# Scan kubernetes YAML manifest files (single file or glob)
kubescape scan framework nsa .
Run 'kubescape list frameworks' for the list of supported frameworks
`
ErrUnknownSeverity = errors.New("unknown severity")
)
func getFrameworkCmd(ks meta.IKubescape, scanInfo *cautils.ScanInfo) *cobra.Command {
@@ -58,7 +66,9 @@ func getFrameworkCmd(ks meta.IKubescape, scanInfo *cautils.ScanInfo) *cobra.Comm
},
RunE: func(cmd *cobra.Command, args []string) error {
flagValidationFramework(scanInfo)
if err := validateFrameworkScanInfo(scanInfo); err != nil {
return err
}
scanInfo.FrameworkScan = true
var frameworks []string
@@ -91,40 +101,113 @@ func getFrameworkCmd(ks meta.IKubescape, scanInfo *cautils.ScanInfo) *cobra.Comm
}
scanInfo.FrameworkScan = true
scanInfo.SetPolicyIdentifiers(frameworks, reporthandling.KindFramework)
scanInfo.SetPolicyIdentifiers(frameworks, apisv1.KindFramework)
results, err := ks.Scan(scanInfo)
if err != nil {
logger.L().Fatal(err.Error())
}
results.HandleResults()
if results.GetRiskScore() > float32(scanInfo.FailThreshold) {
return fmt.Errorf("scan risk-score %.2f is above permitted threshold %.2f", results.GetRiskScore(), scanInfo.FailThreshold)
if err = results.HandleResults(); err != nil {
logger.L().Fatal(err.Error())
}
if !scanInfo.VerboseMode {
cautils.SimpleDisplay(os.Stderr, "Run with '--verbose'/'-v' flag for detailed resources view\n\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)))
}
enforceSeverityThresholds(results.GetData().Report.SummaryDetails.GetResourcesSeverityCounters(), scanInfo, terminateOnExceedingSeverity)
return nil
},
}
}
// func init() {
// scanCmd.AddCommand(frameworkCmd)
// scanInfo = cautils.ScanInfo{}
// }
// func SetScanForFirstFramework(frameworks []string) []reporthandling.PolicyIdentifier {
// newPolicy := reporthandling.PolicyIdentifier{}
// newPolicy.Kind = reporthandling.KindFramework
// newPolicy.Name = frameworks[0]
// scanInfo.PolicyIdentifier = append(scanInfo.PolicyIdentifier, newPolicy)
// return scanInfo.PolicyIdentifier
// }
func flagValidationFramework(scanInfo *cautils.ScanInfo) {
if scanInfo.Submit && scanInfo.Local {
logger.L().Fatal("you can use `keep-local` or `submit`, but not both")
// 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 {
return false, err
}
if 100 < scanInfo.FailThreshold {
logger.L().Fatal("bad argument: out of range threshold")
getFailedResourcesFuncsBySeverity := []struct {
SeverityName string
GetFailedResources func() int
}{
{reporthandlingapis.SeverityLowString, severityCounters.NumberOfLowSeverity},
{reporthandlingapis.SeverityMediumString, severityCounters.NumberOfMediumSeverity},
{reporthandlingapis.SeverityHighString, severityCounters.NumberOfHighSeverity},
{reporthandlingapis.SeverityCriticalString, severityCounters.NumberOfCriticalSeverity},
}
targetSeverityIdx := 0
for idx, description := range getFailedResourcesFuncsBySeverity {
if strings.EqualFold(description.SeverityName, targetSeverity) {
targetSeverityIdx = idx
break
}
}
for _, description := range getFailedResourcesFuncsBySeverity[targetSeverityIdx:] {
failedResourcesCount := description.GetFailedResources()
if failedResourcesCount > 0 {
return true, nil
}
}
return false, nil
}
// terminateOnExceedingSeverity terminates the application on exceeding severity
func terminateOnExceedingSeverity(scanInfo *cautils.ScanInfo, l logger.ILogger) {
l.Fatal("result exceeds severity threshold", helpers.String("set severity threshold", scanInfo.FailThresholdSeverity))
}
// enforceSeverityThresholds ensures that the scan results are below the defined severity threshold
//
// The function forces the application to terminate with an exit code 1 if at least one control failed control that exceeds the set severity threshold
func enforceSeverityThresholds(severityCounters reportsummary.ISeverityCounters, scanInfo *cautils.ScanInfo, onExceed func(*cautils.ScanInfo, logger.ILogger)) {
// If a severity threshold is not set, we dont need to enforce it
if scanInfo.FailThresholdSeverity == "" {
return
}
if val, err := countersExceedSeverityThreshold(severityCounters, scanInfo); val && err == nil {
onExceed(scanInfo, logger.L())
} else if err != nil {
logger.L().Fatal(err.Error())
}
}
// 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.Submit && scanInfo.Local {
return fmt.Errorf("you can use `keep-local` or `submit`, but not both")
}
if 100 < scanInfo.FailThreshold || 0 > scanInfo.FailThreshold {
return fmt.Errorf("bad argument: out of range threshold")
}
if scanInfo.Submit && scanInfo.OmitRawResources {
return fmt.Errorf("you can use `omit-raw-resources` or `submit`, but not both")
}
severity := scanInfo.FailThresholdSeverity
if err := validateSeverity(severity); severity != "" && err != nil {
return err
}
// Validate the user's credentials
return scanInfo.Credentials.Validate()
}

View File

@@ -1,23 +1,26 @@
package scan
import (
"github.com/armosec/k8s-interface/k8sinterface"
"github.com/armosec/kubescape/core/cautils"
"github.com/armosec/kubescape/core/meta"
"flag"
"fmt"
"github.com/kubescape/k8s-interface/k8sinterface"
"github.com/kubescape/kubescape/v2/core/cautils"
"github.com/kubescape/kubescape/v2/core/meta"
"github.com/spf13/cobra"
)
var scanCmdExamples = `
Scan command is for scanning an existing cluster or kubernetes manifest files based on pre-defind frameworks
Scan command is for scanning an existing cluster or kubernetes manifest files based on pre-defined frameworks
# Scan current cluster with all frameworks
kubescape scan --submit --enable-host-scan
kubescape scan --enable-host-scan --verbose
# Scan kubernetes YAML manifest files
kubescape scan *.yaml
kubescape scan .
# Scan and save the results in the JSON format
kubescape scan --format json --output results.json
kubescape scan --format json --output results.json --format-version=v2
# Display all resources
kubescape scan --verbose
@@ -55,40 +58,52 @@ func GetScanCommand(ks meta.IKubescape) *cobra.Command {
},
PreRun: func(cmd *cobra.Command, args []string) {
k8sinterface.SetClusterContextName(scanInfo.KubeContext)
},
PostRun: func(cmd *cobra.Command, args []string) {
// TODO - revert context
},
}
scanCmd.PersistentFlags().StringVarP(&scanInfo.Account, "account", "", "", "ARMO portal account ID. Default will load account ID from configMap or config file")
scanCmd.PersistentFlags().StringVarP(&scanInfo.Credentials.Account, "account", "", "", "Kubescape SaaS account ID. Default will load account ID from cache")
scanCmd.PersistentFlags().BoolVar(&scanInfo.CreateAccount, "create-account", false, "Create a Kubescape SaaS account ID account ID is not found in cache. After creating the account, the account ID will be saved in cache. In addition, the scanning results will be uploaded to the Kubescape SaaS")
scanCmd.PersistentFlags().StringVarP(&scanInfo.Credentials.ClientID, "client-id", "", "", "Kubescape SaaS client ID. Default will load client ID from cache, read more - https://hub.armosec.io/docs/authentication")
scanCmd.PersistentFlags().StringVarP(&scanInfo.Credentials.SecretKey, "secret-key", "", "", "Kubescape SaaS secret key. Default will load secret key from cache, read more - https://hub.armosec.io/docs/authentication")
scanCmd.PersistentFlags().StringVarP(&scanInfo.KubeContext, "kube-context", "", "", "Kube context. Default will use the current-context")
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")
scanCmd.PersistentFlags().StringVarP(&scanInfo.ExcludedNamespaces, "exclude-namespaces", "e", "", "Namespaces to exclude from scanning. Recommended: kube-system,kube-public")
scanCmd.PersistentFlags().StringVarP(&scanInfo.ExcludedNamespaces, "exclude-namespaces", "e", "", "Namespaces to exclude from scanning. Notice, when running with `exclude-namespace` kubescape does not scan cluster-scoped objects.")
scanCmd.PersistentFlags().Float32VarP(&scanInfo.FailThreshold, "fail-threshold", "t", 100, "Failure threshold is the percent above which the command fails and returns exit code 1")
scanCmd.PersistentFlags().StringVarP(&scanInfo.Format, "format", "f", "pretty-printer", `Output format. Supported formats: "pretty-printer","json","junit","prometheus","pdf"`)
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().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 ARMO backend. Use this flag if you ran with the '--submit' flag in the past and you do not want to submit your current scan results")
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().BoolVar(&scanInfo.VerboseMode, "verbose", false, "Display all of the input resources and not only failed resources")
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. default is --view=%s", cautils.ResourceViewType, cautils.ControlViewType, cautils.ResourceViewType))
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().BoolVarP(&scanInfo.Submit, "submit", "", false, "Send the scan results to ARMO management portal 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().StringVar(&scanInfo.HostSensorYamlPath, "host-scan-yaml", "", "Override default host scanner DaemonSet. Use this flag cautiously")
scanCmd.PersistentFlags().StringVar(&scanInfo.FormatVersion, "format-version", "v1", "Output object can be differnet between versions, this is for maintaining backward and forward compatibility. Supported:'v1'/'v2'")
scanCmd.PersistentFlags().StringVar(&scanInfo.FormatVersion, "format-version", "v1", "Output object can be different between versions, this is for maintaining backward and forward compatibility. Supported:'v1'/'v2'")
scanCmd.PersistentFlags().StringVar(&scanInfo.CustomClusterName, "cluster-name", "", "Set the custom name of the cluster. Not same as the kube-context flag")
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")
// Deprecated flags - remove 1.May.2022
scanCmd.PersistentFlags().BoolVarP(&scanInfo.Silent, "silent", "s", false, "Silent progress messages")
scanCmd.PersistentFlags().MarkDeprecated("silent", "use '--logger' flag instead. Flag will be removed at 1.May.2022")
// hidden flags
scanCmd.PersistentFlags().MarkHidden("host-scan-yaml") // this flag should be used very cautiously. We prefer users will not use it at all unless the DaemonSet can not run pods on the nodes
scanCmd.PersistentFlags().MarkHidden("silent") // this flag should be deprecated since we added the --logger support
// scanCmd.PersistentFlags().MarkHidden("format-version") // meant for testing different output approaches and not for common use
scanCmd.PersistentFlags().MarkHidden("omit-raw-resources")
scanCmd.PersistentFlags().MarkHidden("print-attack-tree")
hostF := scanCmd.PersistentFlags().VarPF(&scanInfo.HostSensorEnabled, "enable-host-scan", "", "Deploy ARMO K8s host-sensor daemonset in the scanned cluster. Deleting it right after we collecting the data. Required to collect valuable data from cluster nodes for certain controls. Yaml file: https://raw.githubusercontent.com/armosec/kubescape/master/hostsensorutils/hostsensor.yaml")
// Retrieve --kubeconfig flag from https://github.com/kubernetes/kubectl/blob/master/pkg/cmd/cmd.go
scanCmd.PersistentFlags().AddGoFlag(flag.Lookup("kubeconfig"))
hostF := scanCmd.PersistentFlags().VarPF(&scanInfo.HostSensorEnabled, "enable-host-scan", "", "Deploy Kubescape host-sensor daemonset in the scanned cluster. Deleting it right after we collecting the data. Required to collect valuable data from cluster nodes for certain controls. Yaml file: https://github.com/kubescape/kubescape/blob/master/core/pkg/hostsensorutils/hostsensor.yaml")
hostF.NoOptDefVal = "true"
hostF.DefValue = "false, for no TTY in stdin"

254
cmd/scan/scan_test.go Normal file
View File

@@ -0,0 +1,254 @@
package scan
import (
logger "github.com/kubescape/go-logger"
"github.com/kubescape/go-logger/helpers"
"github.com/kubescape/kubescape/v2/core/cautils"
"github.com/kubescape/opa-utils/reporthandling/apis"
"github.com/kubescape/opa-utils/reporthandling/results/v1/reportsummary"
"os"
"reflect"
"testing"
)
func TestExceedsSeverity(t *testing.T) {
testCases := []struct {
Description string
ScanInfo *cautils.ScanInfo
SeverityCounters reportsummary.ISeverityCounters
Want bool
Error error
}{
{
Description: "Critical failed resource should exceed Critical threshold",
ScanInfo: &cautils.ScanInfo{FailThresholdSeverity: "critical"},
SeverityCounters: &reportsummary.SeverityCounters{CriticalSeverityCounter: 1},
Want: true,
},
{
Description: "Critical failed resource should exceed Critical threshold set as constant",
ScanInfo: &cautils.ScanInfo{FailThresholdSeverity: apis.SeverityCriticalString},
SeverityCounters: &reportsummary.SeverityCounters{CriticalSeverityCounter: 1},
Want: true,
},
{
Description: "High failed resource should not exceed Critical threshold",
ScanInfo: &cautils.ScanInfo{FailThresholdSeverity: "critical"},
SeverityCounters: &reportsummary.SeverityCounters{HighSeverityCounter: 1},
Want: false,
},
{
Description: "Critical failed resource exceeds High threshold",
ScanInfo: &cautils.ScanInfo{FailThresholdSeverity: "high"},
SeverityCounters: &reportsummary.SeverityCounters{CriticalSeverityCounter: 1},
Want: true,
},
{
Description: "High failed resource exceeds High threshold",
ScanInfo: &cautils.ScanInfo{FailThresholdSeverity: "high"},
SeverityCounters: &reportsummary.SeverityCounters{HighSeverityCounter: 1},
Want: true,
},
{
Description: "Medium failed resource does not exceed High threshold",
ScanInfo: &cautils.ScanInfo{FailThresholdSeverity: "high"},
SeverityCounters: &reportsummary.SeverityCounters{MediumSeverityCounter: 1},
Want: false,
},
{
Description: "Critical failed resource exceeds Medium threshold",
ScanInfo: &cautils.ScanInfo{FailThresholdSeverity: "medium"},
SeverityCounters: &reportsummary.SeverityCounters{CriticalSeverityCounter: 1},
Want: true,
},
{
Description: "High failed resource exceeds Medium threshold",
ScanInfo: &cautils.ScanInfo{FailThresholdSeverity: "medium"},
SeverityCounters: &reportsummary.SeverityCounters{HighSeverityCounter: 1},
Want: true,
},
{
Description: "Medium failed resource exceeds Medium threshold",
ScanInfo: &cautils.ScanInfo{FailThresholdSeverity: "medium"},
SeverityCounters: &reportsummary.SeverityCounters{MediumSeverityCounter: 1},
Want: true,
},
{
Description: "Low failed resource does not exceed Medium threshold",
ScanInfo: &cautils.ScanInfo{FailThresholdSeverity: "medium"},
SeverityCounters: &reportsummary.SeverityCounters{LowSeverityCounter: 1},
Want: false,
},
{
Description: "Critical failed resource exceeds Low threshold",
ScanInfo: &cautils.ScanInfo{FailThresholdSeverity: "low"},
SeverityCounters: &reportsummary.SeverityCounters{CriticalSeverityCounter: 1},
Want: true,
},
{
Description: "High failed resource exceeds Low threshold",
ScanInfo: &cautils.ScanInfo{FailThresholdSeverity: "low"},
SeverityCounters: &reportsummary.SeverityCounters{HighSeverityCounter: 1},
Want: true,
},
{
Description: "Medium failed resource exceeds Low threshold",
ScanInfo: &cautils.ScanInfo{FailThresholdSeverity: "low"},
SeverityCounters: &reportsummary.SeverityCounters{MediumSeverityCounter: 1},
Want: true,
},
{
Description: "Low failed resource exceeds Low threshold",
ScanInfo: &cautils.ScanInfo{FailThresholdSeverity: "low"},
SeverityCounters: &reportsummary.SeverityCounters{LowSeverityCounter: 1},
Want: true,
},
{
Description: "Unknown severity returns an error",
ScanInfo: &cautils.ScanInfo{FailThresholdSeverity: "unknown"},
SeverityCounters: &reportsummary.SeverityCounters{LowSeverityCounter: 1},
Want: false,
Error: ErrUnknownSeverity,
},
}
for _, testCase := range testCases {
t.Run(testCase.Description, func(t *testing.T) {
got, err := countersExceedSeverityThreshold(testCase.SeverityCounters, testCase.ScanInfo)
want := testCase.Want
if got != want {
t.Errorf("got: %v, want: %v", got, want)
}
if err != testCase.Error {
t.Errorf(`got error "%v", want "%v"`, err, testCase.Error)
}
})
}
}
func Test_enforceSeverityThresholds(t *testing.T) {
testCases := []struct {
Description string
SeverityCounters *reportsummary.SeverityCounters
ScanInfo *cautils.ScanInfo
Want bool
}{
{
"Exceeding Critical severity counter should call the terminating function",
&reportsummary.SeverityCounters{CriticalSeverityCounter: 1},
&cautils.ScanInfo{FailThresholdSeverity: apis.SeverityCriticalString},
true,
},
{
"Non-exceeding severity counter should call not the terminating function",
&reportsummary.SeverityCounters{},
&cautils.ScanInfo{FailThresholdSeverity: apis.SeverityCriticalString},
false,
},
}
for _, tc := range testCases {
t.Run(
tc.Description,
func(t *testing.T) {
severityCounters := tc.SeverityCounters
scanInfo := tc.ScanInfo
want := tc.Want
got := false
onExceed := func(*cautils.ScanInfo, logger.ILogger) {
got = true
}
enforceSeverityThresholds(severityCounters, scanInfo, onExceed)
if got != want {
t.Errorf("got: %v, want %v", got, want)
}
},
)
}
}
type spyLogMessage struct {
Message string
Details map[string]string
}
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) 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 Test_terminateOnExceedingSeverity(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)
}
},
)
}
}

116
cmd/scan/validators_test.go Normal file
View File

@@ -0,0 +1,116 @@
package scan
import (
"testing"
"github.com/kubescape/kubescape/v2/core/cautils"
)
// Test_validateControlScanInfo tests how scan info is validated for the `scan control` command
func Test_validateControlScanInfo(t *testing.T) {
testCases := []struct {
Description string
ScanInfo *cautils.ScanInfo
Want error
}{
{
"Empty severity should be valid for scan info",
&cautils.ScanInfo{FailThresholdSeverity: ""},
nil,
},
{
"High severity should be valid for scan info",
&cautils.ScanInfo{FailThresholdSeverity: "High"},
nil,
},
{
"Unknown severity should be invalid for scan info",
&cautils.ScanInfo{FailThresholdSeverity: "Unknown"},
ErrUnknownSeverity,
},
}
for _, tc := range testCases {
t.Run(
tc.Description,
func(t *testing.T) {
var want error = tc.Want
got := validateControlScanInfo(tc.ScanInfo)
if got != want {
t.Errorf("got: %v, want: %v", got, want)
}
},
)
}
}
// Test_validateFrameworkScanInfo tests how scan info is validated for the `scan framework` command
func Test_validateFrameworkScanInfo(t *testing.T) {
testCases := []struct {
Description string
ScanInfo *cautils.ScanInfo
Want error
}{
{
"Empty severity should be valid for scan info",
&cautils.ScanInfo{FailThresholdSeverity: ""},
nil,
},
{
"High severity should be valid for scan info",
&cautils.ScanInfo{FailThresholdSeverity: "High"},
nil,
},
{
"Unknown severity should be invalid for scan info",
&cautils.ScanInfo{FailThresholdSeverity: "Unknown"},
ErrUnknownSeverity,
},
}
for _, tc := range testCases {
t.Run(
tc.Description,
func(t *testing.T) {
var want error = tc.Want
got := validateFrameworkScanInfo(tc.ScanInfo)
if got != want {
t.Errorf("got: %v, want: %v", got, want)
}
},
)
}
}
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)
}
})
}
}

View File

@@ -3,16 +3,16 @@ package submit
import (
"fmt"
"github.com/armosec/kubescape/core/cautils/logger"
"github.com/armosec/kubescape/core/meta"
metav1 "github.com/armosec/kubescape/core/meta/datastructures/v1"
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/spf13/cobra"
)
func getExceptionsCmd(ks meta.IKubescape, submitInfo *metav1.Submit) *cobra.Command {
return &cobra.Command{
Use: "exceptions <full path to exceptins file>",
Use: "exceptions <full path to exceptions file>",
Short: "Submit exceptions to the Kubescape SaaS version",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
@@ -21,7 +21,12 @@ func getExceptionsCmd(ks meta.IKubescape, submitInfo *metav1.Submit) *cobra.Comm
return nil
},
Run: func(cmd *cobra.Command, args []string) {
if err := ks.SubmitExceptions(submitInfo.Account, args[0]); err != nil {
if err := flagValidationSubmit(submitInfo); err != nil {
logger.L().Fatal(err.Error())
}
if err := ks.SubmitExceptions(&submitInfo.Credentials, args[0]); err != nil {
logger.L().Fatal(err.Error())
}
},

View File

@@ -1,42 +1,64 @@
package submit
import (
"github.com/armosec/k8s-interface/k8sinterface"
"github.com/armosec/kubescape/core/cautils"
"github.com/armosec/kubescape/core/cautils/getter"
"github.com/armosec/kubescape/core/cautils/logger"
"github.com/armosec/kubescape/core/cautils/logger/helpers"
"github.com/armosec/kubescape/core/meta"
"github.com/armosec/kubescape/core/meta/cliinterfaces"
v1 "github.com/armosec/kubescape/core/meta/datastructures/v1"
"fmt"
reporterv1 "github.com/armosec/kubescape/core/pkg/resultshandling/reporter/v1"
"github.com/google/uuid"
logger "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/cautils/getter"
"github.com/kubescape/kubescape/v2/core/meta"
"github.com/kubescape/kubescape/v2/core/meta/cliinterfaces"
v1 "github.com/kubescape/kubescape/v2/core/meta/datastructures/v1"
reporterv2 "github.com/kubescape/kubescape/v2/core/pkg/resultshandling/reporter/v2"
"github.com/armosec/rbac-utils/rbacscanner"
"github.com/kubescape/rbac-utils/rbacscanner"
"github.com/spf13/cobra"
)
var (
rbacExamples = `
# Submit cluster's Role-Based Access Control(RBAC)
kubescape submit rbac
# Submit cluster's Role-Based Access Control(RBAC) with account ID
kubescape submit rbac --account <account-id>
`
)
// getRBACCmd represents the RBAC command
func getRBACCmd(ks meta.IKubescape, submitInfo *v1.Submit) *cobra.Command {
return &cobra.Command{
Use: "rbac \nExample:\n$ kubescape submit rbac",
Short: "Submit cluster's Role-Based Access Control(RBAC)",
Long: ``,
Use: "rbac",
Deprecated: "This command is deprecated and will not be supported after 1/Jan/2023. Please use the 'scan' command instead.",
Example: rbacExamples,
Short: "Submit cluster's Role-Based Access Control(RBAC)",
Long: ``,
RunE: func(cmd *cobra.Command, args []string) error {
if err := flagValidationSubmit(submitInfo); err != nil {
return err
}
k8s := k8sinterface.NewKubernetesApi()
// get config
clusterConfig := getTenantConfig(submitInfo.Account, "", k8s)
clusterConfig := getTenantConfig(&submitInfo.Credentials, "", "", k8s)
if err := clusterConfig.SetTenant(); err != nil {
logger.L().Error("failed setting account ID", helpers.Error(err))
}
if clusterConfig.GetAccountID() == "" {
return fmt.Errorf("account ID is not set, run 'kubescape submit rbac --account <account-id>'")
}
// list RBAC
rbacObjects := cautils.NewRBACObjects(rbacscanner.NewRbacScannerFromK8sAPI(k8s, clusterConfig.GetAccountID(), clusterConfig.GetClusterName()))
rbacObjects := cautils.NewRBACObjects(rbacscanner.NewRbacScannerFromK8sAPI(k8s, clusterConfig.GetAccountID(), clusterConfig.GetContextName()))
// submit resources
r := reporterv1.NewReportEventReceiver(clusterConfig.GetConfigObj())
r := reporterv2.NewReportEventReceiver(clusterConfig.GetConfigObj(), uuid.NewString(), reporterv2.SubmitContextRBAC)
submitInterfaces := cliinterfaces.SubmitInterfaces{
ClusterConfig: clusterConfig,
@@ -60,9 +82,16 @@ func getKubernetesApi() *k8sinterface.KubernetesApi {
}
return k8sinterface.NewKubernetesApi()
}
func getTenantConfig(Account, clusterName string, k8s *k8sinterface.KubernetesApi) cautils.ITenantConfig {
func getTenantConfig(credentials *cautils.Credentials, clusterName string, customClusterName string, k8s *k8sinterface.KubernetesApi) cautils.ITenantConfig {
if !k8sinterface.IsConnectedToCluster() || k8s == nil {
return cautils.NewLocalConfig(getter.GetArmoAPIConnector(), Account, clusterName)
return cautils.NewLocalConfig(getter.GetKSCloudAPIConnector(), credentials, clusterName, customClusterName)
}
return cautils.NewClusterConfig(k8s, getter.GetArmoAPIConnector(), Account, clusterName)
return cautils.NewClusterConfig(k8s, getter.GetKSCloudAPIConnector(), credentials, clusterName, customClusterName)
}
// Check if the flag entered are valid
func flagValidationSubmit(submitInfo *v1.Submit) error {
// Validate the user's credentials
return submitInfo.Credentials.Validate()
}

View File

@@ -4,20 +4,18 @@ import (
"encoding/json"
"fmt"
"os"
"time"
"github.com/armosec/k8s-interface/workloadinterface"
"github.com/armosec/kubescape/core/cautils/logger"
"github.com/armosec/kubescape/core/cautils/logger/helpers"
"github.com/armosec/kubescape/core/meta"
"github.com/armosec/kubescape/core/meta/cliinterfaces"
v1 "github.com/armosec/kubescape/core/meta/datastructures/v1"
"github.com/armosec/kubescape/core/pkg/resultshandling/reporter"
reporterv1 "github.com/armosec/kubescape/core/pkg/resultshandling/reporter/v1"
reporterv2 "github.com/armosec/kubescape/core/pkg/resultshandling/reporter/v2"
"github.com/armosec/opa-utils/reporthandling"
"github.com/google/uuid"
reporthandlingv2 "github.com/kubescape/opa-utils/reporthandling/v2"
logger "github.com/kubescape/go-logger"
"github.com/kubescape/go-logger/helpers"
"github.com/kubescape/k8s-interface/workloadinterface"
"github.com/kubescape/kubescape/v2/core/meta"
"github.com/kubescape/kubescape/v2/core/meta/cliinterfaces"
v1 "github.com/kubescape/kubescape/v2/core/meta/datastructures/v1"
reporterv2 "github.com/kubescape/kubescape/v2/core/pkg/resultshandling/reporter/v2"
"github.com/spf13/cobra"
)
@@ -37,19 +35,13 @@ func NewResultsObject(customerGUID, clusterName, filePath string) *ResultsObject
}
}
func (resultsObject *ResultsObject) SetResourcesReport() (*reporthandling.PostureReport, error) {
func (resultsObject *ResultsObject) SetResourcesReport() (*reporthandlingv2.PostureReport, error) {
// load framework results from json file
frameworkReports, err := loadResultsFromFile(resultsObject.filePath)
report, err := loadResultsFromFile(resultsObject.filePath)
if err != nil {
return nil, err
}
return &reporthandling.PostureReport{
FrameworkReports: frameworkReports,
ReportID: uuid.NewString(),
ReportGenerationTime: time.Now().UTC(),
CustomerGUID: resultsObject.customerGUID,
ClusterName: resultsObject.clusterName,
}, nil
return report, nil
}
func (resultsObject *ResultsObject) ListAllResources() (map[string]workloadinterface.IMetadata, error) {
@@ -62,6 +54,11 @@ func getResultsCmd(ks meta.IKubescape, submitInfo *v1.Submit) *cobra.Command {
Short: "Submit a pre scanned results file. The file must be in json format",
Long: ``,
RunE: func(cmd *cobra.Command, args []string) error {
if err := flagValidationSubmit(submitInfo); err != nil {
return err
}
if len(args) == 0 {
return fmt.Errorf("missing results file")
}
@@ -69,22 +66,14 @@ func getResultsCmd(ks meta.IKubescape, submitInfo *v1.Submit) *cobra.Command {
k8s := getKubernetesApi()
// get config
clusterConfig := getTenantConfig(submitInfo.Account, "", k8s)
clusterConfig := getTenantConfig(&submitInfo.Credentials, "", "", k8s)
if err := clusterConfig.SetTenant(); err != nil {
logger.L().Error("failed setting account ID", helpers.Error(err))
}
resultsObjects := NewResultsObject(clusterConfig.GetAccountID(), clusterConfig.GetClusterName(), args[0])
resultsObjects := NewResultsObject(clusterConfig.GetAccountID(), clusterConfig.GetContextName(), args[0])
// submit resources
var r reporter.IReport
switch formatVersion {
case "v2":
r = reporterv2.NewReportEventReceiver(clusterConfig.GetConfigObj(), "")
default:
logger.L().Warning("Deprecated results version. run with '--format-version' flag", helpers.String("your version", formatVersion), helpers.String("latest version", "v2"))
r = reporterv1.NewReportEventReceiver(clusterConfig.GetConfigObj())
}
r := reporterv2.NewReportEventReceiver(clusterConfig.GetConfigObj(), uuid.NewString(), reporterv2.SubmitContextScan)
submitInterfaces := cliinterfaces.SubmitInterfaces{
ClusterConfig: clusterConfig,
@@ -102,18 +91,14 @@ func getResultsCmd(ks meta.IKubescape, submitInfo *v1.Submit) *cobra.Command {
return resultsCmd
}
func loadResultsFromFile(filePath string) ([]reporthandling.FrameworkReport, error) {
frameworkReports := []reporthandling.FrameworkReport{}
func loadResultsFromFile(filePath string) (*reporthandlingv2.PostureReport, error) {
report := &reporthandlingv2.PostureReport{}
f, err := os.ReadFile(filePath)
if err != nil {
return nil, err
}
if err = json.Unmarshal(f, &frameworkReports); err != nil {
frameworkReport := reporthandling.FrameworkReport{}
if err = json.Unmarshal(f, &frameworkReport); err != nil {
return frameworkReports, err
}
frameworkReports = append(frameworkReports, frameworkReport)
if err = json.Unmarshal(f, report); err != nil {
return report, fmt.Errorf("failed to unmarshal results file: %s, make sure you run kubescape with '--format=json --format-version=v2'", err.Error())
}
return frameworkReports, nil
return report, nil
}

View File

@@ -1,26 +1,33 @@
package submit
import (
"github.com/armosec/kubescape/core/meta"
metav1 "github.com/armosec/kubescape/core/meta/datastructures/v1"
"github.com/kubescape/kubescape/v2/core/meta"
metav1 "github.com/kubescape/kubescape/v2/core/meta/datastructures/v1"
"github.com/spf13/cobra"
)
var submitCmdExamples = `
# Submit Kubescape scan results file
kubescape submit results
# Submit exceptions file to Kubescape SaaS
kubescape submit exceptions
`
func GetSubmitCmd(ks meta.IKubescape) *cobra.Command {
var submitInfo metav1.Submit
submitCmd := &cobra.Command{
Use: "submit <command>",
Short: "Submit an object to the Kubescape SaaS version",
Long: ``,
Use: "submit <command>",
Short: "Submit an object to the Kubescape SaaS version",
Long: ``,
Example: submitCmdExamples,
Run: func(cmd *cobra.Command, args []string) {
},
}
submitCmd.PersistentFlags().StringVarP(&submitInfo.Account, "account", "", "", "Armo portal account ID. Default will load account ID from configMap or config file")
submitCmd.PersistentFlags().StringVarP(&submitInfo.Credentials.Account, "account", "", "", "Kubescape SaaS account ID. Default will load account ID from cache")
submitCmd.PersistentFlags().StringVarP(&submitInfo.Credentials.ClientID, "client-id", "", "", "Kubescape SaaS client ID. Default will load client ID from cache, read more - https://hub.armosec.io/docs/authentication")
submitCmd.PersistentFlags().StringVarP(&submitInfo.Credentials.SecretKey, "secret-key", "", "", "Kubescape SaaS secret key. Default will load secret key from cache, read more - https://hub.armosec.io/docs/authentication")
submitCmd.AddCommand(getExceptionsCmd(ks, &submitInfo))
submitCmd.AddCommand(getResultsCmd(ks, &submitInfo))

59
cmd/update/update.go Normal file
View File

@@ -0,0 +1,59 @@
package update
//This update command updates to the latest kubescape release.
//Example:-
// kubescape update
import (
"os/exec"
"runtime"
logger "github.com/kubescape/go-logger"
"github.com/kubescape/kubescape/v2/core/cautils"
"github.com/spf13/cobra"
)
func GetUpdateCmd() *cobra.Command {
updateCmd := &cobra.Command{
Use: "update",
Short: "Update your version",
Long: ``,
RunE: func(_ *cobra.Command, args []string) error {
//Checking the user's version of kubescape to the latest release
if cautils.BuildNumber == cautils.LatestReleaseVersion {
//your version == latest version
logger.L().Info(("You are in the latest version"))
} else {
const OSTYPE string = runtime.GOOS
var ShellToUse string
switch OSTYPE {
case "windows":
cautils.StartSpinner()
//run the installation command for windows
ShellToUse = "powershell"
_, err := exec.Command(ShellToUse, "-c", "iwr -useb https://raw.githubusercontent.com/kubescape/kubescape/master/install.ps1 | iex").Output()
if err != nil {
logger.L().Fatal(err.Error())
}
cautils.StopSpinner()
default:
ShellToUse = "bash"
cautils.StartSpinner()
//run the installation command for linux and macOS
_, err := exec.Command(ShellToUse, "-c", "curl -s https://raw.githubusercontent.com/kubescape/kubescape/master/install.sh | /bin/bash").Output()
if err != nil {
logger.L().Fatal(err.Error())
}
cautils.StopSpinner()
}
}
return nil
},
}
return updateCmd
}

View File

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

View File

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

View File

@@ -4,7 +4,7 @@ import (
"fmt"
"os"
"github.com/armosec/kubescape/core/cautils"
"github.com/kubescape/kubescape/v2/core/cautils"
"github.com/spf13/cobra"
)
@@ -16,7 +16,11 @@ func GetVersionCmd() *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
v := cautils.NewIVersionCheckHandler()
v.CheckLatestVersion(cautils.NewVersionCheckRequest(cautils.BuildNumber, "", "", "version"))
fmt.Fprintln(os.Stdout, "Your current version is: "+cautils.BuildNumber)
fmt.Fprintf(os.Stdout,
"Your current version is: %s [git enabled in build: %t]\n",
cautils.BuildNumber,
isGitEnabled(),
)
return nil
},
}

View File

@@ -0,0 +1,12 @@
package cautils
import (
"fmt"
"strings"
)
func GetControlLink(controlID string) string {
// For CIS Controls, cis-1.1.3 will be transformed to cis-1-1-3 in documentation link.
docLinkID := strings.ReplaceAll(controlID, ".", "-")
return fmt.Sprintf("https://hub.armosec.io/docs/%s", strings.ToLower(docLinkID))
}

View File

@@ -5,13 +5,15 @@ import (
"encoding/json"
"fmt"
"os"
"regexp"
"strings"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/armosec/k8s-interface/k8sinterface"
"github.com/armosec/kubescape/core/cautils/getter"
"github.com/armosec/kubescape/core/cautils/logger"
logger "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"
corev1 "k8s.io/api/core/v1"
)
@@ -31,6 +33,10 @@ type ConfigObj struct {
Token string `json:"invitationParam,omitempty"`
CustomerAdminEMail string `json:"adminMail,omitempty"`
ClusterName string `json:"clusterName,omitempty"`
CloudReportURL string `json:"cloudReportURL,omitempty"`
CloudAPIURL string `json:"cloudAPIURL,omitempty"`
CloudUIURL string `json:"cloudUIURL,omitempty"`
CloudAuthURL string `json:"cloudAuthURL,omitempty"`
}
// Config - convert ConfigObj to config file
@@ -67,9 +73,17 @@ type ITenantConfig interface {
DeleteCachedConfig() error
// getters
GetClusterName() string
GetContextName() string
GetAccountID() string
GetTenantEmail() string
GetToken() string
GetClientID() string
GetSecretKey() string
GetConfigObj() *ConfigObj
GetCloudReportURL() string
GetCloudAPIURL() string
GetCloudUIURL() string
GetCloudAuthURL() string
// GetBackendAPI() getter.IBackend
// GenerateURL()
@@ -86,8 +100,7 @@ type LocalConfig struct {
}
func NewLocalConfig(
backendAPI getter.IBackend, customerGUID, clusterName string) *LocalConfig {
var configObj *ConfigObj
backendAPI getter.IBackend, credentials *Credentials, clusterName string, customClusterName string) *LocalConfig {
lc := &LocalConfig{
backendAPI: backendAPI,
@@ -95,35 +108,62 @@ func NewLocalConfig(
}
// get from configMap
if existsConfigFile() { // get from file
configObj, _ = loadConfigFromFile()
} else {
configObj = &ConfigObj{}
loadConfigFromFile(lc.configObj)
}
if configObj != nil {
lc.configObj = configObj
}
if customerGUID != "" {
lc.configObj.AccountID = customerGUID // override config customerGUID
}
if clusterName != "" {
updateCredentials(lc.configObj, credentials)
updateCloudURLs(lc.configObj)
// If a custom cluster name is provided then set that name, else use the cluster's original name
if customClusterName != "" {
lc.configObj.ClusterName = AdoptClusterName(customClusterName)
} else if clusterName != "" {
lc.configObj.ClusterName = AdoptClusterName(clusterName) // override config clusterName
}
getAccountFromEnv(lc.configObj)
lc.backendAPI.SetAccountID(lc.configObj.AccountID)
lc.backendAPI.SetClientID(lc.configObj.ClientID)
lc.backendAPI.SetSecretKey(lc.configObj.SecretKey)
if lc.configObj.CloudAPIURL != "" {
lc.backendAPI.SetCloudAPIURL(lc.configObj.CloudAPIURL)
} else {
lc.configObj.CloudAPIURL = lc.backendAPI.GetCloudAPIURL()
}
if lc.configObj.CloudAuthURL != "" {
lc.backendAPI.SetCloudAuthURL(lc.configObj.CloudAuthURL)
} else {
lc.configObj.CloudAuthURL = lc.backendAPI.GetCloudAuthURL()
}
if lc.configObj.CloudReportURL != "" {
lc.backendAPI.SetCloudReportURL(lc.configObj.CloudReportURL)
} else {
lc.configObj.CloudReportURL = lc.backendAPI.GetCloudReportURL()
}
if lc.configObj.CloudUIURL != "" {
lc.backendAPI.SetCloudUIURL(lc.configObj.CloudUIURL)
} else {
lc.configObj.CloudUIURL = lc.backendAPI.GetCloudUIURL()
}
logger.L().Debug("Kubescape Cloud URLs", helpers.String("api", lc.backendAPI.GetCloudAPIURL()), helpers.String("auth", lc.backendAPI.GetCloudAuthURL()), helpers.String("report", lc.backendAPI.GetCloudReportURL()), helpers.String("UI", lc.backendAPI.GetCloudUIURL()))
return lc
}
func (lc *LocalConfig) GetConfigObj() *ConfigObj { return lc.configObj }
func (lc *LocalConfig) GetAccountID() string { return lc.configObj.AccountID }
func (lc *LocalConfig) GetClusterName() string { return lc.configObj.ClusterName }
func (lc *LocalConfig) IsConfigFound() bool { return existsConfigFile() }
func (lc *LocalConfig) GetConfigObj() *ConfigObj { return lc.configObj }
func (lc *LocalConfig) GetTenantEmail() string { return lc.configObj.CustomerAdminEMail }
func (lc *LocalConfig) GetAccountID() string { return lc.configObj.AccountID }
func (lc *LocalConfig) GetClientID() string { return lc.configObj.ClientID }
func (lc *LocalConfig) GetSecretKey() string { return lc.configObj.SecretKey }
func (lc *LocalConfig) GetContextName() string { return lc.configObj.ClusterName }
func (lc *LocalConfig) GetToken() string { return lc.configObj.Token }
func (lc *LocalConfig) GetCloudReportURL() string { return lc.configObj.CloudReportURL }
func (lc *LocalConfig) GetCloudAPIURL() string { return lc.configObj.CloudAPIURL }
func (lc *LocalConfig) GetCloudUIURL() string { return lc.configObj.CloudUIURL }
func (lc *LocalConfig) GetCloudAuthURL() string { return lc.configObj.CloudAuthURL }
func (lc *LocalConfig) IsConfigFound() bool { return existsConfigFile() }
func (lc *LocalConfig) SetTenant() error {
// ARMO tenant GUID
// Kubescape Cloud tenant GUID
if err := getTenantConfigFromBE(lc.backendAPI, lc.configObj); err != nil {
return err
}
@@ -144,7 +184,7 @@ func (lc *LocalConfig) DeleteCachedConfig() error {
func getTenantConfigFromBE(backendAPI getter.IBackend, configObj *ConfigObj) error {
// get from armoBE
// get from Kubescape Cloud API
tenantResponse, err := backendAPI.GetTenant()
if err == nil && tenantResponse != nil {
if tenantResponse.AdminMail != "" { // registered tenant
@@ -177,19 +217,19 @@ KS_ACCOUNT_ID
KS_CLIENT_ID
KS_SECRET_KEY
TODO - supprot:
TODO - support:
KS_CACHE // path to cached files
*/
type ClusterConfig struct {
backendAPI getter.IBackend
k8s *k8sinterface.KubernetesApi
configObj *ConfigObj
configMapName string
configMapNamespace string
backendAPI getter.IBackend
configObj *ConfigObj
}
func NewClusterConfig(k8s *k8sinterface.KubernetesApi, backendAPI getter.IBackend, customerGUID, clusterName string) *ClusterConfig {
var configObj *ConfigObj
func NewClusterConfig(k8s *k8sinterface.KubernetesApi, backendAPI getter.IBackend, credentials *Credentials, clusterName string, customClusterName string) *ClusterConfig {
// var configObj *ConfigObj
c := &ClusterConfig{
k8s: k8s,
backendAPI: backendAPI,
@@ -198,26 +238,27 @@ func NewClusterConfig(k8s *k8sinterface.KubernetesApi, backendAPI getter.IBacken
configMapNamespace: getConfigMapNamespace(),
}
// get from configMap
// first, load from configMap
if c.existsConfigMap() {
configObj, _ = c.loadConfigFromConfigMap()
c.loadConfigFromConfigMap()
}
if configObj == nil && existsConfigFile() { // get from file
configObj, _ = loadConfigFromFile()
// second, load from file
if existsConfigFile() { // get from file
loadConfigFromFile(c.configObj)
}
if configObj != nil {
c.configObj = configObj
}
if customerGUID != "" {
c.configObj.AccountID = customerGUID // override config customerGUID
}
if clusterName != "" {
updateCredentials(c.configObj, credentials)
updateCloudURLs(c.configObj)
// If a custom cluster name is provided then set that name, else use the cluster's original name
if customClusterName != "" {
c.configObj.ClusterName = AdoptClusterName(customClusterName)
} else if clusterName != "" {
c.configObj.ClusterName = AdoptClusterName(clusterName) // override config clusterName
}
getAccountFromEnv(c.configObj)
if c.configObj.ClusterName == "" {
c.configObj.ClusterName = AdoptClusterName(k8sinterface.GetClusterName())
c.configObj.ClusterName = AdoptClusterName(k8sinterface.GetContextName())
} else { // override the cluster name if it has unwanted characters
c.configObj.ClusterName = AdoptClusterName(c.configObj.ClusterName)
}
@@ -225,14 +266,44 @@ func NewClusterConfig(k8s *k8sinterface.KubernetesApi, backendAPI getter.IBacken
c.backendAPI.SetAccountID(c.configObj.AccountID)
c.backendAPI.SetClientID(c.configObj.ClientID)
c.backendAPI.SetSecretKey(c.configObj.SecretKey)
if c.configObj.CloudAPIURL != "" {
c.backendAPI.SetCloudAPIURL(c.configObj.CloudAPIURL)
} else {
c.configObj.CloudAPIURL = c.backendAPI.GetCloudAPIURL()
}
if c.configObj.CloudAuthURL != "" {
c.backendAPI.SetCloudAuthURL(c.configObj.CloudAuthURL)
} else {
c.configObj.CloudAuthURL = c.backendAPI.GetCloudAuthURL()
}
if c.configObj.CloudReportURL != "" {
c.backendAPI.SetCloudReportURL(c.configObj.CloudReportURL)
} else {
c.configObj.CloudReportURL = c.backendAPI.GetCloudReportURL()
}
if c.configObj.CloudUIURL != "" {
c.backendAPI.SetCloudUIURL(c.configObj.CloudUIURL)
} else {
c.configObj.CloudUIURL = c.backendAPI.GetCloudUIURL()
}
logger.L().Debug("Kubescape Cloud URLs", helpers.String("api", c.backendAPI.GetCloudAPIURL()), helpers.String("auth", c.backendAPI.GetCloudAuthURL()), helpers.String("report", c.backendAPI.GetCloudReportURL()), helpers.String("UI", c.backendAPI.GetCloudUIURL()))
return c
}
func (c *ClusterConfig) GetConfigObj() *ConfigObj { return c.configObj }
func (c *ClusterConfig) GetDefaultNS() string { return c.configMapNamespace }
func (c *ClusterConfig) GetAccountID() string { return c.configObj.AccountID }
func (c *ClusterConfig) IsConfigFound() bool { return existsConfigFile() || c.existsConfigMap() }
func (c *ClusterConfig) GetConfigObj() *ConfigObj { return c.configObj }
func (c *ClusterConfig) GetDefaultNS() string { return c.configMapNamespace }
func (c *ClusterConfig) GetAccountID() string { return c.configObj.AccountID }
func (c *ClusterConfig) GetClientID() string { return c.configObj.ClientID }
func (c *ClusterConfig) GetSecretKey() string { return c.configObj.SecretKey }
func (c *ClusterConfig) GetTenantEmail() string { return c.configObj.CustomerAdminEMail }
func (c *ClusterConfig) GetToken() string { return c.configObj.Token }
func (c *ClusterConfig) GetCloudReportURL() string { return c.configObj.CloudReportURL }
func (c *ClusterConfig) GetCloudAPIURL() string { return c.configObj.CloudAPIURL }
func (c *ClusterConfig) GetCloudUIURL() string { return c.configObj.CloudUIURL }
func (c *ClusterConfig) GetCloudAuthURL() string { return c.configObj.CloudAuthURL }
func (c *ClusterConfig) IsConfigFound() bool { return existsConfigFile() || c.existsConfigMap() }
func (c *ClusterConfig) SetTenant() error {
@@ -268,7 +339,7 @@ func (c *ClusterConfig) DeleteCachedConfig() error {
}
return nil
}
func (c *ClusterConfig) GetClusterName() string {
func (c *ClusterConfig) GetContextName() string {
return c.configObj.ClusterName
}
@@ -279,18 +350,26 @@ func (c *ClusterConfig) ToMapString() map[string]interface{} {
}
return m
}
func (c *ClusterConfig) loadConfigFromConfigMap() (*ConfigObj, error) {
func (c *ClusterConfig) loadConfigFromConfigMap() error {
configMap, err := c.k8s.KubernetesClient.CoreV1().ConfigMaps(c.configMapNamespace).Get(context.Background(), c.configMapName, metav1.GetOptions{})
if err != nil {
return nil, err
return err
}
if bData, err := json.Marshal(configMap.Data); err == nil {
return readConfig(bData)
}
return nil, nil
return loadConfigFromData(c.configObj, configMap.Data)
}
func loadConfigFromData(co *ConfigObj, data map[string]string) error {
var e error
if jsonConf, ok := data["config.json"]; ok {
e = readConfig([]byte(jsonConf), co)
}
if bData, err := json.Marshal(data); err == nil {
e = readConfig(bData, co)
}
return e
}
func (c *ClusterConfig) existsConfigMap() bool {
_, err := c.k8s.KubernetesClient.CoreV1().ConfigMaps(c.configMapNamespace).Get(context.Background(), c.configMapName, metav1.GetOptions{})
// TODO - check if has customerGUID
@@ -391,10 +470,7 @@ func (c *ClusterConfig) updateConfigMap() error {
}
func updateConfigFile(configObj *ConfigObj) error {
if err := os.WriteFile(ConfigFileFullPath(), configObj.Config(), 0664); err != nil {
return err
}
return nil
return os.WriteFile(ConfigFileFullPath(), configObj.Config(), 0664) //nolint:gosec
}
func (c *ClusterConfig) updateConfigData(configMap *corev1.ConfigMap) {
@@ -408,28 +484,27 @@ func (c *ClusterConfig) updateConfigData(configMap *corev1.ConfigMap) {
}
}
}
func loadConfigFromFile() (*ConfigObj, error) {
func loadConfigFromFile(configObj *ConfigObj) error {
dat, err := os.ReadFile(ConfigFileFullPath())
if err != nil {
return nil, err
return err
}
return readConfig(dat)
return readConfig(dat, configObj)
}
func readConfig(dat []byte) (*ConfigObj, error) {
func readConfig(dat []byte, configObj *ConfigObj) error {
if len(dat) == 0 {
return nil, nil
return nil
}
configObj := &ConfigObj{}
if err := json.Unmarshal(dat, configObj); err != nil {
return nil, err
return err
}
if configObj.AccountID == "" {
configObj.AccountID = configObj.CustomerGUID
}
configObj.CustomerGUID = ""
return configObj, nil
return nil
}
// Check if the customer is submitted
@@ -459,7 +534,11 @@ func DeleteConfigFile() error {
}
func AdoptClusterName(clusterName string) string {
return strings.ReplaceAll(clusterName, "/", "-")
re, err := regexp.Compile(`[^\w]+`)
if err != nil {
return clusterName
}
return re.ReplaceAllString(clusterName, "-")
}
func getConfigMapName() string {
@@ -476,15 +555,70 @@ func getConfigMapNamespace() string {
return "default"
}
func getAccountFromEnv(configObj *ConfigObj) {
func getAccountFromEnv(credentials *Credentials) {
// load from env
if accountID := os.Getenv("KS_ACCOUNT_ID"); accountID != "" {
configObj.AccountID = accountID
if accountID := os.Getenv("KS_ACCOUNT_ID"); credentials.Account == "" && accountID != "" {
credentials.Account = accountID
}
if clientID := os.Getenv("KS_CLIENT_ID"); clientID != "" {
configObj.ClientID = clientID
if clientID := os.Getenv("KS_CLIENT_ID"); credentials.ClientID == "" && clientID != "" {
credentials.ClientID = clientID
}
if secretKey := os.Getenv("KS_SECRET_KEY"); secretKey != "" {
configObj.SecretKey = secretKey
if secretKey := os.Getenv("KS_SECRET_KEY"); credentials.SecretKey == "" && secretKey != "" {
credentials.SecretKey = secretKey
}
}
func updateCredentials(configObj *ConfigObj, credentials *Credentials) {
if credentials == nil {
credentials = &Credentials{}
}
getAccountFromEnv(credentials)
if credentials.Account != "" {
configObj.AccountID = credentials.Account // override config Account
}
if credentials.ClientID != "" {
configObj.ClientID = credentials.ClientID // override config ClientID
}
if credentials.SecretKey != "" {
configObj.SecretKey = credentials.SecretKey // override config SecretKey
}
}
func getCloudURLsFromEnv(cloudURLs *CloudURLs) {
// load from env
if cloudAPIURL := os.Getenv("KS_CLOUD_API_URL"); cloudAPIURL != "" {
cloudURLs.CloudAPIURL = cloudAPIURL
}
if cloudAuthURL := os.Getenv("KS_CLOUD_AUTH_URL"); cloudAuthURL != "" {
cloudURLs.CloudAuthURL = cloudAuthURL
}
if cloudReportURL := os.Getenv("KS_CLOUD_REPORT_URL"); cloudReportURL != "" {
cloudURLs.CloudReportURL = cloudReportURL
}
if cloudUIURL := os.Getenv("KS_CLOUD_UI_URL"); cloudUIURL != "" {
cloudURLs.CloudUIURL = cloudUIURL
}
}
func updateCloudURLs(configObj *ConfigObj) {
cloudURLs := &CloudURLs{}
getCloudURLsFromEnv(cloudURLs)
if cloudURLs.CloudAPIURL != "" {
configObj.CloudAPIURL = cloudURLs.CloudAPIURL // override config CloudAPIURL
}
if cloudURLs.CloudAuthURL != "" {
configObj.CloudAuthURL = cloudURLs.CloudAuthURL // override config CloudAuthURL
}
if cloudURLs.CloudReportURL != "" {
configObj.CloudReportURL = cloudURLs.CloudReportURL // override config CloudReportURL
}
if cloudURLs.CloudUIURL != "" {
configObj.CloudUIURL = cloudURLs.CloudUIURL // override config CloudUIURL
}
}

View File

@@ -0,0 +1,270 @@
package cautils
import (
"encoding/json"
"os"
"testing"
"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
)
func mockConfigObj() *ConfigObj {
return &ConfigObj{
AccountID: "aaa",
ClientID: "bbb",
SecretKey: "ccc",
ClusterName: "ddd",
CustomerAdminEMail: "ab@cd",
Token: "eee",
CloudReportURL: "report.armo.cloud",
CloudAPIURL: "api.armosec.io",
CloudUIURL: "cloud.armosec.io",
CloudAuthURL: "auth.armosec.io",
}
}
func mockLocalConfig() *LocalConfig {
return &LocalConfig{
backendAPI: nil,
configObj: mockConfigObj(),
}
}
func mockClusterConfig() *ClusterConfig {
return &ClusterConfig{
backendAPI: nil,
configObj: mockConfigObj(),
}
}
func TestConfig(t *testing.T) {
co := mockConfigObj()
cop := ConfigObj{}
assert.NoError(t, json.Unmarshal(co.Config(), &cop))
assert.Equal(t, co.AccountID, cop.AccountID)
assert.Equal(t, co.ClientID, cop.ClientID)
assert.Equal(t, co.SecretKey, cop.SecretKey)
assert.Equal(t, co.CloudReportURL, cop.CloudReportURL)
assert.Equal(t, co.CloudAPIURL, cop.CloudAPIURL)
assert.Equal(t, co.CloudUIURL, cop.CloudUIURL)
assert.Equal(t, co.CloudAuthURL, cop.CloudAuthURL)
assert.Equal(t, "", cop.ClusterName) // Not copied to bytes
assert.Equal(t, "", cop.CustomerAdminEMail) // Not copied to bytes
assert.Equal(t, "", cop.Token) // Not copied to bytes
}
func TestITenantConfig(t *testing.T) {
var lc ITenantConfig
var c ITenantConfig
lc = mockLocalConfig()
c = mockClusterConfig()
co := mockConfigObj()
// test LocalConfig methods
assert.Equal(t, co.AccountID, lc.GetAccountID())
assert.Equal(t, co.ClientID, lc.GetClientID())
assert.Equal(t, co.SecretKey, lc.GetSecretKey())
assert.Equal(t, co.ClusterName, lc.GetContextName())
assert.Equal(t, co.CustomerAdminEMail, lc.GetTenantEmail())
assert.Equal(t, co.Token, lc.GetToken())
assert.Equal(t, co.CloudReportURL, lc.GetCloudReportURL())
assert.Equal(t, co.CloudAPIURL, lc.GetCloudAPIURL())
assert.Equal(t, co.CloudUIURL, lc.GetCloudUIURL())
assert.Equal(t, co.CloudAuthURL, lc.GetCloudAuthURL())
// test ClusterConfig methods
assert.Equal(t, co.AccountID, c.GetAccountID())
assert.Equal(t, co.ClientID, c.GetClientID())
assert.Equal(t, co.SecretKey, c.GetSecretKey())
assert.Equal(t, co.ClusterName, c.GetContextName())
assert.Equal(t, co.CustomerAdminEMail, c.GetTenantEmail())
assert.Equal(t, co.Token, c.GetToken())
assert.Equal(t, co.CloudReportURL, c.GetCloudReportURL())
assert.Equal(t, co.CloudAPIURL, c.GetCloudAPIURL())
assert.Equal(t, co.CloudUIURL, c.GetCloudUIURL())
assert.Equal(t, co.CloudAuthURL, c.GetCloudAuthURL())
}
func TestUpdateConfigData(t *testing.T) {
c := mockClusterConfig()
configMap := &corev1.ConfigMap{}
c.updateConfigData(configMap)
assert.Equal(t, c.GetAccountID(), configMap.Data["accountID"])
assert.Equal(t, c.GetClientID(), configMap.Data["clientID"])
assert.Equal(t, c.GetSecretKey(), configMap.Data["secretKey"])
assert.Equal(t, c.GetCloudReportURL(), configMap.Data["cloudReportURL"])
assert.Equal(t, c.GetCloudAPIURL(), configMap.Data["cloudAPIURL"])
assert.Equal(t, c.GetCloudUIURL(), configMap.Data["cloudUIURL"])
assert.Equal(t, c.GetCloudAuthURL(), configMap.Data["cloudAuthURL"])
}
func TestReadConfig(t *testing.T) {
com := mockConfigObj()
co := &ConfigObj{}
b, e := json.Marshal(com)
assert.NoError(t, e)
readConfig(b, co)
assert.Equal(t, com.AccountID, co.AccountID)
assert.Equal(t, com.ClientID, co.ClientID)
assert.Equal(t, com.SecretKey, co.SecretKey)
assert.Equal(t, com.ClusterName, co.ClusterName)
assert.Equal(t, com.CustomerAdminEMail, co.CustomerAdminEMail)
assert.Equal(t, com.Token, co.Token)
assert.Equal(t, com.CloudReportURL, co.CloudReportURL)
assert.Equal(t, com.CloudAPIURL, co.CloudAPIURL)
assert.Equal(t, com.CloudUIURL, co.CloudUIURL)
assert.Equal(t, com.CloudAuthURL, co.CloudAuthURL)
}
func TestLoadConfigFromData(t *testing.T) {
// use case: all data is in base config
{
c := mockClusterConfig()
co := mockConfigObj()
configMap := &corev1.ConfigMap{}
c.updateConfigData(configMap)
c.configObj = &ConfigObj{}
loadConfigFromData(c.configObj, configMap.Data)
assert.Equal(t, c.GetAccountID(), co.AccountID)
assert.Equal(t, c.GetClientID(), co.ClientID)
assert.Equal(t, c.GetSecretKey(), co.SecretKey)
assert.Equal(t, c.GetContextName(), co.ClusterName)
assert.Equal(t, c.GetTenantEmail(), co.CustomerAdminEMail)
assert.Equal(t, c.GetToken(), co.Token)
assert.Equal(t, c.GetCloudReportURL(), co.CloudReportURL)
assert.Equal(t, c.GetCloudAPIURL(), co.CloudAPIURL)
assert.Equal(t, c.GetCloudUIURL(), co.CloudUIURL)
assert.Equal(t, c.GetCloudAuthURL(), co.CloudAuthURL)
}
// use case: all data is in config.json
{
c := mockClusterConfig()
co := mockConfigObj()
configMap := &corev1.ConfigMap{
Data: make(map[string]string),
}
configMap.Data["config.json"] = string(c.GetConfigObj().Config())
c.configObj = &ConfigObj{}
loadConfigFromData(c.configObj, configMap.Data)
assert.Equal(t, c.GetAccountID(), co.AccountID)
assert.Equal(t, c.GetClientID(), co.ClientID)
assert.Equal(t, c.GetSecretKey(), co.SecretKey)
assert.Equal(t, c.GetCloudReportURL(), co.CloudReportURL)
assert.Equal(t, c.GetCloudAPIURL(), co.CloudAPIURL)
assert.Equal(t, c.GetCloudUIURL(), co.CloudUIURL)
assert.Equal(t, c.GetCloudAuthURL(), co.CloudAuthURL)
}
// use case: some data is in config.json
{
c := mockClusterConfig()
configMap := &corev1.ConfigMap{
Data: make(map[string]string),
}
// add to map
configMap.Data["clientID"] = c.configObj.ClientID
configMap.Data["secretKey"] = c.configObj.SecretKey
configMap.Data["cloudReportURL"] = c.configObj.CloudReportURL
// delete the content
c.configObj.ClientID = ""
c.configObj.SecretKey = ""
c.configObj.CloudReportURL = ""
configMap.Data["config.json"] = string(c.GetConfigObj().Config())
loadConfigFromData(c.configObj, configMap.Data)
assert.NotEmpty(t, c.GetAccountID())
assert.NotEmpty(t, c.GetClientID())
assert.NotEmpty(t, c.GetSecretKey())
assert.NotEmpty(t, c.GetCloudReportURL())
}
// use case: some data is in config.json
{
c := mockClusterConfig()
configMap := &corev1.ConfigMap{
Data: make(map[string]string),
}
c.configObj.AccountID = "tttt"
// add to map
configMap.Data["accountID"] = mockConfigObj().AccountID
configMap.Data["clientID"] = c.configObj.ClientID
configMap.Data["secretKey"] = c.configObj.SecretKey
// delete the content
c.configObj.ClientID = ""
c.configObj.SecretKey = ""
configMap.Data["config.json"] = string(c.GetConfigObj().Config())
loadConfigFromData(c.configObj, configMap.Data)
assert.Equal(t, mockConfigObj().AccountID, c.GetAccountID())
assert.NotEmpty(t, c.GetClientID())
assert.NotEmpty(t, c.GetSecretKey())
}
}
func TestAdoptClusterName(t *testing.T) {
tests := []struct {
name string
clusterName string
want string
}{
{
name: "replace 1",
clusterName: "my-name__is--ks",
want: "my-name__is-ks",
},
{
name: "replace 2",
clusterName: "my-name1",
want: "my-name1",
},
{
name: "replace 3",
clusterName: "my:name",
want: "my-name",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := AdoptClusterName(tt.clusterName); got != tt.want {
t.Errorf("AdoptClusterName() = %v, want %v", got, tt.want)
}
})
}
}
func TestUpdateCloudURLs(t *testing.T) {
co := mockConfigObj()
mockCloudAPIURL := "1-2-3-4.com"
os.Setenv("KS_CLOUD_API_URL", mockCloudAPIURL)
assert.NotEqual(t, co.CloudAPIURL, mockCloudAPIURL)
updateCloudURLs(co)
assert.Equal(t, co.CloudAPIURL, mockCloudAPIURL)
}

View File

@@ -2,32 +2,38 @@ package cautils
import (
"github.com/armosec/armoapi-go/armotypes"
"github.com/armosec/k8s-interface/workloadinterface"
"github.com/armosec/opa-utils/reporthandling"
apis "github.com/armosec/opa-utils/reporthandling/apis"
"github.com/armosec/opa-utils/reporthandling/results/v1/resourcesresults"
reporthandlingv2 "github.com/armosec/opa-utils/reporthandling/v2"
"github.com/kubescape/k8s-interface/workloadinterface"
"github.com/kubescape/opa-utils/reporthandling"
apis "github.com/kubescape/opa-utils/reporthandling/apis"
"github.com/kubescape/opa-utils/reporthandling/attacktrack/v1alpha1"
"github.com/kubescape/opa-utils/reporthandling/results/v1/prioritization"
"github.com/kubescape/opa-utils/reporthandling/results/v1/resourcesresults"
reporthandlingv2 "github.com/kubescape/opa-utils/reporthandling/v2"
)
// K8SResources map[<api group>/<api version>/<resource>][]<resourceID>
type K8SResources map[string][]string
type ArmoResources map[string][]string
type KSResources map[string][]string
type OPASessionObj struct {
K8SResources *K8SResources // input k8s objects
ArmoResource *ArmoResources // input ARMO objects
Policies []reporthandling.Framework // list of frameworks to scan
AllResources map[string]workloadinterface.IMetadata // all scanned resources, map[<rtesource ID>]<resource>
ResourcesResult map[string]resourcesresults.Result // resources scan results, map[<rtesource ID>]<resource result>
ResourceSource map[string]string // resources sources, map[<rtesource ID>]<resource result>
PostureReport *reporthandling.PostureReport // scan results v1 - Remove
Report *reporthandlingv2.PostureReport // scan results v2 - Remove
Exceptions []armotypes.PostureExceptionPolicy // list of exceptions to apply on scan results
RegoInputData RegoInputData // input passed to rgo for scanning. map[<control name>][<input arguments>]
K8SResources *K8SResources // input k8s objects
ArmoResource *KSResources // input ARMO objects
AllPolicies *Policies // list of all frameworks
AllResources map[string]workloadinterface.IMetadata // all scanned resources, map[<resource ID>]<resource>
ResourcesResult map[string]resourcesresults.Result // resources scan results, map[<resource ID>]<resource result>
ResourceSource map[string]reporthandling.Source // resources sources, map[<resource ID>]<resource result>
ResourcesPrioritized map[string]prioritization.PrioritizedResource // resources prioritization information, map[<resource ID>]<prioritized resource>
ResourceAttackTracks map[string]v1alpha1.IAttackTrack // resources attack tracks, map[<resource ID>]<attack track>
AttackTracks map[string]v1alpha1.IAttackTrack
Report *reporthandlingv2.PostureReport // scan results v2 - Remove
RegoInputData RegoInputData // input passed to rego for scanning. map[<control name>][<input arguments>]
Metadata *reporthandlingv2.Metadata
InfoMap map[string]apis.StatusInfo // Map errors of resources to StatusInfo
ResourceToControlsMap map[string][]string // map[<apigroup/apiversion/resource>] = [<control_IDs>]
SessionID string // SessionID
InfoMap map[string]apis.StatusInfo // Map errors of resources to StatusInfo
ResourceToControlsMap map[string][]string // map[<apigroup/apiversion/resource>] = [<control_IDs>]
SessionID string // SessionID
Policies []reporthandling.Framework // list of frameworks to scan
Exceptions []armotypes.PostureExceptionPolicy // list of exceptions to apply on scan results
OmitRawResources bool // omit raw resources from output
}
func NewOPASessionObj(frameworks []reporthandling.Framework, k8sResources *K8SResources, scanInfo *ScanInfo) *OPASessionObj {
@@ -37,30 +43,45 @@ func NewOPASessionObj(frameworks []reporthandling.Framework, k8sResources *K8SRe
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]string),
ResourceSource: make(map[string]reporthandling.Source),
SessionID: scanInfo.ScanID,
PostureReport: &reporthandling.PostureReport{
ClusterName: ClusterName,
CustomerGUID: CustomerGUID,
},
Metadata: scanInfoToScanMetadata(scanInfo),
Metadata: scanInfoToScanMetadata(scanInfo),
OmitRawResources: scanInfo.OmitRawResources,
}
}
func (sessionObj *OPASessionObj) SetMapNamespaceToNumberOfResources(mapNamespaceToNumberOfResources map[string]int) {
if sessionObj.Metadata.ContextMetadata.ClusterContextMetadata == nil {
sessionObj.Metadata.ContextMetadata.ClusterContextMetadata = &reporthandlingv2.ClusterMetadata{}
}
if sessionObj.Metadata.ContextMetadata.ClusterContextMetadata.MapNamespaceToNumberOfResources == nil {
sessionObj.Metadata.ContextMetadata.ClusterContextMetadata.MapNamespaceToNumberOfResources = make(map[string]int)
}
sessionObj.Metadata.ContextMetadata.ClusterContextMetadata.MapNamespaceToNumberOfResources = mapNamespaceToNumberOfResources
}
func (sessionObj *OPASessionObj) SetNumberOfWorkerNodes(n int) {
if sessionObj.Metadata.ContextMetadata.ClusterContextMetadata == nil {
sessionObj.Metadata.ContextMetadata.ClusterContextMetadata = &reporthandlingv2.ClusterMetadata{}
}
sessionObj.Metadata.ContextMetadata.ClusterContextMetadata.NumberOfWorkerNodes = n
}
func NewOPASessionObjMock() *OPASessionObj {
return &OPASessionObj{
Policies: nil,
K8SResources: nil,
AllResources: make(map[string]workloadinterface.IMetadata),
ResourcesResult: make(map[string]resourcesresults.Result),
Report: &reporthandlingv2.PostureReport{},
PostureReport: &reporthandling.PostureReport{
ClusterName: "",
CustomerGUID: "",
ReportID: "",
JobID: "",
Policies: nil,
K8SResources: nil,
AllResources: make(map[string]workloadinterface.IMetadata),
ResourcesResult: make(map[string]resourcesresults.Result),
ResourcesPrioritized: make(map[string]prioritization.PrioritizedResource),
Report: &reporthandlingv2.PostureReport{},
Metadata: &reporthandlingv2.Metadata{
ScanMetadata: reporthandlingv2.ScanMetadata{
ScanningTarget: 0,
},
},
}
}
@@ -78,11 +99,12 @@ type Exception struct {
type RegoInputData struct {
PostureControlInputs map[string][]string `json:"postureControlInputs"`
DataControlInputs map[string]string `json:"dataControlInputs"`
// ClusterName string `json:"clusterName"`
// K8sConfig RegoK8sConfig `json:"k8sconfig"`
}
type Policies struct {
Frameworks []string
Controls map[string]reporthandling.Control // map[<control ID>]<control>
Frameworks []string
}

View File

@@ -1,10 +1,10 @@
package cautils
import (
pkgcautils "github.com/armosec/utils-go/utils"
"golang.org/x/mod/semver"
"github.com/armosec/opa-utils/reporthandling"
"github.com/armosec/utils-go/boolutils"
"github.com/kubescape/opa-utils/reporthandling"
)
func NewPolicies() *Policies {
@@ -22,7 +22,7 @@ func (policies *Policies) Set(frameworks []reporthandling.Framework, version str
for j := range frameworks[i].Controls {
compatibleRules := []reporthandling.PolicyRule{}
for r := range frameworks[i].Controls[j].Rules {
if !ruleWithArmoOpaDependency(frameworks[i].Controls[j].Rules[r].Attributes) && isRuleKubescapeVersionCompatible(frameworks[i].Controls[j].Rules[r].Attributes, version) {
if !ruleWithKSOpaDependency(frameworks[i].Controls[j].Rules[r].Attributes) && isRuleKubescapeVersionCompatible(frameworks[i].Controls[j].Rules[r].Attributes, version) {
compatibleRules = append(compatibleRules, frameworks[i].Controls[j].Rules[r])
}
}
@@ -35,12 +35,12 @@ func (policies *Policies) Set(frameworks []reporthandling.Framework, version str
}
}
func ruleWithArmoOpaDependency(attributes map[string]interface{}) bool {
func ruleWithKSOpaDependency(attributes map[string]interface{}) bool {
if attributes == nil {
return false
}
if s, ok := attributes["armoOpa"]; ok { // TODO - make global
return pkgcautils.StringToBool(s.(string))
return boolutils.StringToBool(s.(string))
}
return false
}
@@ -51,18 +51,16 @@ func ruleWithArmoOpaDependency(attributes map[string]interface{}) bool {
func isRuleKubescapeVersionCompatible(attributes map[string]interface{}, version string) bool {
if from, ok := attributes["useFromKubescapeVersion"]; ok && from != nil {
if version != "" {
if semver.Compare(from.(string), BuildNumber) > 0 {
if semver.Compare(version, from.(string)) == -1 {
return false
}
}
}
if until, ok := attributes["useUntilKubescapeVersion"]; ok && until != nil {
if version != "" {
if semver.Compare(BuildNumber, until.(string)) >= 0 {
return false
}
} else {
if version == "" {
return false
}
if semver.Compare(version, until.(string)) >= 0 {
return false
}
}

View File

@@ -1,6 +1,6 @@
package cautils
// CA environment vars
// Kubescape Cloud environment vars
var (
CustomerGUID = ""
ClusterName = ""

View File

@@ -8,15 +8,19 @@ import (
"path/filepath"
"strings"
"github.com/armosec/k8s-interface/workloadinterface"
"github.com/armosec/kubescape/core/cautils/logger"
"github.com/armosec/opa-utils/objectsenvelopes"
"gopkg.in/yaml.v2"
"github.com/kubescape/go-logger/helpers"
"github.com/kubescape/k8s-interface/workloadinterface"
logger "github.com/kubescape/go-logger"
"github.com/kubescape/opa-utils/objectsenvelopes"
"github.com/kubescape/opa-utils/objectsenvelopes/localworkload"
"gopkg.in/yaml.v3"
)
var (
YAML_PREFIX = []string{".yaml", ".yml"}
JSON_PREFIX = []string{".json"}
YAML_PREFIX = []string{"yaml", "yml"}
JSON_PREFIX = []string{"json"}
)
type FileFormat string
@@ -26,23 +30,90 @@ const (
JSON_FILE_FORMAT FileFormat = "json"
)
func LoadResourcesFromFiles(inputPatterns []string) (map[string][]workloadinterface.IMetadata, error) {
files, errs := listFiles(inputPatterns)
// LoadResourcesFromHelmCharts scans a given path (recursively) for helm charts, renders the templates and returns a map of workloads and a map of chart names
func LoadResourcesFromHelmCharts(basePath string) (map[string][]workloadinterface.IMetadata, map[string]string) {
directories, _ := listDirs(basePath)
helmDirectories := make([]string, 0)
for _, dir := range directories {
if ok, _ := IsHelmDirectory(dir); ok {
helmDirectories = append(helmDirectories, dir)
}
}
sourceToWorkloads := map[string][]workloadinterface.IMetadata{}
sourceToChartName := map[string]string{}
for _, helmDir := range helmDirectories {
chart, err := NewHelmChart(helmDir)
if err == nil {
wls, errs := chart.GetWorkloadsWithDefaultValues()
if len(errs) > 0 {
logger.L().Error(fmt.Sprintf("Rendering of Helm chart template '%s', failed: %v", chart.GetName(), errs))
continue
}
chartName := chart.GetName()
for k, v := range wls {
sourceToWorkloads[k] = v
sourceToChartName[k] = chartName
}
}
}
return sourceToWorkloads, sourceToChartName
}
// If the contents at given path is a Kustomize Directory, LoadResourcesFromKustomizeDirectory will
// generate yaml files using "Kustomize" & renders a map of workloads from those yaml files
func LoadResourcesFromKustomizeDirectory(basePath string) (map[string][]workloadinterface.IMetadata, string) {
isKustomizeDirectory := IsKustomizeDirectory(basePath)
isKustomizeFile := IsKustomizeFile(basePath)
if ok := isKustomizeDirectory || isKustomizeFile; !ok {
return nil, ""
}
sourceToWorkloads := map[string][]workloadinterface.IMetadata{}
kustomizeDirectory := NewKustomizeDirectory(basePath)
var newBasePath string
if isKustomizeFile {
newBasePath = filepath.Dir(basePath)
logger.L().Info("Kustomize File Detected, Scanning the rendered Kubernetes Objects...")
} else {
newBasePath = basePath
logger.L().Info("Kustomize Directory Detected, Scanning the rendered Kubernetes Objects...")
}
wls, errs := kustomizeDirectory.GetWorkloads(newBasePath)
kustomizeDirectoryName := GetKustomizeDirectoryName(newBasePath)
if len(errs) > 0 {
logger.L().Error(fmt.Sprintf("Rendering yaml from Kustomize failed: %v", errs))
}
for k, v := range wls {
sourceToWorkloads[k] = v
}
return sourceToWorkloads, kustomizeDirectoryName
}
func LoadResourcesFromFiles(input, rootPath string) map[string][]workloadinterface.IMetadata {
files, errs := listFiles(input)
if len(errs) > 0 {
logger.L().Error(fmt.Sprintf("%v", errs))
}
if len(files) == 0 {
return nil, nil
return nil
}
workloads, errs := loadFiles(files)
workloads, errs := loadFiles(rootPath, files)
if len(errs) > 0 {
logger.L().Error(fmt.Sprintf("%v", errs))
}
return workloads, nil
return workloads
}
func loadFiles(filePaths []string) (map[string][]workloadinterface.IMetadata, []error) {
func loadFiles(rootPath string, filePaths []string) (map[string][]workloadinterface.IMetadata, []error) {
workloads := make(map[string][]workloadinterface.IMetadata, 0)
errs := []error{}
for i := range filePaths {
@@ -51,15 +122,30 @@ func loadFiles(filePaths []string) (map[string][]workloadinterface.IMetadata, []
errs = append(errs, err)
continue
}
if len(f) == 0 {
continue // empty file
}
w, e := ReadFile(f, GetFileFormat(filePaths[i]))
errs = append(errs, e...)
if w != nil {
if _, ok := workloads[filePaths[i]]; !ok {
workloads[filePaths[i]] = []workloadinterface.IMetadata{}
if e != nil {
logger.L().Debug("failed to read file", helpers.String("file", filePaths[i]), helpers.Error(e))
}
if len(w) != 0 {
path := filePaths[i]
if _, ok := workloads[path]; !ok {
workloads[path] = []workloadinterface.IMetadata{}
}
wSlice := workloads[filePaths[i]]
wSlice = append(wSlice, w...)
workloads[filePaths[i]] = wSlice
wSlice := workloads[path]
for j := range w {
lw := localworkload.NewLocalWorkload(w[j].GetObject())
if relPath, err := filepath.Rel(rootPath, path); err == nil {
lw.SetPath(fmt.Sprintf("%s:%d", relPath, j))
} else {
lw.SetPath(fmt.Sprintf("%s:%d", path, j))
}
wSlice = append(wSlice, lw)
}
workloads[path] = wSlice
}
}
return workloads, errs
@@ -68,47 +154,65 @@ func loadFiles(filePaths []string) (map[string][]workloadinterface.IMetadata, []
func loadFile(filePath string) ([]byte, error) {
return os.ReadFile(filePath)
}
func ReadFile(fileContent []byte, fileFromat FileFormat) ([]workloadinterface.IMetadata, []error) {
func ReadFile(fileContent []byte, fileFormat FileFormat) ([]workloadinterface.IMetadata, error) {
switch fileFromat {
switch fileFormat {
case YAML_FILE_FORMAT:
return readYamlFile(fileContent)
case JSON_FILE_FORMAT:
return readJsonFile(fileContent)
default:
return nil, nil // []error{fmt.Errorf("file extension %s not supported", fileFromat)}
return nil, nil
}
}
func listFiles(patterns []string) ([]string, []error) {
files := []string{}
errs := []error{}
for i := range patterns {
if strings.HasPrefix(patterns[i], "http") {
continue
}
if !filepath.IsAbs(patterns[i]) {
o, _ := os.Getwd()
patterns[i] = filepath.Join(o, patterns[i])
}
if IsFile(patterns[i]) {
files = append(files, patterns[i])
} else {
f, err := glob(filepath.Split(patterns[i])) //filepath.Glob(patterns[i])
if err != nil {
errs = append(errs, err)
} else {
files = append(files, f...)
}
}
}
return files, errs
// listFiles returns the list of absolute paths, full file path and list of errors. The list of abs paths and full path have the same length
func listFiles(pattern string) ([]string, []error) {
return listFilesOrDirectories(pattern, false)
}
func readYamlFile(yamlFile []byte) ([]workloadinterface.IMetadata, []error) {
// listDirs returns the list of absolute paths, full directories path and list of errors. The list of abs paths and full path have the same length
func listDirs(pattern string) ([]string, []error) {
return listFilesOrDirectories(pattern, true)
}
func listFilesOrDirectories(pattern string, onlyDirectories bool) ([]string, []error) {
var paths []string
errs := []error{}
if !filepath.IsAbs(pattern) {
o, _ := os.Getwd()
pattern = filepath.Join(o, pattern)
}
if !onlyDirectories && IsFile(pattern) {
paths = append(paths, pattern)
return paths, errs
}
root, shouldMatch := filepath.Split(pattern)
if IsDir(pattern) {
root = pattern
shouldMatch = "*"
}
if shouldMatch == "" {
shouldMatch = "*"
}
f, err := glob(root, shouldMatch, onlyDirectories)
if err != nil {
errs = append(errs, err)
} else {
paths = append(paths, f...)
}
return paths, errs
}
func readYamlFile(yamlFile []byte) ([]workloadinterface.IMetadata, error) {
defer recover()
r := bytes.NewReader(yamlFile)
dec := yaml.NewDecoder(r)
yamlObjs := []workloadinterface.IMetadata{}
@@ -121,25 +225,25 @@ func readYamlFile(yamlFile []byte) ([]workloadinterface.IMetadata, []error) {
}
if obj, ok := j.(map[string]interface{}); ok {
if o := objectsenvelopes.NewObject(obj); o != nil {
if o.GetKind() == "List" {
yamlObjs = append(yamlObjs, handleListObject(o)...)
if o.GetObjectType() == workloadinterface.TypeListWorkloads {
if list := workloadinterface.NewListWorkloadsObj(o.GetObject()); list != nil {
yamlObjs = append(yamlObjs, list.GetItems()...)
}
} else {
yamlObjs = append(yamlObjs, o)
}
}
} else {
errs = append(errs, fmt.Errorf("failed to convert yaml file to map[string]interface, file content: %v", j))
}
}
return yamlObjs, errs
return yamlObjs, nil
}
func readJsonFile(jsonFile []byte) ([]workloadinterface.IMetadata, []error) {
func readJsonFile(jsonFile []byte) ([]workloadinterface.IMetadata, error) {
workloads := []workloadinterface.IMetadata{}
var jsonObj interface{}
if err := json.Unmarshal(jsonFile, &jsonObj); err != nil {
return workloads, []error{err}
return workloads, err
}
convertJsonToWorkload(jsonObj, &workloads)
@@ -178,28 +282,47 @@ func convertYamlToJson(i interface{}) interface{} {
}
func IsYaml(filePath string) bool {
return StringInSlice(YAML_PREFIX, filepath.Ext(filePath)) != ValueNotFound
return StringInSlice(YAML_PREFIX, strings.ReplaceAll(filepath.Ext(filePath), ".", "")) != ValueNotFound
}
func IsJson(filePath string) bool {
return StringInSlice(JSON_PREFIX, filepath.Ext(filePath)) != ValueNotFound
return StringInSlice(JSON_PREFIX, strings.ReplaceAll(filepath.Ext(filePath), ".", "")) != ValueNotFound
}
func glob(root, pattern string) ([]string, error) {
func glob(root, pattern string, onlyDirectories bool) ([]string, error) {
var matches []string
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
// listing only directories
if onlyDirectories {
if info.IsDir() {
if matched, err := filepath.Match(pattern, filepath.Base(path)); err != nil {
return err
} else if matched {
matches = append(matches, path)
}
}
return nil
}
// listing only files
if info.IsDir() {
return nil
}
fileFormat := GetFileFormat(path)
if !(fileFormat == JSON_FILE_FORMAT || fileFormat == YAML_FILE_FORMAT) {
return nil
}
if matched, err := filepath.Match(pattern, filepath.Base(path)); err != nil {
return err
} else if matched {
matches = append(matches, path)
}
return nil
})
if err != nil {
@@ -207,6 +330,8 @@ func glob(root, pattern string) ([]string, error) {
}
return matches, nil
}
// IsFile checks if a given path is a file
func IsFile(name string) bool {
if fi, err := os.Stat(name); err == nil {
if fi.Mode().IsRegular() {
@@ -216,6 +341,16 @@ func IsFile(name string) bool {
return false
}
// IsDir checks if a given path is a directory
func IsDir(name string) bool {
if info, err := os.Stat(name); err == nil {
if info.IsDir() {
return true
}
}
return false
}
func GetFileFormat(filePath string) FileFormat {
if IsYaml(filePath) {
return YAML_FILE_FORMAT
@@ -225,20 +360,3 @@ func GetFileFormat(filePath string) FileFormat {
return FileFormat(filePath)
}
}
// handleListObject handle a List manifest
func handleListObject(obj workloadinterface.IMetadata) []workloadinterface.IMetadata {
yamlObjs := []workloadinterface.IMetadata{}
if i, ok := workloadinterface.InspectMap(obj.GetObject(), "items"); ok && i != nil {
if items, ok := i.([]interface{}); ok && items != nil {
for item := range items {
if m, ok := items[item].(map[string]interface{}); ok && m != nil {
if o := objectsenvelopes.NewObject(m); o != nil {
yamlObjs = append(yamlObjs, o)
}
}
}
}
}
return yamlObjs
}

View File

@@ -6,59 +6,100 @@ import (
"strings"
"testing"
"github.com/kubescape/opa-utils/objectsenvelopes/localworkload"
"github.com/stretchr/testify/assert"
)
func onlineBoutiquePath() string {
o, _ := os.Getwd()
return filepath.Join(filepath.Dir(o), "../examples/online-boutique/*")
return filepath.Join(filepath.Dir(o), "..", "examples", "online-boutique")
}
func helmChartPath() string {
o, _ := os.Getwd()
return filepath.Join(filepath.Dir(o), "..", "examples", "helm_chart")
}
func TestListFiles(t *testing.T) {
filesPath := onlineBoutiquePath()
files, errs := listFiles([]string{filesPath})
files, errs := listFiles(filesPath)
assert.Equal(t, 0, len(errs))
assert.Equal(t, 12, len(files))
}
func TestLoadResourcesFromFiles(t *testing.T) {
workloads, err := LoadResourcesFromFiles([]string{onlineBoutiquePath()})
assert.NoError(t, err)
workloads := LoadResourcesFromFiles(onlineBoutiquePath(), "")
assert.Equal(t, 12, len(workloads))
for i, w := range workloads {
switch filepath.Base(i) {
case "adservice.yaml":
assert.Equal(t, 2, len(w))
assert.Equal(t, "apps/v1//Deployment/adservice", w[0].GetID())
assert.Equal(t, "/v1//Service/adservice", w[1].GetID())
assert.Equal(t, "apps/v1//Deployment/adservice", getRelativePath(w[0].GetID()))
assert.Equal(t, "/v1//Service/adservice", getRelativePath(w[1].GetID()))
}
}
}
func TestLoadResourcesFromHelmCharts(t *testing.T) {
sourceToWorkloads, sourceToChartName := LoadResourcesFromHelmCharts(helmChartPath())
assert.Equal(t, 6, len(sourceToWorkloads))
for file, workloads := range sourceToWorkloads {
assert.Equalf(t, 1, len(workloads), "expected 1 workload in file %s", file)
w := workloads[0]
assert.True(t, localworkload.IsTypeLocalWorkload(w.GetObject()), "Expected localworkload as object type")
assert.Equal(t, "kubescape", sourceToChartName[file])
switch filepath.Base(file) {
case "serviceaccount.yaml":
assert.Equal(t, "/v1//ServiceAccount/kubescape-discovery", getRelativePath(w.GetID()))
case "clusterrole.yaml":
assert.Equal(t, "rbac.authorization.k8s.io/v1//ClusterRole/-kubescape", getRelativePath(w.GetID()))
case "cronjob.yaml":
assert.Equal(t, "batch/v1//CronJob/-kubescape", getRelativePath(w.GetID()))
case "role.yaml":
assert.Equal(t, "rbac.authorization.k8s.io/v1//Role/-kubescape", getRelativePath(w.GetID()))
case "rolebinding.yaml":
assert.Equal(t, "rbac.authorization.k8s.io/v1//RoleBinding/-kubescape", getRelativePath(w.GetID()))
case "clusterrolebinding.yaml":
assert.Equal(t, "rbac.authorization.k8s.io/v1//ClusterRoleBinding/-kubescape", getRelativePath(w.GetID()))
default:
assert.Failf(t, "missing case for file: %s", filepath.Base(file))
}
}
}
func TestLoadFiles(t *testing.T) {
files, _ := listFiles([]string{onlineBoutiquePath()})
_, err := loadFiles(files)
files, _ := listFiles(onlineBoutiquePath())
_, err := loadFiles("", files)
assert.Equal(t, 0, len(err))
}
func TestListDirs(t *testing.T) {
dirs, _ := listDirs(filepath.Join(onlineBoutiquePath(), "adservice.yaml"))
assert.Equal(t, 0, len(dirs))
expectedDirs := []string{filepath.Join("examples", "helm_chart"), filepath.Join("examples", "helm_chart", "templates")}
dirs, _ = listDirs(helmChartPath())
assert.Equal(t, len(expectedDirs), len(dirs))
for i := range expectedDirs {
assert.Contains(t, dirs[i], expectedDirs[i])
}
}
func TestLoadFile(t *testing.T) {
files, _ := listFiles([]string{strings.Replace(onlineBoutiquePath(), "*", "adservice.yaml", 1)})
files, _ := listFiles(filepath.Join(onlineBoutiquePath(), "adservice.yaml"))
assert.Equal(t, 1, len(files))
_, err := loadFile(files[0])
assert.NoError(t, err)
}
func TestMapResources(t *testing.T) {
// policyHandler := &PolicyHandler{}
// k8sResources, err := policyHandler.loadResources(opaSessionObj.Frameworks, scanInfo)
// files, _ := listFiles([]string{onlineBoutiquePath()})
// bb, err := loadFile(files[0])
// if len(err) > 0 {
// t.Errorf("%v", err)
// }
// for i := range bb {
// t.Errorf("%s", bb[i].ToString())
// }
func getRelativePath(p string) string {
pp := strings.SplitAfter(p, "api=")
return pp[1]
}

View File

@@ -0,0 +1,18 @@
package cautils
import "math"
// Float64ToInt convert float64 to int
func Float64ToInt(x float64) int {
return int(math.Round(x))
}
// Float32ToInt convert float32 to int
func Float32ToInt(x float32) int {
return Float64ToInt(float64(x))
}
// Float16ToInt convert float16 to int
func Float16ToInt(x float32) int {
return Float64ToInt(float64(x))
}

View File

@@ -0,0 +1,24 @@
package cautils
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestFloat64ToInt(t *testing.T) {
assert.Equal(t, 3, Float64ToInt(3.49))
assert.Equal(t, 4, Float64ToInt(3.5))
assert.Equal(t, 4, Float64ToInt(3.51))
}
func TestFloat32ToInt(t *testing.T) {
assert.Equal(t, 3, Float32ToInt(3.49))
assert.Equal(t, 4, Float32ToInt(3.5))
assert.Equal(t, 4, Float32ToInt(3.51))
}
func TestFloat16ToInt(t *testing.T) {
assert.Equal(t, 3, Float16ToInt(3.49))
assert.Equal(t, 4, Float16ToInt(3.5))
assert.Equal(t, 4, Float16ToInt(3.51))
}

View File

@@ -1,364 +0,0 @@
package getter
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"strings"
"time"
"github.com/armosec/armoapi-go/armotypes"
"github.com/armosec/kubescape/core/cautils/logger"
"github.com/armosec/kubescape/core/cautils/logger/helpers"
"github.com/armosec/opa-utils/reporthandling"
)
// =======================================================================================================================
// =============================================== ArmoAPI ===============================================================
// =======================================================================================================================
var (
// ATTENTION!!!
// Changes in this URLs variable names, or in the usage is affecting the build process! BE CAREFUL
armoERURL = "report.armo.cloud"
armoBEURL = "api.armo.cloud"
armoFEURL = "portal.armo.cloud"
armoAUTHURL = "auth.armo.cloud"
armoStageERURL = "report-ks.eustage2.cyberarmorsoft.com"
armoStageBEURL = "api-stage.armo.cloud"
armoStageFEURL = "armoui.eustage2.cyberarmorsoft.com"
armoStageAUTHURL = "eggauth.eustage2.cyberarmorsoft.com"
armoDevERURL = "report.eudev3.cyberarmorsoft.com"
armoDevBEURL = "api-dev.armo.cloud"
armoDevFEURL = "armoui-dev.eudev3.cyberarmorsoft.com"
armoDevAUTHURL = "eggauth.eudev3.cyberarmorsoft.com"
)
// Armo API for downloading policies
type ArmoAPI struct {
httpClient *http.Client
apiURL string
authURL string
erURL string
feURL string
accountID string
clientID string
secretKey string
feToken FeLoginResponse
authCookie string
loggedIn bool
}
var globalArmoAPIConnector *ArmoAPI
func SetARMOAPIConnector(armoAPI *ArmoAPI) {
logger.L().Debug("Armo URLs", helpers.String("api", armoAPI.apiURL), helpers.String("auth", armoAPI.authURL), helpers.String("report", armoAPI.erURL), helpers.String("UI", armoAPI.feURL))
globalArmoAPIConnector = armoAPI
}
func GetArmoAPIConnector() *ArmoAPI {
if globalArmoAPIConnector == nil {
// logger.L().Error("returning nil API connector")
SetARMOAPIConnector(NewARMOAPIProd())
}
return globalArmoAPIConnector
}
func NewARMOAPIDev() *ArmoAPI {
apiObj := newArmoAPI()
apiObj.apiURL = armoDevBEURL
apiObj.authURL = armoDevAUTHURL
apiObj.erURL = armoDevERURL
apiObj.feURL = armoDevFEURL
return apiObj
}
func NewARMOAPIProd() *ArmoAPI {
apiObj := newArmoAPI()
apiObj.apiURL = armoBEURL
apiObj.erURL = armoERURL
apiObj.feURL = armoFEURL
apiObj.authURL = armoAUTHURL
return apiObj
}
func NewARMOAPIStaging() *ArmoAPI {
apiObj := newArmoAPI()
apiObj.apiURL = armoStageBEURL
apiObj.erURL = armoStageERURL
apiObj.feURL = armoStageFEURL
apiObj.authURL = armoStageAUTHURL
return apiObj
}
func NewARMOAPICustomized(armoERURL, armoBEURL, armoFEURL, armoAUTHURL string) *ArmoAPI {
apiObj := newArmoAPI()
apiObj.erURL = armoERURL
apiObj.apiURL = armoBEURL
apiObj.feURL = armoFEURL
apiObj.authURL = armoAUTHURL
return apiObj
}
func newArmoAPI() *ArmoAPI {
return &ArmoAPI{
httpClient: &http.Client{Timeout: time.Duration(61) * time.Second},
loggedIn: false,
}
}
func (armoAPI *ArmoAPI) Post(fullURL string, headers map[string]string, body []byte) (string, error) {
if headers == nil {
headers = make(map[string]string)
}
armoAPI.appendAuthHeaders(headers)
return HttpPost(armoAPI.httpClient, fullURL, headers, body)
}
func (armoAPI *ArmoAPI) Delete(fullURL string, headers map[string]string) (string, error) {
if headers == nil {
headers = make(map[string]string)
}
armoAPI.appendAuthHeaders(headers)
return HttpDelete(armoAPI.httpClient, fullURL, headers)
}
func (armoAPI *ArmoAPI) Get(fullURL string, headers map[string]string) (string, error) {
if headers == nil {
headers = make(map[string]string)
}
armoAPI.appendAuthHeaders(headers)
return HttpGetter(armoAPI.httpClient, fullURL, headers)
}
func (armoAPI *ArmoAPI) GetAccountID() string { return armoAPI.accountID }
func (armoAPI *ArmoAPI) IsLoggedIn() bool { return armoAPI.loggedIn }
func (armoAPI *ArmoAPI) GetClientID() string { return armoAPI.clientID }
func (armoAPI *ArmoAPI) GetSecretKey() string { return armoAPI.secretKey }
func (armoAPI *ArmoAPI) GetFrontendURL() string { return armoAPI.feURL }
func (armoAPI *ArmoAPI) GetAPIURL() string { return armoAPI.apiURL }
func (armoAPI *ArmoAPI) GetReportReceiverURL() string { return armoAPI.erURL }
func (armoAPI *ArmoAPI) SetAccountID(accountID string) { armoAPI.accountID = accountID }
func (armoAPI *ArmoAPI) SetClientID(clientID string) { armoAPI.clientID = clientID }
func (armoAPI *ArmoAPI) SetSecretKey(secretKey string) { armoAPI.secretKey = secretKey }
func (armoAPI *ArmoAPI) GetFramework(name string) (*reporthandling.Framework, error) {
respStr, err := armoAPI.Get(armoAPI.getFrameworkURL(name), nil)
if err != nil {
return nil, nil
}
framework := &reporthandling.Framework{}
if err = JSONDecoder(respStr).Decode(framework); err != nil {
return nil, err
}
SaveInFile(framework, GetDefaultPath(name+".json"))
return framework, err
}
func (armoAPI *ArmoAPI) GetFrameworks() ([]reporthandling.Framework, error) {
respStr, err := armoAPI.Get(armoAPI.getListFrameworkURL(), nil)
if err != nil {
return nil, nil
}
frameworks := []reporthandling.Framework{}
if err = JSONDecoder(respStr).Decode(&frameworks); err != nil {
return nil, err
}
// SaveInFile(framework, GetDefaultPath(name+".json"))
return frameworks, err
}
func (armoAPI *ArmoAPI) GetControl(policyName string) (*reporthandling.Control, error) {
return nil, fmt.Errorf("control api is not public")
}
func (armoAPI *ArmoAPI) GetExceptions(clusterName string) ([]armotypes.PostureExceptionPolicy, error) {
exceptions := []armotypes.PostureExceptionPolicy{}
respStr, err := armoAPI.Get(armoAPI.getExceptionsURL(clusterName), nil)
if err != nil {
return nil, err
}
if err = JSONDecoder(respStr).Decode(&exceptions); err != nil {
return nil, err
}
return exceptions, nil
}
func (armoAPI *ArmoAPI) GetTenant() (*TenantResponse, error) {
url := armoAPI.getAccountURL()
if armoAPI.accountID != "" {
url = fmt.Sprintf("%s?customerGUID=%s", url, armoAPI.accountID)
}
respStr, err := armoAPI.Get(url, nil)
if err != nil {
return nil, err
}
tenant := &TenantResponse{}
if err = JSONDecoder(respStr).Decode(tenant); err != nil {
return nil, err
}
if tenant.TenantID != "" {
armoAPI.accountID = tenant.TenantID
}
return tenant, nil
}
// ControlsInputs // map[<control name>][<input arguments>]
func (armoAPI *ArmoAPI) GetAccountConfig(clusterName string) (*armotypes.CustomerConfig, error) {
accountConfig := &armotypes.CustomerConfig{}
if armoAPI.accountID == "" {
return accountConfig, nil
}
respStr, err := armoAPI.Get(armoAPI.getAccountConfig(clusterName), nil)
if err != nil {
return nil, err
}
if err = JSONDecoder(respStr).Decode(&accountConfig); err != nil {
return nil, err
}
return accountConfig, nil
}
// ControlsInputs // map[<control name>][<input arguments>]
func (armoAPI *ArmoAPI) GetControlsInputs(clusterName string) (map[string][]string, error) {
accountConfig, err := armoAPI.GetAccountConfig(clusterName)
if err == nil {
return accountConfig.Settings.PostureControlInputs, nil
}
return nil, err
}
func (armoAPI *ArmoAPI) ListCustomFrameworks() ([]string, error) {
respStr, err := armoAPI.Get(armoAPI.getListFrameworkURL(), nil)
if err != nil {
return nil, err
}
frs := []reporthandling.Framework{}
if err = json.Unmarshal([]byte(respStr), &frs); err != nil {
return nil, err
}
frameworkList := []string{}
for _, fr := range frs {
if !isNativeFramework(fr.Name) {
frameworkList = append(frameworkList, fr.Name)
}
}
return frameworkList, nil
}
func (armoAPI *ArmoAPI) ListFrameworks() ([]string, error) {
respStr, err := armoAPI.Get(armoAPI.getListFrameworkURL(), nil)
if err != nil {
return nil, err
}
frs := []reporthandling.Framework{}
if err = json.Unmarshal([]byte(respStr), &frs); err != nil {
return nil, err
}
frameworkList := []string{}
for _, fr := range frs {
if isNativeFramework(fr.Name) {
frameworkList = append(frameworkList, strings.ToLower(fr.Name))
} else {
frameworkList = append(frameworkList, fr.Name)
}
}
return frameworkList, nil
}
func (armoAPI *ArmoAPI) ListControls(l ListType) ([]string, error) {
return nil, fmt.Errorf("control api is not public")
}
func (armoAPI *ArmoAPI) PostExceptions(exceptions []armotypes.PostureExceptionPolicy) error {
for i := range exceptions {
ex, err := json.Marshal(exceptions[i])
if err != nil {
return err
}
_, err = armoAPI.Post(armoAPI.exceptionsURL(""), map[string]string{"Content-Type": "application/json"}, ex)
if err != nil {
return err
}
}
return nil
}
func (armoAPI *ArmoAPI) DeleteException(exceptionName string) error {
_, err := armoAPI.Delete(armoAPI.exceptionsURL(exceptionName), nil)
if err != nil {
return err
}
return nil
}
func (armoAPI *ArmoAPI) Login() error {
if armoAPI.accountID == "" {
return fmt.Errorf("failed to login, missing accountID")
}
if armoAPI.clientID == "" {
return fmt.Errorf("failed to login, missing clientID")
}
if armoAPI.secretKey == "" {
return fmt.Errorf("failed to login, missing secretKey")
}
// init URLs
feLoginData := FeLoginData{ClientId: armoAPI.clientID, Secret: armoAPI.secretKey}
body, _ := json.Marshal(feLoginData)
resp, err := http.Post(armoAPI.getApiToken(), "application/json", bytes.NewBuffer(body))
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("error authenticating: %d", resp.StatusCode)
}
responseBody, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
var feLoginResponse FeLoginResponse
if err = json.Unmarshal(responseBody, &feLoginResponse); err != nil {
return err
}
armoAPI.feToken = feLoginResponse
/* Now we have JWT */
armoAPI.authCookie, err = armoAPI.getAuthCookie()
if err != nil {
return err
}
armoAPI.loggedIn = true
return nil
}

View File

@@ -1,169 +0,0 @@
package getter
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"net/url"
"strings"
)
var NativeFrameworks = []string{"nsa", "mitre", "armobest", "devopsbest"}
func (armoAPI *ArmoAPI) getFrameworkURL(frameworkName string) string {
u := url.URL{}
u.Scheme = "https"
u.Host = armoAPI.apiURL
u.Path = "api/v1/armoFrameworks"
q := u.Query()
q.Add("customerGUID", armoAPI.getCustomerGUIDFallBack())
if isNativeFramework(frameworkName) {
q.Add("frameworkName", strings.ToUpper(frameworkName))
} else {
// For customer framework has to be the way it was added
q.Add("frameworkName", frameworkName)
}
u.RawQuery = q.Encode()
return u.String()
}
func (armoAPI *ArmoAPI) getListFrameworkURL() string {
u := url.URL{}
u.Scheme = "https"
u.Host = armoAPI.apiURL
u.Path = "api/v1/armoFrameworks"
q := u.Query()
q.Add("customerGUID", armoAPI.getCustomerGUIDFallBack())
u.RawQuery = q.Encode()
return u.String()
}
func (armoAPI *ArmoAPI) getExceptionsURL(clusterName string) string {
u := url.URL{}
u.Scheme = "https"
u.Host = armoAPI.apiURL
u.Path = "api/v1/armoPostureExceptions"
q := u.Query()
q.Add("customerGUID", armoAPI.getCustomerGUIDFallBack())
// if clusterName != "" { // TODO - fix customer name support in Armo BE
// q.Add("clusterName", clusterName)
// }
u.RawQuery = q.Encode()
return u.String()
}
func (armoAPI *ArmoAPI) exceptionsURL(exceptionsPolicyName string) string {
u := url.URL{}
u.Scheme = "https"
u.Host = armoAPI.apiURL
u.Path = "api/v1/postureExceptionPolicy"
q := u.Query()
q.Add("customerGUID", armoAPI.getCustomerGUIDFallBack())
if exceptionsPolicyName != "" { // for delete
q.Add("policyName", exceptionsPolicyName)
}
u.RawQuery = q.Encode()
return u.String()
}
func (armoAPI *ArmoAPI) getAccountConfig(clusterName string) string {
u := url.URL{}
u.Scheme = "https"
u.Host = armoAPI.apiURL
u.Path = "api/v1/armoCustomerConfiguration"
q := u.Query()
q.Add("customerGUID", armoAPI.getCustomerGUIDFallBack())
if clusterName != "" { // TODO - fix customer name support in Armo BE
q.Add("clusterName", clusterName)
}
u.RawQuery = q.Encode()
return u.String()
}
func (armoAPI *ArmoAPI) getAccountURL() string {
u := url.URL{}
u.Scheme = "https"
u.Host = armoAPI.apiURL
u.Path = "api/v1/createTenant"
return u.String()
}
func (armoAPI *ArmoAPI) getApiToken() string {
u := url.URL{}
u.Scheme = "https"
u.Host = armoAPI.authURL
u.Path = "frontegg/identity/resources/auth/v1/api-token"
return u.String()
}
func (armoAPI *ArmoAPI) getOpenidCustomers() string {
u := url.URL{}
u.Scheme = "https"
u.Host = armoAPI.apiURL
u.Path = "api/v1/openid_customers"
return u.String()
}
func (armoAPI *ArmoAPI) getAuthCookie() (string, error) {
selectCustomer := ArmoSelectCustomer{SelectedCustomerGuid: armoAPI.accountID}
requestBody, _ := json.Marshal(selectCustomer)
client := &http.Client{}
httpRequest, err := http.NewRequest(http.MethodPost, armoAPI.getOpenidCustomers(), bytes.NewBuffer(requestBody))
if err != nil {
return "", err
}
httpRequest.Header.Set("Content-Type", "application/json")
httpRequest.Header.Set("Authorization", fmt.Sprintf("Bearer %s", armoAPI.feToken.Token))
httpResponse, err := client.Do(httpRequest)
if err != nil {
return "", err
}
defer httpResponse.Body.Close()
if httpResponse.StatusCode != http.StatusOK {
return "", fmt.Errorf("failed to get cookie from %s: status %d", armoAPI.getOpenidCustomers(), httpResponse.StatusCode)
}
cookies := httpResponse.Header.Get("set-cookie")
if len(cookies) == 0 {
return "", fmt.Errorf("no cookie field in response from %s", armoAPI.getOpenidCustomers())
}
authCookie := ""
for _, cookie := range strings.Split(cookies, ";") {
kv := strings.Split(cookie, "=")
if kv[0] == "auth" {
authCookie = kv[1]
}
}
if len(authCookie) == 0 {
return "", fmt.Errorf("no auth cookie field in response from %s", armoAPI.getOpenidCustomers())
}
return authCookie, nil
}
func (armoAPI *ArmoAPI) appendAuthHeaders(headers map[string]string) {
if armoAPI.feToken.Token != "" {
headers["Authorization"] = fmt.Sprintf("Bearer %s", armoAPI.feToken.Token)
}
if armoAPI.authCookie != "" {
headers["Cookie"] = fmt.Sprintf("auth=%s", armoAPI.authCookie)
}
}
func (armoAPI *ArmoAPI) getCustomerGUIDFallBack() string {
if armoAPI.accountID != "" {
return armoAPI.accountID
}
return "11111111-1111-1111-1111-111111111111"
}

View File

@@ -8,11 +8,11 @@ type FeLoginData struct {
type FeLoginResponse struct {
Token string `json:"accessToken"`
RefreshToken string `json:"refreshToken"`
ExpiresIn int32 `json:"expiresIn"`
Expires string `json:"expires"`
ExpiresIn int32 `json:"expiresIn"`
}
type ArmoSelectCustomer struct {
type KSCloudSelectCustomer struct {
SelectedCustomerGuid string `json:"selectedCustomer"`
}

View File

@@ -1,10 +1,13 @@
package getter
import (
"fmt"
"strings"
"github.com/armosec/opa-utils/gitregostore"
"github.com/armosec/opa-utils/reporthandling"
"github.com/armosec/armoapi-go/armotypes"
"github.com/kubescape/opa-utils/gitregostore"
"github.com/kubescape/opa-utils/reporthandling"
"github.com/kubescape/opa-utils/reporthandling/attacktrack/v1alpha1"
)
// =======================================================================================================================
@@ -22,11 +25,11 @@ func NewDownloadReleasedPolicy() *DownloadReleasedPolicy {
}
}
func (drp *DownloadReleasedPolicy) GetControl(policyName string) (*reporthandling.Control, error) {
func (drp *DownloadReleasedPolicy) GetControl(ID string) (*reporthandling.Control, error) {
var control *reporthandling.Control
var err error
control, err = drp.gs.GetOPAControl(policyName)
control, err = drp.gs.GetOPAControlByID(ID)
if err != nil {
return nil, err
}
@@ -53,13 +56,29 @@ func (drp *DownloadReleasedPolicy) ListFrameworks() ([]string, error) {
return drp.gs.GetOPAFrameworksNamesList()
}
func (drp *DownloadReleasedPolicy) ListControls(listType ListType) ([]string, error) {
switch listType {
case ListID:
return drp.gs.GetOPAControlsIDsList()
default:
return drp.gs.GetOPAControlsNamesList()
func (drp *DownloadReleasedPolicy) ListControls() ([]string, error) {
controlsIDsList, err := drp.gs.GetOPAControlsIDsList()
if err != nil {
return []string{}, err
}
controlsNamesList, err := drp.gs.GetOPAControlsNamesList()
if err != nil {
return []string{}, err
}
controls, err := drp.gs.GetOPAControls()
if err != nil {
return []string{}, err
}
var controlsFrameworksList [][]string
for _, control := range controls {
controlsFrameworksList = append(controlsFrameworksList, control.FrameworkNames)
}
controlsNamesWithIDsandFrameworksList := make([]string, len(controlsIDsList))
// by design all slices have the same lengt
for i := range controlsIDsList {
controlsNamesWithIDsandFrameworksList[i] = fmt.Sprintf("%v|%v|%v", controlsIDsList[i], controlsNamesList[i], strings.Join(controlsFrameworksList[i], ","))
}
return controlsNamesWithIDsandFrameworksList, nil
}
func (drp *DownloadReleasedPolicy) GetControlsInputs(clusterName string) (map[string][]string, error) {
@@ -70,6 +89,14 @@ func (drp *DownloadReleasedPolicy) GetControlsInputs(clusterName string) (map[st
return defaultConfigInputs.Settings.PostureControlInputs, err
}
func (drp *DownloadReleasedPolicy) GetAttackTracks() ([]v1alpha1.AttackTrack, error) {
attackTracks, err := drp.gs.GetAttackTracks()
if err != nil {
return nil, err
}
return attackTracks, err
}
func (drp *DownloadReleasedPolicy) SetRegoObjects() error {
fwNames, err := drp.gs.GetOPAFrameworksNamesList()
if len(fwNames) != 0 && err == nil {
@@ -90,3 +117,11 @@ func contains(s []string, str string) bool {
}
return false
}
func (drp *DownloadReleasedPolicy) GetExceptions(clusterName string) ([]armotypes.PostureExceptionPolicy, error) {
exceptions, err := drp.gs.GetSystemPostureExceptionPolicies()
if err != nil {
return nil, err
}
return exceptions, nil
}

View File

@@ -0,0 +1,42 @@
package getter
import (
"context"
"os"
containeranalysis "cloud.google.com/go/containeranalysis/apiv1"
)
type GCPCloudAPI struct {
credentialsPath string
context context.Context
client *containeranalysis.Client
projectID string
credentialsCheck bool
}
func GetGlobalGCPCloudAPIConnector() *GCPCloudAPI {
if os.Getenv("KS_GCP_CREDENTIALS_PATH") == "" || os.Getenv("KS_GCP_PROJECT_ID") == "" {
return &GCPCloudAPI{
credentialsCheck: false,
}
} else {
return &GCPCloudAPI{
context: context.Background(),
credentialsPath: os.Getenv("KS_GCP_CREDENTIALS_PATH"),
projectID: os.Getenv("KS_GCP_PROJECT_ID"),
credentialsCheck: true,
}
}
}
func (api *GCPCloudAPI) SetClient(client *containeranalysis.Client) {
api.client = client
}
func (api *GCPCloudAPI) GetCredentialsPath() string { return api.credentialsPath }
func (api *GCPCloudAPI) GetClient() *containeranalysis.Client { return api.client }
func (api *GCPCloudAPI) GetProjectID() string { return api.projectID }
func (api *GCPCloudAPI) GetCredentialsCheck() bool { return api.credentialsCheck }
func (api *GCPCloudAPI) GetContext() context.Context { return api.context }

View File

@@ -2,22 +2,17 @@ package getter
import (
"github.com/armosec/armoapi-go/armotypes"
"github.com/armosec/opa-utils/reporthandling"
"github.com/kubescape/opa-utils/reporthandling"
"github.com/kubescape/opa-utils/reporthandling/attacktrack/v1alpha1"
)
// supported listing
type ListType string
const ListID ListType = "id"
const ListName ListType = "name"
type IPolicyGetter interface {
GetFramework(name string) (*reporthandling.Framework, error)
GetFrameworks() ([]reporthandling.Framework, error)
GetControl(name string) (*reporthandling.Control, error)
GetControl(ID string) (*reporthandling.Control, error)
ListFrameworks() ([]string, error)
ListControls(ListType) ([]string, error)
ListControls() ([]string, error)
}
type IExceptionsGetter interface {
@@ -27,10 +22,18 @@ type IBackend interface {
GetAccountID() string
GetClientID() string
GetSecretKey() string
GetCloudReportURL() string
GetCloudAPIURL() string
GetCloudUIURL() string
GetCloudAuthURL() string
SetAccountID(accountID string)
SetClientID(clientID string)
SetSecretKey(secretKey string)
SetCloudReportURL(cloudReportURL string)
SetCloudAPIURL(cloudAPIURL string)
SetCloudUIURL(cloudUIURL string)
SetCloudAuthURL(cloudAuthURL string)
GetTenant() (*TenantResponse, error)
}
@@ -38,3 +41,7 @@ type IBackend interface {
type IControlsInputsGetter interface {
GetControlsInputs(clusterName string) (map[string][]string, error)
}
type IAttackTracksGetter interface {
GetAttackTracks() ([]v1alpha1.AttackTrack, error)
}

View File

@@ -2,7 +2,6 @@ package getter
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
@@ -21,18 +20,19 @@ func SaveInFile(policy interface{}, pathStr string) error {
if err != nil {
return err
}
err = os.WriteFile(pathStr, []byte(fmt.Sprintf("%v", string(encodedData))), 0644)
err = os.WriteFile(pathStr, encodedData, 0644) //nolint:gosec
if err != nil {
if os.IsNotExist(err) {
pathDir := path.Dir(pathStr)
if err := os.Mkdir(pathDir, 0744); err != nil {
return err
// pathDir could contain subdirectories
if erm := os.MkdirAll(pathDir, 0755); erm != nil {
return erm
}
} else {
return err
}
err = os.WriteFile(pathStr, []byte(fmt.Sprintf("%v", string(encodedData))), 0644)
err = os.WriteFile(pathStr, encodedData, 0644) //nolint:gosec
if err != nil {
return err
}
@@ -40,13 +40,6 @@ func SaveInFile(policy interface{}, pathStr string) error {
return nil
}
// JSONDecoder returns JSON decoder for given string
func JSONDecoder(origin string) *json.Decoder {
dec := json.NewDecoder(strings.NewReader(origin))
dec.UseNumber()
return dec
}
func HttpDelete(httpClient *http.Client, fullURL string, headers map[string]string) (string, error) {
req, err := http.NewRequest("DELETE", fullURL, nil)
@@ -65,6 +58,7 @@ func HttpDelete(httpClient *http.Client, fullURL string, headers map[string]stri
}
return respStr, nil
}
func HttpGetter(httpClient *http.Client, fullURL string, headers map[string]string) (string, error) {
req, err := http.NewRequest("GET", fullURL, nil)

View File

@@ -0,0 +1,26 @@
package getter
import (
"strings"
stdjson "encoding/json"
jsoniter "github.com/json-iterator/go"
)
var (
json jsoniter.API
)
func init() {
// NOTE(fredbi): attention, this configuration rounds floats down to 6 digits
// For finer-grained config, see: https://pkg.go.dev/github.com/json-iterator/go#section-readme
json = jsoniter.ConfigFastest
}
// JSONDecoder returns JSON decoder for given string
func JSONDecoder(origin string) *stdjson.Decoder {
dec := stdjson.NewDecoder(strings.NewReader(origin))
dec.UseNumber()
return dec
}

View File

@@ -0,0 +1,32 @@
package getter
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestJSONDecoder(t *testing.T) {
t.Run("should decode json string", func(t *testing.T) {
const input = `"xyz"`
d := JSONDecoder(input)
var receiver string
require.NoError(t, d.Decode(&receiver))
require.Equal(t, "xyz", receiver)
})
t.Run("should decode json number", func(t *testing.T) {
const input = `123.01`
d := JSONDecoder(input)
var receiver float64
require.NoError(t, d.Decode(&receiver))
require.Equal(t, 123.01, receiver)
})
t.Run("requires json quotes", func(t *testing.T) {
const input = `xyz`
d := JSONDecoder(input)
var receiver string
require.Error(t, d.Decode(&receiver))
})
}

View File

@@ -0,0 +1,379 @@
package getter
import (
"bytes"
"fmt"
"io"
"net/http"
"strings"
"time"
"github.com/armosec/armoapi-go/armotypes"
"github.com/kubescape/opa-utils/reporthandling"
"github.com/kubescape/opa-utils/reporthandling/attacktrack/v1alpha1"
)
var (
ksCloudERURL = "report.armo.cloud"
ksCloudBEURL = "api.armosec.io"
ksCloudFEURL = "cloud.armosec.io"
ksCloudAUTHURL = "auth.armosec.io"
ksCloudStageERURL = "report-ks.eustage2.cyberarmorsoft.com"
ksCloudStageBEURL = "api-stage.armosec.io"
ksCloudStageFEURL = "armoui-stage.armosec.io"
ksCloudStageAUTHURL = "eggauth-stage.armosec.io"
ksCloudDevERURL = "report.eudev3.cyberarmorsoft.com"
ksCloudDevBEURL = "api-dev.armosec.io"
ksCloudDevFEURL = "cloud-dev.armosec.io"
ksCloudDevAUTHURL = "eggauth-dev.armosec.io"
)
// KSCloudAPI allows accessing the API of the Kubescape Cloud offering
type KSCloudAPI struct {
httpClient *http.Client
cloudAPIURL string
cloudAuthURL string
cloudReportURL string
cloudUIURL string
accountID string
clientID string
secretKey string
authCookie string
feToken FeLoginResponse
loggedIn bool
}
var globalKSCloudAPIConnector *KSCloudAPI
func SetKSCloudAPIConnector(ksCloudAPI *KSCloudAPI) {
globalKSCloudAPIConnector = ksCloudAPI
}
func GetKSCloudAPIConnector() *KSCloudAPI {
if globalKSCloudAPIConnector == nil {
SetKSCloudAPIConnector(NewKSCloudAPIProd())
}
return globalKSCloudAPIConnector
}
func NewKSCloudAPIDev() *KSCloudAPI {
apiObj := newKSCloudAPI()
apiObj.cloudAPIURL = ksCloudDevBEURL
apiObj.cloudAuthURL = ksCloudDevAUTHURL
apiObj.cloudReportURL = ksCloudDevERURL
apiObj.cloudUIURL = ksCloudDevFEURL
return apiObj
}
func NewKSCloudAPIProd() *KSCloudAPI {
apiObj := newKSCloudAPI()
apiObj.cloudAPIURL = ksCloudBEURL
apiObj.cloudReportURL = ksCloudERURL
apiObj.cloudUIURL = ksCloudFEURL
apiObj.cloudAuthURL = ksCloudAUTHURL
return apiObj
}
func NewKSCloudAPIStaging() *KSCloudAPI {
apiObj := newKSCloudAPI()
apiObj.cloudAPIURL = ksCloudStageBEURL
apiObj.cloudReportURL = ksCloudStageERURL
apiObj.cloudUIURL = ksCloudStageFEURL
apiObj.cloudAuthURL = ksCloudStageAUTHURL
return apiObj
}
func NewKSCloudAPICustomized(ksCloudERURL, ksCloudBEURL, ksCloudFEURL, ksCloudAUTHURL string) *KSCloudAPI {
apiObj := newKSCloudAPI()
apiObj.cloudReportURL = ksCloudERURL
apiObj.cloudAPIURL = ksCloudBEURL
apiObj.cloudUIURL = ksCloudFEURL
apiObj.cloudAuthURL = ksCloudAUTHURL
return apiObj
}
func newKSCloudAPI() *KSCloudAPI {
return &KSCloudAPI{
httpClient: &http.Client{Timeout: time.Duration(61) * time.Second},
loggedIn: false,
}
}
func (api *KSCloudAPI) Post(fullURL string, headers map[string]string, body []byte) (string, error) {
if headers == nil {
headers = make(map[string]string)
}
api.appendAuthHeaders(headers)
return HttpPost(api.httpClient, fullURL, headers, body)
}
func (api *KSCloudAPI) Delete(fullURL string, headers map[string]string) (string, error) {
if headers == nil {
headers = make(map[string]string)
}
api.appendAuthHeaders(headers)
return HttpDelete(api.httpClient, fullURL, headers)
}
func (api *KSCloudAPI) Get(fullURL string, headers map[string]string) (string, error) {
if headers == nil {
headers = make(map[string]string)
}
api.appendAuthHeaders(headers)
return HttpGetter(api.httpClient, fullURL, headers)
}
func (api *KSCloudAPI) GetAccountID() string { return api.accountID }
func (api *KSCloudAPI) IsLoggedIn() bool { return api.loggedIn }
func (api *KSCloudAPI) GetClientID() string { return api.clientID }
func (api *KSCloudAPI) GetSecretKey() string { return api.secretKey }
func (api *KSCloudAPI) GetCloudReportURL() string { return api.cloudReportURL }
func (api *KSCloudAPI) GetCloudAPIURL() string { return api.cloudAPIURL }
func (api *KSCloudAPI) GetCloudUIURL() string { return api.cloudUIURL }
func (api *KSCloudAPI) GetCloudAuthURL() string { return api.cloudAuthURL }
func (api *KSCloudAPI) SetAccountID(accountID string) { api.accountID = accountID }
func (api *KSCloudAPI) SetClientID(clientID string) { api.clientID = clientID }
func (api *KSCloudAPI) SetSecretKey(secretKey string) { api.secretKey = secretKey }
func (api *KSCloudAPI) SetCloudReportURL(cloudReportURL string) { api.cloudReportURL = cloudReportURL }
func (api *KSCloudAPI) SetCloudAPIURL(cloudAPIURL string) { api.cloudAPIURL = cloudAPIURL }
func (api *KSCloudAPI) SetCloudUIURL(cloudUIURL string) { api.cloudUIURL = cloudUIURL }
func (api *KSCloudAPI) SetCloudAuthURL(cloudAuthURL string) { api.cloudAuthURL = cloudAuthURL }
func (api *KSCloudAPI) GetAttackTracks() ([]v1alpha1.AttackTrack, error) {
respStr, err := api.Get(api.getAttackTracksURL(), nil)
if err != nil {
return nil, nil
}
attackTracks := []v1alpha1.AttackTrack{}
if err = JSONDecoder(respStr).Decode(&attackTracks); err != nil {
return nil, err
}
return attackTracks, err
}
func (api *KSCloudAPI) GetFramework(name string) (*reporthandling.Framework, error) {
respStr, err := api.Get(api.getFrameworkURL(name), nil)
if err != nil {
return nil, nil
}
framework := &reporthandling.Framework{}
if err = JSONDecoder(respStr).Decode(framework); err != nil {
return nil, err
}
return framework, err
}
func (api *KSCloudAPI) GetFrameworks() ([]reporthandling.Framework, error) {
respStr, err := api.Get(api.getListFrameworkURL(), nil)
if err != nil {
return nil, nil
}
frameworks := []reporthandling.Framework{}
if err = JSONDecoder(respStr).Decode(&frameworks); err != nil {
return nil, err
}
return frameworks, err
}
func (api *KSCloudAPI) GetControl(ID string) (*reporthandling.Control, error) {
return nil, fmt.Errorf("control api is not public")
}
func (api *KSCloudAPI) GetExceptions(clusterName string) ([]armotypes.PostureExceptionPolicy, error) {
exceptions := []armotypes.PostureExceptionPolicy{}
respStr, err := api.Get(api.getExceptionsURL(clusterName), nil)
if err != nil {
return nil, err
}
if err = JSONDecoder(respStr).Decode(&exceptions); err != nil {
return nil, err
}
return exceptions, nil
}
func (api *KSCloudAPI) GetTenant() (*TenantResponse, error) {
url := api.getAccountURL()
if api.accountID != "" {
url = fmt.Sprintf("%s?customerGUID=%s", url, api.accountID)
}
respStr, err := api.Get(url, nil)
if err != nil {
return nil, err
}
tenant := &TenantResponse{}
if err = JSONDecoder(respStr).Decode(tenant); err != nil {
return nil, err
}
if tenant.TenantID != "" {
api.accountID = tenant.TenantID
}
return tenant, nil
}
// ControlsInputs // map[<control name>][<input arguments>]
func (api *KSCloudAPI) GetAccountConfig(clusterName string) (*armotypes.CustomerConfig, error) {
accountConfig := &armotypes.CustomerConfig{}
if api.accountID == "" {
return accountConfig, nil
}
respStr, err := api.Get(api.getAccountConfig(clusterName), nil)
if err != nil {
return nil, err
}
if err = JSONDecoder(respStr).Decode(&accountConfig); err != nil {
// try with default scope
respStr, err = api.Get(api.getAccountConfigDefault(clusterName), nil)
if err != nil {
return nil, err
}
if err = JSONDecoder(respStr).Decode(&accountConfig); err != nil {
return nil, err
}
}
return accountConfig, nil
}
// ControlsInputs // map[<control name>][<input arguments>]
func (api *KSCloudAPI) GetControlsInputs(clusterName string) (map[string][]string, error) {
accountConfig, err := api.GetAccountConfig(clusterName)
if err == nil {
return accountConfig.Settings.PostureControlInputs, nil
}
return nil, err
}
func (api *KSCloudAPI) ListCustomFrameworks() ([]string, error) {
respStr, err := api.Get(api.getListFrameworkURL(), nil)
if err != nil {
return nil, err
}
frs := []reporthandling.Framework{}
if err = json.Unmarshal([]byte(respStr), &frs); err != nil {
return nil, err
}
frameworkList := []string{}
for _, fr := range frs {
if !isNativeFramework(fr.Name) {
frameworkList = append(frameworkList, fr.Name)
}
}
return frameworkList, nil
}
func (api *KSCloudAPI) ListFrameworks() ([]string, error) {
respStr, err := api.Get(api.getListFrameworkURL(), nil)
if err != nil {
return nil, err
}
frs := []reporthandling.Framework{}
if err = json.Unmarshal([]byte(respStr), &frs); err != nil {
return nil, err
}
frameworkList := []string{}
for _, fr := range frs {
if isNativeFramework(fr.Name) {
frameworkList = append(frameworkList, strings.ToLower(fr.Name))
} else {
frameworkList = append(frameworkList, fr.Name)
}
}
return frameworkList, nil
}
func (api *KSCloudAPI) ListControls() ([]string, error) {
return nil, fmt.Errorf("control api is not public")
}
func (api *KSCloudAPI) PostExceptions(exceptions []armotypes.PostureExceptionPolicy) error {
for i := range exceptions {
ex, err := json.Marshal(exceptions[i])
if err != nil {
return err
}
_, err = api.Post(api.exceptionsURL(""), map[string]string{"Content-Type": "application/json"}, ex)
if err != nil {
return err
}
}
return nil
}
func (api *KSCloudAPI) DeleteException(exceptionName string) error {
_, err := api.Delete(api.exceptionsURL(exceptionName), nil)
if err != nil {
return err
}
return nil
}
func (api *KSCloudAPI) Login() error {
if api.accountID == "" {
return fmt.Errorf("failed to login, missing accountID")
}
if api.clientID == "" {
return fmt.Errorf("failed to login, missing clientID")
}
if api.secretKey == "" {
return fmt.Errorf("failed to login, missing secretKey")
}
// init URLs
feLoginData := FeLoginData{ClientId: api.clientID, Secret: api.secretKey}
body, _ := json.Marshal(feLoginData)
resp, err := http.Post(api.getApiToken(), "application/json", bytes.NewBuffer(body))
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("error authenticating: %d", resp.StatusCode)
}
responseBody, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
var feLoginResponse FeLoginResponse
if err = json.Unmarshal(responseBody, &feLoginResponse); err != nil {
return err
}
api.feToken = feLoginResponse
/* Now we have JWT */
api.authCookie, err = api.getAuthCookie()
if err != nil {
return err
}
api.loggedIn = true
return nil
}

View File

@@ -0,0 +1,186 @@
package getter
import (
"bytes"
"fmt"
"net/http"
"net/url"
"strings"
)
var NativeFrameworks = []string{"nsa", "mitre", "armobest", "devopsbest"}
func (api *KSCloudAPI) getFrameworkURL(frameworkName string) string {
u := url.URL{}
u.Scheme, u.Host = parseHost(api.GetCloudAPIURL())
u.Path = "api/v1/armoFrameworks"
q := u.Query()
q.Add("customerGUID", api.getCustomerGUIDFallBack())
if isNativeFramework(frameworkName) {
q.Add("frameworkName", strings.ToUpper(frameworkName))
} else {
// For customer framework has to be the way it was added
q.Add("frameworkName", frameworkName)
}
u.RawQuery = q.Encode()
return u.String()
}
func (api *KSCloudAPI) getAttackTracksURL() string {
u := url.URL{}
u.Scheme, u.Host = parseHost(api.GetCloudAPIURL())
u.Path = "api/v1/attackTracks"
q := u.Query()
q.Add("customerGUID", api.getCustomerGUIDFallBack())
u.RawQuery = q.Encode()
return u.String()
}
func (api *KSCloudAPI) getListFrameworkURL() string {
u := url.URL{}
u.Scheme, u.Host = parseHost(api.GetCloudAPIURL())
u.Path = "api/v1/armoFrameworks"
q := u.Query()
q.Add("customerGUID", api.getCustomerGUIDFallBack())
u.RawQuery = q.Encode()
return u.String()
}
func (api *KSCloudAPI) getExceptionsURL(clusterName string) string {
u := url.URL{}
u.Scheme, u.Host = parseHost(api.GetCloudAPIURL())
u.Path = "api/v1/armoPostureExceptions"
q := u.Query()
q.Add("customerGUID", api.getCustomerGUIDFallBack())
// if clusterName != "" { // TODO - fix customer name support in Armo BE
// q.Add("clusterName", clusterName)
// }
u.RawQuery = q.Encode()
return u.String()
}
func (api *KSCloudAPI) exceptionsURL(exceptionsPolicyName string) string {
u := url.URL{}
u.Scheme, u.Host = parseHost(api.GetCloudAPIURL())
u.Path = "api/v1/postureExceptionPolicy"
q := u.Query()
q.Add("customerGUID", api.getCustomerGUIDFallBack())
if exceptionsPolicyName != "" { // for delete
q.Add("policyName", exceptionsPolicyName)
}
u.RawQuery = q.Encode()
return u.String()
}
func (api *KSCloudAPI) getAccountConfigDefault(clusterName string) string {
config := api.getAccountConfig(clusterName)
url := config + "&scope=customer"
return url
}
func (api *KSCloudAPI) getAccountConfig(clusterName string) string {
u := url.URL{}
u.Scheme, u.Host = parseHost(api.GetCloudAPIURL())
u.Path = "api/v1/armoCustomerConfiguration"
q := u.Query()
q.Add("customerGUID", api.getCustomerGUIDFallBack())
if clusterName != "" { // TODO - fix customer name support in Armo BE
q.Add("clusterName", clusterName)
}
u.RawQuery = q.Encode()
return u.String()
}
func (api *KSCloudAPI) getAccountURL() string {
u := url.URL{}
u.Scheme, u.Host = parseHost(api.GetCloudAPIURL())
u.Path = "api/v1/createTenant"
return u.String()
}
func (api *KSCloudAPI) getApiToken() string {
u := url.URL{}
u.Scheme, u.Host = parseHost(api.GetCloudAuthURL())
u.Path = "identity/resources/auth/v1/api-token"
return u.String()
}
func (api *KSCloudAPI) getOpenidCustomers() string {
u := url.URL{}
u.Scheme, u.Host = parseHost(api.GetCloudAPIURL())
u.Path = "api/v1/openid_customers"
return u.String()
}
func (api *KSCloudAPI) getAuthCookie() (string, error) {
selectCustomer := KSCloudSelectCustomer{SelectedCustomerGuid: api.accountID}
requestBody, _ := json.Marshal(selectCustomer)
client := &http.Client{}
httpRequest, err := http.NewRequest(http.MethodPost, api.getOpenidCustomers(), bytes.NewBuffer(requestBody))
if err != nil {
return "", err
}
httpRequest.Header.Set("Content-Type", "application/json")
httpRequest.Header.Set("Authorization", fmt.Sprintf("Bearer %s", api.feToken.Token))
httpResponse, err := client.Do(httpRequest)
if err != nil {
return "", err
}
defer httpResponse.Body.Close()
if httpResponse.StatusCode != http.StatusOK {
return "", fmt.Errorf("failed to get cookie from %s: status %d", api.getOpenidCustomers(), httpResponse.StatusCode)
}
cookies := httpResponse.Header.Get("set-cookie")
if len(cookies) == 0 {
return "", fmt.Errorf("no cookie field in response from %s", api.getOpenidCustomers())
}
authCookie := ""
for _, cookie := range strings.Split(cookies, ";") {
kv := strings.Split(cookie, "=")
if kv[0] == "auth" {
authCookie = kv[1]
}
}
if len(authCookie) == 0 {
return "", fmt.Errorf("no auth cookie field in response from %s", api.getOpenidCustomers())
}
return authCookie, nil
}
func (api *KSCloudAPI) appendAuthHeaders(headers map[string]string) {
if api.feToken.Token != "" {
headers["Authorization"] = fmt.Sprintf("Bearer %s", api.feToken.Token)
}
if api.authCookie != "" {
headers["Cookie"] = fmt.Sprintf("auth=%s", api.authCookie)
}
}
func (api *KSCloudAPI) getCustomerGUIDFallBack() string {
if api.accountID != "" {
return api.accountID
}
return "11111111-1111-1111-1111-111111111111"
}
func parseHost(host string) (string, string) {
if strings.HasPrefix(host, "http://") {
return "http", strings.Replace(host, "http://", "", 1)
}
// default scheme
return "https", strings.Replace(host, "https://", "", 1)
}

View File

@@ -1,20 +1,33 @@
package getter
import (
"encoding/json"
"errors"
"fmt"
"os"
"path/filepath"
"strings"
"github.com/armosec/armoapi-go/armotypes"
"github.com/armosec/opa-utils/reporthandling"
"github.com/kubescape/opa-utils/reporthandling"
"github.com/kubescape/opa-utils/reporthandling/attacktrack/v1alpha1"
)
// =======================================================================================================================
// ============================================== LoadPolicy =============================================================
// =======================================================================================================================
var DefaultLocalStore = getCacheDir()
var (
DefaultLocalStore = getCacheDir()
ErrNotImplemented = errors.New("feature is currently not supported")
ErrNotFound = errors.New("name not found")
ErrNameRequired = errors.New("missing required input framework name")
ErrIDRequired = errors.New("missing required input control ID")
ErrFrameworkNotMatching = errors.New("framework from file not matching")
ErrControlNotMatching = errors.New("framework from file not matching")
_ IPolicyGetter = &LoadPolicy{}
_ IExceptionsGetter = &LoadPolicy{}
)
func getCacheDir() string {
defaultDirPath := ".kubescape"
@@ -24,120 +37,225 @@ func getCacheDir() string {
return defaultDirPath
}
// Load policies from a local repository
// LoadPolicy loads policies from a local repository.
type LoadPolicy struct {
filePaths []string
}
// NewLoadPolicy builds a LoadPolicy.
func NewLoadPolicy(filePaths []string) *LoadPolicy {
return &LoadPolicy{
filePaths: filePaths,
}
}
// Return control from file
func (lp *LoadPolicy) GetControl(controlName string) (*reporthandling.Control, error) {
// GetControl returns a control from the policy file.
func (lp *LoadPolicy) GetControl(controlID string) (*reporthandling.Control, error) {
if controlID == "" {
return nil, ErrIDRequired
}
control := &reporthandling.Control{}
// NOTE: this assumes that only the first path contains either a valid control descriptor or a framework descriptor
filePath := lp.filePath()
f, err := os.ReadFile(filePath)
buf, err := os.ReadFile(filePath)
if err != nil {
return nil, err
}
if err = json.Unmarshal(f, control); err != nil {
return control, err
// check if the file is a control descriptor: a ControlID field is populated.
var control reporthandling.Control
if err = json.Unmarshal(buf, &control); err == nil && control.ControlID != "" {
if strings.EqualFold(controlID, control.ControlID) {
return &control, nil
}
return nil, fmt.Errorf("controlID: %s: %w", controlID, ErrControlNotMatching)
}
if controlName != "" && !strings.EqualFold(controlName, control.Name) && !strings.EqualFold(controlName, control.ControlID) {
framework, err := lp.GetFramework(control.Name)
if err != nil {
return nil, fmt.Errorf("control from file not matching")
} else {
for _, ctrl := range framework.Controls {
if strings.EqualFold(ctrl.Name, controlName) || strings.EqualFold(ctrl.ControlID, controlName) {
control = &ctrl
break
}
}
// check if the file is a framework descriptor
var framework reporthandling.Framework
if err = json.Unmarshal(buf, &framework); err != nil {
return nil, err
}
for _, toPin := range framework.Controls {
ctrl := toPin
if strings.EqualFold(ctrl.ControlID, controlID) {
return &ctrl, nil
}
}
return control, err
return nil, fmt.Errorf("controlID: %s: %w", controlID, ErrControlNotMatching)
}
// GetFramework retrieves a framework configuration from the policy paths.
func (lp *LoadPolicy) GetFramework(frameworkName string) (*reporthandling.Framework, error) {
framework := &reporthandling.Framework{}
var err error
if frameworkName == "" {
return nil, ErrNameRequired
}
for _, filePath := range lp.filePaths {
f, err := os.ReadFile(filePath)
buf, err := os.ReadFile(filePath)
if err != nil {
return nil, err
}
if err = json.Unmarshal(f, framework); err != nil {
return framework, err
var framework reporthandling.Framework
if err = json.Unmarshal(buf, &framework); err != nil {
return nil, err
}
if strings.EqualFold(frameworkName, framework.Name) {
break
return &framework, nil
}
}
if frameworkName != "" && !strings.EqualFold(frameworkName, framework.Name) {
return nil, fmt.Errorf("framework from file not matching")
}
return framework, err
return nil, fmt.Errorf("framework: %s: %w", frameworkName, ErrFrameworkNotMatching)
}
// GetFrameworks returns all configured framework descriptors.
func (lp *LoadPolicy) GetFrameworks() ([]reporthandling.Framework, error) {
frameworks := []reporthandling.Framework{}
var err error
return frameworks, err
}
frameworks := make([]reporthandling.Framework, 0, 10)
seenFws := make(map[string]struct{})
func (lp *LoadPolicy) ListFrameworks() ([]string, error) {
fwNames := []string{}
framework := &reporthandling.Framework{}
for _, f := range lp.filePaths {
file, err := os.ReadFile(f)
if err == nil {
if err := json.Unmarshal(file, framework); err == nil {
if !contains(fwNames, framework.Name) {
fwNames = append(fwNames, framework.Name)
}
}
buf, err := os.ReadFile(f)
if err != nil {
return nil, err
}
var framework reporthandling.Framework
if err = json.Unmarshal(buf, &framework); err != nil {
// ignore invalid framework files
continue
}
// dedupe
_, alreadyLoaded := seenFws[framework.Name]
if alreadyLoaded {
continue
}
seenFws[framework.Name] = struct{}{}
frameworks = append(frameworks, framework)
}
return fwNames, nil
return frameworks, nil
}
func (lp *LoadPolicy) ListControls(listType ListType) ([]string, error) {
// TODO - Support
return []string{}, fmt.Errorf("loading controls list from file is not supported")
// ListFrameworks lists the names of all configured frameworks in this policy.
func (lp *LoadPolicy) ListFrameworks() ([]string, error) {
frameworkNames := make([]string, 0, 10)
for _, f := range lp.filePaths {
buf, err := os.ReadFile(f)
if err != nil {
return nil, err
}
var framework reporthandling.Framework
if err := json.Unmarshal(buf, &framework); err != nil {
continue
}
if framework.Name == "" || contains(frameworkNames, framework.Name) {
continue
}
frameworkNames = append(frameworkNames, framework.Name)
}
return frameworkNames, nil
}
func (lp *LoadPolicy) GetExceptions(clusterName string) ([]armotypes.PostureExceptionPolicy, error) {
// ListControls returns the list of controls for this framework.
//
// At this moment, controls are listed for one single configured framework.
func (lp *LoadPolicy) ListControls() ([]string, error) {
controlIDs := make([]string, 0, 100)
filePath := lp.filePath()
exception := []armotypes.PostureExceptionPolicy{}
f, err := os.ReadFile(filePath)
buf, err := os.ReadFile(filePath)
if err != nil {
return nil, err
}
err = json.Unmarshal(f, &exception)
var framework reporthandling.Framework
if err = json.Unmarshal(buf, &framework); err != nil {
return nil, err
}
for _, ctrl := range framework.Controls {
controlIDs = append(controlIDs, ctrl.ControlID)
}
return controlIDs, nil
}
// GetExceptions retrieves configured exceptions.
//
// NOTE: the cluster parameter is not used at this moment.
func (lp *LoadPolicy) GetExceptions(_ /* clusterName */ string) ([]armotypes.PostureExceptionPolicy, error) {
// NOTE: this assumes that the first path contains a valid exceptions descriptor
filePath := lp.filePath()
buf, err := os.ReadFile(filePath)
if err != nil {
return nil, err
}
exception := make([]armotypes.PostureExceptionPolicy, 0, 300)
err = json.Unmarshal(buf, &exception)
return exception, err
}
func (lp *LoadPolicy) GetControlsInputs(clusterName string) (map[string][]string, error) {
// GetControlsInputs retrieves the map of control configs.
//
// NOTE: the cluster parameter is not used at this moment.
func (lp *LoadPolicy) GetControlsInputs(_ /* clusterName */ string) (map[string][]string, error) {
// NOTE: this assumes that only the first path contains a valid control inputs descriptor
filePath := lp.filePath()
accountConfig := &armotypes.CustomerConfig{}
f, err := os.ReadFile(filePath)
fileName := filepath.Base(filePath)
buf, err := os.ReadFile(filePath)
if err != nil {
formattedError := fmt.Errorf(
`Error opening %s file, "controls-config" will be downloaded from ARMO management portal`,
fileName,
)
return nil, formattedError
}
controlInputs := make(map[string][]string, 100) // from armotypes.Settings.PostureControlInputs
if err = json.Unmarshal(buf, &controlInputs); err != nil {
formattedError := fmt.Errorf(
`Error reading %s file, %v, "controls-config" will be downloaded from ARMO management portal`,
fileName, err,
)
return nil, formattedError
}
return controlInputs, nil
}
// GetAttackTracks yields the attack tracks from a config file.
func (lp *LoadPolicy) GetAttackTracks() ([]v1alpha1.AttackTrack, error) {
attackTracks := make([]v1alpha1.AttackTrack, 0, 20)
buf, err := os.ReadFile(lp.filePath())
if err != nil {
return nil, err
}
if err = json.Unmarshal(f, &accountConfig.Settings.PostureControlInputs); err == nil {
return accountConfig.Settings.PostureControlInputs, nil
if err = json.Unmarshal(buf, &attackTracks); err != nil {
return nil, err
}
return nil, err
return attackTracks, nil
}
// temporary support for a list of files

View File

@@ -1,13 +1,409 @@
package getter
import (
"fmt"
"os"
"path/filepath"
)
"testing"
var mockFrameworkBasePath = filepath.Join("examples", "mocks", "frameworks")
"github.com/stretchr/testify/require"
)
func MockNewLoadPolicy() *LoadPolicy {
return &LoadPolicy{
filePaths: []string{""},
}
}
func TestLoadPolicy(t *testing.T) {
t.Parallel()
const (
testFramework = "MITRE"
testControl = "C-0053"
)
t.Run("with GetFramework", func(t *testing.T) {
t.Run("should retrieve named framework", func(t *testing.T) {
t.Parallel()
p := NewLoadPolicy([]string{testFrameworkFile(testFramework)})
fw, err := p.GetFramework(testFramework)
require.NoError(t, err)
require.NotNil(t, fw)
require.Equal(t, testFramework, fw.Name)
})
t.Run("should fail to retrieve framework", func(t *testing.T) {
t.Parallel()
p := NewLoadPolicy([]string{testFrameworkFile(testFramework)})
fw, err := p.GetFramework("wrong")
require.Error(t, err)
require.Nil(t, fw)
})
t.Run("edge case: should error on empty framework", func(t *testing.T) {
t.Parallel()
p := NewLoadPolicy([]string{testFrameworkFile(testFramework)})
fw, err := p.GetFramework("")
require.ErrorIs(t, err, ErrNameRequired)
require.Nil(t, fw)
})
t.Run("edge case: corrupted json", func(t *testing.T) {
t.Parallel()
const invalidFramework = "invalid-fw"
p := NewLoadPolicy([]string{testFrameworkFile(invalidFramework)})
fw, err := p.GetFramework(invalidFramework)
require.Error(t, err)
require.Nil(t, fw)
})
t.Run("edge case: missing json", func(t *testing.T) {
t.Parallel()
const invalidFramework = "nowheretobefound"
p := NewLoadPolicy([]string{testFrameworkFile(invalidFramework)})
_, err := p.GetFramework(invalidFramework)
require.Error(t, err)
})
})
t.Run("with GetControl", func(t *testing.T) {
t.Run("should retrieve named control from framework", func(t *testing.T) {
t.Parallel()
const (
expectedControlName = "Access container service account"
)
p := NewLoadPolicy([]string{testFrameworkFile(testFramework)})
ctrl, err := p.GetControl(testControl)
require.NoError(t, err)
require.NotNil(t, ctrl)
require.Equal(t, testControl, ctrl.ControlID)
require.Equal(t, expectedControlName, ctrl.Name)
})
t.Run("with single control descriptor", func(t *testing.T) {
const (
singleControl = "C-0001"
expectedControlName = "Forbidden Container Registries"
)
t.Run("should retrieve named control from control descriptor", func(t *testing.T) {
t.Parallel()
p := NewLoadPolicy([]string{testFrameworkFile(singleControl)})
ctrl, err := p.GetControl(singleControl)
require.NoError(t, err)
require.NotNil(t, ctrl)
require.Equal(t, singleControl, ctrl.ControlID)
require.Equal(t, expectedControlName, ctrl.Name)
})
t.Run("should fail to retrieve named control from control descriptor", func(t *testing.T) {
t.Parallel()
p := NewLoadPolicy([]string{testFrameworkFile(singleControl)})
ctrl, err := p.GetControl("wrong")
require.Error(t, err)
require.Nil(t, ctrl)
})
})
t.Run("with framework descriptor", func(t *testing.T) {
t.Run("should fail to retrieve named control", func(t *testing.T) {
t.Parallel()
const testControl = "wrong"
p := NewLoadPolicy([]string{testFrameworkFile(testFramework)})
ctrl, err := p.GetControl(testControl)
require.ErrorIs(t, err, ErrControlNotMatching)
require.Nil(t, ctrl)
})
})
t.Run("edge case: corrupted json", func(t *testing.T) {
t.Parallel()
const invalidControl = "invalid-fw"
p := NewLoadPolicy([]string{testFrameworkFile(invalidControl)})
_, err := p.GetControl(invalidControl)
require.Error(t, err)
})
t.Run("edge case: missing json", func(t *testing.T) {
t.Parallel()
const invalidControl = "nowheretobefound"
p := NewLoadPolicy([]string{testFrameworkFile(invalidControl)})
_, err := p.GetControl(invalidControl)
require.Error(t, err)
})
t.Run("edge case: should error on empty control", func(t *testing.T) {
t.Parallel()
p := NewLoadPolicy([]string{testFrameworkFile(testFramework)})
ctrl, err := p.GetControl("")
require.ErrorIs(t, err, ErrIDRequired)
require.Nil(t, ctrl)
})
})
t.Run("with ListFrameworks", func(t *testing.T) {
t.Run("should return all frameworks in the policy path", func(t *testing.T) {
t.Parallel()
const (
extraFramework = "NSA"
attackTracks = "attack-tracks"
)
p := NewLoadPolicy([]string{
testFrameworkFile(testFramework),
testFrameworkFile(extraFramework),
testFrameworkFile(extraFramework), // should be deduped
testFrameworkFile(attackTracks), // should be ignored
})
fws, err := p.ListFrameworks()
require.NoError(t, err)
require.Len(t, fws, 2)
require.Equal(t, testFramework, fws[0])
require.Equal(t, extraFramework, fws[1])
})
t.Run("should not return an empty framework", func(t *testing.T) {
t.Parallel()
const (
extraFramework = "NSA"
attackTracks = "attack-tracks"
controlsInputs = "controls-inputs"
)
p := NewLoadPolicy([]string{
testFrameworkFile(testFramework),
testFrameworkFile(extraFramework),
testFrameworkFile(attackTracks), // should be ignored
testFrameworkFile(controlsInputs), // should be ignored
})
fws, err := p.ListFrameworks()
require.NoError(t, err)
require.Len(t, fws, 2)
require.NotContains(t, fws, "")
require.Equal(t, testFramework, fws[0])
require.Equal(t, extraFramework, fws[1])
})
t.Run("should fail on file error", func(t *testing.T) {
t.Parallel()
const (
extraFramework = "NSA"
nowhere = "nowheretobeseen"
)
p := NewLoadPolicy([]string{
testFrameworkFile(testFramework),
testFrameworkFile(extraFramework),
testFrameworkFile(nowhere), // should raise an error
})
fws, err := p.ListFrameworks()
require.Error(t, err)
require.Nil(t, fws)
})
})
t.Run("edge case: policy without path", func(t *testing.T) {
t.Parallel()
p := NewLoadPolicy([]string{})
require.Empty(t, p.filePath())
})
t.Run("with GetFrameworks", func(t *testing.T) {
const extraFramework = "NSA"
t.Run("should return all configured frameworks", func(t *testing.T) {
t.Parallel()
p := NewLoadPolicy([]string{
testFrameworkFile(testFramework),
testFrameworkFile(extraFramework),
})
fws, err := p.GetFrameworks()
require.NoError(t, err)
require.Len(t, fws, 2)
require.Equal(t, testFramework, fws[0].Name)
require.Equal(t, extraFramework, fws[1].Name)
})
t.Run("should return dedupe configured frameworks", func(t *testing.T) {
t.Parallel()
const attackTracks = "attack-tracks"
p := NewLoadPolicy([]string{
testFrameworkFile(testFramework),
testFrameworkFile(extraFramework),
testFrameworkFile(extraFramework),
testFrameworkFile(attackTracks), // should be ignored
})
fws, err := p.GetFrameworks()
require.NoError(t, err)
require.Len(t, fws, 2)
require.Equal(t, testFramework, fws[0].Name)
require.Equal(t, extraFramework, fws[1].Name)
})
})
t.Run("with ListControls", func(t *testing.T) {
t.Run("should return controls", func(t *testing.T) {
t.Parallel()
p := NewLoadPolicy([]string{testFrameworkFile(testFramework)})
controlIDs, err := p.ListControls()
require.NoError(t, err)
require.Greater(t, len(controlIDs), 0)
require.Equal(t, testControl, controlIDs[0])
})
})
t.Run("with GetAttackTracks", func(t *testing.T) {
t.Run("should return attack tracks", func(t *testing.T) {
t.Parallel()
const attackTracks = "attack-tracks"
p := NewLoadPolicy([]string{testFrameworkFile(attackTracks)})
tracks, err := p.GetAttackTracks()
require.NoError(t, err)
require.Greater(t, len(tracks), 0)
for _, track := range tracks {
require.Equal(t, "AttackTrack", track.Kind)
}
})
t.Run("edge case: corrupted json", func(t *testing.T) {
t.Parallel()
const invalidTracks = "invalid-fw"
p := NewLoadPolicy([]string{testFrameworkFile(invalidTracks)})
_, err := p.GetAttackTracks()
require.Error(t, err)
})
t.Run("edge case: missing json", func(t *testing.T) {
t.Parallel()
const invalidTracks = "nowheretobefound"
p := NewLoadPolicy([]string{testFrameworkFile(invalidTracks)})
_, err := p.GetAttackTracks()
require.Error(t, err)
})
})
t.Run("with GetControlsInputs", func(t *testing.T) {
const cluster = "dummy" // unused parameter at the moment
t.Run("should return control inputs for a cluster", func(t *testing.T) {
t.Parallel()
fixture, expected := writeTempJSONControlInputs(t)
t.Cleanup(func() {
_ = os.Remove(fixture)
})
p := NewLoadPolicy([]string{fixture})
inputs, err := p.GetControlsInputs(cluster)
require.NoError(t, err)
require.EqualValues(t, expected, inputs)
})
t.Run("edge case: corrupted json", func(t *testing.T) {
t.Parallel()
const invalidInputs = "invalid-fw"
p := NewLoadPolicy([]string{testFrameworkFile(invalidInputs)})
_, err := p.GetControlsInputs(cluster)
require.Error(t, err)
})
t.Run("edge case: missing json", func(t *testing.T) {
t.Parallel()
const invalidInputs = "nowheretobefound"
p := NewLoadPolicy([]string{testFrameworkFile(invalidInputs)})
_, err := p.GetControlsInputs(cluster)
require.Error(t, err)
})
})
t.Run("with GetExceptions", func(t *testing.T) {
const cluster = "dummy" // unused parameter at the moment
t.Run("should return exceptions", func(t *testing.T) {
t.Parallel()
const exceptions = "exceptions"
p := NewLoadPolicy([]string{testFrameworkFile(exceptions)})
exceptionPolicies, err := p.GetExceptions(cluster)
require.NoError(t, err)
require.Greater(t, len(exceptionPolicies), 0)
t.Logf("len=%d", len(exceptionPolicies))
for _, policy := range exceptionPolicies {
require.NotEmpty(t, policy.Name)
}
})
t.Run("edge case: corrupted json", func(t *testing.T) {
t.Parallel()
const invalidInputs = "invalid-fw"
p := NewLoadPolicy([]string{testFrameworkFile(invalidInputs)})
_, err := p.GetExceptions(cluster)
require.Error(t, err)
})
t.Run("edge case: missing json", func(t *testing.T) {
t.Parallel()
const invalidInputs = "nowheretobefound"
p := NewLoadPolicy([]string{testFrameworkFile(invalidInputs)})
_, err := p.GetExceptions(cluster)
require.Error(t, err)
})
})
}
func testFrameworkFile(framework string) string {
return filepath.Join(".", "testdata", fmt.Sprintf("%s.json", framework))
}
func writeTempJSONControlInputs(t testing.TB) (string, map[string][]string) {
fileName := testFrameworkFile("control-inputs")
mock := map[string][]string{
"key1": {
"val1", "val2",
},
"key2": {
"val3", "val4",
},
}
buf, err := json.Marshal(mock)
require.NoError(t, err)
require.NoError(t, os.WriteFile(fileName, buf, 0600))
return fileName, mock
}

View File

@@ -0,0 +1,85 @@
{
"guid": "",
"name": "Forbidden Container Registries",
"attributes": {
"armoBuiltin": true,
"attackTracks": [
{
"attackTrack": "container",
"categories": [
"Initial access"
]
}
],
"controlTypeTags": [
"security",
"compliance"
],
"microsoftMitreColumns": [
"Initial Access"
]
},
"id": "C-0001",
"controlID": "C-0001",
"creationTime": "",
"description": "In cases where the Kubernetes cluster is provided by a CSP (e.g., AKS in Azure, GKE in GCP, or EKS in AWS), compromised cloud credential can lead to the cluster takeover. Attackers may abuse cloud account credentials or IAM mechanism to the clusters management layer.",
"remediation": "Limit the registries from which you pull container images from",
"rules": [
{
"guid": "",
"name": "rule-identify-blocklisted-image-registries",
"attributes": {
"armoBuiltin": true,
"m$K8sThreatMatrix": "Initial Access::Compromised images in registry"
},
"creationTime": "",
"rule": "package armo_builtins\nimport data\n# Check for images from blocklisted repos\n\nuntrustedImageRepo[msga] {\n\tpod := input[_]\n\tk := pod.kind\n\tk == \"Pod\"\n\tcontainer := pod.spec.containers[i]\n\tpath := sprintf(\"spec.containers[%v].image\", [format_int(i, 10)])\n\timage := container.image\n untrusted_or_public_registries(image)\n\n\tmsga := {\n\t\t\"alertMessage\": sprintf(\"image '%v' in container '%s' comes from untrusted registry\", [image, container.name]),\n\t\t\"packagename\": \"armo_builtins\",\n\t\t\"alertScore\": 2,\n\t\t\"fixPaths\": [],\n\t\t\"failedPaths\": [path],\n \"alertObject\": {\n\t\t\t\"k8sApiObjects\": [pod]\n\t\t}\n }\n}\n\nuntrustedImageRepo[msga] {\n\twl := input[_]\n\tspec_template_spec_patterns := {\"Deployment\",\"ReplicaSet\",\"DaemonSet\",\"StatefulSet\",\"Job\"}\n\tspec_template_spec_patterns[wl.kind]\n\tcontainer := wl.spec.template.spec.containers[i]\n\tpath := sprintf(\"spec.template.spec.containers[%v].image\", [format_int(i, 10)])\n\timage := container.image\n untrusted_or_public_registries(image)\n\n\tmsga := {\n\t\t\"alertMessage\": sprintf(\"image '%v' in container '%s' comes from untrusted registry\", [image, container.name]),\n\t\t\"packagename\": \"armo_builtins\",\n\t\t\"alertScore\": 2,\n\t\t\"fixPaths\": [],\n\t\t\"failedPaths\": [path],\n \"alertObject\": {\n\t\t\t\"k8sApiObjects\": [wl]\n\t\t}\n }\n}\n\nuntrustedImageRepo[msga] {\n\twl := input[_]\n\twl.kind == \"CronJob\"\n\tcontainer := wl.spec.jobTemplate.spec.template.spec.containers[i]\n\tpath := sprintf(\"spec.jobTemplate.spec.template.spec.containers[%v].image\", [format_int(i, 10)])\n\timage := container.image\n untrusted_or_public_registries(image)\n\n\tmsga := {\n\t\t\"alertMessage\": sprintf(\"image '%v' in container '%s' comes from untrusted registry\", [image, container.name]),\n\t\t\"packagename\": \"armo_builtins\",\n\t\t\"alertScore\": 2,\n\t\t\"fixPaths\": [],\n\t\t\"failedPaths\": [path],\n \"alertObject\": {\n\t\t\t\"k8sApiObjects\": [wl]\n\t\t}\n }\n}\n\nuntrusted_or_public_registries(image){\n\t# see default-config-inputs.json for list values\n\tuntrusted_registries := data.postureControlInputs.untrustedRegistries\n\trepo_prefix := untrusted_registries[_]\n\tstartswith(image, repo_prefix)\n}\n\nuntrusted_or_public_registries(image){\n\t# see default-config-inputs.json for list values\n\tpublic_registries := data.postureControlInputs.publicRegistries\n\trepo_prefix := public_registries[_]\n\tstartswith(image, repo_prefix)\n}",
"resourceEnumerator": "",
"ruleLanguage": "Rego",
"match": [
{
"apiGroups": [
"*"
],
"apiVersions": [
"*"
],
"resources": [
"Pod",
"Deployment",
"ReplicaSet",
"DaemonSet",
"StatefulSet",
"Job",
"CronJob"
]
}
],
"ruleDependencies": [],
"configInputs": [
"settings.postureControlInputs.publicRegistries",
"settings.postureControlInputs.untrustedRegistries"
],
"controlConfigInputs": [
{
"path": "settings.postureControlInputs.publicRegistries",
"name": "Public registries",
"description": "Kubescape checks none of these public registries are in use."
},
{
"path": "settings.postureControlInputs.untrustedRegistries",
"name": "Registries block list",
"description": "Kubescape checks none of the following registries are in use."
}
],
"description": "Identifying if pod container images are from unallowed registries",
"remediation": "Use images from safe registry",
"ruleQuery": "",
"relevantCloudProviders": null
}
],
"rulesIDs": [
""
],
"baseScore": 7
}

2832
core/cautils/getter/testdata/MITRE.json vendored Normal file

File diff suppressed because one or more lines are too long

2249
core/cautils/getter/testdata/NSA.json vendored Normal file

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,136 @@
[
{
"apiVersion": "regolibrary.kubescape/v1alpha1",
"kind": "AttackTrack",
"metadata": {
"name": "node"
},
"spec": {
"data": {
"name": "Initial access",
"subSteps": [
{
"name": "Execution",
"subSteps": [
{
"name": "Persistence"
},
{
"name": "Credential access"
},
{
"name": "Defense evasion"
},
{
"name": "Discovery"
},
{
"name": "Lateral movement"
},
{
"name": "Impact - data theft"
},
{
"name": "Impact - data destruction"
},
{
"name": "Impact - service injection"
}
]
}
]
}
}
},
{
"apiVersion": "regolibrary.kubescape/v1alpha1",
"kind": "AttackTrack",
"metadata": {
"name": "kubeapi"
},
"spec": {
"data": {
"name": "Initial access",
"subSteps": [
{
"name": "Persistence"
},
{
"name": "Privilege escalation"
},
{
"name": "Credential access"
},
{
"name": "Discovery"
},
{
"name": "Lateral movement"
},
{
"name": "Defense evasion"
},
{
"name": "Impact - data destruction"
},
{
"name": "Impact - service injection"
}
]
}
}
},
{
"apiVersion": "regolibrary.kubescape/v1alpha1",
"kind": "AttackTrack",
"metadata": {
"name": "container"
},
"spec": {
"data": {
"name": "Initial access",
"subSteps": [
{
"name": "Execution",
"subSteps": [
{
"name": "Privilege escalation"
},
{
"name": "Credential access",
"subSteps": [
{
"name": "Impact - service access"
},
{
"name": "Impact - K8s API access",
"subSteps": [
{
"name": "Defense evasion - KubeAPI"
}
]
}
]
},
{
"name": "Discovery"
},
{
"name": "Lateral movement"
},
{
"name": "Impact - Data access in container"
},
{
"name": "Persistence"
}
]
},
{
"name": "Impact - service destruction"
}
]
}
}
}
]

View File

@@ -0,0 +1,125 @@
{
"publicRegistries": [],
"untrustedRegistries": [],
"listOfDangerousArtifacts": [
"bin/bash",
"sbin/sh",
"bin/ksh",
"bin/tcsh",
"bin/zsh",
"usr/bin/scsh",
"bin/csh",
"bin/busybox",
"usr/bin/busybox"
],
"sensitiveKeyNames": [
"aws_access_key_id",
"aws_secret_access_key",
"azure_batchai_storage_account",
"azure_batchai_storage_key",
"azure_batch_account",
"azure_batch_key",
"secret",
"key",
"password",
"pwd",
"token",
"jwt",
"bearer",
"credential"
],
"servicesNames": [
"nifi-service",
"argo-server",
"minio",
"postgres",
"workflow-controller-metrics",
"weave-scope-app",
"kubernetes-dashboard"
],
"memory_limit_max": [],
"cpu_request_min": [],
"wlKnownNames": [
"coredns",
"kube-proxy",
"event-exporter-gke",
"kube-dns",
"17-default-backend",
"metrics-server",
"ca-audit",
"ca-dashboard-aggregator",
"ca-notification-server",
"ca-ocimage",
"ca-oracle",
"ca-posture",
"ca-rbac",
"ca-vuln-scan",
"ca-webhook",
"ca-websocket",
"clair-clair"
],
"sensitiveInterfaces": [
"nifi",
"argo-server",
"weave-scope-app",
"kubeflow",
"kubernetes-dashboard",
"jenkins",
"prometheus-deployment"
],
"max_high_vulnerabilities": [
"10"
],
"sensitiveValues": [
"BEGIN \\w+ PRIVATE KEY",
"PRIVATE KEY",
"eyJhbGciO",
"JWT",
"Bearer",
"_key_",
"_secret_"
],
"memory_request_max": [],
"memory_request_min": [],
"cpu_request_max": [],
"cpu_limit_max": [],
"cpu_limit_min": [],
"insecureCapabilities": [
"SETPCAP",
"NET_ADMIN",
"NET_RAW",
"SYS_MODULE",
"SYS_RAWIO",
"SYS_PTRACE",
"SYS_ADMIN",
"SYS_BOOT",
"MAC_OVERRIDE",
"MAC_ADMIN",
"PERFMON",
"ALL",
"BPF"
],
"max_critical_vulnerabilities": [
"5"
],
"sensitiveValuesAllowed": [],
"memory_limit_min": [],
"recommendedLabels": [
"app",
"tier",
"phase",
"version",
"owner",
"env"
],
"k8sRecommendedLabels": [
"app.kubernetes.io/name",
"app.kubernetes.io/instance",
"app.kubernetes.io/version",
"app.kubernetes.io/component",
"app.kubernetes.io/part-of",
"app.kubernetes.io/managed-by",
"app.kubernetes.io/created-by"
],
"imageRepositoryAllowList": []
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,3 @@
{
"guid": "",
}

View File

@@ -0,0 +1,22 @@
//go:build !gitenabled
package cautils
import (
"errors"
"github.com/kubescape/go-git-url/apis"
)
var ErrFatalNotSupportedByBuild = errors.New(`git scan not supported by this build. Build with tag "gitenabled" to enable the git scan feature`)
type gitRepository struct {
}
func newGitRepository(root string) (*gitRepository, error) {
return &gitRepository{}, ErrWarnNotSupportedByBuild
}
func (g *gitRepository) GetFileLastCommit(filePath string) (*apis.Commit, error) {
return nil, ErrFatalNotSupportedByBuild
}

View File

@@ -0,0 +1,11 @@
//go:build !gitenabled
package cautils
func (s *LocalGitRepositoryTestSuite) TestGetLastCommit() {
s.T().Log("warn: skipped testing native git functionality [GetLastCommit]")
}
func (s *LocalGitRepositoryTestSuite) TestGetFileLastCommit() {
s.T().Log("warn: skipped testing native git functionality [GetFileLastCommit]")
}

View File

@@ -0,0 +1,141 @@
//go:build gitenabled
package cautils
import (
"fmt"
"time"
"github.com/kubescape/go-git-url/apis"
git2go "github.com/libgit2/git2go/v33"
)
type gitRepository struct {
git2GoRepo *git2go.Repository
fileToLastCommit map[string]*git2go.Commit
}
func newGitRepository(root string) (*gitRepository, error) {
git2GoRepo, err := git2go.OpenRepository(root)
if err != nil {
return nil, err
}
return &gitRepository{
git2GoRepo: git2GoRepo,
}, nil
}
func (g *gitRepository) GetFileLastCommit(filePath string) (*apis.Commit, error) {
if len(g.fileToLastCommit) == 0 {
filePathToCommitTime := map[string]time.Time{}
filePathToCommit := map[string]*git2go.Commit{}
allCommits, _ := g.getAllCommits()
// builds a map of all files to their last commit
for _, commit := range allCommits {
// Ignore merge commits (2+ parents)
if commit.ParentCount() <= 1 {
tree, err := commit.Tree()
if err != nil {
continue
}
// ParentCount can be either 1 or 0 (initial commit)
// In case it's the initial commit, prevTree is nil
var prevTree *git2go.Tree
if commit.ParentCount() == 1 {
prevCommit := commit.Parent(0)
prevTree, err = prevCommit.Tree()
if err != nil {
continue
}
}
diff, err := g.git2GoRepo.DiffTreeToTree(prevTree, tree, nil)
if err != nil {
continue
}
numDeltas, err := diff.NumDeltas()
if err != nil {
continue
}
for i := 0; i < numDeltas; i++ {
delta, err := diff.Delta(i)
if err != nil {
continue
}
deltaFilePath := delta.NewFile.Path
commitTime := commit.Author().When
// In case we have the commit information for the file which is not the latest - we override it
if currentCommitTime, exists := filePathToCommitTime[deltaFilePath]; exists {
if currentCommitTime.Before(commitTime) {
filePathToCommitTime[deltaFilePath] = commitTime
filePathToCommit[deltaFilePath] = commit
}
} else {
filePathToCommitTime[deltaFilePath] = commitTime
filePathToCommit[deltaFilePath] = commit
}
}
}
}
g.fileToLastCommit = filePathToCommit
}
if relevantCommit, exists := g.fileToLastCommit[filePath]; exists {
return g.getCommit(relevantCommit), nil
}
return nil, fmt.Errorf("failed to get commit information for file: %s", filePath)
}
func (g *gitRepository) getAllCommits() ([]*git2go.Commit, error) {
logItr, itrErr := g.git2GoRepo.Walk()
if itrErr != nil {
return nil, itrErr
}
pushErr := logItr.PushHead()
if pushErr != nil {
return nil, pushErr
}
var allCommits []*git2go.Commit
err := logItr.Iterate(func(commit *git2go.Commit) bool {
if commit != nil {
allCommits = append(allCommits, commit)
return true
}
return false
})
if err != nil {
return nil, err
}
if err != nil {
return nil, err
}
return allCommits, nil
}
func (g *gitRepository) getCommit(commit *git2go.Commit) *apis.Commit {
return &apis.Commit{
SHA: commit.Id().String(),
Author: apis.Committer{
Name: commit.Author().Name,
Email: commit.Author().Email,
Date: commit.Author().When,
},
Message: commit.Message(),
Committer: apis.Committer{},
Files: []apis.Files{},
}
}

View File

@@ -0,0 +1,44 @@
//go:build gitenabled
package cautils
func (s *LocalGitRepositoryTestSuite) TestGetLastCommit() {
if localRepo, err := NewLocalGitRepository(s.gitRepositoryPaths["localrepo"]); s.NoError(err) {
if commit, err := localRepo.GetLastCommit(); s.NoError(err) {
s.Equal("7e09312b8017695fadcd606882e3779f10a5c832", commit.SHA)
s.Equal("Amir Malka", commit.Author.Name)
s.Equal("amirm@armosec.io", commit.Author.Email)
s.Equal("2022-05-22 19:11:57 +0300 +0300", commit.Author.Date.String())
s.Equal("added file B\n", commit.Message)
}
}
}
func (s *LocalGitRepositoryTestSuite) TestGetFileLastCommit() {
s.Run("fileA", func() {
if localRepo, err := NewLocalGitRepository(s.gitRepositoryPaths["localrepo"]); s.NoError(err) {
if commit, err := localRepo.GetFileLastCommit("fileA"); s.NoError(err) {
s.Equal("9fae4be19624297947d2b605cefbff516628612d", commit.SHA)
s.Equal("Amir Malka", commit.Author.Name)
s.Equal("amirm@armosec.io", commit.Author.Email)
s.Equal("2022-05-22 18:55:48 +0300 +0300", commit.Author.Date.String())
s.Equal("added file A\n", commit.Message)
}
}
})
s.Run("fileB", func() {
if localRepo, err := NewLocalGitRepository(s.gitRepositoryPaths["localrepo"]); s.NoError(err) {
if commit, err := localRepo.GetFileLastCommit("dirA/fileB"); s.NoError(err) {
s.Equal("7e09312b8017695fadcd606882e3779f10a5c832", commit.SHA)
s.Equal("Amir Malka", commit.Author.Name)
s.Equal("amirm@armosec.io", commit.Author.Email)
s.Equal("2022-05-22 19:11:57 +0300 +0300", commit.Author.Date.String())
s.Equal("added file B\n", commit.Message)
}
}
})
}

View File

@@ -0,0 +1,16 @@
package cautils
import (
"testing"
giturl "github.com/kubescape/go-git-url"
"github.com/stretchr/testify/require"
)
func TestEnsureRemoteParsed(t *testing.T) {
const remote = "git@gitlab.com:foobar/gitlab-tests/sample-project.git"
require.NotPanics(t, func() {
_, _ = giturl.NewGitURL(remote)
})
}

92
core/cautils/helmchart.go Normal file
View File

@@ -0,0 +1,92 @@
package cautils
import (
"path/filepath"
"strings"
logger "github.com/kubescape/go-logger"
"github.com/kubescape/go-logger/helpers"
"github.com/kubescape/k8s-interface/workloadinterface"
"github.com/kubescape/opa-utils/objectsenvelopes/localworkload"
helmchart "helm.sh/helm/v3/pkg/chart"
helmloader "helm.sh/helm/v3/pkg/chart/loader"
helmchartutil "helm.sh/helm/v3/pkg/chartutil"
helmengine "helm.sh/helm/v3/pkg/engine"
)
type HelmChart struct {
chart *helmchart.Chart
path string
}
func IsHelmDirectory(path string) (bool, error) {
return helmchartutil.IsChartDir(path)
}
func NewHelmChart(path string) (*HelmChart, error) {
chart, err := helmloader.Load(path)
if err != nil {
return nil, err
}
return &HelmChart{
chart: chart,
path: path,
}, nil
}
func (hc *HelmChart) GetName() string {
return hc.chart.Name()
}
func (hc *HelmChart) GetDefaultValues() map[string]interface{} {
return hc.chart.Values
}
// GetWorkloads renders chart template using the default values and returns a map of source file to its workloads
func (hc *HelmChart) GetWorkloadsWithDefaultValues() (map[string][]workloadinterface.IMetadata, []error) {
return hc.GetWorkloads(hc.GetDefaultValues())
}
// GetWorkloads renders chart template using the provided values and returns a map of source (absolute) file path to its workloads
func (hc *HelmChart) GetWorkloads(values map[string]interface{}) (map[string][]workloadinterface.IMetadata, []error) {
vals, err := helmchartutil.ToRenderValues(hc.chart, values, helmchartutil.ReleaseOptions{}, nil)
if err != nil {
return nil, []error{err}
}
sourceToFile, err := helmengine.Render(hc.chart, vals)
if err != nil {
return nil, []error{err}
}
workloads := make(map[string][]workloadinterface.IMetadata, 0)
errs := []error{}
for path, renderedYaml := range sourceToFile {
if !IsYaml(strings.ToLower(path)) {
continue
}
wls, e := ReadFile([]byte(renderedYaml), YAML_FILE_FORMAT)
if e != nil {
logger.L().Debug("failed to read rendered yaml file", helpers.String("file", path), helpers.Error(e))
}
if len(wls) == 0 {
continue
}
// separate base path and file name. We do not use the os.Separator because the paths returned from the helm engine are not OS specific (e.g. mychart/templates/myfile.yaml)
if firstPathSeparatorIndex := strings.Index(path, string("/")); firstPathSeparatorIndex != -1 {
absPath := filepath.Join(hc.path, path[firstPathSeparatorIndex:])
workloads[absPath] = []workloadinterface.IMetadata{}
for i := range wls {
lw := localworkload.NewLocalWorkload(wls[i].GetObject())
lw.SetPath(absPath)
workloads[absPath] = append(workloads[absPath], lw)
}
}
}
return workloads, errs
}

View File

@@ -0,0 +1,132 @@
package cautils
import (
_ "embed"
"encoding/json"
"os"
"path/filepath"
"strings"
"testing"
"github.com/kubescape/opa-utils/objectsenvelopes/localworkload"
"github.com/stretchr/testify/suite"
)
type HelmChartTestSuite struct {
suite.Suite
helmChartPath string
expectedFiles []string
expectedDefaultValues map[string]interface{}
}
func TestHelmChartTestSuite(t *testing.T) {
suite.Run(t, new(HelmChartTestSuite))
}
func (s *HelmChartTestSuite) SetupSuite() {
o, _ := os.Getwd()
s.helmChartPath = filepath.Join(filepath.Dir(o), "..", "examples", "helm_chart")
s.expectedFiles = []string{
filepath.Join(s.helmChartPath, "templates", "clusterrolebinding.yaml"),
filepath.Join(s.helmChartPath, "templates", "clusterrole.yaml"),
filepath.Join(s.helmChartPath, "templates", "serviceaccount.yaml"),
filepath.Join(s.helmChartPath, "templates", "rolebinding.yaml"),
filepath.Join(s.helmChartPath, "templates", "role.yaml"),
filepath.Join(s.helmChartPath, "templates", "cronjob.yaml"),
}
var obj interface{}
file, _ := os.ReadFile(filepath.Join("testdata", "helm_expected_default_values.json"))
_ = json.Unmarshal([]byte(file), &obj)
s.expectedDefaultValues = obj.(map[string]interface{})
}
func (s *HelmChartTestSuite) TestInvalidHelmDirectory() {
_, err := NewHelmChart("/invalid_path")
s.Error(err)
}
func (s *HelmChartTestSuite) TestValidHelmDirectory() {
chart, err := NewHelmChart(s.helmChartPath)
s.NoError(err)
s.NotNil(chart)
}
func (s *HelmChartTestSuite) TestGetName() {
chart, _ := NewHelmChart(s.helmChartPath)
s.Equal("kubescape", chart.GetName())
}
func (s *HelmChartTestSuite) TestGetDefaultValues() {
chart, _ := NewHelmChart(s.helmChartPath)
values := chart.GetDefaultValues()
valuesJson, _ := json.Marshal(values)
expectedValuesJson, _ := json.Marshal(s.expectedDefaultValues)
s.JSONEq(string(valuesJson), string(expectedValuesJson))
}
func (s *HelmChartTestSuite) TestGetWorkloadsWithOverride() {
chart, err := NewHelmChart(s.helmChartPath)
s.NoError(err, "Expected a valid helm chart")
values := chart.GetDefaultValues()
// Default pullPolicy value = Always
pullPolicyValue := values["image"].(map[string]interface{})["pullPolicy"].(string)
s.Equal(pullPolicyValue, "Always")
// Override default value
values["image"].(map[string]interface{})["pullPolicy"] = "Never"
fileToWorkloads, errs := chart.GetWorkloads(values)
s.Len(errs, 0)
s.Lenf(fileToWorkloads, len(s.expectedFiles), "Expected %d files", len(s.expectedFiles))
for _, expectedFile := range s.expectedFiles {
s.Contains(fileToWorkloads, expectedFile)
s.FileExists(expectedFile)
s.GreaterOrEqualf(len(fileToWorkloads[expectedFile]), 1, "Expected at least one workload in %q", expectedFile)
for i := range fileToWorkloads[expectedFile] {
pathInWorkload := fileToWorkloads[expectedFile][i].(*localworkload.LocalWorkload).GetPath()
s.Equal(pathInWorkload, expectedFile, "Expected GetPath() to return a valid path on workload")
}
if strings.Contains(expectedFile, "cronjob.yaml") {
jsonBytes, _ := json.Marshal(fileToWorkloads[expectedFile][0].GetObject())
s.Contains(string(jsonBytes), "\"imagePullPolicy\":\"Never\"", "Expected to overriden value of imagePullPolicy to be 'Never'")
}
}
}
func (s *HelmChartTestSuite) TestGetWorkloadsMissingValue() {
chart, _ := NewHelmChart(s.helmChartPath)
values := chart.GetDefaultValues()
delete(values, "image")
fileToWorkloads, errs := chart.GetWorkloads(values)
s.Nil(fileToWorkloads)
s.Len(errs, 1, "Expected an error due to missing value")
expectedErrMsg := "<.Values.image.repository>: nil pointer"
s.Containsf(errs[0].Error(), expectedErrMsg, "expected error containing %q, got %q", expectedErrMsg, errs[0])
}
func (s *HelmChartTestSuite) TestIsHelmDirectory() {
ok, err := IsHelmDirectory(s.helmChartPath)
s.True(ok)
s.NoError(err)
o, _ := os.Getwd()
nonHelmDir := filepath.Join(filepath.Dir(o), "../examples/online-boutique")
ok, err = IsHelmDirectory(nonHelmDir)
s.False(ok)
s.Contains(err.Error(), "no Chart.yaml exists in directory")
}

View File

@@ -0,0 +1,115 @@
package cautils
import (
"os"
"path/filepath"
logger "github.com/kubescape/go-logger"
"github.com/kubescape/go-logger/helpers"
"github.com/kubescape/k8s-interface/workloadinterface"
"github.com/kubescape/opa-utils/objectsenvelopes/localworkload"
"sigs.k8s.io/kustomize/api/krusty"
"sigs.k8s.io/kustomize/kyaml/filesys"
)
type KustomizeDirectory struct {
path string
}
// Used for checking if there is "Kustomization" file in the given Directory
var kustomizationFileMatchers = [3]string{"kustomization.yml", "kustomization.yaml", "Kustomization"}
func IsKustomizeDirectory(path string) bool {
if isDir := IsDir(path); !isDir {
return false
}
if lastChar := path[len(path)-1:]; lastChar != "/" {
path += "/"
}
matches := 0
for _, kustomizationFileMatcher := range kustomizationFileMatchers {
checkPath := path + kustomizationFileMatcher
if _, err := os.Stat(checkPath); err == nil {
matches++
}
}
switch matches {
case 0:
return false
case 1:
return true
default:
logger.L().Info("Multiple kustomize files found while checking Kustomize Directory")
return false
}
}
// Used for checking if the path is Kustomization file.
func IsKustomizeFile(path string) bool {
fileName := filepath.Base(path)
for _, kustomizationFileMatcher := range kustomizationFileMatchers {
if fileName == kustomizationFileMatcher {
return true
}
}
return false
}
func NewKustomizeDirectory(path string) *KustomizeDirectory {
return &KustomizeDirectory{
path: path,
}
}
func GetKustomizeDirectoryName(path string) string {
if isKustomizeDirectory := IsKustomizeDirectory(path); !isKustomizeDirectory {
return ""
}
return filepath.Dir(path)
}
// Get Workloads, creates the yaml files(K8s resources) using Kustomize and
// renders the workloads from the yaml files (k8s resources)
func (kd *KustomizeDirectory) GetWorkloads(kustomizeDirectoryPath string) (map[string][]workloadinterface.IMetadata, []error) {
fSys := filesys.MakeFsOnDisk()
kustomizer := krusty.MakeKustomizer(krusty.MakeDefaultOptions())
resmap, err := kustomizer.Run(fSys, kustomizeDirectoryPath)
if err != nil {
return nil, []error{err}
}
yml, err := resmap.AsYaml()
if err != nil {
return nil, []error{err}
}
workloads := make(map[string][]workloadinterface.IMetadata, 0)
errs := []error{}
wls, e := ReadFile(yml, YAML_FILE_FORMAT)
if e != nil {
logger.L().Debug("failed to read rendered yaml file", helpers.String("file", kustomizeDirectoryPath), helpers.Error(e))
}
if len(wls) != 0 {
workloads[kustomizeDirectoryPath] = []workloadinterface.IMetadata{}
for i := range wls {
lw := localworkload.NewLocalWorkload(wls[i].GetObject())
lw.SetPath(kustomizeDirectoryPath)
workloads[kustomizeDirectoryPath] = append(workloads[kustomizeDirectoryPath], lw)
}
}
return workloads, errs
}

View File

@@ -0,0 +1,140 @@
package cautils
import (
"errors"
"fmt"
"path"
"strings"
gitv5 "github.com/go-git/go-git/v5"
configv5 "github.com/go-git/go-git/v5/config"
plumbingv5 "github.com/go-git/go-git/v5/plumbing"
"github.com/kubescape/go-git-url/apis"
)
type LocalGitRepository struct {
*gitRepository
goGitRepo *gitv5.Repository
head *plumbingv5.Reference
config *configv5.Config
}
var ErrWarnNotSupportedByBuild = errors.New(`git commits retrieval not supported by this build. Build with tag "gitenabled" to enable the full git scan feature`)
func NewLocalGitRepository(path string) (*LocalGitRepository, error) {
goGitRepo, err := gitv5.PlainOpenWithOptions(path, &gitv5.PlainOpenOptions{DetectDotGit: true})
if err != nil {
return nil, err
}
head, err := goGitRepo.Head()
if err != nil {
return nil, err
}
if !head.Name().IsBranch() {
return nil, fmt.Errorf("current HEAD reference is not a branch")
}
config, err := goGitRepo.Config()
if err != nil {
return nil, err
}
if len(config.Remotes) == 0 {
return nil, fmt.Errorf("no remotes found")
}
l := &LocalGitRepository{
goGitRepo: goGitRepo,
head: head,
config: config,
}
if repoRoot, err := l.GetRootDir(); err == nil {
gitRepository, err := newGitRepository(repoRoot)
if err != nil && !errors.Is(err, ErrWarnNotSupportedByBuild) {
return l, err
}
l.gitRepository = gitRepository
}
return l, nil
}
// GetBranchName get current branch name
func (g *LocalGitRepository) GetBranchName() string {
return g.head.Name().Short()
}
// GetRemoteUrl get default remote URL
func (g *LocalGitRepository) GetRemoteUrl() (string, error) {
branchName := g.GetBranchName()
if branchRef, branchFound := g.config.Branches[branchName]; branchFound {
remoteName := branchRef.Remote
// branchRef.Remote can be a reference to a config.Remotes entry or directly a gitUrl
if _, found := g.config.Remotes[remoteName]; !found {
return remoteName, nil
}
if len(g.config.Remotes[remoteName].URLs) == 0 {
return "", fmt.Errorf("expected to find URLs for remote '%s', branch '%s'", remoteName, branchName)
}
return g.config.Remotes[remoteName].URLs[0], nil
}
const defaultRemoteName string = "origin"
defaultRemote, ok := g.config.Remotes[defaultRemoteName]
if !ok {
return "", fmt.Errorf("did not find a default remote with name '%s'", defaultRemoteName)
} else if len(defaultRemote.URLs) == 0 {
return "", fmt.Errorf("expected to find URLs for remote '%s'", defaultRemoteName)
}
return defaultRemote.URLs[0], nil
}
// GetName get origin name without the .git suffix
func (g *LocalGitRepository) GetName() (string, error) {
originUrl, err := g.GetRemoteUrl()
if err != nil {
return "", err
}
baseName := path.Base(originUrl)
// remove .git
return strings.TrimSuffix(baseName, ".git"), nil
}
// GetLastCommit get latest commit object
func (g *LocalGitRepository) GetLastCommit() (*apis.Commit, error) {
cIter, err := g.goGitRepo.Log(&gitv5.LogOptions{})
if err != nil {
return nil, err
}
commit, err := cIter.Next()
defer cIter.Close()
if err != nil {
return nil, err
}
return &apis.Commit{
SHA: commit.Hash.String(),
Author: apis.Committer{
Name: commit.Author.Name,
Email: commit.Author.Email,
Date: commit.Author.When,
},
Message: commit.Message,
Committer: apis.Committer{},
Files: []apis.Files{},
}, nil
}
func (g *LocalGitRepository) GetRootDir() (string, error) {
wt, err := g.goGitRepo.Worktree()
if err != nil {
return "", fmt.Errorf("failed to get repo root")
}
return wt.Filesystem.Root(), nil
}

View File

@@ -0,0 +1,200 @@
package cautils
import (
"archive/zip"
"fmt"
"io"
"os"
"path/filepath"
"strings"
"testing"
configv5 "github.com/go-git/go-git/v5/config"
plumbingv5 "github.com/go-git/go-git/v5/plumbing"
"github.com/stretchr/testify/suite"
)
var TEST_REPOS = [...]string{"localrepo", "withoutremotes"}
type LocalGitRepositoryTestSuite struct {
suite.Suite
archives map[string]*zip.ReadCloser
gitRepositoryPaths map[string]string
destinationPath string
}
func unzipFile(zipPath, destinationFolder string) (*zip.ReadCloser, error) {
archive, err := zip.OpenReader(zipPath)
if err != nil {
return nil, err
}
for _, f := range archive.File {
filePath := filepath.Join(destinationFolder, f.Name) //nolint:gosec
if !strings.HasPrefix(filePath, filepath.Clean(destinationFolder)+string(os.PathSeparator)) {
return nil, fmt.Errorf("invalid file path")
}
if f.FileInfo().IsDir() {
os.MkdirAll(filePath, os.ModePerm)
continue
}
if erc := copyFileInFolder(filePath, f); erc != nil {
return nil, erc
}
}
return archive, err
}
func copyFileInFolder(filePath string, f *zip.File) (err error) {
if err = os.MkdirAll(filepath.Dir(filePath), os.ModePerm); err != nil {
return err
}
dstFile, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode())
if err != nil {
return err
}
defer func() {
_ = dstFile.Close()
}()
fileInArchive, err := f.Open()
if err != nil {
return err
}
defer func() {
_ = fileInArchive.Close()
}()
_, err = io.Copy(dstFile, fileInArchive) //nolint:gosec
if err = dstFile.Close(); err != nil {
return err
}
if err = fileInArchive.Close(); err != nil {
return err
}
return err
}
func (s *LocalGitRepositoryTestSuite) SetupSuite() {
s.archives = make(map[string]*zip.ReadCloser)
s.gitRepositoryPaths = make(map[string]string)
destinationPath := filepath.Join(".", "testdata", "temp")
s.destinationPath = destinationPath
os.RemoveAll(destinationPath)
for _, repo := range TEST_REPOS {
zippedFixturePath := filepath.Join(".", "testdata", repo+".git")
gitRepositoryPath := filepath.Join(destinationPath, repo)
archive, err := unzipFile(zippedFixturePath, destinationPath)
if err == nil {
s.archives[repo] = archive
s.gitRepositoryPaths[repo] = gitRepositoryPath
}
}
}
func TestLocalGitRepositoryTestSuite(t *testing.T) {
suite.Run(t, new(LocalGitRepositoryTestSuite))
}
func (s *LocalGitRepositoryTestSuite) TearDownSuite() {
if s.archives != nil {
for _, archive := range s.archives {
if archive != nil {
archive.Close()
}
}
}
os.RemoveAll(s.destinationPath)
}
func (s *LocalGitRepositoryTestSuite) TestInvalidRepositoryPath() {
if _, err := NewLocalGitRepository("/invalidpath"); s.Error(err) {
s.Equal("repository does not exist", err.Error())
}
}
func (s *LocalGitRepositoryTestSuite) TestRepositoryWithoutRemotes() {
if _, err := NewLocalGitRepository(s.gitRepositoryPaths["withoutremotes"]); s.Error(err) {
s.Equal("no remotes found", err.Error())
}
}
func (s *LocalGitRepositoryTestSuite) TestGetBranchName() {
if localRepo, err := NewLocalGitRepository(s.gitRepositoryPaths["localrepo"]); s.NoError(err) {
s.Equal("master", localRepo.GetBranchName())
}
}
func (s *LocalGitRepositoryTestSuite) TestGetName() {
if localRepo, err := NewLocalGitRepository(s.gitRepositoryPaths["localrepo"]); s.NoError(err) {
if name, err := localRepo.GetName(); s.NoError(err) {
s.Equal("localrepo", name)
}
}
}
func (s *LocalGitRepositoryTestSuite) TestGetOriginUrl() {
if localRepo, err := NewLocalGitRepository(s.gitRepositoryPaths["localrepo"]); s.NoError(err) {
if url, err := localRepo.GetRemoteUrl(); s.NoError(err) {
s.Equal("git@github.com:testuser/localrepo", url)
}
}
}
func TestGetRemoteUrl(t *testing.T) {
testCases := []struct {
Name string
LocalRepo LocalGitRepository
Want string
WantErr error
}{
{
Name: "Branch with missing upstream and missing 'origin' fallback should return an error",
LocalRepo: LocalGitRepository{
config: &configv5.Config{
Branches: make(map[string]*configv5.Branch),
Remotes: make(map[string]*configv5.RemoteConfig),
},
head: plumbingv5.NewReferenceFromStrings("HEAD", "ref: refs/heads/v4"),
},
Want: "",
WantErr: fmt.Errorf("did not find a default remote with name 'origin'"),
},
}
for _, tc := range testCases {
t.Run(tc.Name, func(t *testing.T) {
localRepo := LocalGitRepository{
config: &configv5.Config{
Branches: make(map[string]*configv5.Branch),
Remotes: make(map[string]*configv5.RemoteConfig),
},
head: plumbingv5.NewReferenceFromStrings("HEAD", "ref: refs/heads/v4"),
}
want := tc.Want
wantErr := tc.WantErr
got, gotErr := localRepo.GetRemoteUrl()
if got != want {
t.Errorf("Remote URLs dont match: got '%s', want '%s'", got, want)
}
if gotErr.Error() != wantErr.Error() {
t.Errorf("Errors dont match: got '%v', want '%v'", gotErr, wantErr)
}
},
)
}
}

View File

@@ -1,31 +0,0 @@
package helpers
import "time"
type StringObj struct {
key string
value string
}
type ErrorObj struct {
key string
value error
}
type IntObj struct {
key string
value int
}
type InterfaceObj struct {
key string
value interface{}
}
func Error(e error) *ErrorObj { return &ErrorObj{key: "error", value: e} }
func Int(k string, v int) *IntObj { return &IntObj{key: k, value: v} }
func String(k, v string) *StringObj { return &StringObj{key: k, value: v} }
func Interface(k string, v interface{}) *InterfaceObj { return &InterfaceObj{key: k, value: v} }
func Time() *StringObj {
return &StringObj{key: "time", value: time.Now().Format("2006-01-02 15:04:05")}
}

View File

@@ -1,69 +0,0 @@
package helpers
import (
"strings"
)
type Level int8
const (
UnknownLevel Level = iota - -1
DebugLevel
InfoLevel //default
SuccessLevel
WarningLevel
ErrorLevel
FatalLevel
_defaultLevel = InfoLevel
_minLevel = DebugLevel
_maxLevel = FatalLevel
)
func ToLevel(level string) Level {
switch strings.ToLower(level) {
case "debug":
return DebugLevel
case "info":
return InfoLevel
case "success":
return SuccessLevel
case "warning", "warn":
return WarningLevel
case "error":
return ErrorLevel
case "fatal":
return FatalLevel
default:
return UnknownLevel
}
}
func (l Level) String() string {
switch l {
case DebugLevel:
return "debug"
case InfoLevel:
return "info"
case SuccessLevel:
return "success"
case WarningLevel:
return "warning"
case ErrorLevel:
return "error"
case FatalLevel:
return "fatal"
}
return ""
}
func (l Level) Skip(l2 Level) bool {
return l < l2
}
func SupportedLevels() []string {
levels := []string{}
for i := _minLevel; i <= _maxLevel; i++ {
levels = append(levels, i.String())
}
return levels
}

View File

@@ -1,62 +0,0 @@
package helpers
type IDetails interface {
Key() string
Value() interface{}
}
// ======================================================================================
// ============================== String ================================================
// ======================================================================================
// Key
func (s *StringObj) Key() string {
return s.key
}
// Value
func (s *StringObj) Value() interface{} {
return s.value
}
// ======================================================================================
// =============================== Error ================================================
// ======================================================================================
// Key
func (s *ErrorObj) Key() string {
return s.key
}
// Value
func (s *ErrorObj) Value() interface{} {
return s.value
}
// ======================================================================================
// ================================= Int ================================================
// ======================================================================================
// Key
func (s *IntObj) Key() string {
return s.key
}
// Value
func (s *IntObj) Value() interface{} {
return s.value
}
// ======================================================================================
// =========================== Interface ================================================
// ======================================================================================
// Key
func (s *InterfaceObj) Key() string {
return s.key
}
// Value
func (s *InterfaceObj) Value() interface{} {
return s.value
}

View File

@@ -1,81 +0,0 @@
package logger
import (
"os"
"strings"
"github.com/armosec/kubescape/core/cautils/logger/helpers"
"github.com/armosec/kubescape/core/cautils/logger/nonelogger"
"github.com/armosec/kubescape/core/cautils/logger/prettylogger"
"github.com/armosec/kubescape/core/cautils/logger/zaplogger"
)
type ILogger interface {
Fatal(msg string, details ...helpers.IDetails) // print log and exit 1
Error(msg string, details ...helpers.IDetails)
Success(msg string, details ...helpers.IDetails)
Warning(msg string, details ...helpers.IDetails)
Info(msg string, details ...helpers.IDetails)
Debug(msg string, details ...helpers.IDetails)
SetLevel(level string) error
GetLevel() string
SetWriter(w *os.File)
GetWriter() *os.File
LoggerName() string
}
var l ILogger
// Return initialized logger. If logger not initialized, will call InitializeLogger() with the default value
func L() ILogger {
if l == nil {
InitDefaultLogger()
}
return l
}
/* InitLogger initialize desired logger
Use:
InitLogger("<logger name>")
Supported logger names (call ListLoggersNames() for listing supported loggers)
- "zap": Logger from package "go.uber.org/zap"
- "pretty", "colorful": Human friendly colorful logger
- "none", "mock", "empty", "ignore": Logger will not print anything
Default:
- "pretty"
e.g.
InitLogger("none") -> will initialize the mock logger
*/
func InitLogger(loggerName string) {
switch strings.ToLower(loggerName) {
case zaplogger.LoggerName:
l = zaplogger.NewZapLogger()
case prettylogger.LoggerName, "colorful":
l = prettylogger.NewPrettyLogger()
case nonelogger.LoggerName, "mock", "empty", "ignore":
l = nonelogger.NewNoneLogger()
default:
InitDefaultLogger()
}
}
func InitDefaultLogger() {
l = prettylogger.NewPrettyLogger()
}
func DisableColor(flag bool) {
prettylogger.DisableColor(flag)
}
func ListLoggersNames() []string {
return []string{prettylogger.LoggerName, zaplogger.LoggerName, nonelogger.LoggerName}
}

View File

@@ -1,28 +0,0 @@
package nonelogger
import (
"os"
"github.com/armosec/kubescape/core/cautils/logger/helpers"
)
const LoggerName string = "none"
type NoneLogger struct {
}
func NewNoneLogger() *NoneLogger {
return &NoneLogger{}
}
func (nl *NoneLogger) GetLevel() string { return "" }
func (nl *NoneLogger) LoggerName() string { return LoggerName }
func (nl *NoneLogger) SetWriter(w *os.File) {}
func (nl *NoneLogger) GetWriter() *os.File { return nil }
func (nl *NoneLogger) SetLevel(level string) error { return nil }
func (nl *NoneLogger) Fatal(msg string, details ...helpers.IDetails) {}
func (nl *NoneLogger) Error(msg string, details ...helpers.IDetails) {}
func (nl *NoneLogger) Warning(msg string, details ...helpers.IDetails) {}
func (nl *NoneLogger) Success(msg string, details ...helpers.IDetails) {}
func (nl *NoneLogger) Info(msg string, details ...helpers.IDetails) {}
func (nl *NoneLogger) Debug(msg string, details ...helpers.IDetails) {}

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