dokku / dokku-daemon

A daemon wrapper around dokku
MIT License
32 stars 13 forks source link

Invalid JSON response when env. vars contain bad characters #31

Open petrbroz opened 2 years ago

petrbroz commented 2 years ago

Description of problem

The JSON response from dokku-daemon is invalid in certain situations, for example, when config variables contain "bad" characters such as double-quotes or backslashes.

Btw. I think this sometimes happens in other types of commands as well, for example, when the response from the logs command contains "bad" characters, the JSON response from dokku-daemon also cannot be parsed.

Steps to Reproduce

  1. Create a dummy dokku app, e.g., dokku apps:create dummy-app
  2. Set some config variable with a double-quote in its value to this app, e.g., dokku config:set dummy-app FOO="bar\"baz"
  3. Connect to dokku-daemon with socat
  4. Try exporting the config of the app in JSON format, e.g., config:export dummy-app --format json

Actual Results

{"ok":true,"output":"{\"FOO\":\"bar\\"baz\"}"} (this JSON doesn't seem to be valid)

Expected Results

Probably {"ok":true,"output":"{\"FOO\":\"bar\\\"baz\"}"}.

Environment Information

dokku report dummy-app output

-----> uname: Linux ip-10-57-230-158 5.15.0-1011-aws #14-Ubuntu SMP Wed Jun 1 20:54:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
-----> memory: 
                      total        used        free      shared  buff/cache   available
       Mem:            7948         808         826           1        6313        6842
       Swap:              0           0           0
-----> docker version: 
       Client: Docker Engine - Community
        Version:           20.10.17
        API version:       1.41
        Go version:        go1.17.11
        Git commit:        100c701
        Built:             Mon Jun  6 23:02:46 2022
        OS/Arch:           linux/amd64
        Context:           default
        Experimental:      true

       Server: Docker Engine - Community
        Engine:
         Version:          20.10.17
         API version:      1.41 (minimum version 1.12)
         Go version:       go1.17.11
         Git commit:       a89b842
         Built:            Mon Jun  6 23:00:51 2022
         OS/Arch:          linux/amd64
         Experimental:     false
        containerd:
         Version:          1.6.8
         GitCommit:        9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
        runc:
         Version:          1.1.4
         GitCommit:        v1.1.4-0-g5fd4c4d
        docker-init:
         Version:          0.19.0
         GitCommit:        de40ad0
-----> docker daemon info: 
       Client:
        Context:    default
        Debug Mode: true
        Plugins:
         app: Docker App (Docker Inc., v0.9.1-beta3)
         buildx: Docker Buildx (Docker Inc., v0.8.2-docker)
         compose: Docker Compose (Docker Inc., v2.6.0)
         scan: Docker Scan (Docker Inc., v0.17.0)

       Server:
        Containers: 6
         Running: 6
         Paused: 0
         Stopped: 0
        Images: 86
        Server Version: 20.10.17
        Storage Driver: overlay2
         Backing Filesystem: extfs
         Supports d_type: true
         Native Overlay Diff: true
         userxattr: false
        Logging Driver: json-file
        Cgroup Driver: systemd
        Cgroup Version: 2
        Plugins:
         Volume: local
         Network: bridge host ipvlan macvlan null overlay
         Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
        Swarm: inactive
        Runtimes: runc io.containerd.runc.v2 io.containerd.runtime.v1.linux
        Default Runtime: runc
        Init Binary: docker-init
        containerd version: 9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
        runc version: v1.1.4-0-g5fd4c4d
        init version: de40ad0
        Security Options:
         apparmor
         seccomp
          Profile: default
         cgroupns
        Kernel Version: 5.15.0-1011-aws
        Operating System: Ubuntu 22.04 LTS
        OSType: linux
        Architecture: x86_64
        CPUs: 2
        Total Memory: 7.762GiB
        Name: ip-10-57-230-158
        ID: KJNR:KPSJ:BM2Z:GDJJ:K74N:7VRZ:CRWL:LUAE:5PF7:7UTK:PYLC:QELE
        Docker Root Dir: /var/lib/docker
        Debug Mode: false
        Registry: https://index.docker.io/v1/
        Labels:
        Experimental: false
        Insecure Registries:
         127.0.0.0/8
        Live Restore Enabled: false

-----> git version: git version 2.34.1
-----> sigil version: 0.9.0build+bc921b7
-----> herokuish version: 
       herokuish: 0.5.37
       buildpacks:
         heroku-buildpack-multi     v1.2.0
         heroku-buildpack-ruby      v244
         heroku-buildpack-nodejs    v198
         heroku-buildpack-clojure   v90
         heroku-buildpack-python    v214
         heroku-buildpack-java      v72
         heroku-buildpack-gradle    v38
         heroku-buildpack-scala     v94
         heroku-buildpack-play      v26
         heroku-buildpack-php       v223
         heroku-buildpack-go        v166
         heroku-buildpack-nginx     v16
         buildpack-null             v3
-----> dokku version: dokku version 0.28.1
-----> plugn version: plugn: 0.12.0build+3a27594
-----> dokku plugins: 
         00_dokku-standard    0.28.1 enabled    dokku core standard plugin
         20_events            0.28.1 enabled    dokku core events logging plugin
         app-json             0.28.1 enabled    dokku core app-json plugin
         apps                 0.28.1 enabled    dokku core apps plugin
         builder              0.28.1 enabled    dokku core builder plugin
         builder-dockerfile   0.28.1 enabled    dokku core builder-dockerfile plugin
         builder-herokuish    0.28.1 enabled    dokku core builder-herokuish plugin
         builder-lambda       0.27.0 enabled    dokku core builder-lambda plugin
         builder-null         0.28.1 enabled    dokku core builder-null plugin
         builder-pack         0.28.1 enabled    dokku core builder-pack plugin
         buildpacks           0.28.1 enabled    dokku core buildpacks plugin
         caddy-vhosts         0.28.1 enabled    dokku core caddy-vhosts plugin
         certs                0.28.1 enabled    dokku core certificate management plugin
         checks               0.28.1 enabled    dokku core checks plugin
         common               0.28.1 enabled    dokku core common plugin
         config               0.28.1 enabled    dokku core config plugin
         cron                 0.28.1 enabled    dokku core cron plugin
         docker-options       0.28.1 enabled    dokku core docker-options plugin
         domains              0.28.1 enabled    dokku core domains plugin
         enter                0.28.1 enabled    dokku core enter plugin
         git                  0.28.1 enabled    dokku core git plugin
         logs                 0.28.1 enabled    dokku core logs plugin
         network              0.28.1 enabled    dokku core network plugin
         nginx-vhosts         0.28.1 enabled    dokku core nginx-vhosts plugin
         plugin               0.28.1 enabled    dokku core plugin plugin
         proxy                0.28.1 enabled    dokku core proxy plugin
         ps                   0.28.1 enabled    dokku core ps plugin
         registry             0.28.1 enabled    dokku core registry plugin
         repo                 0.28.1 enabled    dokku core repo plugin
         resource             0.28.1 enabled    dokku core resource plugin
         run                  0.28.1 enabled    dokku core run plugin
         scheduler            0.28.1 enabled    dokku core scheduler plugin
         scheduler-docker-local 0.28.1 enabled    dokku core scheduler-docker-local plugin
         scheduler-null       0.28.1 enabled    dokku core scheduler-null plugin
         shell                0.28.1 enabled    dokku core shell plugin
         ssh-keys             0.28.1 enabled    dokku core ssh-keys plugin
         storage              0.28.1 enabled    dokku core storage plugin
         trace                0.28.1 enabled    dokku core trace plugin
         traefik-vhosts       0.28.1 enabled    dokku core traefik-vhosts plugin
=====> dummy-app app-json information
       App json computed selected:    app.json
       App json global selected:      app.json
       App json selected:             
=====> dummy-app app information
       App created at:                1663330986
       App deploy source:             
       App deploy source metadata:    
       App dir:                       /home/dokku/dummy-app
       App locked:                    false
=====> dummy-app builder information
       Builder build dir:             
       Builder computed build dir:    
       Builder computed selected:     
       Builder global build dir:      
       Builder global selected:       
       Builder selected:              
=====> dummy-app builder-dockerfile information
       Builder dockerfile computed dockerfile path: Dockerfile               
       Builder dockerfile global dockerfile path: Dockerfile               
       Builder dockerfile dockerfile path:                          
=====> dummy-app builder-lambda information
       Builder lambda computed lambdayml path: lambda.yml               
       Builder lambda global lambdayml path: lambda.yml               
       Builder lambda lambdayml path:                          
=====> dummy-app builder-pack information
       Builder pack computed projecttoml path: project.toml             
       Builder pack global projecttoml path: project.toml             
       Builder pack projecttoml path:                          
=====> dummy-app buildpacks information
       Buildpacks computed stack:     gliderlabs/herokuish:latest-20
       Buildpacks global stack:       
       Buildpacks list:               
       Buildpacks stack:              
=====> dummy-app ssl information
       Ssl dir:                       /home/dokku/dummy-app/tls
       Ssl enabled:                   false                    
       Ssl hostnames:                                          
       Ssl expires at:                                         
       Ssl issuer:                                             
       Ssl starts at:                                          
       Ssl subject:                                            
       Ssl verified:                                           
=====> dummy-app checks information
       Checks disabled list:          none                     
       Checks skipped list:           none                     
=====> dummy-app cron information
       Cron task count:               0
=====> dummy-app docker options information
       Docker options build:                                   
       Docker options deploy:         --restart=on-failure:10  
       Docker options run:                                     
=====> dummy-app domains information
       Domains app enabled:           true                     
       Domains app vhosts:                                     
       Domains global enabled:        true                     
       Domains global vhosts:         autodesk.io              
=====> dummy-app git information
       Git deploy branch:             master                   
       Git global deploy branch:      master                   
       Git keep git dir:              false                    
       Git rev env var:               GIT_REV                  
       Git sha:                                                
       Git last updated at:                                    
=====> dummy-app logs information
       Logs computed max size:        10m
       Logs global max size:          10m
       Logs global vector sink:       
       Logs max size:                 
       Logs vector sink:              
=====> dummy-app network information
       Network attach post create:           
       Network attach post deploy:           
       Network bind all interfaces:          false
       Network computed attach post create:  
       Network computed attach post deploy:  
       Network computed bind all interfaces: false
       Network computed initial network:     
       Network computed tld:                 
       Network global attach post create:    
       Network global attach post deploy:    
       Network global bind all interfaces:   false
       Network global initial network:       
       Network global tld:                   
       Network initial network:              
       Network static web listener:          
       Network tld:                          
       Network web listeners:                
=====> dummy-app nginx information
       Nginx access log format:                                
       Nginx access log path:         /var/log/nginx/dummy-app-access.log
       Nginx bind address ipv4:                                
       Nginx bind address ipv6:       ::                       
       Nginx client max body size:                             
       Nginx disable custom config:   false                    
       Nginx error log path:          /var/log/nginx/dummy-app-error.log
       Nginx global hsts:             true                     
       Nginx computed hsts:           true                     
       Nginx hsts:                                             
       Nginx hsts include subdomains: true                     
       Nginx hsts max age:            15724800                 
       Nginx hsts preload:            false                    
       Nginx proxy buffer size:       4096                     
       Nginx proxy buffering:         on                       
       Nginx proxy buffers:           8 4096                   
       Nginx proxy busy buffers size: 8192                     
       Nginx proxy read timeout:      60s                      
       Nginx last visited at:                                  
       Nginx x forwarded for value:   $remote_addr             
       Nginx x forwarded port value:  $server_port             
       Nginx x forwarded proto value: $scheme                  
       Nginx x forwarded ssl:                                  
=====> dummy-app proxy information
       Proxy enabled:                 true
       Proxy port map:                
       Proxy type:                    nginx
=====> dummy-app ps information
       Deployed:                      false
       Processes:                     0
       Ps can scale:                  true
       Ps computed procfile path:     Procfile
       Ps global procfile path:       Procfile
       Ps procfile path:              
       Ps restart policy:             on-failure:10
       Restore:                       true
       Running:                       false
=====> dummy-app registry information
       Registry computed image repo:      dokku/dummy-app
       Registry computed push on release: false
       Registry computed server:          
       Registry global push on release:   
       Registry global server:            
       Registry image repo:               
       Registry push on release:          
       Registry server:                   
       Registry tag version:              
=====> dummy-app resource information
=====> dummy-app scheduler information
       Scheduler computed selected:   docker-local
       Scheduler global selected:     docker-local
       Scheduler selected:            
=====> dummy-app scheduler-docker-local information
       Scheduler docker local disable chown:                          
       Scheduler docker local init process: true                     
       Scheduler docker local parallel schedule count:                          
=====> dummy-app storage information
       Storage build mounts:                                   
       Storage deploy mounts:                                  
       Storage run mounts:  

How (deb/make/rpm) and where (AWS, VirtualBox, physical, etc.) was Dokku installed?

Installed to an AWS EC2 instance.

petrbroz commented 2 years ago

I'm wondering if this could be addressed by supporting an --encoded flag in the same way as it can be used with config:set (basically base64 encoding all config values returned from config:export independently from what --format is used)?