Skip to content

fix(admin): carry namespaceid on appauth delete events - #7962

Merged
Aias00 merged 1 commit into
apache:masterfrom
Duansg:fix-appauth-delete-namespace
Oct 23, 2026
Merged

Aias00 merged 1 commit into
apache:masterfrom
Duansg:fix-appauth-delete-namespace

Conversation

@Duansg

@Duansg Duansg commented Oct 21, 2026

Copy link
Copy Markdown
Member

What is the problem

AppAuthServiceImpl#delete built the AppAuthData of a DELETE event without a namespaceId, and published one event for the whole batch.

Data-changed listeners treat a null namespace as SYS_DEFAULT_NAMESPACE_ID:

  • Node-based sync (zookeeper / nacos / etcd / consul / apollo / polaris): AbstractNodeDataChangedListener#onAppAuthChanged builds the key prefix from default, so the key ns-A.<authDataId>.<appKey> is never deleted.
  • Websocket: WebsocketDataChangedListener groups by each item's namespace, so the DELETE message only reaches gateways of the default namespace.

Impact: after POST /appAuth/batchDelete in a non-default namespace (e.g. ns-A), gateways of ns-A keep the deleted appKey/secret, and signed requests with it are still accepted. If the default namespace has an app auth with the same appKey, that one is wrongly removed instead.

What this PR does

  • Set namespaceId on every AppAuthData of the DELETE event. A missing value on a legacy row falls back to SYS_DEFAULT_NAMESPACE_ID, the same default the listeners use, so the delete is never rolled back by an NPE.
  • Group the deleted app auths by namespace and publish one DataChangedEvent(APP_AUTH, DELETE, data, namespaceId) per namespace. A batch spanning several namespaces is no longer routed by its first item only (findFirst() in the node listeners).

Delivery timing is unchanged: DataChangedEventDispatcher still defers every event to afterCommit. In cluster mode, ClusterDataChangedEventForwarder already forwards the event's namespaceId to the master.

Tests

AppAuthServiceTest:

  • deleting in ns-A and in the default namespace keeps the namespace on both the event and its data
  • a mixed batch (ns-A ×2, ns-B, default) publishes exactly 3 events, each with only its own app auths
  • a row without a namespace falls back to the default namespace
  • no event is published for empty/null ids, missing records, or 0 / -1 affected rows

Make sure that:

  • You have read the contribution guidelines.
  • You submit test cases (unit or integration tests) that back your changes.
  • Your local test passed ./mvnw clean install -Dmaven.javadoc.skip=true.

@Aias00

Aias00 commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

/retest

@Aias00 Aias00 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: #7962 fix(admin): carry namespaceid on appauth delete events

Verdict: approved — cleanly fixes namespace data loss when deleting AppAuth records, ensuring multi-namespace cache eviction operates correctly on downstream gateways.

What I verified

  1. Problem:
    • In AppAuthServiceImpl.delete(List<String> ids), the previous implementation built AppAuthData without setting .namespaceId(...), and dispatched a single new DataChangedEvent(ConfigGroupEnum.APP_AUTH, DataEventTypeEnum.DELETE, appAuthData) without passing namespaceId.
    • In multi-namespace environments, gateways listening for namespace-scoped synchronization either ignored the deletion event or failed to evict auth credentials under non-default namespaces.
  2. Solution:
    • AppAuthData.builder() now preserves .namespaceId(...), defaulting blank or null IDs to Constants.SYS_DEFAULT_NAMESPACE_ID for legacy data compatibility.
    • Deleted records are partitioned via .collect(Collectors.groupingBy(AppAuthData::getNamespaceId)).
    • Separate, scoped DataChangedEvent instances with explicit namespaceId are published for each partition:
      namespaceDataList.forEach((namespaceId, dataList) -> eventPublisher.publishEvent(
              new DataChangedEvent(ConfigGroupEnum.APP_AUTH, DataEventTypeEnum.DELETE, dataList, namespaceId)));
  3. Test verification:
    • AppAuthServiceTest adds thorough unit tests:
      • testDeletePreservesNamespace: verifies single-namespace event emission.
      • testDeletePublishesOneEventPerNamespace: verifies multi-namespace batches emit distinct events per namespace with correct data payloads.
      • testDeleteFallsBackToDefaultNamespaceWhenMissing: checks fallback to default namespace.
      • Negative cases: empty/null IDs, unmapped IDs, and zero-row deletions do not publish events.
  4. CI:
    • Unit tests, pr_build, license check, CodeQL, and e2e passed.

@Aias00
Aias00 merged commit 76a0204 into apache:master Oct 23, 2026
47 of 67 checks passed
@Duansg
Duansg deleted the fix-appauth-delete-namespace branch October 23, 2026 07:34
@Aias00 Aias00 added this to the 2.7.2 milestone Nov 13, 2026
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.

2 participants