@yunuseon/kayra 0.22.1 → 0.22.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -54,6 +54,8 @@
54
54
  - role: monitor
55
55
  become: true
56
56
  when: monitor is defined
57
+ vars:
58
+ monitor_page: true
57
59
 
58
60
  post_tasks:
59
61
  - name: Record which kayra set this server up
@@ -5,7 +5,8 @@
5
5
  # monitor_endpoints and monitor_hosts) plus monitor.extra, and alerting through
6
6
  # the notifier's ntfy after three failures, again once it has recovered.
7
7
  # Watched names are pinned to their servers' addresses (extra_hosts), so home
8
- # names resolve through the tunnel from the edge as they do at home.
8
+ # names resolve through the tunnel from the edge as they do at home. On a
9
+ # platform server (monitor_page) its page is status.<domain>, behind the login.
9
10
  # =============================================================================
10
11
 
11
12
  - name: Check the monitor has a notifier and its tokens
@@ -9,9 +9,28 @@ services:
9
9
  volumes:
10
10
  - ./config:/config:ro
11
11
  mem_limit: 128m
12
+ {% if monitor_page | default(false) %}
13
+ # status.<domain>, for staff only: Traefik reaches it on platform-internal.
14
+ networks: [default, platform-internal]
15
+ labels:
16
+ - "traefik.enable=true"
17
+ - "traefik.docker.network=platform-internal"
18
+ - "traefik.http.routers.status.rule=Host(`status.{{ domain }}`)"
19
+ - "traefik.http.routers.status.entrypoints=websecure"
20
+ - "traefik.http.routers.status.tls.certresolver=le"
21
+ - "traefik.http.routers.status.middlewares=authelia@file"
22
+ - "traefik.http.services.status.loadbalancer.server.port=8080"
23
+ {% endif %}
12
24
  {% if monitor_hosts | length > 0 %}
13
25
  extra_hosts:
14
26
  {% for host, address in monitor_hosts | dictsort %}
15
27
  - "{{ host }}:{{ address }}"
16
28
  {% endfor %}
17
29
  {% endif %}
30
+ {% if monitor_page | default(false) %}
31
+
32
+ networks:
33
+ platform-internal:
34
+ name: platform-internal
35
+ external: true
36
+ {% endif %}
@@ -94,6 +94,11 @@ access_control:
94
94
  policy: '{{ env "AUTH_POLICY" }}'
95
95
  subject:
96
96
  - 'group:admin'
97
+ # The monitor's page, where the server runs one.
98
+ - domain: 'status.{{ env "DOMAIN" }}'
99
+ policy: '{{ env "AUTH_POLICY" }}'
100
+ subject:
101
+ - 'group:admin'
97
102
 
98
103
  session:
99
104
  name: 'authelia_session'
package/hosts.conf CHANGED
@@ -1,6 +1,9 @@
1
1
  # Platform subdomains to add to /etc/hosts and to the mkcert SAN list.
2
2
  # App subdomains live in each app's app.yml; apps may not claim these.
3
3
  # One subdomain per line. Read by scripts/local/setup-hosts.sh and scripts/local/certs.sh.
4
+ # status is routed only where the server runs a monitor (monitor in vars.yml);
5
+ # verify and the monitors expect it only there.
4
6
  deploy
5
7
  auth
6
8
  traefik
9
+ status
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yunuseon/kayra",
3
- "version": "0.22.1",
3
+ "version": "0.22.2",
4
4
  "description": "A self-hosted app platform and the CLI that runs it: Traefik, Authelia, a registry, rootless BuildKit and a small deployer per server, set up with OpenTofu and Ansible.",
5
5
  "license": "MIT",
6
6
  "author": "Yunus Öztürk",
@@ -3,8 +3,8 @@
3
3
  # monitor-endpoints.sh <server> — what the server's monitor (Gatus, the
4
4
  # monitor role) checks, from the same sources as verify.sh: for each server in
5
5
  # its vars.yml's monitor.watch,
6
- # platform: auth.<domain> answers; the platform's pages (hosts.conf) send a
7
- # browser to the login; every app route answers, not 5xx;
6
+ # platform: auth.<domain> answers; the platform's pages (hosts.conf, status
7
+ # where it runs a monitor) send a browser to the login; every app route answers, not 5xx;
8
8
  # deploy.<domain>/health is 200 (monitor_health_tokens.<server>)
9
9
  # edge: every edge_routes name answers, not 5xx
10
10
  # nas: nothing of its own: its stacks are monitor.extra
@@ -50,7 +50,9 @@ watched() {
50
50
  case "$kind" in
51
51
  platform)
