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
307 lines
13 KiB
Go
307 lines
13 KiB
Go
package s3api
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/url"
|
|
"testing"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/iam_pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/s3api/policy_engine"
|
|
s3_constants "github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants"
|
|
"github.com/seaweedfs/seaweedfs/weed/s3api/s3err"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// In-process reproducers for aws:SourceIp condition handling on inline policies.
|
|
//
|
|
// These exercise the full chain: PutUserPolicy/PutGroupPolicy → reload →
|
|
// VerifyActionPermission against a synthetic HTTP request whose RemoteAddr is
|
|
// 127.0.0.1. The whole point is to prove that the Condition block is honored
|
|
// (or, before the fix lands, that it is silently dropped).
|
|
|
|
const inlineCondTestBucket = "inline-cond-bucket"
|
|
|
|
func inlineCondPolicyDoc(cidr string) string {
|
|
return `{
|
|
"Version":"2012-10-17",
|
|
"Statement":[{
|
|
"Effect":"Allow",
|
|
"Action":"s3:*",
|
|
"Resource":["arn:aws:s3:::` + inlineCondTestBucket + `","arn:aws:s3:::` + inlineCondTestBucket + `/*"],
|
|
"Condition":{"IpAddress":{"aws:SourceIp":"` + cidr + `"}}
|
|
}]
|
|
}`
|
|
}
|
|
|
|
// inlineCondRequest builds a minimal request that VerifyActionPermission can
|
|
// evaluate: RemoteAddr set so extractSourceIP returns 127.0.0.1, and the bucket
|
|
// path so GetBucketAndObject (if reached) is unambiguous.
|
|
func inlineCondRequest(t *testing.T, method string) *http.Request {
|
|
t.Helper()
|
|
req, err := http.NewRequest(method, "http://s3.amazonaws.com/"+inlineCondTestBucket+"/obj", nil)
|
|
require.NoError(t, err)
|
|
req.Host = "s3.amazonaws.com"
|
|
req.RemoteAddr = "127.0.0.1:54321"
|
|
return req
|
|
}
|
|
|
|
// seedInlineCondUser puts a user "alice" with a single access key into both
|
|
// api.mockConfig and the credential store, then reloads the in-memory IAM so
|
|
// identity lookups observe her. Returns the loaded Identity.
|
|
func seedInlineCondUser(t *testing.T, api *EmbeddedIamApiForTest) *Identity {
|
|
t.Helper()
|
|
if api.mockConfig == nil {
|
|
api.mockConfig = &iam_pb.S3ApiConfiguration{}
|
|
}
|
|
api.mockConfig.Identities = append(api.mockConfig.Identities, &iam_pb.Identity{
|
|
Name: "alice",
|
|
Credentials: []*iam_pb.Credential{
|
|
{AccessKey: "AKIAALICE", SecretKey: "alice-secret"},
|
|
},
|
|
})
|
|
require.NoError(t, api.credentialManager.SaveConfiguration(context.Background(), api.mockConfig))
|
|
require.NoError(t, api.iam.LoadS3ApiConfigurationFromCredentialManager())
|
|
ident := api.iam.lookupByIdentityName("alice")
|
|
require.NotNil(t, ident, "alice must be loaded after reload")
|
|
return ident
|
|
}
|
|
|
|
// TestUserInlinePolicySourceIpCondition_Denies is the primary reproducer: a
|
|
// user inline policy with an aws:SourceIp condition that does NOT match the
|
|
// caller's source IP must result in AccessDenied. Today this passes (bug)
|
|
// because PutUserPolicy flattens the document into ident.Actions and the
|
|
// Condition block is dropped.
|
|
func TestUserInlinePolicySourceIpCondition_Denies(t *testing.T) {
|
|
api := NewEmbeddedIamApiForTest()
|
|
api.mockConfig = &iam_pb.S3ApiConfiguration{}
|
|
seedInlineCondUser(t, api)
|
|
|
|
// Allow s3:* on the bucket only when SourceIp is in 198.51.100.0/24 (TEST-NET-2).
|
|
// 127.0.0.1 must not match, so the action must be denied.
|
|
_, iamErr := api.PutUserPolicy(api.mockConfig, url.Values{
|
|
"UserName": {"alice"},
|
|
"PolicyName": {"OnlyFromTestNet"},
|
|
"PolicyDocument": {inlineCondPolicyDoc("198.51.100.0/24")},
|
|
})
|
|
require.Nil(t, iamErr, "PutUserPolicy must succeed")
|
|
require.NoError(t, api.PutS3ApiConfiguration(api.mockConfig))
|
|
require.NoError(t, api.iam.LoadS3ApiConfigurationFromCredentialManager())
|
|
|
|
ident := api.iam.lookupByIdentityName("alice")
|
|
require.NotNil(t, ident)
|
|
|
|
req := inlineCondRequest(t, http.MethodPut)
|
|
got := api.iam.VerifyActionPermission(req, ident, s3_constants.ACTION_WRITE, inlineCondTestBucket, "obj")
|
|
assert.Equal(t, s3err.ErrAccessDenied, got,
|
|
"PutObject from 127.0.0.1 must be denied: the user inline policy's aws:SourceIp condition (198.51.100.0/24) does not match")
|
|
}
|
|
|
|
// TestUserInlinePolicySourceIpCondition_Allows is the companion: with a
|
|
// matching CIDR (127.0.0.0/8), the same call must succeed.
|
|
func TestUserInlinePolicySourceIpCondition_Allows(t *testing.T) {
|
|
api := NewEmbeddedIamApiForTest()
|
|
api.mockConfig = &iam_pb.S3ApiConfiguration{}
|
|
seedInlineCondUser(t, api)
|
|
|
|
_, iamErr := api.PutUserPolicy(api.mockConfig, url.Values{
|
|
"UserName": {"alice"},
|
|
"PolicyName": {"FromLoopback"},
|
|
"PolicyDocument": {inlineCondPolicyDoc("127.0.0.0/8")},
|
|
})
|
|
require.Nil(t, iamErr)
|
|
require.NoError(t, api.PutS3ApiConfiguration(api.mockConfig))
|
|
require.NoError(t, api.iam.LoadS3ApiConfigurationFromCredentialManager())
|
|
|
|
ident := api.iam.lookupByIdentityName("alice")
|
|
require.NotNil(t, ident)
|
|
|
|
req := inlineCondRequest(t, http.MethodPut)
|
|
got := api.iam.VerifyActionPermission(req, ident, s3_constants.ACTION_WRITE, inlineCondTestBucket, "obj")
|
|
assert.Equal(t, s3err.ErrNone, got,
|
|
"PutObject from 127.0.0.1 must be allowed: the user inline policy's aws:SourceIp condition (127.0.0.0/8) matches")
|
|
}
|
|
|
|
// TestUserInlinePolicySourceIpCondition_IgnoresForwardedHeaders proves that a
|
|
// spoofed X-Forwarded-For cannot satisfy an aws:SourceIp condition: the policy
|
|
// requires 198.51.100.0/24, the peer is 127.0.0.1, and the header claims
|
|
// 198.51.100.5. The condition must be evaluated against the peer, not the
|
|
// header, so the request is denied.
|
|
func TestUserInlinePolicySourceIpCondition_IgnoresForwardedHeaders(t *testing.T) {
|
|
api := NewEmbeddedIamApiForTest()
|
|
api.mockConfig = &iam_pb.S3ApiConfiguration{}
|
|
seedInlineCondUser(t, api)
|
|
|
|
_, iamErr := api.PutUserPolicy(api.mockConfig, url.Values{
|
|
"UserName": {"alice"},
|
|
"PolicyName": {"OnlyFromTestNet"},
|
|
"PolicyDocument": {inlineCondPolicyDoc("198.51.100.0/24")},
|
|
})
|
|
require.Nil(t, iamErr, "PutUserPolicy must succeed")
|
|
require.NoError(t, api.PutS3ApiConfiguration(api.mockConfig))
|
|
require.NoError(t, api.iam.LoadS3ApiConfigurationFromCredentialManager())
|
|
|
|
ident := api.iam.lookupByIdentityName("alice")
|
|
require.NotNil(t, ident)
|
|
|
|
req := inlineCondRequest(t, http.MethodPut)
|
|
req.Header.Set("X-Forwarded-For", "198.51.100.5")
|
|
got := api.iam.VerifyActionPermission(req, ident, s3_constants.ACTION_WRITE, inlineCondTestBucket, "obj")
|
|
assert.Equal(t, s3err.ErrAccessDenied, got,
|
|
"PutObject from 127.0.0.1 must be denied despite X-Forwarded-For claiming 198.51.100.5: aws:SourceIp is the peer, not the header")
|
|
}
|
|
|
|
// TestGroupInlinePolicy_PutAndEnforce verifies that PutGroupPolicy is supported
|
|
// (no longer returns NotImplemented) and that an aws:SourceIp condition on the
|
|
// resulting inline policy is honored for group members.
|
|
func TestGroupInlinePolicy_PutAndEnforce(t *testing.T) {
|
|
api := NewEmbeddedIamApiForTest()
|
|
api.mockConfig = &iam_pb.S3ApiConfiguration{}
|
|
seedInlineCondUser(t, api)
|
|
// Groups live in their own credential-store namespace (CreateGroup, not
|
|
// SaveConfiguration). Seed devs+alice via the dedicated API and refresh
|
|
// through the framework hook so both mockConfig.Groups and iam.groups
|
|
// observe the new group.
|
|
ctx := context.Background()
|
|
require.NoError(t, api.credentialManager.CreateGroup(ctx, &iam_pb.Group{
|
|
Name: "devs",
|
|
Members: []string{"alice"},
|
|
}))
|
|
require.NoError(t, api.refreshIAMConfiguration())
|
|
|
|
// PutGroupPolicy must succeed. This is the call that returns
|
|
// NotImplemented today; this test will fail with that error.
|
|
_, iamErr := api.PutGroupPolicy(api.mockConfig, url.Values{
|
|
"GroupName": {"devs"},
|
|
"PolicyName": {"DevsFromLoopback"},
|
|
"PolicyDocument": {inlineCondPolicyDoc("198.51.100.0/24")},
|
|
})
|
|
require.Nil(t, iamErr, "PutGroupPolicy must succeed; got: %+v", iamErr)
|
|
require.NoError(t, api.iam.LoadS3ApiConfigurationFromCredentialManager())
|
|
|
|
ident := api.iam.lookupByIdentityName("alice")
|
|
require.NotNil(t, ident)
|
|
|
|
// Deny path: condition does not match the loopback caller.
|
|
req := inlineCondRequest(t, http.MethodPut)
|
|
got := api.iam.VerifyActionPermission(req, ident, s3_constants.ACTION_WRITE, inlineCondTestBucket, "obj")
|
|
assert.Equal(t, s3err.ErrAccessDenied, got,
|
|
"group member from 127.0.0.1 must be denied when the group inline policy's aws:SourceIp condition (198.51.100.0/24) does not match")
|
|
|
|
// Round-trip via the store: list & get must observe the new inline policy.
|
|
listResp, iamErr := api.ListGroupPolicies(api.mockConfig, url.Values{"GroupName": {"devs"}})
|
|
require.Nil(t, iamErr)
|
|
assert.Contains(t, listResp.ListGroupPoliciesResult.PolicyNames, "DevsFromLoopback")
|
|
|
|
getResp, iamErr := api.GetGroupPolicy(api.mockConfig, url.Values{
|
|
"GroupName": {"devs"}, "PolicyName": {"DevsFromLoopback"},
|
|
})
|
|
require.Nil(t, iamErr)
|
|
assert.Contains(t, getResp.GetGroupPolicyResult.PolicyDocument, "aws:SourceIp",
|
|
"GetGroupPolicy must round-trip the Condition block")
|
|
|
|
// Flip the policy to the matching CIDR and verify the allow path.
|
|
_, iamErr = api.PutGroupPolicy(api.mockConfig, url.Values{
|
|
"GroupName": {"devs"},
|
|
"PolicyName": {"DevsFromLoopback"},
|
|
"PolicyDocument": {inlineCondPolicyDoc("127.0.0.0/8")},
|
|
})
|
|
require.Nil(t, iamErr)
|
|
require.NoError(t, api.iam.LoadS3ApiConfigurationFromCredentialManager())
|
|
|
|
ident = api.iam.lookupByIdentityName("alice")
|
|
require.NotNil(t, ident)
|
|
got = api.iam.VerifyActionPermission(inlineCondRequest(t, http.MethodPut), ident,
|
|
s3_constants.ACTION_WRITE, inlineCondTestBucket, "obj")
|
|
assert.Equal(t, s3err.ErrNone, got,
|
|
"group member from 127.0.0.1 must be allowed when the group inline policy's aws:SourceIp condition (127.0.0.0/8) matches")
|
|
|
|
// Cleanup: DeleteGroupPolicy must also be implemented and must drop the
|
|
// engine registration so the action is no longer permitted via this group.
|
|
_, iamErr = api.DeleteGroupPolicy(api.mockConfig, url.Values{
|
|
"GroupName": {"devs"}, "PolicyName": {"DevsFromLoopback"},
|
|
})
|
|
require.Nil(t, iamErr, "DeleteGroupPolicy must succeed")
|
|
require.NoError(t, api.iam.LoadS3ApiConfigurationFromCredentialManager())
|
|
ident = api.iam.lookupByIdentityName("alice")
|
|
require.NotNil(t, ident)
|
|
got = api.iam.VerifyActionPermission(inlineCondRequest(t, http.MethodPut), ident,
|
|
s3_constants.ACTION_WRITE, inlineCondTestBucket, "obj")
|
|
assert.Equal(t, s3err.ErrAccessDenied, got,
|
|
"after DeleteGroupPolicy, the group inline policy must no longer grant access")
|
|
}
|
|
|
|
// TestUserInlinePolicy_ConditionDiscriminatesAllowVsDeny pairs allow and deny
|
|
// against the same user with the same Actions list. If the engine path is not
|
|
// in use, both calls would hit the legacy Actions branch and both would be
|
|
// allowed; the discriminator is that switching the CIDR must flip the result.
|
|
func TestUserInlinePolicy_ConditionDiscriminatesAllowVsDeny(t *testing.T) {
|
|
api := NewEmbeddedIamApiForTest()
|
|
api.mockConfig = &iam_pb.S3ApiConfiguration{}
|
|
seedInlineCondUser(t, api)
|
|
|
|
// Allow from loopback first: must succeed.
|
|
_, iamErr := api.PutUserPolicy(api.mockConfig, url.Values{
|
|
"UserName": {"alice"},
|
|
"PolicyName": {"P"},
|
|
"PolicyDocument": {inlineCondPolicyDoc("127.0.0.0/8")},
|
|
})
|
|
require.Nil(t, iamErr)
|
|
require.NoError(t, api.PutS3ApiConfiguration(api.mockConfig))
|
|
require.NoError(t, api.iam.LoadS3ApiConfigurationFromCredentialManager())
|
|
|
|
ident := api.iam.lookupByIdentityName("alice")
|
|
require.NotNil(t, ident)
|
|
got := api.iam.VerifyActionPermission(inlineCondRequest(t, http.MethodPut), ident,
|
|
s3_constants.ACTION_WRITE, inlineCondTestBucket, "obj")
|
|
require.Equal(t, s3err.ErrNone, got, "policy with matching CIDR must allow")
|
|
|
|
// Replace with non-matching CIDR: must now deny. Same user, same action,
|
|
// same Actions list (Admin:bucket). Only the Condition block changed.
|
|
_, iamErr = api.PutUserPolicy(api.mockConfig, url.Values{
|
|
"UserName": {"alice"},
|
|
"PolicyName": {"P"},
|
|
"PolicyDocument": {inlineCondPolicyDoc("198.51.100.0/24")},
|
|
})
|
|
require.Nil(t, iamErr)
|
|
require.NoError(t, api.PutS3ApiConfiguration(api.mockConfig))
|
|
require.NoError(t, api.iam.LoadS3ApiConfigurationFromCredentialManager())
|
|
|
|
ident = api.iam.lookupByIdentityName("alice")
|
|
require.NotNil(t, ident)
|
|
got = api.iam.VerifyActionPermission(inlineCondRequest(t, http.MethodPut), ident,
|
|
s3_constants.ACTION_WRITE, inlineCondTestBucket, "obj")
|
|
require.Equal(t, s3err.ErrAccessDenied, got,
|
|
"flipping aws:SourceIp to a non-matching CIDR must flip the decision; "+
|
|
"this proves the engine (not the legacy Actions list) drives the outcome")
|
|
}
|
|
|
|
// TestUserInlinePolicy_ReloadFromStore verifies that after the IAM is reloaded
|
|
// (simulating a restart), the stored user inline policy is re-registered and
|
|
// its Condition block is still enforced. Catches a regression where the engine
|
|
// state is rebuilt only from managed policies, not inline ones.
|
|
func TestUserInlinePolicy_ReloadFromStore(t *testing.T) {
|
|
api := NewEmbeddedIamApiForTest()
|
|
api.mockConfig = &iam_pb.S3ApiConfiguration{}
|
|
seedInlineCondUser(t, api)
|
|
|
|
// Persist an inline policy via the credential store directly, bypassing
|
|
// the API. This is the on-disk state a fresh process boots into.
|
|
var doc policy_engine.PolicyDocument
|
|
require.NoError(t, doc.UnmarshalJSON([]byte(inlineCondPolicyDoc("198.51.100.0/24"))))
|
|
require.NoError(t, api.credentialManager.PutUserInlinePolicy(
|
|
context.Background(), "alice", "OnlyFromTestNet", doc))
|
|
|
|
// Simulate restart: full reload from credential store.
|
|
require.NoError(t, api.iam.LoadS3ApiConfigurationFromCredentialManager())
|
|
|
|
ident := api.iam.lookupByIdentityName("alice")
|
|
require.NotNil(t, ident)
|
|
|
|
req := inlineCondRequest(t, http.MethodPut)
|
|
got := api.iam.VerifyActionPermission(req, ident, s3_constants.ACTION_WRITE, inlineCondTestBucket, "obj")
|
|
assert.Equal(t, s3err.ErrAccessDenied, got,
|
|
"after reload, the persisted user inline policy's aws:SourceIp condition must still be honored")
|
|
}
|