Skip to content

Commit 0efa670

Browse files
authored
Merge pull request #1 from vaggeliskls/feat/prepare-repo
Feat/prepare repo
2 parents 41129ae + 41e3b14 commit 0efa670

File tree

10 files changed

+402
-1
lines changed

10 files changed

+402
-1
lines changed

.env

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# LDAP Configuration
2+
LDAP_ENABLED=false
3+
LDAP_URL=ldaps://ldap.example.com
4+
LDAP_ATTRIBUTE=uid
5+
LDAP_BASE_DN=ou=users,dc=example,dc=com
6+
LDAP_BIND_DN=uid=searchuser,ou=users,dc=example,dc=com
7+
LDAP_BIND_PASSWORD=securepassword
8+
9+
# OAUTH Configuration
10+
OAUTH_ENABLED=false
11+
OAUTH_CLIENT_ID=1234567890-abcdefghijklm.apps.googleusercontent.com
12+
OAUTH_CLIENT_SECRET=ABC123def456GHI789jkl0mnopqrs
13+
OAUTH_SCOPE="openid email profile"
14+
OAUTH_REDIRECT_URI=http://localhost
15+
OAUTH_METADATA_URL="https://accounts.google.com/.well-known/openid-configuration"
16+
OAUTH_CRYPTO_PASSPHRASE=mysecurepassphrase
17+
OAUTH_FORWARDED_HEADER=X-Forwarded-Host X-Forwarded-Port X-Forwarded-Proto
18+
19+
# Basic Digest Authentication with users space separated
20+
BASIC_AUTH_ENABLED=false
21+
BASIC_AUTH_REALM=Webdev
22+
BASIC_USERS=alice:alice bob:bob

.github/pull_request_template.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Current Behaviour
2+
3+
# Expected Behaviour

.github/workflows/ci.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Create WebDav Docker Image
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
env:
8+
REGISTRY: ghcr.io
9+
TAG_NAME: ${{ github.ref_name }}
10+
11+
jobs:
12+
webdav:
13+
name: WebDav Server
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout current repository
17+
uses: actions/checkout@v4
18+
19+
- name: Set up QEMU
20+
uses: docker/setup-qemu-action@v3
21+
22+
- name: Set up Docker Buildx
23+
uses: docker/setup-buildx-action@v3
24+
25+
- name: Docker meta
26+
id: meta
27+
uses: docker/metadata-action@v5
28+
with:
29+
# list of Docker images to use as base name for tags
30+
images: |
31+
${{ env.REGISTRY }}/${{ github.repository }}
32+
# generate Docker tags based on the following events/attributes
33+
tags: |
34+
type=ref,event=branch
35+
type=ref,event=pr
36+
type=semver,pattern={{version}}
37+
38+
- name: Login to Github packages
39+
uses: docker/login-action@v3
40+
with:
41+
registry: ${{ env.REGISTRY }}
42+
username: ${{ github.actor }}
43+
password: ${{ secrets.GITHUB_TOKEN }}
44+
45+
- name: 📦 Build and push
46+
uses: docker/build-push-action@v6
47+
with:
48+
context: .
49+
file: ./Dockerfile
50+
push: true
51+
tags: ${{ steps.meta.outputs.tags }}
52+
labels: ${{ steps.meta.outputs.labels }}
53+
platforms: linux/amd64,linux/arm64

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
webdav-data
2+
test

Dockerfile

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
FROM httpd:2.4
2+
3+
# Metadata labels
4+
LABEL maintainer="vaggeliskls <https://github.com/vaggeliskls>"
5+
LABEL description="A WebDAV server running on Apache httpd, configured for non-root execution."
6+
LABEL build_date="$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
7+
LABEL license="MIT"
8+
9+
# Install gettext for envsubst
10+
RUN apt-get update && apt-get install -y gettext-base libapache2-mod-auth-openidc
11+
12+
# Create a non-root user and group
13+
RUN groupadd -r webuser && useradd -r -g webuser webuser
14+
15+
# Create necessary directories and adjust ownership
16+
RUN mkdir -p "/var/www/html" && \
17+
mkdir -p "/var/lib/dav/data" && \
18+
touch "/var/lib/dav/DavLock" && \
19+
chown -R webuser:webuser "/var/www/html" "/var/lib/dav" "/usr/local/apache2"
20+
21+
# Uncomment necessary LoadModule lines in httpd.conf
22+
RUN for i in \
23+
authn_core authn_file authz_core authz_user auth_digest \
24+
ldap authnz_ldap ssl auth_basic \
25+
alias headers mime setenvif \
26+
dav dav_fs; \
27+
do \
28+
sed -i -e "/^#LoadModule ${i}_module.*/s/^#//" /usr/local/apache2/conf/httpd.conf; \
29+
done
30+
31+
# Enable Icons
32+
RUN sed -i '/httpd-autoindex.conf/s/^#//' conf/httpd.conf;
33+
34+
# Copy the new configuration files into the container
35+
COPY ./webdav.conf /usr/local/apache2/conf/webdav.conf.template
36+
COPY ./virtualhost.conf /usr/local/apache2/conf/virtualhost.conf.template
37+
38+
# Change ports in the Apache configuration to higher ports
39+
RUN sed -i 's/Listen 80/Listen 8080/' /usr/local/apache2/conf/httpd.conf && \
40+
sed -i 's/Listen 443/Listen 8443/' /usr/local/apache2/conf/httpd.conf
41+
42+
# Copy the entrypoint script into the container
43+
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
44+
# Make the entrypoint script executable
45+
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
46+
47+
# Expose the new higher ports
48+
EXPOSE 8080/tcp 8443/tcp
49+
# Switch to the non-root user
50+
USER webuser
51+
ENTRYPOINT [ "docker-entrypoint.sh" ]
52+
CMD [ "httpd-foreground" ]