52
52
  endpoint "auth.${domain}" "$server" "https://auth.${domain}/" false false '[STATUS] == 200' "$cert"
53
+ monitored="$( [ -f "${dir}/vars.yml" ] && yq -r '.monitor != null' "${dir}/vars.yml" || echo false)"
53
54
  awk '!/^[[:space:]]*(#|$)/ {print $1}' "${KAYRA_ROOT}/hosts.conf" | while IFS= read -r sub; do
55
+ [ "$sub" != status ] || [ "$monitored" = true ] || continue
54
56
  [ "$sub" = auth ] || endpoint "${sub}.${domain}" "$server" "https://${sub}.${domain}/" false false '[STATUS] == 302' "$cert"
55
57
  done
56
58
  endpoint "deploy.${domain}/health" "$server" "https://deploy.${domain}/health" false true '[STATUS] == 200'
@@ -5,8 +5,9 @@
5
5
  #
6
6
  # From here, the way the world reaches it (each name pinned to the server's
7
7
  # address, so neither DNS nor /etc/hosts has to be in place yet):
8
- # - auth.<domain> answers; the platform's own pages (hosts.conf) send a
9
- # browser to the login, not a 403 from rules Authelia never loaded
8
+ # - auth.<domain> answers; the platform's own pages (hosts.conf; status only
9
+ # where a monitor runs) send a browser to the login, not a 403 from rules
10
+ # Authelia never loaded
10
11
  # - every certificate is a real one (Let's Encrypt or mkcert), never
11
12
  # Traefik's default
12
13
  # - an unsigned webhook is refused (with webhooks: false, /hook is not
@@ -87,8 +88,13 @@ check() {
87
88
  }
88
89
 
89
90
  check "auth.${domain} answers" "auth.${domain}" GET answers
91
+ monitored="$( [ -f "${dir}/vars.yml" ] && yq -r '.monitor != null' "${dir}/vars.yml" || echo false)"
90
92
  while IFS= read -r sub; do
91
- [ "$sub" = auth ] || check "${sub}.${domain} sends a browser to the login" "${sub}.${domain}" GET to_login
93
+ case "$sub" in
94
+ auth) ;;
95
+ status) [ "$monitored" != true ] || check "${sub}.${domain} sends a browser to the login" "${sub}.${domain}" GET to_login ;;
96
+ *) check "${sub}.${domain} sends a browser to the login" "${sub}.${domain}" GET to_login ;;
97
+ esac
92
98
  done < <(awk '!/^[[:space:]]*(#|$)/ {print $1}' "${KAYRA_ROOT}/hosts.conf")
93
99
 
94
100
  first_app="$(head -1 <<< "$registered_wanted")"
@@ -28,9 +28,14 @@ locals {
28
28
  }
29
29
  uncloned = [for name, manifest in local.manifests : name if !fileexists(manifest)]
30
30
 
31
+ # status only where the server runs a monitor, which serves it.
32
+ vars_file = "${var.fleet_root}/servers/${var.server}/vars.yml"
33
+ monitored = fileexists(local.vars_file) ? try(yamldecode(file(local.vars_file)).monitor, null) != null : false
31
34
  platform_subdomains = [
32
- for line in split("\n", file("${path.module}/../../../hosts.conf")) :
33
- split(" ", trimspace(line))[0] if trimspace(line) != "" && !startswith(trimspace(line), "#")
35
+ for sub in [
36
+ for line in split("\n", file("${path.module}/../../../hosts.conf")) :
37
+ split(" ", trimspace(line))[0] if trimspace(line) != "" && !startswith(trimspace(line), "#")
38
+ ] : sub if sub != "status" || local.monitored
34
39
  ]
35
40
  app_subdomains = flatten([
36
41
  for name, manifest in local.manifests :
@@ -0,0 +1,6 @@
1
+ kind: platform
2
+ target: hetzner
3
+ domain: example.com
4
+ apps:
5
+ - {name: shop, repo: https://github.com/acme/shop.git}
6
+ - {name: blog, repo: https://github.com/acme/blog.git, path: site}
@@ -62,3 +62,18 @@ run "app_not_cloned" {
62
62
 
63
63
  expect_failures = [hcloud_zone_rrset.a]
64
64
  }
65
+
66
+ # A server running a monitor serves its page, status.<domain>, too.
67
+ run "monitor_page" {
68
+ command = plan
69
+
70
+ variables {
71
+ server = "watching"
72
+ zone = "example.com"
73
+ }
74
+
75
+ assert {
76
+ condition = contains(output.hosts, "status.example.com")
77
+ error_message = "status should be a host where the server runs a monitor"
78
+ }
79
+ }