base of lab 4

This commit is contained in:
2026-11-10 17:12:13 +03:00
parent 276dbdad8a
commit 1ec85a2402
78 changed files with 6133 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
global
log stdout format raw local0
maxconn 2048
defaults
mode http
log global
option httplog
timeout connect 1s
timeout client 12s
timeout server 10s
timeout check 1s
timeout queue 2s
retries 0
resolvers docker
nameserver docker 127.0.0.11:53
resolve_retries 3
timeout resolve 1s
timeout retry 1s
hold valid 1s
hold obsolete 1s
hold nx 1s
hold refused 1s
hold timeout 1s
frontend public
bind :8080
http-request deny if { path_beg /actuator }
default_backend api
backend api
balance roundrobin
option httpchk
http-check send meth GET uri /health/ready ver HTTP/1.1 hdr Host api
http-check expect status 200
server-template node 1-8 api:8080 check inter 1s fastinter 500ms downinter 1s fall 2 rise 2 resolvers docker resolve-prefer ipv4 init-addr libc,none
+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"