feat: harden Jeannie API gateway
This commit is contained in:
parent
ef4eee8162
commit
10a6f10705
|
|
@ -0,0 +1,12 @@
|
|||
apiVersion: v1
|
||||
kind: Endpoints
|
||||
metadata:
|
||||
name: jeannie-api
|
||||
namespace: jeannie-api
|
||||
subsets:
|
||||
- addresses:
|
||||
- ip: 192.168.100.73
|
||||
ports:
|
||||
- name: http
|
||||
port: 8787
|
||||
protocol: TCP
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: jeannie-api-read
|
||||
namespace: jeannie-api
|
||||
annotations:
|
||||
traefik.ingress.kubernetes.io/router.middlewares: jeannie-api-jeannie-api-auth@kubernetescrd,jeannie-api-jeannie-api-rate-limit@kubernetescrd,jeannie-api-jeannie-api-read-retry@kubernetescrd
|
||||
spec:
|
||||
ingressClassName: traefik
|
||||
rules:
|
||||
- host: api.lab2025.duckdns.org
|
||||
http:
|
||||
paths:
|
||||
- path: /v1/health
|
||||
pathType: Exact
|
||||
backend:
|
||||
service:
|
||||
name: jeannie-api
|
||||
port:
|
||||
number: 8787
|
||||
- path: /v1/commands
|
||||
pathType: Exact
|
||||
backend:
|
||||
service:
|
||||
name: jeannie-api
|
||||
port:
|
||||
number: 8787
|
||||
- path: /v1/executions
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: jeannie-api
|
||||
port:
|
||||
number: 8787
|
||||
---
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: jeannie-api-execute
|
||||
namespace: jeannie-api
|
||||
annotations:
|
||||
traefik.ingress.kubernetes.io/router.middlewares: jeannie-api-jeannie-api-auth@kubernetescrd,jeannie-api-jeannie-api-rate-limit@kubernetescrd
|
||||
spec:
|
||||
ingressClassName: traefik
|
||||
rules:
|
||||
- host: api.lab2025.duckdns.org
|
||||
http:
|
||||
paths:
|
||||
- path: /v1/execute
|
||||
pathType: Exact
|
||||
backend:
|
||||
service:
|
||||
name: jeannie-api
|
||||
port:
|
||||
number: 8787
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
resources:
|
||||
- namespace.yaml
|
||||
- service.yaml
|
||||
- endpoints.yaml
|
||||
- transport.yaml
|
||||
- middleware.yaml
|
||||
- ingress.yaml
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
apiVersion: traefik.io/v1alpha1
|
||||
kind: Middleware
|
||||
metadata:
|
||||
name: jeannie-api-auth
|
||||
namespace: jeannie-api
|
||||
spec:
|
||||
forwardAuth:
|
||||
address: http://jeannie-api.jeannie-api.svc.cluster.local:8787/v1/health
|
||||
authRequestHeaders:
|
||||
- Authorization
|
||||
trustForwardHeader: false
|
||||
---
|
||||
apiVersion: traefik.io/v1alpha1
|
||||
kind: Middleware
|
||||
metadata:
|
||||
name: jeannie-api-rate-limit
|
||||
namespace: jeannie-api
|
||||
spec:
|
||||
rateLimit:
|
||||
average: 10
|
||||
burst: 20
|
||||
period: 1s
|
||||
---
|
||||
apiVersion: traefik.io/v1alpha1
|
||||
kind: Middleware
|
||||
metadata:
|
||||
name: jeannie-api-read-retry
|
||||
namespace: jeannie-api
|
||||
spec:
|
||||
retry:
|
||||
attempts: 2
|
||||
initialInterval: 100ms
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: jeannie-api
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: jeannie-api
|
||||
namespace: jeannie-api
|
||||
annotations:
|
||||
traefik.ingress.kubernetes.io/service.serverstransport: jeannie-api-jeannie-api-backend@kubernetescrd
|
||||
spec:
|
||||
clusterIP: None
|
||||
ports:
|
||||
- name: http
|
||||
port: 8787
|
||||
targetPort: 8787
|
||||
protocol: TCP
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
apiVersion: traefik.io/v1alpha1
|
||||
kind: ServersTransport
|
||||
metadata:
|
||||
name: jeannie-api-backend
|
||||
namespace: jeannie-api
|
||||
spec:
|
||||
forwardingTimeouts:
|
||||
dialTimeout: 3s
|
||||
responseHeaderTimeout: 30s
|
||||
idleConnTimeout: 60s
|
||||
|
|
@ -58,6 +58,15 @@ variable "applications" {
|
|||
self_heal = true
|
||||
create_namespace = true
|
||||
}
|
||||
jeannie-api = {
|
||||
project = "default"
|
||||
path = "apps/jeannie-api"
|
||||
namespace = "jeannie-api"
|
||||
target_revision = "main"
|
||||
prune = true
|
||||
self_heal = true
|
||||
create_namespace = true
|
||||
}
|
||||
website-production = {
|
||||
project = "default"
|
||||
path = "apps/website"
|
||||
|
|
|
|||
|
|
@ -983,7 +983,21 @@ resource "helm_release" "traefik" {
|
|||
enabled = true
|
||||
}
|
||||
}
|
||||
metrics = {
|
||||
prometheus = {
|
||||
entryPoint = "metrics"
|
||||
addEntryPointsLabels = true
|
||||
addServicesLabels = true
|
||||
}
|
||||
}
|
||||
ports = {
|
||||
metrics = {
|
||||
port = 9100
|
||||
expose = {
|
||||
default = true
|
||||
}
|
||||
exposedPort = 9100
|
||||
}
|
||||
web = {
|
||||
port = 8000
|
||||
exposedPort = 80
|
||||
|
|
@ -1007,6 +1021,10 @@ resource "helm_release" "traefik" {
|
|||
general = {
|
||||
level = "INFO"
|
||||
}
|
||||
access = {
|
||||
enabled = true
|
||||
format = "json"
|
||||
}
|
||||
}
|
||||
resources = {
|
||||
requests = {
|
||||
|
|
@ -2004,6 +2022,25 @@ resource "helm_release" "prometheus_stack" {
|
|||
target_label = "instance"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
job_name = "traefik"
|
||||
static_configs = [
|
||||
{
|
||||
targets = ["traefik.${var.traefik.namespace}.svc:9100"]
|
||||
labels = {
|
||||
host_group = "ingress"
|
||||
}
|
||||
}
|
||||
]
|
||||
metrics_path = "/metrics"
|
||||
scheme = "http"
|
||||
relabel_configs = [
|
||||
{
|
||||
source_labels = ["__address__"]
|
||||
target_label = "instance"
|
||||
}
|
||||
]
|
||||
}
|
||||
])
|
||||
resources = {
|
||||
|
|
|
|||
|
|
@ -24,3 +24,28 @@ The initial allowlist contains read-only commands only. Execution state is
|
|||
stored in memory and command output is returned through
|
||||
GET /v1/executions/{id}. It is not a public edge service and does not accept
|
||||
arbitrary shell commands.
|
||||
|
||||
## Kubernetes API gateway
|
||||
|
||||
The `jeannie-api` Argo application publishes the Debian API through Traefik
|
||||
at `api.lab2025.duckdns.org`. The backend remains the Debian host at
|
||||
`192.168.100.73:8787`; Kubernetes does not run a second Jeannie server.
|
||||
|
||||
The gateway applies the existing bearer-token authentication, a rate limit of
|
||||
10 requests per second with a burst of 20, and backend timeouts of 3 seconds
|
||||
for dialing, 30 seconds for response headers, and 60 seconds for idle
|
||||
connections. Read-only routes may be retried once; `POST /v1/execute` is not
|
||||
retried so a command cannot be submitted twice by the gateway.
|
||||
|
||||
Traefik exposes JSON access logs and Prometheus request metrics. Prometheus
|
||||
scrapes the Traefik metrics endpoint as the `traefik` job, with entrypoint and
|
||||
service labels enabled.
|
||||
|
||||
For a LAN test after the edge/DNS certificate is available, use the host's
|
||||
LAN address or a local DNS override. Direct backend testing remains:
|
||||
|
||||
curl -H 'Authorization: Bearer replace-with-a-secret' \
|
||||
http://192.168.100.73:8787/v1/health
|
||||
|
||||
Through the API gateway, use the API hostname and the Traefik load-balancer
|
||||
address from the cluster network.
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ domain:
|
|||
- kapowarr.lab2025.duckdns.org
|
||||
- suwayomi.lab2025.duckdns.org
|
||||
- maintainerr.lab2025.duckdns.org
|
||||
- api.lab2025.duckdns.org
|
||||
|
||||
network:
|
||||
lan_cidr: 192.168.100.0/24
|
||||
|
|
|
|||
Loading…
Reference in New Issue