Skip to main content

SKY-DEP002 · Deployment and infrastructure

Internet-facing Ingress reaches the Flask debugger

High

flask run --debug turns on the Werkzeug debugger, a page that lets the visitor run Python code on the server after an error. SKY-DEP002 reports a Kubernetes deployment whose internet-facing Ingress routes to a container started that way.

Languages
Kubernetes YAML, Flask
Quality gate
counted toward the gate limits (full and diff scans). Reported under security (danger). It counts toward max_high and max_security.
Finding type
review
Catalog name
External Ingress exposes the Flask development debugger
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

Anyone who can trigger an error page, or guess the debugger PIN, gets a Python console on the server with the app's secrets and network access. Flask's own documentation says never to use it in production.

What Skylos flags

app/main.py · Python
from flask import Flask app = Flask(__name__)  @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: ["flask"]          args: ["--app", "app.main:app", "run", "--debug",                 "--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: ["flask"]          args: ["--app", "app.main:app", "run", "--debug", "--no-debugger",                 "--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

Debug mode is still on, but --no-debugger comes after --debug and turns the interactive debugger off, so there is no code console. Debug mode still reloads on file changes, which SKY-DEP003 reports.

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. For a flask run container, works out the debugger setting from the literal flags: --debug turns it on, and a later --no-debug or --no-debugger turns it off again.
  5. Does not need the source-file or required-guards annotations.
  6. Reports HIGH on the container's args line.

How to fix it

Run Flask behind a production server such as Gunicorn, with no debug flags.

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.0Removed:           command: ["flask"]Removed:           args: ["--app", "app.main:app", "run", "--debug",Removed:                  "--host", "0.0.0.0", "--port", "8000"]Added:           command: ["gunicorn"]Added:           args: ["app.main:app", "--workers", "2", "--bind", "0.0.0.0: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

  • Debug mode turned on through FLASK_DEBUG=1 in the environment or app.run(debug=True) in code 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", "app.main:app", "run", "--debug"]  # skylos: ignore[SKY-DEP002]
  • [tool.skylos] ignore = ["SKY-DEP002"] 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.