-
Notifications
You must be signed in to change notification settings - Fork 433
kubo rpc: tls and basic http auth guide #1989
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ce36c9d
add tls and basic http auth guide
2color 03f6e44
chore: add caddy to allowed names
2color 627d89b
fix: typo
2color 5e5892a
docs: refinemets
2color 1097548
chore: update permalink
2color 3370781
add link to guide from rpc docs
2color 1bd73ec
nit: include rpc in url slug
lidel b025d1e
test: regenerate rpc docs
lidel c79d583
Merge branch 'main' into add-kubo-tls-guide
lidel 923abe0
fix link and lint
lidel b78370d
Apply suggestions from code review
2color 10177f7
Apply suggestions from code review
2color File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
--- | ||
title: TLS and HTTP Auth for Kubo RPC with Caddy | ||
2color marked this conversation as resolved.
Show resolved
Hide resolved
|
||
description: Learn how to set up TLS for Kubo with Caddy reverse proxy for secure RPC API access over public networks. | ||
--- | ||
|
||
# Setting up TLS and HTTP authentication for Kubo RPC with Caddy reverse proxy | ||
2color marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
This guide will help you set up two things: | ||
|
||
- **Transport Encryption:** Caddy as a reverse proxy with automatic TLS certificate management for your Kubo node using a domain you control. | ||
- **Authentication:** Basic HTTP authentication for the [Kubo RPC API](../reference/kubo/rpc.md). | ||
|
||
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. | ||
|
||
## Prerequisites | ||
|
||
Before starting, ensure you have: | ||
|
||
- A domain name (referred to as `YOUR_DOMAIN`) with its A record pointing to your server's IP address | ||
- Kubo running on a server/VM with a public IP address | ||
- Port 443 open on your server's firewall | ||
- [Caddy web server](https://caddyserver.com/) installed on the server | ||
|
||
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. | ||
|
||
## Configure Kubo | ||
|
||
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: | ||
|
||
``` | ||
"API": { | ||
"HTTPHeaders": { | ||
"Access-Control-Allow-Origin": ["https://YOUR_DOMAIN"], | ||
"Access-Control-Allow-Credentials": ["true"] | ||
}, | ||
"Authorizations": { | ||
"api": { | ||
"AuthSecret": "basic:hello:world123" | ||
"AllowedPaths": [ | ||
"/api/v0" | ||
] | ||
} | ||
} | ||
} | ||
``` | ||
|
||
This configuration: | ||
|
||
- 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. | ||
- Restricts API access to the Kubo RPC API, allowing access to the `/api/v0` endpoints with basic HTTP authentication. | ||
|
||
> **Note:** You should set the `AuthSecret` to a stronger username and password combination. | ||
|
||
## Configure Caddy | ||
|
||
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: | ||
|
||
``` | ||
YOUR_DOMAIN { | ||
reverse_proxy localhost:5001 | ||
|
||
log { | ||
output stdout | ||
format json | ||
level INFO | ||
} | ||
} | ||
``` | ||
|
||
This configuration: | ||
|
||
- Sets up a reverse proxy to Kubo's API on port 5001 | ||
- Logs requests to the Kubo API in JSON format to stdout | ||
|
||
## Restart Caddy | ||
|
||
Restart the Caddy service to apply the changes: | ||
|
||
```bash | ||
sudo systemctl restart caddy | ||
``` | ||
|
||
## Test the Connection | ||
|
||
To verify everything is working correctly, test the connection using the IPFS CLI, making sure to replace `YOUR_DOMAIN` with your actual domain name: | ||
|
||
```bash | ||
ipfs id --api /dns/YOUR_DOMAIN/tcp/443/https --api-auth basic:hello:world123 | ||
2color marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
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. | ||
2color marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Security Considerations | ||
|
||
- Change the `AuthSecret` to a strong username and password combination | ||
- Consider restricting the `AllowedPaths` further based on your needs | ||
- Keep your Caddy and Kubo installations updated | ||
- Regularly monitor the logs for any suspicious activity | ||
|
||
## Troubleshooting | ||
|
||
If you encounter issues: | ||
|
||
1. Check Caddy logs | ||
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). | ||
3. Ensure port 443 is open and not blocked by your firewall | ||
4. Check that Kubo is running and accessible on localhost:5001 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.