java - 如何保护 GAE 灵活环境上的 google cron 服务任务?

标签 java security google-app-engine cron app-engine-flexible

我想要一个网址:

  • 仅由 google cron 服务调用

  • 不由网络浏览器中的用户调用

Whats on the google docs不起作用:当 cron 服务调用 servlet 时,它还会给我一个 403 错误 - 禁止访问...

并且没有关于灵活环境的 app.yaml 文件的安全相关信息。

我的两个观察:

  • Google 声明“Google App Engine 从 IP 地址 0.1.0.1 发出 Cron 请求”。但我得到了另一个启动 cron 作业的 IP 地址:

another IP address

  • 从该 IP 地址来看,HTTP header 实际上包含 X-Appengine-Cron(值为 true)

你有什么想法吗?

最佳答案

引用的文档片段提及基于 app.yaml 文件的 handlers 部分中的 login: admin 配置的安全方法不正确- handlers 部分适用于 the (non-java) standard environment app.yaml ,不是the flexible environment one 。因此,您可能想要删除此类未记录的配置,只是为了确保它不会产生一些意外/不需要的负面影响。

仅检查 X-Appengine-Cron 就足够了:它只能由应用程序的 cron 服务设置。来自 Securing URLs for cron :

Requests from the Cron Service will also contain a HTTP header:

X-Appengine-Cron: true

The X-Appengine-Cron header is set internally by Google App Engine. If your request handler finds this header it can trust that the request is a cron request. If the header is present in an external user request to your app, it is stripped, except for requests from logged in administrators of the application, who are allowed to set the header for testing purposes.

至于为什么对 cron 请求的响应是 403 - 您应该显示您的处理程序代码,该代码(最有可能)负责构建回复。

关于java - 如何保护 GAE 灵活环境上的 google cron 服务任务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42767839/

相关文章:

java - 序列化检查——编译时间和运行时间

java - 如果函数有@Test 注解,如何使用函数参数?

security - 禁用重定向 symfony 安全

google-app-engine - 当内存利用率超过限制时横向扩展 GAE

python - 我可以使用Python在App Engine中创建线程吗?

java - 使用 split 或 tokenizer 将字符串放入大括号内的方法

php - 使用 SHA-256 进行 CodeIgniter 哈希

javascript - 在 Rails 中清理 CSS

python - urlfetch_stub.py : Received a 301 to a POST. 使用 GET 重定向

java - 启动webview后软键盘一直在