diff --git a/.gitignore b/.gitignore index 74dc99a6..0d0871de 100644 --- a/.gitignore +++ b/.gitignore @@ -146,3 +146,6 @@ cai.png cai.dot cai*.png test_20* + +# CI +!ci/build/ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 00000000..5b1cfdce --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,25 @@ +stages: + - build + - setup + - test # unit tests validation + - ctf-super-easy # "Super easy" CTF challenges coming out of PentestPerf + - ctf-easy # "Easy" CTF challenges coming out of PentestPerf + - ctf-medium # "Medium" CTF challenges coming out of PentestPerf + - ctf-hard # "Hard" CTF challenges coming out of PentestPerf + - ctf-super-hard # "Super hard" CTF challenges coming out of PentestPerf + +variables: + DOCKER_HOST: tcp://docker:2375 + DOCKER_DRIVER: overlay2 + DOCKER_TLS_CERTDIR: "" + VERSION: "0.1" + DISTRO: ubuntu:22.04 + +include: + - project: 'aliasrobotics/alias_research/cai' + ref: main + file: + - 'ci/build_container/.build.yml' # build + #- 'ci/setup/.setup.yml' # setup + - 'ci/test/.test.yml' # test + #- 'ci/ctfs/.ctf.yml' # ctf diff --git a/README.md b/README.md index 957a2f23..3843823c 100644 --- a/README.md +++ b/README.md @@ -377,8 +377,8 @@ CAI is developed by [Alias Robotics](https://aliasrobotics.com) and funded as pa - [x] re-organize tools - [ ] add tests -> Fill up all empty files or remove them - [x] add tests + - [ ] review agent tests and use pytest utilities (parametrize, etc) - [ ] CI - - [ ] Tracing - [ ] Graph/flow and other abstractions - [ ] Plan/router diff --git a/ci/build/.build.yml b/ci/build/.build.yml new file mode 100644 index 00000000..e0a6f168 --- /dev/null +++ b/ci/build/.build.yml @@ -0,0 +1,48 @@ +# +# TEMPLATE: +# The following pieces create containers on the go +# to facilitate reproduction of jobs. +# +.base_attacker_container: &base_attacker_container + stage: build + image: docker:latest + services: + - docker:dind + before_script: + # - echo $CI_JOB_TOKEN | docker login -u gitlab-ci-token --password-stdin $CI_REGISTRY; + - | + for i in $(seq 1 5); do + echo $CI_JOB_TOKEN | docker login -u gitlab-ci-token --password-stdin $CI_REGISTRY_IMAGE && break || sleep 10 + + echo "Retrying docker login ($i/5)..." + done + - apk add --no-cache docker-compose + script: + - cat .devcontainer/Dockerfile > Dockerfile_base + # Build the image + - docker build -t $CI_REGISTRY_IMAGE:$TAGGING -f Dockerfile_base . + - docker push $CI_REGISTRY_IMAGE:$TAGGING + +# +# JOB: +# A job to create the base container image for the attacker +# in x86_64. +# +# NOTE: Enable only if base container needs to be rebuilt. +# this will typically be the case whenever we change +# .devcontainer/Dockerfile +# +🚧 base_attacker_container: + variables: + TAGGING: latest + <<: *base_attacker_container + tags: # local runners won't have the right configuration + - p40 + - x86 + rules: + - if: '$CI_COMMIT_BRANCH' + changes: + - .devcontainer/Dockerfile + - ci/build/**/* + when: on_success + - when: never diff --git a/ci/test/.test.yml b/ci/test/.test.yml new file mode 100644 index 00000000..d9f4dc9b --- /dev/null +++ b/ci/test/.test.yml @@ -0,0 +1,29 @@ + +.use_base_container: &use_base_container + stage: test + image: "${CI_REGISTRY_IMAGE}:latest" + services: + - name: docker:dind + +.run_test: &run_test + <<: *use_base_container + script: + - pip3 install -e . + - pytest $TEST_PATH -s + tags: + - p40 + - x86 + rules: + - if: $CI_COMMIT_BRANCH + when: on_success + +🏗️ tools reconnaissance/filesystem: + <<: *run_test + variables: + TEST_PATH: tests/tools/reconnaissance/test_filesystem.py + + +# 🏗️ tools test_list_dir: +# <<: *run_test +# variables: +# TEST_PATH: tests/tests/tools/reconnaissance/filesystem/list_dir.py diff --git a/tests/reconnaissance/test_filesystem.py b/tests/tools/reconnaissance/test_filesystem.py similarity index 100% rename from tests/reconnaissance/test_filesystem.py rename to tests/tools/reconnaissance/test_filesystem.py