gpt4 book ai didi

django - 生产中的 celery 花安全

转载 作者:行者123 更新时间:2023-11-28 19:36:09 24 4
gpt4 key购买 nike

我希望使用 Flower ( https://github.com/mher/flower ) 来监视我的 Celery 任务,而不是在他们的文档 ( http://docs.celeryproject.org/en/latest/userguide/monitoring.html#flower-real-time-celery-web-monitor ) 中推荐的 django-admin。但是,因为我是新手,所以我对 Flower 页面仅基于 HTTP 而不是 HTTPS 的方式感到有点困惑。我如何为我的 Celery 任务启用安全性,这样任何老用户都不能只访问不需要登录的网站 http://flowerserver.com:5555并改变一些东西?

我考虑过 Celery 的 own documentation在此,但不幸的是,他们没有提及如何保护 Flower 的 api 或 web ui。全部内容:[此处需要更多文本]

谢谢!

更新:我的问题部分与此处重复:How do I add authentication and endpoint to Django Celery Flower Monitoring?

但是,我在这里通过询问如何使用包含 nginx、gunicorn 和 celery 的环境在同一台远程计算机上运行它来澄清他的问题。我也想知道如何设置 Flower 的外部可访问 url,但如果可能的话,我也更喜欢 https 而不是 http(或者某种保护 webui 和远程访问它的方法)。我还需要知道让 Flower 运行是否对任何可能访问 Flower 的内部 API 的人来说都是一个相当大的安全风险,以及保护它的最佳方法是什么,或者是否应该完全禁用它并仅在 as-需要的依据。

最佳答案

您可以使用 --auth 标志运行 flower,它将使用特定的谷歌电子邮件进行身份验证:

celery flower --auth=your.email@gmail.com

编辑 1:

新版本的 Flower 需要更多的标志和一个注册的 OAuth2 客户端 Google Developer Console :

celery flower \
--auth=your.email@gmail.com \
--oauth2_key="client_id" \
--oauth2_secret="client_secret" \
--oauth2_redirect_uri="http://example.com:5555/login"

oauth2_redirect_uri 必须是实际的 flower 登录 url,并且还必须添加到 Google Development Console 中的授权重定向 url。

不幸的是,此功能在当前稳定版本 0.7.2 中无法正常工作,但现在已在开发版本 0.8.0-dev 中使用此 commit 修复。

编辑 2:

您可以使用 basic authentication 配置 Flower:

celery flower --basic_auth=user1:password1,user2:password2

然后为除 localhost 之外的所有端口阻塞 5555 端口,并为 nginx 或 apache 配置反向代理:

ProxyRequests off
ProxyPreserveHost On
ProxyPass / http://localhost:5555

然后确保代理模块已打开:

sudo a2enmod proxy
sudo a2enmod proxy_http

如果您无法在单独的子域上设置它,例如:flower.example.com(上面的配置),您可以为 example.com/flower 设置它:

使用 url_prefix 运行花:

celery flower --url_prefix=flower --basic_auth=user1:password1,user2:password2

在 apache 配置中:

ProxyPass /flower http://localhost:5555

当然要确保配置了SSL,否则没有意义:)

关于django - 生产中的 celery 花安全,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19689510/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com