Add cross-field CRD validation for LldapUser and LldapMembership#33
Merged
Conversation
Refines the LldapUser CEL message to name the policies that require a
passwordSecretRef ('Manage' or 'InitialOnly'), and adds a stateless
validate_membership_references in lldap-operator-reconciler for matching
an LldapMembership's user/group against caller-supplied candidates.
Closes #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds the cross-field invariants the structural OpenAPI schema cannot express. The
LldapUseradmission-time CEL rule that requiresspec.passwordSecretRefwheneverspec.passwordPolicyisManageorInitialOnlyis preserved, with a refined error message that names the policies requiring the secret. ForLldapMembership, a stateless matcher (validate_membership_referencesinlldap-operator-reconciler) checks that a membership's referenced user/group exist among caller-supplied candidates within the same namespace and samelldap-operator.lukidoescode.com/lldap-instancelabel value. The validator has no kube client and no I/O — the future membership reconciler (#14) will list candidates and feed them in.Negative and positive CEL evaluation tests now run against the actual rule expressions via
cel-interpreter, replacing the previous rule-text-presence-only coverage. The CRD reference docs gain a## Validation Rulessection on theLldapUserandLldapMembershippages describing both admission-time and reconcile-time checks.Decisions Made
kubectl apply.lldap-operator-reconciler, notlldap-operator-crds. Although the matcher is pure, its concern is reconciliation semantics; the CRD crate stays a pure schema crate.MembershipReference,UserCandidate,GroupCandidate), not onObjectMetaor the CRD wrappers. This keepslldap-operator-reconcilerfree ofk8s-openapiandlldap-operator-crdsas production deps; the adapter (ObjectMeta+ spec → candidate) lives at the boundary in whatever code wires the reconciler.UserNotFound/GroupNotFoundare hard errors at the validator level. The future membership reconciler (Membership Reconciler #14) translates them into aPendingcondition + requeue at the call site; the validator itself does not bake in retry semantics. Noted on Membership Reconciler #14.MissingNamespace/MissingInstanceLabelvariants on the error enum. Those are caller pre-conditions: aMembershipReferencecannot be constructed without all four borrowed strings.CRD / API Compatibility
LldapUserCRD: thex-kubernetes-validationsmessage for the password-secret rule changes wording. The rule expression and rejection semantics are unchanged; only the human-readable error text differs. No stored-version migration; existing valid resources remain valid.lldap-operator-reconciler:MembershipReference,UserCandidate,GroupCandidate,MembershipValidationError,validate_membership_references. The crate was previously empty, so this is additive only.Risks and Mitigations
crd_yaml_snapshottest compares generated CRD YAML against the committed chart files and fails CI on divergence;cargo run -p lldap-operator-crds --bin crdgenregenerates them.LldapMembershipdocumentation states the constraint and Membership Reconciler #14 carries the wiring task with a comment pointing implementers atvalidate_membership_referencesand theUserNotFound→Pending/requeue translation.cel-interpreter-based unit tests that evaluate each rule against constructed positive and negativeselfpayloads, so any future edit that breaks the intended semantics fails tests rather than silently shipping.Rollback Strategy
Revert this commit. The CEL message change is cosmetic at the API-server layer — older chart versions ship the previous message text and continue to enforce identical semantics. The new
lldap-operator-reconcilersymbols have no in-tree callers yet, so rolling them back removes nothing operationally.Verification
cargo fmt --all -- --check— cleancargo clippy --workspace --all-targets -- -D warnings— cleancargo clippy --workspace --all-targets --tests -- -D warnings— cleancargo test --workspace— 103 tests pass (67 inlldap-operator-crdsincluding 13 new CEL eval tests; 8 inlldap-operator-reconcilercovering everyMembershipValidationErrorvariant and theIntoIteratorsignature)cargo changeset verify --base main— all changed crates have changeset coveragegrep 'passwordSecretRef is required' charts/lldap-operator/crds/lldap-user.yamlconfirms the refined message in the generated CRD YAML