Skip to content
This repository was archived by the owner on Sep 12, 2018. It is now read-only.

Commit 436aa94

Browse files
author
Olivier Gambier
committed
Enhanced debugging infos
- removed version / config leakage in headers for all requests - moved versions output to ping - added more hosts debugging infos in the ping endpoint - renamed _versions to _debug - removed version from the / endpoint - made / text configurable (issue) Docker-DCO-1.1-Signed-off-by: Olivier Gambier <[email protected]> (github: dmp42)
1 parent fb94977 commit 436aa94

File tree

3 files changed

+22
-31
lines changed

3 files changed

+22
-31
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ When using the `config_sample.yml`, you can pass all options through as environm
153153
1. `loglevel`: string, level of debugging. Any of python's
154154
[logging](http://docs.python.org/2/library/logging.html) module levels:
155155
`debug`, `info`, `warn`, `error` or `critical`
156-
1. `debug_versions`: boolean, enable the `/_versions` endpoint for debugging.
156+
1. `debug`: boolean, make the `/_ping` endpoint output more useful informations, such as library versions and host information.
157157
1. `storage_redirect`: Redirect resource requested if storage engine supports
158158
this, e.g. S3 will redirect signed URLs, this can be used to offload the
159159
server.

config/config_sample.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# All other flavors inherit the `common' config snippet
22
common: &common
3+
issue: '"docker-registry server"'
34
# Default log level is info
45
loglevel: _env:LOGLEVEL:info
5-
# Enable the debugging /_versions endpoint
6-
debug_versions: _env:DEBUG_VERSIONS:false
6+
# Enable debugging (additional informations in the output of the _ping endpoint)
7+
debug: _env:DEBUG:false
78
# By default, the registry acts standalone (eg: doesn't query the index)
89
standalone: _env:STANDALONE:true
910
# The default endpoint to use (if NOT standalone) is index.docker.io
@@ -179,7 +180,7 @@ elliptics:
179180
dev: &dev
180181
<<: *local
181182
loglevel: _env:LOGLEVEL:debug
182-
debug_versions: _env:DEBUG_VERSIONS:true
183+
debug: _env:DEBUG:true
183184
search_backend: _env:SEARCH_BACKEND:sqlalchemy
184185

185186
# This flavor is used by unit tests

docker_registry/app.py

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44
import logging.handlers
55
import os
6+
import platform
67
import sys
78

89
from . import toolkit
@@ -26,24 +27,16 @@
2627
@app.route('/_ping')
2728
@app.route('/v1/_ping')
2829
def ping():
29-
headers = {'X-Docker-Registry-Standalone': cfg.standalone is True}
30-
if mirroring.is_mirror():
31-
headers['X-Docker-Registry-Standalone'] = 'mirror'
32-
return toolkit.response(headers=headers)
30+
headers = {
31+
'X-Docker-Registry-Standalone': 'mirror' if mirroring.is_mirror()
32+
else (cfg.standalone is True)
33+
}
34+
infos = {}
35+
if cfg.debug:
36+
# Versions
37+
versions = infos['versions'] = {}
38+
headers['X-Docker-Registry-Config'] = cfg.flavor
3339

34-
35-
@app.route('/_versions')
36-
@app.route('/v1/_versions')
37-
def versions():
38-
"""Return a JSON object ({"package-name": "package-version", ...}).
39-
40-
This is an unofficial endpoint for debugging your docker-registry
41-
install. If you're running a publicly-accessible endpoint, it's
42-
probably best to disable this endpoint to avoid leaking
43-
implementation details.
44-
"""
45-
versions = {}
46-
if cfg.debug_versions:
4740
for name, module in sys.modules.items():
4841
if name.startswith('_'):
4942
continue
@@ -53,20 +46,17 @@ def versions():
5346
continue
5447
versions[name] = version
5548
versions['python'] = sys.version
56-
return toolkit.response(versions)
5749

50+
# Hosts infos
51+
infos['host'] = platform.uname()
52+
infos['launch'] = sys.argv
5853

59-
@app.route('/')
60-
def root():
61-
return toolkit.response('docker-registry server ({0}) (v{1})'
62-
.format(cfg.flavor, __version__))
54+
return toolkit.response(infos, headers=headers)
6355

6456

65-
@app.after_request
66-
def after_request(response):
67-
response.headers['X-Docker-Registry-Version'] = __version__
68-
response.headers['X-Docker-Registry-Config'] = cfg.flavor
69-
return response
57+
@app.route('/')
58+
def root():
59+
return toolkit.response(cfg.issue)
7060

7161

7262
def bugsnag(application, api_key, flavor, version):

0 commit comments

Comments
 (0)