Skip to content
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

Gluetun Control Server APIKEY Auth #5

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ A shell script and Docker container for automatically setting qBittorrent's list
| QBT_PASSWORD | `password` | `adminadmin` | qBittorrent password |
| QBT_ADDR | `http://192.168.1.100:8080` | `http://localhost:8080` | HTTP URL for the qBittorrent web UI, with port |
| GTN_ADDR | `http://192.168.1.100:8000` | `http://localhost:8000` | HTTP URL for the gluetun control server, with port |
| GTN_APIKEY | `apikey` | `CHANGEME` | API Key for communication to gluetun control server |


## Gluetun Control Server Authentication
1. Create a new file on your Gluetun host system with the following contents:
```toml
# See https://github.com/qdm12/gluetun-wiki/blob/main/setup/advanced/control-server.md for more
[[roles]]
name = "qbittorrent"
# Define a list of routes with the syntax "Http-Method /path"
routes = ["GET /v1/openvpn/portforwarded"]
# Define an authentication method with its parameters
auth = "apikey"
apikey = "CHANGEME" # can be generated using "docker run --rm qmcgaw/gluetun genkey"
```
3. Bind mount the file you created to `/gluetun/auth/config.toml` in your gluetun docker instance.

## Example

Expand All @@ -29,6 +45,7 @@ The following is an example docker-compose:
- QBT_PASSWORD=password
- QBT_ADDR=http://192.168.1.100:8080
- GTN_ADDR=http://192.168.1.100:8000
- GTN_APIKEY=apikey
```

## Development
Expand All @@ -39,4 +56,4 @@ The following is an example docker-compose:

### Run Container

`docker run --rm -it -e QBT_USERNAME=admin -e QBT_PASSWORD=adminadmin -e QBT_ADDR=http://192.168.1.100:8080 -e GTN_ADDR=http://192.168.1.100:8000 qbittorrent-port-forward-gluetun-server:latest`
`docker run --rm -it -e QBT_USERNAME=admin -e QBT_PASSWORD=adminadmin -e QBT_ADDR=http://192.168.1.100:8080 -e GTN_ADDR=http://192.168.1.100:8000 -e GTN_APIKEY=CHANGEME qbittorrent-port-forward-gluetun-server:latest`
3 changes: 2 additions & 1 deletion main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ qbt_username="${QBT_USERNAME:-admin}"
qbt_password="${QBT_PASSWORD:-adminadmin}"
qbt_addr="${QBT_ADDR:-http://localhost:8080}" # ex. http://10.0.1.48:8080
gtn_addr="${GTN_ADDR:-http://localhost:8000}" # ex. http://10.0.1.48:8000
gtn_apikey="${GTN_APIKEY:-CHANGEME}"

port_number=$(curl --fail --silent --show-error $GTN_ADDR/v1/openvpn/portforwarded | jq '.port')
port_number=$(curl --fail --silent --show-error --header "X-API-Key: $GTN_APIKEY" $gtn_addr/v1/openvpn/portforwarded | jq '.port')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be $gtn_apikey, not $GTN_APIKEY.

if [ ! "$port_number" ] || [ "$port_number" = "0" ]; then
echo "Could not get current forwarded port from gluetun, exiting..."
exit 1
Expand Down