cockpit-tailscale/README.md

175 lines
4.1 KiB
Markdown
Raw Permalink Normal View History

2023-06-16 22:54:41 -06:00
Cockpit application to manage Tailscale
2023-06-17 00:17:53 -06:00
=======================================
2023-06-23 03:30:10 -06:00
!["Prompt"](https://raw.githubusercontent.com/gbraad/assets/gh-pages/icons/prompt-icon-64.png)
2023-06-23 03:30:10 -06:00
A Cockpit application to manage Tailscale
![Screenshot](./docs/screenshot.png)
2023-06-23 03:30:10 -06:00
Development
-----------
2023-06-23 21:49:45 -06:00
This repository includes deployment scripts for the Cocpit Tailscale development environment.
2023-06-23 03:30:10 -06:00
The easiest to get started is by using the following cloud development environments:
* Open in [Gitpod workspace](https://gitpod.io/#https://github.com/spotsnel/cockpit-tailscale)
* Open in [CodeSandbox](https://codesandbox.io/p/github/spotsnel/cockpit-tailscale)
2023-06-23 22:22:32 -06:00
or you can either use a local `devsys`/`almsys`, as published here:
2023-06-23 03:30:10 -06:00
* https://github.com/gbraad-devenv/fedora
* https://github.com/gbraad-devenv/almalinux
2023-06-23 21:49:45 -06:00
2023-06-23 03:30:10 -06:00
### Preparation
Install the following packages to develop and build:
2023-06-23 21:49:45 -06:00
2023-06-23 22:22:32 -06:00
```bash
2023-06-23 03:30:10 -06:00
$ sudo dnf install -y make npm
```
and to make the RPM you need:
2023-06-23 21:49:45 -06:00
2023-06-23 22:22:32 -06:00
```bash
2023-06-23 21:49:45 -06:00
$ sudo dnf install -y rpm-build gettext libappstream-glib
```
#### Cockpit user
2023-06-23 22:22:32 -06:00
If you want to run Cockpit, you need a user with a password:
2023-06-23 21:49:45 -06:00
2023-06-23 22:22:32 -06:00
```bash
2023-06-23 21:49:45 -06:00
$ sudo dnf install -y passwd
$ sudo passwd gbraad
2023-06-23 03:30:10 -06:00
```
2023-06-23 21:49:45 -06:00
After which you can use this user to log in to Cockpit.
2023-06-23 03:30:10 -06:00
### Build
To perform a development build:
2023-06-23 22:22:32 -06:00
```bash
2023-06-23 21:49:45 -06:00
$ npm run dev
2023-06-23 03:30:10 -06:00
````
To perform a production build:
2023-06-23 22:22:32 -06:00
```bash
2023-06-23 21:49:45 -06:00
$ npm run build
```
For the RPM package:
2023-06-23 22:22:32 -06:00
```bash
2023-06-23 21:49:45 -06:00
$ npm run rpm
2023-06-23 03:30:10 -06:00
```
2023-06-23 21:49:45 -06:00
### Cockpit
After the build, copy contents to `/usr/share/cockpit/tailscale`, `/usr/share/local/cockpit/tailscale` or `~/.local/share/cockpit/tailscale`.
#### Link development
2023-06-23 03:30:10 -06:00
2023-06-23 22:22:32 -06:00
For convenience, you can also create a symlink to `~/.local/share/cockpit/tailscale` to `$PWD/dist`. However, you will need to log out and log in because Cockpit caches the page and assets.
2023-06-23 03:30:10 -06:00
2023-06-23 21:49:45 -06:00
To create a link:
2023-06-23 22:22:32 -06:00
```bash
2023-06-23 21:49:45 -06:00
$ npm run link
```
And to remove:
2023-06-23 22:22:32 -06:00
```bash
2023-06-23 21:49:45 -06:00
$ npm run unlink
```
2023-06-23 22:28:54 -06:00
Note: this only works when the current user also logs in. Otherwise, use the tasks
`linkusr` and `unlinkusr` which uses `sudo` to create the link in `/usr/local/share/cockpit`.
2023-06-23 21:49:45 -06:00
#### Run Cockpit
2023-06-23 22:22:32 -06:00
2023-06-23 21:49:45 -06:00
You can run Cockpit in a container or remote development environment with the following command:
2023-06-23 22:22:32 -06:00
```bash
2023-06-23 21:49:45 -06:00
$ npm run cockpit
```
You will need to use an account with a password to log in.
2023-06-23 03:30:10 -06:00
2023-06-23 22:22:32 -06:00
#### Origins
If the login fails and you see `bad Origin` errors, you need to modify the `/etc/cockpit/cockpit.conf` file and add something like:
2023-06-23 03:30:10 -06:00
2023-06-23 22:22:32 -06:00
```ini
[WebService]
Origins=https://jqgnyj-9090.csb.app
2023-06-23 03:30:10 -06:00
```
2023-06-23 22:22:32 -06:00
The example shows CodeSandbox. For Gitpod this might look like this:
```ini
[WebService]
Origins=https://9090-spotsnel-cockpittailsca-57e5sbbb0zb.ws-us100.gitpod.io
```
### Tailscale systemd image
You can run this as part of [spotsnel/tailscale-systemd](https://github.com/spotsnel/tailscale-systemd) container image to deploy this inside a Podman machine or similar:
```bash
2023-06-23 03:30:10 -06:00
$ tailscale ssh podmandesktop / podman exec -it tailscale-system bash
# dnf install -y cockpit passwd
# systemctl enable --now cockpit.socket
# curl -L https://github.com/spotsnel/cockpit-tailscale/releases/download/v0.0.1/cockpit-tailscale-v0.0.1.tar.gz -o dist.tar.gz
# tar zxvf dist.tar.gz
# mkdir /usr/local/share/cockpit
# mv dist /usr/local/share/cockpit/tailscale
# passwd root
# tailscale up --ssh
```
2023-06-23 22:22:32 -06:00
2023-06-23 03:30:10 -06:00
Now you can access the remote cockpit from another host by 'add new host'.
Note: remote hosts get authenticated over SSH. If you have conflicts, like on WSL, you can serve on `localhost` instead.
`/etc/systemd/system/cockpit.socket.d/listen.conf`
2023-06-23 22:22:32 -06:00
```ini
2023-06-23 03:30:10 -06:00
[Socket]
ListenStream=
ListenStream=127.0.0.1:9090
FreeBind=yes
```
2023-06-23 22:22:32 -06:00
Note: the blank `ListenStream` is intentional as it resets the parameter.
Now set up the forward from the Tailscale client to open port `9090`:
```bash
2023-06-23 03:30:10 -06:00
# tailscale serve tcp:9090 tcp://localhost:9090
# systemctl daemon-reload
# systemctl restart cockpit.socket
```
2023-06-23 22:22:32 -06:00
Now you can navigate to the Tailscale IP:
```
# tailscale ip -4
100.113.113.114
```
Open https://100.113.113.114:9090.
Authors
-------
| [!["Gerard Braad"](http://gravatar.com/avatar/e466994eea3c2a1672564e45aca844d0.png?s=60)](http://gbraad.nl "Gerard Braad <me@gbraad.nl>") |
|---|
| [@gbraad](https://gbraad.nl/social) |