AWS IAM Policies for Yarkon

AWS IAM policies can be a complex matter. There is a lot of power and flexibility, but things can get complicated.

Use this page as a reference for some of the basic and most commonly used policies for Yarkon. You can use them as-is, or as a starting point for your own customization.

In general, the IAM policies used by Yarkon are similar when using the shared Cloud Edition or the self-hosted Enterprise and Team Editions. The one notable difference is the IAM role used to run the Yarkon service. When using the Cloud Edition, together with the Integrated Security model, you have to create that IAM role (see below for more details). The self hosted editions of Yarkon will have the role automatically created for you by the one-click CloudFormation template used to set up Yarkon, and will also set the EC2 to run under this role.

Shared Security

Basic

Use this starter policy together with the Cloud Edition and the Shared Security model. It gives all users access to all buckets, and allows all actions. It makes it good to get things going out of the gate, but after you see it in action, you’d probably want to lock things done and limit the permissions allowed to your end users.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "s3:*",
            "Resource": "arn:aws:s3:::*"
        }
    ]
}

Specific buckets

Use this policy together with the Cloud Edition and the Shared Security model. It gives all users access to two specific buckets (in this sample, they are yarkons3-finance and yarkons3-sales), and allows all actions on objects in these two buckets. This approach is good for most organizations where you want to give all users the same level of access, to a set of buckets used for documents.

The CORS permissions are required by the Admin Console in case you need to enable CORS on some or all of the buckets.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "s3:ListAllMyBuckets",
            "Resource": "arn:aws:s3:::*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:ListBucket",
                "s3:GetBucketLocation"
            ],
            "Resource": [
                "arn:aws:s3:::yarkons3-finance",
                "arn:aws:s3:::yarkons3-sales"
            ]
        },
        {
            "Effect": "Allow",
            "Action": "s3:*",
            "Resource": [
                "arn:aws:s3:::yarkons3-finance/*",
                "arn:aws:s3:::yarkons3-sales/*"
            ]
        }
    ]
}

Limited permissions

In most cases, you would not want your end users to have permissions to allow all S3 actions. The below is a sample policy limiting the user permissions over buckets and objects (documents) to the bare minimum that is required by Yarkon.

Note: you still have to enable CORS on the buckets. For the Admin Console to be able to do it, the CORS permissions must be granted. You can do it and then remove the permissions to ensure the end users cannot do it. The CORS permissions are s3:GetBucketCORS and s3:PutBucketCORS and have to be given on any bucket you’d like to update.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "s3:ListAllMyBuckets",
            "Resource": "arn:aws:s3:::*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:ListBucket",
                "s3:GetBucketLocation"
            ],
            "Resource": [
                "arn:aws:s3:::yarkons3-finance",
                "arn:aws:s3:::yarkons3-sales"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:PutObject",
                "s3:PutObjectAcl",
                "s3:GetObject",
                "s3:GetObjectAcl",
                "s3:DeleteObject",
                "s3:ListMultipartUploadParts",
                "s3:AbortMultipartUpload"
            ],
            "Resource": [
                "arn:aws:s3:::yarkons3-finance/*",
                "arn:aws:s3:::yarkons3-sales/*"
            ]
        }
    ]
}

Integrated/Federated Security

The following policies are meant to accompany a dedicated AWS user, created for the Yarkon Admin Console. See the Getting Started Guide for the details on how to use it.

Either the Integrated Security Model or the Federated Security Model allow you to set up different permissions to different users or groups. The aforementioned Yarkon Admin Console dedicated AWS user should be assigned its own IAM Role with the below permissions. Then, you grant permissions to end users using the standard IAM policies, through user and group policies (inline or attached).

IAM Role

When you set up Yarkon Enterprise Edition or Yarkon Team Edition from an AMI, the AWS IAM policy for the IAM EC2 Machine Role required is automatically set up for you, so you can focus on the group and user policies. The role policy is available here for your reference only.

Note: The SES permissions are only used by the Admin Console in case you use SES to send welcome and password reset emails. You can remove them if you are not planning to use SES to send email.

