CDK를 사용한 Fargate + EFS 권한

8405 단어 devopsawscdk
EFS에 대한 권한을 분류하는 데 너무 오래 고생했습니다. 2개의 레이어가 있는 것으로 나타났습니다. IAM 역할 및 Posix 권한. 둘 다 비슷한 모양의 액세스가 거부되었습니다. 드디어!

단일 AZ로 나를 판단하지 마십시오. Fargate에서 단일 작업을 실행 중이며 하나의 인스턴스만 필요합니다.

const {vpc, az, region, account} = props;

const fileSystem = new FileSystem(this, 'Efs', {
  vpc,
  performanceMode: PerformanceMode.GENERAL_PURPOSE,
  vpcSubnets: {
    subnetType: ec2.SubnetType.PUBLIC,
    onePerAz: true,
    availabilityZones: [az]
  }
});

const accessPoint = new AccessPoint(this, 'AccessPoint', {
  fileSystem: fileSystem,
});

const task = new ecs.FargateTaskDefinition(this, 'Task', {
  cpu: 256,
  memoryLimitMiB: 512
});

const volumeName = 'efs-volume';

task.addVolume({
  name: volumeName,
  efsVolumeConfiguration: {
    fileSystemId: fileSystem.fileSystemId,
    transitEncryption: 'ENABLED',
    authorizationConfig:{
      accessPointId: accessPoint.accessPointId,
      iam: 'ENABLED'
    }
  }
});

const container = task.addContainer('Container', {
  image: ecs.ContainerImage.fromAsset('./container'),
  portMappings: [{hostPort: 80, containerPort: 80}],
});

container.addMountPoints({
  containerPath: '/mount/data',
  sourceVolume: volumeName,
  readOnly: false
});

task.addToTaskRolePolicy(
  new iam.PolicyStatement({
    actions: [
      'elasticfilesystem:ClientRootAccess',
      'elasticfilesystem:ClientWrite',
      'elasticfilesystem:ClientMount',
      'elasticfilesystem:DescribeMountTargets'
    ],
    resources: [`arn:aws:elasticfilesystem:${region}:${account}:file-system/${fileSystem.fileSystemId}`]
  })
);

task.addToTaskRolePolicy(
  new iam.PolicyStatement({
    actions: ['ec2:DescribeAvailabilityZones'],
    resources: ['*']
  })
);


나는 이것이 누군가의 두통을 덜어주기를 바랍니다!

Originally posted on my blog

좋은 웹페이지 즐겨찾기