App namespaces¶
Apps from GEWIS/k8s-apps arrive in the
external-apps layer. Each environment of an app (sudosos-prod,
sudosos-test, …) gets a namespace, and its manifests come from the app's own
repository. That repository is outside this one's review, so what it may deploy is
limited in three ways.
Deploy identity¶
Flux applies each environment as its own ServiceAccount in flux-system, named
after the namespace (flux-system/sudosos-prod). That account is bound only
in its own namespace, to the app-deployer Role. The Role allows the
usual workload, Service, Secret, PVC, Traefik, cert-manager Certificate,
SealedSecret and ExternalSecret objects. It does not allow RBAC, Issuers,
DaemonSets or anything cluster-scoped.
k8s-apps itself is applied without a ServiceAccount, so as cluster-admin. Merging to
its main branch is how a person grants these rights, which is intentional.
The ServiceAccount, Role, RoleBinding, quota and namespace label all come
from the components/app-namespace component in k8s-apps, derived from the
Namespace's name. See that repository's README.
Quota¶
Every app namespace gets the ResourceQuota app-quota and the LimitRange app-defaults:
| Limit | Value |
|---|---|
requests.cpu |
4 |
requests.memory |
16Gi |
requests.storage |
100Gi |
persistentvolumeclaims |
10 |
services.loadbalancers, services.nodeports |
0 |
The LimitRange gives every container without a request a 50m CPU and 128Mi memory
request, so the quota can count it. It sets no limits, because most apps
have never been sized and a default memory limit would OOM-kill them.
LoadBalancer and NodePort Services are refused, so an app cannot take an
address from the Cilium pool or a port on every node, and so cannot get around Traefik.
Hostnames¶
flux/30_config/admission/app-ingress-hosts.yaml is a
ValidatingAdmissionPolicy for namespaces labelled
gewis.nl/app-namespace: "true". It reads the allowed hosts from the
namespace's gewis.nl/ingress-hosts annotation (comma-separated, exact names).
Both are set in k8s-apps, which the app's own repository cannot change:
- An IngressRoute route needs a
Host(...)from that list, and everyHost(...)in it must be listed. Its match must be a chain of&&, orHost(...) && (...).||elsewhere,!andHostRegexpare refused, because each of them can match hosts outside the list. - An Ingress needs a listed
hoston every rule and nodefaultBackend. - Services, Ingresses and IngressRoutes may not carry external-dns
hostnameannotations, so an app cannot publish a DNS name for a host it does not route. - Without the annotation, no host is allowed.
*allows any host. Onlywebhost-prodandwebhost-testuse it, because their hosts come from the HelmRelease values ink8s-appsitself.
With hosts limited this way, an app cannot take over another app's or the
platform's hostname (auth.gewis.nl, openbao.gewis.nl). Since it cannot
create an Issuer either, it cannot get a certificate for such a hostname.
A new app hostname therefore needs a line in the namespace annotation in
k8s-apps before its route is admitted. The label key and annotation key are the
contract between this policy and the component in k8s-apps; changing either
means changing both repositories.