README.md

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,76 @@
1-
# webdav-server
1+
# 🌐 Simple & Powerful WebDAV Server
2+
3+
The **WebDAV Server** is a lightweight, customizable solution built with Docker, designed for secure file sharing and remote access. It offers flexible configuration options and supports multiple authentication methods, including basic authentication, LDAP, and OAuth. With minimal setup, this server is ideal for both personal and enterprise use cases where easy deployment and secure access are key.
4+
5+
6+
> [!NOTE]
7+
> The pre-built Docker image is available at: **`ghcr.io/vaggeliskls/webdav-server:latest`**
8+
9+
## 📦 Prerequisites
10+
11+
Before getting started, make sure you have the following:
12+
13+
- **Docker** version **20.0** or higher
14+
- Basic knowledge of Docker and WebDAV
15+
16+
## 🚀 Key Features
17+
18+
- **Effortless Deployment**: Set up a fully operational WebDAV server quickly using Docker.
19+
- **Flexible Authentication**:
20+
- Basic Authentication 🛡️
21+
- LDAP Authentication 🛡️
22+
- OAuth Authentication 🛡️
23+
- **Proxy-Ready**: Easily integrate with reverse proxies to add more authentication layers.
24+
- **Authentication is Optional**: The server runs without authentication by default, allowing flexibility for your setup.
25+
26+
## 🔧 Authentication Setup
27+
28+
You can enable various authentication mechanisms using environment variables in a `.env` file. Here’s how to configure each one:
29+
30+
### 🔐 Basic Authentication
31+
32+
To enable basic authentication with username and password protection:
33+
34+
```bash
35+
BASIC_AUTH_ENABLED=true
36+
BASIC_AUTH_REALM=WebDAV
37+
BASIC_USERS=alice:alice123 bob:bob123
38+
```
39+
40+
### 🔐 OAuth Authentication
41+
OAuth authentication (example with Google OAuth) configuration:
42+
```
43+
OAUTH_ENABLED=true
44+
OAUTH_CLIENT_ID=1234567890-abcdefghijklm.apps.googleusercontent.com
45+
OAUTH_CLIENT_SECRET=ABC123def456GHI789jkl0mnopqrs
46+
OAUTH_SCOPE="openid email profile"
47+
OAUTH_REDIRECT_URI=http://localhost
48+
OAUTH_METADATA_URL="https://accounts.google.com/.well-known/openid-configuration"
49+
OAUTH_CRYPTO_PASSPHRASE=mysecurepassphrase
50+
OAUTH_FORWARDED_HEADER=X-Forwarded-Host,X-Forwarded-Port,X-Forwarded-Proto
51+
```
52+
53+
### 🔐 LDAP Authentication
54+
LDAP integration for centralized user management:
55+
```
56+
LDAP_ENABLED=true
57+
LDAP_URL=ldaps://ldap.example.com
58+
LDAP_ATTRIBUTE=uid
59+
LDAP_BASE_DN=ou=users,dc=example,dc=com
60+
LDAP_BIND_DN=uid=admin,ou=users,dc=example,dc=com
61+
LDAP_BIND_PASSWORD=securepassword
62+
```
63+
64+
## 📖 Usage Guide
65+
66+
1. Clone Repository
67+
68+
2. Start the WebDAV Server: `docker compose up --build`
69+
70+
3. Open http://localhost or your server's IP in a browser or WebDAV client to start using the service.
71+
72+
73+
## 📚 References
74+
75+
- [Docker Apache WebDAV](https://github.com/mgutt/docker-apachewebdav)
76+
- [What is WebDAV?](https://www.jscape.com/blog/what-is-webdav)

docker-compose.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
version: "3.8"
2+
3+
services:
4+
webdav:
5+
image: ghcr.io/vaggeliskls/webdav-server:latest
6+
build:
7+
context: .
8+
dockerfile: Dockerfile
9+
platform: linux/amd64
10+
volumes:
11+
- ./webdav-data:/var/lib/dav/data
12+
networks:
13+
- webdav-network
14+
env_file:
15+
- .env
16+
labels:
17+
- "traefik.enable=true"
18+
- "traefik.http.routers.webdav.service=webdav"
19+
# Register Middleware ====================================================
20+
- "traefik.http.routers.webdav.middlewares=compresstraefik"
21+
# =================================================================================
22+
- "traefik.http.middlewares.compresstraefik.compress=true"
23+
- "traefik.http.services.webdav.loadbalancer.server.port=8080"
24+
- "traefik.http.services.webdav.loadbalancer.passhostheader=true"
25+
## Use PathPrefix rule to catch all requests
26+
- "traefik.http.routers.webdav.rule=PathPrefix(`/`)"
27+
- "traefik.http.routers.webdav.entrypoints=web,websecure"
28+
29+
webdav-proxy:
30+
image: traefik:v3.1
31+
platform: linux/amd64
32+
command:
33+
- "--providers.docker=true"
34+
- "--providers.docker.exposedbydefault=false"
35+
- "--entrypoints.web.address=:80"
36+
- "--entrypoints.websecure.address=:443"
37+
ports:
38+
- "80:80"
39+
- "443:443"
40+
volumes:
41+
- /var/run/docker.sock:/var/run/docker.sock
42+
networks:
43+
- webdav-network
44+
45+
networks:
46+
webdav-network:
47+
driver: bridge

docker-entrypoint.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# Function to uncomment a block in a file based on a dynamic block name
5+
uncomment_block() {
6+
local block_name="$1"
7+
sed -i "/# ${block_name}_START/,/# ${block_name}_END/ s/^# //" "/usr/local/apache2/conf/webdav.conf"
8+
}
9+
10+
# Function to comment a block in a file based on a dynamic block name
11+
comment_block() {
12+
local block_name="$1"
13+
sed -i "/# ${block_name}_START/,/# ${block_name}_END/ s/^[^#]/# &/" "/usr/local/apache2/conf/webdav.conf"
14+
}
15+
16+
envsubst < /usr/local/apache2/conf/webdav.conf.template > /usr/local/apache2/conf/webdav.conf
17+
envsubst < /usr/local/apache2/conf/virtualhost.conf.template > /usr/local/apache2/conf/virtualhost.conf
18+
19+
comment_block "OAUTH_BLOCK"
20+
comment_block "LDAP_BLOCK"
21+
comment_block "BASIC_BLOCK"
22+
comment_block "PUBLIC_BLOCK"
23+
24+
if [ "$LDAP_ENABLED" = "true" ]; then
25+
echo "--> LDAP is enabled";
26+
uncomment_block "LDAP_BLOCK"
27+
elif [ "$OAUTH_ENABLED" = "true" ]; then
28+
echo "--> OAUTH is enabled";
29+
uncomment_block "OAUTH_BLOCK"
30+
elif [ "$BASIC_AUTH_ENABLED" = "true" ]; then
31+
echo "--> Basic Auth is enabled";
32+
uncomment_block "BASIC_BLOCK"
33+
# Prepare the password file
34+
touch "/var/lib/dav/user.passwd"
35+
echo "$BASIC_USERS" | tr ' ' '\n' | while IFS=':' read -r USERNAME PASSWORD; do
36+
# Output the username and password
37+
echo "Username: $USERNAME, Password: $PASSWORD"
38+
HASH="`printf '%s' "$USERNAME:$BASIC_AUTH_REALM:$PASSWORD" | md5sum | awk '{print $1}'`"
39+
printf '%s\n' "$USERNAME:$BASIC_AUTH_REALM:$HASH" >> /var/lib/dav/user.passwd
40+
done
41+
else
42+
echo "--> No Authentication is enabled";
43+
uncomment_block "PUBLIC_BLOCK"
44+
fi
45+
46+
# mkdir -p /test
47+
# cp /usr/local/apache2/conf/webdav.conf /test/webdav.conf
48+
49+
echo "Include conf/webdav.conf" >> /usr/local/apache2/conf/httpd.conf
50+
echo "Include conf/virtualhost.conf" >> /usr/local/apache2/conf/httpd.conf
51+
rm -rf /usr/local/apache2/conf/*.template
52+
53+
exec "$@"

virtualhost.conf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<VirtualHost *:80>
2+
ServerName localhost
3+
DocumentRoot "/var/www/html/"
4+
<Directory "/var/www/html/">
5+
Require all denied
6+
</Directory>
7+
CustomLog /proc/self/fd/1 combined
8+
ErrorLog /proc/self/fd/2
9+
# This lets certain DAV methods work behind an SSL reverse proxy.
10+
RequestHeader edit Destination ^https http early
11+
12+
</VirtualHost>

0 commit comments

Comments
 (0)