diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 454681c9..7b16864c 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -44,7 +44,7 @@ jobs: ArmoERServer: report.euprod1.cyberarmorsoft.com 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 diff --git a/README.md b/README.md index 8451864d..83f57a7c 100644 --- a/README.md +++ b/README.md @@ -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 @@ -33,12 +35,26 @@ We invite you to our team! We are excited about this project and want to return Want to contribute? Want to discuss something? Have an issue? * Open a issue, we are trying to respond within 48 hours -* [Join us](https://discordapp.com/invite/CTcCaBbb) in a discussion on our discord server! +* [Join us](https://armosec.github.io/kubescape/) in a discussion on our discord server! -[logo](https://discordapp.com/invite/CTcCaBbb) +[logo](https://armosec.github.io/kubescape/) # 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 | @@ -119,13 +135,30 @@ 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 built.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` 1. Clone Project ``` -git clone git@github.com:armosec/kubescape.git kubescape && cd "$_" +git clone https://github.com/armosec/kubescape.git kubescape && cd "$_" ``` 2. Build @@ -144,7 +177,7 @@ go mod tidy && go build -o kubescape . 1. Clone Project ``` -git clone git@github.com:armosec/kubescape.git kubescape && cd "$_" +git clone https://github.com/armosec/kubescape.git kubescape && cd "$_" ``` 2. Build diff --git a/build.py b/build.py new file mode 100644 index 00000000..cec9f379 --- /dev/null +++ b/build.py @@ -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, "Faild to get dependancies") + + except OSError: + print("An error occure: (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, "Faild 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() \ No newline at end of file diff --git a/cmd/framework.go b/cmd/framework.go index 1487e0fa..e247e183 100644 --- a/cmd/framework.go +++ b/cmd/framework.go @@ -23,7 +23,7 @@ import ( ) var scanInfo cautils.ScanInfo -var supportedFrameworks = []string{"nsa"} +var supportedFrameworks = []string{"nsa", "mitre"} type CLIHandler struct { policyHandler *policyhandler.PolicyHandler @@ -39,7 +39,7 @@ var frameworkCmd = &cobra.Command{ if len(args) < 1 && !(cmd.Flags().Lookup("use-from").Changed) { return fmt.Errorf("requires at least one argument") } else if len(args) > 0 { - if !isValidFramework(args[0]) { + if !isValidFramework(strings.ToLower(args[0])) { return fmt.Errorf(fmt.Sprintf("supported frameworks: %s", strings.Join(supportedFrameworks, ", "))) } } @@ -50,7 +50,7 @@ var frameworkCmd = &cobra.Command{ scanInfo.PolicyIdentifier.Kind = opapolicy.KindFramework if !(cmd.Flags().Lookup("use-from").Changed) { - scanInfo.PolicyIdentifier.Name = args[0] + scanInfo.PolicyIdentifier.Name = strings.ToLower(args[0]) } if len(args) > 0 { if len(args[1:]) == 0 || args[1] != "-" { diff --git a/docs/favicon.ico b/docs/favicon.ico new file mode 100644 index 00000000..038e7cf0 Binary files /dev/null and b/docs/favicon.ico differ diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 00000000..add13cd3 --- /dev/null +++ b/docs/index.html @@ -0,0 +1,24 @@ + + + + + Kubscape Website + + + + + + + Kubescap logo + + + + \ No newline at end of file diff --git a/install.ps1 b/install.ps1 new file mode 100644 index 00000000..0bbcf61b --- /dev/null +++ b/install.ps1 @@ -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 diff --git a/website/index.html b/website/index.html new file mode 100644 index 00000000..9c7d7b85 --- /dev/null +++ b/website/index.html @@ -0,0 +1,14 @@ + + + + Kubscape Website + +

Kubscape Website

+ + +

+ Join us!!! + +

+ + \ No newline at end of file