|
|
3 月之前 | |
|---|---|---|
| .. | ||
| GOVERNANCE_PERMISSIONS.md | 3 月之前 | |
| INTEGRATION_EXAMPLE.md | 3 月之前 | |
| POLICY_EXAMPLES.md | 3 月之前 | |
| README_POLICY_ENGINE.md | 3 月之前 | |
| conditions.go | 3 月之前 | |
| engine.go | 3 月之前 | |
| engine_test.go | 3 月之前 | |
| examples.go | 3 月之前 | |
| integration.go | 3 月之前 | |
| types.go | 3 月之前 | |
| wildcard_matcher.go | 3 月之前 | |
| wildcard_matcher_test.go | 3 月之前 | |
This document describes the comprehensive policy evaluation engine that has been added to SeaweedFS, providing AWS S3-compatible policy support while maintaining full backward compatibility with existing identities.json configuration.
The policy engine provides:
identities.json continues to work unchangedpolicy_engine/types.go - Core policy data structures and validationpolicy_engine/conditions.go - Condition evaluators (StringEquals, IpAddress, etc.)policy_engine/engine.go - Main policy evaluation enginepolicy_engine/integration.go - Integration with existing IAM systempolicy_engine/engine_test.go - Comprehensive testspolicy_engine/examples.go - Usage examples and documentation (excluded from builds)policy_engine/wildcard_matcher.go - Optimized wildcard pattern matchingpolicy_engine/wildcard_matcher_test.go - Wildcard matching testsPolicyEngine
├── Bucket Policies (per-bucket JSON policies)
├── User Policies (converted from identities.json + new IAM policies)
├── Condition Evaluators (IP, time, string, numeric, etc.)
└── Evaluation Logic (AWS-compliant precedence)
Your existing configuration continues to work exactly as before:
{
"identities": [
{
"name": "readonly_user",
"credentials": [{"accessKey": "key123", "secretKey": "secret123"}],
"actions": ["Read:public-bucket/*", "List:public-bucket"]
}
]
}
Legacy actions are automatically converted to AWS-style policies:
Read:bucket/* → s3:GetObject on arn:aws:s3:::bucket/*Write:bucket → s3:PutObject, s3:DeleteObject on arn:aws:s3:::bucket/*Admin → s3:* on arn:aws:s3:::*Set bucket-level policies using standard S3 API:
# Set bucket policy
curl -X PUT "http://localhost:8333/bucket?policy" \
-H "Authorization: AWS access_key:signature" \
-d '{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::bucket/*"
}
]
}'
# Get bucket policy
curl "http://localhost:8333/bucket?policy"
# Delete bucket policy
curl -X DELETE "http://localhost:8333/bucket?policy"
Support for all AWS condition operators:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::secure-bucket/*",
"Condition": {
"IpAddress": {
"aws:SourceIp": ["192.168.1.0/24", "10.0.0.0/8"]
},
"Bool": {
"aws:SecureTransport": "true"
},
"DateGreaterThan": {
"aws:CurrentTime": "2023-01-01T00:00:00Z"
}
}
}
]
}
StringEquals, StringNotEquals, StringLike, StringNotLikeNumericEquals, NumericLessThan, NumericGreaterThan, etc.DateEquals, DateLessThan, DateGreaterThan, etc.IpAddress, NotIpAddress (supports CIDR notation)BoolArnEquals, ArnLikeNullStandard AWS condition keys are supported:
aws:CurrentTime - Current request timeaws:SourceIp - Client IP addressaws:SecureTransport - Whether HTTPS is usedaws:UserAgent - Client user agents3:x-amz-acl - Requested ACLs3:VersionId - Object version IDidentities.json + new IAM policies{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicRead",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::public-bucket/*"
}
]
}
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": ["s3:GetObject", "s3:PutObject"],
"Resource": "arn:aws:s3:::secure-bucket/*",
"Condition": {
"IpAddress": {
"aws:SourceIp": "192.168.1.0/24"
}
}
}
]
}
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": ["arn:aws:s3:::ssl-bucket/*", "arn:aws:s3:::ssl-bucket"],
"Condition": {
"Bool": {
"aws:SecureTransport": "false"
}
}
}
]
}
identities.json or AWS-style policiesRun the policy engine tests:
# Core policy tests
go test -v -run TestPolicyEngine
# Condition evaluator tests
go test -v -run TestConditionEvaluators
# Legacy compatibility tests
go test -v -run TestConvertIdentityToPolicy
# Validation tests
go test -v -run TestPolicyValidation
identities.json unchangedidentities.jsonThe policy engine provides a seamless upgrade path from SeaweedFS's existing simple IAM system to full AWS S3-compatible policies, giving you the best of both worlds: simplicity for basic use cases and power for complex enterprise scenarios.