Repository navigation
Expand file tree
/
Copy pathrustfs-security-test.sh
More file actions
executable file
·1263 lines (1143 loc) · 52.7 KB
/
Copy pathrustfs-security-test.sh
File metadata and controls
executable file
·1263 lines (1143 loc) · 52.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# Copyright 2024 RustFS Team
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# rustfs-security-test.sh
# RustFS unified IAM / STS / OIDC security test suite (backlog #2024).
#
# Integrates the backlog security case matrix (IAM-102..114, SA-101..104,
# STS-101..112, OIDC-101..108) with the request flows proven by
# admin_iam_crud_test / sts_query_compat_test / oidc_keycloak_live.sh.
#
# Every case runs in three topologies, matching the other functional suites:
# 1. single-single (vm000, /data/rustfs1/mnmd)
# 2. single-multi (vm000, /data/rustfs{1...4}/mnmd)
# 3. multi-multi (vm000+vm001+vm002, 3x4)
#
# Per topology the flow is identical to the S3/KMS/Tier suites: clean the
# shared VMs, install the package, start the cluster, run the cases, tear
# the environment down, and aggregate one report for the dashboard.
#
# Usage:
# ./rustfs-security-test.sh --all-topologies -y --package-url <deb url>
# ./rustfs-security-test.sh --topology single-single -y --version 1.0.0-rc.4-preview.1
# ./rustfs-security-test.sh --all-topologies -y --oidc-live --package-url <deb url>
#
# Environment:
# RUSTFS_ACCESS_KEY / RUSTFS_SECRET_KEY admin credentials
# RUSTFS_NODES / RUSTFS_SSH_USER shared test VMs (default vm000..002 / azureuser)
# RUSTFS_API_ENDPOINT override the topology endpoint
# REPORT_FILE markdown report path (default /tmp/rustfs-security-report.md)
# LOG_FILE append suite output to this file
set -Eeuo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TEST_TMP="$(mktemp -d "${TMPDIR:-/tmp}/rustfs-security.XXXXXX")"
STS_DIAGNOSTICS_FILE="${TEST_TMP}/sts105-diagnostics.log"
KEEP_TMP=0
cleanup_tmp() {
if [ "${KEEP_TMP}" -eq 1 ]; then
echo "security suite logs retained in ${TEST_TMP}" >&2
else
rm -rf "${TEST_TMP}"
fi
}
trap cleanup_tmp EXIT
# ==================== Configuration ====================
read -r -a NODES <<< "${RUSTFS_NODES:-vm000 vm001 vm002 vm003}"
SSH_USER="${RUSTFS_SSH_USER:-azureuser}"
SSH_PORT="${RUSTFS_SSH_PORT:-22}"
SSH_OPTS=(-o BatchMode=yes -o ConnectTimeout=10 -o StrictHostKeyChecking=accept-new -p "${SSH_PORT}")
RUSTFS_VERSION="${RUSTFS_VERSION:-1.0.0-rc.4-preview.1}"
PACKAGE_URL="${PACKAGE_URL:-}"
ARCH="${RUSTFS_ARCH:-amd64}"
PACKAGES_DIR="/home/rustfs/packages"
PACKAGE_FILE="rustfs.deb"
PACKAGE_SHA256="${PACKAGE_SHA256:-}"
ACCESS_KEY="${RUSTFS_ACCESS_KEY:-rustfsadmin}"
SECRET_KEY="${RUSTFS_SECRET_KEY:-rustfsadmin}"
REGION="us-east-1"
RUSTFS_CONFIG_FILE="/etc/default/rustfs"
RUSTFS_SERVICE="rustfs"
RUSTFS_PACKAGE_NAME="rustfs"
RUSTFS_USER="rustfs"
RUSTFS_ADDRESS=":9000"
RUSTFS_CONSOLE_ADDRESS=":9001"
RUSTFS_CONSOLE_ENABLE=true
RUSTFS_OBS_LOGGER_LEVEL="${RUSTFS_OBS_LOGGER_LEVEL:-error,rustfs::admin::auth=debug}"
RUSTFS_OBS_LOG_DIRECTORY="/var/log/rustfs/"
TOPO_SINGLE_SINGLE="single-single"
TOPO_SINGLE_MULTI="single-multi"
TOPO_MULTI_MULTI="multi-multi"
# Endpoints used by the S3 clients for each topology (same as the S3 suite).
ENDPOINT_SINGLE_SINGLE="http://rustfs-node1:9000"
ENDPOINT_SINGLE_MULTI="http://rustfs-node1:9000"
ENDPOINT_MULTI_MULTI="http://rustfs-node1:9000"
# Volumes per topology (same as the S3 suite).
VOLUMES_SINGLE_SINGLE="/data/rustfs1/mnmd"
VOLUMES_SINGLE_MULTI="/data/rustfs{1...4}/mnmd"
VOLUMES_MULTI_MULTI="http://rustfs-node{1...4}:9000/data/rustfs{1...4}/mnmd"
SERVICE_TIMEOUT=300
API_ENDPOINT="${ENDPOINT_SINGLE_SINGLE}"
SIGV4_REGION="${REGION}"
SIGV4_SERVICE="s3"
API_REQUEST_TIMEOUT=120
ADMIN_API_CODE_FILE="${TEST_TMP}/api-code"
REPORT_FILE="${REPORT_FILE:-/tmp/rustfs-security-report.md}"
LOG_FILE="${LOG_FILE:-}"
REPORT_SECTIONS_FILE="${TEST_TMP}/report-sections.md"
RUSTFS_VERSION_INFO=""
# ==================== Runtime options ====================
DRY_RUN=0
ASSUME_YES=0
KEEP_ENV=0
OIDC_LIVE=0
OIDC_RUN=0
SELECTED_TOPOLOGIES=()
ENDPOINT=""
VOLUMES=""
VALIDATION_CASE=""
VALIDATION_SOURCE_CASE_ID=""
SELECTED_CASES=""
VALIDATION_ARTIFACTS_DIR=""
VALIDATION_CANDIDATE_MANIFEST=""
VALIDATION_TESTING_COMMIT=""
VALIDATION_BINARY_SHA256=""
VALIDATION_OBJECT_CLEANUP_STATUS=PASS
RUN_TOKEN=""
# ==================== Helpers ====================
log() { printf '\033[1;36m[INFO]\033[0m %s\n' "$*"; }
warn() { printf '\033[1;33m[WARN]\033[0m %s\n' "$*"; }
die() { printf '\033[1;31m[ERROR]\033[0m %s\n' "$*" >&2; exit 1; }
confirm() {
[ "${ASSUME_YES}" -eq 1 ] && return 0
printf '\033[1;33m[CONFIRM]\033[0m %s (y/N) ' "$1"
read -r answer
case "${answer}" in y|Y|yes|YES) return 0 ;; *) die "cancelled" ;; esac
}
need_cmd() {
[ "${DRY_RUN}" -eq 1 ] && return 0
command -v "$1" >/dev/null 2>&1 || die "missing command: $1 ($2); install it first"
}
build_package_url() {
local tag="${RUSTFS_VERSION#v}" asset
asset="${tag//-/.}"
printf 'https://github.com/rustfs/rustfs/releases/download/%s/rustfs_%s_%s.deb' "${tag}" "${asset}" "${ARCH}"
}
resolve_package_url() {
if [ -n "${PACKAGE_URL}" ]; then printf '%s' "${PACKAGE_URL}";
else build_package_url; fi
}
run_remote() {
local node="$1" script
script="$(cat)"
if [ "${DRY_RUN}" -eq 1 ]; then
log "DRY-RUN: ssh ${SSH_USER}@${node} <<'REMOTE'"
printf '%s\n' "${script}" | sed 's/^/ | /'
return 0
fi
ssh "${SSH_OPTS[@]}" "${SSH_USER}@${node}" 'bash -s' <<<"${script}"
}
service_action() {
local action="$1" node="$2"
log "${node}: systemctl ${action} ${RUSTFS_SERVICE}"
[ "${DRY_RUN}" -eq 1 ] && return 0
ssh "${SSH_OPTS[@]}" "${SSH_USER}@${node}" \
"if [ \"\$(id -u)\" -ne 0 ]; then sudo -n systemctl ${action} ${RUSTFS_SERVICE}; else systemctl ${action} ${RUSTFS_SERVICE}; fi" \
|| die "${node}: systemctl ${action} failed"
}
wait_service_active() {
local node="$1" waited=0
[ "${DRY_RUN}" -eq 1 ] && return 0
while [ "${waited}" -lt "${SERVICE_TIMEOUT}" ]; do
if ssh "${SSH_OPTS[@]}" "${SSH_USER}@${node}" "systemctl is-active --quiet ${RUSTFS_SERVICE}" 2>/dev/null; then
log "${node}: ${RUSTFS_SERVICE} is active"; return 0
fi
sleep 5; waited=$((waited+5))
done
die "${node}: timed out waiting for ${RUSTFS_SERVICE} (${SERVICE_TIMEOUT}s)"
}
start_and_wait_nodes() {
local nodes=("$@") pids=() i=0 fail=0
for node in "${nodes[@]}"; do service_action start "${node}" & pids[$i]=$!; i=$((i+1)); done
if [ "${#pids[@]}" -gt 0 ]; then
for pid in "${pids[@]}"; do wait "${pid}" || fail=1; done
fi
[ "${fail}" -eq 0 ] || die "systemctl start failed on one or more nodes"
for node in "${nodes[@]}"; do wait_service_active "${node}"; done
}
cleanup_node() {
local node="$1"
log "cleanup: purge ${RUSTFS_PACKAGE_NAME} and remove data dirs on ${node}"
{
printf 'set -euo pipefail\n'
printf 'SUDO=""; [ "$(id -u)" -ne 0 ] && SUDO="sudo -n"\n'
printf '${SUDO} systemctl stop %s 2>/dev/null || true\n' "${RUSTFS_SERVICE}"
printf 'if ${SUDO} dpkg -l %s 2>/dev/null | grep -q "^ii"; then ${SUDO} dpkg -P %s; fi\n' "${RUSTFS_PACKAGE_NAME}" "${RUSTFS_PACKAGE_NAME}"
printf 'for i in 1 2 3 4; do ${SUDO} rm -rf /data/rustfs${i}/mnmd; done\n'
printf '${SUDO} rm -rf /var/log/rustfs /var/lib/rustfs/kms\n'
} | run_remote "${node}"
}
volume_dirs() {
local volumes="$1" expr path prefix suffix i start end
for expr in ${volumes}; do
path="${expr#*://}"; path="${path#*/}"; path="/${path}"
if [[ "${path}" =~ \{([0-9]+)\.\.\.([0-9]+)\} ]]; then
start="${BASH_REMATCH[1]}"; end="${BASH_REMATCH[2]}"
prefix="${path%%\{*}"; suffix="${path#*\}}"
for ((i=start; i<=end; i++)); do printf '%s%s%s\n' "${prefix}" "${i}" "${suffix}"; done
else
printf '%s\n' "${path}"
fi
done
}
ensure_volume_dirs() {
local node="$1" volumes="$2" dirs=() d
while IFS= read -r d; do dirs+=("${d}"); done < <(volume_dirs "${volumes}" | sort -u)
log "${node}: ensuring data dirs (${dirs[*]})"
{
printf 'set -euo pipefail\n'
printf 'SUDO=""; [ "$(id -u)" -ne 0 ] && SUDO="sudo -n"\n'
printf 'id -u %s >/dev/null 2>&1 || ${SUDO} useradd -r -s /bin/false -d /opt/%s %s\n' "${RUSTFS_USER}" "${RUSTFS_USER}" "${RUSTFS_USER}"
for d in "${dirs[@]}"; do
printf '${SUDO} mkdir -p %s\n' "${d}"
printf '${SUDO} chown -R %s:%s %s\n' "${RUSTFS_USER}" "${RUSTFS_USER}" "${d}"
done
printf '${SUDO} mkdir -p /var/lib/rustfs/kms\n'
printf '${SUDO} chown -R %s:%s /var/lib/rustfs/kms\n' "${RUSTFS_USER}" "${RUSTFS_USER}"
} | run_remote "${node}"
}
rustfs_config_body() {
local volumes="$1"
cat <<EOF
RUSTFS_ACCESS_KEY=${ACCESS_KEY}
RUSTFS_SECRET_KEY=${SECRET_KEY}
RUSTFS_VOLUMES="${volumes}"
RUSTFS_ADDRESS="${RUSTFS_ADDRESS}"
RUSTFS_CONSOLE_ADDRESS="${RUSTFS_CONSOLE_ADDRESS}"
RUSTFS_CONSOLE_ENABLE=${RUSTFS_CONSOLE_ENABLE}
RUSTFS_OBS_LOGGER_LEVEL=${RUSTFS_OBS_LOGGER_LEVEL}
RUSTFS_OBS_LOG_DIRECTORY="${RUSTFS_OBS_LOG_DIRECTORY}"
EOF
if [ "${VALIDATION_CASE}" = oidc.login-and-session ]; then
cat <<EOF
RUSTFS_OUTBOUND_ALLOW_ORIGINS=${VALIDATION_OIDC_ORIGIN}
RUSTFS_IDENTITY_OPENID_ENABLE=on
RUSTFS_IDENTITY_OPENID_CONFIG_URL=${VALIDATION_OIDC_CONFIG_URL}
RUSTFS_IDENTITY_OPENID_ISSUER=${VALIDATION_OIDC_ISSUER}
RUSTFS_IDENTITY_OPENID_CLIENT_ID=rustfs-validation
RUSTFS_IDENTITY_OPENID_CLIENT_SECRET=${VALIDATION_OIDC_CLIENT_SECRET}
RUSTFS_IDENTITY_OPENID_SCOPES=openid,profile,email
RUSTFS_IDENTITY_OPENID_ROLE_POLICY=readonly
EOF
fi
}
write_rustfs_config() {
local node="$1" volumes="$2" body
body="$(rustfs_config_body "${volumes}")"
log "${node}: writing config ${RUSTFS_CONFIG_FILE} (volumes=${volumes})"
{
printf 'set -euo pipefail\n'
printf 'SUDO=""; [ "$(id -u)" -ne 0 ] && SUDO="sudo -n"\n'
printf 'if [ -f %s ]; then ${SUDO} cp -a %s %s.bak.$(date +%%Y%%m%%d%%H%%M%%S); fi\n' "${RUSTFS_CONFIG_FILE}" "${RUSTFS_CONFIG_FILE}" "${RUSTFS_CONFIG_FILE}"
printf '%s tee %s >/dev/null <<RUSTFS_EOF\n' '${SUDO}' "${RUSTFS_CONFIG_FILE}"
printf '%s' "${body}"
printf '\nRUSTFS_EOF\n'
printf '${SUDO} systemctl daemon-reload\n'
} | run_remote "${node}"
}
resolve_topology() {
case "$1" in
"${TOPO_SINGLE_SINGLE}") ENDPOINT="${ENDPOINT_SINGLE_SINGLE}"; VOLUMES="${VOLUMES_SINGLE_SINGLE}"; return 0 ;;
"${TOPO_SINGLE_MULTI}") ENDPOINT="${ENDPOINT_SINGLE_MULTI}"; VOLUMES="${VOLUMES_SINGLE_MULTI}"; return 0 ;;
"${TOPO_MULTI_MULTI}") ENDPOINT="${ENDPOINT_MULTI_MULTI}"; VOLUMES="${VOLUMES_MULTI_MULTI}"; return 0 ;;
*) die "unknown topology: $1 (single-single|single-multi|multi-multi)" ;;
esac
}
topology_nodes() {
case "$1" in
"${TOPO_SINGLE_SINGLE}"|"${TOPO_SINGLE_MULTI}") printf '%s' "${NODES[0]}" ;;
*) printf '%s' "${NODES[*]}" ;;
esac
}
env_setup() {
local topo="$1" url script
resolve_topology "${topo}"
if [ -n "${RUSTFS_API_ENDPOINT:-}" ]; then
ENDPOINT="${RUSTFS_API_ENDPOINT}"
fi
url="$(resolve_package_url)"
read -r -a nodes <<<"$(topology_nodes "${topo}")"
log "environment setup: topology=${topo} nodes=${nodes[*]} endpoint=${ENDPOINT}"
API_ENDPOINT="${ENDPOINT}"
# Clean slate on all three nodes (even if only some are used by this topology).
for node in "${NODES[@]}"; do cleanup_node "${node}"; done
# Download + install on the nodes used by this topology.
for node in "${nodes[@]}"; do
script="$(cat <<EOF
set -euo pipefail
SUDO=""; [ "\$(id -u)" -ne 0 ] && SUDO="sudo -n"
\${SUDO} mkdir -p "${PACKAGES_DIR}"
PKG_TMP="\$(mktemp /tmp/rustfs-security-pkg.XXXXXX.deb)"
curl -fSL --retry 3 -o "\${PKG_TMP}" "${url}"
\${SUDO} install -m 0644 "\${PKG_TMP}" "${PACKAGES_DIR}/${PACKAGE_FILE}"
rm -f "\${PKG_TMP}"
if [ -n "${PACKAGE_SHA256}" ]; then
echo "${PACKAGE_SHA256} ${PACKAGES_DIR}/${PACKAGE_FILE}" | sha256sum -c - || exit 1
fi
\${SUDO} dpkg -i --force-confold "${PACKAGES_DIR}/${PACKAGE_FILE}"
\${SUDO} systemctl daemon-reload
EOF
)"
printf '%s\n' "${script}" | run_remote "${node}"
done
for node in "${nodes[@]}"; do
write_rustfs_config "${node}" "${VOLUMES}"
ensure_volume_dirs "${node}" "${VOLUMES}"
done
start_and_wait_nodes "${nodes[@]}"
if [ "${DRY_RUN}" -eq 0 ]; then
local waited=0
while [ "${waited}" -lt "${SERVICE_TIMEOUT}" ]; do
if curl -fsS --max-time 5 "${ENDPOINT}/minio/health/live" >/dev/null 2>&1; then
log "endpoint ready: ${ENDPOINT}"; break
fi
sleep 5; waited=$((waited+5))
done
[ "${waited}" -lt "${SERVICE_TIMEOUT}" ] || die "endpoint ${ENDPOINT} not ready"
export AWS_ACCESS_KEY_ID="${ACCESS_KEY}"
export AWS_SECRET_ACCESS_KEY="${SECRET_KEY}"
export AWS_DEFAULT_REGION="${REGION}"
export AWS_EC2_METADATA_DISABLED=true
fi
}
env_teardown() {
local topo="$1"
log "environment teardown: ${topo}"
for node in "${NODES[@]}"; do cleanup_node "${node}"; done
}
# ==================== Admin API (SigV4, optional JSON body) ====================
sha256_hex() { printf '%s' "$1" | openssl dgst -sha256 -hex 2>/dev/null | awk '{print $NF}'; }
hmac_sha256_hex() { printf '%s' "$2" | openssl dgst -sha256 -mac HMAC -macopt "hexkey:$1" -hex 2>/dev/null | awk '{print $NF}'; }
hex_of_ascii() { printf '%s' "$1" | od -An -vtx1 | tr -d ' \n'; }
# SigV4 URI-encode one query name or value: keep RFC 3986 unreserved
# characters, percent-encode every other byte as uppercase %XX.
sigv4_uri_encode() {
local LC_ALL=C
local s="$1" out="" i c
for (( i = 0; i < ${#s}; i++ )); do
c="${s:i:1}"
case "${c}" in
[A-Za-z0-9_.~-]) out+="${c}" ;;
*) out+="$(printf '%%%02X' "$(( $(printf '%d' "'${c}") & 255 ))")" ;;
esac
done
printf '%s' "${out}"
}
canonical_query() {
local q="$1"
[ -z "${q}" ] && return 0
# The server percent-decodes the raw query and re-encodes every pair for
# the canonical request (name and value, RFC 3986 unreserved only), and a
# valueless param (?flag) comes back as "flag=". Callers pass raw values,
# so encode here and send the same encoded string on the wire; anything
# signed verbatim (e.g. "@" in an access key, ":" in an ARN) fails with
# SignatureDoesNotMatch.
local pairs=() pair name value
IFS='&' read -r -a pairs <<< "${q}"
for pair in "${pairs[@]}"; do
[ -n "${pair}" ] || continue
name="${pair%%=*}"
if [ "${name}" = "${pair}" ]; then value=""; else value="${pair#*=}"; fi
printf '%s=%s\n' "$(sigv4_uri_encode "${name}")" "$(sigv4_uri_encode "${value}")"
done | LC_ALL=C sort | paste -sd '&' -
}
admin_api() {
local method="$1" path="$2" query="${3:-}" body="${4:-}"
local amz_date date_stamp host_port
local canonical_headers signed_headers canonical_request string_to_sign
local scope k_date k_region k_service k_signing signature auth
local url tmp headers code
if [ "${DRY_RUN}" -eq 1 ]; then
printf '200' > "${ADMIN_API_CODE_FILE}"
return 0
fi
# Callers often embed the query in the path (e.g. add-user?accessKey=x).
# Split it so the canonical request separates URI and query like the server.
local path_only="${path%%\?*}" embedded_query="${path#*\?}"
if [ "${embedded_query}" != "${path}" ]; then
if [ -n "${query}" ]; then query="${query}&${embedded_query}"; else query="${embedded_query}"; fi
path="${path_only}"
fi
# The S3-compatible admin channel accepts only the UNSIGNED-PAYLOAD signing
# form on the functional nightlies; body-hash signing is rejected.
local payload_hash="UNSIGNED-PAYLOAD"
host_port="${API_ENDPOINT#*://}"
host_port="${host_port%%/*}"
amz_date="$(date -u +%Y%m%dT%H%M%SZ)"
date_stamp="${amz_date:0:8}"
query="$(canonical_query "${query}")"
canonical_headers="host:${host_port}
x-amz-content-sha256:${payload_hash}
x-amz-date:${amz_date}
"
signed_headers="host;x-amz-content-sha256;x-amz-date"
if [ -n "${body}" ]; then
canonical_headers="content-type:application/json
${canonical_headers}"
signed_headers="content-type;${signed_headers}"
fi
canonical_request="${method}
${path}
${query}
${canonical_headers}
${signed_headers}
${payload_hash}"
scope="${date_stamp}/${SIGV4_REGION}/${SIGV4_SERVICE}/aws4_request"
string_to_sign="AWS4-HMAC-SHA256
${amz_date}
${scope}
$(sha256_hex "${canonical_request}")"
k_date="$(hmac_sha256_hex "$(hex_of_ascii "AWS4${SECRET_KEY}")" "${date_stamp}")"
k_region="$(hmac_sha256_hex "${k_date}" "${SIGV4_REGION}")"
k_service="$(hmac_sha256_hex "${k_region}" "${SIGV4_SERVICE}")"
k_signing="$(hmac_sha256_hex "${k_service}" "aws4_request")"
signature="$(hmac_sha256_hex "${k_signing}" "${string_to_sign}")"
auth="AWS4-HMAC-SHA256 Credential=${ACCESS_KEY}/${scope}, SignedHeaders=${signed_headers}, Signature=${signature}"
url="http://${host_port}${path}${query:+?${query}}"
tmp="$(mktemp)"
headers="$(mktemp)"
local curl_args=()
[ -n "${body}" ] && curl_args+=(--data-binary "${body}" -H 'Content-Type: application/json')
code="$(curl -sS --max-time "${API_REQUEST_TIMEOUT}" -o "${tmp}" -D "${headers}" -w '%{http_code}' \
-H "Host: ${host_port}" \
-H "x-amz-content-sha256: ${payload_hash}" \
-H "x-amz-date: ${amz_date}" \
-H "Authorization: ${auth}" \
${curl_args[@]+"${curl_args[@]}"} \
-X "${method}" "${url}")" || code="000"
printf '%s' "${code}" > "${ADMIN_API_CODE_FILE}"
if [ "${path}" = /rustfs/admin/v3/revoke-tokens/builtin ]; then
{
printf 'STS-105 revoke: endpoint=%s http_status=%s signed_at=%s\n' "${API_ENDPOINT}" "${code}" "${amz_date}"
printf '%s\n' '--- response headers ---'
cat "${headers}"
printf '%s\n' '--- response body ---'
cat "${tmp}"
printf '\n%s\n' '--- end revoke response ---'
} >> "${STS_DIAGNOSTICS_FILE}"
fi
cat "${tmp}"
rm -f "${tmp}" "${headers}"
}
admin_api_code() { cat "${ADMIN_API_CODE_FILE}"; }
assert_admin_ok() {
local expected="$1" context="$2"
local code
code="$(admin_api_code)"
[ "${code}" = "${expected}" ] || {
echo "admin ${context}: expected HTTP ${expected}, got ${code}" >&2
return 1
}
}
# ==================== AWS / S3 helpers ====================
aws_run() {
AWS_OUT="$(aws --endpoint-url "${ENDPOINT}" --region "${REGION}" "$@" 2>&1)"; AWS_CODE=$?
}
aws_run_as() {
# usage: aws_run_as AK SK [TOKEN] -- args...
local ak="$1" sk="$2" token=""
shift 2
if [ "${1:-}" != "--" ]; then token="$1"; shift; fi
[ "${1:-}" = "--" ] && shift
local env_args=(AWS_ACCESS_KEY_ID="${ak}" AWS_SECRET_ACCESS_KEY="${sk}" AWS_EC2_METADATA_DISABLED=true AWS_DEFAULT_REGION="${REGION}")
if [ -n "${token}" ]; then env_args+=(AWS_SESSION_TOKEN="${token}"); fi
AWS_OUT="$(env "${env_args[@]}" aws --endpoint-url "${ENDPOINT}" --region "${REGION}" "$@" 2>&1)"; AWS_CODE=$?
}
assert_aws_ok() {
[ "${AWS_CODE}" -eq 0 ] || { echo "aws failed (exit ${AWS_CODE}): $*"; echo "${AWS_OUT}"; return 1; }
}
assert_aws_fails() {
[ "${AWS_CODE}" -ne 0 ] || { echo "aws unexpectedly succeeded (exit ${AWS_CODE}): $*"; return 1; }
}
new_bucket() {
local b="$1"
aws_run s3api create-bucket --bucket "${b}"
assert_aws_ok || return 1
}
rm_bucket() {
local b="$1"
aws_run s3api delete-bucket --bucket "${b}" 2>/dev/null || true
}
# ==================== Test harness ====================
collect_sts_server_diagnostics() {
local since="$1" node
local nodes=()
read -r -a nodes <<< "$(topology_nodes "${CURRENT_TOPOLOGY}")"
for node in "${nodes[@]}"; do
printf 'STS-105 server node: %s\n' "${node}"
# Collect before the suite removes the service and its log directory.
ssh "${SSH_OPTS[@]}" -o ServerAliveInterval=5 -o ServerAliveCountMax=2 "${SSH_USER}@${node}" \
"timeout 25s bash -s -- '${since}'" <<'REMOTE' || printf 'STS-105 server logs unavailable: %s\n' "${node}"
since="${1/T/ }"
since="${since%Z} UTC"
SUDO=()
[ "$(id -u)" -eq 0 ] || SUDO=(sudo -n)
date -u +server_time=%Y-%m-%dT%H:%M:%SZ
rustfs --version
printf '%s\n' '--- rustfs journal ---'
"${SUDO[@]}" journalctl -u rustfs --since "${since}" --no-pager -o short-iso -n 200
printf '%s\n' '--- rustfs log files (recent tails) ---'
"${SUDO[@]}" bash -o pipefail -c '
find /var/log/rustfs -maxdepth 1 -type f -printf "%T@ %p\0" |
sort -z -n | tail -z -n 3 | cut -z -d " " -f 2- |
xargs -0 -r tail -v -c 65536
'
REMOTE
done
}
declare -a FAILED_TESTS=()
declare -a CASE_RESULTS=()
PASS=0
FAIL=0
SKIP=0
run_test() {
local id="$1" name="$2" fn="$3"
local out="${TEST_TMP}/${id}.out"
local started_at
if [ -n "${SELECTED_CASES:-}" ]; then
case ",${SELECTED_CASES:-}," in
*",${id},"*) ;;
*) return 0 ;;
esac
fi
if [ "${DRY_RUN}" -eq 1 ]; then
printf ' [DRY-RUN] %s %s\n' "${id}" "${name}"
CASE_RESULTS+=("${id}|${name}|PASS")
return 0
fi
if [ "${id}" = STS-105 ]; then
started_at="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
printf 'STS-105 context: topology=%s started_at=%s method=POST path=/rustfs/admin/v3/revoke-tokens/builtin\n' \
"${CURRENT_TOPOLOGY}" "${started_at}" > "${STS_DIAGNOSTICS_FILE}"
fi
printf '\n--- %s %s ---\n' "${id}" "${name}"
if "${fn}" > "${out}" 2>&1; then
PASS=$((PASS+1)); printf '\033[1;32m[PASS]\033[0m %s %s\n' "${id}" "${name}"
CASE_RESULTS+=("${id}|${name}|PASS")
else
FAIL=$((FAIL+1)); FAILED_TESTS+=("${id} ${name}")
CASE_RESULTS+=("${id}|${name}|FAIL")
printf '\033[1;31m[FAIL]\033[0m %s %s\n' "${id}" "${name}"
sed 's/^/ | /' "${out}" | tail -50
if [ "${id}" = STS-105 ]; then
collect_sts_server_diagnostics "${started_at}" >> "${STS_DIAGNOSTICS_FILE}" 2>&1
fi
fi
if [ "${id}" = STS-105 ]; then
cat "${STS_DIAGNOSTICS_FILE}"
fi
}
validation_write_evidence() {
local evidence_dir="${VALIDATION_ARTIFACTS_DIR}/evidence/${VALIDATION_CASE}"
mkdir -p "${evidence_dir}"
cp "${TEST_TMP}/${VALIDATION_SOURCE_CASE_ID:-${VALIDATION_CASE}}.out" "${evidence_dir}/test.log"
for item in validation-iam-policy.json validation-iam-observations.json; do
if [ -f "${TEST_TMP}/${item}" ]; then cp "${TEST_TMP}/${item}" "${evidence_dir}/${item}"; fi
done
}
validation_write_result() {
local verdict="$1" reason="$2" cleanup_status="$3"
local args=("${SCRIPT_DIR}/scripts/validation_result.py"
--case-id "${VALIDATION_CASE}" --profile single-1disk
--result-file "${VALIDATION_ARTIFACTS_DIR}/cases/${VALIDATION_CASE}.json"
--verdict "${verdict}" --cleanup-status "${cleanup_status}")
if [ -n "${reason}" ]; then args+=(--reason "${reason}"); fi
if [ "${verdict}" != RUNNING ]; then
args+=(--candidate-manifest "${VALIDATION_CANDIDATE_MANIFEST}"
--rc-bin "$(command -v rc)" --testing-commit "${VALIDATION_TESTING_COMMIT}"
--binary-sha256 "${VALIDATION_BINARY_SHA256}"
--evidence "evidence/${VALIDATION_CASE}/test.log")
fi
if [ "${verdict}" = PASS ] && [ "${VALIDATION_CASE}" = "iam.policy-enforcement" ]; then
args+=(--evidence "evidence/${VALIDATION_CASE}/validation-iam-policy.json"
--evidence "evidence/${VALIDATION_CASE}/validation-iam-observations.json")
fi
python3 "${args[@]}"
}
skip_test() {
local id="$1" name="$2"
SKIP=$((SKIP+1))
CASE_RESULTS+=("${id}|${name}|SKIP")
printf '\033[1;33m[SKIP]\033[0m %s %s\n' "${id}" "${name}"
}
# ==================== IAM: users / groups / policies ====================
admin_user_add() { admin_api PUT "/rustfs/admin/v3/add-user?accessKey=${1}" "" "{\"secretKey\":\"${2}\",\"status\":\"enabled\"}"; }
admin_user_remove() { admin_api DELETE "/rustfs/admin/v3/remove-user?accessKey=${1}"; }
admin_policy_add() { admin_api PUT "/rustfs/admin/v3/add-canned-policy?name=${1}" "" "${2}"; }
admin_policy_attach() { admin_api POST "/rustfs/admin/v3/idp/builtin/policy/attach" "" "{\"policies\":[\"${2}\"],\"user\":\"${1}\"}"; }
admin_policy_detach() { admin_api POST "/rustfs/admin/v3/idp/builtin/policy/detach" "" "{\"policies\":[\"${2}\"],\"user\":\"${1}\"}"; }
# IAM-101 (user CRUD lifecycle) was removed: its core assertion required the
# user-info response body to echo the access key, which was confirmed
# not-a-defect by product (rustfs/backlog#2414); the user CRUD/disappearance
# behavior is still covered by IAM-103 and the policy lifecycle by IAM-106/107.
case_iam_102_user_disable() {
local user="sec102u" secret="sec102secret" out
out="$(admin_user_add "${user}" "${secret}")"; assert_admin_ok 200 "add-user"
aws_run_as "${user}" "${secret}" -- s3 ls; assert_aws_ok "enabled user works"
out="$(admin_api PUT "/rustfs/admin/v3/set-user-status?accessKey=${user}&status=disabled")"; assert_admin_ok 200 "disable"
aws_run_as "${user}" "${secret}" -- s3 ls; assert_aws_fails "disabled user denied"
out="$(admin_api PUT "/rustfs/admin/v3/set-user-status?accessKey=${user}&status=enabled")"; assert_admin_ok 200 "enable"
aws_run_as "${user}" "${secret}" -- s3 ls; assert_aws_ok "re-enabled user works"
admin_user_remove "${user}" >/dev/null
}
case_iam_103_delete_invalidates() {
local user="sec103u" secret="sec103secret" out
out="$(admin_user_add "${user}" "${secret}")"; assert_admin_ok 200 "add-user"
aws_run_as "${user}" "${secret}" -- s3 ls; assert_aws_ok "user works before delete"
out="$(admin_user_remove "${user}")"; assert_admin_ok 200 "remove-user"
aws_run_as "${user}" "${secret}" -- s3 ls; assert_aws_fails "deleted user denied"
}
case_iam_105_readonly_boundary() {
local user="sec105u" secret="sec105secret" out
out="$(admin_user_add "${user}" "${secret}")"; assert_admin_ok 200 "add-user"
out="$(admin_policy_attach "${user}" readonly)"; assert_admin_ok 200 "attach readonly"
new_bucket sec105-bucket || return 1
aws_run_as "${user}" "${secret}" -- s3 ls s3://sec105-bucket; assert_aws_ok "readonly can list bucket"
aws_run_as "${user}" "${secret}" -- s3api put-object --bucket sec105-bucket --key hello.txt --body /etc/hostname
assert_aws_fails "readonly cannot write"
rm_bucket sec105-bucket
admin_user_remove "${user}" >/dev/null
}
case_iam_106_custom_policy_crud() {
local policy='{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["s3:GetObject"],"Resource":["arn:aws:s3:::sec106-bucket/*"]}]}'
local out
out="$(admin_policy_add sec106p "${policy}")"; assert_admin_ok 200 "add-canned-policy"
out="$(admin_api GET /rustfs/admin/v3/list-canned-policies)"; assert_admin_ok 200 "list-canned-policies"
printf '%s' "${out}" | grep -q sec106p || { echo "list missing policy"; return 1; }
out="$(admin_api GET "/rustfs/admin/v3/info-canned-policy?name=sec106p")"; assert_admin_ok 200 "info-canned-policy"
printf '%s' "${out}" | grep -q "s3:GetObject" || { echo "policy body did not round-trip"; return 1; }
out="$(admin_api DELETE "/rustfs/admin/v3/remove-canned-policy?name=sec106p")"; assert_admin_ok 200 "remove-canned-policy"
out="$(admin_api GET /rustfs/admin/v3/list-canned-policies)"; assert_admin_ok 200 "list after remove"
if printf '%s' "${out}" | grep -q sec106p; then echo "policy still listed"; return 1; fi
}
case_iam_107_attach_detach() {
local user="sec107u" secret="sec107secret"
local policy='{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["s3:ListBucket"],"Resource":["arn:aws:s3:::sec107-bucket"]}]}'
local out
out="$(admin_user_add "${user}" "${secret}")"; assert_admin_ok 200 "add-user"
out="$(admin_policy_add sec107p "${policy}")"; assert_admin_ok 200 "add policy"
new_bucket sec107-bucket || return 1
out="$(admin_policy_attach "${user}" sec107p)"; assert_admin_ok 200 "attach"
aws_run_as "${user}" "${secret}" -- s3 ls s3://sec107-bucket; assert_aws_ok "policy grants list"
out="$(admin_policy_detach "${user}" sec107p)"; assert_admin_ok 200 "detach"
aws_run_as "${user}" "${secret}" -- s3 ls s3://sec107-bucket; assert_aws_fails "detached user denied"
out="$(admin_policy_detach "${user}" sec107p)"; assert_admin_ok 200 "detach idempotent"
rm_bucket sec107-bucket
admin_user_remove "${user}" >/dev/null
}
case_iam_109_deny_precedence() {
local user="sec109u" secret="sec109secret"
local allow='{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["s3:ListBucket"],"Resource":["arn:aws:s3:::sec109-bucket"]}]}'
local deny='{"Version":"2012-10-17","Statement":[{"Effect":"Deny","Action":["s3:ListBucket"],"Resource":["arn:aws:s3:::sec109-bucket"]}]}'
local out
out="$(admin_user_add "${user}" "${secret}")"; assert_admin_ok 200 "add-user"
out="$(admin_policy_add sec109-allow "${allow}")"; assert_admin_ok 200 "add allow"
out="$(admin_policy_add sec109-deny "${deny}")"; assert_admin_ok 200 "add deny"
new_bucket sec109-bucket || return 1
out="$(admin_api POST /rustfs/admin/v3/idp/builtin/policy/attach "" "{\"policies\":[\"sec109-allow\",\"sec109-deny\"],\"user\":\"${user}\"}")"
assert_admin_ok 200 "attach allow+deny"
aws_run_as "${user}" "${secret}" -- s3 ls s3://sec109-bucket; assert_aws_fails "deny overrides allow"
rm_bucket sec109-bucket
admin_user_remove "${user}" >/dev/null
}
validation_iam_policy_body() {
local user="$1" secret="$2" bucket="$3" policy_name="$4" policy="$5" out
out="$(admin_user_add "${user}" "${secret}")"; assert_admin_ok 200 "add validation user" || return 1
out="$(admin_policy_add "${policy_name}" "${policy}")"; assert_admin_ok 200 "add validation policy" || return 1
out="$(admin_policy_attach "${user}" "${policy_name}")"; assert_admin_ok 200 "attach validation policy" || return 1
printf 'validation policy attached to %s\n' "${user}"
printf '%s\n' "${policy}" > "${TEST_TMP}/validation-iam-policy.json"
printf 'validation-payload-%s\n' "${RUN_TOKEN}" > "${TEST_TMP}/validation-iam-source.bin"
aws_run_as "${user}" "${secret}" -- s3api put-object --bucket "${bucket}" --key object.bin --body "${TEST_TMP}/validation-iam-source.bin"
assert_aws_ok "allowed PUT" || return 1
aws_run_as "${user}" "${secret}" -- s3api get-object --bucket "${bucket}" --key object.bin "${TEST_TMP}/validation-iam-read.bin"
assert_aws_ok "allowed GET" || return 1
cmp "${TEST_TMP}/validation-iam-source.bin" "${TEST_TMP}/validation-iam-read.bin" || return 1
aws_run_as "${user}" "${secret}" -- s3api delete-object --bucket "${bucket}" --key object.bin
assert_aws_fails "explicit deny DELETE" || return 1
[[ "${AWS_OUT}" == *AccessDenied* ]] || { echo "DELETE failure was not AccessDenied"; return 1; }
aws_run s3api get-object --bucket "${bucket}" --key object.bin "${TEST_TMP}/validation-iam-root-read.bin"
assert_aws_ok "denied DELETE preserved object" || return 1
cmp "${TEST_TMP}/validation-iam-source.bin" "${TEST_TMP}/validation-iam-root-read.bin" || return 1
jq -n --arg user "${user}" --arg bucket "${bucket}" \
--arg sha256 "$(sha256sum "${TEST_TMP}/validation-iam-source.bin" | awk '{print $1}')" \
'{principal:$user,bucket:$bucket,allowed:["PutObject","GetObject"],explicitly_denied:"DeleteObject",object_preserved:true,payload_sha256:$sha256}' \
> "${TEST_TMP}/validation-iam-observations.json"
}
test_validation_iam_policy_enforcement() {
local user="valiam-${RUN_TOKEN//-/}" secret
secret="$(openssl rand -hex 24)" || return 1
local bucket="val-iam-${RUN_TOKEN}" policy_name="valiam-${RUN_TOKEN//-/}" result=0 out
local policy
policy="$(jq -nc --arg bucket "${bucket}" '{Version:"2012-10-17",Statement:[
{Effect:"Allow",Action:["s3:PutObject","s3:GetObject"],Resource:["arn:aws:s3:::"+$bucket+"/*"]},
{Effect:"Deny",Action:["s3:DeleteObject"],Resource:["arn:aws:s3:::"+$bucket+"/*"]}
]}')"
new_bucket "${bucket}" || return 1
validation_iam_policy_body "${user}" "${secret}" "${bucket}" "${policy_name}" "${policy}" || result=$?
if [ -f "${TEST_TMP}/validation-iam-source.bin" ]; then
aws_run s3api delete-object --bucket "${bucket}" --key object.bin
[ "${AWS_CODE}" -eq 0 ] || VALIDATION_OBJECT_CLEANUP_STATUS=FAIL
fi
out="$(admin_user_remove "${user}")"
assert_admin_ok 200 "remove validation user" || VALIDATION_OBJECT_CLEANUP_STATUS=FAIL
out="$(admin_api DELETE "/rustfs/admin/v3/remove-canned-policy?name=${policy_name}")"
assert_admin_ok 200 "remove validation policy" || VALIDATION_OBJECT_CLEANUP_STATUS=FAIL
aws_run s3api delete-bucket --bucket "${bucket}"
[ "${AWS_CODE}" -eq 0 ] || VALIDATION_OBJECT_CLEANUP_STATUS=FAIL
[ "${VALIDATION_OBJECT_CLEANUP_STATUS}" = PASS ] || result=1
return "${result}"
}
case_iam_113_access_key_list_hides_secret() {
local user="sec113u" secret="sec113secret-xyz" out
out="$(admin_user_add "${user}" "${secret}")"; assert_admin_ok 200 "add-user"
out="$(admin_api GET "/rustfs/admin/v3/list-access-keys-bulk?all=true")"; assert_admin_ok 200 "list-access-keys-bulk"
if printf '%s' "${out}" | grep -q '"secretKey"'; then echo "bulk listing exposed secretKey"; return 1; fi
if printf '%s' "${out}" | grep -q "${secret}"; then echo "bulk listing exposed secret"; return 1; fi
admin_user_remove "${user}" >/dev/null
}
# ==================== Service accounts ====================
create_service_account() {
# usage: create_service_account TARGET [POLICY_JSON]; prints AK<TAB>SK
local target="$1" policy="${2:-}"
local body="{\"targetUser\":\"${target}\"}"
[ -n "${policy}" ] && body="{\"targetUser\":\"${target}\",\"policy\":${policy}}"
local out
out="$(admin_api PUT /rustfs/admin/v3/add-service-accounts "" "${body}")"
assert_admin_ok 200 "add-service-accounts"
printf '%s' "${out}" | jq -r '.credentials.accessKey + "\t" + .credentials.secretKey'
}
case_sa_101_create_and_use() {
local sa
sa="$(create_service_account "${ACCESS_KEY}")"
local sa_ak="${sa%%$'\t'*}" sa_sk="${sa#*$'\t'}"
aws_run_as "${sa_ak}" "${sa_sk}" -- s3 ls; assert_aws_ok "service account can list buckets"
admin_api DELETE "/rustfs/admin/v3/delete-service-account?accessKey=${sa_ak}" >/dev/null
}
case_sa_103_parent_boundary() {
local user="sec103p" secret="sec103secret" out
local policy='{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["s3:PutObject"],"Resource":["arn:aws:s3:::sec103p-bucket/*"]}]}'
out="$(admin_user_add "${user}" "${secret}")"; assert_admin_ok 200 "add-user"
out="$(admin_policy_attach "${user}" readonly)"; assert_admin_ok 200 "attach readonly"
new_bucket sec103p-bucket || return 1
local sa
sa="$(create_service_account "${user}" "${policy}")"
local sa_ak="${sa%%$'\t'*}" sa_sk="${sa#*$'\t'}"
aws_run_as "${sa_ak}" "${sa_sk}" -- s3api put-object --bucket sec103p-bucket --key hello.txt --body /etc/hostname
assert_aws_fails "service account cannot exceed readonly parent"
admin_api DELETE "/rustfs/admin/v3/delete-service-account?accessKey=${sa_ak}" >/dev/null
rm_bucket sec103p-bucket
admin_user_remove "${user}" >/dev/null
}
case_sa_104_delete_invalidates() {
local sa
sa="$(create_service_account "${ACCESS_KEY}")"
local sa_ak="${sa%%$'\t'*}" sa_sk="${sa#*$'\t'}"
aws_run_as "${sa_ak}" "${sa_sk}" -- s3 ls; assert_aws_ok "service account works"
local out
out="$(admin_api DELETE "/rustfs/admin/v3/delete-service-account?accessKey=${sa_ak}")"; assert_admin_ok 200 "delete-service-account"
aws_run_as "${sa_ak}" "${sa_sk}" -- s3 ls; assert_aws_fails "deleted service account denied"
}
# ==================== STS ====================
assume_role() {
# usage: assume_role [AK] [SK] [DURATION]; prints AWSAK<TAB>AWSK<TAB>TOKEN<TAB>EXPIRATION
local ak="${1:-${ACCESS_KEY}}" sk="${2:-${SECRET_KEY}}" duration="${3:-900}"
aws_run_as "${ak}" "${sk}" -- sts assume-role \
--role-arn arn:aws:iam::123456789012:role/test \
--role-session-name secsts \
--duration-seconds "${duration}"
[ "${AWS_CODE}" -eq 0 ] || return 1
printf '%s' "${AWS_OUT}" | jq -r '.Credentials.AccessKeyId + "\t" + .Credentials.SecretAccessKey + "\t" + .Credentials.SessionToken + "\t" + .Credentials.Expiration'
}
case_sts_101_assume_role() {
local creds
creds="$(assume_role)" || { echo "AssumeRole failed"; return 1; }
local sts_ak sts_sk sts_token sts_exp
IFS=$'\t' read -r sts_ak sts_sk sts_token sts_exp <<<"${creds}"
aws_run_as "${sts_ak}" "${sts_sk}" "${sts_token}" -- s3 ls; assert_aws_ok "STS credentials can list buckets"
}
case_sts_102_duration_clamp() {
local creds
creds="$(assume_role "${ACCESS_KEY}" "${SECRET_KEY}" 604800)" || { echo "AssumeRole with 7d failed"; return 1; }
local sts_ak sts_sk sts_token sts_exp
IFS=$'\t' read -r sts_ak sts_sk sts_token sts_exp <<<"${creds}"
local expiry_epoch now_epoch max_epoch
expiry_epoch="$(date -u -d "${sts_exp}" +%s)"
now_epoch="$(date -u +%s)"
max_epoch=$(( now_epoch + 12 * 3600 + 120 ))
[ "${expiry_epoch}" -le "${max_epoch}" ] || {
echo "expected DurationSeconds clamped to 12h, got expiry ${sts_exp}" >&2
return 1
}
}
case_sts_104_temp_boundary() {
local user="sec104u" secret="sec104secret" out
local policy='{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["sts:AssumeRole"],"Resource":["arn:aws:s3:::*"]},{"Effect":"Allow","Action":["s3:ListBucket"],"Resource":["arn:aws:s3:::sec104-a-bucket"]}]}'
out="$(admin_user_add "${user}" "${secret}")"; assert_admin_ok 200 "add-user"
out="$(admin_policy_add sec104p "${policy}")"; assert_admin_ok 200 "add policy"
out="$(admin_policy_attach "${user}" sec104p)"; assert_admin_ok 200 "attach"
new_bucket sec104-a-bucket || return 1
new_bucket sec104-b-bucket || return 1
local creds
creds="$(assume_role "${user}" "${secret}")" || { echo "user AssumeRole failed"; return 1; }
local sts_ak sts_sk sts_token sts_exp
IFS=$'\t' read -r sts_ak sts_sk sts_token sts_exp <<<"${creds}"
aws_run_as "${sts_ak}" "${sts_sk}" "${sts_token}" -- s3 ls s3://sec104-a-bucket; assert_aws_ok "STS creds can list allowed bucket"
aws_run_as "${sts_ak}" "${sts_sk}" "${sts_token}" -- s3api put-object --bucket sec104-b-bucket --key hello.txt --body /etc/hostname
assert_aws_fails "STS creds cannot exceed identity scope"
rm_bucket sec104-a-bucket
rm_bucket sec104-b-bucket
admin_user_remove "${user}" >/dev/null
}
case_sts_105_revoke() {
local creds
creds="$(assume_role)" || { echo "AssumeRole failed"; return 1; }
local sts_ak sts_sk sts_token sts_exp out
IFS=$'\t' read -r sts_ak sts_sk sts_token sts_exp <<<"${creds}"
aws_run_as "${sts_ak}" "${sts_sk}" "${sts_token}" -- s3 ls; assert_aws_ok "STS creds work before revoke" || return 1
out="$(admin_api POST "/rustfs/admin/v3/revoke-tokens/builtin?user=${ACCESS_KEY}&fullRevoke=true")"; assert_admin_ok 200 "revoke-tokens" || return 1
printf '%s' "${out}" | jq -e '.revoked | numbers | select(. > 0 and floor == .)' >/dev/null 2>&1 || {
echo "revoke-tokens did not report a positive revoked count" >&2
return 1
}
aws_run_as "${sts_ak}" "${sts_sk}" "${sts_token}" -- s3 ls
{
printf 'STS-105 post-revoke: aws_exit=%s\n' "${AWS_CODE}"
printf '%s\n' "${AWS_OUT}"
} >> "${STS_DIAGNOSTICS_FILE}"
assert_aws_fails "STS creds invalid after revoke" || return 1
local error_code
error_code="$(printf '%s\n' "${AWS_OUT}" | sed -n 's/.*An error occurred (\([A-Za-z]*\)) when calling.*/\1/p' | head -1)"
case "${error_code}" in
InvalidAccessKeyId|AccessDenied)
printf 'STS-105 post-revoke: aws_exit=%s error_code=%s\n' "${AWS_CODE}" "${error_code}" >> "${STS_DIAGNOSTICS_FILE}"
;;
*) echo "STS request failed without the expected credential rejection" >&2; return 1 ;;
esac
}
# Issue #9279 uses an S3-scoped SigV4 POST, rather than the AWS CLI's STS
# signer. Also verify every returned field and use the temporary credentials.
case_sts_106_root_query() {
RUSTFS_ACCESS_KEY="${ACCESS_KEY}" RUSTFS_SECRET_KEY="${SECRET_KEY}" \
python3 "${SCRIPT_DIR}/scripts/sts_root_regression.py" --endpoint "${ENDPOINT}"
}
sts_root_startup_case() {
# The installed candidate runs on loopback with private temporary data and
# credentials. The helper always stops its own process; systemd and the
# topology's root credentials/data are never changed for these cases.
local option options=()
for option in "${SSH_OPTS[@]}"; do options+=("--ssh-option=${option}"); done
python3 "${SCRIPT_DIR}/scripts/sts_root_regression.py" \
--ssh-target "${SSH_USER}@${NODES[0]}" "${options[@]}" \
--rustfs-bin /usr/bin/rustfs --case "$1"
}
case_sts_107_short_root_secret() {
sts_root_startup_case secret-4
}
case_sts_108_seven_byte_root_secret() {
sts_root_startup_case secret-7
}
case_sts_109_short_root_access_key() {
sts_root_startup_case access-2
}
case_sts_110_minimum_root_credentials() {
sts_root_startup_case minimum
}
case_sts_111_eight_byte_root_secret() {
sts_root_startup_case secret-8
}
case_sts_112_utf8_root_secret() {
sts_root_startup_case secret-8-utf8
}
# ==================== OIDC / SSO ====================
case_oidc_102_validate_rejects_bad_config() {
local body='{"provider_id":"bad","enabled":true,"display_name":"bad","config_url":"http://127.0.0.1:1/nope","client_id":"nope","scopes":["openid"]}'
local out
out="$(admin_api POST /rustfs/admin/v3/oidc/validate "" "${body}")"
[ "$(admin_api_code)" != "200" ] || { echo "validate accepted unreachable config_url"; return 1; }
}
case_oidc_108_reject_garbage_jwt() {
local expired_jwt
expired_jwt="$(python3 - <<'PY'
import base64
import json
import time
def b64(data: dict) -> str:
raw = json.dumps(data, separators=(",", ":")).encode()
return base64.urlsafe_b64encode(raw).rstrip(b"=").decode()
header = b64({"alg": "none", "typ": "JWT"})
claims = b64({"iss": "https://idp.invalid", "aud": "rustfs", "exp": int(time.time()) - 3600})
print(f"{header}.{claims}.")
PY
)"
aws_run sts assume-role-with-web-identity \
--role-arn arn:aws:iam::123456789012:role/test \
--role-session-name sec108 \
--duration-seconds 900 \
--web-identity-token "${expired_jwt}"
assert_aws_fails "expired/garbage web identity token"