Skip to content
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

Bugfix #23 and improvements as suggested in #48 #50

Merged
merged 47 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
da30491
update ioutils -> io
arizon-dread Jun 18, 2024
4630017
format
arizon-dread Jun 18, 2024
76ed498
add v2 endpoint and ajust logic to match
arizon-dread Jun 18, 2024
71dce87
prometheus counter for found viruses
arizon-dread Jun 18, 2024
4aa1463
format printf
arizon-dread Jun 18, 2024
e5a5854
add endpoint
arizon-dread Jun 18, 2024
ee7337c
go.mod and go.sum, update to go 1.22
arizon-dread Jun 18, 2024
b1c4305
the rest of vendor stuff
arizon-dread Jun 18, 2024
f697aa9
ignore debugging executables
arizon-dread Jun 18, 2024
1bbcba8
add struct for responses with proper json annotations
arizon-dread Jun 18, 2024
787793e
ignore vscode stuff
arizon-dread Jun 18, 2024
869695f
fix response for multi file stream scanning so that it doesn't return…
arizon-dread Jun 18, 2024
26b7701
fix http status handling for missing filename in multipart header
arizon-dread Jun 19, 2024
ee4a157
remove writeheader from filename error handling, it will be set when …
arizon-dread Jun 19, 2024
e382100
update comment
arizon-dread Jun 19, 2024
86574ec
removed vendor to use modules instead
arizon-dread Jun 19, 2024
3a85156
remove vendor and use only go modules
arizon-dread Jun 19, 2024
329fbee
bump go alpine image to 3.20 + bump go patch version to 1.22.4 b/c of…
Jul 2, 2024
c2cac96
update readme, use /v2/scan in the documentation
arizon-dread Jul 14, 2024
32f3d1b
Encapsulate json in array brackets in examples to adher to the new /v…
arizon-dread Jul 14, 2024
fb74018
Use the same data folders for freshclam and clamd
Oct 8, 2024
1b8dc98
chore(deps): update alpine docker tag to v3.20
renovate[bot] May 22, 2024
1f68fb3
chore(deps): update docker/build-push-action action to v6
renovate[bot] Jun 17, 2024
b72a12f
Update README.md
davosian Oct 15, 2024
12cd48f
Merge remote-tracking branch 'clamav-rest/master' into scan-v2
arizon-dread Oct 15, 2024
a1a8396
update status codes
arizon-dread Oct 15, 2024
bd319bc
fixes for file structure
arizon-dread Oct 20, 2024
8c2ce04
revert from clamav/clamav:1.4.1 to alpine:3.20
arizon-dread Oct 21, 2024
b46fc19
revert from moving/symlinking clamavs original dirs to /clamav
arizon-dread Oct 21, 2024
e7188dd
Add filename to response if the /v2/scan endpoint is used
arizon-dread Oct 26, 2024
9fc3f1b
add filename to readme examples
arizon-dread Oct 26, 2024
1cd0740
escape the ? in sed for NotifyClamd
arizon-dread Oct 27, 2024
ac92f6b
Merge branch 'master' into scan-v2 after topic/bch/56-fix-notify-path…
arizon-dread Nov 13, 2024
79fef61
update to centos:stream9 because centos:stream8 is EOL and won't buil…
arizon-dread Nov 14, 2024
70dec07
use go modules. update to stream9
arizon-dread Nov 14, 2024
1726d5a
add nc to trigger reload of database after 120 seconds to get new sig…
arizon-dread Nov 14, 2024
27e718d
create folder structure for clamav so it matches the entrypoint.sh sc…
arizon-dread Nov 14, 2024
4aed176
Merge remote-tracking branch 'origin/master' into scan-v2
arizon-dread Jan 7, 2025
aaf3ebd
update user group separator and uniform docker syntax to uppercase as…
arizon-dread Jan 8, 2025
4bcb9d7
minor docker syntax fix
davosian Jan 8, 2025
30f6e23
update user group separator and uniform docker syntax to uppercase as…
arizon-dread Jan 8, 2025
501b207
Merge branch 'scan-v2' of https://github.com/arizon-dread/clamav-rest…
davosian Jan 8, 2025
1e9abd1
Minor documentation improvements
davosian Jan 8, 2025
c1013d8
added project history and attribution
davosian Jan 8, 2025
04a55fc
Prepared update documentation
davosian Jan 8, 2025
ad922dc
unify responses
arizon-dread Jan 8, 2025
a83dc6b
unify response http status and make sure all endpoints increment the …
arizon-dread Jan 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ src
*.swp
clamrest
pyenv
__debug*
.vscode
clamav-rest
23 changes: 14 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:alpine3.19 as build
FROM golang:alpine3.20 AS build

# Update libraries
RUN apk update && apk upgrade
Expand All @@ -8,7 +8,7 @@ WORKDIR /go/src

