openziti / ziti-doc

Documentation describing the usage of the Ziti platform.
https://openziti.io
Apache License 2.0
34 stars 41 forks source link

Linux tunneler help #52

Closed qrkourier closed 2 years ago

qrkourier commented 3 years ago

Some notes that we could fold-in to https://openziti.github.io/ziti/clients/tunneler.html#linux

ziti-edge-tunnel

# transparent install procedure for ziti-edge-tunnel

# where to install the executable binary
❯ ZITI_EDGE_TUNNEL_BIN_DIR=/usr/local/bin

# where to look at startup for enrolled identity JSON config files
❯ ZITI_EDGE_TUNNEL_ID_DIR=~/.ziti-edge-tunnel

# create the identity directory
❯ mkdir -pvm0700 $ZITI_EDGE_TUNNEL_ID_DIR

# create a systemd service
❯ cat <<ZITI_SERVICE | sudo tee /usr/lib/systemd/system/ziti-edge-tunnel.service                
[Unit]
Description=Ziti Edge Tunnel
After=network.target
ConditionDirectoryNotEmpty=$ZITI_EDGE_TUNNEL_ID_DIR

[Service]
User=root
ExecStart=${ZITI_EDGE_TUNNEL_BIN_DIR}/ziti-edge-tunnel run --verbose 4 --identity-dir $ZITI_EDGE_TUNNEL_ID_DIR
Restart=always
RestartSec=2
LimitNOFILE=65535

[Install]
WantedBy=multi-user.target
ZITI_SERVICE

# load the new systemd config
❯ sudo systemctl daemon-reload

# download some version of ziti-edge-tunnel
❯ curl -sSLf https://raw.githubusercontent.com/openziti/ziti-tunnel-sdk-c/main/docker/fetch-github-releases.sh | ZITI_VERSION=0.17.7 bash -x /dev/stdin ziti-edge-tunnel

# install in a directory that is in the executable search PATH
❯ sudo mv -v ./ziti-edge-tunnel ${ZITI_EDGE_TUNNEL_BIN_DIR}/

# verify the installed version
❯ sudo ziti-edge-tunnel version

# use a downloaded enrollment token to generate an identity
❯ sudo ziti-edge-tunnel enroll --jwt ~/Downloads/linuxTunneler1.jwt --identity ${ZITI_EDGE_TUNNEL_ID_DIR}/linuxTunneler1.json

# start the daemon
❯ sudo systemctl start ziti-edge-tunnel.service

# view the logs
❯ sudo journalctl -lfu ziti-edge-tunnel.service

ziti-tunnel

sabedevops commented 3 years ago

Consider adding some sanity checks to the systemd unit file like ConditionDirectoryNotEmpty

Additionally, should we be steering users to the XDG Base Directory Specification?

qrkourier commented 3 years ago

@sabedevops Good stuff. I added that unit conditional and XDG_DATA_HOME looks like something we should use with the (eventual) install package for this service unit, unless you see a specific way we could apply it in this manual install procedure.

sabedevops commented 3 years ago

For the purposes of this script, this can be done generically like this:

[ ! -z "$XDG_DATA_HOME" ] && ZITI_EDGE_TUNNEL_ID_DIR="$XDG_DATA_HOME/ziti-edge-tunnel" || ZITI_EDGE_TUNNEL_ID="$HOME/.ziti-edge-tunnel"

This may not align with current documentation and user expectations, so it may be worth ignoring at this time.

Also, please be advised the approach in this script is not bulletproof, since things like Kerberized NFS homedirs with root squashing will cause the service to fail due to permissions. Nonetheless, it's a great start @qrkourier

qrkourier commented 2 years ago

@dovholuknf Based on today's conversation about the older and newer Linux tunnelers we should refactor this document to position the preferred tunneler as such, and document the dwindling-few unique capabilities of the non-preferred tunneler ziti-tunnel. You may assign this issue to me. :+1: