Skip to main content

SKY-DEP003 · Deployment and infrastructure

Internet-facing Ingress routes to a server in reload mode

Medium

Reload mode makes a development server watch its source files and restart when they change. SKY-DEP003 reports a Kubernetes deployment whose internet-facing Ingress routes to a Uvicorn, Gunicorn or Flask container started with --reload, or with Flask debug mode, which reloads too.

Languages
Kubernetes YAML, Uvicorn, Gunicorn, Flask
Quality gate
counted toward the gate limits (full and diff scans). Reported under reliability. It counts toward max_reliability, which is 0 by default, so one finding fails --gate.
Finding type
review
Catalog name
External Ingress routes to a reload-mode application server
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

The file watcher costs CPU in every pod, and Uvicorn's reloader runs a single worker process, so the service has less capacity than you think. Any file change inside the container restarts it mid-request.

What Skylos flags

app/main.py · Python
from fastapi import FastAPI app = FastAPI()  @app.get("/orders")def orders():    return {"orders": []}
deploy/api.yaml · YAMLReported on line 19
apiVersion: apps/v1kind: Deploymentmetadata:  name: api  namespace: prodspec:  selector:    matchLabels:      app: api  template:    metadata:      labels:        app: api    spec:      containers:        - name: api          image: ghcr.io/acme/api:1.4.0          command: ["uvicorn"]          args: ["app.main:app", "--reload", "--host", "0.0.0.0", "--port", "8000"]          ports:            - name: http              containerPort: 8000---apiVersion: v1kind: Servicemetadata:  name: api  namespace: prodspec:  selector:    app: api  ports:    - name: http      port: 80      targetPort: http---apiVersion: networking.k8s.io/v1kind: Ingressmetadata:  name: api  namespace: prod  annotations:    skylos.dev/network-scope: external    skylos.dev/backend-protocol: httpspec:  rules:    - host: api.example.com      http:        paths:          - path: /            pathType: Prefix            backend:              service:                name: api                port:                  name: http

What Skylos leaves alone

app/main.py: same as in the flagged example.

deploy/api.yaml · YAML
apiVersion: apps/v1kind: Deploymentmetadata:  name: api  namespace: prodspec:  selector:    matchLabels:      app: api  template:    metadata:      labels:        app: api    spec:      containers:        - name: api          image: ghcr.io/acme/api:1.4.0          command: ["uvicorn"]          args: ["app.main:app", "--workers", "2",                 "--host", "0.0.0.0", "--port", "8000"]          ports:            - name: http              containerPort: 8000---apiVersion: v1kind: Servicemetadata:  name: api  namespace: prodspec:  selector:    app: api  ports:    - name: http      port: 80      targetPort: http---apiVersion: networking.k8s.io/v1kind: Ingressmetadata:  name: api  namespace: prod  annotations:    skylos.dev/network-scope: external    skylos.dev/backend-protocol: httpspec:  rules:    - host: api.example.com      http:        paths:          - path: /            pathType: Prefix            backend:              service:                name: api                port:                  name: http

Why Skylos leaves it alone

The same Uvicorn container behind the same public Ingress, started with two worker processes instead of the reloader.

How Skylos decides

  1. Runs with --danger (or -a). Reads Kubernetes YAML in the repository and only works when an Ingress opts in with the annotations skylos.dev/network-scope: external (or internet, public) and skylos.dev/backend-protocol: http.
  2. Follows one chain inside one YAML file: Ingress path, to the Service and port it names, to the one workload the Service selects, to the one container whose port the Service targets. The server must be started with a literal command and args (uvicorn, gunicorn, flask run, or python -m one of them) bound to 0.0.0.0 or :: on that port.
  3. Any missing, dynamic or ambiguous link (two matching workloads, a Helm template value, HTTPS or gRPC backends, rewrite or snippet annotations) makes it report nothing rather than guess.
  4. Reports a literal --reload on a Uvicorn, Gunicorn or flask run command, and Flask debug mode (--debug) unless --no-reload follows.
  5. Does not need the source-file or required-guards annotations.
  6. Reports MEDIUM, as a reliability finding, on the container's args line.

How to fix it

Remove --reload; roll out code changes by building a new image. Set the number of workers for the pod's CPU instead.

deploy/api.yaml · YAML · the fix, against the flagged file
apiVersion: apps/v1kind: Deploymentmetadata:  name: api  namespace: prodspec:  selector:    matchLabels:      app: api  template:    metadata:      labels:        app: api    spec:      containers:        - name: api          image: ghcr.io/acme/api:1.4.0          command: ["uvicorn"]Removed:           args: ["app.main:app", "--reload", "--host", "0.0.0.0", "--port", "8000"]Added:           args: ["app.main:app", "--workers", "2",Added:                  "--host", "0.0.0.0", "--port", "8000"]          ports:            - name: http              containerPort: 8000---apiVersion: v1kind: Servicemetadata:  name: api  namespace: prodspec:  selector:    app: api  ports:    - name: http      port: 80      targetPort: http---apiVersion: networking.k8s.io/v1kind: Ingressmetadata:  name: api  namespace: prod  annotations:    skylos.dev/network-scope: external    skylos.dev/backend-protocol: httpspec:  rules:    - host: api.example.com      http:        paths:          - path: /            pathType: Prefix            backend:              service:                name: api                port:                  name: http

When it can be wrong

  • Reload turned on in code (uvicorn.run(..., reload=True)) or through environment variables is not read.
  • Without the two Ingress annotations the rule never runs. Keep them in a protected place: removing them silences the rule.
  • Resources split across several YAML files, Helm charts and Kustomize overlays are not joined or rendered. Scan rendered manifests.

Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.

How to silence it

  • Put the marker on the reported args line.

    YAML
    args: ["app.main:app", "--reload"]  # skylos: ignore[SKY-DEP003]
  • [tool.skylos] ignore = ["SKY-DEP003"] turns the rule off for the project.

  • A baseline (skylos baseline ., then --baseline) accepts the findings that exist today and reports new ones.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.