🪣 RustFS Policy Generator

Générez des policies S3/RustFS, exportez en Terraform/CloudFormation, et testez vos accès.

Accès complet via credentials IAM. Anonymous denied.

Paramètres généraux

Utilisateur IAM

🛡️ Guardrails de sécurité

Deny statements ajoutés à la bucket policy pour renforcer la sécurité.

Exiger HTTPS (deny insecure transport)

Deny toute requête non chiffrée (HTTP) vers le bucket. Standard de sécurité minimal.

Exiger chiffrement SSE (encryption at rest)

Reject les uploads sans header d'encryption. Protège contre les objets stockés en clair.

Restreindre à un VPC Endpoint

N'autorise les accès que depuis un VPC endpoint spécifique. Empêche l'accès depuis Internet.

Restreindre à une Organization AWS

N'autorise l'accès qu'aux comptes membres d'une organization donnée.

🧪 Testeur de policy

Testez votre configuration en temps réel. Upload une image pour tester l'upload, ou vérifiez l'accès public.

Sortie

Bucket Policy

{
  "Version": "2012-10-17",
  "Statement": []
}

IAM Policy

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "ListBucketPrivate",
      "Effect": "Allow",
      "Action": [
        "s3:ListBucket",
        "s3:GetBucketLocation"
      ],
      "Resource": [
        "arn:aws:s3:::my-bucket"
      ],
      "Condition": {
        "StringLike": {
          "s3:prefix": [
            "private/*"
          ]
        }
      }
    },
    {
      "Sid": "ReadWritePrivate",
      "Effect": "Allow",
      "Action": [
        "s3:GetObject",
        "s3:PutObject",
        "s3:DeleteObject"
      ],
      "Resource": [
        "arn:aws:s3:::my-bucket/private*"
      ]
    }
  ]
}

.env

RUSTFS_ENDPOINT=http://localhost:9000
RUSTFS_REGION=us-east-1
RUSTFS_BUCKET=my-bucket
RUSTFS_PREFIX=private/
RUSTFS_ACCESS_KEY=app-user
RUSTFS_SECRET_KEY=ChangeMe-StrongSecret!

Commandes RustFS Admin

# 1) Appliquer la bucket policy
cat > /tmp/bucket-policy.json <<'EOF'
{
  "Version": "2012-10-17",
  "Statement": []
}
EOF
aws s3api put-bucket-policy --bucket my-bucket \
  --policy file:///tmp/bucket-policy.json \
  --endpoint-url http://localhost:9000

# 2) Créer l'utilisateur IAM
curl -X PUT "http://localhost:9000/rustfs/admin/v3/add-user?accessKey=app-user" \
  -H "Content-Type: application/json" \
  -d '{"secretKey": "ChangeMe-StrongSecret!", "status": "enabled"}'

# 3) Créer la politique IAM
cat > /tmp/iam-policy.json <<'EOF'
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "ListBucketPrivate",
      "Effect": "Allow",
      "Action": [
        "s3:ListBucket",
        "s3:GetBucketLocation"
      ],
      "Resource": [
        "arn:aws:s3:::my-bucket"
      ],
      "Condition": {
        "StringLike": {
          "s3:prefix": [
            "private/*"
          ]
        }
      }
    },
    {
      "Sid": "ReadWritePrivate",
      "Effect": "Allow",
      "Action": [
        "s3:GetObject",
        "s3:PutObject",
        "s3:DeleteObject"
      ],
      "Resource": [
        "arn:aws:s3:::my-bucket/private*"
      ]
    }
  ]
}
EOF
curl -X PUT "http://localhost:9000/rustfs/admin/v3/add-canned-policy?name=private-policy" \
  -H "Content-Type: application/json" \
  --data-binary @/tmp/iam-policy.json

# 4) Attacher la politique à l'utilisateur
curl -X PUT "http://localhost:9000/rustfs/admin/v3/set-user-or-group-policy?policyName=private-policy&userOrGroup=app-user&isGroup=false"

Node.js Snippet

// RUSTFS_ENDPOINT=http://localhost:9000
// RUSTFS_REGION=us-east-1
// RUSTFS_BUCKET=my-bucket
// RUSTFS_PREFIX=private/
// RUSTFS_ACCESS_KEY=app-user
// RUSTFS_SECRET_KEY=ChangeMe-StrongSecret!

import { S3Client, PutObjectCommand, GetObjectCommand, ListObjectsV2Command } from "@aws-sdk/client-s3";
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
import { Readable } from "node:stream";

const s3 = new S3Client({
  endpoint: process.env.RUSTFS_ENDPOINT,
  region: process.env.RUSTFS_REGION,
  credentials: {
    accessKeyId: process.env.RUSTFS_ACCESS_KEY,
    secretAccessKey: process.env.RUSTFS_SECRET_KEY,
  },
  forcePathStyle: true, // OBLIGATOIRE avec RustFS
});

// Upload
async function upload(key, body, contentType = "application/octet-stream") {
  const fullKey = `${process.env.RUSTFS_PREFIX}${key}`;
  await s3.send(new PutObjectCommand({
    Bucket: process.env.RUSTFS_BUCKET, Key: fullKey, Body: body, ContentType: contentType,
  }));
  return fullKey;
}

// Télécharger (privé)
async function download(key) {
  const fullKey = `${process.env.RUSTFS_PREFIX}${key}`;
  const { Body } = await s3.send(new GetObjectCommand({
    Bucket: process.env.RUSTFS_BUCKET, Key: fullKey,
  }));
  return Readable.from(Body);
}

// URL signée (partage temporaire)
async function signedUrl(key, expiresIn = 3600) {
  const fullKey = `${process.env.RUSTFS_PREFIX}${key}`;
  return getSignedUrl(s3, new GetObjectCommand({
    Bucket: process.env.RUSTFS_BUCKET, Key: fullKey,
  }), { expiresIn });
}

// Démo
await upload("doc.pdf", Buffer.from("hello"));
console.log(await signedUrl("doc.pdf"));