Clone
8
AWS IAM CLI
chrislusf edited this page 2025-12-14 17:29:15 -08:00

AWS IAM CLI with SeaweedFS

This guide shows how to use the AWS CLI to manage IAM users, access keys, and policies in SeaweedFS.

Installation

See AWS-CLI-with-SeaweedFS for AWS CLI installation instructions.

Prerequisites

1. Start SeaweedFS with S3/IAM

The IAM API is embedded in the S3 server by default:

# Start with embedded IAM (default)
weed s3 -filer=localhost:8888

# Or with weed server
weed server -s3

2. Create Admin Credentials

Create an admin user to manage IAM:

echo 's3.configure -apply -user admin -access_key admin_access_key -secret_key admin_secret_key -actions Admin' | weed shell

3. Configure AWS CLI

Set the endpoint to your S3 server (IAM uses the same endpoint):

export AWS_ACCESS_KEY_ID=admin_access_key
export AWS_SECRET_ACCESS_KEY=admin_secret_key

# IAM and S3 use the same endpoint
export AWS_ENDPOINT=http://localhost:8333

User Management

Create a User

aws --endpoint $AWS_ENDPOINT iam create-user --user-name bob

Output:

{
    "User": {
        "UserName": "bob"
    }
}

List Users

aws --endpoint $AWS_ENDPOINT iam list-users

Output:

{
    "Users": [
        { "UserName": "admin" },
        { "UserName": "bob" }
    ]
}

Get User Details

aws --endpoint $AWS_ENDPOINT iam get-user --user-name bob

Delete User

aws --endpoint $AWS_ENDPOINT iam delete-user --user-name bob

Enable/Disable User

Disable or re-enable a user without deleting them:

# Disable a user (all their access keys will stop working)
aws --endpoint $AWS_ENDPOINT iam set-user-status --user-name bob --status Inactive

# Re-enable the user
aws --endpoint $AWS_ENDPOINT iam set-user-status --user-name bob --status Active

Access Key Management

Create Access Key

aws --endpoint $AWS_ENDPOINT iam create-access-key --user-name bob

Output:

{
    "AccessKey": {
        "UserName": "bob",
        "AccessKeyId": "X8R439UM7OSQJX28I9QTP",
        "Status": "Active",
        "SecretAccessKey": "FLh9yeeYhzA7qsiyLIXsvuhv4g2cSgoUJJe/EqZw1z"
    }
}

List Access Keys

aws --endpoint $AWS_ENDPOINT iam list-access-keys --user-name bob

Output:

{
    "AccessKeyMetadata": [
        {
            "UserName": "bob",
            "AccessKeyId": "X8R439UM7OSQJX28I9QTP",
            "Status": "Active"
        }
    ]
}

Delete Access Key

aws --endpoint $AWS_ENDPOINT iam delete-access-key --user-name bob --access-key-id X8R439UM7OSQJX28I9QTP

Update Access Key Status

Deactivate or reactivate an access key without deleting it:

# Deactivate an access key
aws --endpoint $AWS_ENDPOINT iam update-access-key \
  --user-name bob \
  --access-key-id X8R439UM7OSQJX28I9QTP \
  --status Inactive

# Reactivate the access key
aws --endpoint $AWS_ENDPOINT iam update-access-key \
  --user-name bob \
  --access-key-id X8R439UM7OSQJX28I9QTP \
  --status Active

Self-Service: Manage Your Own Keys

Users can manage their own access keys without admin privileges:

# Set credentials for the user
export AWS_ACCESS_KEY_ID=bob_access_key
export AWS_SECRET_ACCESS_KEY=bob_secret_key

# Create a new key for yourself (no --user-name needed)
aws --endpoint $AWS_ENDPOINT iam create-access-key

# List your own keys
aws --endpoint $AWS_ENDPOINT iam list-access-keys

Policy Management

Create and Attach a Read-Only Policy

# Create policy document
cat > readonly-policy.json << 'EOF'
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "s3:Get*",
        "s3:List*"
      ],
      "Resource": [
        "arn:aws:s3:::my-bucket",
        "arn:aws:s3:::my-bucket/*"
      ]
    }
  ]
}
EOF

# Attach to user
aws --endpoint $AWS_ENDPOINT iam put-user-policy \
  --user-name bob \
  --policy-name ReadOnlyPolicy \
  --policy-document file://readonly-policy.json

Create Read-Write Policy for Specific Bucket

cat > readwrite-policy.json << 'EOF'
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "s3:Get*",
        "s3:Put*",
        "s3:Delete*",
        "s3:List*"
      ],
      "Resource": [
        "arn:aws:s3:::data-bucket",
        "arn:aws:s3:::data-bucket/*"
      ]
    }
  ]
}
EOF

aws --endpoint $AWS_ENDPOINT iam put-user-policy \
  --user-name bob \
  --policy-name DataBucketAccess \
  --policy-document file://readwrite-policy.json

Get User Policy

aws --endpoint $AWS_ENDPOINT iam get-user-policy \
  --user-name bob \
  --policy-name ReadOnlyPolicy

Delete User Policy

aws --endpoint $AWS_ENDPOINT iam delete-user-policy \
  --user-name bob \
  --policy-name ReadOnlyPolicy

Verify Configuration

Check the current S3/IAM configuration:

echo 's3.configure' | weed shell

Output:

{
  "identities": [
    {
      "name": "admin",
      "credentials": [
        {
          "accessKey": "admin_access_key",
          "secretKey": "admin_secret_key"
        }
      ],
      "actions": ["Admin"]
    },
    {
      "name": "bob",
      "credentials": [
        {
          "accessKey": "X8R439UM7OSQJX28I9QTP",
          "secretKey": "FLh9yeeYhzA7qsiyLIXsvuhv4g2cSgoUJJe/EqZw1z"
        }
      ],
      "actions": [
        "Read:my-bucket",
        "List:my-bucket"
      ]
    }
  ]
}

Complete Workflow Example

# 1. Set admin credentials
export AWS_ACCESS_KEY_ID=admin_key
export AWS_SECRET_ACCESS_KEY=admin_secret
export AWS_ENDPOINT=http://localhost:8333

# 2. Create a new user
aws --endpoint $AWS_ENDPOINT iam create-user --user-name alice

# 3. Create access key for the user
aws --endpoint $AWS_ENDPOINT iam create-access-key --user-name alice

# 4. Create a read-only policy
cat > alice-policy.json << 'EOF'
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": ["s3:Get*", "s3:List*"],
      "Resource": ["arn:aws:s3:::shared-bucket/*"]
    }
  ]
}
EOF

# 5. Attach policy to user
aws --endpoint $AWS_ENDPOINT iam put-user-policy \
  --user-name alice \
  --policy-name SharedBucketReadOnly \
  --policy-document file://alice-policy.json

# 6. Verify
echo 's3.configure' | weed shell