# Build go package
ADD . /go/src/clamav-rest/
RUN cd /go/src/clamav-rest && go mod download github.com/dutchcoders/go-clamd@latest && go mod init clamav-rest && go mod tidy && go mod vendor && go build -v
RUN cd /go/src/clamav-rest && go mod tidy && go build -v

FROM alpine:3.21

Expand All @@ -31,21 +31,26 @@ ADD ./server.* /etc/ssl/clamav-rest/
# Install ClamAV
RUN apk --no-cache add clamav clamav-libunrar \
&& mkdir /run/clamav \
&& chown clamav:clamav /run/clamav
&& chown clamav:clamav /run/clamav


# Configure clamAV to run in foreground with port 3310
RUN sed -i 's/^#Foreground .*$/Foreground true/g' /etc/clamav/clamd.conf \
RUN sed -i 's/^#Foreground .*$/Foreground yes/g' /etc/clamav/clamd.conf \
&& sed -i 's/^#TCPSocket .*$/TCPSocket 3310/g' /etc/clamav/clamd.conf \
&& sed -i 's/^#Foreground .*$/Foreground true/g' /etc/clamav/freshclam.conf
&& sed -i 's/^#Foreground .*$/Foreground yes/g' /etc/clamav/freshclam.conf

RUN freshclam --quiet --no-dns

COPY entrypoint.sh /usr/bin/

RUN mkdir /clamav \
&& chown -R clamav.clamav /clamav \
&& chown -R clamav.clamav /var/log/clamav \
&& chown -R clamav.clamav /run/clamav
RUN mkdir -p /clamav/etc \
&& mkdir -p /clamav/data \
&& mkdir -p /clamav/tmp

RUN chown -R clamav:clamav /clamav \
&& chown -R clamav:clamav /var/log/clamav \
&& chown -R clamav:clamav /run/clamav


ENV PORT=9000
ENV SSL_PORT=9443
Expand Down
50 changes: 31 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ This is a two in one docker image which runs the open source virus scanner ClamA

# Updates

