Compare commits

..

32 Commits

Author SHA1 Message Date
David Wertenteil
0e5b9f7dd1 Merge 90052ad9e3 into 35c7b16e4a 2021-10-07 17:07:06 +03:00
dwertent
90052ad9e3 Merge branch 'master' of github.com:armosec/kubescape into dev 2021-10-07 15:46:50 +03:00
Rotem Refael
35c7b16e4a Update build.yaml
change report link
2021-10-07 15:18:37 +03:00
David Wertenteil
7ac75acfc2 Merge pull request #125 from dwertent/master
Update display color
2021-10-07 15:11:43 +03:00
dwertent
22662fddcd update display color 2021-10-07 15:03:48 +03:00
David Wertenteil
6df1cdf5d8 Merge pull request #124 from dwertent/master
Changing warning to excluded in results
2021-10-07 14:00:19 +03:00
dwertent
2287c51d73 changing warning to excluded 2021-10-07 13:59:20 +03:00
David Wertenteil
372942a14f Merge pull request #122 from dwertent/master
Adding go sum
2021-10-07 10:18:23 +03:00
dwertent
6362246da4 Merge remote-tracking branch 'upstream/dev' 2021-10-07 10:11:41 +03:00
dwertent
9986d69215 adding go sum 2021-10-07 10:11:14 +03:00
Ben Hirschberg
ca49bc1ddd Merge pull request #121 from armosec/dev
Fixed issues, update windows support
2021-10-06 18:20:37 +03:00
David Wertenteil
1229c73ddc Merge pull request #120 from dwertent/master
Fixing exception cluster name support
2021-10-06 18:16:51 +03:00
dwertent
7416202555 adding mitre example 2021-10-06 18:14:24 +03:00
dwertent
a0ba683eea Merge remote-tracking branch 'upstream/dev' 2021-10-06 18:12:48 +03:00
dwertent
89654eb26f update exception cluster name compare 2021-10-06 18:12:33 +03:00
Bezbran
9d1736a141 Typo in readme built.py -->> build.py 2021-10-06 15:22:38 +03:00
David Wertenteil
eaa4ed3da5 Merge pull request #118 from xdavidel/master
Update windows support in build
2021-10-06 15:10:02 +03:00
David Delarosa
0db3f65312 Merge remote-tracking branch 'upstream/dev' 2021-10-06 15:05:07 +03:00
David Wertenteil
1ea0a3ccc5 Merge pull request #117 from dwertent/master
load configMap configuration before file configuration
2021-10-06 14:24:30 +03:00
dwertent
16cd30bea8 load configMap before file 2021-10-06 14:06:36 +03:00
David Delarosa
075ba4c603 Comment out this windows exe
The build workflow relay on the same binary name - so we won't change
that right now.
2021-10-06 11:23:56 +03:00
David Delarosa
2d898822df Merge branch 'dev-win' 2021-10-06 10:36:11 +03:00
David Delarosa
25b8ec82e8 Cannot use both 'uses' and 'run' 2021-10-06 10:21:29 +03:00
David Delarosa
44b74e2681 Change workflow to use build.py script 2021-10-05 17:28:38 +03:00
David Wertenteil
485e171008 Merge pull request #116 from dwertent/master
Revert python script build
2021-10-05 17:17:13 +03:00
dwertent
c12eb83b4b remove comment 2021-10-05 17:12:43 +03:00
dwertent
84060e7823 revert python build 2021-10-05 17:07:30 +03:00
David Wertenteil
d80d50b59d Merge pull request #115 from dwertent/master
fixed in cluster crash - #114
2021-10-05 16:56:00 +03:00
dwertent
f11f054fea offline not new feature 2021-10-05 16:51:03 +03:00
dwertent
4c1d491d5a Merge remote-tracking branch 'upstream/dev' 2021-10-05 16:43:54 +03:00
dwertent
2b67cc520c windows install support 2021-10-05 16:43:05 +03:00
dwertent
2a5712bd3c fixed in cluster crash 2021-10-05 16:11:41 +03:00
12 changed files with 1272 additions and 22 deletions

