如何将服务器的私钥存储在 google 应用引擎中?

How do I store the private key of my server in google app engine?

我正在使用 "github.com/dgrijalva/jwt-go" 创建 JSON 网络令牌。
当我在本地托管我的服务器时,我可以像往常一样使用我的私钥。但在 GAE 中它不会工作,因为我无权访问文件系统。

你们会怎么做?将密钥存储在数据存储区或任何其他想法中?

谢谢

编辑:

我的 app.yaml 看起来像这样(低于 api_version 和东西):

handlers:
- url: /.*
  script: _go_app

在 AppEngine 上,您无权访问主机操作系统的文件系统,但您可以访问 Web 应用程序的文件(您有 read-only 权限,您不能更改它们,并且您无法在应用的文件夹中创建新文件)。

所以问题是:您是否要在不重新部署您的应用程序的情况下从您的应用程序更改此私钥?或者如果它与您的应用程序代码一起“静态”部署就完全没问题了?

如果您不需要更改它(或仅在您重新部署您的应用程序时),最简单的方法是将其存储为“静态”文件作为您的 web 应用程序的一部分。您可以使用相对路径引用应用程序的文件,其中当前或工作目录是应用程序的根目录。例如。如果您的应用程序在其根目录(app.yaml 所在的位置)包含一个 key 文件夹,并且 key 文件夹中有一个 my_key.txt 文件,您可以使用路径:key/my_key.txt.

实际上,将静态文件与您的应用程序代码一起“传送”是很常见的:想想 HTML 由 Go 代码读取和处理的模板(例如包 html/template)以生成HTML 结果; HTML 模板文件的内容不直接提供给客户。

如果您需要不时更改它而无需重新部署您的应用程序,则将其存储在您的应用程序可以读取和修改的数据存储中。

注:

重要说明:并非每个文件都可以通过代码读取,这取决于应用程序配置。引用自 Configuring with app.yaml / Static file handlers:

Static files are files to be served directly to the user for a given URL, such as images, CSS stylesheets, or JavaScript source files. Static file handlers describe which files in the application directory are static files, and which URLs serve them.

For efficiency, App Engine stores and serves static files separately from application files. Static files are not available in the application's file system. If you have data files that need to be read by the application code, the data files must be application files, and must not be matched by a static file pattern.

Static file handlers can be defined in two ways: as a directory structure of static files that maps to a URL path, or as a pattern that maps URLs to specific files.

阅读link如何正确配置应用程序和静态文件/目录。

解决方案是让 app.yaml 保持原样。将 app.yaml 放在项目的根 lvl 中。然后将所有导入从 GOPATH 开始更改为从项目根目录开始。让我选择将 app.yaml 和 main go 文件放在项目根目录下的不同文件夹中的问题是因为双重导入。阅读此内容以获得更好的理解:Google Go AppEngine imports and conflicts when serving / testing

该解决方案使我的项目找到了我想要的文件。