4 changed files with 89 additions and 5 deletions
-
43weed/iam/integration/iam_manager_trust.go
-
15weed/s3api/auth_credentials_trust.go
-
9weed/s3api/s3_iam_middleware.go
-
27weed/s3api/s3api_sts.go
@ -0,0 +1,43 @@ |
|||||
|
package integration |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
"fmt" |
||||
|
|
||||
|
"github.com/seaweedfs/seaweedfs/weed/iam/policy" |
||||
|
"github.com/seaweedfs/seaweedfs/weed/iam/utils" |
||||
|
) |
||||
|
|
||||
|
// ValidateTrustPolicyForPrincipal validates if a principal is allowed to assume a role
|
||||
|
func (m *IAMManager) ValidateTrustPolicyForPrincipal(ctx context.Context, roleArn, principalArn string) error { |
||||
|
if !m.initialized { |
||||
|
return fmt.Errorf("IAM manager not initialized") |
||||
|
} |
||||
|
|
||||
|
// Extract role name from ARN
|
||||
|
roleName := utils.ExtractRoleNameFromArn(roleArn) |
||||
|
|
||||
|
// Get role definition
|
||||
|
roleDef, err := m.roleStore.GetRole(ctx, m.getFilerAddress(), roleName) |
||||
|
if err != nil { |
||||
|
return fmt.Errorf("role not found: %s", roleName) |
||||
|
} |
||||
|
|
||||
|
if roleDef.TrustPolicy == nil { |
||||
|
return fmt.Errorf("role has no trust policy") |
||||
|
} |
||||
|
|
||||
|
// Create evaluation context
|
||||
|
evalCtx := &policy.EvaluationContext{ |
||||
|
Principal: principalArn, |
||||
|
Action: "sts:AssumeRole", |
||||
|
Resource: roleArn, |
||||
|
} |
||||
|
|
||||
|
// Evaluate the trust policy
|
||||
|
if !m.evaluateTrustPolicy(roleDef.TrustPolicy, evalCtx) { |
||||
|
return fmt.Errorf("trust policy denies access to principal: %s", principalArn) |
||||
|
} |
||||
|
|
||||
|
return nil |
||||
|
} |
||||
@ -0,0 +1,15 @@ |
|||||
|
package s3api |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
"fmt" |
||||
|
) |
||||
|
|
||||
|
// ValidateTrustPolicyForPrincipal validates if a principal is allowed to assume a role
|
||||
|
// Delegates to the IAM integration if available
|
||||
|
func (iam *IdentityAccessManagement) ValidateTrustPolicyForPrincipal(ctx context.Context, roleArn, principalArn string) error { |
||||
|
if iam.iamIntegration != nil { |
||||
|
return iam.iamIntegration.ValidateTrustPolicyForPrincipal(ctx, roleArn, principalArn) |
||||
|
} |
||||
|
return fmt.Errorf("IAM integration not available") |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue