我想要一个网址:
仅由 google cron 服务调用
不由网络浏览器中的用户调用
Whats on the google docs不起作用:当 cron 服务调用 servlet 时,它还会给我一个 403 错误 - 禁止访问...
并且没有关于灵活环境的 app.yaml 文件的安全相关信息。
我的两个观察:
- Google 声明“Google App Engine 从 IP 地址 0.1.0.1 发出 Cron 请求”。但我得到了另一个启动 cron 作业的 IP 地址:
- 从该 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/