all for lab4

This commit is contained in:
2026-11-08 18:17:48 +03:00
parent c1bd817abf
commit fc22dcc4a4
72 changed files with 12880 additions and 102 deletions
+41
View File
@@ -0,0 +1,41 @@
FROM golang:1.24.2-bookworm AS builder
ENV CGO_ENABLED=0
WORKDIR /src
RUN git clone --depth 1 \
--branch RELEASE.2025-04-22T22-12-26Z \
https://github.com/minio/minio.git /src/minio
WORKDIR /src/minio
RUN go build -trimpath -o /out/minio .
WORKDIR /src
RUN git clone --depth 1 \
--branch RELEASE.2025-04-16T18-13-26Z \
https://github.com/minio/mc.git /src/mc
WORKDIR /src/mc
RUN go build -trimpath -o /out/mc .
FROM debian:bookworm-slim
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates curl \
&& rm -rf /var/lib/apt/lists/*
COPY --from=builder /out/minio /usr/local/bin/minio
COPY --from=builder /out/mc /usr/local/bin/mc
RUN mkdir -p /data
EXPOSE 9000 9001
ENTRYPOINT ["minio"]
CMD ["server", "/data", "--console-address", ":9001"]
+93
View File
@@ -0,0 +1,93 @@
#!/bin/sh
set -eu
: "${MINIO_ROOT_USER:?}"
: "${MINIO_ROOT_PASSWORD:?}"
: "${S3_BUCKET:?}"
: "${S3_ACCESS_KEY:?}"
: "${S3_SECRET_KEY:?}"
if [ "$S3_ACCESS_KEY" = "$MINIO_ROOT_USER" ]; then
echo "API must use a separate MinIO user" >&2
exit 1
fi
if [ "$S3_SECRET_KEY" = "$MINIO_ROOT_PASSWORD" ]; then
echo "API and administrator passwords must differ" >&2
exit 1
fi
case "$S3_BUCKET" in
""|*[!a-z0-9.-]*)
echo "Invalid bucket name" >&2
exit 1
;;
esac
mc alias set storage http://minio:9000 \
"$MINIO_ROOT_USER" "$MINIO_ROOT_PASSWORD" >/dev/null
mc mb --ignore-existing "storage/$S3_BUCKET"
mc anonymous set none "storage/$S3_BUCKET"
cat > /tmp/attachments-policy.json <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "InspectAttachmentBucket",
"Effect": "Allow",
"Action": [
"s3:GetBucketLocation",
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::$S3_BUCKET"
]
},
{
"Sid": "ManageOriginalAttachments",
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:PutObject",
"s3:DeleteObject",
"s3:AbortMultipartUpload",
"s3:ListMultipartUploadParts"
],
"Resource": [
"arn:aws:s3:::$S3_BUCKET/originals/*"
]
}
]
}
EOF
POLICY_NAME=messenger-attachments-api
mc admin policy create \
storage "$POLICY_NAME" /tmp/attachments-policy.json
mc admin user add \
storage "$S3_ACCESS_KEY" "$S3_SECRET_KEY" >/dev/null
mc admin user info --json \
storage "$S3_ACCESS_KEY" > /tmp/api-user.json
if grep -Eq \
'"policyName"[[:space:]]*:[[:space:]]*"messenger-attachments-api"' \
/tmp/api-user.json
then
echo "API policy is already attached"
else
mc admin policy attach \
storage "$POLICY_NAME" --user "$S3_ACCESS_KEY"
fi
mc alias set app http://minio:9000 \
"$S3_ACCESS_KEY" "$S3_SECRET_KEY" >/dev/null
mc stat "app/$S3_BUCKET" >/dev/null
echo "Bootstrap completed: private bucket and API user are ready"
+98
View File
@@ -0,0 +1,98 @@
#!/bin/sh
set -eu
: "${S3_BUCKET:?}"
: "${S3_ACCESS_KEY:?}"
: "${S3_SECRET_KEY:?}"
mc alias set app http://minio:9000 \
"$S3_ACCESS_KEY" "$S3_SECRET_KEY" >/dev/null
TEST_ID="$(cat /proc/sys/kernel/random/uuid)"
OBJECT_KEY="originals/access-check-$TEST_ID.txt"
OUTSIDE_KEY="outside-access-check-$TEST_ID.txt"
cleanup() {
mc rm --force \
"app/$S3_BUCKET/$OBJECT_KEY" >/dev/null 2>&1 || true
mc rm --force \
"app/$S3_BUCKET/$OUTSIDE_KEY" >/dev/null 2>&1 || true
}
trap cleanup EXIT
printf 'private attachment test' > /tmp/expected.txt
mc cp /tmp/expected.txt \
"app/$S3_BUCKET/$OBJECT_KEY" >/dev/null
mc cat "app/$S3_BUCKET/$OBJECT_KEY" > /tmp/actual.txt
cmp /tmp/expected.txt /tmp/actual.txt
echo "PASS: API credentials can upload and download originals"
HTTP_CODE="$(
curl --silent --show-error \
--connect-timeout 3 \
--max-time 10 \
--output /tmp/anonymous-response.xml \
--write-out '%{http_code}' \
"http://minio:9000/$S3_BUCKET/$OBJECT_KEY"
)"
if [ "$HTTP_CODE" != "403" ]; then
echo "FAIL: anonymous GET returned HTTP $HTTP_CODE" >&2
exit 1
fi
if ! grep -q '<Code>AccessDenied</Code>' \
/tmp/anonymous-response.xml
then
echo "FAIL: expected S3 AccessDenied response" >&2
exit 1
fi
echo "PASS: anonymous download of an existing object is denied"
if mc cp /tmp/expected.txt \
"app/$S3_BUCKET/$OUTSIDE_KEY" \
> /tmp/outside-result.txt 2>&1
then
echo "FAIL: API credentials can write outside originals/" >&2
exit 1
fi
if ! grep -Eiq \
'AccessDenied|Access Denied|Insufficient permissions|not authorized|not allowed' \
/tmp/outside-result.txt
then
echo "FAIL: write failed for a reason other than access denial" >&2
cat /tmp/outside-result.txt >&2
exit 1
fi
echo "PASS: writing outside originals/ is denied"
if mc admin info app > /tmp/admin-result.txt 2>&1
then
echo "FAIL: API credentials have administrative access" >&2
exit 1
fi
if ! grep -Eiq \
'AccessDenied|Access Denied|Insufficient permissions|not authorized|not allowed' \
/tmp/admin-result.txt
then
echo "FAIL: admin command failed for an unexpected reason" >&2
cat /tmp/admin-result.txt >&2
exit 1
fi
echo "PASS: administrative access is denied"
mc rm "app/$S3_BUCKET/$OBJECT_KEY" >/dev/null
echo "PASS: API credentials can delete originals for cleanup"
echo "PASS: S3 access checks completed"