eik.mdwn (16819B)
1 Notes regarding `eik` 2 3 See also: 4 5 * [[eik_containers]] 6 7 ssh config 8 ---------- 9 10 Host eik.permacomputing.net 11 Hostname 193.170.194.218 12 User <username> 13 Port 22 14 IdentityFile ~/.ssh/<ssh-private-key> 15 16 ikiwiki 17 ------- 18 19 The configuration lives in `/etc/ikiwiki/permacomputing.setup`. If you make changes to this configuration, you need to rebuild the wiki with the following command. 20 21 cd /etc/ikiwiki 22 sudo -su ikiwiki ikiwiki --setup permacomputing.setup 23 24 The htpasswd lives in the same directory. 25 26 The database and other important state files like in the `srcdir`: `/var/www/permacomputing.net-src/.ikiwiki/`. 27 28 ### single sign-on with rauthy 29 30 We leverage the ikiwiki [httpauth](https://ikiwiki.info/plugins/httpauth/) plugin and the [`preferred_username`](https://github.com/sebadob/rauthy/releases/tag/v0.35.2) header functionality of Rauthy. Users are redirected to log into their Rauthy managed account and then via [forward authentication](https://sebadob.github.io/rauthy/work/forward_auth.html) we pass the required headers to `httpauth` and it's done. 31 32 ### admin functions 33 34 * [list of all users](https://permacomputing.net/ikiwiki.cgi?do=userlist) 35 36 ### non-web editing of the wiki 37 38 Everyone in the `gitusers` group has access to push commits to [the ikiwiki git repo](https://git.permacomputing.net/permacomputing/log.html). 39 40 Due to how user permissions are configured on the server, you'll need to exempt the directory from the standard Git permissions check. You need run this command **on the server** where your system account lives and not your local machine. 41 42 git config --global --add safe.directory /var/www/git.permacomputing.net/repos/permacomputing.git 43 44 You can see who's in the `gitusers` list by running: 45 46 getent group gitusers 47 48 This means you can edit the wiki on your local system with the following workflow: 49 50 git clone eik.permacomputing.net:/var/www/git.permacomputing.net/repos/permacomputing.git permawiki 51 cd permawiki 52 ${VISUAL} test.md 53 git add test.md 54 git commit -m "testing remote git wiki updates" 55 git push 56 57 If all goes well, you should then see your changes on the [[test]] page. 58 59 60 disk volumes 61 ------------ 62 63 `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: 64 65 sudo lvextend --size +5G --resizefs /dev/mapper/permacomputing--vg-var 66 sudo lvextend --extents +100%FREE --resizefs /dev/mapper/permacomputing--vg-root 67 68 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. 69 70 71 upgrading debian 72 ---------------- 73 74 We recently added space, which should make upgrades easier. Here are some tricks we developed when space on `/` was tight. 75 76 77 * 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 ...`. 78 * 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. 79 * Delete a bunch of packages that you don't need if they're on the system. 80 * 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. 81 82 83 http certs 84 ---------- 85 86 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: 87 88 listen 80; 89 listen 443 ssl; 90 91 However when authentication is required we force `https` like this: 92 93 location /supercoolauth.cgi { 94 return 301 https://$http_host$request_uri; 95 } 96 97 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. 98 99 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. 100 101 102 cerca 103 ----- 104 105 We maintain a single patch on `bbs-patches` to disable registration (See below for how we manage this with our own Git hosting). 106 107 Our system configuration documentation has been upstreamed to [`docs/hosting.md`](https://github.com/cblgh/cerca/blob/main/docs/hosting.md) 🎉 108 109 You can edit the CSS, about pages, registration instructions etc. all in `/var/www/bbs.permacomputing.net/data/`. There are some other configurations lying around there which might be useful also. When making changes, you need to restart Cerca: `systemctl restart cerca`. 110 111 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). 112 113 ### Hacking cerca 114 115 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 🤓 116 117 ### Update cerca 118 119 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. 120 121 You can build a static binary on your own machine with: 122 123 go build -v \ 124 -ldflags="-s -w -linkmode 'external' -extldflags '-static'" \ 125 ./cmd/cerca 126 127 ### warawara 🤖 128 129 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`. 130 131 132 motd message 133 ------------ 134 135 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! 136 137 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. 138 139 140 git hosting 141 ----------- 142 143 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. 144 145 * to add a new eik user to the group (replacing `USERNAME` as needed): 146 147 ```usermod --append --groups gitusers USERNAME``` 148 149 * to create a new repository on eik (replacing `USERNAME` and `REPONAME`): 150 151 ``` 152 ssh USERNAME@eik 153 cd /var/www/git.permacomputing.net 154 ./new_repos.sh REPONAME "one line about the repos" 155 ``` 156 157 * to clone (locally) your new repo: 158 159 ``` 160 git config --global init.defaultBranch main # if not done already 161 git clone USERNAME@eik:/var/www/git.permacomputing.net/repos/REPONAME.git 162 ``` 163 164 * to add a repository as a git remote (for `git push`, replacing `USERNAME` and `REPONAME`): 165 166 ``` 167 git remote add pmc \ 168 ssh://USERNAME@eik:/var/www/git.permacomputing.net/repos/REPONAME.git 169 ``` 170 171 stagit 172 ------ 173 174 [stagit](https://codemadness.org/stagit.html) is used to produce the staticly generated web interface that is [git.permacomputing.net](https://git.permacomputing.net). 175 176 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). 177 178 home pages 179 ---------- 180 181 You can share web stuff via a local `public_html` directory. 182 183 cd 184 mkdir public_html 185 echo "hello, world! > public_html/index.html 186 187 Then visit `eik.permacomputing.net/~YOURUSERNAME`. 188 189 The `nginx` incantation for this is configured in `/etc/nginx/sites-enabled/eik.permacomputing.net`. 190 191 mosh 192 ---- 193 194 [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`). 195 196 firewall 197 -------- 198 199 [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. 200 201 IDS 202 --- 203 204 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 205 206 fail2ban-client set $JAIL_NAME unbanip $IP_ADDRESS 207 208 backups 209 ------- 210 211 We are using [restic](https://restic.readthedocs.io/) for backups. 212 213 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). 214 215 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. 216 217 # .ssh/authorized_keys 218 restrict,command="/lib/sftp-server" ssh-ed25519 ... 219 220 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`. 221 222 smtp relay 223 ---------- 224 225 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. 226 227 Some handy commands for introspecting the mail system. 228 229 mail # read mails on local account 230 tail -f /var/log/mail.log # postfix logs 231 232 You need to `systemctl restart postfix` when you update the `main.cf`. 233 234 You cand send a test mail with the following: 235 236 echo "Subject: test from eik" | /usr/sbin/sendmail -v some@where.nice 237 238 creating system users 239 --------------------- 240 241 We seem to be doing this. 242 243 useradd --system --shell /sbin/nologin <username> 244 245 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. 246 247 rauthy 248 ------ 249 250 ### build 251 252 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. 253 254 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. 255 256 sudo apt-get install musl-tools 257 rustup target add x86_64-unknown-linux-musl 258 cargo build --target=x86_64-unknown-linux-musl --release 259 260 You can transfer to eik like so. 261 262 scp target/x86_64-unknown-linux-musl/release/rauthy eik.permacomputing.net: 263 264 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. 265 266 ### configure 267 268 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). 269 270 You can `journalctl -fu rauthy` to follow along with the logs and the usual `systemctl restart rauthy` will restart Rauthy. 271 272 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. 273 274 ### admin 275 276 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. 277 278 ### arbitrary single sign-on 279 280 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. 281 282 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. 283 284 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: 285 286 * 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) 287 * Disable PKCE in the `rauthy` web client UI 288 * 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. 289 290 Here's an example `nginx` configuration. 291 292 upstream rauthy { 293 server 127.0.0.1:8080 fail_timeout=5; 294 } 295 296 location /auth { 297 internal; 298 299 proxy_set_header X-Original-URI $request_uri; 300 proxy_set_header X-Forwarded-Method $request_method; 301 proxy_set_header X-Forwarded-Proto $scheme; 302 proxy_set_header X-Forwarded-Host $http_host; 303 proxy_set_header X-Forwarded-URI $request_uri; 304 305 proxy_set_header Content-Length ""; 306 proxy_set_header Connection ""; 307 proxy_pass_request_body off; 308 309 proxy_pass http://rauthy/auth/v1/clients/<YOUR-CLIENT-ID>/forward_auth; 310 } 311 312 location = /callback { 313 proxy_set_header X-Forwarded-Proto $scheme; 314 proxy_set_header X-Forwarded-Host $http_host; 315 proxy_pass http://rauthy/auth/v1/clients/<YOUR-CLIENT-ID>/forward_auth/callback?$args; 316 } 317 318 location / { 319 auth_request /auth; 320 auth_request_set $redirection_url $upstream_http_location; 321 error_page 401 =302 $redirection_url; 322 323 # NOTE(d1): finally, serve your webshit 324 try_files $uri $uri/ =404; 325 } 326 327 ### nss 328 329 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. 330 331 ### pam 332 333 PAM users need to be created on the Rauthy admin side of things, connected to a normal user account via email. See `/etc/pam.d` for all adjusted configurations where the PAM system can ask Rauthy via API for additional login details. You can `tail -f /var/log/auth.log` to see how a log in attempt is responded to. Use the `/usr/sbin/rauthy-authorized-keys <username>` command to retrieve a SSH public key part for a specific user. The `/etc/ssh/sshd_config` is a part of the puzzle, with 2 options: 1) allowing password login with `PasswordAuthentication`. The passwords are ephemerally generated on the Rauthy user self-service UI 2) allowing `/usr/sbin/rauthy-authorized-keys` lookup with `AuthorizedKeysCommand`. We configure these options on a per-user basis. 334 335 ### restricting users based on group membership 336 337 We make use of the the Rauthy feature which restricts access to specific 338 clients based on group membership. This allows us to control where users with 339 accounts on the SSO can log in and where they can't.