SKY-DEP002 · Deployment and infrastructure
Internet-facing Ingress reaches the Flask debugger
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 towardmax_highandmax_security. - Finding type
- review
- Catalog name
- External Ingress exposes the Flask development debugger
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
from flask import Flask app = Flask(__name__) @app.get("/orders")def orders(): return {"orders": []}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: httpWhat Skylos leaves alone
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: httpWhy 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
- Runs with
--danger(or-a). Reads Kubernetes YAML in the repository and only works when anIngressopts in with the annotationsskylos.dev/network-scope: external(orinternet,public) andskylos.dev/backend-protocol: http. - Follows one chain inside one YAML file: Ingress path, to the
Serviceand 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 literalcommandandargs(uvicorn,gunicorn,flask run, orpython -mone of them) bound to0.0.0.0or::on that port. - 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.
- For a
flask runcontainer, works out the debugger setting from the literal flags:--debugturns it on, and a later--no-debugor--no-debuggerturns it off again. - Does not need the
source-fileorrequired-guardsannotations. - Reports HIGH on the container's
argsline.
How to fix it
Run Flask behind a production server such as Gunicorn, with no debug flags.
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: httpWhen it can be wrong
- Debug mode turned on through
FLASK_DEBUG=1in the environment orapp.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
argsline.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.