zrok/docs/getting-started.mdx

364 lines
16 KiB
Plaintext
Raw Normal View History

2023-01-30 20:19:39 +01:00
---
title: Getting Started with zrok
sidebar_label: Getting Started
sidebar_position: 10
2023-01-30 20:19:39 +01:00
---
import { AssetsProvider } from '@site/src/components/assets-context';
import DownloadCard from '@site/src/components/download-card';
import styles from '@site/src/css/download-card.module.css';
2023-02-03 02:34:57 +01:00
## What's a zrok?
2023-02-03 02:34:57 +01:00
2023-11-30 15:05:10 +01:00
`zrok` (*/ziːɹɒk/ ZEE-rock*) is a secure, open-source, self-hostable sharing platform that simplifies shielding and sharing network services or files. There's a hardened zrok-as-a-service offering available at [zrok.io](https://zrok.io) with a generous free tier.
2023-05-30 21:53:17 +02:00
## Open Source
2023-05-30 21:53:17 +02:00
`zrok` is licensed under Apache 2.0.
2023-02-03 02:34:57 +01:00
Check [the roadmap](https://github.com/orgs/openziti/projects/16) if you're thinking about the future. We would love to hear your ideas for `zrok`!
2023-02-03 02:34:57 +01:00
2023-11-27 21:21:39 +01:00
The best ways to engage are [Discourse](https://openziti.discourse.group/) for questions and [GitHub Issues](https://github.com/openziti/zrok/issues) for documenting problems.
[Read more about zrok open source](/concepts/opensource.md).
2023-02-03 01:41:08 +01:00
### Ziti native
2023-02-03 01:41:08 +01:00
`zrok` is a _Ziti Native Application_, built on the [OpenZiti](https://openziti.io) platform, and supported by the OpenZiti community and NetFoundry team.
2023-01-19 17:22:21 +01:00
## What's it for?
2023-11-27 21:21:39 +01:00
Use `zrok` to share a running service, like a web server or a network socket, or to share a directory of static files.
If [sharing publicly](./concepts/sharing-public.md), you can reserve a subdomain, enable authentication options, or both. Public shares proxy HTTPS to your service or files.
If [sharing privately](./concepts/sharing-private.md), only users with the share token can access your share. In addition to what you can share publicly, private shares can include TCP and UDP services.
## Installing the zrok Command
<AssetsProvider>
<div className={styles.downloadContainer}>
<DownloadCard
osName="Windows"
osLogo="/img/logo-windows.svg"
infoText="Binary executable"
guideLink="/docs/guides/install/windows"
/>
<DownloadCard
osName="macOS"
osLogo="/img/logo-apple.svg"
infoText="Binary executable"
guideLink="/docs/guides/install/macos"
/>
<DownloadCard
osName="Linux"
osLogo="/img/logo-linux.svg"
infoText="DEB, RPM packages"
guideLink="/docs/guides/install/linux"
/>
</div>
</AssetsProvider>
## Generating an Invitation
2023-01-30 20:43:04 +01:00
:::note
2023-11-27 21:21:39 +01:00
If not using `zrok.io` (zrok-as-a-service), you must configure the `zrok` command to use your instance. See the [instance configuration guide](/guides/self-hosting/instance-configuration.mdx) in the self-hosting section for details.
2023-01-30 20:43:04 +01:00
:::
2023-11-27 21:21:39 +01:00
Invite yourself to `zrok` by running the `zrok invite` command:
```text
zrok invite
```
```buttonless title="Output"
enter and confirm your email address...
> user@domain.com
> user@domain.com
[ Submit ]
invitation sent to 'user@domain.com'!
```
2023-01-18 18:56:35 +01:00
The `zrok invite` command presents a small form that allows you to enter (and then confirm) your email address. Tabbing to the `[ Submit ]` button will send the request to your configured `zrok` service.
Next, check the email where you sent the invite. You should receive a message asking you to click a link to create your `zrok` account. When you click that link, you will be brought to a web page that will allow you to set a password for your new account:
![Enter a Password](images/zrok_verify.png)
2023-11-27 21:21:39 +01:00
Enter a password and its confirmation, and click the `Register Account` button. You'll see the following:
![Successful Registration](images/zrok_registration_success.png)
For now, we'll ignore the "enable your shell for zrok" section. Just click the `zrok web portal` link:
![Web Login](images/zrok_web_login.png)
2023-01-18 18:56:35 +01:00
After clicking the `Log In` button, you'll be brought into the `zrok` _web console_:
![Web Console; Empty](images/zrok_web_console_empty.png)
Congratulations! Your `zrok` account is ready to go!
## Enabling Your zrok Environment
2023-01-19 17:22:21 +01:00
When your `zrok` account was created, the service generated a _secret token_ that identifies and authenticates in a single step. Protect your secret token as if it were a password, or an important account number; it's a _secret_, protect it.
When we left off you had downloaded, extracted, and configured your `zrok` environment. In order to use that environment with your account, you'll need to `enable` it. Enabling an environment generates a secure identity and the necessary underlying security policies with the OpenZiti network hosting the `zrok` service.
2023-01-19 17:22:21 +01:00
From the web console, click on your email address in the upper right corner of the header. That drop down menu contains an `Enable Your Environment` link. Click that link and a modal dialog will be shown like this:
![Enable Modal Dialog](images/zrok_enable_modal.png)
This dialog box shows you the `zrok enable` command that you can use to enable any shell to work with your `zrok` account with a single command.
Let's copy that command and paste it into your shell:
```buttonless title="Example"
2023-01-19 17:22:21 +01:00
$ zrok enable klFEoIi0QAg7
⣻ contacting the zrok service...
```
2023-10-12 05:48:15 +02:00
After a few seconds, the message will change and indicate that the enable operation succeeded:
```buttonless title="Example"
2023-01-19 17:22:21 +01:00
$ zrok enable klFEoIi0QAg7
⣻ the zrok environment was successfully enabled...
```
Now, if we run a `zrok status` command, you will see the details of your environment:
```txt
zrok status
```
```buttonless title="Output"
Config:
2023-06-13 21:22:23 +02:00
CONFIG VALUE SOURCE
apiEndpoint https://api.staging.zrok.io env
Environment:
2023-06-13 21:22:23 +02:00
PROPERTY VALUE
Secret Token <<SET>>
Ziti Identity <<SET>>
```
Excellent... our environment is now fully enabled.
2023-01-18 18:56:35 +01:00
If we return to the _web console_, we'll now see the new environment reflected in the explorer view:
![New Environment in Web UI](images/zrok_web_ui_new_environment.png)
2023-01-18 18:56:35 +01:00
In my case, the environment is named `michael@ziti-lx`, which is the username of my shell and the hostname of the system the shell is running on.
2023-01-30 20:43:04 +01:00
:::note
Should you want to use a non-default name for your environment, you can pass the `-d` option to the `zrok enable` command. See `zrok enable --help` for details.
:::
2023-01-18 18:56:35 +01:00
If you click on the environment node in the explorer in the _web console_, the details panel shown at the bottom of the page will change:
![Empty Environment](images/zrok_web_ui_empty_shares.png)
2023-01-19 17:22:21 +01:00
The explorer supports clicking, dragging, mouse wheel zooming, and selecting the nodes in the graph for more information (and available actions) for the selected node. If you ever get lost in the explorer, click the ![Zoom to Fit](images/zrok_zoom_to_fit.png) _zoom to fit_ icon in the lower right corner of the explorer.
2023-01-19 17:22:21 +01:00
If we click on the `Detail` tab for our environment, we'll see something like:
![Environment Detail](images/zrok_web_ui_empty_environment_detail.png)
2023-02-01 21:45:58 +01:00
:::note
With your `zrok` account you can `zrok enable` multiple environments. This will allow you to run `zrok share` in one environment, and `zrok access` in other environments.
:::
2023-01-19 17:22:21 +01:00
Your environment is fully ready to go. Now we can move on to the fun stuff...
## Sharing
2023-01-17 21:54:37 +01:00
`zrok` is designed to make sharing resources as effortless as possible, while providing a high degree of security and control.
2023-01-17 21:54:37 +01:00
### Ephemeral by Default
Shared resources are _ephemeral_ by default; as soon as you terminate the `zrok share` command, the entire share is removed and is no longer available to any users. Identifiers for shared resources are randomly allocated when the share is created.
### Public Shares and Frontends
2023-11-27 21:21:39 +01:00
Resources that are shared _publicly_ are exposed to any users on the internet who have access to the `zrok` instance's "frontend".
2023-01-17 21:54:37 +01:00
A frontend is an HTTPS listener exposed to the internet, that lets any user with your ephemeral share token access your publicly shared resources.
2023-11-27 21:21:39 +01:00
For example, I might create a public share using the `zrok share public` command, which results in my `zrok` instance exposing a URL like `https://2ptgbr8tlfvk.share.zrok.io` to access my resources.
2023-01-19 17:22:21 +01:00
2023-11-27 21:21:39 +01:00
In this case, my share was given the "share token" of `2ptgbr8tlfvk`. That URL can be given to any user, allowing them to immediately access the shared resources directly from my local environment, all without exposing any access to my private, secure environment. The physical network location of my environment is not exposed to anonymous consumers of my resources.
2023-01-19 17:22:21 +01:00
2023-02-01 19:47:01 +01:00
:::note
Here is the `--help` output from `zrok share public`:
```text
zrok share public
2023-02-01 19:47:01 +01:00
```
```buttonless title="Output"
2023-02-01 19:47:01 +01:00
Error: accepts 1 arg(s), received 0
Usage:
zrok share public <target> [flags]
Flags:
--backend-mode string The backend mode {proxy, web, caddy, drive} (default "proxy")
2023-02-01 19:47:01 +01:00
--basic-auth stringArray Basic authentication users (<username:password>,...)
--frontends stringArray Selected frontends to use for the share (default [public])
--headless Disable TUI and run headless
-h, --help help for public
--insecure Enable insecure TLS certificate validation for <target>
Global Flags:
-p, --panic Panic instead of showing pretty errors
-v, --verbose Enable verbose logging
[ERROR]: an error occurred (accepts 1 arg(s), received 0)
```
`<target>` defines the path to the local resource that you intend to share. The form of `<target>` depends on the `--backend-mode` that you're using.
In the case of `--backend-mode proxy`, `<target>` should be a URL to an HTTP endpoint.
In the case of `--backend-mode web`, `<target>` is the path to a file on disk that serves as the "root" of the file tree to be shared.
:::
2023-01-19 17:22:21 +01:00
If we return to the web console, we see our share in the explorer:
![Web Console Share](images/zrok_web_console_explorer_share.png)
If we click on our new share in the explorer, we can see the share details:
![Share Details](images/zrok_web_console_share_detail.png)
2023-01-17 21:54:37 +01:00
2023-01-19 17:22:21 +01:00
If we click on the _frontend endpoint_ a new browser tab opens and we see the content of our share:
![Share Frontend](images/zrok_web_console_share_frontend.png)
If we click on the environment in the explorer, we're shown all of the shares for that environment (including our new share), along with a spark line that shows the activity:
![Environment Spark Line](images/zrok_web_console_environment_spark.png)
2023-01-17 21:54:37 +01:00
And as soon as I terminate the `zrok share` client, the resources are removed from the `zrok` environment.
2023-01-30 21:25:32 +01:00
If we try to reload the frontend endpoint in our web browser, we'll see:
2023-01-19 17:22:21 +01:00
![Not Found](images/zrok_not_found.png)
2023-01-17 21:54:37 +01:00
### Private Shares
`zrok` also provides a powerful _private_ sharing model. If I execute the following command:
```buttonless title="Example"
2023-01-19 17:22:21 +01:00
$ zrok share private http://localhost:8080
2023-01-17 21:54:37 +01:00
```
The `zrok` service will respond with the following:
2023-01-19 17:22:21 +01:00
```buttonless title="Output"
2023-01-19 17:22:21 +01:00
access your share with: zrok access private wvszln4dyz9q
2023-01-17 21:54:37 +01:00
```
Rather than allowing access to your service through a public frontend, a _private_ share is only exposed to the underlying OpenZiti network, and can only be accessed using the `zrok access` command.
2023-01-17 21:54:37 +01:00
2023-01-19 17:22:21 +01:00
The `zrok access private wvszln4dyz9q` command can be run by any `zrok` user, allowing them to create and bind a local HTTP listener, that allows for private access to your shared resources.
2023-01-17 21:54:37 +01:00
### Proxy Backend Mode
2023-01-19 17:22:21 +01:00
Without specifying a _backend mode_, the `zrok share` command will assume that you're trying to share a `proxy` resource. A `proxy` resource is usually some private HTTP/HTTPS endpoint (like a development server, or a private application) running in your local environment. Usually such an endpoint would have no inbound connectivity except for however it is reachable from your local environment. It might be running on `localhost`, or only listening on a private LAN segment behind a firewall.
2023-01-17 21:54:37 +01:00
For these services a `proxy` share will allow those endpoints to be reached, either _publicly_ or _privately_ through the `zrok` service.
### Web Backend Mode
2023-01-19 17:22:21 +01:00
The `zrok share` command accepts a `--backend-mode` option. Besides `proxy`, the current `v0.3` release (as of this writing) also supports a `web` mode. The `web` mode allows you to specify a local folder on your filesystem, and instantly turns your `zrok` client into a web server, exposing your web content either _publicly_ or _privately_ without having to a configure a web server.
2023-01-18 17:23:08 +01:00
### Reserved Shares
`zrok` shares are _ephemeral_ unless you specifically create a "reserved" share.
A reserved share can be re-used multiple times; it will survive termination of the `zrok share` command, allowing for longer-lasting semi-permanent access to shared resources.
The first step is to create the reserved share:
```txt title="Example"
2023-01-19 17:22:21 +01:00
$ zrok reserve public --backend-mode web v0.3_getting_started
[ 0.275] INFO main.(*reserveCommand).run: your reserved share token is 'mltwsinym1s2'
[ 0.275] INFO main.(*reserveCommand).run: reserved frontend endpoint: https://mltwsinym1s2.share.zrok.io
2023-01-18 17:23:08 +01:00
```
I'm asking the `zrok` service to reserve a share with a `web` backend mode, pointing at my local `docs` folder.
2023-01-19 17:22:21 +01:00
You'll want to remember the share token (`mltwsinym1s2` in this case), and the frontend endpoint URL. If this were a _private_ reserved share, there would not be a frontend URL.
2023-01-18 17:23:08 +01:00
If we do nothing else, and then point a web browser at the frontend endpoint, we get:
2023-01-19 17:22:21 +01:00
![Not Found](images/zrok_reserved_not_found.png)
2023-01-18 17:23:08 +01:00
This is the `404` error message returned by the `zrok` frontend. We're getting this because we haven't yet started up a `zrok share` for the service. Let's do that:
This command:
```txt title="Example"
2023-01-19 17:22:21 +01:00
$ zrok share reserved mltwsinym1s2
2023-01-18 17:23:08 +01:00
```
...results in a new share backend starting up and connecting to the existing reserved share:
![zrok share reserved](images/zrok_share_reserved.png)
And now if we refresh the frontend endpoint URL in the web browser, we'll see an index of the `docs` directory:
2023-11-27 21:21:39 +01:00
![zrok docs share](images/zrok_web_console_share_frontend.png)
2023-01-18 17:23:08 +01:00
2023-01-19 14:54:03 +01:00
With the reserved share, we're free to stop and restart the `zrok share reserved` command as many times as we want, without losing the token for our share.
2023-01-18 17:23:08 +01:00
When we're done with the reserved share, we can _release_ it using this command:
```txt title="Example"
2023-01-19 17:22:21 +01:00
$ zrok release mltwsinym1s2
[ 0.230] INFO main.(*releaseCommand).run: reserved share 'mltwsinym1s2' released
2023-01-18 17:23:08 +01:00
```
2023-01-18 18:45:43 +01:00
## Concepts Review
2023-01-18 17:23:08 +01:00
2023-01-18 18:45:43 +01:00
In summary, `zrok` lets you easily and securely share resources with both general internet users (through _public_ sharing) and also with other `zrok` users (through _private_ sharing).
Here's a quick review of the `zrok` mental model and the vocabulary.
2023-11-27 21:21:39 +01:00
### Instance and Account
2023-01-18 18:45:43 +01:00
2023-11-27 21:21:39 +01:00
You create an _account_ with a `zrok` _instance_. Your account is identified by a username and a password, which you use to log into the _web console_. Your account also has a _secret token_, which you will use to authenticate from the `zrok` command-line to interact with the _instance_.
2023-01-18 18:45:43 +01:00
2023-11-27 21:21:39 +01:00
You create a new _account_ with a `zrok` _instance_ through the `zrok invite` command.
2023-01-18 18:45:43 +01:00
### Environment
Using your _secret token_ you use the `zrok` command-line interface to create an _environment_. An _environment_ corresponds to a single command-line user on a specific _host system_.
You create a new _environment_ by using the `zrok enable` command.
### Shares
Once you've enabled an _environment_, you then create one or more _shares_. Shares have either a _public_ or _private_ _sharing mode_. _Shares_ share a specific type of resource using a _backend mode_. As of this writing `zrok` supports a `proxy` _backend mode_ to share local HTTP resources as a _reverse proxy_. `zrok` also supports a `web` _backend mode_ to share local file and HTML resources by enabling a basic HTTP server.
2023-11-27 21:21:39 +01:00
Every _share_ is identified by a _share token_. _Public shares_ can be accessed through either a _frontend_ instance offered through the `zrok` _instance_, or through the `zrok access` command. _Private shares_ can only be accessed through the `zrok access` command.
2023-01-18 18:45:43 +01:00
You use the `zrok share` command to create and enable _ephemeral shares_.
### Reserved Shares
`zrok` supports creating _shares_ that have a consistent _share token_ that survives restarts of the `zrok share` command. These are considered _non-ephemeral_, and is callled a _reserved share_.
You use the `zrok reserve` command to create _reserved shares_. Reserved shares last until you use the `zrok release` command to delete them.
2023-01-18 17:23:08 +01:00
2023-11-27 21:21:39 +01:00
## Self-Hosting an Instance
2023-01-19 18:06:01 +01:00
2024-05-03 16:33:13 +02:00
Interested in self-hosting your own `zrok` instance? See the [self-hosting guides](/docs/category/self-hosting/)!
2023-01-19 18:06:01 +01:00
2024-05-03 16:33:13 +02:00
## Resources
- Learn about [OpenZiti](https://openziti.io/)