Skip to content

feat: Stabilisation#9

Open
adwk67 wants to merge 29 commits intomainfrom
feat/stabilise-opa-auth
Open

feat: Stabilisation#9
adwk67 wants to merge 29 commits intomainfrom
feat/stabilise-opa-auth

Conversation

@adwk67
Copy link
Member

@adwk67 adwk67 commented Mar 6, 2026

Part of #8
Fixes #2

N.B. Code changes - especially unit tests - done with support from Claude.

Summary: Stabilise OPA authorizer — permissions, coverage, and policy testing

Hook implementation

All pre* coprocessor hooks now route to OPA. Key changes vs the previous state:

  • OpType enum is added to every OPA request (GET, SCAN, PUT, DELETE, APPEND, INCREMENT, CHECK_AND_PUT, CHECK_AND_DELETE, ROW_MUTATIONS, NONE), allowing Rego policies to restrict access by
    operation type. OpType serialises using Jackson's default enum .name() (uppercase), so acl.operations entries in Rego must also be uppercase (e.g. ["EXISTS", "GET", "SCAN", "NONE"])
  • families map ({ familyName: [qualifier, ...] }) passed on all region-level requests, enabling column-family-level policy decisions
  • preCheckAndMutate now explicitly handles RowMutations (previously fell through unchecked); the deprecated ByteArrayComparable and Filter-based preCheckAndPut/preCheckAndDelete overloads are
    implemented because HBase's default preCheckAndMutate delegates to them
  • Read-then-write operations (APPEND, INCREMENT, CHECK_AND_PUT, CHECK_AND_DELETE) enforce both READ and WRITE
  • All hook permissions are now aligned with the HBase 2.6.4 reference AccessController (namespace scoping, action choices)
  • TestCoprocessorInterfaceCoverage — a reflection test that fails the build if any pre* hook is added to the interface without being explicitly overridden or excluded

Coverage summary

Dimension Detail
Hooks with OPA calls 49 / 49 (100%)
Intentional stubs 4 — preGrant, preRevoke, preExecuteProcedures, preHasUserPermissions
Intentionally excluded 2 — preClose, preGetTableDescriptors
Unit tests 96 tests across 3 classes (61 master, 33 region, 2 variant)
Only untested OPA hook preEndpointInvocation (requires a live protobuf Service stub)

OPA policy utility tests

There is a lightweight test layer that sits between the Java unit tests and the full kuttl integration tests, so that OPA JSON calls can be tested explicitly against Rego rules.

  • Call capture: OpaFixtureWriter registers as a WireMock ServeEventListener in each test class. After each class teardown it remaps the three canonical test principals to Rego-recognisable Kerberos
    names, deduplicates, and writes target/test-rego/fixtures.json — a single JSON document with allowed and denied arrays of captured OPA request bodies.
  • Rego policy source: src/test/rego/hbase.rego is a committed copy of the Rego policy from hbase-operator/tests/templates/kuttl/opa/12-rego-rules.txt.j2 with $NAMESPACE substituted to test-ns. It
    must be manually regenerated when the operator policy changes. The principal remapping in OpaFixtureWriter is intentionally aligned with the Kerberos principals used in the kuttl integration tests. This is
    a hard dependency between this component and the operator integration tests.
  • Maven integration: download-maven-plugin fetches a pinned OPA binary (v0.63.0) during process-test-resources; exec-maven-plugin runs opa test in the verify phase after Surefire. Fixtures live
    in target/ and are not committed.
  • Coverage: 3 principals — admin (allow-all), unknown (deny-all), readonlyuser (ro ACL with operation and family restrictions) — producing 41 fixtures (19 allowed, 22 denied). This exercises the
    matches_operation and matches_families non-null branches of the Rego policy, which correspond directly to the readonlyuser scenarios in the kuttl integration tests.

Tip

To test these changes, you can use a custom image oci.stackable.tech/sandbox/andrew/hbase:2.6.4-stackable0.0.0-dev in Harbor that contains these changes, along with an operator PR that extends the rego rules to increase the coverage.

adwk67 and others added 29 commits March 6, 2026 10:09
Describes a fast intermediate test layer that captures unit-test WireMock
payloads, remaps usernames to Rego-compatible principals, and validates the
Rego policy logic using the opa test CLI — without integration test overhead.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Five tasks: OpaFixtureWriter class, test wiring, Rego files,
Maven plugins (download-maven-plugin + exec-maven-plugin), and
end-to-end verification.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- OpaFixtureWriter writes to target/test-rego/fixtures.json (was
  src/test/rego/fixtures.json) so test runs no longer dirty the working tree
- pom.xml opa-policy-test execution updated to match new path
- hbase_test.rego: add print() calls so --explain notes reports fixture counts
- .gitignore: add /docs/plans/ (plan docs are local-only, not committed)
- Remove stale design doc and completed implementation plan from git

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
prePrepareBulkLoad, preCleanupBulkLoad, preBulkLoadHFile (region-level),
preLockHeartbeat, and preRequestLock (table, namespace, and region-scope
branches) were implemented but had no unit tests. Brings coverage from
83 to 90 passing tests.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@adwk67 adwk67 mentioned this pull request Mar 9, 2026
12 tasks
@adwk67 adwk67 marked this pull request as ready for review March 9, 2026 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Preview/extended version of opa-authorizer

1 participant