Skip to content

Commit f5e9849

Browse files
authored
Merge pull request #1989 from ipfs/add-kubo-tls-guide
kubo rpc: tls and basic http auth guide
2 parents 6cb430e + 10177f7 commit f5e9849

File tree

5 files changed

+116
-0
lines changed

5 files changed

+116
-0
lines changed

.github/styles/pln-ignore.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ bool(ean)
2222
boolean
2323
boxo
2424
browserify
25+
caddy
26+
Caddyfile
2527
callout
2628
callouts
2729
cas
@@ -114,6 +116,7 @@ keepalive
114116
keypair
115117
keystores
116118
kubo
119+
Kubo's
117120
kubuxu
118121
laika
119122
lan
@@ -213,6 +216,7 @@ Someguy
213216
subcommand
214217
substring
215218
sys
219+
systemd
216220
sztandera
217221
testground
218222
testnet

docs/.vuepress/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ module.exports = {
208208
'/how-to/configure-node',
209209
'/how-to/modify-bootstrap-list',
210210
'/how-to/nat-configuration',
211+
'/how-to/kubo-rpc-tls-auth',
211212
'/how-to/ipfs-updater',
212213
[
213214
'https://github.com/ipfs-examples/js-ipfs-examples/tree/master/examples/custom-ipfs-repo',

docs/how-to/kubo-rpc-tls-auth.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
---
2+
title: Secure Kubo RPC with TLS and HTTP Auth
3+
description: Learn how to set up TLS for Kubo with Caddy reverse proxy for secure RPC API access over public networks.
4+
---
5+
6+
# Secure Kubo RPC with TLS and HTTP Auth
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 using a domain you control.
11+
- **Authentication:** Basic HTTP authentication for the [Kubo RPC API](../reference/kubo/rpc.md).
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 CIDs from CI, or other services. Since the Kubo RPC API is exposed over plain HTTP, TLS is used 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+
The guide assumes the Caddy process is managed by systemd. If you are using a different process manager or Docker, you will need to adjust the configuration accordingly.
25+
26+
## Configure Kubo
27+
28+
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:
29+
30+
```
31+
"API": {
32+
"HTTPHeaders": {
33+
"Access-Control-Allow-Origin": ["https://YOUR_DOMAIN"],
34+
"Access-Control-Allow-Credentials": ["true"]
35+
},
36+
"Authorizations": {
37+
"api": {
38+
"AuthSecret": "basic:hello:world123"
39+
"AllowedPaths": [
40+
"/api/v0"
41+
]
42+
}
43+
}
44+
}
45+
```
46+
47+
This configuration:
48+
49+
- 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.
50+
- Restricts API access to the Kubo RPC API, allowing access to the `/api/v0` endpoints with basic HTTP authentication.
51+
52+
> **Note:** You should set the `AuthSecret` to a stronger username and password combination.
53+
54+
## Configure Caddy
55+
56+
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:
57+
58+
```
59+
YOUR_DOMAIN {
60+
reverse_proxy localhost:5001
61+
62+
log {
63+
output stdout
64+
format json
65+
level INFO
66+
}
67+
}
68+
```
69+
70+
This configuration:
71+
72+
- Sets up a reverse proxy to Kubo's API on port 5001
73+
- Logs requests to the Kubo API in JSON format to stdout
74+
75+
## Restart Caddy
76+
77+
Restart the Caddy service to apply the changes:
78+
79+
```bash
80+
sudo systemctl restart caddy
81+
```
82+
83+
## Test the Connection
84+
85+
To verify everything is working correctly, test the connection using the IPFS CLI, making sure to replace `YOUR_DOMAIN` with your actual domain name:
86+
87+
```bash
88+
ipfs id --api /dns/YOUR_DOMAIN/tcp/443/https --api-auth basic:hello:world123
89+
```
90+
91+
If successful, you should see your node's identify displayed. The command connects to your Kubo node through the secure HTTPS endpoint using basic authentication.
92+
93+
## Security Considerations
94+
95+
- Change the `AuthSecret` to a strong username and password combination
96+
- Consider restricting the `AllowedPaths` further based on your needs
97+
- Keep your Caddy and Kubo installations updated
98+
- Regularly monitor the logs for any suspicious activity
99+
100+
## Troubleshooting
101+
102+
If you encounter issues:
103+
104+
1. Check Caddy logs
105+
2. Verify your domain's DNS settings, ensuring the A record is correct. Sometimes changes can take a few minutes to propagate (depending on the TTL of the DNS record).
106+
3. Ensure port 443 is open and not blocked by your firewall
107+
4. Check that Kubo is running and accessible on localhost:5001

docs/reference/kubo/rpc.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ The RPC API provides admin-level access to your Kubo IPFS node, including `/api/
6262

6363
It is bound to `localhost` by default on purpose. You should never expose it to the public internet, just like you would never expose a SQL database or other backend service.
6464

65+
To expose the RPC API to the public internet with TLS encryption and HTTP authentication, check out the [TLS and HTTP Auth for Kubo with Caddy](../../how-to/kubo-rpc-tls-auth.md) guide.
66+
6567
If you are looking for an interface designed for browsers and public internet, consider implementation-agnostic [HTTP Gateway](../../reference/http/gateway.md) instead.
6668
:::
6769

tools/http-api-docs/markdown.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ The RPC API provides admin-level access to your Kubo IPFS node, including `+"`/a
8282
8383
It is bound to `+"`localhost`"+` by default on purpose. You should never expose it to the public internet, just like you would never expose a SQL database or other backend service.
8484
85+
To expose the RPC API to the public internet with TLS encryption and HTTP authentication, check out the [TLS and HTTP Auth for Kubo with Caddy](../../how-to/kubo-rpc-tls-auth.md) guide.
86+
8587
If you are looking for an interface designed for browsers and public internet, consider implementation-agnostic [HTTP Gateway](../../reference/http/gateway.md) instead.
8688
:::
8789

0 commit comments

Comments
 (0)