Выполнение lab4 на 4

This commit is contained in:
Daria0w0
2026-11-06 17:35:48 +03:00
parent 9197e151ba
commit 879463c947
89 changed files with 5551 additions and 108 deletions
+2 -2
View File
@@ -7,8 +7,8 @@ defaults
mode http
option httplog
timeout connect 1s
timeout client 15s
timeout server 12s
timeout client 65s
timeout server 65s
timeout check 1s
retries 0
+19
View File
@@ -0,0 +1,19 @@
FROM golang:1.26.3 AS server-build
ENV CGO_ENABLED=0 GOTOOLCHAIN=local
RUN git clone --depth 1 --branch RELEASE.2025-04-22T22-12-26Z https://github.com/minio/minio.git /src
WORKDIR /src
RUN go build -trimpath -o /out/minio .
FROM golang:1.26.3 AS client-build
ENV CGO_ENABLED=0 GOTOOLCHAIN=local
RUN git clone --depth 1 --branch RELEASE.2025-04-16T18-13-26Z https://github.com/minio/mc.git /src
WORKDIR /src
RUN go build -trimpath -o /out/mc .
FROM alpine:3.22.2 AS server
COPY --from=server-build /out/minio /usr/local/bin/minio
ENTRYPOINT ["minio"]
FROM alpine:3.22.2 AS client
COPY --from=client-build /out/mc /usr/local/bin/mc
ENTRYPOINT ["mc"]
+15
View File
@@ -0,0 +1,15 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["s3:GetBucketLocation", "s3:ListBucket"],
"Resource": ["arn:aws:s3:::BUCKET_NAME"]
},
{
"Effect": "Allow",
"Action": ["s3:PutObject", "s3:GetObject", "s3:DeleteObject"],
"Resource": ["arn:aws:s3:::BUCKET_NAME/attachments/*"]
}
]
}
+31
View File
@@ -0,0 +1,31 @@
#!/bin/sh
set -eu
# Do not enable shell tracing: arguments below contain credentials.
bucket="${S3_BUCKET:?S3_BUCKET is required}"
case "$bucket" in
''|*[!a-z0-9.-]*) echo 'Invalid bucket name' >&2; exit 1 ;;
esac
root_user="$(cat /run/secrets/s3_root_user)"
root_password="$(cat /run/secrets/s3_root_password)"
api_user="$(cat /run/secrets/s3_access_key_id)"
api_password="$(cat /run/secrets/s3_secret_access_key)"
# Bound startup wait to 60 attempts. Also retries if the server is not ready
# when Docker reports that its process has started.
attempt=0
until mc alias set local http://s3:9000 "$root_user" "$root_password" >/dev/null 2>&1; do
attempt=$((attempt + 1))
if [ "$attempt" -ge 60 ]; then
echo 'S3 bootstrap: server unavailable' >&2
exit 1
fi
sleep 2
done
mc mb --ignore-existing "local/$bucket" >/dev/null
mc anonymous set none "local/$bucket" >/dev/null
sed "s/BUCKET_NAME/$bucket/g" /bootstrap/api-policy.json > /tmp/api-policy.json
mc admin policy create local attachments-api /tmp/api-policy.json >/dev/null
# Reapplying with the same local credentials preserves the user identity.
mc admin user add local "$api_user" "$api_password" >/dev/null
mc admin policy attach local attachments-api --user "$api_user" >/dev/null
echo 'PASS: bucket configured private; API user policy applied.'
+35
View File
@@ -0,0 +1,35 @@
#!/bin/sh
set -eu
# Synthetic fixture only. Credentials are not printed.
bucket="${S3_BUCKET:?}"
key=attachments/infrastructure-check.txt
mc alias set api http://s3:9000 "$(cat /run/secrets/s3_access_key_id)" "$(cat /run/secrets/s3_secret_access_key)" >/dev/null 2>&1
printf 'lab4-private-storage-check\n' > /tmp/expected
if [ "${1:-check}" = seed ]; then
mc cp /tmp/expected "api/$bucket/$key" >/dev/null
echo 'PASS: API credentials can upload fixture.'
exit 0
fi
mc cat "api/$bucket/$key" > /tmp/actual
cmp /tmp/expected /tmp/actual
echo 'PASS: API credentials read original bytes after bootstrap/restart.'
# BusyBox wget makes a real unsigned HTTP request, bypassing the application.
if wget -S -O /tmp/unsigned "http://s3:9000/$bucket/$key" 2>/tmp/http-status; then
echo 'FAIL: anonymous download succeeded' >&2; exit 1
fi
grep -q '403 Forbidden' /tmp/http-status
echo 'PASS: unsigned GET of existing object returns HTTP 403.'
if mc --json cp /tmp/expected "api/$bucket/outside-api-prefix.txt" >/tmp/denied 2>&1; then
echo 'FAIL: API wrote outside permitted prefix' >&2; exit 1
fi
grep -qi 'AccessDenied\|Access Denied\|Insufficient permissions' /tmp/denied
echo 'PASS: API cannot write outside attachments prefix.'
# mc admin info can emit a JSON error while returning exit code 0.
mc --json admin info api >/tmp/denied 2>&1 || true
grep -q '"status":"error"' /tmp/denied
grep -qi 'AccessDenied\|Access Denied' /tmp/denied
echo 'PASS: API cannot access administrative server information.'
mc rm "api/$bucket/$key" >/dev/null
echo 'PASS: API can delete its test object; fixture removed.'