코드의 여백

MinIO로 버킷 관리부터 이벤트 자동화까지

by rowing0328

Intro

지난 1부에서 MinIO의 설치와 기본 구조에 대해 알아봤다.

이번에는 버킷 관리, 사용자 권한 설정, 객체 정책, 그리고 이벤트 연동 자동화를 다뤄보려 한다.

 

 

버킷 생성 및 정책 설정

 

버킷 생성

mc mb myminio/mybucket
  • myminio: 등록한 MinIO 서버 별칭
  • mybucket: 생성할 버킷 이름

 

버킷 접근 정책

버킷은 기본적으로 프라이빗이다.

퍼블릭 읽기 정책을 적용하려면 JSON 정책 파일을 작성한다.

 

  • 예시: public-read.json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": ["s3:GetBucketLocation", "s3:ListBucket"],
      "Effect": "Allow",
      "Principal": {"AWS": ["*"]},
      "Resource": ["arn:aws:s3:::mybucket"]
    },
    {
      "Action": ["s3:GetObject"],
      "Effect": "Allow",
      "Principal": {"AWS": ["*"]},
      "Resource": ["arn:aws:s3:::mybucket/*"]
    }
  ]
}

 

  • 등록 및 적용
mc admin policy add myminio public-read public-read.json
mc admin policy set myminio public-read user=testuser

 

익명 접근 허용 / 차단

# 퍼블릭 전환
mc anonymous set download myminio/mybucket

# 다시 프라이빗 전환
mc anonymous set none myminio/mybucket

 

 

IAM 사용자 및 권한 설정

 

사용자 생성

mc admin user add myminio testuser testpassword

 

정책 할당

mc admin policy set myminio readwrite user=testuser
  • 내장 정책: readonly, readwrite, writeonly

 

사용자 정보 확인

mc admin user info myminio testuser
mc admin policy list myminio

 

 

객체 버전 관리 및 라이프 사이클

 

버전 관리 활성화

mc version enable myminio/mybucket
  • 객체를 덮어쓸 때도 새 버전으로 저장
  • 삭제 시 “삭제 마커”로 처리되어 복구 가능

 

객체 라이프 사이클 정책 (자동 삭제)

 

  • JSON 파일로 설정
{
  "Rules": [
    {
      "ID": "delete-old",
      "Status": "Enabled",
      "Prefix": "",
      "Expiration": { "Days": 30 }
    }
  ]
}
mc ilm import myminio/mybucket policy.json

 

  • CLI 직접 설정
mc ilm add myminio/mybucket --expiry-days 30
mc ilm add myminio/mybucket --prefix "logs/" --expiry-days 7

 

 

객체 태깅 및 락 (WORM)

 

태깅

mc tag set myminio/mybucket/object.jpg key=value
mc tag list myminio/mybucket/object.jpg
  • 최대 10개 key-value 태그
  • 정책 기반 제어 및 검색 용도

 

객체 락 (보존 정책)

mc retention set governance 30d myminio/mybucket/myobject.jpg
  • 버전 관리 활성화 필수
  • WORM:WORM: Write Once Read Many

 

 

Webhook 기반 이벤트 자동화

 

이벤트 처리 구조

[MinIO] --(이벤트 발생)--> [Webhook 서버] --(자동 로직 실행)

 

FastAPI 기반 Webhook 서버 예시

from fastapi import FastAPI, Request

app = FastAPI()

@app.post("/minio-event")
async def minio_event_handler(request: Request):
    event = await request.json()
    print(event)  # 여기에 핸들러 로직 추가
    return {"result": "ok"}

 

MinIO 이벤트 환경변수 설정

export MINIO_NOTIFY_WEBHOOK_ENABLE_myhandler="on"
export MINIO_NOTIFY_WEBHOOK_ENDPOINT_myhandler="http://localhost:8000/minio-event"

 

이벤트 등록

mc event add myminio/mybucket arn:minio:sqs::myhandler --event put --prefix images/ --suffix .jpg
  • 특정 경로/확장자에만 이벤트 감지

 

이벤트 수정 / 삭제

# 기존 이벤트 제거
mc event remove myminio/mybucket arn:minio:sqs::myhandler

# 수정: 재등록
mc event add myminio/mybucket arn:minio:sqs::myhandler --event put --prefix new/ --suffix .png

 

이벤트 확인

mc event list myminio/mybucket

 

 

마무리

MinIO는 단순히 "S3 호환 저장소"가 아니다.

프라이빗 클라우드, 온프레미스 환경, 사내 자동화 시스템 등 다양한 곳에서 강력한 대안이 된다.

 

 

참고 자료:

MinIO Official Web Site - MinIO Client

 

MinIO Client — MinIO Object Storage for Linux

The following commands add a temporary extension to your system PATH for running the mc utility. Defer to your operating system instructions for making permanent modifications to your system PATH. Alternatively, execute mc by navigating to the parent folde

min.io

 

MinIO Official Web Site - Identity and Access Management

 

Identity and Access Management — MinIO Object Storage for Linux

Identity and Access Management Table of Contents MinIO requires the client perform both authentication and authorization for each new operation. AuthenticationThe process of verifying the identity of a connecting client. MinIO requires clients authenticate

min.io

 

MinIO Official Web Site - Monitoring Bucket and Object Events

 

Monitoring Bucket and Object Events — MinIO Object Storage for Linux

 

min.io

블로그의 정보

코드의 여백

rowing0328

활동하기