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
308 lines
10 KiB
Go
308 lines
10 KiB
Go
package iam
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"encoding/json"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/aws/aws-sdk-go/service/s3"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
const (
|
|
testKeycloakBucket = "test-keycloak-bucket"
|
|
)
|
|
|
|
// TestKeycloakIntegrationAvailable checks if Keycloak is available for testing
|
|
func TestKeycloakIntegrationAvailable(t *testing.T) {
|
|
framework := NewS3IAMTestFramework(t)
|
|
defer framework.Cleanup()
|
|
|
|
if !framework.useKeycloak {
|
|
t.Skip("Keycloak not available, skipping integration tests")
|
|
}
|
|
|
|
// Test Keycloak health
|
|
assert.True(t, framework.useKeycloak, "Keycloak should be available")
|
|
assert.NotNil(t, framework.keycloakClient, "Keycloak client should be initialized")
|
|
}
|
|
|
|
// TestKeycloakAuthentication tests authentication flow with real Keycloak
|
|
func TestKeycloakAuthentication(t *testing.T) {
|
|
framework := NewS3IAMTestFramework(t)
|
|
defer framework.Cleanup()
|
|
|
|
if !framework.useKeycloak {
|
|
t.Skip("Keycloak not available, skipping integration tests")
|
|
}
|
|
|
|
t.Run("admin_user_authentication", func(t *testing.T) {
|
|
// Test admin user authentication
|
|
token, err := framework.getKeycloakToken("admin-user")
|
|
require.NoError(t, err)
|
|
assert.NotEmpty(t, token, "JWT token should not be empty")
|
|
|
|
// Verify token can be used to create S3 client
|
|
s3Client, err := framework.CreateS3ClientWithKeycloakToken(token)
|
|
require.NoError(t, err)
|
|
assert.NotNil(t, s3Client, "S3 client should be created successfully")
|
|
|
|
// Test bucket operations with admin privileges
|
|
err = framework.CreateBucket(s3Client, testKeycloakBucket)
|
|
assert.NoError(t, err, "Admin user should be able to create buckets")
|
|
|
|
// Verify bucket exists
|
|
buckets, err := s3Client.ListBuckets(&s3.ListBucketsInput{})
|
|
require.NoError(t, err)
|
|
|
|
found := false
|
|
for _, bucket := range buckets.Buckets {
|
|
if *bucket.Name == testKeycloakBucket {
|
|
found = true
|
|
break
|
|
}
|
|
}
|
|
assert.True(t, found, "Created bucket should be listed")
|
|
})
|
|
|
|
t.Run("read_only_user_authentication", func(t *testing.T) {
|
|
// Test read-only user authentication
|
|
token, err := framework.getKeycloakToken("read-user")
|
|
require.NoError(t, err)
|
|
assert.NotEmpty(t, token, "JWT token should not be empty")
|
|
|
|
// Debug: decode token to verify it's for read-user
|
|
parts := strings.Split(token, ".")
|
|
if len(parts) >= 2 {
|
|
payload := parts[1]
|
|
// JWTs use URL-safe base64 encoding without padding (RFC 4648 §5)
|
|
decoded, err := base64.RawURLEncoding.DecodeString(payload)
|
|
if err == nil {
|
|
var claims map[string]interface{}
|
|
if json.Unmarshal(decoded, &claims) == nil {
|
|
t.Logf("Token username: %v", claims["preferred_username"])
|
|
t.Logf("Token roles: %v", claims["roles"])
|
|
}
|
|
}
|
|
}
|
|
|
|
// First test with direct HTTP request to verify OIDC authentication works
|
|
t.Logf("Testing with direct HTTP request...")
|
|
err = framework.TestKeycloakTokenDirectly(token)
|
|
require.NoError(t, err, "Direct HTTP test should succeed")
|
|
|
|
// Create S3 client with Keycloak token
|
|
s3Client, err := framework.CreateS3ClientWithKeycloakToken(token)
|
|
require.NoError(t, err)
|
|
|
|
// Test that read-only user can list buckets
|
|
t.Logf("Testing ListBuckets with AWS SDK...")
|
|
_, err = s3Client.ListBuckets(&s3.ListBucketsInput{})
|
|
assert.NoError(t, err, "Read-only user should be able to list buckets")
|
|
|
|
// Test that read-only user cannot create buckets
|
|
t.Logf("Testing CreateBucket with AWS SDK...")
|
|
err = framework.CreateBucket(s3Client, testKeycloakBucket+"-readonly")
|
|
assert.Error(t, err, "Read-only user should not be able to create buckets")
|
|
})
|
|
|
|
t.Run("invalid_user_authentication", func(t *testing.T) {
|
|
// Test authentication with invalid credentials
|
|
_, err := framework.keycloakClient.AuthenticateUser("invalid-user", "invalid-password")
|
|
assert.Error(t, err, "Authentication with invalid credentials should fail")
|
|
})
|
|
}
|
|
|
|
// TestKeycloakTokenExpiration tests JWT token expiration handling
|
|
func TestKeycloakTokenExpiration(t *testing.T) {
|
|
framework := NewS3IAMTestFramework(t)
|
|
defer framework.Cleanup()
|
|
|
|
if !framework.useKeycloak {
|
|
t.Skip("Keycloak not available, skipping integration tests")
|
|
}
|
|
|
|
// Get a short-lived token (if Keycloak is configured for it)
|
|
// Use consistent password that matches Docker setup script logic: "adminuser123"
|
|
tokenResp, err := framework.keycloakClient.AuthenticateUser("admin-user", "adminuser123")
|
|
require.NoError(t, err)
|
|
|
|
// Verify token properties
|
|
assert.NotEmpty(t, tokenResp.AccessToken, "Access token should not be empty")
|
|
assert.Equal(t, "Bearer", tokenResp.TokenType, "Token type should be Bearer")
|
|
assert.Greater(t, tokenResp.ExpiresIn, 0, "Token should have expiration time")
|
|
|
|
// Test that token works initially
|
|
token, err := framework.getKeycloakToken("admin-user")
|
|
require.NoError(t, err)
|
|
|
|
s3Client, err := framework.CreateS3ClientWithKeycloakToken(token)
|
|
require.NoError(t, err)
|
|
|
|
_, err = s3Client.ListBuckets(&s3.ListBucketsInput{})
|
|
assert.NoError(t, err, "Fresh token should work for S3 operations")
|
|
}
|
|
|
|
// TestKeycloakRoleMapping tests role mapping from Keycloak to S3 policies
|
|
func TestKeycloakRoleMapping(t *testing.T) {
|
|
framework := NewS3IAMTestFramework(t)
|
|
defer framework.Cleanup()
|
|
|
|
if !framework.useKeycloak {
|
|
t.Skip("Keycloak not available, skipping integration tests")
|
|
}
|
|
|
|
testCases := []struct {
|
|
username string
|
|
expectedRole string
|
|
canCreateBucket bool
|
|
canListBuckets bool
|
|
description string
|
|
}{
|
|
{
|
|
username: "admin-user",
|
|
expectedRole: "S3AdminRole",
|
|
canCreateBucket: true,
|
|
canListBuckets: true,
|
|
description: "Admin user should have full access",
|
|
},
|
|
{
|
|
username: "read-user",
|
|
expectedRole: "S3ReadOnlyRole",
|
|
canCreateBucket: false,
|
|
canListBuckets: true,
|
|
description: "Read-only user should have read-only access",
|
|
},
|
|
{
|
|
username: "write-user",
|
|
expectedRole: "S3ReadWriteRole",
|
|
canCreateBucket: true,
|
|
canListBuckets: true,
|
|
description: "Read-write user should have read-write access",
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
t.Run(tc.username, func(t *testing.T) {
|
|
// Get Keycloak token for the user
|
|
token, err := framework.getKeycloakToken(tc.username)
|
|
require.NoError(t, err)
|
|
|
|
// Create S3 client with Keycloak token
|
|
s3Client, err := framework.CreateS3ClientWithKeycloakToken(token)
|
|
require.NoError(t, err, tc.description)
|
|
|
|
// Test list buckets permission
|
|
_, err = s3Client.ListBuckets(&s3.ListBucketsInput{})
|
|
if tc.canListBuckets {
|
|
assert.NoError(t, err, "%s should be able to list buckets", tc.username)
|
|
} else {
|
|
assert.Error(t, err, "%s should not be able to list buckets", tc.username)
|
|
}
|
|
|
|
// Test create bucket permission
|
|
testBucketName := testKeycloakBucket + "-" + tc.username
|
|
err = framework.CreateBucket(s3Client, testBucketName)
|
|
if tc.canCreateBucket {
|
|
assert.NoError(t, err, "%s should be able to create buckets", tc.username)
|
|
} else {
|
|
assert.Error(t, err, "%s should not be able to create buckets", tc.username)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestKeycloakS3Operations tests comprehensive S3 operations with Keycloak authentication
|
|
func TestKeycloakS3Operations(t *testing.T) {
|
|
framework := NewS3IAMTestFramework(t)
|
|
defer framework.Cleanup()
|
|
|
|
if !framework.useKeycloak {
|
|
t.Skip("Keycloak not available, skipping integration tests")
|
|
}
|
|
|
|
// Use admin user for comprehensive testing
|
|
token, err := framework.getKeycloakToken("admin-user")
|
|
require.NoError(t, err)
|
|
|
|
s3Client, err := framework.CreateS3ClientWithKeycloakToken(token)
|
|
require.NoError(t, err)
|
|
|
|
bucketName := testKeycloakBucket + "-operations"
|
|
|
|
t.Run("bucket_lifecycle", func(t *testing.T) {
|
|
// Create bucket
|
|
err = framework.CreateBucket(s3Client, bucketName)
|
|
require.NoError(t, err, "Should be able to create bucket")
|
|
|
|
// Verify bucket exists
|
|
buckets, err := s3Client.ListBuckets(&s3.ListBucketsInput{})
|
|
require.NoError(t, err)
|
|
|
|
found := false
|
|
for _, bucket := range buckets.Buckets {
|
|
if *bucket.Name == bucketName {
|
|
found = true
|
|
break
|
|
}
|
|
}
|
|
assert.True(t, found, "Created bucket should be listed")
|
|
})
|
|
|
|
t.Run("object_operations", func(t *testing.T) {
|
|
objectKey := "test-object.txt"
|
|
objectContent := "Hello from Keycloak-authenticated SeaweedFS!"
|
|
|
|
// Put object
|
|
err = framework.PutTestObject(s3Client, bucketName, objectKey, objectContent)
|
|
require.NoError(t, err, "Should be able to put object")
|
|
|
|
// Get object
|
|
content, err := framework.GetTestObject(s3Client, bucketName, objectKey)
|
|
require.NoError(t, err, "Should be able to get object")
|
|
assert.Equal(t, objectContent, content, "Object content should match")
|
|
|
|
// List objects
|
|
objects, err := framework.ListTestObjects(s3Client, bucketName)
|
|
require.NoError(t, err, "Should be able to list objects")
|
|
assert.Contains(t, objects, objectKey, "Object should be listed")
|
|
|
|
// Delete object
|
|
err = framework.DeleteTestObject(s3Client, bucketName, objectKey)
|
|
assert.NoError(t, err, "Should be able to delete object")
|
|
})
|
|
}
|
|
|
|
// TestKeycloakFailover tests fallback to mock OIDC when Keycloak is unavailable
|
|
func TestKeycloakFailover(t *testing.T) {
|
|
// Temporarily override Keycloak URL to simulate unavailability
|
|
originalURL := os.Getenv("KEYCLOAK_URL")
|
|
os.Setenv("KEYCLOAK_URL", "http://localhost:9999") // Non-existent service
|
|
defer func() {
|
|
if originalURL != "" {
|
|
os.Setenv("KEYCLOAK_URL", originalURL)
|
|
} else {
|
|
os.Unsetenv("KEYCLOAK_URL")
|
|
}
|
|
}()
|
|
|
|
framework := NewS3IAMTestFramework(t)
|
|
defer framework.Cleanup()
|
|
|
|
// Should fall back to mock OIDC
|
|
assert.False(t, framework.useKeycloak, "Should fall back to mock OIDC when Keycloak is unavailable")
|
|
assert.Nil(t, framework.keycloakClient, "Keycloak client should not be initialized")
|
|
assert.NotNil(t, framework.mockOIDC, "Mock OIDC server should be initialized")
|
|
|
|
// Test that mock authentication still works
|
|
s3Client, err := framework.CreateS3ClientWithJWT("admin-user", "TestAdminRole")
|
|
require.NoError(t, err, "Should be able to create S3 client with mock authentication")
|
|
|
|
// Basic operation should work
|
|
_, err = s3Client.ListBuckets(&s3.ListBucketsInput{})
|
|
// Note: This may still fail due to session store issues, but the client creation should work
|
|
}
|