GHSA-5VHW-52XR-8X4J
STS AssumeRoleWithWebIdentity ignores trust policies when policy.defaultEffect is Allow
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-5VHW-52XR-8X4J divulgada | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Summary
`PolicyEngine.EvaluateTrustPolicy` (weed/iam/policy/policy_engine.go) starts from the engine's `DefaultEffect` and keeps it when no trust-policy statement matches. With `"policy": {"defaultEffect": "Allow"}` in the S3 IAM config, `AssumeRoleWithWebIdentity` issues credentials for a role whose trust policy does not admit the caller — a wrong `sub`, or an unmet `Condition`. Any holder of a validly signed token from any registered OIDC provider can assume any role and act with that role's policies.
Up to d75162370 (#7970), `IAMManager.evaluateTrustPolicy` ended in `return false`, deny-by-default whatever `DefaultEffect` said. #7970 moved trust evaluation into `PolicyEngine.EvaluateTrustPolicy`, which is where the fallback appeared. #7970's own `TestTrustPolicyEvaluation` expects a non-matching federated principal to be denied, but it runs only with `DefaultEffect: "Deny"`. We may be wrong that the fallback is unintended; if it is intended, please close this.
Affected versions
Releases 4.06 (the first containing d75162370) through 4.48, and master at 150a69fe1. Reproduced on 150a69fe1.
Deployment and configuration
- An S3 gateway with IAM enabled: `weed mini -s3.iam.config=iam.json -s3.config=s3.json` reproduces it.
- The IAM config sets `"policy": {"defaultEffect": "Allow"}`. `Deny` is not affected.
- The config registers an OIDC provider and a role whose trust policy restricts `oidc:sub`.
- Zero-config IAM, with no `-s3.iam.config`, also runs with `DefaultEffect: Allow`, but on released versions it has no roles.
Attacker's starting position
Holds a validly signed token from any OIDC provider the gateway trusts, for example:
- any workload in a SPIFFE trust domain whose OIDC discovery provider is registered;
- any CI job, if a CI provider's OIDC issuer is registered.
The attacker needs no S3 credentials.
Trust boundary crossed
The role's trust policy admits only specific subjects. A different subject of the same issuer obtains the role's session credentials, and with them the role's S3 permissions.
Reproduction
`iam.json`, with an issuer serving discovery and JWKS at `http://127.0.0.1:18999` for an RSA key the tester holds:
{"sts":{"tokenDuration":"1h","maxSessionLength":"12h","issuer":"seaweedfs-sts","signingKey":"<base64 32 bytes>",
"providers":[{"name":"spire","type":"oidc","enabled":true,"config":{"issuer":"http://127.0.0.1:18999","clientId":"probe-aud","jwksUri":"http://127.0.0.1:18999/keys"}}]},
"policy":{"defaultEffect":"Allow"},
"policies":[{"name":"bkt-rw","document":{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["s3:*"],"Resource":["arn:aws:s3:::probe-bkt","arn:aws:s3:::probe-bkt/*"]}]}}],
"roles":[{"roleName":"checkout-runtime","roleArn":"arn:aws:iam::role/checkout-runtime",
"trustPolicy":{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"Federated":"spire"},"Action":["sts:AssumeRoleWithWebIdentity"],
"Condition":{"StringEquals":{"oidc:sub":"spiffe://acme.example/ns/checkout/sa/checkout-runtime"}}}]},
"attachedPolicies":["bkt-rw"]}]}- Start the gateway with `weed mini -s3.iam.config=iam.json -s3.config=s3.json` (an admin identity creates `probe-bkt`).
- Sign an RS256 token with the issuer's key: `iss` = the issuer, `aud` = `probe-aud`, `sub` = `spiffe://acme.example/ns/other/sa/x`, which is not the subject the trust policy names.
- Call `aws sts assume-role-with-web-identity --endpoint-url http://127.0.0.1:8333 --role-arn arn:aws:iam::role/checkout-runtime --role-session-name x --web-identity-token <token>`.
- Use the returned credentials: `aws s3 cp f s3://probe-bkt/f` succeeds.
Expected: step 3 is refused with AccessDenied ("trust policy validation failed"). That is what happens with `defaultEffect: Deny`.
Actual: step 3 returns credentials, and step 4 writes to the bucket the role's policy grants.
Proposed fix
A trust policy always starts from an implicit deny, as in AWS; an explicit Deny still wins. The patch below makes that change and adds a test, which fails on master under `DefaultEffect: Allow`. `go test ./weed/iam/... ./weed/s3api/ ./weed/server/` passes with it.
Upgrade note: deployments on `defaultEffect: Allow` whose trust policies do not match their callers will see those assumptions refused.
diff --git a/weed/iam/policy/policy_engine.go b/weed/iam/policy/policy_engine.go
index f53768bb4..6730a3b06 100644
--- a/weed/iam/policy/policy_engine.go
+++ b/weed/iam/policy/policy_engine.go
@@ -473,8 +473,14 @@ func (e *PolicyEngine) EvaluateTrustPolicy(ctx context.Context, trustPolicy *Pol
return nil, fmt.Errorf("trust policy cannot be nil")
}
+ // A trust policy is deny-by-default, whatever the engine's DefaultEffect:
+ // that setting governs requests no identity policy speaks to, but a role
+ // may be assumed only by a principal a trust statement explicitly allows.
+ // Falling back to DefaultEffect "Allow" let any caller holding a valid
+ // token from a registered provider assume any role, trust conditions
+ // notwithstanding.
result := &EvaluationResult{
- Effect: Effect(e.config.DefaultEffect),
+ Effect: EffectDeny,
EvaluationDetails: &EvaluationDetails{
Principal: evalCtx.Principal,
Action: evalCtx.Action,
@@ -511,7 +517,7 @@ func (e *PolicyEngine) EvaluateTrustPolicy(ctx context.Context, trustPolicy *Pol
// AWS IAM evaluation logic:
// 1. If there's an explicit Deny, the result is Deny
// 2. If there's an Allow and no Deny, the result is Allow
- // 3. Otherwise, use the default effect
+ // 3. Otherwise, the implicit deny stands
if explicitDeny {
result.Effect = EffectDeny
} else if hasAllow {
diff --git a/weed/iam/policy/trust_policy_implicit_deny_test.go b/weed/iam/policy/trust_policy_implicit_deny_test.go
new file mode 100644
index 000000000..2058bcf7c
--- /dev/null
+++ b/weed/iam/policy/trust_policy_implicit_deny_test.go
@@ -0,0 +1,80 @@
+package policy
+
+import (
+ "context"
+ "encoding/json"
+ "testing"
+)
+
+const subjectBoundTrustPolicy = `{"Version":"2012-10-17","Statement":[{"Effect":"Allow",
+ "Principal":{"Federated":"https://oidc.example"},"Action":["sts:AssumeRoleWithWebIdentity"],
+ "Condition":{"StringEquals":{"oidc:sub":"spiffe://example.org/ns/app/sa/app"}}}]}`
+
+func webIdentityContext(sub string) *EvaluationContext {
+ return &EvaluationContext{
+ Principal: "web-identity-user",
+ Action: "sts:AssumeRoleWithWebIdentity",
+ Resource: "arn:aws:iam::role/app",
+ RequestContext: map[string]interface{}{
+ "aws:FederatedProvider": "https://oidc.example",
+ "oidc:iss": "https://oidc.example",
+ "oidc:sub": sub,
+ },
+ }
+}
+
+// A trust policy is deny-by-default. The engine's DefaultEffect decides
+// requests no identity policy speaks to; it must not let a principal the trust
+// policy does not allow assume the role.
+func TestEvaluateTrustPolicyIsImplicitDenyWhateverTheDefaultEffect(t *testing.T) {
+ var trust PolicyDocument
+ if err := json.Unmarshal([]byte(subjectBoundTrustPolicy), &trust); err != nil {
+ t.Fatalf("parse test trust policy: %v", err)
+ }
+ for _, defaultEffect := range []string{"Allow", "Deny"} {
+ t.Run("defaultEffect="+defaultEffect, func(t *testing.T) {
+ engine := NewPolicyEngine()
+ if err := engine.Initialize(&PolicyEngineConfig{DefaultEffect: defaultEffect, StoreType: "memory"}); err != nil {
+ t.Fatalf("initialize policy engine: %v", err)
+ }
+
+ res, err := engine.EvaluateTrustPolicy(context.Background(), &trust, webIdentityContext("spiffe://example.org/ns/other/sa/x"))
+ if err != nil {
+ t.Fatalf("evaluate trust policy: %v", err)
+ }
+ if res.Effect != EffectDeny {
+ t.Errorf("a subject the trust policy does not allow got %s", res.Effect)
+ }
+
+ res, err = engine.EvaluateTrustPolicy(context.Background(), &trust, webIdentityContext("spiffe://example.org/ns/app/sa/app"))
+ if err != nil {
+ t.Fatalf("evaluate trust policy: %v", err)
+ }
+ if res.Effect != EffectAllow {
+ t.Errorf("the subject the trust policy allows got %s", res.Effect)
+ }
+ })
+ }
+}
+
+func TestEvaluateTrustPolicyExplicitDenyWins(t *testing.T) {
+ var trust PolicyDocument
+ doc := `{"Version":"2012-10-17","Statement":[
+ {"Effect":"Allow","Principal":{"Federated":"https://oidc.example"},"Action":["sts:AssumeRoleWithWebIdentity"]},
+ {"Effect":"Deny","Principal":{"Federated":"https://oidc.example"},"Action":["sts:AssumeRoleWithWebIdentity"],
+ "Condition":{"StringEquals":{"oidc:sub":"spiffe://example.org/ns/app/sa/app"}}}]}`
+ if err := json.Unmarshal([]byte(doc), &trust); err != nil {
+ t.Fatalf("parse test trust policy: %v", err)
+ }
+ engine := NewPolicyEngine()
+ if err := engine.Initialize(&PolicyEngineConfig{DefaultEffect: "Allow", StoreType: "memory"}); err != nil {
+ t.Fatalf("initialize policy engine: %v", err)
+ }
+ res, err := engine.EvaluateTrustPolicy(context.Background(), &trust, webIdentityContext("spiffe://example.org/ns/app/sa/app"))
+ if err != nil {
+ t.Fatalf("evaluate trust policy: %v", err)
+ }
+ if res.Effect != EffectDeny {
+ t.Errorf("explicit Deny did not win: %s", res.Effect)
+ }
+}Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
Gogithub.com/seaweedfs/seaweedfs |
Sin parche | — | — | — |
Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/seaweedfs/seaweedfs/security/advisories/GHSA-5vhw-52xr-8x4jLas referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