View File

@@ -5,7 +5,6 @@ on:
branches: [ master ]
pull_request:
branches: [ master ]
types: [ closed ]
jobs:
once:
name: Create release
@@ -41,10 +40,10 @@ jobs:
env:
RELEASE: v1.0.${{ github.run_number }}
ArmoBEServer: api.armo.cloud
ArmoERServer: report.euprod1.cyberarmorsoft.com
ArmoERServer: report.armo.cloud
ArmoWebsite: portal.armo.cloud
CGO_ENABLED: 0
run: mkdir -p build/${{ matrix.os }} && go mod tidy && go build -ldflags "-w -s -X github.com/armosec/kubescape/cmd.BuildNumber=$RELEASE -X github.com/armosec/kubescape/cautils/getter.ArmoBEURL=$ArmoBEServer -X github.com/armosec/kubescape/cautils/getter.ArmoERURL=$ArmoERServer -X github.com/armosec/kubescape/cautils/getter.ArmoFEURL=$ArmoWebsite" -o build/${{ matrix.os }}/kubescape # && md5sum build/${{ matrix.os }}/kubescape > build/${{ matrix.os }}/kubescape.md5
run: python build.py
- name: Upload Release binaries
id: upload-release-asset

1
.gitignore vendored
View File

@@ -1,5 +1,4 @@
*.vs*
*go.sum*
*kubescape*
*debug*
.idea

View File

