From 65f7fd0131924afe721c6c4c959fc7f1647cfa5e Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Mon, 18 Oct 2021 16:06:04 +0300 Subject: [PATCH 01/13] Deployments: change the outputs of appimage build and docker build to conform to the naming convention of InfectionMonkey-v*.* AppImages are built into InfectionMonkey-v1.11.0.AppImage Docker is build into InfectionMonkey-docker-v1.11.0.tgz --- build_scripts/appimage/appimage.sh | 5 +++-- build_scripts/appimage/clean.sh | 4 ++-- build_scripts/docker/docker.sh | 13 +++++++------ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/build_scripts/appimage/appimage.sh b/build_scripts/appimage/appimage.sh index 4b575e568..39d606e3d 100755 --- a/build_scripts/appimage/appimage.sh +++ b/build_scripts/appimage/appimage.sh @@ -119,7 +119,8 @@ build_package() { --deploy-deps-only="$MONGO_PATH/bin/mongod"\ --output appimage - move_package_to_dist_dir $dist_dir + dst_name="InfectionMonkey-v$version.AppImage" + move_package_to_dist_dir $dist_dir $dst_name popd } @@ -135,5 +136,5 @@ set_version() { } move_package_to_dist_dir() { - mv Infection_Monkey*.AppImage "$1/" + mv Infection_Monkey*.AppImage "$1/$2" } diff --git a/build_scripts/appimage/clean.sh b/build_scripts/appimage/clean.sh index 6ce76cd32..98f89b7e4 100755 --- a/build_scripts/appimage/clean.sh +++ b/build_scripts/appimage/clean.sh @@ -8,5 +8,5 @@ APPIMAGE_DIR="$(realpath $(dirname $BASH_SOURCE[0]))" rm -rf "$HOME/git/monkey" rm -rf "$HOME/.monkey_island" rm -rf "$APPIMAGE_DIR/squashfs-root" -rm "$APPIMAGE_DIR"/Infection_Monkey*x86_64.AppImage -rm "$APPIMAGE_DIR/../dist/Infection_Monkey*x86_64.AppImage" +rm "$APPIMAGE_DIR"/Infection_Monkey*.AppImage +rm "$APPIMAGE_DIR/../dist/InfectionMonkey*.AppImage" diff --git a/build_scripts/docker/docker.sh b/build_scripts/docker/docker.sh index 6f55ff6a0..24fdd6455 100755 --- a/build_scripts/docker/docker.sh +++ b/build_scripts/docker/docker.sh @@ -1,5 +1,4 @@ DOCKER_DIR="$(realpath $(dirname $BASH_SOURCE[0]))" -OUTPUT_NAME_TGZ="$DOCKER_DIR/infection_monkey_docker_$(date +%Y%m%d_%H%M%S).tgz" source "$DOCKER_DIR/../common.sh" @@ -41,12 +40,14 @@ build_package() { pushd ./docker docker_image_name="guardicore/monkey-island:$version" - tar_name="$DOCKER_DIR/dk.monkeyisland.$version.tar" + tar_name="$DOCKER_DIR/InfectionMonkey-docker-v$version.tar" build_docker_image_tar "$docker_image_name" "$tar_name" - build_docker_image_tgz "$tar_name" "$version" - move_package_to_dist_dir $dist_dir + tgz_name="$DOCKER_DIR/InfectionMonkey-docker-v$version.tgz" + build_docker_image_tgz "$tar_name" "$tgz_name" + + move_package_to_dist_dir $tgz_name $dist_dir popd } @@ -60,9 +61,9 @@ build_docker_image_tgz() { mkdir tgz mv "$1" ./tgz cp ./DOCKER_README.md ./tgz/README.md - tar -C ./tgz -cvf "$OUTPUT_NAME_TGZ" --gzip . + tar -C ./tgz -cvf "$2" --gzip . } move_package_to_dist_dir() { - mv $OUTPUT_NAME_TGZ "$1/" + mv "$1" "$2/" } From 226c72df5f5dc694276553ec2dd1110468078d8c Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Mon, 18 Oct 2021 17:33:19 +0300 Subject: [PATCH 02/13] Deployments: Rename appImage deployment only if a specific version is not specified With this change, Jenkins will output packages in the following naming conventions: Develop: InfectionMonkey-$commit_number_x86_64.AppImage Release: InfectionMonkey-v$version.AppImage --- build_scripts/appimage/appimage.sh | 17 +++++++++++------ build_scripts/appimage/infection-monkey.desktop | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/build_scripts/appimage/appimage.sh b/build_scripts/appimage/appimage.sh index 39d606e3d..5e2a25245 100755 --- a/build_scripts/appimage/appimage.sh +++ b/build_scripts/appimage/appimage.sh @@ -119,7 +119,12 @@ build_package() { --deploy-deps-only="$MONGO_PATH/bin/mongod"\ --output appimage - dst_name="InfectionMonkey-v$version.AppImage" + # Rename to + if $IS_RELEASE_BUILD; then + dst_name="InfectionMonkey-v$version.AppImage" + else + dst_name="" + fi move_package_to_dist_dir $dist_dir $dst_name popd @@ -127,14 +132,14 @@ build_package() { set_version() { # The linuxdeploy and appimage-builder tools will use the commit hash of the - # repo to name the AppImage, which is preferable to using "dev". If the - # version was specified in a command-line argument (i.e. not "dev"), then + # repo to name the AppImage. If the + # version was specified in a command-line argument, then # setting the VERSION environment variable will change this behavior. - if [ $1 != "dev" ]; then - export VERSION=$1 + if [ -n "$1" ]; then + export VERSION="$1" fi } move_package_to_dist_dir() { - mv Infection_Monkey*.AppImage "$1/$2" + mv InfectionMonkey*.AppImage "$1/$2" } diff --git a/build_scripts/appimage/infection-monkey.desktop b/build_scripts/appimage/infection-monkey.desktop index dcefbb51a..f53feaab9 100644 --- a/build_scripts/appimage/infection-monkey.desktop +++ b/build_scripts/appimage/infection-monkey.desktop @@ -1,6 +1,6 @@ [Desktop Entry] Type=Application -Name=Infection Monkey +Name=InfectionMonkey Exec=bash Comment=An automated breach and attack simulation platform Icon=monkey-icon From 25df96da63ce6f6191eb85d3585897f81891717e Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Mon, 18 Oct 2021 17:45:14 +0300 Subject: [PATCH 03/13] Deployments: Rename docker deployment only if a version is not specified With this change, Jenkins will output docker packages in the following naming conventions: Develop: InfectionMonkey-docker-$commit_number.tgz Release: InfectionMonkey-docker-v$version.tgz --- build_scripts/docker/docker.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/build_scripts/docker/docker.sh b/build_scripts/docker/docker.sh index 24fdd6455..860667de6 100755 --- a/build_scripts/docker/docker.sh +++ b/build_scripts/docker/docker.sh @@ -39,12 +39,18 @@ build_package() { local dist_dir=$2 pushd ./docker + if [ -n "$1" ]; then + version="v$(git rev-parse --short HEAD)" + else + version="v$version" + fi + docker_image_name="guardicore/monkey-island:$version" - tar_name="$DOCKER_DIR/InfectionMonkey-docker-v$version.tar" + tar_name="$DOCKER_DIR/InfectionMonkey-docker-$version.tar" build_docker_image_tar "$docker_image_name" "$tar_name" - tgz_name="$DOCKER_DIR/InfectionMonkey-docker-v$version.tgz" + tgz_name="$DOCKER_DIR/InfectionMonkey-docker-$version.tgz" build_docker_image_tgz "$tar_name" "$tgz_name" move_package_to_dist_dir $tgz_name $dist_dir From 46ef9df1d2a1804276559c0a2a5487abc76bdc63 Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Mon, 18 Oct 2021 17:46:41 +0300 Subject: [PATCH 04/13] Deployments: change the default monkey_version to "" If the version is none (default) the commit number will be used which is preferred in dev environment --- build_scripts/build_package.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build_scripts/build_package.sh b/build_scripts/build_package.sh index eebae5d89..26ca5588d 100755 --- a/build_scripts/build_package.sh +++ b/build_scripts/build_package.sh @@ -44,7 +44,6 @@ echo_help() { echo " (Default: $DEFAULT_REPO_MONKEY_HOME)" echo "" echo "--version A version number for the package." - echo " (Default: dev)" echo "" echo "--deployment A deployment type for the package." echo " (Default: develop)" @@ -110,7 +109,7 @@ agent_binary_dir="" as_root=false branch="develop" monkey_repo="$DEFAULT_REPO_MONKEY_HOME" -monkey_version="dev" +monkey_version="" package="" deployment_type="" From eedf4484bc6b39e3fdc0f03c5c89aa2aa60877c1 Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Tue, 19 Oct 2021 12:12:25 +0300 Subject: [PATCH 05/13] Deployments: fix the extraction of commit number in docker.sh --- build_scripts/docker/docker.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/build_scripts/docker/docker.sh b/build_scripts/docker/docker.sh index 860667de6..af719fb0d 100755 --- a/build_scripts/docker/docker.sh +++ b/build_scripts/docker/docker.sh @@ -15,6 +15,8 @@ setup_build_dir() { copy_entrypoint_to_build_dir "$build_dir" + build_commit=$(git rev-parse --git-dir "$monkey_repo" --short HEAD) + copy_monkey_island_to_build_dir "$monkey_repo/monkey" "$build_dir" copy_server_config_to_build_dir "$build_dir" modify_deployment "$deployment_type" "$build_dir" @@ -40,9 +42,9 @@ build_package() { pushd ./docker if [ -n "$1" ]; then - version="v$(git rev-parse --short HEAD)" - else version="v$version" + else + version="v$build_commit" fi docker_image_name="guardicore/monkey-island:$version" From 6b0a689adb72a03f0c63329e504747e38ae4dd7d Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Tue, 19 Oct 2021 11:02:50 -0400 Subject: [PATCH 06/13] Docker: Fix `git rev-parse` command Add -C to git command in order to execute rev-parse outside the repo. --- build_scripts/docker/docker.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build_scripts/docker/docker.sh b/build_scripts/docker/docker.sh index af719fb0d..519cc54d0 100755 --- a/build_scripts/docker/docker.sh +++ b/build_scripts/docker/docker.sh @@ -15,7 +15,7 @@ setup_build_dir() { copy_entrypoint_to_build_dir "$build_dir" - build_commit=$(git rev-parse --git-dir "$monkey_repo" --short HEAD) + build_commit=$(git -C "$monkey_repo" rev-parse --short HEAD) copy_monkey_island_to_build_dir "$monkey_repo/monkey" "$build_dir" copy_server_config_to_build_dir "$build_dir" @@ -44,7 +44,7 @@ build_package() { if [ -n "$1" ]; then version="v$version" else - version="v$build_commit" + version="$build_commit" fi docker_image_name="guardicore/monkey-island:$version" From 530ba633d286f835194e0d5632adbf33812799c5 Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Thu, 21 Oct 2021 14:36:01 +0200 Subject: [PATCH 07/13] Build: Add build commit to appimage build name --- build_scripts/appimage/appimage.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/build_scripts/appimage/appimage.sh b/build_scripts/appimage/appimage.sh index 5e2a25245..032ae7663 100755 --- a/build_scripts/appimage/appimage.sh +++ b/build_scripts/appimage/appimage.sh @@ -35,6 +35,8 @@ setup_build_dir() { mkdir -p "$BUILD_DIR" + build_commit=$(git -C "$monkey_repo" rev-parse --short HEAD) + copy_monkey_island_to_build_dir "$monkey_repo/monkey" "$BUILD_DIR" copy_server_config_to_build_dir modify_deployment "$deployment_type" "$BUILD_DIR" @@ -123,7 +125,7 @@ build_package() { if $IS_RELEASE_BUILD; then dst_name="InfectionMonkey-v$version.AppImage" else - dst_name="" + dst_name="InfectionMonkey-$build_commit.AppImage" fi move_package_to_dist_dir $dist_dir $dst_name From e406294b2845aea6ccf0ca5c3c465b66fa761b1c Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Thu, 21 Oct 2021 16:43:12 +0200 Subject: [PATCH 08/13] Changelog: Log for broken updates issue --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 929bf73f9..148637c72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,6 +59,7 @@ Changelog](https://keepachangelog.com/en/1.0.0/). - Bug that periodically cleared the telemetry table's filter. #1392 - Crashes, stack traces, and other malfunctions when data from older versions of Infection Monkey is present in the data directory. #1114 +- Broken update links. #1524 ### Security - Generate a random password when creating a new user for CommunicateAsNewUser From 6d827ad1af4fb280e7c5d67e280f45a799e723dd Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Thu, 21 Oct 2021 17:02:37 +0200 Subject: [PATCH 09/13] Build: Refactor commit id --- build_scripts/appimage/appimage.sh | 7 +++---- build_scripts/build_package.sh | 3 ++- build_scripts/common.sh | 5 +++++ build_scripts/docker/docker.sh | 7 +++---- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/build_scripts/appimage/appimage.sh b/build_scripts/appimage/appimage.sh index 032ae7663..5619d2525 100755 --- a/build_scripts/appimage/appimage.sh +++ b/build_scripts/appimage/appimage.sh @@ -35,8 +35,6 @@ setup_build_dir() { mkdir -p "$BUILD_DIR" - build_commit=$(git -C "$monkey_repo" rev-parse --short HEAD) - copy_monkey_island_to_build_dir "$monkey_repo/monkey" "$BUILD_DIR" copy_server_config_to_build_dir modify_deployment "$deployment_type" "$BUILD_DIR" @@ -107,7 +105,8 @@ remove_python_appdir_artifacts() { build_package() { local version=$1 - local dist_dir=$2 + local commit_id=$2 + local dist_dir=$3 log_message "Building AppImage" set_version "$version" @@ -125,7 +124,7 @@ build_package() { if $IS_RELEASE_BUILD; then dst_name="InfectionMonkey-v$version.AppImage" else - dst_name="InfectionMonkey-$build_commit.AppImage" + dst_name="InfectionMonkey-$commit_id.AppImage" fi move_package_to_dist_dir $dist_dir $dst_name diff --git a/build_scripts/build_package.sh b/build_scripts/build_package.sh index 26ca5588d..e787fdd35 100755 --- a/build_scripts/build_package.sh +++ b/build_scripts/build_package.sh @@ -198,7 +198,8 @@ install_package_specific_build_prereqs "$WORKSPACE" setup_build_dir "$agent_binary_dir" "$monkey_repo" "$deployment_type" -build_package "$monkey_version" "$DIST_DIR" +commit_id=$(get_commit_id "$monkey_repo") +build_package "$monkey_version" "$commit_id" "$DIST_DIR" log_message "Finished building package: $package" exit 0 diff --git a/build_scripts/common.sh b/build_scripts/common.sh index a8e7c190a..2f244fd51 100644 --- a/build_scripts/common.sh +++ b/build_scripts/common.sh @@ -93,3 +93,8 @@ remove_node_modules() { rm -rf "$1/node_modules" rm -rf "$1/.npm" } + +get_commit_id() { + local monkey_repo=$1 + echo $(git -C "$monkey_repo" rev-parse --short HEAD) +} diff --git a/build_scripts/docker/docker.sh b/build_scripts/docker/docker.sh index 519cc54d0..42004f8f7 100755 --- a/build_scripts/docker/docker.sh +++ b/build_scripts/docker/docker.sh @@ -15,8 +15,6 @@ setup_build_dir() { copy_entrypoint_to_build_dir "$build_dir" - build_commit=$(git -C "$monkey_repo" rev-parse --short HEAD) - copy_monkey_island_to_build_dir "$monkey_repo/monkey" "$build_dir" copy_server_config_to_build_dir "$build_dir" modify_deployment "$deployment_type" "$build_dir" @@ -38,13 +36,14 @@ copy_server_config_to_build_dir() { build_package() { local version=$1 - local dist_dir=$2 + local commit_id=$2 + local dist_dir=$3 pushd ./docker if [ -n "$1" ]; then version="v$version" else - version="$build_commit" + version="$commit_id" fi docker_image_name="guardicore/monkey-island:$version" From d55cbcfbd314bd1996762aa0571c6f389167b7a9 Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Thu, 21 Oct 2021 17:25:00 +0200 Subject: [PATCH 10/13] Build: Fix move package to dist dir on appimage --- build_scripts/appimage/appimage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_scripts/appimage/appimage.sh b/build_scripts/appimage/appimage.sh index 5619d2525..a5d0bebc0 100755 --- a/build_scripts/appimage/appimage.sh +++ b/build_scripts/appimage/appimage.sh @@ -142,5 +142,5 @@ set_version() { } move_package_to_dist_dir() { - mv InfectionMonkey*.AppImage "$1/$2" + mv Infection*Monkey*.AppImage "$1/$2" } From c3f581290610ea35111572bf0a78d608cda665d3 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Thu, 21 Oct 2021 12:19:08 -0400 Subject: [PATCH 11/13] Build: Refactor agent versioning --- build_scripts/appimage/appimage.sh | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/build_scripts/appimage/appimage.sh b/build_scripts/appimage/appimage.sh index a5d0bebc0..fead9901a 100755 --- a/build_scripts/appimage/appimage.sh +++ b/build_scripts/appimage/appimage.sh @@ -104,12 +104,16 @@ remove_python_appdir_artifacts() { } build_package() { - local version=$1 local commit_id=$2 local dist_dir=$3 log_message "Building AppImage" - set_version "$version" + + if [ -n "$1" ]; then + local version="v$1" + else + local version="$commit_id" + fi pushd "$APPIMAGE_DIR" ARCH="x86_64" linuxdeploy \ @@ -120,27 +124,12 @@ build_package() { --deploy-deps-only="$MONGO_PATH/bin/mongod"\ --output appimage - # Rename to - if $IS_RELEASE_BUILD; then - dst_name="InfectionMonkey-v$version.AppImage" - else - dst_name="InfectionMonkey-$commit_id.AppImage" - fi + dst_name="InfectionMonkey-$version.AppImage" move_package_to_dist_dir $dist_dir $dst_name popd } -set_version() { - # The linuxdeploy and appimage-builder tools will use the commit hash of the - # repo to name the AppImage. If the - # version was specified in a command-line argument, then - # setting the VERSION environment variable will change this behavior. - if [ -n "$1" ]; then - export VERSION="$1" - fi -} - move_package_to_dist_dir() { mv Infection*Monkey*.AppImage "$1/$2" } From fcc444b098ee3cce140237c07ba474c31d1bc230 Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Fri, 22 Oct 2021 10:03:18 +0300 Subject: [PATCH 12/13] Docs: change installer filenames in docker and appImage setup docs --- docs/content/setup/docker.md | 4 ++-- docs/content/setup/linux.md | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/content/setup/docker.md b/docs/content/setup/docker.md index d92aa1bf5..f195caf34 100644 --- a/docs/content/setup/docker.md +++ b/docs/content/setup/docker.md @@ -23,13 +23,13 @@ The Infection Monkey Docker container works on Linux only. It is not compatible 1. Extract the Monkey Island Docker tarball: ```bash - tar -xvzf monkey-island-docker.tar.gz + tar -xvzf InfectionMonkey-docker-v1.12.0.tgz ``` 1. Load the Monkey Island Docker image: ```bash - sudo docker load -i dk.monkeyisland.VERSION.tar + sudo docker load -i InfectionMonkey-docker-v1.12.0.tar ``` ### 2. Start MongoDB diff --git a/docs/content/setup/linux.md b/docs/content/setup/linux.md index 7fcd09d24..7d577f2a5 100644 --- a/docs/content/setup/linux.md +++ b/docs/content/setup/linux.md @@ -27,11 +27,11 @@ installed, but the ones that we've tested are: 1. Make the AppImage package executable: ```bash - chmod u+x Infection_Monkey_v1.11.0.AppImage + chmod u+x InfectionMonkey-v1.12.0.AppImage ``` 1. Start Monkey Island by running the Infection Monkey AppImage package: ```bash - ./Infection_Monkey_v1.11.0.AppImage + ./InfectionMonkey-v1.12.0.AppImage ``` 1. Access the Monkey Island web UI by pointing your browser at `https://localhost:5000`. @@ -56,7 +56,7 @@ private certificate authority. `server_config.json` file. ```bash - ./Infection_Monkey_v1.11.0.AppImage --setup-only + ./InfectionMonkey-v1.12.0.AppImage --setup-only ``` 1. (Optional but recommended) Move your `.crt` and `.key` files to @@ -92,7 +92,7 @@ private certificate authority. 1. Start Monkey Island by running the Infection Monkey AppImage package: ```bash - ./Infection_Monkey_v1.11.0.AppImage + ./InfectionMonkey-v1.12.0.AppImage ``` 1. Access the Monkey Island web UI by pointing your browser at From 82cffc4748dc8ed611bdb7d2716b0d5a946539e7 Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Fri, 22 Oct 2021 10:03:58 +0300 Subject: [PATCH 13/13] Docs: add a note about possibility to run AppImage from WSL --- docs/content/setup/linux.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/content/setup/linux.md b/docs/content/setup/linux.md index 7d577f2a5..275330c2c 100644 --- a/docs/content/setup/linux.md +++ b/docs/content/setup/linux.md @@ -23,6 +23,9 @@ installed, but the ones that we've tested are: - Ubuntu Focal 20.04 - Ubuntu Hirsute 21.04 +On Windows, AppImage can be run in WSL. + + ## Deployment 1. Make the AppImage package executable: