nixos-config/hosts/plover/README.adoc

188 lines
8.9 KiB
Plaintext
Raw Normal View History

2022-11-23 05:27:01 +00:00
= Plover, the general-purpose server
2022-12-28 06:10:16 +00:00
:toc:
:nixos-infect-commit: bca605ce2c91bc4d79bf8afaa4e7ee4fee9563d4
2022-11-23 05:27:01 +00:00
This is Plover, a configuration meant to be used in a low-powered general-purpose machine.
It isn't much of an instance to be seriously used yet but hopefully it is getting there.
This configuration is expected to be deployed in a Google Compute instance.
It has a reasonable set of assumptions to keep in mind when modifying this configuration:
- Most of the defaults are left to the link:https://github.com/NixOS/nixpkgs/tree/f92201f46109aabbbf41b8dc24bb9d342eb93a35/nixos/modules/virtualisation[image profiles from nixpkgs] including networking options and filesystems.
2023-01-17 08:32:56 +00:00
Though, they should be handled on link:./modules/hardware[`./modules/hardware`].
2022-11-23 05:27:01 +00:00
- No additional storage drives.
2023-01-17 08:32:56 +00:00
2022-11-23 05:27:01 +00:00
- At least 32 GB of space is assumed.
Some of the self-hosted services from this server:
* An nginx server which will make tie all of the self-hosted services together.
* A link:https://github.com/dani-garcia/vaultwarden[Vaultwarden] instance for a little password management.
* A link:https://gitea.io/[Gitea] instance for my personal projects.
2022-12-28 06:10:16 +00:00
* A link:https://www.keycloak.org/[Keycloak] instance for identity management.
2023-01-17 08:32:56 +00:00
* A VPN tunnel with link:https://www.wireguard.com/[Wireguard].
2023-02-09 06:18:10 +00:00
* A DNS server with link:https://coredns.io/[CoreDNS] managed as a "hidden" authoritative server and as a local DNS server for easily accessing the services with domain names.
2022-11-29 02:43:27 +00:00
[#general-deployment-guidelines]
== General deployment guidelines
If you want to deploy it anywhere else, you have to keep some things in mind.
* This uses link:https://github.com/mozilla/sops[sops] and link:https://github.com/Mic92/sops-nix[sops-nix] to decrypt secrets.
It mainly use the private key to the link:./files/age-key.pub[`./files/age-key.pub`] and move it to the appropriate location (i.e., `/var/lib/sops-nix/key.txt`).
* Be sure to set the appropriate firewalls either in the NixOS configuration or in the VPS provider firewall settings.
Take note some formats such as Google Compute image disable them entirely so it's safer to leave the firewall service and just configure the allowed ports and other settings.
2022-12-28 06:10:16 +00:00
* There are some things that are manually configured such as additional setup for the database.
Mostly related to setting up the proper roles which should be set up with the initial script at this point but there are some still left.
* If needed, restoring the application data from the backup into the services (e.g., Gitea, Keycloak, Vaultwarden).
* Configuring the remaining parts for the services (which unfortunately involves manually going into each application).
* Configure the database users with each appropriate service.
2023-01-12 08:51:36 +00:00
* Configure the services with users if starting from scratch.
** For Gitea, you have to create the main admin user with the admin interface.
+
--
Here's a way to quickly create a user in the admin interface.
[source, shell]
----
sudo -u gitea gitea admin user create --username USERNAME --email EMAIL \
--random-password --config /var/lib/gitea/custom/conf/app.ini --admin
----
--
** For Vaultwarden, you have to go to the admin page of the Vaultwarden instance (i.e., `$VAULTWARDEN_INSTANCE/admin`), get the admin token to enter, and invite users from there.
** For Keycloak, you have to create the appropriate realms and users as follows from the link:https://www.keycloak.org/docs/20.0.2/server_admin/index.html[server administration guide].
Though, you can easily create one from the command-line interface with `kcadm.sh`.
** For Portunus, this is already taken care of with a seed file.
Still, test the logins as indicated from the seed file.
=== Networking guidelines
Networking for a first-timer can be confusing (at least for me).
So here's the documentation for what is the practices that are following here.
2023-02-09 06:18:10 +00:00
* Networks are mainly divided into client and server blocks.
Keep in mind, these blocks are not subnets.
They're more like abstract guidelines for assigning subnets with some ease and some exceptions could be made.
2023-02-09 06:18:10 +00:00
* Server block are made up of interfaces attached to machines that provide services.
They mainly live in `172.16.0.0/13` and `10.0.0.0/9` for IPv4, `fc00::/8` for IPv6.
2023-02-09 06:18:10 +00:00
* Client block are made up of interfaces attached to machines that are mainly used as clients.
They mainly live in `172.24.0.0/13` and `10.128.0.0/9` for IPv4, `fd00::/8` for IPv6.
Furthermore, most of them should be freely assigned an IP address.
Thus, use of DHCP is pretty much ideal.
2023-02-09 06:18:10 +00:00
* Wireguard interfaces (including the server) are mainly at `172.28.0.0/14`, `10.200.0.0/13`, and `fd00:ffff::/64`.
They are also included as part of the client block.
The same principles are applied if you are considering to implement other VPN servers instead of the current setup.
2023-02-09 06:18:10 +00:00
* For private network `192.168.0.0/16` (for IPv4), it is basically a free-for-all.
There is no equivalent of a free-for-all network for IPv6 networks.
We're just dealing with the fact that the aforementioned network is widely used so we'll leave no assumptions here.
For more details, you can see the interfaces and their networking-related configuration in link:./modules/hardware/networks.nix[`./modules/hardware/networks.nix`].
2022-11-29 02:43:27 +00:00
== Deploying it as a Google Compute instance
Some documented guidelines to deploy this instance in Google Cloud Platform (GCP) so you won't have to re-read those documentation like a stuck rat the next time you visit them.
* A GCP Compute Instance image of the configuration is available to be stored at your storage buckets.
You can simply build it at `packages.plover-gce` and store it there.
+
You can take it further automating it by running link:../../scripts/generate-and-upload-gce-image[`../../scripts/generate-and-upload-gce-image`] which is just a modified version of the link:https://github.com/NixOS/nixpkgs/blob/ebdafd7244832f1f52cacd3eda39f2156988957e/nixos/maintainers/scripts/gce/create-gce.sh[`create-gce.sh` script from nixpkgs].
* If you already have access to at least one GCP KMS key, then skip this part.
Add a key to be used for deployment to wherever relevant file in the link:./secrets[secrets directory]. footnote:[Of course, you need previous keys which you're likely using the private age key for this system.]
For this, you'll have to create a GCP keyring on their key management system (KMS) and generate a key there.
* Enable link:https://cloud.google.com/compute/docs/oslogin/set-up-oslogin[OS Login] for your Compute Engine instance.
* Enable HTTP and HTTPS traffic in the firewall settings.
2022-11-29 02:43:27 +00:00
* Don't forget to set the appropriate scopes for the instance.
Use the least privileged scopes as much as possible.
2022-11-29 02:43:27 +00:00
* Reserve a static IP address, pls.
Just don't forget to immediately assign it to the instance since it will charge higher if you just leave it alone.
* Creating a dedicated link:https://cloud.google.com/iam/docs/service-accounts[service account] for the VM is recommended.
Just make sure to set the least amount of privileges for that account.
== Deploying it to Hetzner Cloud
A deployment to Hetzner Cloud is composed of mainly three things:
- A server.
- A firewall.
- A private network.
First, we will set up the latter two before creating the server. footnote:[Though, it can be created in any order, it's just personal preferences at this point.]
2023-02-09 06:18:10 +00:00
The firewall is already set in the host so no need to worry about it (as long as it is configured correctly, of course :p).
Next up, the networking setup which is composed of a public IP used for accessing some services and a private network used to communicate inside of the network.
2023-01-17 08:32:56 +00:00
However, the main reason we have a private network is to setup a VPN service to hide some of the more sensitive services.
You can create one from Hetzner Cloud web UI.
If you want to create with `hcloud`, however...
[source, shell]
----
hcloud network create --name plover-local --ip-range 172.16.0.0/12
----
To deploy this to Hetzner Cloud, just initialize a server and run link:https://github.com/elitak/nixos-infect/[nixos-infect] script.
As an example, you can run the server with the following link:https://community.hetzner.com/tutorials/basic-cloud-config[cloud config].
[source, yaml, subs=attributes]
----
#cloud-config
runcmd:
- curl https://raw.githubusercontent.com/elitak/nixos-infect/{nixos-infect-commit}/nixos-infect | NIX_CHANNEL=nixos-unstable bash 2>&1 | tee /tmp/infect.log
----
You could also easily create a server with `hcloud` with the following command:
[source, shell]
----
hcloud server create --location hel1 --type cx21 --image ubuntu-22.04 \
--network plover-local \
--user-data-from-file ./files/hcloud/hcloud-user-data.yml \
--ssh-key foodogsquared@foodogsquared.one \
--name nixos-plover
----
2023-02-09 06:18:10 +00:00
Don't forget to setup the prerequisites such as filesystems properly.
2023-01-06 12:26:13 +00:00
Here's a set of commands setting up to the current filesystem configuration.
[source, shell]
----
e2label /dev/sda1 nixos
fatlabel /dev/sda15 boot
----
Next, do the steps as written from <<general-deployment-guidelines>>.