@@ -15,6 +15,8 @@ Use Kubescape to test clusters or scan single YAML files and integrate it to you
curl -s https://raw.githubusercontent.com/armosec/kubescape/master/install.sh | /bin/bash
```
[Install on windows](#install-on-windows)
## Run:
```
kubescape scan framework nsa --exclude-namespaces kube-system,kube-public
@@ -39,6 +41,20 @@ Want to contribute? Want to discuss something? Have an issue?
# Options and examples
## 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
```
## Flags
| flag | default | description | options |
@@ -62,6 +78,12 @@ Want to contribute? Want to discuss something? Have an issue?
kubescape scan framework nsa --exclude-namespaces kube-system,kube-public
```
* Scan a running Kubernetes cluster with [`mitre`](https://www.microsoft.com/security/blog/2020/04/02/attack-matrix-kubernetes/) framework
```
kubescape scan framework mitre --exclude-namespaces kube-system,kube-public
```
* Scan local `yaml`/`json` files before deploying
```
kubescape scan framework nsa *.yaml
@@ -99,7 +121,7 @@ for example:
```
helm template bitnami/mysql --generate-name --dry-run | kubescape scan framework nsa -
```
### Offline Support <img src="docs/new-feature.svg">
### Offline Support
It is possible to run Kubescape offline!
@@ -119,7 +141,24 @@ Kubescape is an open source project, we welcome your feedback and ideas for impr
# How to build
## For development
## Build using python script
Kubescpae can be built using:
``` sh
python build.py
```
Note: In order to built using the above script, one must set the environment
variables in this script:
+ RELEASE
+ ArmoBEServer
+ ArmoERServer
+ ArmoWebsite
## Build using go
Note: development (and the release process) is done with Go `1.16`

82
build.py Normal file
View File

@@ -0,0 +1,82 @@
import os
import sys
import hashlib
import platform
import subprocess
BASE_GETTER_CONST = "github.com/armosec/kubescape/cautils/getter"
BE_SERVER_CONST = BASE_GETTER_CONST + ".ArmoBEURL"
ER_SERVER_CONST = BASE_GETTER_CONST + ".ArmoERURL"
WEBSITE_CONST = BASE_GETTER_CONST + ".ArmoFEURL"
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/cmd.BuildNumber"
releaseVersion = os.getenv("RELEASE")
ArmoBEServer = os.getenv("ArmoBEServer")
ArmoERServer = os.getenv("ArmoERServer")
ArmoWebsite = os.getenv("ArmoWebsite")
# Create build directory
buildDir = getBuildDir()
if not os.path.isdir(buildDir):
os.makedirs(buildDir)
# Get dependencies
try:
status = subprocess.call(["go", "mod", "tidy"])
checkStatus(status, "Failed to get dependencies")
except OSError:
print("An error occured: (Hint: check if go is installed)")
raise
# Build kubescape
ldflags = "-w -s -X %s=%s -X %s=%s -X %s=%s -X %s=%s" \
% (buildUrl, releaseVersion, BE_SERVER_CONST, ArmoBEServer,
ER_SERVER_CONST, ArmoERServer, WEBSITE_CONST, ArmoWebsite)
status = subprocess.call(["go", "build", "-o", "%s/%s" % (buildDir, packageName), "-ldflags" ,ldflags])
checkStatus(status, "Failed to build kubescape")
sha1 = hashlib.sha1()
with open(buildDir + "/" + packageName, "rb") as kube:
sha1.update(kube.read())
with open(buildDir + "/" + packageName + ".sha1", "w") as kube_sha:
kube_sha.write(sha1.hexdigest())
print("Build Done")
if __name__ == "__main__":
main()

View File

@@ -10,4 +10,7 @@ RUN GOOS=linux CGO_ENABLED=0 go build -ldflags="-s -w " -installsuffix cgo -o k
FROM alpine
COPY --from=builder /work/kubescape /usr/bin/kubescape
# # Download the frameworks. Use the "--use-default" flag when running kubescape
# RUN kubescape download framework nsa && kubescape download framework mitre
CMD ["kubescape"]

View File

@@ -189,20 +189,20 @@ func (c *ClusterConfig) SetKeyValueInConfigmap(key string, value string) error {
func (c *ClusterConfig) SetCustomerGUID() error {
// get from file
if existsConfigJson() {
c.configObj, _ = loadConfigFromFile()
} else if c.existsConfigMap() {
// get from configMap
if c.existsConfigMap() {
c.configObj, _ = c.loadConfigFromConfigMap()
} else if existsConfigJson() { // get from file
c.configObj, _ = loadConfigFromFile()
} else {
c.createConfigMap()
createConfigJson()
}
customerGUID := c.GetCustomerGUID()
// get from armoBE
tenantResponse, err := c.armoAPI.GetCustomerGUID(customerGUID)
if err == nil && tenantResponse != nil {
if tenantResponse.AdminMail != "" { // this customer already belongs to some user
if existsConfigJson() {
@@ -222,7 +222,7 @@ func (c *ClusterConfig) SetCustomerGUID() error {
}
}
} else {
if err != nil && strings.Contains(err.Error(), "Invitation for tenant already exists") {
if err != nil && strings.Contains(err.Error(), "already exists") {
return nil
}
return err

View File

@@ -24,8 +24,8 @@ var FailureDisplay = color.New(color.Bold, color.FgHiRed).FprintfFunc()
var WarningDisplay = color.New(color.Bold, color.FgCyan).FprintfFunc()
var FailureTextDisplay = color.New(color.Faint, color.FgHiRed).FprintfFunc()
var InfoDisplay = color.New(color.Bold, color.FgHiYellow).FprintfFunc()
var InfoTextDisplay = color.New(color.Faint, color.FgHiYellow).FprintfFunc()
var SimpleDisplay = color.New(color.Bold, color.FgHiWhite).FprintfFunc()
var InfoTextDisplay = color.New(color.Bold, color.FgHiYellow).FprintfFunc()
var SimpleDisplay = color.New().FprintfFunc()
var SuccessDisplay = color.New(color.Bold, color.FgHiGreen).FprintfFunc()
var DescriptionDisplay = color.New(color.Faint, color.FgWhite).FprintfFunc()

View File

@@ -104,13 +104,18 @@ func GetClusterName() string {
}
func GetDefaultNamespace() string {
defaultNamespace := "default"
clientCfg, err := clientcmd.NewDefaultClientConfigLoadingRules().Load()
if err != nil {
return "default"
return defaultNamespace
}
namespace := clientCfg.Contexts[clientCfg.CurrentContext].Namespace
if namespace == "" {
namespace = "default"
apiContext, ok := clientCfg.Contexts[clientCfg.CurrentContext]
if !ok || apiContext == nil {
return defaultNamespace
}
namespace := apiContext.Namespace
if apiContext.Namespace == "" {
namespace = defaultNamespace
}
return namespace
}

1097
go.sum Normal file

File diff suppressed because it is too large Load Diff

26
install.ps1 Normal file
View File

@@ -0,0 +1,26 @@
Write-Host "Installing Kubescape..." -ForegroundColor Cyan
$BASE_DIR=$env:USERPROFILE + "\.kubescape"
$packageName = "/kubescape-windows-latest"
# Get latest release url
$config = Invoke-WebRequest "https://api.github.com/repos/armosec/kubescape/releases/latest" | ConvertFrom-Json
$url = $config.html_url.Replace("/tag/","/download/")
$fullUrl = $url + $packageName
# Create a new directory if needed
New-Item -Path $BASE_DIR -ItemType "directory" -ErrorAction SilentlyContinue
# Download the binary
Invoke-WebRequest -Uri $fullUrl -OutFile $BASE_DIR\kubescape.exe
# Update user PATH if needed
$currentPath = [Environment]::GetEnvironmentVariable("Path", "User")
if (-not $currentPath.Contains($BASE_DIR)) {
$confirmation = Read-Host "Add kubescape to user path? (y/n)"
if ($confirmation -eq 'y') {
[Environment]::SetEnvironmentVariable("Path", [Environment]::GetEnvironmentVariable("Path", "User") + ";$BASE_DIR;", "User")
}
}
Write-Host "Finished Installation" -ForegroundColor Green

View File

@@ -134,7 +134,7 @@ func (printer *Printer) PrintResults() {
func (printer *Printer) printSummary(controlName string, controlSummary *ControlSummary) {
cautils.SimpleDisplay(printer.writer, "Summary - ")
cautils.SuccessDisplay(printer.writer, "Passed:%v ", controlSummary.TotalResources-controlSummary.TotalFailed)
cautils.WarningDisplay(printer.writer, "Warning:%v ", controlSummary.TotalWarnign)
cautils.WarningDisplay(printer.writer, "Excluded:%v ", controlSummary.TotalWarnign)
cautils.FailureDisplay(printer.writer, "Failed:%v ", controlSummary.TotalFailed)
cautils.InfoDisplay(printer.writer, "Total:%v\n", controlSummary.TotalResources)
if controlSummary.TotalFailed > 0 {
@@ -151,7 +151,7 @@ func (printer *Printer) printTitle(controlName string, controlSummary *ControlSu
} else if controlSummary.TotalFailed != 0 {
cautils.FailureDisplay(printer.writer, "failed %v\n", emoji.SadButRelievedFace)
} else if controlSummary.TotalWarnign != 0 {
cautils.WarningDisplay(printer.writer, "warning %v\n", emoji.NeutralFace)
cautils.WarningDisplay(printer.writer, "excluded %v\n", emoji.NeutralFace)
} else {
cautils.SuccessDisplay(printer.writer, "passed %v\n", emoji.ThumbsUp)
}
@@ -194,7 +194,7 @@ func generateRow(control string, cs ControlSummary) []string {
}
func generateHeader() []string {
return []string{"Control Name", "Failed Resources", "Warning Resources", "All Resources", "% success"}
return []string{"Control Name", "Failed Resources", "Excluded Resources", "All Resources", "% success"}
}
func percentage(big, small int) int {

View File

@@ -98,7 +98,7 @@ func hasException(designator *armotypes.PortalDesignator, workload k8sinterface.
return false // if designators are empty
}
if cluster != "" && cautils.ClusterName != "" && regexCompare(cluster, cautils.ClusterName) { // TODO - where do we receive cluster name from?
if cluster != "" && cautils.ClusterName != "" && !regexCompare(cluster, cautils.ClusterName) { // TODO - where do we receive cluster name from?
return false // cluster name does not match
}