Policy examples for network access
The following examples show how to allow or deny access to EFS file systems by network path. To use these examples, replace the AWS Region, account IDs, file system IDs, IP address ranges, and principal ARNs with your own values. For descriptions of the actions and condition keys used in these examples, see Permissions for EFS Endpoints. Access through EFS Endpoints requires each client action under both the elasticfilesystem and elasticfilesystem-endpoint IAM names. The examples that grant access through EFS Endpoints therefore list each client action twice.
Example 1: Grant full access through EFS Endpoints and mount targets
The following identity policy allows a principal to mount a file system with read, write, and root access through either network path.
{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowFullAccessBothPaths", "Effect": "Allow", "Action": [ "elasticfilesystem:CreateMountSession", "elasticfilesystem:ClientMount", "elasticfilesystem:ClientWrite", "elasticfilesystem:ClientRootAccess", "elasticfilesystem-endpoint:ClientMount", "elasticfilesystem-endpoint:ClientWrite", "elasticfilesystem-endpoint:ClientRootAccess" ], "Resource": "arn:aws:elasticfilesystem:us-east-1:111122223333:file-system/fs-0123456789abcdef0" } ] }
Example 2: Grant read-only access through both network paths
The following identity policy allows a principal to mount a file system with read-only access. It omits the ClientWrite actions, so the client can't modify data.
{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowReadOnlyBothPaths", "Effect": "Allow", "Action": [ "elasticfilesystem:CreateMountSession", "elasticfilesystem:ClientMount", "elasticfilesystem-endpoint:ClientMount" ], "Resource": "arn:aws:elasticfilesystem:us-east-1:111122223333:file-system/fs-0123456789abcdef0" } ] }
Example 3: Allow a principal to connect only through EFS Endpoints
The following file system policy grants read and write access to a role, but only through EFS Endpoints. Without the condition in the first statement, the elasticfilesystem actions would also allow the role to connect through a mount target. The second statement grants the CreateMountSession action that the mount helper uses. It has no condition because the network path condition keys don't apply to that action.
{ "Version": "2012-10-17", "Statement": [ { "Sid": "EndpointOnlyAccess", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::111122223333:role/AgentSessionRole" }, "Action": [ "elasticfilesystem:ClientMount", "elasticfilesystem:ClientWrite", "elasticfilesystem-endpoint:ClientMount", "elasticfilesystem-endpoint:ClientWrite" ], "Resource": "arn:aws:elasticfilesystem:us-east-1:111122223333:file-system/fs-0123456789abcdef0", "Condition": { "Bool": { "elasticfilesystem:AccessedViaRegionalEndpoint": "true" } } }, { "Sid": "AllowMountSession", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::111122223333:role/AgentSessionRole" }, "Action": [ "elasticfilesystem:CreateMountSession" ], "Resource": "arn:aws:elasticfilesystem:us-east-1:111122223333:file-system/fs-0123456789abcdef0" } ] }
Example 4: Grant full access through mount targets and read-only access through EFS Endpoints
The following file system policy grants full access through mount targets and read-only access through EFS Endpoints. Because ClientRootAccess is granted only when AccessedViaMountTarget is true, root access isn't available through EFS Endpoints. The role that connects through EFS Endpoints also needs elasticfilesystem:CreateMountSession in its identity policy.
{ "Version": "2012-10-17", "Statement": [ { "Sid": "MountTargetFullAccess", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::111122223333:role/AppRole" }, "Action": [ "elasticfilesystem:ClientMount", "elasticfilesystem:ClientWrite", "elasticfilesystem:ClientRootAccess" ], "Resource": "arn:aws:elasticfilesystem:us-east-1:111122223333:file-system/fs-0123456789abcdef0", "Condition": { "Bool": { "elasticfilesystem:AccessedViaMountTarget": "true" } } }, { "Sid": "EndpointReadOnly", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::111122223333:role/AgentSessionRole" }, "Action": [ "elasticfilesystem:ClientMount", "elasticfilesystem-endpoint:ClientMount" ], "Resource": "arn:aws:elasticfilesystem:us-east-1:111122223333:file-system/fs-0123456789abcdef0", "Condition": { "Bool": { "elasticfilesystem:AccessedViaRegionalEndpoint": "true" } } } ] }
Example 5: Grant cross-account access through EFS Endpoints
The following file system policy allows a role in account 444455556666 to mount the file system through EFS Endpoints. The second statement allows the role to call CreateMountSession on this file system. It has no condition because the network path condition keys don't apply to that action. The role also needs an identity policy in account 444455556666 that grants the same actions on this file system.
{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowCrossAccountEndpointAccess", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::444455556666:role/AgentRuntimeRole" }, "Action": [ "elasticfilesystem:ClientMount", "elasticfilesystem:ClientWrite", "elasticfilesystem-endpoint:ClientMount", "elasticfilesystem-endpoint:ClientWrite" ], "Resource": "arn:aws:elasticfilesystem:us-east-1:111122223333:file-system/fs-0123456789abcdef0", "Condition": { "Bool": { "elasticfilesystem:AccessedViaRegionalEndpoint": "true" } } }, { "Sid": "AllowCrossAccountMountSession", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::444455556666:role/AgentRuntimeRole" }, "Action": "elasticfilesystem:CreateMountSession", "Resource": "arn:aws:elasticfilesystem:us-east-1:111122223333:file-system/fs-0123456789abcdef0" } ] }
Example 6: Allow access through EFS Endpoints only from specific IP address ranges
The following identity policy allows a principal to mount a file system through EFS Endpoints only from an IP address range that you specify, for example the public IP addresses of your NAT gateways. Replace {{public-ip-range}} with your IP address range in CIDR notation. The second statement grants mount target access in a separate statement, so the IP address condition doesn't apply to clients that connect through a mount target.
{ "Version": "2012-10-17", "Statement": [ { "Sid": "EndpointAccessFromCorporateNetwork", "Effect": "Allow", "Action": [ "elasticfilesystem:ClientMount", "elasticfilesystem:ClientWrite", "elasticfilesystem-endpoint:ClientMount", "elasticfilesystem-endpoint:ClientWrite" ], "Resource": "arn:aws:elasticfilesystem:us-east-1:111122223333:file-system/fs-0123456789abcdef0", "Condition": { "Bool": { "elasticfilesystem:AccessedViaRegionalEndpoint": "true" }, "IpAddress": { "aws:SourceIp": "{{public-ip-range}}" } } }, { "Sid": "MountTargetAccess", "Effect": "Allow", "Action": [ "elasticfilesystem:ClientMount", "elasticfilesystem:ClientWrite" ], "Resource": "arn:aws:elasticfilesystem:us-east-1:111122223333:file-system/fs-0123456789abcdef0", "Condition": { "Bool": { "elasticfilesystem:AccessedViaMountTarget": "true" } } }, { "Sid": "AllowMountSession", "Effect": "Allow", "Action": "elasticfilesystem:CreateMountSession", "Resource": "arn:aws:elasticfilesystem:us-east-1:111122223333:file-system/fs-0123456789abcdef0" } ] }
Example 7: Deny all access through EFS Endpoints
The following statement denies every action in the elasticfilesystem-endpoint IAM name. It restricts access to mount targets with one statement and no condition keys. The statement uses a wildcard so that it denies all access through EFS Endpoints, and it applies even if you later attach a broader allow policy. The client can still call CreateMountSession, but Amazon EFS rejects the connection. To also deny the CreateMountSession call, add a statement that denies elasticfilesystem:CreateMountSession. You can use this statement in a file system policy, an identity policy, or a service control policy (SCP). As an SCP, it denies access through EFS Endpoints to all EFS file systems in every account where you attach it. The following example shows it as a file system policy.
{ "Version": "2012-10-17", "Statement": [ { "Sid": "DenyEndpointAccess", "Effect": "Deny", "Principal": "*", "Action": "elasticfilesystem-endpoint:*", "Resource": "arn:aws:elasticfilesystem:us-east-1:111122223333:file-system/fs-0123456789abcdef0" } ] }
Example 8: Deny access through EFS Endpoints with a condition key
The following file system policy denies access through EFS Endpoints by using the elasticfilesystem client actions and the AccessedViaRegionalEndpoint condition key. Use this form when you manage network path controls with condition keys across your policies.
{ "Version": "2012-10-17", "Statement": [ { "Sid": "DenyAnyEndpointAccess", "Effect": "Deny", "Principal": "*", "Action": [ "elasticfilesystem:ClientMount", "elasticfilesystem:ClientWrite", "elasticfilesystem:ClientRootAccess" ], "Resource": "arn:aws:elasticfilesystem:us-east-1:111122223333:file-system/fs-0123456789abcdef0", "Condition": { "Bool": { "elasticfilesystem:AccessedViaRegionalEndpoint": "true" } } } ] }