HUB
Sign inSign up

cyrius44/scanasservice

By cyrius44

•Updated 1 day ago

This API allows you to submit a file to a ClamAV antivirus engine and retrieve the result.

Image
Security
Message queues
Databases & storage
0

919

cyrius44/scanasservice repository overview

⁠ScanAV as Service (SAVaS)

Antivirus scanning of files as a service, built on ClamAV⁠, Kafka and S3 storage (MinIO).

šŸ“– Documentation: https://cyr-ius.github.io/scanavasservice/⁠

⁠Features

  • Submit a file through the REST API, or drop it straight into an S3 bucket.
  • Scan results stored as S3 object tags, readable through the API, sent to a webhook or published to Kafka.
  • Clean files moved to processed/, infected files to quarantine/.
  • Adaptive load balancing across several clamd instances, with cooldown of failing ones.
  • Horizontal scaling: scanners form a Kafka consumer group.
  • Hardened by default: OIDC or client-credential authentication, per-caller file isolation, upload size limit, SSRF-protected webhooks, verified Kafka TLS, non-root image.

⁠How it works

flowchart LR
    C[Client] -->|upload| A[API]
    A --> S[(S3 bucket)]
    S -->|put event| K[[Kafka]]
    K --> W[Worker]
    W -->|INSTREAM| AV[clamd]
    W -->|tags, processed/ or quarantine/| S
    W -.->|result| H[Webhook / Kafka]

The image runs two components: the API (uvicorn app.api:app, port 8000) and the worker (python -m app), which consumes the Kafka topic and scans the files.

⁠Quick start

Requirements: Docker with Docker Compose.

  1. Set the secrets (in your shell or in a .env file next to the Compose file):

    export CLIENT_ID=demo
    export CLIENT_SECRET="$(openssl rand -base64 32)"
    export SECRET_KEY="$(openssl rand -base64 64 | tr -d '\n')"
    
  2. Start the example stack (Kafka, MinIO, two ClamAV instances and the scanner):

    docker compose -f examples/docker/docker-compose.yaml up --build -d
    

    ClamAV downloads its signatures on first start: allow a minute or two. The API listens on 127.0.0.1:8000.

  3. Scan a file:

    TOKEN=$(curl -s -X POST http://localhost:8000/api/token \
      -d "username=$CLIENT_ID" -d "password=$CLIENT_SECRET" | jq -r .access_token)
    
    KEY=$(curl -s -X POST http://localhost:8000/api/v1/upload \
      -H "Authorization: Bearer $TOKEN" -F "file=@./sample.pdf" | jq -r .key)
    
    curl -s -H "Authorization: Bearer $TOKEN" http://localhost:8000/api/v1/status/$KEY | jq
    

    The status is PENDING until the scan ends, then CLEAN, INFECTED or ERROR. Use demo/test_upload.com (EICAR test file) to try a detection.

  4. Download a clean file:

    curl -H "Authorization: Bearer $TOKEN" -o scanned.pdf \
      http://localhost:8000/api/v1/download/$KEY
    

The interactive API documentation is at http://localhost:8000/api/docs⁠.

Warning

The example stack uses the MinIO root credentials (`minioadmin`) and an unauthenticated Kafka. It is meant for a local test only: see the [deployment guide](https://cyr-ius.github.io/scanavasservice/demarrage/deploiement/).

⁠Configuration

Everything is configured through environment variables. The main ones:

VariablePurpose
KAFKA_SERVERS, KAFKA_TOPICKafka brokers and topic of the S3 put events
S3_ENDPOINT_URL, S3_BUCKETS3 endpoint and bucket of the files to scan
S3_ACCESS_KEY, S3_SECRET_KEYS3 credentials
CLAMD_HOSTSclamd instances (host:port, comma separated)
CLIENT_ID, CLIENT_SECRETClient credentials of the API
SECRET_KEYSigning key of the API tokens (same on every instance)
OIDC_ISSUER, OIDC_JWKS_URLOptional OIDC identity provider

See the full list of variables⁠ with their defaults.

⁠Development

The repository ships a devcontainer (.devcontainer/) that starts Kafka, MinIO and ClamAV. Outside of it, install Python 3.15 and uv⁠:

uv sync --extra dev
uv run python -m app                              # worker
uv run uvicorn app.api:app --port 8000 --reload   # API
uv run pytest && uv run ruff check . && uv run ruff format --check .
uv run --extra docs mkdocs serve -a 127.0.0.1:8001   # documentation preview

In the devcontainer, start the Execute - API + Runtime launch configuration, then run the Demo - upload a file to scan task to send a clean or an infected (EICAR) file and see its verdict. The devcontainer sets development-only API credentials (CLIENT_ID=dev).

Commits follow Conventional Commits⁠; releases are made by Release Please.

⁠Security

Please report vulnerabilities privately, as described in SECURITY.md⁠.

⁠License

Apache-2.0⁠

Tag summary

Content type

Image

Digest

sha256:0de3d9ce8…

Size

99.2 MB

Last updated

1 day ago

docker pull cyrius44/scanasservice