balena-os / balena-supervisor

Balena Supervisor: balena's agent on devices.
https://balena.io
Other
148 stars 61 forks source link

Malformed request should return 400 #1296

Open 20k-ultra opened 4 years ago

20k-ultra commented 4 years ago

If you send a malformed payload to endpoints a 503 Service Unavailable is returned instead of a 400 Bad Request. I believe the 503 is from a proxy sitting in front of the Supervisor API because the API throws an exception resulting in service not responding to the proxy and it then resulting in a 503.

Example of malformed request:

$ curl -I -X POST "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$BALENA_APP_ID/restart-service?apikey=$BALENA_SUPERVISOR_API_KEY"      
HTTP/1.1 503 Service Unavailable
Content-Type: application/json; charset=utf-8
Content-Length: 84
ETag: W/"54-D6KLXxUoJRtNGzUt9zQapEy3/t8"
Date: Tue, 05 May 2020 16:49:29 GMT
Connection: keep-alive
CameronDiver commented 4 years ago

@20k-ultra I think this is actually masking something else. We don't have a proxy in front of the supervisor API, and I've no idea how you managed to get one :)

Is it reproducible? You weren't trying to proxy through BoB or anything like that?

20k-ultra commented 4 years ago

I'm talking directly to the supervisor which you can confirm by looking at:

The following verifies which *.local domain is my Pi4 running normal stack (not BoB). I am using the heuristics of the fact BoB runs 25 containers.

$ sudo balena scan
[sudo] password for mig: 
Reporting scan results
- 
  host:          d0973e8.local
  address:       192.168.1.76
  dockerInfo: 
    Containers:        3
    ContainersRunning: 2
    ContainersPaused:  0
    ContainersStopped: 1
    Images:            137
    Driver:            overlay2
    SystemTime:        2020-05-05T17:20:47.868747792Z
    KernelVersion:     4.19.71
    OperatingSystem:   balenaOS 2.47.0+rev1
    Architecture:      aarch64
  dockerVersion: 
    Version:    18.09.10-dev
    ApiVersion: 1.39
- 
  host:          db2c8b4.local
  address:       192.168.1.184
  dockerInfo: 
    Containers:        25
    ContainersRunning: 25
    ContainersPaused:  0
    ContainersStopped: 0
    Images:            33
    Driver:            aufs
    SystemTime:        2020-05-05T17:20:47.836991299Z
    KernelVersion:     5.2.10-yocto-standard
    OperatingSystem:   balenaOS 2020.04.0
    Architecture:      x86_64
  dockerVersion: 
    Version:    18.09.10-dev
    ApiVersion: 1.39

The following confirms I am using curl on the Supervisor API on the Pi not BoB

$ echo $BALENA_SUPERVISOR_ADDRESS 
http://d0973e8.local:48484