Managing users and IAM policies in S3

Introduction

The account root key received from Atman allows you to create IAM users yourself, generate access keys for them and grant permissions via policies. Management is carried out using the standard AWS CLI (or any AWS IAM-compatible SDK) directed at our S3 endpoint.

The master key has full permissions for all buckets and users in the account. It should be treated like an administrator password: use it only for managing users, and issue separate IAM user keys with minimal permissions to applications. The examples use anonymised names — you should replace them with your own:

Symbol in the instructions

Meaning

‘https://s3.example.com’

The S3 endpoint address provided by us

root account

AWS CLI profile with the account’s master key

app-user-01

Nazwa tworzonego użytkownika IAM

example-bucket

Bucket name

Configuring the AWS CLI

All you need is AWS CLI version 2 and a single profile with a master key. Installation instructions can be found in the AWS CLI documentation.

1. Creating a profile with a master key:

aws configure --profile konto-root
# AWS Access Key ID:     <ACCESS_KEY_ROOT>
# AWS Secret Access Key: <SECRET_KEY_ROOT>
# Default region name:   default
# Default output format: js# Default output format: json

2. Checking the connection

A list of the account’s buckets should appear (it may be empty):

aws --profile konto-root --endpoint-url https://s3.example.com s3 ls

IAM operates at the same address as S3, so every aws iam … command also requires --endpoint-url https://s3.example.com. The region is required by the CLI, but it has no bearing on how it works — you should leave it as default.

To avoid repeating the parameters, you can set variables in the following steps:

export AWS_PROFILE=konto-root
export EP=https://s3.example.com

It is also possible to add an endpoint in the ~/.aws/config file; this allows you to omit the ``–endpoint-url https://s3.example.com``` option from your commands.

[profile konto-root]

endpoint_url = https://s3.example.com

Creating a user and keys

A new user has no permissions until policies are assigned to them (see the next section).

1. Utwórzenie użytkownika:

aws --endpoint-url https://s3.example.com iam create-user --user-name app-user-01

2. Generating an access key for the user:

aws --endpoint-url https://s3.example.com iam create-access-key --user-name app-user-01

Sample answer:

{
    "AccessKey": {
        "UserName": "app-user-01",
        "AccessKeyId": "<ACCESS_KEY_ID>",
        "Status": "Active",
        "SecretAccessKey": "<SECRET_ACCESS_KEY>"
    }
}

The SecretAccessKey is displayed only once — you should save it straight away in a secure place (e.g. in a password manager or secret vault). If it is lost, you will need to generate a new key and delete the old one (see the section on rotation).

A user may hold multiple keys at the same time, which allows for key rotation without interrupting the application’s operation.

Granting authorisations

Permissions are granted via a policy in JSON format, stored in a file and attached to a user using the put-user-policy command. A single user may have several policies with different names; permissions are cumulative, and explicit Deny statements always take precedence.

aws --endpoint-url https://s3.example.com iam put-user-policy \
  --user-name app-user-01 \
  --policy-name FullAccess \
  --policy-document file://policy.json

Calling the policy again with the same name overwrites it with the new content.

Example 1: full access to S3

A user can create buckets and perform any operations on all buckets within their account.

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