{
    "Version": "2012-10-17",
    "Statement": [{
            "Effect": "Allow",
            "Action": [
                "iam:List*",
                "iam:Get*"
            ],
            "Resource": "arn:aws:iam::<account-number>:*"
        }, {
            "Effect": "Allow",
            "Action": "s3:*",
            "Resource": "arn:aws:s3:::*"
        }, {
            "Effect": "Allow",
            "Action": "ses:SendRawEmail",
            "Resource": "*"
        }, {
            "Effect": "Allow",
            "Action": "sts:AssumeRole",
            "Resource": "arn:aws:iam::<account-number>:role/yarkons3-console-role"
        }
    ]
}

When using the Cloud Edition, you have to create this role yourself, and ensure the trust is set up correctly, as following:

{
    "Version": "2012-10-17",
    "Statement": [{
            "Effect": "Allow",
            "Action": [
                "iam:List*",
                "iam:Get*"
            ],
            "Resource": "arn:aws:iam::<account-number>:*"
        },
        {
            "Effect": "Allow",
            "Action": "s3:*",
            "Resource": "arn:aws:s3:::*"
        },
        {
            "Effect": "Allow",
            "Action": "sts:AssumeRole",
            "Resource": "arn:aws:iam::<account-number>:role/yarkons3-console-role"
        }
    ]
}

The role also requires the below Trust Policy to be set:

{
    "Version": "2012-10-17",
    "Statement": [{
            "Effect": "Allow",
            "Principal": {
                "Service": "ec2.amazonaws.com"
            },
            "Action": "sts:AssumeRole"
        },
        {
            "Sid": "",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::<account-number>:root"
            },
            "Action": "sts:AssumeRole"
        }
    ]
}

User policy

The below user policy is a sample showing how to limit access of user to a specific bucket – just rename the <bucket-name> place-holder in the policy to your bucket name. The policy can be inline or attached.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:ListBucket",
                "s3:GetBucketLocation"
            ],
            "Resource": "arn:aws:s3:::<bucket-name>"
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:PutObject",
                "s3:PutObjectAcl",
                "s3:GetObject",
                "s3:GetObjectAcl",
                "s3:DeleteObject"
            ],
            "Resource": "arn:aws:s3:::<bucket-name>/*"
        }
    ]
}

Group policy

The below group policy is a sample showing how to limit access of group members to a specific bucket – just rename the <bucket-name> place-holder in the policy to your bucket name. The policy can be inline or attached.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:ListBucket",
                "s3:GetBucketLocation"
            ],
            "Resource": "arn:aws:s3:::<bucket-name>"
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:PutObject",
                "s3:PutObjectAcl",
                "s3:GetObject",
                "s3:GetObjectAcl",
                "s3:DeleteObject"
            ],
            "Resource": "arn:aws:s3:::<bucket-name>/*"
        }
    ]
}

Folder level permissions

AWS IAM allows great flexibility. The following annotated example policy shows how to create a policy that allows a user full access to a specific folder only, while disallowing any access, not even listing, of any other folder. In this case, the folder was named based on the user name, and is placed in a shared home folder.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AllowUserToSeeHomeBucket",
            "Action": [
                "s3:GetBucketLocation"
            ],
            "Effect": "Allow",
            "Resource": [
                "arn:aws:s3:::<bucket-name>"
            ]
        },
        {
            "Sid": "AllowSeeingUserFolder",
            "Action": "s3:ListBucket",
            "Effect": "Allow",
            "Resource": "arn:aws:s3:::<bucket-name>",
            "Condition": {
                "StringEquals": {
                    "s3:prefix": "home/john/",
                    "s3:delimiter": [
                        "/"
                    ]
                }
            }
        },
        {
            "Sid": "AllowListingOfUserFolder",
            "Action": [
                "s3:ListBucket"
            ],
            "Effect": "Allow",
            "Resource": [
                "arn:aws:s3:::<bucket-name>"
            ],
            "Condition": {
                "StringLike": {
                    "s3:prefix": [
                        "home/john/*"
                    ]
                }
            }
        },
        {
            "Sid": "AllowAllS3ActionsInUserFolder",
            "Effect": "Allow",
            "Action": [
                "s3:*"
            ],
            "Resource": [
                "arn:aws:s3:::<bucket-name>/home/john/*"
            ]
        }
    ]
}

Yarkon respects the standard AWS substitution for a user name ${aws:username}, so it you have AWS user names defined for the users, you can use a single policy to handle all users.

Shared bucket for B2B

version 2.8.3+

Suppose you are using Yarkon for your business and your end users work for vendors that are clients of yours. You want to have all your vendors using a single bucket named acme-vendors, with each having their own folder in it, but without allowing one vendor to see, or even know, about any other vendor.

