Skip to content

Commit ce36c9d

Browse files
committed
add tls and basic http auth guide
1 parent 5c87dc0 commit ce36c9d

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed

docs/.vuepress/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ module.exports = {
207207
'/how-to/command-line-quick-start',
208208
'/how-to/configure-node',
209209
'/how-to/modify-bootstrap-list',
210+
'/how-to/kubo-tls',
210211
'/how-to/nat-configuration',
211212
'/how-to/ipfs-updater',
212213
[

docs/how-to/kubo-tls.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
---
2+
title: TLS and HTTP Auth for Kubo
3+
description: Learn how to set up TLS and basic HTTP auth for Kubo with Caddy reverse proxy for secure API access over public networks.
4+
---
5+
6+
# Setting up TLS and basic HTTP auth for Kubo with Caddy reverse proxy
7+
8+
This guide will help you set up two things:
9+
10+
- **Transport Encryption:** Caddy as a reverse proxy with automatic TLS certificate management for your Kubo node.
11+
- **Authentication:** Basic HTTP auth for the Kubo RPC API.
12+
13+
This is highly recommended if you run your own Kubo node and want to use the Kubo RPC API over public networks, for example, to pin data from CI, or other services. Since the Kubo RPC API is exposed over plain HTTP, you will need to use TLS to ensure the connection to the API is encrypted.
14+
15+
## Prerequisites
16+
17+
Before starting, ensure you have:
18+
19+
- A domain name (referred to as `YOUR_DOMAIN`) with its A record pointing to your server's IP address
20+
- Kubo running on a server/VM with a public IP address
21+
- Port 443 open on your server's firewall
22+
- [Caddy web server](https://caddyserver.com/) installed on the server
23+
24+
## Configure Kubo
25+
26+
First, you'll need to configure Kubo to work with the reverse proxy. Edit your Kubo config file (usually located at `~/.ipfs/config`) and update the API section:
27+
28+
```
29+
"API": {
30+
"HTTPHeaders": {
31+
"Access-Control-Allow-Origin": ["https://YOUR_DOMAIN"],
32+
"Access-Control-Allow-Credentials": ["true"]
33+
},
34+
"Authorizations": {
35+
"api": {
36+
"AuthSecret": "basic:hello:world123"
37+
"AllowedPaths": [
38+
"/api/v0"
39+
]
40+
}
41+
}
42+
}
43+
```
44+
45+
This configuration:
46+
47+
- Sets CORS headers to allow requests from `YOUR_DOMAIN`. Kubo will match the `host` header in the request with the `Access-Control-Allow-Origin` from the configuration, so you need to ensure the origin is correct.
48+
- Restricts API access to the Kubo RPC API, allowing access to the `/api/v0` endpoints with basic http authentication.
49+
50+
> **Note:** You should set the `AuthSecret` to a stronger username and password combination.
51+
52+
## Configure Caddy
53+
54+
Create or edit your Caddyfile (typically at `/etc/caddy/Caddyfile`) with the following configuration, making sure to replace `YOUR_DOMAIN` with your actual domain name:
55+
56+
```
57+
YOUR_DOMAIN {
58+
reverse_proxy localhost:5001
59+
60+
log {
61+
output stdout
62+
format json
63+
level INFO
64+
}
65+
}
66+
```
67+
68+
This configuration:
69+
70+
- Sets up a reverse proxy to Kubo's API on port 5001
71+
- Logs requests to the Kubo API in JSON format to stdout
72+
73+
## Restart Caddy
74+
75+
```bash
76+
sudo systemctl restart caddy
77+
```
78+
79+
## Test the Connection
80+
81+
To verify everything is working correctly, test the connection using the IPFS CLI:
82+
83+
```bash
84+
ipfs id --api /dns/YOUR_DOMAIN/tcp/443/https --api-auth basic:hello:world123
85+
```
86+
87+
If successful, you should see your node's information displayed. The command connects to your Kubo node through the secure HTTPS endpoint using basic authentication.
88+
89+
## Security Considerations
90+
91+
- Change the `AuthSecret` to a strong username and password combination
92+
- Consider restricting the `AllowedPaths` further based on your needs
93+
- Keep your Caddy and Kubo installations updated
94+
- Regularly monitor the logs for any suspicious activity
95+
96+
## Troubleshooting
97+
98+
If you encounter issues:
99+
100+
1. Check Caddy logs
101+
2. Verify your domain's DNS settings, ensuring the A record is correct
102+
3. Ensure port 443 is open and not blocked by your firewall
103+
4. Check that Kubo is running and accessible on localhost:5001

0 commit comments

Comments
 (0)