diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index f232127c..a0f30262 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -58,3 +58,32 @@ jobs: labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max + + + # DO NOT PUBLISH THE WHITEBOX VERSION FOR NOW + # # Extract metadata (tags, labels) for Docker Whitebox variant + # - name: Extract Docker metadata (Whitebox) + # id: meta-whitebox + # uses: docker/metadata-action@v5 + # with: + # images: ${{ env.IMAGE_NAME }} + # flavor: | + # latest=auto + # suffix=-whitebox,onlatest=true + # tags: | + # type=raw,value=latest,enable={{is_default_branch}} + # type=ref,event=branch + # type=ref,event=tag + # type=sha + + # - name: Build and push Docker image (Whitebox) + # uses: docker/build-push-action@v5 + # with: + # context: . + # push: ${{ github.event_name != 'pull_request' }} # Don't push on PRs, just build + # tags: ${{ steps.meta-whitebox.outputs.tags }} + # labels: ${{ steps.meta-whitebox.outputs.labels }} + # build-args: | + # GAME_MODULE=netsecgame.game.worlds.WhiteBoxNetSecGame + # cache-from: type=gha + # cache-to: type=gha,mode=max diff --git a/Dockerfile b/Dockerfile index 58a470ae..591e5f55 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,11 +22,15 @@ WORKDIR ${DESTINATION_DIR} # If a requirements.txt file is in the repository RUN if [ -f pyproject.toml ]; then pip install .[server] ; fi +ARG GAME_MODULE="netsecgame.game.worlds.NetSecGame" +# Pass the build argument to an environment variable so CMD can use it +ENV ENV_GAME_MODULE=$GAME_MODULE + # Expose the port the coordinator will run on EXPOSE 9000 # Run the Python script when the container launches (with default arguments --task_config=netsecenv_conf.yaml --game_port=9000 --game_host=0.0.0.0) -ENTRYPOINT ["python3", "-m", "netsecgame.game.worlds.NetSecGame", "--task_config=netsecenv_conf.yaml", "--game_port=9000", "--game_host=0.0.0.0"] +ENTRYPOINT ["sh", "-c", "exec python3 -m ${ENV_GAME_MODULE} --task_config=netsecenv_conf.yaml --game_port=9000 --game_host=0.0.0.0 \"$@\"", "--"] # Default command arguments (can be overridden at runtime) CMD ["--debug_level=INFO"] diff --git a/NetSecGameAgents b/NetSecGameAgents index 8ac0af82..085692da 160000 --- a/NetSecGameAgents +++ b/NetSecGameAgents @@ -1 +1 @@ -Subproject commit 8ac0af82d6d9769e73aab3926ff98ee996ed66d2 +Subproject commit 085692da0d85635bfa7343d8900f8621bbd132e9 diff --git a/README.md b/README.md index 6d42ed0f..4dcd348c 100755 --- a/README.md +++ b/README.md @@ -18,6 +18,13 @@ Optionally, you can build the image locally with: docker build -t netsecgame:local . ``` +To build a Whitebox version of the game image locally, you can use the `--build-arg` flag to override the default module path: +> [!WARNING] +> The Whitebox variant is currently experimental. +```bash +docker build --build-arg GAME_MODULE="netsecgame.game.worlds.WhiteBoxNetSecGame" -t netsecgame:local-whitebox . +``` + ### Installing from source In case you need to modify the envirment and run directly, we recommed to insall it in a virtual environemnt (Python vevn or Conda): #### Python venv diff --git a/examples/example_task_configuration.yaml b/examples/example_task_configuration.yaml index 084054f6..933c3978 100644 --- a/examples/example_task_configuration.yaml +++ b/examples/example_task_configuration.yaml @@ -7,7 +7,7 @@ coordinator: agents: Attacker: # Configuration of 'Attacker' agents - max_steps: 25 + max_steps: 50 goal: description: "Exfiltrate data from Samba server to remote C&C server." is_any_part_of_goal_random: True diff --git a/netsecgame/game/worlds/WhiteBoxNetSecGame.py b/netsecgame/game/worlds/WhiteBoxNetSecGame.py index b6135fd6..277fc239 100644 --- a/netsecgame/game/worlds/WhiteBoxNetSecGame.py +++ b/netsecgame/game/worlds/WhiteBoxNetSecGame.py @@ -15,8 +15,8 @@ class WhiteBoxNetSecGame(NetSecGame): WhiteBoxNetSecGame is an extension for the NetSecGame environment that provides list of all possible actions to each agent that registers in the game. """ - def __init__(self, game_host, game_port, task_config, allowed_roles=["Attacker", "Defender", "Benign"], seed=42, include_block_action=False): - super().__init__(game_host, game_port, task_config, allowed_roles, seed) + def __init__(self, game_host, game_port, task_config, seed=None, include_block_action=True): + super().__init__(game_host, game_port, task_config, seed) self._all_actions = None self._include_block_action = include_block_action