如何在 GAE flexible env 上保护 google cron 服务任务?

How to secure google cron service tasks on GAE flexible env?

我想要 url:

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

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

我的两个观察:

你有什么想法吗?

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

只检查 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 - 您应该显示您的处理程序代码,它(很可能)是负责构建回复的代码。