As of October 21 2024, freshclam notifies the correct `.clamd.conf` so that `clamd` is notified about updates and the correct version is returned now.
2025-01-08: [PR 50](https://github.com/ajilach/clamav-rest/pull/50) integrated which now provides a new `/v2` endpoint returning more scan result information: status, description, http status and a list of scanned files. See the PR for more details. The old `/scan` endpoint is now considered deprecated. Also, a file size scan limit has been added which can be configured through the `MAX_FILE_SIZE` environment variable.

2024-10-21: freshclam notifies the correct `.clamd.conf` so that `clamd` is notified about updates and the correct version is returned now.
This is an additional fix to the latest fix from October 15 2024 which was not working. Thanks to [christianbumann](https://github.com/christianbumann) and [arizon-dread](https://github.com/arizon-dread).

As of October 15 2024, ClamAV was thought to handle database updates correctly thanks to [christianbumann](https://github.com/christianbumann). It turned out that this was not the case.
2024-10-15: ClamAV was thought to handle database updates correctly thanks to [christianbumann](https://github.com/christianbumann). It turned out that this was not the case.

As of May 2024, the releases are built for multiple architectures thanks to efforts from [kcirtapfromspace](https://github.com/kcirtapfromspace) and support non-root read-only deployments thanks to [robaca](https://github.com/robaca).

Expand Down Expand Up @@ -59,37 +61,40 @@ docker run -p 9000:9000 -p 9443:9443 -itd --name clamav-rest ajilaag/clamav-rest

Test that service detects common test virus signature:

**HTTP**
**HTTP:**

```bash
$ curl -i -F "[email protected]" http://localhost:9000/scan
$ curl -i -F "[email protected]" http://localhost:9000/v2/scan
HTTP/1.1 100 Continue

HTTP/1.1 406 Not Acceptable
Content-Type: application/json; charset=utf-8
Date: Mon, 28 Aug 2017 20:22:34 GMT
Content-Length: 56

{ "Status": "FOUND", "Description": "Eicar-Test-Signature" }
[{ "Status": "FOUND", "Description": "Eicar-Test-Signature","FileName":"eicar.com.txt"}]
```

**HTTPS**
**HTTPS:**

```bash
$ curl -i -k -F "[email protected]" https://localhost:9443/scan
$ curl -i -k -F "[email protected]" https://localhost:9443/v2/scan
HTTP/1.1 100 Continue

HTTP/1.1 406 Not Acceptable
Content-Type: application/json; charset=utf-8
Date: Mon, 28 Aug 2017 20:22:34 GMT
Content-Length: 56

{ "Status": "FOUND", "Description": "Eicar-Test-Signature" }
[{ "Status": "FOUND", "Description": "Eicar-Test-Signature","FileName":"eicar.com.txt"}]
```

Test that service returns 200 for clean file:

**HTTP**
**HTTP:**

```bash
$ curl -i -F "[email protected]" http://localhost:9000/scan
$ curl -i -F "[email protected]" http://localhost:9000/v2/scan

HTTP/1.1 100 Continue

Expand All @@ -98,11 +103,12 @@ Content-Type: application/json; charset=utf-8
Date: Mon, 28 Aug 2017 20:23:16 GMT
Content-Length: 33

{ "Status": "OK", "Description": "" }
[{ "Status": "OK", "Description": "","FileName":"clamrest.go"}]
```
**HTTPS**
**HTTPS:**

```bash
$ curl -i -k -F "[email protected]" https://localhost:9443/scan
$ curl -i -k -F "[email protected]" https://localhost:9443/v2/scan

HTTP/1.1 100 Continue

Expand All @@ -111,14 +117,16 @@ Content-Type: application/json; charset=utf-8
Date: Mon, 28 Aug 2017 20:23:16 GMT
Content-Length: 33

{ "Status": "OK", "Description": "" }
[{ "Status": "OK", "Description": "","FileName":"clamrest.go"}]
```

## Status Codes
- 200 - clean file = no KNOWN infections
- 400 - ClamAV returned general error for file
- 406 - INFECTED
- 412 - unable to parse file
- 413 - request entity too large, the file exceeds the scannable limit. Set MAX_FILE_SIZE to scan larger files
- 422 - filename is missing in MimePart
- 501 - unknown request

# Configuration
Expand Down Expand Up @@ -172,24 +180,28 @@ clamscan --database=/clamav/data --version

[Prometheus metrics](https://prometheus.io/docs/guides/go-application/) were implemented, which can be retrieved as follows

**HTTP**:
**HTTP:**
curl http://localhost:9000/metrics

**HTTPS:**
curl https://localhost:9443/metrics

# Developing
# Development

Source Code can be found here: https://github.com/ajilach/clamav-rest
Source code can be found here: https://github.com/ajilach/clamav-rest

Build golang (linux) binary and docker image:

```bash
# env GOOS=linux GOARCH=amd64 go build
docker build . -t clamav-go-rest
docker run -p 9000:9000 -p 9443:9443 -itd --name clamav-rest clamav-go-rest
docker build . -t clamav-rest
docker run -p 9000:9000 -p 9443:9443 -itd --name clamav-rest clamav-rest
```

# History

This work is based on the awesome work done by [o20ne/clamav-rest](https://github.com/o20ne/clamav-rest) which is based on [niilo/clamav-rest](https://github.com/niilo/clamav-rest) which is based on the original code from [osterzel/clamav-rest](https://github.com/osterzel/clamav-rest).

# References

* https://www.clamav.net
Expand Down
18 changes: 13 additions & 5 deletions centos.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM quay.io/centos/centos:stream8 as build
FROM quay.io/centos/centos:stream9 as build

# Set timezone to Europe/Zurich
ENV TZ=Europe/Zurich
Expand All @@ -16,17 +16,17 @@ ENV GOPATH=/go \

# Build go package
ADD . /go/src/clamav-rest/
RUN cd /go/src/clamav-rest && go mod download github.com/dutchcoders/go-clamd@latest && go mod init clamav-rest && go mod tidy && go mod vendor && go build -v
RUN cd /go/src/clamav-rest && go mod tidy && go build -v

FROM quay.io/centos/centos:stream8
FROM quay.io/centos/centos:stream9

# Copy compiled clamav-rest binary from build container to production container
COPY --from=build /go/src/clamav-rest/clamav-rest /usr/bin/

# Install ClamAV
RUN dnf -y update \
&& dnf install -y epel-release \
&& dnf install -y clamav-server clamav-data clamav-update clamav-filesystem clamav clamav-scanner-systemd clamav-devel clamav-lib clamav-server-systemd \
&& dnf install -y clamav-server clamav-data clamav-update clamav-filesystem clamav clamav-scanner-systemd clamav-devel clamav-lib clamav-server-systemd nc \
&& mkdir /run/clamav \
&& chown clamscan:clamscan /run/clamav \
# Clean
Expand All @@ -44,7 +44,15 @@ RUN freshclam --quiet --no-dns
ADD ./server.* /etc/ssl/clamav-rest/

COPY entrypoint.sh /usr/bin/
RUN mkdir /etc/clamav/ && ln -s /etc/clamd.d/scan.conf /etc/clamav/clamd.conf

# Create folders for clamav so it matches what happens in entrypoint.sh
RUN install -d -m 0775 -oclamupdate -groot /var/log/clamav /etc/clamav /clamav /clamav/etc /clamav/data /clamav/tmp \
&& cp /etc/clamd.d/scan.conf /etc/clamav/clamd.conf \
&& cp /etc/freshclam.conf /etc/clamav/freshclam.conf \
&& chown clamupdate:root /etc/clamav/freshclam.conf

# On CentOS, clamupdate is the user.
USER clamupdate

EXPOSE 9000
EXPOSE 9443
Expand Down
Loading