Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Censor all information from worker options tab #1304

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -540,3 +540,10 @@ Default: None
Sets the URI to which an OAuth 2.0 server redirects the user after successful authentication and authorization.

`oauth2_redirect_uri` option should be used with :ref:`auth`, :ref:`auth_provider`, :ref:`oauth2_key` and :ref:`oauth2_secret` options.

censor_config
~~~~~~~~~~~~~

Default: False

Censors all fields in all worker's config tabs
2 changes: 1 addition & 1 deletion flower/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
VERSION = (2, 0, 0)
VERSION = (2, 0, 1)
__version__ = '.'.join(map(str, VERSION)) + '-dev'
12 changes: 12 additions & 0 deletions flower/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ def rewrite_handler(handler, url_prefix):
handler.handler_class, handler.kwargs, handler.name)
return ("/{}{}".format(url_prefix.strip("/"), handler[0]), handler[1])

def rewrite_handler_censor_config(handler):
if type(handler) is url:
if handler.name == "config":
return url(handler.regex.pattern, handler.handler_class, {"censor_config": True}, handler.name)
return handler


class Flower(tornado.web.Application):
pool_executor_cls = ThreadPoolExecutor
Expand All @@ -41,6 +47,12 @@ def __init__(self, options=None, capp=None, events=None,
if options is not None and options.url_prefix:
handlers = [rewrite_handler(h, options.url_prefix) for h in handlers]
kwargs.update(handlers=handlers)

if options.censor_config:
logging.debug("Censoring config from web interface")
handlers = [rewrite_handler_censor_config(h) for h in handlers]
kwargs.update(handlers=handlers)

super().__init__(**kwargs)
self.options = options or default_options
self.io_loop = io_loop or ioloop.IOLoop.instance()
Expand Down
2 changes: 2 additions & 0 deletions flower/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
define("url_prefix", type=str, help="base url prefix")
define("task_runtime_metric_buckets", type=float, default=Histogram.DEFAULT_BUCKETS,
multiple=True, help="histogram latency bucket value")
define("censor_config", type=bool, default=False,
help="censor config from web interface")


default_options = options
27 changes: 17 additions & 10 deletions flower/templates/worker.html
Original file line number Diff line number Diff line change
Expand Up @@ -333,14 +333,22 @@ <h3 id="workername">{{ worker['name'] }}</h3>
<caption>Configuration options</caption>
<tbody>
{% for name,value in sorted(worker.get('conf', {}).items()) %}
{% if value is not None %}
<tr>
<td><a
href="https://docs.celeryq.dev/en/latest/userguide/configuration.html#{{ name.lower().replace('_', '-') }}"
target="_blank">{{ name }}</a></td>
<td>{{ value }}</td>
</tr>
{% end %}
{% if value is not None %}
<tr>
<td><a href="http://docs.celeryproject.org/en/latest/userguide/configuration.html#{{ name.lower().replace('_', '-') }}" target="_blank">{{ name }}</a></td>
{% if censor_config == True %}
<td><em>Censored</em></td>
{% else %}
<td>{{ value }}</td>
{% end %}
</tr>
{% else %}
<tr>
<td><a href="http://docs.celeryproject.org/en/latest/userguide/configuration.html#{{ name.lower().replace('_', '-') }}" target="_blank">{{ name }}</a></td>
<td>{{ value }}</td>
</tr>
{% end %}
{% end %}
{% end %}
</tbody>
</table>
Expand Down Expand Up @@ -386,5 +394,4 @@ <h3 id="workername">{{ worker['name'] }}</h3>
</div>
</div>
</div>
</div>
{% end %}
</div>
2 changes: 1 addition & 1 deletion flower/views/workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async def get(self, name):
if 'stats' not in worker:
raise web.HTTPError(404, f"Unable to get stats for '{name}' worker")

self.render("worker.html", worker=dict(worker, name=name))
self.render("worker.html", worker=dict(worker, name=name), censor_config=options.censor_config)


class WorkersView(BaseHandler):
Expand Down