zrok/docs/guides/linux-frontdoor.md

145 lines
4.7 KiB
Markdown
Raw Normal View History

2023-11-16 00:55:21 +01:00
---
title: zrok frontdoor
sidebar_label: frontdoor
2023-11-16 00:55:21 +01:00
sidebar_position: 40
---
## Goal
Proxy a reserved public subdomain to a backend target with a Linux system service.
2023-11-16 00:55:21 +01:00
## How it Works
The `zrok-share` package creates a `zrok-share.service` unit in systemd. The administrator edits the service's configuration file to specify the:
1. zrok environment enable token
1. target URL or files to be shared and backend mode, e.g. `proxy`
1. authentication options, if wanted
When the service starts it will:
2023-11-16 04:10:37 +01:00
1. enable the zrok environment unless `/var/lib/zrok-share/.zrok/environment.json` exists
1. reserve a public subdomain for the service unless `/var/lib/zrok-share/.zrok/reserved.json` exists
1. start sharing the target specified in the configuration file
2023-11-16 00:55:21 +01:00
## Installation
1. Set up `zrok`'s Linux package repository by following [the Linux install guide](/guides/install/linux.mdx#install-zrok-from-the-repository). This will complete the installation in one step if you prefer that convenience.
```bash
curl -sSLf https://get.openziti.io/install.bash \
| sudo bash -s zrok-share
```
1. If you set up the repository by following the guide, then also install the `zrok-share` package. This provides the systemd service.
2023-11-16 00:55:21 +01:00
```bash title="Ubuntu, Debian"
sudo sudo apt install zrok-share
2023-11-16 00:55:21 +01:00
```
```bash title="Fedora, Rocky"
sudo dnf install zrok-share
2023-11-16 00:55:21 +01:00
```
## Enable
2023-11-16 04:10:37 +01:00
Save the enable token from the zrok console in the configuration file.
2023-11-16 00:55:21 +01:00
2023-11-16 04:10:37 +01:00
```bash title="/opt/openziti/etc/zrok/zrok-share.env"
2023-11-16 00:55:21 +01:00
ZROK_ENABLE_TOKEN="14cbfca9772f"
```
## Use Cases
2023-11-16 05:02:37 +01:00
You may change the target for the current backend mode, e.g. `proxy`, by editing the configuration file and restarting the service. The reserved subdomain will remain the same.
2023-11-16 00:55:21 +01:00
2023-11-16 05:02:37 +01:00
You may switch between backend modes or change authentication options by deleting `/var/lib/zrok-share/.zrok/reserved.json` and restarting the service. A new subdomain will be reserved.
2023-11-16 00:55:21 +01:00
### Proxy a Web Server
2023-11-16 04:10:37 +01:00
Proxy a reserved subdomain to an existing web server. The web server could be on a private network or on the same host as zrok.
2023-11-16 00:55:21 +01:00
2023-11-16 04:10:37 +01:00
```bash title="/opt/openziti/etc/zrok/zrok-share.env"
2023-11-16 00:55:21 +01:00
ZROK_TARGET="http://127.0.0.1:3000"
ZROK_BACKEND_MODE="proxy"
```
### Serve Static Files
2023-11-16 05:17:38 +01:00
Run zrok's embedded web server to serve the files in a directory. If there's an `index.html` file in the directory then visitors will see that web page in their browser, otherwise they'll see a generated index of the files. The directory must be readable by 'other', e.g. `chmod -R o+rX /var/www/html`.
2023-11-16 00:55:21 +01:00
```bash title="/opt/openziti/etc/zrok/zrok-share.env"
ZROK_TARGET="/var/www/html"
ZROK_BACKEND_MODE="web"
```
### Caddy Server
2023-11-16 00:55:21 +01:00
Use zrok's built-in Caddy server to serve static files or as a reverse proxy to multiple web servers with various HTTP routes or as a load-balanced set. A sample Caddyfile is available in the path shown.
2023-11-16 00:55:21 +01:00
```bash title="/opt/openziti/etc/zrok/zrok-share.env"
ZROK_TARGET="/opt/openziti/etc/zrok/multiple_upstream.Caddyfile"
ZROK_BACKEND_MODE="caddy"
2023-11-16 00:55:21 +01:00
```
### Network Drive
2023-11-16 00:55:21 +01:00
This uses zrok's `drive` backend mode to serve a directory of static files as a virtual network drive. The directory must be readable by 'other', e.g. `chmod -R o+rX /usr/share/doc`.
2023-11-16 00:55:21 +01:00
```bash title="/opt/openziti/etc/zrok/zrok-share.env"
ZROK_TARGET="/usr/share/doc"
ZROK_BACKEND_MODE="drive"
2023-11-16 00:55:21 +01:00
```
[Learn more about this feature in this blog post](https://blog.openziti.io/zrok-drives-an-early-preview).
2023-11-16 00:55:21 +01:00
## Authentication
2023-11-16 05:17:38 +01:00
You can limit access to certain email addresses with OAuth or require a password.
2023-11-16 00:55:21 +01:00
### OAuth
You can require that visitors authenticate with an email address that matches at least one of the suffixes you specify. Add the following to the configuration file.
```bash title="/opt/openziti/etc/zrok/zrok-share.env"
ZROK_OAUTH_PROVIDER="github" # or google
ZROK_OAUTH_EMAILS="bob@example.com @acme.example.com"
```
### Password
Enable HTTP basic authentication by adding the following to the configuration file.
```bash title="/opt/openziti/etc/zrok/zrok-share.env"
ZROK_BASIC_AUTH="user:passwd"
```
## Start the Service
Start the service, and check the zrok console or the service log for the reserved subdomain.
2023-11-16 05:02:37 +01:00
```bash title="run now and at startup"
2023-11-16 00:55:21 +01:00
sudo systemctl enable --now zrok-share.service
2023-11-16 05:02:37 +01:00
```
2023-11-16 04:10:37 +01:00
2023-11-16 05:02:37 +01:00
```bash title="run now"
2023-11-16 04:10:37 +01:00
sudo systemctl restart zrok-share.service
2023-11-16 00:55:21 +01:00
```
```bash
journalctl -u zrok-share.service
```
2023-11-16 05:02:37 +01:00
## Compatibility
The Linux distribution must have a package manager that understands the `.deb` or `.rpm` format and be running systemd v232 or newer. The service was tested with:
* Ubuntu 20.04, 22.04, 23.04
* Debian 11 12
* Rocky 8, 9
* Fedora 37, 38
2023-11-16 05:02:37 +01:00
## Package Contents
The files included in the `zrok-share` package are sourced [here in GitHub](https://github.com/openziti/zrok/tree/main/nfpm).