Example 2: reading from just one bucket

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": ["s3:ListBucket", "s3:GetBucketLocation"],
      "Resource": "arn:aws:s3:::example-bucket"
    },
    {
      "Effect": "Allow",
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::example-bucket/*"
    }
  ]
}

Permissions for the bucket itself (e.g. listing) apply to the ARN without /*, whilst permissions for objects apply to the ARN with /*. Omitting one of these is the most common cause of the AccessDenied error.

Managed policies (optional)

Instead of using your own JSON, you can connect a ready-made managed policy:

aws --endpoint-url https://s3.example.com iam attach-user-policy \
  --user-name app-user-01 \
  --policy-arn arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccessaws:policy/AmazonS3ReadOnlyAccess

AmazonS3FullAccess and AmazonS3ReadOnlyAccess are available. Managed policies apply to all buckets in the account, so you can use your own policies to apply restrictions to specific buckets.

Verification and management

The most commonly used commands (all with the master key and --endpoint-url https://s3.example.com):

Cel

Polecenie

List of users

aws iam list-users

Klucze użytkownika

aws iam list-access-keys --user-name app-user-01

User inline policies

aws iam list-user-policies --user-name app-user-01

Policy content

aws iam get-user-policy --user-name app-user-01 --policy-name FullAccess

Connected managed policies

aws iam list-attached-user-policies --user-name app-user-01

Example:

Sprawdzenie polityk użytkownika.

aws --endpoint-url https://s3.example.com iam list-user-policies --user-name app-user-01
{
    "PolicyNames": [
        "FullAccess"
    ]
}

Deleting policies

Inline policy (added by put-user-policy):

aws --endpoint-url https://s3.example.com iam delete-user-policy \
  --user-name app-user-01 \
  --policy-name FullAccess

You can check the names of inline policies by:

aws --endpoint-url https://s3.example.com iam list-user-policies --user-name app-user-01

Managed policy (added by attach-user-policy):

aws --endpoint-url https://s3.example.com iam detach-user-policy \
  --user-name app-user-01 \
  --policy-arn arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess

You can view the connected managed policies by:

aws --endpoint-url https://s3.example.com iam list-attached-user-policies --user-name app

Key rotation and user deletion

Key rotation without any interruption in operation

  1. You need to generate a second key: aws iam create-access-key --user-name app-user-01.

  2. Change the key in the app and check that it works.

  3. Deactivate the old key (it can still be restored):

aws --endpoint-url https://s3.example.com iam update-access-key \
  --user-name app-user-01 --access-key-id <STARY_ACCESS_KEY_ID> --status Inactive
  1. After a few days, you can remove the old key without any problems:

aws --endpoint-url https://s3.example.com iam delete-access-key \
  --user-name app-user-01 --access-key-id <STARY_ACCESS_KEY_ID>

Rotation of the root key

The client can rotate the master key as follows:

  1. aws --endpoint-url https://s3.example.com iam create-access-key

  2. Receiving a new key — the old one still works.

  3. Update the root-account profile (aws configure --profile root-account) and wherever the master key is stored.

  4. [root-account-profile] endpoint_url = https://s3.example.com

  5. Deactivating the old key: aws --profile root-account --endpoint-url  https://s3.example.com  iam update-access-key --access-key-id <OLD_KEY_ID> --status Inactive

  6. Deleting an old key: aws --profile root-account --endpoint-url https://s3.example.com iam delete-access-key --access-key-id <OLD_KEY_ID>

Rotating the master key does not affect IAM user keys or the operation of the applications that use them.

Usunięcie użytkownika

A user can only be deleted once their keys and policies have been deleted:

aws --endpoint-url https://s3.example.com iam delete-access-key --user-name app-user-01 --access-key-id <ACCESS_KEY_ID>
aws --endpoint-url https://s3.example.com iam delete-user-policy --user-name app-user-01 --policy-name FullAccess
aws --endpoint-url https://s3.example.com iam detach-user-policy --user-name app-user-01 --policy-arn arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess
aws --endpoint-url https://s3.example.com iam delete-user --user-name app-user-01

Deleting a user does not delete buckets or data — these belong to the account, not to the user.

Best practice and common mistakes

Safety

  • The master key must not be used in production applications or scripts — it is for IAM management only.

  • Each application or system is assigned a separate user with minimal permissions (e.g. just one bucket or prefix).

  • Keys should be changed regularly, e.g. every 90 days, and immediately after the departure of anyone who knew them.

  • Keys should not be stored in code repositories; they can be kept in a password manager or a secret vault.

  • If you suspect that the master key has been compromised, you must generate a new one immediately.

The most common mistakes

Symptom

Cause and solution

Could not connect to the endpoint URL or the request is sent to AWS

Brak --endpoint-url https://s3.example.com w poleceniu

AccessDenied when listing a bucket

The policy only grants permissions for arn:aws:s3:::example-bucket/*; add s3:ListBucket to arn:aws:s3:::example-bucket

AccessDenied when creating a user

The command was executed using a standard user key instead of the master key

MalformedPolicyDocument

JSON syntax error — check the file, e.g. using jq . policy.json

DeleteConflict when deleting a user

If you still have any keys or policies, delete them first

LimitExceeded when creating a key

The user already has two keys — delete the one they’re not using

If you have any questions or encounter any problems, please contact our support team, providing your username, the command you ran and the full error message (without any secret keys).