diff --git a/CHANGELOG.md b/CHANGELOG.md index b325849..18bbe16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed +- **Operator, ACL conflicts:** the `ACLConflict` condition and the `KafkaAccessPolicy` webhook + rejection now say that the Deny is applied and the Allow is dropped, and the condition names + which side this resource holds. Since 1.1.0 they still said the whole ACL tuple was dropped. + ## [1.1.0] - 2026-11-11 ### Added diff --git a/internal/operator/reconcile/reconcile.go b/internal/operator/reconcile/reconcile.go index 6bb5ef4..1a47ed4 100644 --- a/internal/operator/reconcile/reconcile.go +++ b/internal/operator/reconcile/reconcile.go @@ -194,8 +194,9 @@ type ClusterACLView struct { // the AND-merge sees every owner's consent. clusterDefaults may be nil. // // Cross-resource Allow/Deny conflicts (which no single-resource validation can -// see) are resolved first-seen-wins, exactly as BuildDesiredSet documents: the -// conflicting tuple is dropped from the union. That is deliberate — the view +// see) are resolved first-seen-wins, exactly as BuildDesiredSet documents, and +// the Deny-first sort makes the Deny that first-seen survivor: the Allow is +// dropped from the union and the Deny is applied. That is deliberate — the view // must stay buildable so reconciles keep running; the conflict surfaces as // drift on the losing resource. func BuildClusterACLView(topics []*v1alpha1.KafkaTopic, policies []*v1alpha1.KafkaAccessPolicy, @@ -1435,7 +1436,8 @@ func setTerminalValidationFailedReasons(kind string, conds *[]metav1.Condition, // True (reason CrossResourceConflict) when this resource (kind/namespace/name) // is a party to any conflict in the view, naming the other party + subject; // else False (reason NoConflict). NON-terminal — informational only; the -// conflicting tuple is already dropped from the applied union (no flapping). +// view already resolved the conflict to the Deny (the Allow is dropped from +// the applied union, no flapping). // When view is nil (single-resource fallback), the condition is cleared. func setACLConflictCondition(conds *[]metav1.Condition, view *ClusterACLView, kind, namespace, name string, gen int64) { if view == nil { @@ -1446,17 +1448,17 @@ func setACLConflictCondition(conds *[]metav1.Condition, view *ClusterACLView, ki return c.SourceKind == kind && c.SourceNamespace == namespace && c.SourceName == name } for _, cf := range view.Conflicts { - var other access.ACL + var mine, other access.ACL switch { case isParty(cf.A): - other = cf.B + mine, other = cf.A, cf.B case isParty(cf.B): - other = cf.A + mine, other = cf.B, cf.A default: continue } - msg := fmt.Sprintf("ACL %s conflicts Allow/Deny with %s/%s/%s on the same tuple; the tuple is dropped from the applied set", - cf.Subject, other.SourceKind, other.SourceNamespace, other.SourceName) + msg := fmt.Sprintf("ACL %s: this resource's %s conflicts with the %s from %s/%s/%s on the same tuple; the Deny is applied and the Allow is not", + cf.Subject, mine.Permission, other.Permission, other.SourceKind, other.SourceNamespace, other.SourceName) setCond(conds, v1alpha1.CondACLConflict, metav1.ConditionTrue, reasonCrossResourceConflict, msg, gen) return } diff --git a/internal/operator/reconcile/reconcile_test.go b/internal/operator/reconcile/reconcile_test.go index d248647..7e9d171 100644 --- a/internal/operator/reconcile/reconcile_test.go +++ b/internal/operator/reconcile/reconcile_test.go @@ -2018,6 +2018,12 @@ func TestSetACLConflictConditionIsPartyAsA(t *testing.T) { if !strings.Contains(c.Message, "the-subject") { t.Fatalf("ACLConflict message = %q, want to contain subject %q", c.Message, "the-subject") } + // Party A holds the Allow: the message must say its Allow loses to the Deny. + for _, want := range []string{"this resource's Allow", "the Deny from KafkaAccessPolicy/ns1/policy-p1", "the Deny is applied and the Allow is not"} { + if !strings.Contains(c.Message, want) { + t.Fatalf("ACLConflict message = %q, want to contain %q", c.Message, want) + } + } } // TestSetACLConflictConditionIsPartyAsB verifies that when the resource is party @@ -2045,6 +2051,10 @@ func TestSetACLConflictConditionIsPartyAsB(t *testing.T) { if !strings.Contains(c.Message, "ns1/topic-t1") { t.Fatalf("ACLConflict message = %q, want to contain other party namespace/name %q", c.Message, "ns1/topic-t1") } + // Party B holds the Deny, which is the side that is applied. + if !strings.Contains(c.Message, "this resource's Deny conflicts with the Allow") { + t.Fatalf("ACLConflict message = %q, want it to name this resource's Deny against the Allow", c.Message) + } } // TestReconcileTopicACLConflictConditionTrue verifies that ReconcileTopic sets diff --git a/internal/operator/webhook/kafkaaccesspolicy_webhook.go b/internal/operator/webhook/kafkaaccesspolicy_webhook.go index dc133d1..1efcc5a 100644 --- a/internal/operator/webhook/kafkaaccesspolicy_webhook.go +++ b/internal/operator/webhook/kafkaaccesspolicy_webhook.go @@ -265,7 +265,7 @@ func (v *KafkaAccessPolicyValidator) checkConflict(ctx context.Context, pol *v1a return fmt.Errorf( "KafkaAccessPolicy %s/%s introduces an ACL conflict with %s %s/%s on subject %q: "+ "Allow/Deny disagreement on the same ACL tuple (spec §21); "+ - "the tuple will be dropped from the applied set — resolve the disagreement before admission", + "the operator would apply the Deny and drop the Allow — resolve the disagreement before admission", pol.Namespace, pol.Name, otherKind, otherNS, otherName, cf.Subject) } return nil