Skip to content

[fix][txn] Improve transaction admin checks - #26773

Merged
lhotari merged 1 commit into
apache:masterfrom
lhotari:improve-transaction-admin-checks
Sep 30, 2026
Merged

lhotari merged 1 commit into
apache:masterfrom
lhotari:improve-transaction-admin-checks

Conversation

@lhotari

@lhotari lhotari commented Sep 30, 2026

Copy link
Copy Markdown
Member

Motivation

The v3 transaction admin endpoints expose two kinds of information: coordinator-wide
data (coordinator list, coordinator stats and internal stats, transaction metadata and
slow transactions), which spans all tenants, and topic-scoped transaction buffer and
pending ack stats. Access checks for these endpoints were not consistent with other admin
endpoints: coordinator-wide reads did not require superuser access and the topic-scoped
stats endpoints only validated topic ownership, not the caller's permission on the topic.

Modifications

  • Require superuser access for the coordinator-wide read endpoints: listCoordinators,
    getCoordinatorStats (all or by id), getCoordinatorInternalStats,
    getTransactionMetadata and getSlowTransactions.
  • Check the GET_STATS topic operation before resolving the topic for the transaction
    buffer and pending ack stats endpoints, in the same way as other topic stats endpoints.
    Callers with produce or consume permission on the topic keep access.
  • Update TransactionAndSchemaAuthZTest to cover the expected access for these endpoints
    and remove the related TODOs.

Roles without the required permission now get an authorization error (HTTP 401) from
these endpoints.

Verifying this change

  • Make sure that the change passes the CI checks.

This change is covered by the updated TransactionAndSchemaAuthZTest, which verifies that
coordinator-wide reads are allowed for superusers and rejected for tenant admins and other
roles, and that the topic-scoped transaction stats endpoints require the GET_STATS topic
operation.

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

The v3 transaction admin endpoints did not check access consistently with
other admin endpoints: coordinator-wide reads did not require superuser
access, and the topic-scoped transaction buffer and pending ack stats
endpoints only validated topic ownership.

- Require superuser access for listCoordinators, getCoordinatorStats (all
  or by id), getCoordinatorInternalStats, getTransactionMetadata and
  getSlowTransactions.
- Check the GET_STATS topic operation before resolving the topic for the
  transaction buffer and pending ack stats endpoints. Roles with produce or
  consume permission on the topic keep access.
- Update TransactionAndSchemaAuthZTest to cover these endpoints and remove
  the related TODOs.

Roles without the required permission now get an authorization error
(HTTP 401) from these endpoints.

Assisted-by: Claude Code
@lhotari
lhotari merged commit c50739c into apache:master Sep 30, 2026
82 of 84 checks passed
ascentstream-bot pushed a commit to ascentstream/pulsar that referenced this pull request Oct 1, 2026
ascentstream-bot pushed a commit to ascentstream/pulsar that referenced this pull request Oct 2, 2026
Radiancebobo pushed a commit to Radiancebobo/pulsar that referenced this pull request Oct 8, 2026
crossoverJie added a commit to crossoverJie/pulsar-client-go that referenced this pull request Oct 15, 2026
TestTxn_TCClient read transaction metadata through the raw admin HTTP helper
(httpGet -> httpDo), which calls the plain-text web service without any
credentials, so the broker authenticates it as the "anonymous" role.

apache/pulsar#26773 ("Improve transaction admin checks", shipped in 4.2.5 and
5.0.0) added validateSuperUserAccess() to the transaction metadata admin
endpoint (GET /admin/v3/transactions/transactionMetadata/{mostSigBits}/{leastSigBits}).
The unauthenticated request is now rejected with HTTP 401, so transactionStats
fails and the test panics on the nil stats map.

Add an httpGetWithTLS helper that calls the TLS web service using the test
client certificate, whose CN ("admin") is a super-user role in standalone.conf,
and use it for the transaction metadata request.

Verified against Pulsar 4.2.4, 4.2.5 and 5.0.0.

Co-Authored-By: CodeBuddy Code <[email protected]>
nodece pushed a commit to apache/pulsar-client-go that referenced this pull request Oct 20, 2026
…ior changes (#1545)

* [fix][test] Make TestSetTopicAutoCreation tolerant of broker error message changes

The test asserted exact broker error strings, which broke when Pulsar
changed the messages:

- apache/pulsar#25163 (shipped in 4.2.5) relaxed the non-partitioned
  autoTopicCreation override validation and changed the rejection text from
  "[defaultNumPartitions] is not allowed to be set when the type is
  non-partition." to "[defaultNumPartitions] must be null, 0 or 1 when the
  type is non-partitioned."
- 5.0.0 changed the missing-tenant error from "Tenant does not exist" to
  "Namespace does not exist".

Replace the single exact-match `errReason` with an `errReasons` slice and
assert containment, so the test passes against both old and new broker
versions instead of being brittle to broker wording changes.

Verified against Pulsar 4.2.4, 4.2.5 and 5.0.0.

Co-Authored-By: CodeBuddy Code <[email protected]>

* [fix][test] Authenticate transaction metadata request as super-user

TestTxn_TCClient read transaction metadata through the raw admin HTTP helper
(httpGet -> httpDo), which calls the plain-text web service without any
credentials, so the broker authenticates it as the "anonymous" role.

apache/pulsar#26773 ("Improve transaction admin checks", shipped in 4.2.5 and
5.0.0) added validateSuperUserAccess() to the transaction metadata admin
endpoint (GET /admin/v3/transactions/transactionMetadata/{mostSigBits}/{leastSigBits}).
The unauthenticated request is now rejected with HTTP 401, so transactionStats
fails and the test panics on the nil stats map.

Add an httpGetWithTLS helper that calls the TLS web service using the test
client certificate, whose CN ("admin") is a super-user role in standalone.conf,
and use it for the transaction metadata request.

Verified against Pulsar 4.2.4, 4.2.5 and 5.0.0.

Co-Authored-By: CodeBuddy Code <[email protected]>

* [fix][test] Make TestPartitionState tolerant of removed stats field

apache/pulsar#26687 (PIP-379: Remove the classic Shared and Key_Shared
dispatcher implementations, shipped in 5.0.0) removed
consumersAfterMarkDeletePosition from the subscription stats. The broker no
longer serializes the field, so it unmarshals to a nil map instead of the
empty map the test asserted.

Assert the map is empty, which holds both for the old behavior (empty map)
and the new one (absent/nil).

Verified against Pulsar 4.2.4, 4.2.5 and 5.0.0.

Co-Authored-By: CodeBuddy Code <[email protected]>

* [fix][test] Address review feedback on admin test helpers

- httpGetWithTLS: give the HTTPS test client a 30s timeout so a stalled
  broker/network path cannot hang the test run.
- TestSetTopicAutoCreation: replace the unchecked `err.(rest.Error)` type
  assertion (which panics on transport/TLS errors) with `require.ErrorAs`.

Co-Authored-By: CodeBuddy Code <[email protected]>

* [fix][test] Cache the TLS admin HTTP client in test helper

Build the HTTPS client (key pair, CA pool) once via sync.Once and reuse it
across calls instead of rebuilding it on every request.

Co-Authored-By: CodeBuddy Code <[email protected]>

---------

Co-authored-by: CodeBuddy Code <[email protected]>
nodece pushed a commit to ascentstream/pulsar that referenced this pull request Nov 6, 2026
nodece pushed a commit to ascentstream/pulsar that referenced this pull request Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants