ops: configure PKI and scoped OpenBao identities
This commit is contained in:
Regular → Executable
+101
-12
@@ -2,35 +2,124 @@
|
||||
|
||||
set -eu
|
||||
|
||||
alias_name=bootstrap
|
||||
policy_name=messenger-attachments
|
||||
policy_file=/tmp/messenger-attachments-policy.json
|
||||
: "${MINIO_ROOT_USER:?MINIO_ROOT_USER is required}"
|
||||
: "${MINIO_ROOT_PASSWORD:?MINIO_ROOT_PASSWORD is required}"
|
||||
: "${S3_BUCKET:?S3_BUCKET is required}"
|
||||
: "${S3_API_ACCESS_KEY:?S3_API_ACCESS_KEY is required}"
|
||||
: "${S3_API_SECRET_KEY:?S3_API_SECRET_KEY is required}"
|
||||
: "${S3_WORKER_ACCESS_KEY:?S3_WORKER_ACCESS_KEY is required}"
|
||||
: "${S3_WORKER_SECRET_KEY:?S3_WORKER_SECRET_KEY is required}"
|
||||
: "${S3_RECONCILER_ACCESS_KEY:?S3_RECONCILER_ACCESS_KEY is required}"
|
||||
: "${S3_RECONCILER_SECRET_KEY:?S3_RECONCILER_SECRET_KEY is required}"
|
||||
|
||||
mc alias set "$alias_name" http://s3:9000 "$MINIO_ROOT_USER" "$MINIO_ROOT_PASSWORD"
|
||||
export SSL_CERT_FILE=${SSL_CERT_FILE:-/run/security/internal-ca/ca.crt}
|
||||
|
||||
alias_name=bootstrap
|
||||
policy_dir=/tmp/minio-policies
|
||||
mkdir -p "$policy_dir"
|
||||
|
||||
mc alias set "$alias_name" https://s3:9000 "$MINIO_ROOT_USER" "$MINIO_ROOT_PASSWORD"
|
||||
mc mb --ignore-existing "$alias_name/$S3_BUCKET"
|
||||
mc anonymous set none "$alias_name/$S3_BUCKET"
|
||||
|
||||
cat >"$policy_file" <<EOF
|
||||
cat >"$policy_dir/messenger-api.json" <<EOF
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": ["s3:GetBucketLocation", "s3:ListBucket"],
|
||||
"Action": ["s3:GetBucketLocation"],
|
||||
"Resource": ["arn:aws:s3:::$S3_BUCKET"]
|
||||
},
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": ["s3:ListBucket"],
|
||||
"Resource": ["arn:aws:s3:::$S3_BUCKET"],
|
||||
"Condition": {"StringLike": {"s3:prefix": ["staging/*", "attachments/*"]}}
|
||||
},
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": ["s3:GetObject"],
|
||||
"Resource": ["arn:aws:s3:::$S3_BUCKET/attachments/*"]
|
||||
},
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": ["s3:GetObject", "s3:PutObject", "s3:DeleteObject"],
|
||||
"Resource": ["arn:aws:s3:::$S3_BUCKET/*"]
|
||||
"Resource": ["arn:aws:s3:::$S3_BUCKET/staging/*"]
|
||||
}
|
||||
]
|
||||
}
|
||||
EOF
|
||||
|
||||
mc admin policy create "$alias_name" "$policy_name" "$policy_file"
|
||||
mc admin user add "$alias_name" "$S3_ACCESS_KEY" "$S3_SECRET_KEY"
|
||||
mc admin policy attach "$alias_name" "$policy_name" --user "$S3_ACCESS_KEY"
|
||||
cat >"$policy_dir/messenger-worker.json" <<EOF
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": ["s3:GetBucketLocation"],
|
||||
"Resource": ["arn:aws:s3:::$S3_BUCKET"]
|
||||
},
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": ["s3:ListBucket"],
|
||||
"Resource": ["arn:aws:s3:::$S3_BUCKET"],
|
||||
"Condition": {"StringLike": {"s3:prefix": ["staging/*", "attachments/*"]}}
|
||||
},
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": ["s3:GetObject", "s3:DeleteObject"],
|
||||
"Resource": ["arn:aws:s3:::$S3_BUCKET/staging/*"]
|
||||
},
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": ["s3:GetObject", "s3:PutObject", "s3:DeleteObject"],
|
||||
"Resource": ["arn:aws:s3:::$S3_BUCKET/attachments/*"]
|
||||
}
|
||||
]
|
||||
}
|
||||
EOF
|
||||
|
||||
mc alias set application http://s3:9000 "$S3_ACCESS_KEY" "$S3_SECRET_KEY"
|
||||
mc ls "application/$S3_BUCKET" >/dev/null
|
||||
cat >"$policy_dir/messenger-reconciler.json" <<EOF
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": ["s3:GetBucketLocation"],
|
||||
"Resource": ["arn:aws:s3:::$S3_BUCKET"]
|
||||
},
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": ["s3:ListBucket"],
|
||||
"Resource": ["arn:aws:s3:::$S3_BUCKET"],
|
||||
"Condition": {"StringLike": {"s3:prefix": ["staging/*", "attachments/*"]}}
|
||||
},
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": ["s3:GetObject", "s3:DeleteObject"],
|
||||
"Resource": [
|
||||
"arn:aws:s3:::$S3_BUCKET/staging/*",
|
||||
"arn:aws:s3:::$S3_BUCKET/attachments/*"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
EOF
|
||||
|
||||
create_user() {
|
||||
access_key=$1
|
||||
secret_key=$2
|
||||
policy=$3
|
||||
|
||||
mc admin policy create "$alias_name" "$policy" "$policy_dir/$policy.json"
|
||||
mc admin user add "$alias_name" "$access_key" "$secret_key"
|
||||
mc admin policy attach "$alias_name" "$policy" --user "$access_key"
|
||||
}
|
||||
|
||||
create_user "$S3_API_ACCESS_KEY" "$S3_API_SECRET_KEY" messenger-api
|
||||
create_user "$S3_WORKER_ACCESS_KEY" "$S3_WORKER_SECRET_KEY" messenger-worker
|
||||
create_user "$S3_RECONCILER_ACCESS_KEY" "$S3_RECONCILER_SECRET_KEY" messenger-reconciler
|
||||
|
||||
mc alias set application https://s3:9000 "$S3_API_ACCESS_KEY" "$S3_API_SECRET_KEY"
|
||||
mc ls "application/$S3_BUCKET/staging/" >/dev/null
|
||||
|
||||
Reference in New Issue
Block a user