Skip to content

Commit 1e6dd5d

Browse files
docs: Add comprehensive add-package guide and update documentation index
Co-authored-by: fabriziosalmi <1569108+fabriziosalmi@users.noreply.github.com>
1 parent dc5d081 commit 1e6dd5d

File tree

3 files changed

+197
-14
lines changed

3 files changed

+197
-14
lines changed

README.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -176,19 +176,20 @@ For complete documentation, including configuration options, rule format details
176176
### 📑 Table of Contents
177177

178178
1. [**Installation**](docs/installation.md) - *Instructions for installing the Caddy WAF middleware.*
179-
2. [**Configuration Options**](docs/configuration.md) - *Detailed explanation of all available configuration settings.*
180-
3. [**Rules Format (`rules.json`)**](docs/rules.md) - *A comprehensive guide to defining custom rules using the JSON format.*
181-
4. [**Blacklist Formats**](docs/blacklists.md) - *Documentation of the formats used for defining IP and DNS blacklists.*
182-
5. [**Rate Limiting**](docs/ratelimit.md) - *How to configure rate limiting, including parameters and usage.*
183-
6. [**Country Blocking and Whitelisting**](docs/geoblocking.md) - *Details on how to configure country-based blocking and whitelisting.*
184-
7. [**Protected Attack Types**](docs/attacks.md) - *An overview of the wide range of web-based threats that the Caddy WAF is designed to protect against.*
185-
8. [**Dynamic Updates**](docs/dynamicupdates.md) - *How to dynamically update the WAF rules and other settings without downtime.*
186-
9. [**Metrics**](docs/metrics.md) - *Details about the WAF's metrics endpoint and the different metrics collected.*
187-
10. [**Prometheus Metrics**](docs/prometheus.md) - *Instructions on how to expose WAF metrics using the Prometheus format.*
188-
11. [**ELK Observability**](https://github.com/fabriziosalmi/caddy-waf/blob/main/docs/caddy-waf-elk.md) - *Instructions on how to configure caddy-waf ELK stack observability.*
189-
12. [**Rule/Blacklist Population Scripts**](docs/scripts.md) - *Documentation on the provided scripts to automatically fetch, update and generate rules and blacklists.*
190-
13. [**Testing**](docs/testing.md) - *Guidance on how to test the WAF's effectiveness using the provided testing tools.*
191-
14. [**Docker Support**](docs/docker.md) - *Instructions on how to build and run the WAF using Docker.*
179+
2. [**Using `caddy add-package`**](docs/add-package-guide.md) - *Quick guide for installing with the `caddy add-package` command.*
180+
3. [**Configuration Options**](docs/configuration.md) - *Detailed explanation of all available configuration settings.*
181+
4. [**Rules Format (`rules.json`)**](docs/rules.md) - *A comprehensive guide to defining custom rules using the JSON format.*
182+
5. [**Blacklist Formats**](docs/blacklists.md) - *Documentation of the formats used for defining IP and DNS blacklists.*
183+
6. [**Rate Limiting**](docs/ratelimit.md) - *How to configure rate limiting, including parameters and usage.*
184+
7. [**Country Blocking and Whitelisting**](docs/geoblocking.md) - *Details on how to configure country-based blocking and whitelisting.*
185+
8. [**Protected Attack Types**](docs/attacks.md) - *An overview of the wide range of web-based threats that the Caddy WAF is designed to protect against.*
186+
9. [**Dynamic Updates**](docs/dynamicupdates.md) - *How to dynamically update the WAF rules and other settings without downtime.*
187+
10. [**Metrics**](docs/metrics.md) - *Details about the WAF's metrics endpoint and the different metrics collected.*
188+
11. [**Prometheus Metrics**](docs/prometheus.md) - *Instructions on how to expose WAF metrics using the Prometheus format.*
189+
12. [**ELK Observability**](https://github.com/fabriziosalmi/caddy-waf/blob/main/docs/caddy-waf-elk.md) - *Instructions on how to configure caddy-waf ELK stack observability.*
190+
13. [**Rule/Blacklist Population Scripts**](docs/scripts.md) - *Documentation on the provided scripts to automatically fetch, update and generate rules and blacklists.*
191+
14. [**Testing**](docs/testing.md) - *Guidance on how to test the WAF's effectiveness using the provided testing tools.*
192+
15. [**Docker Support**](docs/docker.md) - *Instructions on how to build and run the WAF using Docker.*
192193

193194
---
194195

docs/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ This documentation provides everything you need to deploy and manage the Caddy W
88

99
### 🚀 Getting Started
1010

11-
1. **[Introduction](introduction.md)** - *Overview of the Caddy WAF, its purpose, and key benefits.
11+
1. **[Introduction](introduction.md)** - *Overview of the Caddy WAF, its purpose, and key benefits.*
1212
2. **[Installation](installation.md)** - *Instructions for installing the Caddy WAF middleware.*
13+
3. **[Using caddy add-package](add-package-guide.md)** - *Quick guide for installing with the `caddy add-package` command.*
1314

1415
### ⚙️ Core Configuration
1516

docs/add-package-guide.md

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
# Using `caddy add-package` to Install Caddy WAF
2+
3+
This guide demonstrates how to install the Caddy WAF module using Caddy's built-in `caddy add-package` command.
4+
5+
## Prerequisites
6+
7+
- Caddy v2.7 or higher already installed on your system
8+
- Internet connection (to download the custom binary)
9+
- Appropriate permissions to replace the Caddy binary
10+
11+
## Quick Installation
12+
13+
To add the Caddy WAF module to your existing Caddy installation:
14+
15+
```bash
16+
caddy add-package github.com/fabriziosalmi/caddy-waf
17+
```
18+
19+
That's it! The command will:
20+
1. Detect your current Caddy installation and modules
21+
2. Send a build request to Caddy's remote build service
22+
3. Download a new binary with the WAF module included
23+
4. Backup your current Caddy binary
24+
5. Replace the binary with the new one
25+
26+
## Verification
27+
28+
After installation, verify the module is loaded:
29+
30+
```bash
31+
caddy list-modules | grep waf
32+
```
33+
34+
Expected output:
35+
```
36+
http.handlers.waf
37+
```
38+
39+
You can also check the full list of modules:
40+
```bash
41+
caddy list-modules --packages
42+
```
43+
44+
## Usage Example
45+
46+
Once installed, you can use the WAF module in your Caddyfile:
47+
48+
```caddyfile
49+
{
50+
auto_https off
51+
admin localhost:2019
52+
}
53+
54+
:8080 {
55+
log {
56+
output stdout
57+
format console
58+
level INFO
59+
}
60+
61+
route {
62+
waf {
63+
metrics_endpoint /waf_metrics
64+
rule_file rules.json
65+
ip_blacklist_file ip_blacklist.txt
66+
dns_blacklist_file dns_blacklist.txt
67+
anomaly_threshold 10
68+
69+
rate_limit {
70+
requests 100
71+
window 60s
72+
cleanup_interval 300s
73+
}
74+
}
75+
76+
respond "Hello, World!" 200
77+
}
78+
}
79+
```
80+
81+
## Advanced Options
82+
83+
### Keep Backup
84+
85+
By default, the command deletes the backup after successful replacement. To keep the backup:
86+
87+
```bash
88+
caddy add-package --keep-backup github.com/fabriziosalmi/caddy-waf
89+
```
90+
91+
The backup will be saved as `caddy.backup` in the same directory.
92+
93+
### Version Pinning
94+
95+
To install a specific version of the module:
96+
97+
```bash
98+
caddy add-package github.com/fabriziosalmi/caddy-waf@v0.1.3
99+
```
100+
101+
Note: Replace `v0.1.3` with the desired version tag.
102+
103+
## Troubleshooting
104+
105+
### Command Not Found
106+
107+
If the `caddy add-package` command is not available, you may be using an older version of Caddy:
108+
109+
```bash
110+
caddy version
111+
```
112+
113+
You need Caddy v2.7 or higher. Update Caddy first:
114+
115+
```bash
116+
# Using the official install script
117+
curl https://caddyserver.com/api/download\?os=linux\&arch=amd64 -o caddy
118+
chmod +x caddy
119+
sudo mv caddy /usr/local/bin/
120+
```
121+
122+
### Permission Denied
123+
124+
If you get a permission denied error, run the command with sudo:
125+
126+
```bash
127+
sudo caddy add-package github.com/fabriziosalmi/caddy-waf
128+
```
129+
130+
### Build Service Unavailable
131+
132+
If Caddy's remote build service is unavailable, you can build from source instead:
133+
134+
```bash
135+
# Install xcaddy
136+
go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest
137+
138+
# Build with the module
139+
xcaddy build --with github.com/fabriziosalmi/caddy-waf
140+
```
141+
142+
### Module Already Exists
143+
144+
If you get an error that the package already exists, the module is already installed. To update:
145+
146+
```bash
147+
# Remove the package first
148+
caddy remove-package github.com/fabriziosalmi/caddy-waf
149+
150+
# Then add it again
151+
caddy add-package github.com/fabriziosalmi/caddy-waf
152+
```
153+
154+
## Removing the Module
155+
156+
To remove the Caddy WAF module:
157+
158+
```bash
159+
caddy remove-package github.com/fabriziosalmi/caddy-waf
160+
```
161+
162+
## Comparison with Other Installation Methods
163+
164+
| Method | Pros | Cons |
165+
|--------|------|------|
166+
| `caddy add-package` | Simple, no build tools needed, keeps existing modules | Requires internet, depends on remote build service |
167+
| `xcaddy build` | Full control, works offline (after dependencies cached), good for development | Requires Go and build tools, more complex |
168+
| Quick script | Automated setup with sample configs | Downloads and builds from source, requires build tools |
169+
170+
## Next Steps
171+
172+
- Read the [Configuration Guide](configuration.md) to customize your WAF rules
173+
- Learn about [Rate Limiting](ratelimit.md) configuration
174+
- Explore [GeoIP Blocking](geoblocking.md) features
175+
- Check out the [Metrics](metrics.md) endpoint for monitoring
176+
177+
## References
178+
179+
- [Caddy Command Line Documentation](https://caddyserver.com/docs/command-line)
180+
- [Caddy Module System](https://caddyserver.com/docs/extending-caddy)
181+
- [xcaddy Build Tool](https://github.com/caddyserver/xcaddy)

0 commit comments

Comments
 (0)