-
Notifications
You must be signed in to change notification settings - Fork 3
Many improvements #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0710434
add poetry.lock
Res260 8aa9ec1
add .idea to .gitignore
Res260 37ef4e8
Add multiple files to `ctf init`: github CI tests, setup-codespace sc…
Res260 b20df33
add `--force` option to `ctf init`
Res260 543152a
README.md: Add description of the tool, feature list, CTF structure, …
Res260 a5fdf88
bump version to 1.2.0
Res260 5c239d0
PR fixes
Res260 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,4 +18,4 @@ challenges/*/terraform/versions.tf | |
| *.egg-info | ||
|
|
||
| .vscode/ | ||
|
|
||
| .idea | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MOBergeron marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| { | ||
| "image": "mcr.microsoft.com/devcontainers/base:ubuntu", | ||
| "features": { | ||
| "ghcr.io/robbert229/devcontainer-features/opentofu:1": { | ||
| "version": "1.9.0" | ||
| }, | ||
| "ghcr.io/devcontainers-extra/features/ansible:2": {} | ||
| }, | ||
| "runArgs": [ | ||
| "--privileged", | ||
| "--cap-add=SYS_PTRACE", | ||
| "--security-opt", "seccomp=unconfined", | ||
| "--cgroupns=host", | ||
| "--pid=host", | ||
| "--volume", "/dev:/dev", | ||
| "--volume", "/lib/modules:/lib/modules:ro" | ||
| ] | ||
| } |
Res260 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,218 @@ | ||
| name: Tests | ||
| on: | ||
| pull_request: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| check_changes: | ||
| name: Check changes | ||
| outputs: | ||
| run_job: ${{ steps.check_files.outputs.run_job }} | ||
| tracks: ${{ steps.check_files.outputs.tracks }} | ||
| runs-on: ubuntu-24.04 | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Check modified files | ||
| id: check_files | ||
| run: | | ||
| tracks=() | ||
| echo "run_job=false" > "$GITHUB_OUTPUT" | ||
| while IFS= read -r file | ||
| do | ||
| if [[ $file == challenges/*/ansible/** || $file == challenges/*/terraform/** || $file == scripts/*.py || $file == .deploy/* ]]; then | ||
| echo "[+] Detected required deployment because of file: ${file}" | ||
| echo "run_job=true" > "$GITHUB_OUTPUT" | ||
| if [[ $file == scripts/*.py || $file == .deploy/* ]]; then | ||
| echo "[!] Running full deployment to properly test the scripts or .deploy changes." | ||
| tracks=() | ||
| break | ||
| else | ||
| track=$(sed -E 's/challenges\/(.+)\/(ansible|terraform)\/.*/\1/g' <<< "$file") | ||
| if [[ ! " ${tracks[*]} " =~ [[:space:]]${track}[[:space:]] ]]; then | ||
| tracks+=("$track") | ||
| fi | ||
| fi | ||
| fi | ||
| done < <(git diff --name-only origin/main..) | ||
| echo "tracks=${tracks[*]}" >> "$GITHUB_OUTPUT" | ||
|
|
||
| static_validations: | ||
| name: Static validations | ||
| timeout-minutes: 5 | ||
| runs-on: ubuntu-24.04 | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup OpenTofu | ||
| run: | | ||
| curl -sL https://get.opentofu.org/install-opentofu.sh -o install-opentofu.sh | ||
| chmod +x install-opentofu.sh | ||
| ./install-opentofu.sh --install-method deb | ||
| rm -f install-opentofu.sh | ||
|
|
||
| - name: Install python dependencies | ||
| run: | | ||
| pip install git+https://github.com/nsec/ctf-script.git | ||
|
|
||
| - name: Run ctf validate | ||
| run: | | ||
| ctf validate | ||
|
|
||
| deploy: | ||
| name: Full deployment test | ||
| needs: check_changes | ||
| if: needs.check_changes.outputs.run_job == 'true' | ||
| timeout-minutes: 180 | ||
| strategy: | ||
| fail-fast: false | ||
| runs-on: ubuntu-24.04 | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Git LFS Pull for deployment | ||
| run: | | ||
| tracks="${{needs.check_changes.outputs.tracks}}" | ||
|
|
||
| if [ -z "$tracks" ]; then | ||
| echo "Pulling all Git LFS" | ||
| git lfs pull -I **/challenges/**/ansible/**/* | ||
| else | ||
| IFS=' ' read -ra tracks <<< "$tracks" | ||
|
|
||
| for track in "${tracks[@]}" | ||
| do | ||
| echo "Pulling Git LFS for ${track}, if any..." | ||
| git lfs pull -I **/challenges/"$track"/ansible/**/* | ||
| done | ||
| fi | ||
|
|
||
| echo "Pulled files:" | ||
| { git lfs ls-files | grep -E '[a-f0-9]{10}\s\*'; } || true | ||
|
|
||
| - name: Remove docker | ||
| run: | | ||
| sudo apt-get autopurge -y moby-containerd docker uidmap | ||
| sudo ip link delete docker0 | ||
| sudo nft flush ruleset | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| sudo apt-get install --no-install-recommends --yes zfsutils-linux | ||
|
|
||
| - name: Setup squid | ||
| run: | | ||
| sudo apt-get install --no-install-recommends --yes squid | ||
|
|
||
| ( | ||
| cat << EOF | ||
| # No logging | ||
| cache_access_log /dev/null | ||
| cache_store_log none | ||
| cache_log /dev/null | ||
|
|
||
| # Caching | ||
| maximum_object_size 200 MB | ||
| cache_mem 1024 MB | ||
|
|
||
| # Port and mode configuration | ||
| acl local_subnet src 9000::/16 | ||
| http_access allow local_subnet | ||
| http_access deny all | ||
| http_port [2602:fc62:ef:11::2]:3128 | ||
|
|
||
| # Hide our traces | ||
| forwarded_for transparent | ||
| via off | ||
| reply_header_access X-Cache deny all | ||
| reply_header_access X-Cache-Lookup deny all | ||
|
|
||
| EOF | ||
| ) | sudo tee /etc/squid/conf.d/ctf.conf | ||
|
|
||
| sudo systemctl restart squid --no-block | ||
| sudo ip -6 a add dev lo 2602:fc62:ef:11::2/128 | ||
|
|
||
| - name: Setup Incus | ||
| run: | | ||
| curl https://pkgs.zabbly.com/get/incus-stable | sudo sh | ||
| sudo chmod 666 /var/lib/incus/unix.socket | ||
|
|
||
| incus network create incusbr0 | ||
| incus profile device add default eth0 nic network=incusbr0 name=eth0 | ||
|
|
||
| incus storage create default zfs size=100GiB | ||
| incus profile device add default root disk pool=default path=/ | ||
|
|
||
| sudo zfs set sync=disabled default | ||
|
|
||
| sudo ip6tables -I FORWARD -j REJECT | ||
|
|
||
| - name: Setup Ansible | ||
| run: | | ||
| pipx install --force --include-deps ansible | ||
| pipx inject ansible passlib | ||
|
|
||
| - name: Setup OpenTofu | ||
| run: | | ||
| curl -sL https://get.opentofu.org/install-opentofu.sh -o install-opentofu.sh | ||
| chmod +x install-opentofu.sh | ||
| ./install-opentofu.sh --install-method deb | ||
| rm -f install-opentofu.sh | ||
|
|
||
| - name: Install python dependencies | ||
| run: | | ||
| pip install -e . | ||
|
|
||
| - name: Deployment check | ||
| run: | | ||
| tracks="${{needs.check_changes.outputs.tracks}}" | ||
|
|
||
| if [ -z "$tracks" ]; then | ||
| ctf check | ||
| else | ||
| ctf check --tracks $tracks | ||
| fi | ||
|
|
||
| - name: File generation | ||
| run: | | ||
| tracks="${{needs.check_changes.outputs.tracks}}" | ||
|
|
||
| if [ -z "$tracks" ]; then | ||
| ctf generate | ||
| else | ||
| ctf generate --tracks $tracks | ||
| fi | ||
|
|
||
| - name: Test deployment | ||
| run: | | ||
| tracks="${{needs.check_changes.outputs.tracks}}" | ||
|
|
||
| if [ -z "$tracks" ]; then | ||
| tracks="$(python3 -c 'from scripts.utils import get_all_available_tracks,validate_track_can_be_deployed;print(str([t for t in get_all_available_tracks() if validate_track_can_be_deployed(t)]).strip("[]\x27").replace("\x27, \x27"," "))')" | ||
| fi | ||
|
|
||
| IFS=" " read -r -a tracks <<< "$tracks" | ||
|
|
||
| for track in "${tracks[@]}" | ||
| do | ||
| ctf deploy --production --tracks "$track" | ||
| done | ||
|
|
||
| - name: Check deployment results | ||
| run: | | ||
| incus project list | ||
| incus network zone record list ctf | ||
| incus network list --all-projects | ||
| incus list --all-projects |
MOBergeron marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,4 +18,6 @@ challenges/*/terraform/versions.tf | |
| *.egg-info | ||
|
|
||
| .vscode/ | ||
| !.vscode/settings.json | ||
| !.vscode/extensions.json | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "recommendations": [ | ||
| "redhat.vscode-yaml", | ||
| "hashicorp.terraform", | ||
| "github.codespaces", | ||
| "redhat.ansible" | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "[yaml]": { | ||
| "editor.tabSize": 2 | ||
| }, | ||
| "yaml.schemas": { | ||
| "scripts/schemas/track.yaml.json": "challenges/**/track.yaml", | ||
| "scripts/schemas/post.json": "challenges/*/posts/*.yaml" | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.