While completely fulfilling this requirement is actually not possible with IAM, it is definitely possible with Yarkon, thanks to the extra policy processing handled by the Yarkon server. To illustrate how this would be done, consider the following sample structure:

  • acme-vendors (bucket)
    • acme-vendor-east (folder)
      • CT (folder)
      • NJ (folder)
      • NY (folder)
    • acme-vendor-central (folder)
      • CO (folder)
      • KY (folder)
      • TX (folder)
    • acme-vendor-west (folder)
      • CA (folder)
      • OR (folder)
      • WA (folder)

And suppose you need the following roles defined:

  • An administrator user to manage all vendors, with full access to all folders.
  • An administrator user for each vendor, with full access to the vendor folder and its sub-folders.
  • An end user for each vendor, with limited read only access to the vendor folder and its sub-folders.

The following policies will get the job done (shown for acme-vendor-east only, it is similar for the others).

The policy for the system administrator:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AllowUserToSeeLocationOfBucket",
            "Action": [
                "s3:GetBucketLocation"
            ],
            "Effect": "Allow",
            "Resource": [
                "arn:aws:s3:::acme-vendors"
            ]
        },
        {
            "Action": "s3:ListBucket",
            "Effect": "Allow",
            "Resource": "arn:aws:s3:::acme-vendors"
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:*"
            ],
            "Resource": [
                "arn:aws:s3:::acme-vendors/*"
            ]
        }
    ]
}

The policy for the vendor’s administrator:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AllowUserToSeeLocationOfBucket",
            "Action": [
                "s3:GetBucketLocation"
            ],
            "Effect": "Allow",
            "Resource": [
                "arn:aws:s3:::acme-vendors"
            ]
        },
        {
            "Sid": "AllowRootAndHomeListingOfVendorsBucket",
            "Action": "s3:ListBucket",
            "Effect": "Allow",
            "Resource": "arn:aws:s3:::acme-vendors",
            "Condition": {
                "StringEquals": {
                    "s3:prefix": "acme-vendor-east/",
                    "s3:delimiter": [
                        "/"
                    ]
                }
            }
        },
        {
            "Sid": "AllowListingOfUserFolder",
            "Action": [
                "s3:ListBucket"
            ],
            "Effect": "Allow",
            "Resource": [
                "arn:aws:s3:::acme-vendors"
            ],
            "Condition": {
                "StringLike": {
                    "s3:prefix": [
                        "acme-vendor-east/*"
                    ]
                }
            }
        },
        {
            "Sid": "AllowAllS3ActionsInUserFolder",
            "Effect": "Allow",
            "Action": [
                "s3:*"
            ],
            "Resource": [
                "arn:aws:s3:::acme-vendors/acme-vendor-east/*"
            ]
        }
    ]
}

The policy for the vendor’s end user:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AllowUserToSeeLocationOfBucket",
            "Action": [
                "s3:GetBucketLocation"
            ],
            "Effect": "Allow",
            "Resource": [
                "arn:aws:s3:::acme-vendors"
            ]
        },
        {
            "Sid": "AllowRootAndHomeListingOfVendorsBucket",
            "Action": "s3:ListBucket",
            "Effect": "Allow",
            "Resource": "arn:aws:s3:::acme-vendors",
            "Condition": {
                "StringEquals": {
                    "s3:prefix": "acme-vendor-east/",
                    "s3:delimiter": [
                        "/"
                    ]
                }
            }
        },
        {
            "Sid": "AllowListingOfUserFolder",
            "Action": [
                "s3:ListBucket"
            ],
            "Effect": "Allow",
            "Resource": [
                "arn:aws:s3:::acme-vendors"
            ],
            "Condition": {
                "StringLike": {
                    "s3:prefix": [
                        "acme-vendor-east/*"
                    ]
                }
            }
        },
        {
            "Sid": "AllowReadOnlyS3ActionsInUserFolder",
            "Effect": "Allow",
            "Action": [
                "s3:head*",
                "s3:get*"
            ],
            "Resource": [
                "arn:aws:s3:::acme-vendors/acme-vendor-east/*"
            ]
        }
    ]
}

Note that the Yarkon Web Application, when used by an end user that belongs to this vendor, will see the folder acme-vendor-east as the root, and not the bucket.

You can use these policies as a basis for more advanced variations of this approach.