如何为Google Cloud Run应用程序启用HSTS



我的Google Cloud Run应用程序使用传统的302响应将HTTP请求重定向到HTTPS。有没有办法让Google Cloud Run使用HSTS头?

我的应用程序堆栈是express。我试过helmet.hsts(),但它不起作用。似乎HTTP请求在到达我的express应用程序之前会被谷歌代理重定向。

这是我的请求和回复示例:

* Rebuilt URL to: <URL>
*   Trying 2001:4860:4802:36::35...
* TCP_NODELAY set
* Connected to <HOST> (2001:4860:4802:36::35) port 80 (#0)
> GET / HTTP/1.1
> Host: <HOST>
> User-Agent: curl/7.55.1
> Accept: */*
>
< HTTP/1.1 302 Found
< Location: <URL>
< X-Cloud-Trace-Context: e1f3dfe0e7bd604c447ca0c8f8c0ea5c
< Date: Thu, 24 Jun 2021 10:23:48 GMT
< Content-Type: text/html
< Server: Google Frontend
< Content-Length: 0
<
* Connection #0 to host <HOST> left intact

您不能自定义Cloud Run内置代理。因此,您不能像严格的传输安全标头那样添加所需的标头。

但是,作为解决方法,您可以部署HTTPS负载均衡器,并将您的Cloud Run服务添加为Serverless NEG后端。然后,您必须配置HTTPS负载均衡器以添加自定义标头

最新更新