首页 > 解决方案 > 无法访问 tmp 目录中的文件

问题描述

我正在尝试使用 ebconfig 访问已下载到 /tmp/ 目录的.json 文件,以在 S3 上存储私钥

files:
  "/tmp/firebaseadminsdk.json" :
    mode: "000400"
    owner: root 
    group: root
    authentication: "S3Auth"
    source: 'source url'

但它给了我以下错误

Error: EACCES: permission denied, open '/tmp/firebaseadminsdk.json'

文档中有一段说

The second entry uses the S3Auth authentication method to download the private key from the specified URL and save it to /etc/pki/tls/certs/server.key. The proxy server can then read the private key from this location to terminate HTTPS connections at the instance.

不幸的是,我没有使用任何代理,因为建议不要使用,如果我将其更改为 ,它会导致实例的运行状况变得严重。

我再次确认 IAM 帐户对包含该文件的存储桶具有读写访问权限。我还添加了一个存储桶策略,以授予 IAM 帐户与存储桶交互的完全访问权限,如下所示 在此处输入图像描述

{
    "Version": "2012-10-17",
    "Id": "Policy1546355608026",
    "Statement": [
        {
            "Sid": "Stmt_____",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::______:role/aws-elasticbeanstalk-ec2-role"
            },
            "Action": "s3:*",
            "Resource": "arn:aws:s3:::_____/firebaseadminsdk.json"
        }
    ]
}

我还将 ec2 转到我的实例中,并将 S3fullaccess 策略添加到实例正在使用的 IAM 角色中,但在完成所有这些操作之后,错误仍然存​​在。

我也在使用负载均衡器,这可能会导致一些问题?

错误信息

Error: EACCES: permission denied, open '/tmp/firebaseadminsdk.json'
    at Object.openSync (fs.js:436:3)
    at Object.readFileSync (fs.js:341:35)
    at Object.Module._extensions..json (internal/modules/cjs/loader.js:705:20)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (/var/app/current/index.js:9:22)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
fs.js:115
    throw err;

标签: amazon-web-servicesamazon-s3amazon-elastic-beanstalk

解决方案


在您的文件复制代码中,从所有者读取更改权限400到为所有人读取444

files:
  "/tmp/firebaseadminsdk.json" :
    mode: "000444"
    owner: root 
    group: root
    authentication: "S3Auth"
    source: 'source url'

所有人的私钥读取权限可能不安全。

但我将它用于应用程序的 alpha 版本,稍后也会因为密钥轮换而实施 AWS KMS(密钥管理服务)。


推荐阅读