28 Commits
Author SHA1 Message Date
adguard-cidre-ci fba41f5da7 Bump build version to 1.5.5 [skip ci] 2026-11-28 04:07:49 +00:00
Boteex Bot ec7fef42df Pin python Docker tag to 0f9552b (#30)
CI / build-and-scan (push) Successful in 48s
2026-11-28 05:03:27 +01:00
Djeex d4869064e6 Use the shared cicdeex actions (#29)
CI / build-and-scan (push) Successful in 32s
Co-authored-by: Djeex <[email protected]>
2026-11-22 13:20:37 +01:00
Djeex 711dd000a5 Merge pull request 'Run the weekly scan on Saturday' (#28) from ci-align into main
CI / build-and-scan (push) Successful in 43s
2026-11-21 23:48:35 +01:00
Djeex 97e30ebf06 Run the weekly scan on Saturday
CI / build-and-scan (pull_request) Successful in 38s
2026-11-21 22:31:35 +00:00
Djeex bde49062b9 Merge pull request 'Use the shared Renovate preset' (#27) from renovate-preset into main
CI / build-and-scan (push) Successful in 1m6s
2026-11-21 22:12:02 +01:00
Djeex 11d84c91c9 Use the shared Renovate preset
CI / build-and-scan (pull_request) Successful in 31s
2026-11-21 20:56:56 +00:00
Djeex e84aecaf35 Do not pin digests for CI tool images (#25)
CI / build-and-scan (push) Successful in 27s
## Summary
- `pinDigests: false` for the custom regex manager (CI tool images in `docker run`/`docker create`). Renovate cannot write a digest in those lines, so its `pin-dependencies` branch failed with `update failure` and no Dockerfile digest was pinned.

## Test plan
- [ ] CI green on this PR
- [ ] After merge, the next Renovate run opens a `pin` PR for the Dockerfile digests, without `update failure`
- [ ] Trivy/gitleaks/hadolint updates keep working

Reviewed-on: #25
Co-authored-by: Djeex <[email protected]>
2026-11-21 19:45:42 +01:00
Djeex 4cd835f708 Merge pull request 'Update aquasec/trivy Docker tag to v0.76.2' (#24) from renovate/aquasec-trivy-0.x into main
CI / build-and-scan (push) Successful in 1m0s
2026-11-21 19:25:55 +01:00
Djeex 9a4930ff4a Update aquasec/trivy Docker tag to v0.76.2
renovate/stability-days Updates have met minimum release age requirement
CI / build-and-scan (pull_request) Successful in 24s
2026-11-21 18:17:15 +00:00
Djeex 01dbf55e93 Track CI tool images with Renovate (#23)
CI / build-and-scan (push) Successful in 2m16s
## Summary
- Custom Renovate manager for the CI tool images pinned in `docker run`/`docker create` commands (Trivy, gitleaks, hadolint), which the default managers do not detect.
- Renovate will now open PRs to bump them; they are not automerged.

## Test plan
- [ ] CI green on this PR
- [ ] After merge, Renovate opens a PR bumping Trivy
- [ ] That PR passes CI before merging

Reviewed-on: #23
Co-authored-by: Djeex <[email protected]>
2026-11-21 18:46:36 +01:00
Djeex ec4ef966bf Pin image digests and add minimum release age (#22)
CI / build-and-scan (push) Successful in 27s
## Summary
- `docker:pinDigests`: Renovate pins image digests and opens digest PRs when a base image is rebuilt, so security fixes are picked up.
- `minimumReleaseAge`: 3 days globally, 7 days for pip.
- Automerge for `pin` and `digest` updates, like patch updates.

## Test plan
- [ ] CI green on this PR
- [ ] After merge, Renovate opens a pin PR for the Dockerfile digests
- [ ] That PR automerges once CI passes

Reviewed-on: #22
Co-authored-by: Djeex <[email protected]>
2026-11-21 18:11:46 +01:00
Djeex 9cbdb38547 Update dependency pyyaml to v6.0.4 (#21)
CI / build-and-scan (push) Successful in 29s
Co-authored-by: Djeex <[email protected]>
2026-11-21 01:06:07 +01:00
adguard-cidre-ci f5c388beeb Bump build version to 1.5.4 [skip ci] 2026-10-30 04:16:48 +00:00
Djeex b80f466f35 Update python Docker tag to v3.15.2
CI / build-and-scan (pull_request) Successful in 1m2s
CI / build-and-scan (push) Successful in 37s
2026-10-30 04:05:13 +00:00
adguard-cidre-ci 880143c9b8 Bump build version to 1.5.3 [skip ci] 2026-10-24 12:55:17 +00:00
Djeex 5ebe160ad0 Update python Docker tag to v3.15.1 (#19)
CI / build-and-scan (push) Successful in 39s
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| python | final | minor | `3.14.8-alpine` -> `3.15.1-alpine` |

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4yNjQuMCIsInVwZGF0ZWRJblZlciI6IjM5LjI2NC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJib3QiLCJtaW5vciJdfQ==-->

Reviewed-on: #19
2026-10-24 14:52:33 +02:00
adguard-cidre-ci 48ca7889e3 Bump build version to 1.5.2 [skip ci] 2026-10-02 03:09:34 +00:00
Djeex cb94dd0bb9 Update python Docker tag to v3.14.8
CI / build-and-scan (pull_request) Successful in 54s
CI / build-and-scan (push) Successful in 46s
2026-10-02 03:00:53 +00:00
adguard-cidre-ci 89afe87b47 Bump build version to 1.5.1 [skip ci] 2026-08-26 13:31:12 +00:00
DjeexandDjeex e91bba759b CI/CD hardening: lint, secret scan, coverage gate, auto CVE-fix PRs, GHCR + GitHub mirror publishing (#17)
CI / build-and-scan (push) Successful in 47s
- release changelog: commits rendered as description (link), divider lines dropped
- gitleaks secret scan and hadolint on every push/PR
- ruff lint/format gate (Python repos) with a pytest --cov-fail-under gate
- scheduled CRITICAL Trivy failures attempt an apk upgrade rebuild and open a follow-up PR if it clears the finding, instead of just failing red
- images also published to ghcr.io/djeex/<repo>
- a matching GitHub Release is created on the GitHub mirror, with a notice pointing back to this repo as the source of truth

---------

Co-authored-by: Djeex <[email protected]>
Reviewed-on: #17
2026-08-26 15:30:30 +02:00
Djeex b197fd5977 Merge pull request 'Fix ci release template' (#16) from fix-ci-release-template into main
CI / build-and-scan (push) Successful in 28s
Reviewed-on: #16
2026-08-23 23:24:41 +02:00
Djeex 13926f2e9f Link each commit in the release changelog to its own commit page
CI / build-and-scan (pull_request) Successful in 23s
COMMIT_LIST only rendered the bare subject line per commit, with no
way to jump to that specific commit — only the triggering commit
(Source:) had a link. Each line now reads
"- [<short-sha>](<repo>/commit/<sha>) <subject>", matching the same
link style already used for Source.
2026-08-23 23:20:45 +02:00
Djeex ae16862a11 Align release changelog with the commit-list template used on the sibling repos
CI / build-and-scan (pull_request) Successful in 26s
2026-08-23 22:57:01 +02:00
Djeex 6ac20e25e3 Merge pull request 'Run container as non-root via PUID/PGID / Move environment configuration to a .env file' (#14) from dev-v2 into main
CI / build-and-scan (push) Successful in 32s
Reviewed-on: #14
2026-08-23 15:17:00 +02:00
Djeex 620d00134c Move environment configuration to a .env file
CI / build-and-scan (pull_request) Successful in 47s
2026-08-23 15:11:22 +02:00
Djeex d13f79ed82 Bump version to 1.5.0 for non-root support 2026-08-23 14:15:20 +02:00
Djeex cf96acda92 Run container as non-root via PUID/PGID with a startup entrypoint banner and logs 2026-08-23 14:14:54 +02:00
12 changed files with 282 additions and 190 deletions

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
# User/group id the process runs as, matches ownership of the /adguard mount
PUID=1000
PGID=1000
# Timezone of the container
TZ=Europe/Paris
# Country codes for CIDR lists, comma separated. Prefix with ! to exclude instead of include.
# Full lists here: https://github.com/vulnebify/cidre/tree/main/output/cidr/ipv4
BLOCK_COUNTRIES=cn,ru
# Scheduling: daily or weekly
BLOCKLIST_CRON_TYPE=daily
# If weekly, choose the day: mon, tue, wed, thu, fri, sat, sun
BLOCKLIST_CRON_DAY=mon
# Time of day to run the update, 24h HH:MM format
BLOCKLIST_CRON_TIME=06:00
# Docker API URL used to restart the AdGuard container (via socket-proxy)
DOCKER_API_URL=http://socket-proxy-adguard:2375
# Name of the AdGuard Home container to restart
ADGUARD_CONTAINER_NAME=adguardhome
+52 -124
View File
@@ -6,7 +6,8 @@ on:
pull_request: pull_request:
branches: [main] branches: [main]
schedule: schedule:
- cron: "0 6 * * 1" # Saturday 05:00 UTC: 06:00 in Paris in winter, 07:00 in summer (Gitea runs cron in UTC).
- cron: "0 5 * * 6"
jobs: jobs:
build-and-scan: build-and-scan:
@@ -18,6 +19,21 @@ jobs:
fetch-depth: 0 fetch-depth: 0
persist-credentials: false persist-credentials: false
- name: Get shared actions
uses: actions/checkout@v7
with:
repository: labeex/cicdeex
ref: 1.1.0
token: ${{ secrets.CICDEEX_TOKEN }}
path: .cicdeex
persist-credentials: false
- name: Scan for secrets
uses: ./.cicdeex/secret-scan
- name: Lint Dockerfile with hadolint
uses: ./.cicdeex/hadolint
- name: Build Docker image - name: Build Docker image
run: | run: |
docker build -t adguard-cidre:ci . 2>&1 | tee build.log docker build -t adguard-cidre:ci . 2>&1 | tee build.log
@@ -42,7 +58,10 @@ jobs:
- name: Run unit tests - name: Run unit tests
run: | run: |
docker build --target test -t adguard-cidre:test . docker build --target test -t adguard-cidre:test .
docker run --rm adguard-cidre:test pytest -v docker run --rm adguard-cidre:test pytest -v --cov=. --cov-report=term-missing --cov-fail-under=75
- name: Lint with ruff
run: docker build --target lint -t adguard-cidre:lint .
- name: Check deprecation warnings - name: Check deprecation warnings
run: | run: |
@@ -52,131 +71,40 @@ jobs:
fi fi
- name: Scan with Trivy (critical - blocking) - name: Scan with Trivy (critical - blocking)
run: | id: trivy_critical
docker run --rm \ continue-on-error: true
-e DOCKER_HOST=tcp://dockerhost:2375 \ uses: ./.cicdeex/trivy
--add-host=dockerhost:host-gateway \ with:
aquasec/trivy:0.74.0 image --exit-code 1 --severity CRITICAL adguard-cidre:ci image: adguard-cidre:ci
- name: Handle CRITICAL findings
if: steps.trivy_critical.outcome == 'failure'
uses: ./.cicdeex/remediate
with:
push-token: ${{ secrets.CI_PUSH_TOKEN }}
- name: Scan with Trivy (high - informative) - name: Scan with Trivy (high - informative)
run: | uses: ./.cicdeex/trivy
docker run --rm \ with:
-e DOCKER_HOST=tcp://dockerhost:2375 \ image: adguard-cidre:ci
--add-host=dockerhost:host-gateway \ severity: HIGH
aquasec/trivy:0.74.0 image --exit-code 0 --severity HIGH adguard-cidre:ci exit-code: "0"
- name: Publish tagged image - name: Publish tagged image
id: publish
if: github.event_name == 'push' && github.ref == 'refs/heads/main' if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: | uses: ./.cicdeex/publish
BEFORE="${{ github.event.before }}" with:
if [ -n "$BEFORE" ] && [ "$BEFORE" != "0000000000000000000000000000000000000000" ] && git cat-file -e "$BEFORE" 2>/dev/null; then image: adguard-cidre:ci
CHANGED=$(git diff --name-only "$BEFORE" "${{ github.sha }}") paths: '^(Dockerfile|blocklist_scheduler\.py|VERSION)$'
else push-token: ${{ secrets.CI_PUSH_TOKEN }}
CHANGED=$(git diff --name-only HEAD~1 HEAD) registry-token: ${{ secrets.REGISTRY_TOKEN }}
fi github-mirror: "true"
echo "Changed files:" github-token: ${{ secrets.GH_TOKEN }}
echo "$CHANGED"
if ! echo "$CHANGED" | grep -qE '^(Dockerfile|blocklist_scheduler\.py|VERSION)$'; then - name: Notify failures
echo "No container-relevant file changed, skipping publish." if: always()
exit 0 uses: ./.cicdeex/notify
fi with:
webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }}
if echo "$CHANGED" | grep -qE '^VERSION$'; then status: ${{ job.status }}
echo "VERSION was manually edited in this push, using it as-is."
else
echo "VERSION untouched but container files changed, auto-bumping the build number (Z)."
OLD_VERSION=$(tr -d '[:space:]' < VERSION)
IFS='.' read -r MAJOR MINOR PATCH <<< "$OLD_VERSION"
NEW_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))"
echo "$NEW_VERSION" > VERSION
git config user.name "adguard-cidre-ci"
git config user.email "[email protected]"
git add VERSION
git commit -m "Bump build version to $NEW_VERSION [skip ci]"
# Belt and suspenders: actions/checkout can leave its own ephemeral
# credential injected as an extraheader, which would silently override
# the URL-embedded token below. persist-credentials:false on checkout
# should already prevent this, but strip it here too just in case.
git config --unset-all http.https://git.djeex.fr/.extraheader || true
git push "https://Djeex:${{ secrets.CI_PUSH_TOKEN }}@git.djeex.fr/Djeex/adguard-cidre.git" HEAD:main
fi
VERSION=$(tr -d '[:space:]' < VERSION)
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
MINOR_TAG="${MAJOR}.${MINOR}"
IMAGE=git.djeex.fr/djeex/adguard-cidre
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login git.djeex.fr -u Djeex --password-stdin
# Retag the already-built, already-scanned image — never rebuild for publish,
# so what ships is byte-for-byte what Trivy just scanned.
docker tag adguard-cidre:ci "$IMAGE:latest"
docker tag adguard-cidre:ci "$IMAGE:$MINOR_TAG"
docker tag adguard-cidre:ci "$IMAGE:$VERSION"
docker push "$IMAGE:latest"
docker push "$IMAGE:$MINOR_TAG"
docker push "$IMAGE:$VERSION"
TRIGGER_MSG=$(git log -1 --format=%s "${{ github.sha }}")
PR_NUM=$(echo "$TRIGGER_MSG" | grep -oE '#[0-9]+' | head -1 | tr -d '#' || true)
CATEGORY="🔧 Maintenance"
CHANGE_TITLE="$TRIGGER_MSG"
if [ -n "$PR_NUM" ]; then
PR_JSON=$(curl -s -H "Authorization: token ${{ secrets.CI_PUSH_TOKEN }}" \
"https://git.djeex.fr/api/v1/repos/Djeex/adguard-cidre/pulls/$PR_NUM")
PR_TITLE=$(echo "$PR_JSON" | jq -r '.title // empty' 2>/dev/null || true)
LABELS=$(echo "$PR_JSON" | jq -r '.labels[]?.name' 2>/dev/null || true)
if [ -n "$PR_TITLE" ]; then
CHANGE_TITLE="$PR_TITLE"
fi
if echo "$LABELS" | grep -qx 'bug'; then
CATEGORY="⚠️ Hotfix"
elif echo "$LABELS" | grep -qx 'major'; then
CATEGORY="💥 Breaking change"
elif echo "$LABELS" | grep -qx 'minor'; then
CATEGORY="✨ Update"
fi
fi
CHANGED_LIST=$(echo "$CHANGED" | sed 's/^/- /')
REPO_URL="https://git.djeex.fr/Djeex/adguard-cidre"
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
SOURCE_LINE="[${SHORT_SHA}](${REPO_URL}/commit/${{ github.sha }})"
if [ -n "$PR_NUM" ]; then
SOURCE_LINE="[#${PR_NUM}](${REPO_URL}/pulls/${PR_NUM}) · ${SOURCE_LINE}"
fi
BODY=$(cat <<EOF
## Changelog
### ${CATEGORY}
${CHANGE_TITLE}
**Source:** ${SOURCE_LINE}
**Image:** \`${IMAGE}:${VERSION}\`
**Changed files:**
${CHANGED_LIST}
EOF
)
JSON_PAYLOAD=$(jq -n \
--arg tag "$VERSION" \
--arg name "$VERSION" \
--arg body "$BODY" \
'{tag_name: $tag, name: $name, target_commitish: "main", body: $body}')
curl -s -o /dev/null -w "Release API response: %{http_code}\n" -X POST \
-H "Authorization: token ${{ secrets.CI_PUSH_TOKEN }}" \
-H "Content-Type: application/json" \
-d "$JSON_PAYLOAD" \
"https://git.djeex.fr/api/v1/repos/Djeex/adguard-cidre/releases"
+12 -5
View File
@@ -1,8 +1,8 @@
FROM python:3.14.7-alpine AS base FROM python:3.15.2-alpine@sha256:0f9552bb28711333da16915ec146f5e6bb44a7fdac9ced15dc17c2e0206346dd AS base
ENV TZ=Europe/Paris ENV TZ=Europe/Paris
RUN apk add --no-cache tzdata curl \ RUN apk add --no-cache tzdata curl su-exec \
&& cp /usr/share/zoneinfo/$TZ /etc/localtime \ && cp /usr/share/zoneinfo/$TZ /etc/localtime \
&& echo $TZ > /etc/timezone && echo $TZ > /etc/timezone
@@ -11,12 +11,19 @@ WORKDIR /app
COPY requirements.txt . COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt RUN pip install --no-cache-dir -r requirements.txt
COPY blocklist_scheduler.py . COPY blocklist_scheduler.py entrypoint.sh VERSION ./
RUN chmod +x entrypoint.sh
FROM base AS test FROM base AS test
RUN pip install --no-cache-dir pytest==9.1.1 RUN pip install --no-cache-dir pytest==9.1.1 pytest-cov==7.1.0
COPY tests/ tests/ COPY tests/ tests/
COPY pytest.ini . COPY pytest.ini .
FROM base AS lint
RUN pip install --no-cache-dir ruff==0.16.4
COPY ruff.toml .
COPY tests/ tests/
RUN ruff check . && ruff format --check .
FROM base FROM base
ENTRYPOINT ["python3", "blocklist_scheduler.py"] ENTRYPOINT ["./entrypoint.sh"]
+9 -4
View File
@@ -31,6 +31,8 @@
| Variable | Description | Example | Possible Values | | Variable | Description | Example | Possible Values |
|--------------------------|--------------------------------------------------------------------------|-----------------------------|---------------------------------------------| |--------------------------|--------------------------------------------------------------------------|-----------------------------|---------------------------------------------|
| `PUID` | User ID the process runs as (drops root at startup) | `1000` | Any valid numeric UID |
| `PGID` | Group ID the process runs as | `1000` | Any valid numeric GID |
| `TZ` | Timezone of the container to correctly schedule updates | `Europe/Paris` | Any valid timezone (e.g., `UTC`, `America/New_York`, etc.) | | `TZ` | Timezone of the container to correctly schedule updates | `Europe/Paris` | Any valid timezone (e.g., `UTC`, `America/New_York`, etc.) |
| `BLOCK_COUNTRIES` | List of country codes for CIDR lists, separated by commas. You can also define an exclude list (all countries except the specified ones) by prefixing each country code with !. Mixing inclusion and exclusion codes is not supported. | including list : `cn,ru,ir`, excluding list : `!cn,!ru,!ir` | ISO 2-letter country codes | | `BLOCK_COUNTRIES` | List of country codes for CIDR lists, separated by commas. You can also define an exclude list (all countries except the specified ones) by prefixing each country code with !. Mixing inclusion and exclusion codes is not supported. | including list : `cn,ru,ir`, excluding list : `!cn,!ru,!ir` | ISO 2-letter country codes |
| `BLOCKLIST_CRON_TYPE` | Scheduling type: `daily` or `weekly` | `daily` | `daily`, `weekly` | | `BLOCKLIST_CRON_TYPE` | Scheduling type: `daily` or `weekly` | `daily` | `daily`, `weekly` |
@@ -64,6 +66,8 @@
container_name: adguard-cidre container_name: adguard-cidre
restart: unless-stopped restart: unless-stopped
environment: environment:
- PUID=1000 # user id the process runs as, matches ownership of the /adguard mount
- PGID=1000 # group id the process runs as
- TZ=Europe/Paris # change to your timezone - TZ=Europe/Paris # change to your timezone
- BLOCK_COUNTRIES=cn,ru # choose countries listed IP to block. Full lists here https://github.com/vulnebify/cidre/tree/main/output/cidr/ipv4 - BLOCK_COUNTRIES=cn,ru # choose countries listed IP to block. Full lists here https://github.com/vulnebify/cidre/tree/main/output/cidr/ipv4
- BLOCKLIST_CRON_TYPE=daily # daily or weekly - BLOCKLIST_CRON_TYPE=daily # daily or weekly
@@ -121,11 +125,12 @@
git clone https://git.djeex.fr/Djeex/adguard-cidre git clone https://git.djeex.fr/Djeex/adguard-cidre
cd adguard-cidre cd adguard-cidre
``` ```
2. **Modify docker-compose.yml** 2. **Edit the `.env` file**
- Set `BLOCK_COUNTRIES` environment variable with the countries you want to block. - A `.env` file is included at the repo root with all environment variables (see [Environment Variables](#environment-variables)). Edit values there instead of `docker-compose.yml`.
- Adjust `BLOCKLIST_CRON` variables if you want a different update frequency. - Set `BLOCK_COUNTRIES` with the countries you want to block.
- Bind mount your adguard configuration folder (wich contains `AdGuardHome.yaml`) to `/adguard` - Adjust `BLOCKLIST_CRON_*` variables if you want a different update frequency.
- Bind mount your adguard configuration folder (wich contains `AdGuardHome.yaml`) to `/adguard` in `docker-compose.yml`.
- (optionnally) create and edit `manually_blocked_ips.conf` file in your adguard configuration folder to add other IPs you want to block. Only valid IP or CIDR entries will be processed, for exemple : - (optionnally) create and edit `manually_blocked_ips.conf` file in your adguard configuration folder to add other IPs you want to block. Only valid IP or CIDR entries will be processed, for exemple :
```bash ```bash
+1 -1
View File
@@ -1 +1 @@
1.4.1 1.5.5
+51 -19
View File
@@ -1,17 +1,18 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os
import sys
import logging import logging
import requests import os
import yaml
import schedule
import time
import re import re
import sys
import time
from pathlib import Path from pathlib import Path
import requests
import schedule
import yaml
logging.basicConfig( logging.basicConfig(
level=logging.INFO, level=logging.INFO,
format='[blocklist] %(levelname)s: %(message)s', format="%(asctime)s [%(levelname)s] %(message)s",
stream=sys.stdout, stream=sys.stdout,
) )
@@ -19,7 +20,9 @@ ADGUARD_YAML = Path("/adguard/AdGuardHome.yaml")
TMP_YAML = ADGUARD_YAML.parent / (ADGUARD_YAML.name + ".tmp") TMP_YAML = ADGUARD_YAML.parent / (ADGUARD_YAML.name + ".tmp")
MANUAL_IPS_FILE = Path("/adguard/manually_blocked_ips.conf") MANUAL_IPS_FILE = Path("/adguard/manually_blocked_ips.conf")
CIDR_BASE_URL = "https://raw.githubusercontent.com/vulnebify/cidre/main/output/cidr/ipv4" CIDR_BASE_URL = "https://raw.githubusercontent.com/vulnebify/cidre/main/output/cidr/ipv4"
COUNTRY_LIST_URL = "https://raw.githubusercontent.com/vulnebify/cidre/refs/heads/main/cidre/countries.py" COUNTRY_LIST_URL = (
"https://raw.githubusercontent.com/vulnebify/cidre/refs/heads/main/cidre/countries.py"
)
FIRST_BACKUP = ADGUARD_YAML.parent / "AdGuardHome.yaml.first-start.bak" FIRST_BACKUP = ADGUARD_YAML.parent / "AdGuardHome.yaml.first-start.bak"
LAST_UPDATE_BACKUP = ADGUARD_YAML.parent / "AdGuardHome.yaml.last-update.bak" LAST_UPDATE_BACKUP = ADGUARD_YAML.parent / "AdGuardHome.yaml.last-update.bak"
@@ -32,6 +35,7 @@ BLOCKLIST_CRON_DAY = os.getenv("BLOCKLIST_CRON_DAY", "mon").lower()
ADGUARD_CONTAINER_NAME = os.getenv("ADGUARD_CONTAINER_NAME", "adguardhome") ADGUARD_CONTAINER_NAME = os.getenv("ADGUARD_CONTAINER_NAME", "adguardhome")
DOCKER_API_URL = os.getenv("DOCKER_API_URL", "http://socket-proxy-adguard:2375") DOCKER_API_URL = os.getenv("DOCKER_API_URL", "http://socket-proxy-adguard:2375")
def backup_first_start(): def backup_first_start():
if not FIRST_BACKUP.exists(): if not FIRST_BACKUP.exists():
logging.info(f"Creating first start backup: {FIRST_BACKUP}") logging.info(f"Creating first start backup: {FIRST_BACKUP}")
@@ -39,10 +43,12 @@ def backup_first_start():
else: else:
logging.info("First start backup already exists, skipping.") logging.info("First start backup already exists, skipping.")
def backup_last_update(): def backup_last_update():
logging.info(f"Creating last update backup: {LAST_UPDATE_BACKUP}") logging.info(f"Creating last update backup: {LAST_UPDATE_BACKUP}")
LAST_UPDATE_BACKUP.write_text(ADGUARD_YAML.read_text()) LAST_UPDATE_BACKUP.write_text(ADGUARD_YAML.read_text())
def fetch_all_country_codes(): def fetch_all_country_codes():
try: try:
resp = requests.get(COUNTRY_LIST_URL, timeout=15) resp = requests.get(COUNTRY_LIST_URL, timeout=15)
@@ -53,6 +59,7 @@ def fetch_all_country_codes():
logging.error(f"Failed to fetch available country codes: {e}") logging.error(f"Failed to fetch available country codes: {e}")
return set() return set()
def get_selected_countries(): def get_selected_countries():
if not BLOCK_COUNTRIES: if not BLOCK_COUNTRIES:
logging.error("BLOCK_COUNTRIES is not set. Skipping update.") logging.error("BLOCK_COUNTRIES is not set. Skipping update.")
@@ -67,7 +74,9 @@ def get_selected_countries():
is_inclusion = all(not c.startswith("!") for c in raw_codes) is_inclusion = all(not c.startswith("!") for c in raw_codes)
if not (is_exclusion or is_inclusion): if not (is_exclusion or is_inclusion):
logging.error("Mixed syntax in BLOCK_COUNTRIES. Use only inclusion (e.g. 'fr,de') or only exclusion (e.g. '!fr,!de').") logging.error(
"Mixed syntax in BLOCK_COUNTRIES. Use only inclusion (e.g. 'fr,de') or only exclusion (e.g. '!fr,!de')."
)
sys.exit(1) sys.exit(1)
available = fetch_all_country_codes() available = fetch_all_country_codes()
@@ -81,6 +90,7 @@ def get_selected_countries():
else: else:
return sorted(selected & available) return sorted(selected & available)
def download_cidr_lists(countries): def download_cidr_lists(countries):
combined_ips = [] combined_ips = []
for code in countries: for code in countries:
@@ -96,6 +106,7 @@ def download_cidr_lists(countries):
logging.warning(f"Failed to download {code}: {e}") logging.warning(f"Failed to download {code}: {e}")
return combined_ips return combined_ips
def read_manual_ips(): def read_manual_ips():
if MANUAL_IPS_FILE.exists(): if MANUAL_IPS_FILE.exists():
logging.info(f"Reading manual IPs from {MANUAL_IPS_FILE}") logging.info(f"Reading manual IPs from {MANUAL_IPS_FILE}")
@@ -103,7 +114,7 @@ def read_manual_ips():
with MANUAL_IPS_FILE.open() as f: with MANUAL_IPS_FILE.open() as f:
for line in f: for line in f:
line = line.strip() line = line.strip()
if line and (line.count('.') == 3 or '/' in line): if line and (line.count(".") == 3 or "/" in line):
valid_ips.append(line) valid_ips.append(line)
logging.info(f"Added {len(valid_ips)} manual IP entries") logging.info(f"Added {len(valid_ips)} manual IP entries")
return valid_ips return valid_ips
@@ -111,6 +122,7 @@ def read_manual_ips():
logging.info("Manual IPs file does not exist, skipping.") logging.info("Manual IPs file does not exist, skipping.")
return [] return []
def update_yaml_with_ips(ips): def update_yaml_with_ips(ips):
if not ADGUARD_YAML.exists(): if not ADGUARD_YAML.exists():
logging.error(f"{ADGUARD_YAML} does not exist. Cannot update.") logging.error(f"{ADGUARD_YAML} does not exist. Cannot update.")
@@ -127,15 +139,16 @@ def update_yaml_with_ips(ips):
logging.error("Invalid YAML format.") logging.error("Invalid YAML format.")
return False return False
data['dns']['disallowed_clients'] = ips data["dns"]["disallowed_clients"] = ips
with TMP_YAML.open('w') as f: with TMP_YAML.open("w") as f:
yaml.safe_dump(data, f) yaml.safe_dump(data, f)
TMP_YAML.replace(ADGUARD_YAML) TMP_YAML.replace(ADGUARD_YAML)
logging.info(f"Updated {ADGUARD_YAML} with new disallowed clients list.") logging.info(f"Updated {ADGUARD_YAML} with new disallowed clients list.")
return True return True
def restart_adguard_container(): def restart_adguard_container():
restart_url = f"{DOCKER_API_URL}/containers/{ADGUARD_CONTAINER_NAME}/restart" restart_url = f"{DOCKER_API_URL}/containers/{ADGUARD_CONTAINER_NAME}/restart"
logging.info(f"Restarting AdGuard container '{ADGUARD_CONTAINER_NAME}'...") logging.info(f"Restarting AdGuard container '{ADGUARD_CONTAINER_NAME}'...")
@@ -148,6 +161,7 @@ def restart_adguard_container():
except Exception as e: except Exception as e:
logging.error(f"Error restarting container: {e}") logging.error(f"Error restarting container: {e}")
def update_blocklist(): def update_blocklist():
countries = get_selected_countries() countries = get_selected_countries()
if not countries: if not countries:
@@ -164,11 +178,14 @@ def update_blocklist():
if success: if success:
restart_adguard_container() restart_adguard_container()
def schedule_job(): def schedule_job():
try: try:
hour, minute = [int(x) for x in BLOCKLIST_CRON_TIME.split(":")] hour, minute = [int(x) for x in BLOCKLIST_CRON_TIME.split(":")]
except Exception: except Exception:
logging.error(f"Invalid BLOCKLIST_CRON_TIME '{BLOCKLIST_CRON_TIME}', must be HH:MM. Defaulting to 06:00.") logging.error(
f"Invalid BLOCKLIST_CRON_TIME '{BLOCKLIST_CRON_TIME}', must be HH:MM. Defaulting to 06:00."
)
hour, minute = 6, 0 hour, minute = 6, 0
if BLOCKLIST_CRON_TYPE == "daily": if BLOCKLIST_CRON_TYPE == "daily":
@@ -176,20 +193,34 @@ def schedule_job():
logging.info(f"Scheduled daily update at {hour:02d}:{minute:02d}") logging.info(f"Scheduled daily update at {hour:02d}:{minute:02d}")
elif BLOCKLIST_CRON_TYPE == "weekly": elif BLOCKLIST_CRON_TYPE == "weekly":
day_names = { day_names = {
"mon": "monday", "tue": "tuesday", "wed": "wednesday", "thu": "thursday", "mon": "monday",
"fri": "friday", "sat": "saturday", "sun": "sunday", "tue": "tuesday",
"wed": "wednesday",
"thu": "thursday",
"fri": "friday",
"sat": "saturday",
"sun": "sunday",
} }
day = BLOCKLIST_CRON_DAY[:3] day = BLOCKLIST_CRON_DAY[:3]
if day not in day_names: if day not in day_names:
logging.error(f"Invalid BLOCKLIST_CRON_DAY '{BLOCKLIST_CRON_DAY}', must be one of {list(day_names)}. Defaulting to Monday.") logging.error(
f"Invalid BLOCKLIST_CRON_DAY '{BLOCKLIST_CRON_DAY}', must be one of {list(day_names)}. Defaulting to Monday."
)
day = "mon" day = "mon"
getattr(schedule.every(), day_names[day]).at(f"{hour:02d}:{minute:02d}").do(update_blocklist) getattr(schedule.every(), day_names[day]).at(f"{hour:02d}:{minute:02d}").do(
logging.info(f"Scheduled weekly update on {day_names[day].capitalize()} at {hour:02d}:{minute:02d}") update_blocklist
)
logging.info(
f"Scheduled weekly update on {day_names[day].capitalize()} at {hour:02d}:{minute:02d}"
)
else: else:
logging.error(f"Invalid BLOCKLIST_CRON_TYPE '{BLOCKLIST_CRON_TYPE}', must be 'daily' or 'weekly'. Defaulting to daily.") logging.error(
f"Invalid BLOCKLIST_CRON_TYPE '{BLOCKLIST_CRON_TYPE}', must be 'daily' or 'weekly'. Defaulting to daily."
)
schedule.every().day.at(f"{hour:02d}:{minute:02d}").do(update_blocklist) schedule.every().day.at(f"{hour:02d}:{minute:02d}").do(update_blocklist)
logging.info(f"Scheduled daily update at {hour:02d}:{minute:02d}") logging.info(f"Scheduled daily update at {hour:02d}:{minute:02d}")
def main(): def main():
logging.info("Starting blocklist scheduler...") logging.info("Starting blocklist scheduler...")
backup_first_start() backup_first_start()
@@ -199,5 +230,6 @@ def main():
schedule.run_pending() schedule.run_pending()
time.sleep(10) time.sleep(10)
if __name__ == "__main__": if __name__ == "__main__":
main() main()
+9 -7
View File
@@ -5,14 +5,16 @@ services:
container_name: adguard-cidre container_name: adguard-cidre
restart: unless-stopped restart: unless-stopped
environment: environment:
- TZ=Europe/Paris # change to your timezone - PUID=${PUID} # user id the process runs as, matches ownership of the /adguard mount
- BLOCK_COUNTRIES=cn,ru # choose countries listed IP to block. Full lists here https://github.com/vulnebify/cidre/tree/main/output/cidr/ipv4 - PGID=${PGID} # group id the process runs as
- BLOCKLIST_CRON_TYPE=daily # daily or weekly - TZ=${TZ} # change to your timezone
- BLOCK_COUNTRIES=${BLOCK_COUNTRIES} # choose countries listed IP to block. Full lists here https://github.com/vulnebify/cidre/tree/main/output/cidr/ipv4
- BLOCKLIST_CRON_TYPE=${BLOCKLIST_CRON_TYPE} # daily or weekly
# if weekly, choose the day # if weekly, choose the day
# - BLOCKLIST_CRON_DAY=mon - BLOCKLIST_CRON_DAY=${BLOCKLIST_CRON_DAY}
- BLOCKLIST_CRON_TIME=06:00 - BLOCKLIST_CRON_TIME=${BLOCKLIST_CRON_TIME}
- DOCKER_API_URL=http://socket-proxy-adguard:2375 # docker socket proxy - DOCKER_API_URL=${DOCKER_API_URL} # docker socket proxy
- ADGUARD_CONTAINER_NAME=adguardhome # adguard container name - ADGUARD_CONTAINER_NAME=${ADGUARD_CONTAINER_NAME} # adguard container name
volumes: volumes:
- /path/to/adguard/confdir:/adguard - /path/to/adguard/confdir:/adguard
Executable
+105
View File
@@ -0,0 +1,105 @@
#!/bin/sh
set -e
CYAN="\033[1;36m"
NC="\033[0m"
log() { echo "$(date '+%Y-%m-%d %H:%M:%S') $*"; }
fail() { echo "$(date '+%Y-%m-%d %H:%M:%S') [!] $*" >&2; exit 1; }
print_banner() {
version=$(cat VERSION 2>/dev/null || echo "unknown")
title="AdGuard CIDRe - Version ${version}"
lines="Source: https://git.djeex.fr/Djeex/adguard-cidre
Mirror: https://github.com/Djeex/adguard-cidre"
width=${#title}
old_ifs=$IFS
IFS='
'
for l in $lines; do
[ ${#l} -gt "$width" ] && width=${#l}
done
IFS=$old_ifs
width=$((width + 2))
border=""
i=0
while [ "$i" -lt "$width" ]; do
border="${border}─"
i=$((i + 1))
done
printf "${CYAN}╭%s╮${NC}\n" "$border"
total_pad=$((width - ${#title}))
left=$((total_pad / 2))
right=$((total_pad - left))
printf "${CYAN}│${NC}%*s%s%*s${CYAN}│${NC}\n" "$left" "" "$title" "$right" ""
printf "${CYAN}├%s┤${NC}\n" "$border"
IFS='
'
for l in $lines; do
printf "${CYAN}│${NC} %-*s${CYAN}│${NC}\n" "$((width - 1))" "$l"
done
IFS=$old_ifs
printf "${CYAN}╰%s╯${NC}\n" "$border"
}
print_banner
PUID=${PUID:-911}
PGID=${PGID:-911}
case "$PGID" in
''|*[!0-9]*) fail "PGID '$PGID' is not a valid numeric group id." ;;
esac
case "$PUID" in
''|*[!0-9]*) fail "PUID '$PUID' is not a valid numeric user id." ;;
esac
[ -d /adguard ] || fail "/adguard is not mounted — check the volume mapping in docker-compose.yml."
log "[i] Requested PUID=$PUID, PGID=$PGID"
log "[~] Checking group for GID $PGID..."
GROUP_NAME=$(getent group "$PGID" | cut -d: -f1 || true)
if [ -z "$GROUP_NAME" ]; then
log "[→] No existing group with GID $PGID, creating 'appgroup'."
addgroup -g "$PGID" appgroup || fail "Failed to create group with GID $PGID (addgroup exited $?)."
GROUP_NAME=appgroup
else
log "[i] Reusing existing group '$GROUP_NAME' (GID $PGID)."
fi
log "[✓] Group ready: $GROUP_NAME"
log "[~] Checking user for UID $PUID..."
USER_NAME=$(getent passwd "$PUID" | cut -d: -f1 || true)
if [ -z "$USER_NAME" ]; then
log "[→] No existing user with UID $PUID, creating 'appuser'."
adduser -D -u "$PUID" -G "$GROUP_NAME" appuser || fail "Failed to create user with UID $PUID (adduser exited $?)."
USER_NAME=appuser
else
log "[i] Reusing existing user '$USER_NAME' (UID $PUID)."
fi
log "[✓] User ready: $USER_NAME"
# Grant write access to the shared AdGuard config directory and to the files
# this script manages, without touching anything else AdGuardHome owns in
# there (its own db/certs/stats). AdGuardHome itself runs as root, so this is
# a one-way grant: it keeps full access regardless of what we chown here.
log "[~] Setting ownership of /adguard to $USER_NAME:$GROUP_NAME..."
chown "$USER_NAME:$GROUP_NAME" /adguard || fail "chown on /adguard failed — check that the host directory permissions allow it."
log "[✓] Ownership set on /adguard"
for f in AdGuardHome.yaml AdGuardHome.yaml.first-start.bak AdGuardHome.yaml.last-update.bak AdGuardHome.yaml.tmp; do
if [ -e "/adguard/$f" ]; then
chown "$USER_NAME:$GROUP_NAME" "/adguard/$f" || fail "chown on /adguard/$f failed."
log "[✓] chown OK: /adguard/$f"
fi
done
log "[→] Dropping privileges to $USER_NAME:$GROUP_NAME and starting blocklist_scheduler.py"
exec su-exec "$USER_NAME:$GROUP_NAME" python3 blocklist_scheduler.py "$@"
+1 -27
View File
@@ -1,30 +1,4 @@
{ {
"$schema": "https://docs.renovatebot.com/renovate-schema.json", "$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["config:recommended"], "extends": ["local>labeex/renovateex"]
"timezone": "Europe/Paris",
"labels": ["bot"],
"packageRules": [
{
"matchManagers": ["pip_requirements"],
"matchUpdateTypes": ["patch", "minor"],
"automerge": true
},
{
"matchManagers": ["dockerfile"],
"matchUpdateTypes": ["patch"],
"automerge": true
},
{
"matchUpdateTypes": ["major"],
"addLabels": ["major"]
},
{
"matchUpdateTypes": ["minor"],
"addLabels": ["minor"]
}
],
"vulnerabilityAlerts": {
"enabled": true,
"addLabels": ["bug"]
}
} }
+1 -1
View File
@@ -1,3 +1,3 @@
requests==2.34.2 requests==2.34.2
pyyaml==6.0.3 pyyaml==6.0.4
schedule==1.2.2 schedule==1.2.2
+10
View File
@@ -0,0 +1,10 @@
line-length = 100
[lint]
select = ["E", "F", "I", "UP", "B"]
ignore = ["E501"]
[lint.isort]
# See nvidia-stock-bot's ruff.toml for why this is pinned explicitly rather
# than left to auto-detection.
known-first-party = ["blocklist_scheduler"]
+9 -2
View File
@@ -56,6 +56,7 @@ def test_backup_first_start_raises_if_adguard_yaml_missing(tmp_path, monkeypatch
# --- update_yaml_with_ips (pyyaml) --- # --- update_yaml_with_ips (pyyaml) ---
def test_update_yaml_with_ips_writes_disallowed_clients(tmp_path, monkeypatch): def test_update_yaml_with_ips_writes_disallowed_clients(tmp_path, monkeypatch):
adguard_yaml = tmp_path / "AdGuardHome.yaml" adguard_yaml = tmp_path / "AdGuardHome.yaml"
adguard_yaml.write_text("dns:\n bind_hosts:\n - 0.0.0.0\n") adguard_yaml.write_text("dns:\n bind_hosts:\n - 0.0.0.0\n")
@@ -101,8 +102,11 @@ def test_update_yaml_with_ips_missing_dns_key_raises(tmp_path, monkeypatch):
# --- fetch_all_country_codes / download_cidr_lists / restart_adguard_container (requests) --- # --- fetch_all_country_codes / download_cidr_lists / restart_adguard_container (requests) ---
def test_fetch_all_country_codes_parses_codes(monkeypatch): def test_fetch_all_country_codes_parses_codes(monkeypatch):
monkeypatch.setattr(bs.requests, "get", lambda *a, **k: FakeResponse(text='COUNTRIES = ["FR", "DE", "US"]\n')) monkeypatch.setattr(
bs.requests, "get", lambda *a, **k: FakeResponse(text='COUNTRIES = ["FR", "DE", "US"]\n')
)
assert bs.fetch_all_country_codes() == {"fr", "de", "us"} assert bs.fetch_all_country_codes() == {"fr", "de", "us"}
@@ -136,7 +140,9 @@ def test_restart_adguard_container_success_does_not_raise(monkeypatch):
def test_restart_adguard_container_error_status_does_not_raise(monkeypatch): def test_restart_adguard_container_error_status_does_not_raise(monkeypatch):
monkeypatch.setattr(bs.requests, "post", lambda *a, **k: FakeResponse(status_code=500, text="err")) monkeypatch.setattr(
bs.requests, "post", lambda *a, **k: FakeResponse(status_code=500, text="err")
)
bs.restart_adguard_container() bs.restart_adguard_container()
@@ -152,6 +158,7 @@ def test_restart_adguard_container_network_error_does_not_raise(monkeypatch):
# --- schedule_job (schedule) --- # --- schedule_job (schedule) ---
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def clear_schedule(): def clear_schedule():
yield yield