From 7374e615f2cf5375151a39d59369fe88813c73b7 Mon Sep 17 00:00:00 2001 From: Shreya Date: Mon, 26 Apr 2021 16:10:36 +0530 Subject: [PATCH 1/9] Add Swimm pre-commit hook --- .pre-commit-config.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5d4fc18d8..eab23793c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -43,3 +43,7 @@ repos: files: "monkey/" exclude: "monkey/monkey_island/cc/ui" stages: [push] + - repo: https://github.com/swimmio/pre-commit + rev: v0.2 + hooks: + - id: swimm-verify From af4aaf23c6c51fd324c6feae3574795405ce3b86 Mon Sep 17 00:00:00 2001 From: Shreya Date: Mon, 26 Apr 2021 18:08:37 +0530 Subject: [PATCH 2/9] Add Swimm to Linux deployment script --- deployment_scripts/config | 3 +++ deployment_scripts/deploy_linux.sh | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/deployment_scripts/config b/deployment_scripts/config index cad04a01c..101dadd0f 100644 --- a/deployment_scripts/config +++ b/deployment_scripts/config @@ -43,3 +43,6 @@ export TRACEROUTE_32_BINARY_URL="https://github.com/guardicore/monkey/releases/d export SAMBACRY_64_BINARY_URL="https://github.com/guardicore/monkey/releases/download/$MONKEY_LATEST_RELEASE/sc_monkey_runner64.so" export SAMBACRY_32_BINARY_URL="https://github.com/guardicore/monkey/releases/download/$MONKEY_LATEST_RELEASE/sc_monkey_runner32.so" + +# Swimm +export SWIMM_URL=https://github.com/swimmio/SwimmReleases/releases/download/v0.4.4-0/Swimm_0.4.4-0_Setup.deb diff --git a/deployment_scripts/deploy_linux.sh b/deployment_scripts/deploy_linux.sh index c003dd278..e5d798878 100755 --- a/deployment_scripts/deploy_linux.sh +++ b/deployment_scripts/deploy_linux.sh @@ -239,6 +239,15 @@ else curl -o ${MONKEY_BIN_DIR}/traceroute32 ${TRACEROUTE_32_BINARY_URL} fi +# Download Swimm +if exists wget; then + wget ${SWIMM_URL} -O $HOME/swimm +else + curl ${SWIMM_URL} -o $HOME/swimm +fi +sudo dpkg -i $HOME/swimm || (sudo apt-get update && sudo apt-get -f install) +sudo chmod +x $HOME/swimm + sudo chmod +x "${INFECTION_MONKEY_DIR}/build_linux.sh" configure_precommit ${python_cmd} ${monkey_home} From e58edfbd7e773c2b7715aff854f3c53891867722 Mon Sep 17 00:00:00 2001 From: Shreya Date: Mon, 26 Apr 2021 18:13:51 +0530 Subject: [PATCH 3/9] Add Swimm to Windows deployment script --- deployment_scripts/config.ps1 | 1 + deployment_scripts/deploy_windows.ps1 | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/deployment_scripts/config.ps1 b/deployment_scripts/config.ps1 index d140eb711..54ad20be9 100644 --- a/deployment_scripts/config.ps1 +++ b/deployment_scripts/config.ps1 @@ -46,3 +46,4 @@ $OPEN_SSL_URL = "https://indy.fulgan.com/SSL/openssl-1.0.2u-x64_86-win64.zip" $CPP_URL = "https://go.microsoft.com/fwlink/?LinkId=746572" $NPM_URL = "https://nodejs.org/dist/v12.14.1/node-v12.14.1-x64.msi" $UPX_URL = "https://github.com/upx/upx/releases/download/v3.96/upx-3.96-win64.zip" +$SWIMM_URL="https://github.com/swimmio/SwimmReleases/releases/download/v0.4.4-0/Swimm-Setup-0.4.4-0.exe" diff --git a/deployment_scripts/deploy_windows.ps1 b/deployment_scripts/deploy_windows.ps1 index 20f600f51..82c798512 100644 --- a/deployment_scripts/deploy_windows.ps1 +++ b/deployment_scripts/deploy_windows.ps1 @@ -267,6 +267,12 @@ function Deploy-Windows([String] $monkey_home = (Get-Item -Path ".\").FullName, $webClient.DownloadFile($SAMBA_64_BINARY_URL, $samba64_path) } + # Get Swimm + "Downloading Swimm..." + $swimm_filename = Join-Path -Path $HOME -ChildPath "swimm.exe" + $webClient.DownloadFile($SWIMM_URL, $swimm_filename) + Start-Process $swimm_filename + "Script finished" } From 4c8b3b04da0baf8596f04ae3c3032d339e5ce09b Mon Sep 17 00:00:00 2001 From: Shreya Date: Mon, 26 Apr 2021 18:25:34 +0530 Subject: [PATCH 4/9] Add Swimm details to dev env setup guide in docs --- docs/content/development/setup-development-environment.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/content/development/setup-development-environment.md b/docs/content/development/setup-development-environment.md index b7d122778..097e5713d 100644 --- a/docs/content/development/setup-development-environment.md +++ b/docs/content/development/setup-development-environment.md @@ -31,3 +31,9 @@ Pre-commit is a multi-language package manager for pre-commit hooks. It will run Our CI system runs the same checks when pull requests are submitted. This system may report that the build has failed if the pre-commit hooks have not been run or all issues have not been resolved. To install and configure pre-commit, run `pip install --user pre-commit`. Next, go to the top level directory of this repository and run `pre-commit install -t pre-commit -t pre-push`. Pre-commit will now run automatically whenever you `git commit`. + +## Swimm + +Infection Monkey has development tutorials that use [`swimm.io`](https://swimm.io/) to help teach new developers how to perform common code tasks in the Infection Monkey codebase and accelerate the ramp-up process. The tutorials include adding new configuration values, new system info collectors and more. + +In order to pass the pre-commit checks, you'll have to [install Swimm successfully](../swimm). From 60f776fef945e65a780b0f4487dd4b3c309e629a Mon Sep 17 00:00:00 2001 From: Shreya Date: Mon, 26 Apr 2021 19:00:40 +0530 Subject: [PATCH 5/9] Add Swimm details to deployment guide (deployment_scripts/README.md) --- deployment_scripts/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/deployment_scripts/README.md b/deployment_scripts/README.md index 7f4e414bd..aed00ae58 100644 --- a/deployment_scripts/README.md +++ b/deployment_scripts/README.md @@ -85,3 +85,9 @@ been run or all issues have not been resolved. To install and configure pre-commit manually, run `pip install --user pre-commit`. Next, go to the top level directory of this repository and run `pre-commit install -t pre-commit -t pre-push` Now, pre-commit will automatically run whenever you `git commit`. + +## Swimm + +Infection Monkey has development tutorials that use [`swimm.io`](https://swimm.io/) to help teach new developers how to perform common code tasks in the Infection Monkey codebase and accelerate the ramp-up process. The tutorials include adding new configuration values, new system info collectors and more. + +In order to pass the pre-commit checks, you'll have to [install Swimm successfully](https://www.guardicore.com/infectionmonkey/docs/development/swimm/). Both the Linux and Windows deployment scrips will install [Swimm](https://swimm.io/), but you'll have to sign up [here](https://swimm.io/sign-beta) to complete the process. From ba3317b252bbc5ac714e1d7ef1a67ade78873332 Mon Sep 17 00:00:00 2001 From: shreyamalviya Date: Tue, 27 Apr 2021 17:50:38 +0530 Subject: [PATCH 6/9] Set environment variable SKIP=swimm-verify in Windows deployment script so pre-commit skips swimm-verify --- deployment_scripts/deploy_windows.ps1 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/deployment_scripts/deploy_windows.ps1 b/deployment_scripts/deploy_windows.ps1 index 82c798512..3e10c365b 100644 --- a/deployment_scripts/deploy_windows.ps1 +++ b/deployment_scripts/deploy_windows.ps1 @@ -23,6 +23,10 @@ function Configure-precommit([String] $git_repo_dir) exit } Pop-Location + + # Set env variable to skip Swimm verification during pre-commit, Windows not supported yet + [System.Environment]::SetEnvironmentVariable('SKIP','swimm-verify',[System.EnvironmentVariableTarget]::User) + Write-Output "Pre-commit successfully installed" } @@ -273,6 +277,7 @@ function Deploy-Windows([String] $monkey_home = (Get-Item -Path ".\").FullName, $webClient.DownloadFile($SWIMM_URL, $swimm_filename) Start-Process $swimm_filename + "Script finished" } From 05dd10cd96aa9b48afaaeb297b23fb5905aeae9c Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 27 Apr 2021 23:31:51 +0530 Subject: [PATCH 7/9] Modify Swimm details in dev env setup docs --- docs/content/development/setup-development-environment.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content/development/setup-development-environment.md b/docs/content/development/setup-development-environment.md index 097e5713d..ad9a4675b 100644 --- a/docs/content/development/setup-development-environment.md +++ b/docs/content/development/setup-development-environment.md @@ -36,4 +36,4 @@ To install and configure pre-commit, run `pip install --user pre-commit`. Next, Infection Monkey has development tutorials that use [`swimm.io`](https://swimm.io/) to help teach new developers how to perform common code tasks in the Infection Monkey codebase and accelerate the ramp-up process. The tutorials include adding new configuration values, new system info collectors and more. -In order to pass the pre-commit checks, you'll have to [install Swimm successfully](../swimm). +In order to pass the pre-commit checks, you'll have to [install Swimm successfully](https://www.guardicore.com/infectionmonkey/docs/development/swimm/). Both the Linux and Windows deployment scrips will install [Swimm](https://swimm.io/), but you'll have to sign up [here](https://swimm.io/sign-beta) to complete the process. From 9383457518f2fe882054e40cf518f8829fcf7cc3 Mon Sep 17 00:00:00 2001 From: shreyamalviya Date: Wed, 28 Apr 2021 13:32:30 +0530 Subject: [PATCH 8/9] Modify Windows deployment script to check $env:SKIP before adding swimm-verify to it --- deployment_scripts/deploy_windows.ps1 | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/deployment_scripts/deploy_windows.ps1 b/deployment_scripts/deploy_windows.ps1 index 3e10c365b..46f2fb0f4 100644 --- a/deployment_scripts/deploy_windows.ps1 +++ b/deployment_scripts/deploy_windows.ps1 @@ -25,7 +25,15 @@ function Configure-precommit([String] $git_repo_dir) Pop-Location # Set env variable to skip Swimm verification during pre-commit, Windows not supported yet - [System.Environment]::SetEnvironmentVariable('SKIP','swimm-verify',[System.EnvironmentVariableTarget]::User) + $skipValue = [System.Environment]::GetEnvironmentVariable('SKIP', [System.EnvironmentVariableTarget]::User) + if ($skipValue) { # if `SKIP` is not empty + if (-Not ($skipValue -split ',' -contains 'swimm-verify')) { # if `SKIP` doesn't already have "swimm-verify" + [System.Environment]::SetEnvironmentVariable('SKIP', $env:SKIP + ',swimm-verify', [System.EnvironmentVariableTarget]::User) + } + } + else { + [System.Environment]::SetEnvironmentVariable('SKIP', 'swimm-verify', [System.EnvironmentVariableTarget]::User) + } Write-Output "Pre-commit successfully installed" } From 7c34288f1b06bb225fb1bf182e1f27c9a9ab6afe Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Wed, 28 Apr 2021 07:00:57 -0400 Subject: [PATCH 9/9] deployment: Remove swimm debian package after it is installed --- deployment_scripts/deploy_linux.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/deployment_scripts/deploy_linux.sh b/deployment_scripts/deploy_linux.sh index e5d798878..0aa018534 100755 --- a/deployment_scripts/deploy_linux.sh +++ b/deployment_scripts/deploy_linux.sh @@ -240,13 +240,16 @@ else fi # Download Swimm +log_message "Downloading swimm" if exists wget; then wget ${SWIMM_URL} -O $HOME/swimm else curl ${SWIMM_URL} -o $HOME/swimm fi + +log_message "Installing swimm" sudo dpkg -i $HOME/swimm || (sudo apt-get update && sudo apt-get -f install) -sudo chmod +x $HOME/swimm +rm $HOME/swimm sudo chmod +x "${INFECTION_MONKEY_DIR}/build_linux.sh"