diff --git a/k3s_rencher/README-gitops.md b/k3s_rencher/README-gitops.md new file mode 100644 index 0000000..e6e1da3 --- /dev/null +++ b/k3s_rencher/README-gitops.md @@ -0,0 +1,52 @@ +# Git-managed K3s configuration + +This directory contains the Kubernetes resources that are safe to keep in Git. +The intended ownership boundary is: + +- Ansible or the K3s install script bootstraps the cluster and installs Flux. +- Flux reconciles `k3s_rencher/`. +- `infrastructure/` contains shared cluster defaults. +- `apps/` contains workload definitions. +- Secrets are encrypted with SOPS or supplied by an external secrets manager. + +## Bootstrap resources + +The cluster configuration is `k3s_rencher/`. Render it before applying: + +```sh +kubectl kustomize k3s_rencher +kubectl apply -k k3s_rencher +``` + +The overlay currently installs the read-only agent account and its network +policies. Add each workload namespace to its own Kustomize overlay and include +`../../infrastructure/network-policies` in that overlay. NetworkPolicy is +namespace-scoped, so a single policy cannot cover future namespaces. + +## Network defaults + +Managed namespaces start with deny-by-default ingress and egress. DNS is the +only shared egress exception. Add explicit policies for application ingress, +pod-to-pod traffic, and approved external destinations. + +These policies do not restrict `hostNetwork` pods or traffic originating from a +node. Avoid `hostNetwork` unless it is required and review workloads with node +access separately. + +## Agent access + +The agent account uses Kubernetes' built-in `view` ClusterRole. It has no +Secret permissions and no write, exec, attach, or port-forward permissions. +Create a short-lived token at runtime: + +```sh +kubectl -n agent-gateway create token agent-readonly --duration=24h +``` + +Do not commit the token, kubeconfig, K3s join token, or an unencrypted Secret. + +## Cluster-specific settings + +This repository currently manages one cluster, so its Kustomize entrypoint is +at the root of `k3s_rencher/`. Keep shared policy in `infrastructure/` and add +cluster-specific settings there as the installation grows. \ No newline at end of file diff --git a/k3s_rencher/infrastructure/agent-gateway/kustomization.yaml b/k3s_rencher/infrastructure/agent-gateway/kustomization.yaml new file mode 100644 index 0000000..ce15221 --- /dev/null +++ b/k3s_rencher/infrastructure/agent-gateway/kustomization.yaml @@ -0,0 +1,7 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +namespace: agent-gateway +resources: + - namespace.yaml + - rbac.yaml + - ../network-policies \ No newline at end of file diff --git a/k3s_rencher/infrastructure/agent-gateway/namespace.yaml b/k3s_rencher/infrastructure/agent-gateway/namespace.yaml new file mode 100644 index 0000000..57d12b3 --- /dev/null +++ b/k3s_rencher/infrastructure/agent-gateway/namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: agent-gateway \ No newline at end of file diff --git a/k3s_rencher/infrastructure/agent-gateway/rbac.yaml b/k3s_rencher/infrastructure/agent-gateway/rbac.yaml new file mode 100644 index 0000000..e725829 --- /dev/null +++ b/k3s_rencher/infrastructure/agent-gateway/rbac.yaml @@ -0,0 +1,18 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: agent-readonly + namespace: agent-gateway +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: agent-readonly-view +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: view +subjects: + - kind: ServiceAccount + name: agent-readonly + namespace: agent-gateway \ No newline at end of file diff --git a/k3s_rencher/infrastructure/network-policies/allow-dns.yaml b/k3s_rencher/infrastructure/network-policies/allow-dns.yaml new file mode 100644 index 0000000..aa37e5a --- /dev/null +++ b/k3s_rencher/infrastructure/network-policies/allow-dns.yaml @@ -0,0 +1,21 @@ +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: allow-cluster-dns +spec: + podSelector: {} + policyTypes: + - Egress + egress: + - to: + - namespaceSelector: + matchLabels: + kubernetes.io/metadata.name: kube-system + podSelector: + matchLabels: + k8s-app: kube-dns + ports: + - protocol: UDP + port: 53 + - protocol: TCP + port: 53 \ No newline at end of file diff --git a/k3s_rencher/infrastructure/network-policies/default-deny.yaml b/k3s_rencher/infrastructure/network-policies/default-deny.yaml new file mode 100644 index 0000000..4fde025 --- /dev/null +++ b/k3s_rencher/infrastructure/network-policies/default-deny.yaml @@ -0,0 +1,17 @@ +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: default-deny-ingress +spec: + podSelector: {} + policyTypes: + - Ingress +--- +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: default-deny-egress +spec: + podSelector: {} + policyTypes: + - Egress \ No newline at end of file diff --git a/k3s_rencher/infrastructure/network-policies/kustomization.yaml b/k3s_rencher/infrastructure/network-policies/kustomization.yaml new file mode 100644 index 0000000..e0f9b8e --- /dev/null +++ b/k3s_rencher/infrastructure/network-policies/kustomization.yaml @@ -0,0 +1,5 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - default-deny.yaml + - allow-dns.yaml \ No newline at end of file diff --git a/k3s_rencher/kustomization.yaml b/k3s_rencher/kustomization.yaml new file mode 100644 index 0000000..fdb53ab --- /dev/null +++ b/k3s_rencher/kustomization.yaml @@ -0,0 +1,4 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - infrastructure/agent-gateway \ No newline at end of file