permacomputing

Source repository for the main permacomputing wiki site
git clone http://git.permacomputing.net/repos/permacomputing.git # read-only access
Log | Files | Refs

eik.mdwn (15969B)


      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 http certs
     83 ----------
     84 
     85 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:
     86 
     87     listen 80;
     88     listen 443 ssl;
     89 
     90 However when authentication is required we force `https` like this:
     91 
     92     location /supercoolauth.cgi {
     93         return 301 https://$http_host$request_uri;
     94     }
     95 
     96 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.  
     97 
     98 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.  
     99 
    100 
    101 cerca
    102 -----
    103 
    104 We maintain a single patch on `bbs-patches` to disable registration (See below for how we manage this with our own Git hosting).
    105 
    106 Our system configuration documentation has been upstreamed to [`docs/hosting.md`](https://github.com/cblgh/cerca/blob/main/docs/hosting.md) 🎉
    107 
    108 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`.
    109 
    110 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).
    111 
    112 ### Hacking cerca
    113 
    114 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 🤓
    115 
    116 ### Update cerca
    117 
    118 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.
    119 
    120 You can build a static binary on your own machine with:
    121 
    122     go build -v \
    123       -ldflags="-s -w -linkmode 'external' -extldflags '-static'" \
    124       ./cmd/cerca
    125 
    126 ### warawara 🤖
    127 
    128 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`.
    129 
    130 ### compost 👩‍🌾
    131 
    132 Our own [image uploader](https://git.vvvvvvaria.org/pmc/image_upload) for bitrot. It's deployed on eik, `systemctl status compost` to learn more.
    133 
    134 motd message
    135 ------------
    136 
    137 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!
    138 
    139 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.
    140 
    141 git hosting
    142 -----------
    143 
    144 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.
    145 
    146 *  to add a new eik user to the group (replacing `USERNAME` as needed): 
    147 
    148    ```usermod --append --groups gitusers USERNAME```
    149 
    150 *  to create a new repository on eik (replacing `USERNAME` and `REPONAME`): 
    151 
    152    ```
    153    ssh USERNAME@eik
    154    cd /var/www/git.permacomputing.net
    155    ./new_repos.sh REPONAME "one line about the repos"
    156    ```
    157 
    158 *  to clone (locally) your new repo:
    159 
    160    ```
    161    git config --global init.defaultBranch main  # if not done already
    162    git clone USERNAME@eik:/var/www/git.permacomputing.net/repos/REPONAME.git
    163    ```
    164 
    165 *  to add a repository as a git remote (for `git push`, replacing `USERNAME` and `REPONAME`):
    166 
    167    ```
    168    git remote add pmc \
    169      ssh://USERNAME@eik:/var/www/git.permacomputing.net/repos/REPONAME.git
    170    ```
    171 
    172 stagit
    173 ------
    174 
    175 [stagit](https://codemadness.org/stagit.html) is used to produce the staticly generated web interface that is [git.permacomputing.net](https://git.permacomputing.net).
    176 
    177 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).
    178 
    179 home pages
    180 ----------
    181 
    182 You can share web stuff via a local `public_html` directory.
    183 
    184     cd
    185     mkdir public_html
    186     echo "hello, world! > public_html/index.html
    187 
    188 Then visit `eik.permacomputing.net/~YOURUSERNAME`.
    189 
    190 The `nginx` incantation for this is configured in `/etc/nginx/sites-enabled/eik.permacomputing.net`.
    191 
    192 mosh
    193 ----
    194 
    195 [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`).
    196 
    197 firewall
    198 --------
    199 
    200 [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.
    201 
    202 IDS
    203 ---
    204 
    205 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
    206 
    207     fail2ban-client set $JAIL_NAME unbanip $IP_ADDRESS
    208 
    209 backups
    210 -------
    211 
    212 We are using [restic](https://restic.readthedocs.io/) for backups.
    213 
    214 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).
    215 
    216 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.
    217 
    218     # .ssh/authorized_keys
    219     restrict,command="/lib/sftp-server" ssh-ed25519 ...
    220 
    221 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`.
    222 
    223 smtp relay
    224 ----------
    225 
    226 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.
    227 
    228 Some handy commands for introspecting the mail system.
    229 
    230     mail                       # read mails on local account
    231     tail -f /var/log/mail.log  # postfix logs
    232 
    233 You need to `systemctl restart postfix` when you update the `main.cf`.
    234 
    235 You cand send a test mail with the following:
    236 
    237     echo "Subject: test from eik" | /usr/sbin/sendmail -v some@where.nice
    238 
    239 creating system users
    240 ---------------------
    241 
    242 We seem to be doing this.
    243 
    244     useradd --system --shell /sbin/nologin <username>
    245 
    246 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.
    247 
    248 rauthy
    249 ------
    250 
    251 ### build
    252 
    253 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.
    254 
    255 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.
    256 
    257     sudo apt-get install musl-tools
    258     rustup target add x86_64-unknown-linux-musl
    259     cargo build --target=x86_64-unknown-linux-musl --release
    260 
    261 You can transfer to eik like so.
    262 
    263     scp target/x86_64-unknown-linux-musl/release/rauthy eik.permacomputing.net:
    264 
    265 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.
    266 
    267 ### configure
    268 
    269 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).
    270 
    271 You can `journalctl -fu rauthy` to follow along with the logs and the usual `systemctl restart rauthy` will restart Rauthy.
    272 
    273 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.
    274 
    275 ### admin
    276 
    277 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.
    278 
    279 ### arbitrary single sign-on
    280 
    281 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.
    282 
    283 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.
    284 
    285 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:
    286 
    287 * 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)
    288 * Disable PKCE in the `rauthy` web client UI
    289 * 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.
    290 
    291 Here's an example `nginx` configuration.
    292     
    293     upstream rauthy {
    294       server 127.0.0.1:8080 fail_timeout=5;
    295     }
    296 
    297     location /auth {
    298       internal;
    299 
    300       proxy_set_header X-Original-URI $request_uri;
    301       proxy_set_header X-Forwarded-Method $request_method;
    302       proxy_set_header X-Forwarded-Proto $scheme;
    303       proxy_set_header X-Forwarded-Host $http_host;
    304       proxy_set_header X-Forwarded-URI $request_uri;
    305 
    306       proxy_set_header Content-Length "";
    307       proxy_set_header Connection "";
    308       proxy_pass_request_body off;
    309 
    310       proxy_pass http://rauthy/auth/v1/clients/<YOUR-CLIENT-ID>/forward_auth;
    311     }
    312 
    313     location = /callback {
    314       proxy_set_header X-Forwarded-Proto $scheme;
    315       proxy_set_header X-Forwarded-Host $http_host;
    316       proxy_pass http://rauthy/auth/v1/clients/<YOUR-CLIENT-ID>/forward_auth/callback?$args;
    317     }
    318     
    319     location / {
    320         auth_request /auth;
    321         auth_request_set $redirection_url $upstream_http_location;
    322         error_page 401 =302 $redirection_url;
    323 
    324         # NOTE(d1): finally, serve your webshit
    325         try_files $uri $uri/ =404;
    326     }
    327 
    328 ### nss
    329 
    330 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.