eik.mdwn (13973B)
1 Notes regarding `eik` 2 3 ssh config 4 ---------- 5 6 Host eik.permacomputing.net 7 Hostname 193.170.194.218 8 User <username> 9 Port 22 10 IdentityFile ~/.ssh/<ssh-private-key> 11 12 disk volumes 13 ------------ 14 15 `eik` uses LVM, and we recently added 5G to `/var` before realising that that was nearly all of the disk space we'd been allocated. Growing the volume was as simple as: 16 17 sudo lvextend --size +5G --resizefs /dev/mapper/permacomputing--vg-var 18 sudo lvextend --extents +100%FREE --resizefs /dev/mapper/permacomputing--vg-root 19 20 The first attempt to grow `/` had a typo (missing the `+`), so we reached out and got more disk added (possibly `/dev/vda2`: `vda1` is `/boot` and `vda5` is the LVM pool). We will review our consumption needs after we complete more work, but we may want to return the space added on 6 May. 21 22 23 upgrading debian 24 ---------------- 25 26 We recently added space, which should make upgrades easier. Here are some tricks we developed when space on `/` was tight. 27 28 29 * Make sure all old linux kernels are removed. You can upgrade/reboot and then check with `uname -a`/`uname -rms` to see what you're running. Then use `dpkg --list | grep -E 'linux-image|linux-headers'` to identify the old ones and directly `apt remove ...`. 30 * Pay attention to what the `apt full-upgrade` disk space info is telling you. Check what you've got on the `/` partition with `df -h`. If you don't have enough, it won't work. 31 * Delete a bunch of packages that you don't need if they're on the system. 32 * You can usually get away with moving `/usr/include` / `/usr/share` into the `/home` partition and then symlinking them back. This is of course risky business and you should only do it as a last ditch effort. 33 34 http certs 35 ---------- 36 37 We leave the visitor the option to `http` or `https`. This is done in `nginx` with only the following instructions in each `site-enabled` config: 38 39 listen 80; 40 listen 443 ssl; 41 42 However when authentication is required we force `https` like this: 43 44 location /supercoolauth.cgi { 45 return 301 https://$http_host$request_uri; 46 } 47 48 We use `acme.sh` for handling certs, using [the GANDI DNS API subsystem](https://github.com/acmesh-official/acme.sh/wiki/dnsapi#dns_gandi_livedns) to issue and renew our wildcard cert. 49 50 This relies on an environment variable in `/root/.acme.sh/acme.sh.env` called `GANDI_LIVEDNS_TOKEN`. This token expires every year, and must be renewed in the first week of May. 51 52 53 cerca 54 ----- 55 56 We maintain a single patch on `bbs-patches` to disable registration (See below for how we manage this with our own Git hosting). 57 58 Our system configuration documentation has been upstreamed to [`docs/hosting.md`](https://github.com/cblgh/cerca/blob/main/docs/hosting.md) 🎉 59 60 You can edit the CSS, about pages, registration instructions etc. all in `/var/www/bitrot.permacomputing.net/content/`. There are some other configurations lying around there which might be useful also. When making changes, you need to restart Cerca: `systemctl restart bbs-cerca`. 61 62 If you run into issues, have ideas for improvements or otherwise wanna get in touch with the main developer, cblgh, they're very open to discussions on the issue tracker [here](https://github.com/cblgh/cerca/issues). 63 64 ### Hacking cerca 65 66 You can push/pull changes from our private temporary branch. You need to add the `eik` repository to your local checkout. You can do this with something like so: `git remote add pmc ssh://foo@eik:/var/www/git.permacomputing.net/repos/cerca.git` (see "git hosting" below for more details). Then you can `git fetch --all pmc` and you should have a copy of the `bbs-patches` branch. Push all your hacks there so we can get lost in hacks together 🤓 67 68 ### Update cerca 69 70 Due to resource constraints on `eik`, we are building `cerca` on our own machines and then uploading & replacing the binary to update a new version. 71 72 You can build a static binary on your own machine with: 73 74 go build -v \ 75 -ldflags="-s -w -linkmode 'external' -extldflags '-static'" \ 76 ./cmd/cerca 77 78 ### warawara 🤖 79 80 When there is activity on the forum we get XMPP notifications from [warawara](https://git.permacomputing.net/warawara). The binary is located at `/usr/local/bin/warawara` and if it needs to be restarted, you can `systemctl restart warawara`. 81 82 ### compost 👩🌾 83 84 Our own [image uploader](https://git.vvvvvvaria.org/pmc/image_upload) for bitrot. It's deployed on eik, `systemctl status compost` to learn more. 85 86 motd message 87 ------------ 88 89 See `/etc/update-motd.d/` for the scripts. When a user logs in, these scripts are all run. They must be executable to be run. Feel free to add some nice welcome screens! 90 91 There are also some configuration knobs in `/etc/ssh/sshd_config` which related to showing the last log in and the default `/etc/motd`. These have been turned off for now. 92 93 git hosting 94 ----------- 95 96 Git repositories are located in `/var/www/git.permacomputing.net/repos`. Any user in the `gitusers` group has access to reading and writing these files. 97 98 * to add a new eik user to the group (replacing `USERNAME` as needed): 99 100 ```usermod --append --groups gitusers USERNAME``` 101 102 * to create a new repository on eik (replacing `USERNAME` and `REPONAME`): 103 104 ``` 105 ssh USERNAME@eik 106 cd /var/www/git.permacomputing.net 107 ./new_repos.sh REPONAME "one line about the repos" 108 ``` 109 110 * to clone (locally) your new repo: 111 112 ``` 113 git config --global init.defaultBranch main # if not done already 114 git clone USERNAME@eik:/var/www/git.permacomputing.net/repos/REPONAME.git 115 ``` 116 117 * to add a repository as a git remote (for `git push`, replacing `USERNAME` and `REPONAME`): 118 119 ``` 120 git remote add pmc \ 121 ssh://USERNAME@eik:/var/www/git.permacomputing.net/repos/REPONAME.git 122 ``` 123 124 stagit 125 ------ 126 127 [stagit](https://codemadness.org/stagit.html) is used to produce the staticly generated web interface that is [git.permacomputing.net](https://git.permacomputing.net). 128 129 If you follow the instructions above ("git hosting") to add a new git repository, then all the needed hooks and git repo modifications have been installed. Next time you push, you should see your changes reflected on [git.permacomputing.net](https://git.permacomputing.net) and [https://git.permacomputing.net/REPO](git.permacomputing.net/REPO). 130 131 home pages 132 ---------- 133 134 You can share web stuff via a local `public_html` directory. 135 136 cd 137 mkdir public_html 138 echo "hello, world! > public_html/index.html 139 140 Then visit `eik.permacomputing.net/~YOURUSERNAME`. 141 142 The `nginx` incantation for this is configured in `/etc/nginx/sites-enabled/eik.permacomputing.net`. 143 144 mosh 145 ---- 146 147 [mosh](https://mosh.org) is installed on the server to make doing terminal ops more convenient on intermittent connections, long running commands and so on. See the website for more information. You simply replace `ssh` with `mosh` when you want to connect to the server. You need to install the `mosh` client on your machine also (e.g. `apt install mosh`). 148 149 firewall 150 -------- 151 152 [ufw](https://help.ubuntu.com/community/UFW) is installed as a "frontend" for `iptables`. Defaults are set to allow outgoing and block incoming traffic. Only specific ports are open and allow incoming. 153 154 IDS 155 --- 156 157 We use `fail2ban` to dynamically firewall off IPs that appear to be doing suspicious things based on our logs. If your IP gets banned by mistake, ask someone to find your IP in `sudo fail2ban-client banned` output, figure out which jail you're in, and then do 158 159 fail2ban-client set $JAIL_NAME unbanip $IP_ADDRESS 160 161 backups 162 ------- 163 164 We are using [restic](https://restic.readthedocs.io/) for backups. 165 166 On eik, we have created a specific user, following [these docs](https://restic.readthedocs.io/en/stable/080_examples.html#backing-up-your-system-without-running-restic-as-root). 167 168 We're using a temporary homebrew server for remote backups because eik does not have enough storage capacity. You can find the connection details in `/home/restic/.ssh/config`. On the remote hbsc side, we've configured the `authorized_keys` to restrict access to only run the sftp command. 169 170 # .ssh/authorized_keys 171 restrict,command="/lib/sftp-server" ssh-ed25519 ... 172 173 The restic user on eik has a nightly cron configured to run a full system backup. See `/home/restic/backup.sh` for more. Per-backup logs and other configuration are also provided in `/home/restic`. 174 175 smtp relay 176 ---------- 177 178 We are following the [LURK priort art](https://things.bleu255.com/runyourown/Postfix_Relay) with a postfix relay configured as a "satellite system". All services on eik can make use of this for "noreply" functionality. Please first check in the Toolshed group if that's OK. LURK want to keep a clean sheet with their mail server address and avoid problems with spam and block listing. 179 180 Some handy commands for introspecting the mail system. 181 182 mail # read mails on local account 183 tail -f /var/log/mail.log # postfix logs 184 185 You need to `systemctl restart postfix` when you update the `main.cf`. 186 187 You cand send a test mail with the following: 188 189 echo "Subject: test from eik" | /usr/sbin/sendmail -v some@where.nice 190 191 creating system users 192 --------------------- 193 194 We seem to be doing this. 195 196 useradd --system --shell /sbin/nologin <username> 197 198 And then using these in `systemd` files to run services with users with limited permissions. This is at least the case for `cerca` and `rauthy`. Documenting this in case we choose to do it differently in the future. 199 200 rauthy 201 ------ 202 203 ### build 204 205 Install [rustup](https://rustup.rs), grab `musl-tools` and a copy of the Rauthy source code. You'll need to follow [the standard contrib docs](https://github.com/sebadob/rauthy/blob/main/CONTRIBUTING.md) to get a working development environment up and running. 206 207 You can build a binary for eik with the following. Make sure to check out a tag and not build from main. Otherwise, we can potentially destroy our database schema if that binary makes it to eik and is run. 208 209 sudo apt-get install musl-tools 210 rustup target add x86_64-unknown-linux-musl 211 cargo build --target=x86_64-unknown-linux-musl 212 213 You can transfer to eik like so. 214 215 scp target/x86_64-unknown-linux-musl/release/rauthy eik.permacomputing.net: 216 217 Don't forget to `mv` it to `/usr/local/bin` and `chown rauthy:rauthy` on the binary. You should also make sure `rauthy` is stopped on eik before replacing the binary. 218 219 ### configure 220 221 The `rauthy` binary lives in `/usr/local/bin/rauthy` and it's configuration and data is to be found in `/home/rauthy/config.toml`. Here are the [configuration reference docs](https://sebadob.github.io/rauthy/config/config.html). 222 223 You can `journalctl -fu rauthy` to follow along with the logs and the usual `systemctl restart rauthy` will restart Rauthy. 224 225 Rauthy runs under the `rauthy` user, please prefix your commands with `sudo -su rauthy` if running commands directly on the configuration or data to avoid borking permissions. 226 227 ### admin 228 229 See the `/home/rauthy/config.toml` for the fallback admin email. Ask in Toolshed for the password. You can also create an account and be upgraded to administrator by applying the `rauthy_admin` role on user creation. 230 231 ### arbitrary single sign-on 232 233 It is possible to configure `nginx` to use the [`forward auth`](https://sebadob.github.io/rauthy/work/forward_auth.html#advanced-forward-auth) feature of `rauthy`. This means, you can put anything you serve on `nginx` behind a single sign-on. 234 235 This avoids us having to hand out a HTTP basic auth username/password on top of the username/password that people configured for the specific application themselves. If this doesn't make any sense already then you know we had to change it. We have had several reports that this is super confusing and just stopping people logging in to our digital tools. 236 237 The configuration is fairly hairy but once you get it, you get it. And yes, if `rauthy` is down, there is no access. It's as solid as HTTP basic auth. The `rauthy` [docs](https://sebadob.github.io/rauthy/work/forward_auth.html#advanced-forward-auth) cover it but the TLDR; if you're moving fast: 238 239 * Create a confidential client (we don't use the password) on Rauthy with the correct allowed origin (the URL you want to protect) and redirect URI (the URL you want to protect + /callback) 240 * Disable PKCE in the `rauthy` web client UI 241 * Configure your Nginx configuration roughly like below. Refer to [the rauthy docs](https://sebadob.github.io/rauthy/work/forward_auth.html#advanced-forward-auth) for full context and tips. Please note, `<YOUR-CLIENT-ID>` must be replaced in the minimal configuration example below. 242 243 Here's an example `nginx` configuration. 244 245 upstream rauthy { 246 server 127.0.0.1:8080 fail_timeout=5; 247 } 248 249 location /auth { 250 internal; 251 252 proxy_set_header X-Original-URI $request_uri; 253 proxy_set_header X-Forwarded-Method $request_method; 254 proxy_set_header X-Forwarded-Proto $scheme; 255 proxy_set_header X-Forwarded-Host $http_host; 256 proxy_set_header X-Forwarded-URI $request_uri; 257 258 proxy_set_header Content-Length ""; 259 proxy_set_header Connection ""; 260 proxy_pass_request_body off; 261 262 proxy_pass http://rauthy/auth/v1/clients/<YOUR-CLIENT-ID>/forward_auth; 263 } 264 265 location = /callback { 266 proxy_set_header X-Forwarded-Proto $scheme; 267 proxy_set_header X-Forwarded-Host $http_host; 268 proxy_pass http://rauthy/auth/v1/clients/<YOUR-CLIENT-ID>/forward_auth/callback?$args; 269 } 270 271 location / { 272 auth_request /auth; 273 auth_request_set $redirection_url $upstream_http_location; 274 error_page 401 =302 $redirection_url; 275 276 # NOTE(d1): finally, serve your webshit 277 try_files $uri $uri/ =404; 278 } 279 280 ### nss 281 282 See `/etc/rauthy/rauthy-pam-nss.toml` for the configuration. You can `journalctl -fu rauthy-nss` to see what's going down. The simplest test is to run `getent hosts`. The hosts are configured under `Pam > Hosts` in the `rauthy` web UI.