Some checks failed
go: build dev binaries / cleanup (push) Successful in 4s
Codespell / Check for spelling errors (push) Failing after 3s
docker: build dev containers / build-rust-binaries (amd64, x86_64-unknown-linux-musl) (push) Failing after 3s
docker: build dev containers / build-dev-containers (push) Has been skipped
docker: build dev containers / build-rust-binaries (arm64, true, aarch64-unknown-linux-musl) (push) Failing after 3s
End to End / FUSE Mount (push) Failing after 2s
EC Integration Tests / EC Integration Tests (push) Failing after 30s
FUSE DLM Integration Tests / FUSE DLM Integration Tests (push) Failing after 3s
FUSE Volume Server Failover Tests / FUSE Volume Server Failover (push) Failing after 3s
FUSE Integration Tests / FUSE Integration Testing (push) Failing after 2s
FUSE P2P Peer Chunk Sharing Integration Tests / FUSE P2P Peer Chunk Sharing (push) Failing after 3s
go: build binary / Go Vet (push) Failing after 2s
go: build binary / Go Vet 32-bit (push) Failing after 3s
go: build binary / Build (push) Failing after 4s
go: build binary / Build cross-platform (freebsd/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (darwin/arm64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/arm64) (push) Failing after 3s
go: build binary / Test (push) Failing after 2s
go: build binary / Test 32-bit (push) Failing after 3s
helm: lint and test charts / lint-test (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (11) (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (17) (push) Failing after 3s
go: build dev binaries / build_dev_linux_windows (amd64, linux) (push) Failing after 2s
go: build dev binaries / build_dev_linux_windows (amd64, windows) (push) Failing after 3s
go: build dev binaries / build_dev_darwin (amd64, darwin) (push) Has been skipped
go: build dev binaries / build_dev_darwin (arm64, darwin) (push) Has been skipped
Java Client Unit Tests / Java Unit Tests (11) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (17) (push) Failing after 2s
Java Client Unit Tests / Java Unit Tests (21) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (8) (push) Failing after 3s
Kafka Quick Test (Load Test with Schema Registry) / Kafka Client Load Test (Quick) (push) Failing after 3s
Kafka Gateway Tests / Kafka Unit Tests (unit-tests-1) (push) Failing after 11s
Kafka Gateway Tests / Kafka Integration Tests (Critical) (integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka End-to-End Tests (with SMQ) (e2e-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Consumer Group Tests (Highly Isolated) (consumer-group-1) (push) Failing after 2s
Kafka Gateway Tests / Kafka Client Compatibility (with SMQ) (client-compat-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka SMQ Integration Tests (Full Stack) (smq-integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Protocol Tests (Isolated) (protocol-1) (push) Failing after 3s
KMS Tests / KMS Provider Integration Tests (push) Failing after 2s
KMS Tests / S3 KMS End-to-End Tests (push) Failing after 3s
Master Cold Start Tests / Master Cold Start Tests (push) Failing after 4s
Metadata Subscribe Integration Tests / Metadata Subscribe Integration Tests (push) Failing after 3s
Multi-Master Tests / Multi-Master Failover Tests (push) Failing after 3s
Performance / CPU and Heap Profile (push) Failing after 2s
Performance / S3 Read/Write Benchmark (rust volume) (push) Failing after 3s
pjdfstest POSIX Compliance / pjdfstest (push) Failing after 2s
Plugin Worker Integration Tests / Plugin Worker: erasure_coding (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: vacuum (push) Failing after 3s
Rust Volume Server Tests / Rust Integration Tests (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 1) (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 1) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 3) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Distributed Tests (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Performance Tests (push) Failing after 3s
Performance / Throughput Benchmark (go volume) (push) Failing after 3s
Performance / Throughput Benchmark (rust volume) (push) Failing after 2s
Performance / S3 Read/Write Benchmark (go volume) (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: volume_balance (push) Failing after 3s
PostgreSQL Gateway Tests / PostgreSQL Basic Tests (push) Failing after 3s
Rust Volume Server Tests / Rust Unit Tests (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 3) (push) Failing after 3s
Rust Plugin Worker Tests / Rust Plugin Worker Build and Unit Tests (push) Failing after 3s
rust: build dev volume server binaries / cleanup (push) Successful in 3s
S3 ETag and ACL Tests / S3 ETag + ACL Integration Tests (push) Failing after 3s
S3 IAM Integration Tests / IAM Unit Tests (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (advanced) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (basic) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (group) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (policy-enforcement) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (sts) (push) Failing after 4s
S3 Keycloak Integration Tests / S3 Keycloak Integration Tests (push) Failing after 3s
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.11) (push) Failing after 3s
S3 PyArrow Parquet Tests / Go Unit Tests (Implicit Directory) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.12) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-amd64, x86_64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-arm64, aarch64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-linux (linux-amd64, x86_64-unknown-linux-gnu) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.9) (push) Has been cancelled
S3 Proxy Signature Tests / S3 Proxy Signature Verification Tests (push) Has been cancelled
S3 SDK V2 Route Disambiguation Tests / S3 SDK V2 Routing Tests (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (quick) (push) Has been cancelled
S3 SSE Tests / S3 SSE Compatibility Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Metadata Persistence Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Copy Operations Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Multipart Upload Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Performance Test (push) Has been cancelled
S3 SSE Tests / S3 Volume Encryption Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (comprehensive) (push) Has been cancelled
Spark Integration Tests / Spark Integration Tests (push) Failing after 2s
Telemetry Integration Tests / telemetry-integration-test (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 1) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 1) (push) Failing after 3s
Ceph S3 tests / Basic S3 tests (KV store) (push) Has been cancelled
Ceph S3 tests / S3 Versioning & Object Lock tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Unit Tests (push) Failing after 3s
Ceph S3 tests / S3 CORS tests (push) Has been cancelled
Ceph S3 tests / SeaweedFS Custom S3 Copy tests (push) Has been cancelled
Ceph S3 tests / Basic S3 tests (SQL store) (push) Has been cancelled
test s3 over https using aws-cli / awscli-tests (push) Has been cancelled
TLS Rotation Integration Tests / TLS Rotation Integration Tests (push) Has been cancelled
Vacuum Integration Tests / Vacuum Integration Tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Variables Integration Tests (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (advanced-policy) (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (basic-policy) (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (contextual-policy) (push) Failing after 4s
S3 Policy Integration Tests / Trusted Proxy Detection Tests (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Shell Integration Tests (push) Failing after 3s
Samba on FUSE Integration / samba-integration (push) Failing after 2s
SFTP Integration Tests / SFTP Integration Testing (push) Failing after 3s
terraform: validate and test modules / fmt, validate, plan-level tests (push) Failing after 3s
terraform: validate and test modules / local cluster smoke test (real weed) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 3) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 2) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 2) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 3) (push) Failing after 5s
mount: windows conformance / WinFsp conformance (push) Has been cancelled
mount: windows / Mount on Windows (push) Has been cancelled
588 lines
17 KiB
Go
588 lines
17 KiB
Go
package sts_integration
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/seaweedfs/seaweedfs/test/testutil"
|
|
)
|
|
|
|
// TestEnvironment mirrors the one in trino_catalog_test.go but simplified
|
|
type TestEnvironment struct {
|
|
seaweedDir string
|
|
weedBinary string
|
|
dataDir string
|
|
bindIP string
|
|
s3Port int
|
|
s3GrpcPort int
|
|
masterPort int
|
|
masterGrpcPort int
|
|
filerPort int
|
|
filerGrpcPort int
|
|
volumePort int
|
|
volumeGrpcPort int
|
|
weedProcess *exec.Cmd
|
|
weedCancel context.CancelFunc
|
|
dockerAvailable bool
|
|
accessKey string
|
|
secretKey string
|
|
}
|
|
|
|
const testSTSIntegrationSigningKey = "dGVzdC1zaWduaW5nLWtleS1mb3Itc3RzLWludGVncmF0aW9uLXRlc3Rz" // gitleaks:allow - test-signing-key-for-sts-integration-tests
|
|
|
|
func TestSTSIntegration(t *testing.T) {
|
|
if testing.Short() {
|
|
t.Skip("Skipping integration test in short mode")
|
|
}
|
|
|
|
env := NewTestEnvironment(t)
|
|
defer env.Cleanup(t)
|
|
|
|
if !env.dockerAvailable {
|
|
t.Skip("Docker not available, skipping STS integration test")
|
|
}
|
|
|
|
fmt.Printf(">>> Starting SeaweedFS...\n")
|
|
env.StartSeaweedFS(t)
|
|
fmt.Printf(">>> SeaweedFS started.\n")
|
|
|
|
// Run python script in docker to test STS
|
|
runPythonSTSClient(t, env)
|
|
}
|
|
|
|
// TestSTSAssumeRoleAuthorization covers the AssumeRole authorization model:
|
|
// a non-admin caller may assume a role its trust policy admits, an explicit
|
|
// identity-side deny blocks it, and a session policy's explicit deny blocks
|
|
// role chaining.
|
|
func TestSTSAssumeRoleAuthorization(t *testing.T) {
|
|
if testing.Short() {
|
|
t.Skip("Skipping integration test in short mode")
|
|
}
|
|
|
|
env := NewTestEnvironment(t)
|
|
defer env.Cleanup(t)
|
|
|
|
if !env.dockerAvailable {
|
|
t.Skip("Docker not available, skipping STS integration test")
|
|
}
|
|
|
|
fmt.Printf(">>> Starting SeaweedFS...\n")
|
|
env.StartSeaweedFS(t)
|
|
fmt.Printf(">>> SeaweedFS started.\n")
|
|
|
|
runPythonAuthzClient(t, env)
|
|
}
|
|
|
|
func NewTestEnvironment(t *testing.T) *TestEnvironment {
|
|
t.Helper()
|
|
|
|
wd, err := os.Getwd()
|
|
if err != nil {
|
|
t.Fatalf("Failed to get working directory: %v", err)
|
|
}
|
|
|
|
seaweedDir := wd
|
|
for i := 0; i < 6; i++ {
|
|
if _, err := os.Stat(filepath.Join(seaweedDir, "go.mod")); err == nil {
|
|
break
|
|
}
|
|
seaweedDir = filepath.Dir(seaweedDir)
|
|
}
|
|
|
|
weedBinary := filepath.Join(seaweedDir, "weed", "weed")
|
|
info, err := os.Stat(weedBinary)
|
|
if err != nil || info.IsDir() {
|
|
weedBinary = "weed"
|
|
if _, err := exec.LookPath(weedBinary); err != nil {
|
|
t.Skip("weed binary not found, skipping integration test")
|
|
}
|
|
}
|
|
|
|
if !testutil.HasDocker() {
|
|
t.Skip("Docker not available, skipping integration test")
|
|
}
|
|
|
|
// Create a unique temporary directory for this test run
|
|
dataDir, err := os.MkdirTemp("", "seaweed-sts-test-*")
|
|
if err != nil {
|
|
t.Fatalf("Failed to create temp dir: %v", err)
|
|
}
|
|
// The Cleanup method will remove this directory, so no need for defer here.
|
|
|
|
bindIP := testutil.FindBindIP()
|
|
|
|
// Allocate all ports in a single batch to prevent the OS from recycling
|
|
// a released port, which can cause two services to get the same port.
|
|
ports := testutil.MustAllocatePorts(t, 8)
|
|
masterPort, masterGrpcPort := ports[0], ports[1]
|
|
volumePort, volumeGrpcPort := ports[2], ports[3]
|
|
filerPort, filerGrpcPort := ports[4], ports[5]
|
|
s3Port, s3GrpcPort := ports[6], ports[7]
|
|
|
|
return &TestEnvironment{
|
|
seaweedDir: seaweedDir,
|
|
weedBinary: weedBinary,
|
|
dataDir: dataDir,
|
|
bindIP: bindIP,
|
|
s3Port: s3Port,
|
|
s3GrpcPort: s3GrpcPort,
|
|
masterPort: masterPort,
|
|
masterGrpcPort: masterGrpcPort,
|
|
filerPort: filerPort,
|
|
filerGrpcPort: filerGrpcPort,
|
|
volumePort: volumePort,
|
|
volumeGrpcPort: volumeGrpcPort,
|
|
dockerAvailable: testutil.HasDocker(),
|
|
accessKey: "admin",
|
|
secretKey: "adminadmin",
|
|
}
|
|
}
|
|
|
|
func (env *TestEnvironment) StartSeaweedFS(t *testing.T) {
|
|
t.Helper()
|
|
|
|
iamConfigPath := filepath.Join(env.dataDir, "iam.json")
|
|
// Note: signingKey must be base64 encoded for []byte JSON unmarshaling
|
|
iamConfig := fmt.Sprintf(`{
|
|
"identities": [
|
|
{
|
|
"name": "admin",
|
|
"credentials": [
|
|
{ "accessKey": "%s", "secretKey": "%s" }
|
|
],
|
|
"actions": ["Admin", "Read", "Write", "List", "Tagging"]
|
|
},
|
|
{
|
|
"name": "nonadmin",
|
|
"credentials": [
|
|
{ "accessKey": "nonadmin_key", "secretKey": "nonadmin_secret" }
|
|
],
|
|
"actions": ["Read", "Write", "List", "Tagging"]
|
|
},
|
|
{
|
|
"name": "denied",
|
|
"credentials": [
|
|
{ "accessKey": "denied_key", "secretKey": "denied_secret" }
|
|
],
|
|
"actions": ["Read", "Write", "List", "Tagging"],
|
|
"policyNames": ["DenyAssumeRole"]
|
|
}
|
|
],
|
|
"sts": {
|
|
"tokenDuration": "1h",
|
|
"maxSessionLength": "12h",
|
|
"issuer": "seaweedfs-sts",
|
|
"signingKey": "%s"
|
|
},
|
|
"policy": {
|
|
"defaultEffect": "Deny",
|
|
"storeType": "memory"
|
|
},
|
|
"policies": [
|
|
{
|
|
"name": "S3FullAccessPolicy",
|
|
"document": {
|
|
"Version": "2012-10-17",
|
|
"Statement": [
|
|
{
|
|
"Effect": "Allow",
|
|
"Action": ["s3:*"],
|
|
"Resource": ["*"]
|
|
}
|
|
]
|
|
}
|
|
},
|
|
{
|
|
"name": "DenyAssumeRole",
|
|
"document": {
|
|
"Version": "2012-10-17",
|
|
"Statement": [
|
|
{
|
|
"Effect": "Deny",
|
|
"Action": ["sts:AssumeRole"],
|
|
"Resource": ["*"]
|
|
}
|
|
]
|
|
}
|
|
}
|
|
],
|
|
"roles": [
|
|
{
|
|
"roleName": "TestRole",
|
|
"roleArn": "arn:aws:iam::role/TestRole",
|
|
"attachedPolicies": ["S3FullAccessPolicy"],
|
|
"trustPolicy": {
|
|
"Version": "2012-10-17",
|
|
"Statement": [
|
|
{
|
|
"Effect": "Allow",
|
|
"Principal": "*",
|
|
"Action": ["sts:AssumeRole"]
|
|
}
|
|
]
|
|
}
|
|
}
|
|
]
|
|
}`, env.accessKey, env.secretKey, testSTSIntegrationSigningKey)
|
|
if err := os.WriteFile(iamConfigPath, []byte(iamConfig), 0644); err != nil {
|
|
t.Fatalf("Failed to create IAM config: %v", err)
|
|
}
|
|
|
|
// Create empty security.toml
|
|
securityToml := filepath.Join(env.dataDir, "security.toml")
|
|
if err := os.WriteFile(securityToml, []byte("# Empty security config for testing\n"), 0644); err != nil {
|
|
t.Fatalf("Failed to create security.toml: %v", err)
|
|
}
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
env.weedCancel = cancel
|
|
|
|
cmd := exec.CommandContext(ctx, env.weedBinary, "mini",
|
|
"-master.port", fmt.Sprintf("%d", env.masterPort),
|
|
"-master.port.grpc", fmt.Sprintf("%d", env.masterGrpcPort),
|
|
"-volume.port", fmt.Sprintf("%d", env.volumePort),
|
|
"-volume.port.grpc", fmt.Sprintf("%d", env.volumeGrpcPort),
|
|
"-filer.port", fmt.Sprintf("%d", env.filerPort),
|
|
"-filer.port.grpc", fmt.Sprintf("%d", env.filerGrpcPort),
|
|
"-s3.port", fmt.Sprintf("%d", env.s3Port),
|
|
"-s3.port.grpc", fmt.Sprintf("%d", env.s3GrpcPort),
|
|
"-s3.config", iamConfigPath,
|
|
"-s3.iam.config", iamConfigPath,
|
|
"-s3.iam.readOnly", "false",
|
|
"-ip", env.bindIP,
|
|
"-ip.bind", "0.0.0.0",
|
|
"-dir", env.dataDir,
|
|
)
|
|
cmd.Dir = env.dataDir
|
|
cmd.Stdout = os.Stdout
|
|
cmd.Stderr = os.Stderr
|
|
|
|
if err := cmd.Start(); err != nil {
|
|
t.Fatalf("Failed to start SeaweedFS: %v", err)
|
|
}
|
|
env.weedProcess = cmd
|
|
|
|
// Wait for S3 API to be ready
|
|
if !testutil.WaitForService(fmt.Sprintf("http://localhost:%d/status", env.s3Port), 30*time.Second) {
|
|
t.Fatalf("S3 API failed to become ready")
|
|
}
|
|
}
|
|
|
|
func (env *TestEnvironment) Start(t *testing.T) {
|
|
if !testutil.HasDocker() {
|
|
t.Skip("Docker not available")
|
|
}
|
|
}
|
|
|
|
func (env *TestEnvironment) Cleanup(t *testing.T) {
|
|
t.Helper()
|
|
if env.weedCancel != nil {
|
|
env.weedCancel()
|
|
}
|
|
if env.weedProcess != nil {
|
|
time.Sleep(1 * time.Second)
|
|
_ = env.weedProcess.Wait()
|
|
}
|
|
if env.dataDir != "" {
|
|
_ = os.RemoveAll(env.dataDir)
|
|
}
|
|
}
|
|
|
|
func runPythonSTSClient(t *testing.T, env *TestEnvironment) {
|
|
t.Helper()
|
|
|
|
// Write python script to temp dir
|
|
scriptContent := fmt.Sprintf(`
|
|
import boto3
|
|
import botocore.config
|
|
from botocore.exceptions import ClientError
|
|
import json
|
|
import sys
|
|
import time
|
|
import urllib.error
|
|
import urllib.request
|
|
|
|
print("Starting STS inline session policy test...")
|
|
|
|
primary_endpoint = "http://host.docker.internal:%d"
|
|
fallback_endpoint = "http://%s:%d"
|
|
access_key = "%s"
|
|
secret_key = "%s"
|
|
region = "us-east-1"
|
|
|
|
try:
|
|
def wait_for_endpoint(url, timeout=30):
|
|
deadline = time.time() + timeout
|
|
while time.time() < deadline:
|
|
try:
|
|
with urllib.request.urlopen(url, timeout=2):
|
|
return True
|
|
except urllib.error.HTTPError:
|
|
return True
|
|
except Exception:
|
|
time.sleep(1)
|
|
return False
|
|
|
|
def select_endpoint(urls):
|
|
for url in urls:
|
|
if wait_for_endpoint(url):
|
|
return url
|
|
raise Exception("No reachable S3 endpoint from container")
|
|
|
|
endpoint_url = select_endpoint([primary_endpoint, fallback_endpoint])
|
|
print(f"Using endpoint {endpoint_url}")
|
|
|
|
config = botocore.config.Config(
|
|
retries={'max_attempts': 0},
|
|
s3={'addressing_style': 'path'}
|
|
)
|
|
admin_s3 = boto3.client(
|
|
's3',
|
|
endpoint_url=endpoint_url,
|
|
aws_access_key_id=access_key,
|
|
aws_secret_access_key=secret_key,
|
|
region_name=region,
|
|
config=config
|
|
)
|
|
|
|
bucket = f"sts-inline-policy-{int(time.time() * 1000)}"
|
|
key = "allowed.txt"
|
|
|
|
print(f"Creating bucket {bucket} with admin credentials")
|
|
admin_s3.create_bucket(Bucket=bucket)
|
|
admin_s3.put_object(Bucket=bucket, Key=key, Body=b"ok")
|
|
|
|
sts = boto3.client(
|
|
'sts',
|
|
endpoint_url=endpoint_url,
|
|
aws_access_key_id=access_key,
|
|
aws_secret_access_key=secret_key,
|
|
region_name=region,
|
|
config=config
|
|
)
|
|
|
|
role_arn = "arn:aws:iam::role/TestRole"
|
|
session_name = "test-session"
|
|
session_policy = json.dumps({
|
|
"Version": "2012-10-17",
|
|
"Statement": [
|
|
{
|
|
"Effect": "Allow",
|
|
"Action": ["s3:ListBucket"],
|
|
"Resource": [f"arn:aws:s3:::{bucket}"]
|
|
},
|
|
{
|
|
"Effect": "Allow",
|
|
"Action": ["s3:GetObject"],
|
|
"Resource": [f"arn:aws:s3:::{bucket}/*"]
|
|
}
|
|
]
|
|
})
|
|
|
|
print(f"Calling AssumeRole on {role_arn} with inline session policy")
|
|
response = sts.assume_role(
|
|
RoleArn=role_arn,
|
|
RoleSessionName=session_name,
|
|
Policy=session_policy
|
|
)
|
|
|
|
creds = response['Credentials']
|
|
vended_s3 = boto3.client(
|
|
's3',
|
|
endpoint_url=endpoint_url,
|
|
aws_access_key_id=creds['AccessKeyId'],
|
|
aws_secret_access_key=creds['SecretAccessKey'],
|
|
aws_session_token=creds['SessionToken'],
|
|
region_name=region,
|
|
config=config
|
|
)
|
|
|
|
print("Listing objects (allowed)")
|
|
list_resp = vended_s3.list_objects_v2(Bucket=bucket)
|
|
keys = [obj.get('Key') for obj in list_resp.get('Contents', [])]
|
|
if key not in keys:
|
|
print(f"FAILED: Expected to see {key} in list_objects_v2 results")
|
|
sys.exit(1)
|
|
|
|
print("Getting object (allowed)")
|
|
body = vended_s3.get_object(Bucket=bucket, Key=key)['Body'].read()
|
|
if body != b"ok":
|
|
print("FAILED: Unexpected object content")
|
|
sys.exit(1)
|
|
|
|
print("Putting object (expected to be denied)")
|
|
try:
|
|
vended_s3.put_object(Bucket=bucket, Key="denied.txt", Body=b"no")
|
|
print("FAILED: PutObject unexpectedly succeeded")
|
|
sys.exit(1)
|
|
except ClientError as e:
|
|
error_code = e.response.get('Error', {}).get('Code', '')
|
|
if error_code != 'AccessDenied':
|
|
print(f"FAILED: Expected AccessDenied, got {error_code}")
|
|
sys.exit(1)
|
|
print("PutObject correctly denied by inline session policy")
|
|
|
|
print("SUCCESS: Inline session policy downscoping verified")
|
|
sys.exit(0)
|
|
except Exception as e:
|
|
print(f"FAILED: {e}")
|
|
if hasattr(e, 'response'):
|
|
print(f"Response: {e.response}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
sys.exit(1)
|
|
`, env.s3Port, env.bindIP, env.s3Port, env.accessKey, env.secretKey)
|
|
|
|
scriptPath := filepath.Join(env.dataDir, "sts_test.py")
|
|
if err := os.WriteFile(scriptPath, []byte(scriptContent), 0644); err != nil {
|
|
t.Fatalf("Failed to write python script: %v", err)
|
|
}
|
|
|
|
containerName := "seaweed-sts-client-" + fmt.Sprintf("%d", time.Now().UnixNano())
|
|
|
|
cmd := exec.Command("docker", "run", "--rm",
|
|
"--name", containerName,
|
|
"--add-host", "host.docker.internal:host-gateway",
|
|
"-v", fmt.Sprintf("%s:/work", env.dataDir),
|
|
"python:3",
|
|
"/bin/bash", "-c", "pip install boto3 && python /work/sts_test.py",
|
|
)
|
|
|
|
output, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("Python STS client failed: %v\nOutput:\n%s", err, string(output))
|
|
}
|
|
t.Logf("Python STS client output:\n%s", string(output))
|
|
}
|
|
|
|
func runPythonAuthzClient(t *testing.T, env *TestEnvironment) {
|
|
t.Helper()
|
|
|
|
scriptContent := fmt.Sprintf(`
|
|
import boto3
|
|
import botocore.config
|
|
from botocore.exceptions import ClientError
|
|
import json
|
|
import sys
|
|
import time
|
|
import urllib.error
|
|
import urllib.request
|
|
|
|
print("Starting STS AssumeRole authorization test...")
|
|
|
|
primary_endpoint = "http://host.docker.internal:%d"
|
|
fallback_endpoint = "http://%s:%d"
|
|
region = "us-east-1"
|
|
role_arn = "arn:aws:iam::role/TestRole"
|
|
|
|
def wait_for_endpoint(url, timeout=30):
|
|
deadline = time.time() + timeout
|
|
while time.time() < deadline:
|
|
try:
|
|
with urllib.request.urlopen(url, timeout=2):
|
|
return True
|
|
except urllib.error.HTTPError:
|
|
return True
|
|
except Exception:
|
|
time.sleep(1)
|
|
return False
|
|
|
|
def select_endpoint(urls):
|
|
for url in urls:
|
|
if wait_for_endpoint(url):
|
|
return url
|
|
raise Exception("No reachable S3 endpoint from container")
|
|
|
|
def fail(msg):
|
|
print("FAILED: " + msg)
|
|
sys.exit(1)
|
|
|
|
try:
|
|
endpoint_url = select_endpoint([primary_endpoint, fallback_endpoint])
|
|
print("Using endpoint " + endpoint_url)
|
|
config = botocore.config.Config(retries={'max_attempts': 0}, s3={'addressing_style': 'path'})
|
|
|
|
def sts_client(ak, sk, token=None):
|
|
return boto3.client('sts', endpoint_url=endpoint_url, aws_access_key_id=ak,
|
|
aws_secret_access_key=sk, aws_session_token=token,
|
|
region_name=region, config=config)
|
|
|
|
# 1) Non-admin caller may assume a role its trust policy admits, without the
|
|
# Admin action or an identity-side sts:AssumeRole grant.
|
|
print("1) non-admin AssumeRole (expect success)")
|
|
resp = sts_client("nonadmin_key", "nonadmin_secret").assume_role(
|
|
RoleArn=role_arn, RoleSessionName="nonadmin")
|
|
if not resp.get("Credentials", {}).get("AccessKeyId"):
|
|
fail("non-admin AssumeRole did not return credentials")
|
|
print(" ok")
|
|
|
|
# 2) A caller whose attached policy explicitly denies sts:AssumeRole is blocked,
|
|
# even though the trust policy admits it.
|
|
print("2) explicit identity deny (expect AccessDenied)")
|
|
try:
|
|
sts_client("denied_key", "denied_secret").assume_role(
|
|
RoleArn=role_arn, RoleSessionName="denied")
|
|
fail("explicit-deny caller unexpectedly assumed the role")
|
|
except ClientError as e:
|
|
code = e.response.get("Error", {}).get("Code", "")
|
|
if code != "AccessDenied":
|
|
fail("expected AccessDenied for identity deny, got " + code)
|
|
print(" ok")
|
|
|
|
# 3) A session whose inline policy denies sts:AssumeRole cannot chain into
|
|
# another role, even though the trust policy admits the session.
|
|
print("3) session-policy deny blocks role chaining (expect AccessDenied)")
|
|
deny_session = json.dumps({"Version": "2012-10-17", "Statement": [
|
|
{"Effect": "Deny", "Action": "sts:AssumeRole", "Resource": "*"}]})
|
|
hop1 = sts_client("nonadmin_key", "nonadmin_secret").assume_role(
|
|
RoleArn=role_arn, RoleSessionName="hop1", Policy=deny_session)["Credentials"]
|
|
chained = sts_client(hop1["AccessKeyId"], hop1["SecretAccessKey"], hop1["SessionToken"])
|
|
try:
|
|
chained.assume_role(RoleArn=role_arn, RoleSessionName="hop2")
|
|
fail("chained session unexpectedly assumed the role despite session-policy deny")
|
|
except ClientError as e:
|
|
code = e.response.get("Error", {}).get("Code", "")
|
|
if code != "AccessDenied":
|
|
fail("expected AccessDenied for session-policy deny, got " + code)
|
|
print(" ok")
|
|
|
|
print("SUCCESS: AssumeRole authorization scenarios verified")
|
|
sys.exit(0)
|
|
except Exception as e:
|
|
print("FAILED: " + str(e))
|
|
if hasattr(e, "response"):
|
|
print("Response: " + str(e.response))
|
|
import traceback
|
|
traceback.print_exc()
|
|
sys.exit(1)
|
|
`, env.s3Port, env.bindIP, env.s3Port)
|
|
|
|
scriptPath := filepath.Join(env.dataDir, "sts_authz_test.py")
|
|
if err := os.WriteFile(scriptPath, []byte(scriptContent), 0644); err != nil {
|
|
t.Fatalf("Failed to write python script: %v", err)
|
|
}
|
|
|
|
containerName := "seaweed-sts-authz-" + fmt.Sprintf("%d", time.Now().UnixNano())
|
|
|
|
cmd := exec.Command("docker", "run", "--rm",
|
|
"--name", containerName,
|
|
"--add-host", "host.docker.internal:host-gateway",
|
|
"-v", fmt.Sprintf("%s:/work", env.dataDir),
|
|
"python:3",
|
|
"/bin/bash", "-c", "pip install boto3 && python /work/sts_authz_test.py",
|
|
)
|
|
|
|
output, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("Python STS authz client failed: %v\nOutput:\n%s", err, string(output))
|
|
}
|
|
t.Logf("Python STS authz client output:\n%s", string(output))
|
|
}
|
|
|
|
// Helpers copied from trino_catalog_test.go
|