我有一个 Terraform 部署,它将 Docker 映像部署到 ECS Fargate。它将 EFS 卷附加到容器。当我通过 SSH 进入容器时,我看到卷已安装,但我无法写入它。所有 POSIX 权限似乎都正确。
以下是该问题的示例:
$ ssh -i ~/.ssh/_inletchef/ifsudo.pem [email protected]
Last login: Fri Apr 14 21:45:27 2023 from ip-10-0-3-140.us-west-1.compute.internal
-bash-4.2$ sudo -i
-bash-4.2# mount | grep data
127.0.0.1:/ on /mnt/data type nfs4 (rw,relatime,vers=4.1,rsize=1048576,wsize=1048576,namlen=255,hard,noresvport,proto=tcp,port=20403,timeo=600,retrans=2,sec=sys,clientaddr=127.0.0.1,local_lock=none,addr=127.0.0.1)
-bash-4.2# ls -ld /mnt/data
drwxr-xr-x 2 root root 6144 Apr 14 02:33 /mnt/data
-bash-4.2# touch /mnt/data/xxxx touch: cannot touch ‘/mnt/data/xxxx’: Permission denied
在这里,我通过 SSH 进入容器,成为 root 用户,显示卷已挂载,显示挂载目录的权限,并尝试将新文件写入该目录,结果发现失败。
我以“root”身份运行,并且“root”拥有挂载点,并且该挂载点可由所有者写入。因此,POSIX 权限似乎应该允许我写入该目录。
由于上述原因,我猜测我的 EFS 卷由于某种与 POSIX 所有者和 perm 标志无关的原因而不可写入。但我不明白我的配置如何导致该卷为只读。
有人能告诉我为什么在这种设置下我无法写入我的 EFS 卷吗?
以下是我的 Terraform 设置的相关部分:
resource "aws_efs_file_system" "main" {
count = (length(var.efs_mount_point) == 0)? 0 : 1
tags = {
Name = "ecs-efs-fs-${var.instance_name}"
}
}
resource "aws_efs_mount_target" "main" {
count = (length(var.efs_mount_point) == 0)? 0 : "${length(module.aws_account.private_subnets.ids)}"
file_system_id = "${aws_efs_file_system.main[0].id}"
subnet_id = "${element(module.aws_account.private_subnets.ids, count.index)}"
}
resource "aws_efs_access_point" "main" {
count = (length(var.efs_mount_point) == 0)? 0 : 1
file_system_id = aws_efs_file_system.main[0].id
posix_user {
uid = 1000
gid = 1000
}
root_directory {
path = "/"
creation_info {
owner_uid = 1000
owner_gid = 1000
permissions = 777
}
}
}
resource "aws_ecs_task_definition" "main" {
family = var.instance_name
network_mode = "awsvpc"
requires_compatibilities = ["FARGATE"]
...
dynamic "volume" {
content {
name = "efs_volume"
efs_volume_configuration {
file_system_id = aws_efs_file_system.main[0].id
transit_encryption = "ENABLED"
authorization_config {
access_point_id = aws_efs_access_point.main[0].id
iam = "ENABLED"
}
}
}
}
container_definitions = jsonencode([
{
...
"mountPoints": [
{
"containerPath": "${var.efs_mount_point}"
"sourceVolume": "efs_volume"
read_only: false
}
],
...
}
])
}