Skip to content

Conversation

@liuqian1990
Copy link
Contributor

🐛 Bug Fix - Commit Message

fix: resolve namespace isolation issue in rule import functionality

The rule import process was incorrectly triggering REFRESH events for all namespaces
instead of only the target namespace, causing cross-namespace event pollution.

Problem:

  • When importing rules to namespace A, all namespaces (A, B, C...) received REFRESH events
  • This was caused by using syncAll() which broadcasts to all namespaces
  • Violated namespace isolation principle

Solution:

  • Replace syncAll() with syncAllByNamespaceId() in import controller
  • Ensure only the target namespace receives REFRESH events
  • Maintain proper namespace isolation during rule import operations

Files Changed:

  • shenyu-admin/src/main/java/com/woo/shenyu/admin/controller/ConfigsExportImportController.java

Testing:

  • ✅ Import rules to namespace A - only namespace A receives events
  • ✅ Other namespaces (B, C) are unaffected
  • ✅ Namespace isolation is maintained

📋 GitHub Issue Description

Bug Report: Cross-Namespace Event Pollution During Rule Import

🐛 Bug Description

When importing rules to a specific namespace, the system incorrectly triggers REFRESH events for rules in ALL namespaces instead of only the target namespace.

🔍 Root Cause Analysis

The issue is in ConfigsExportImportController.java line 146:

// Problem: broadcasts to ALL namespaces
syncDataService.syncAll(DataEventTypeEnum.REFRESH);

The syncAll() method:
1. Fetches rules from ALL namespaces via ruleService.listAll()
2. Groups by namespace and sends events to each namespace
3. Causes namespace B to receive REFRESH events when importing to namespace A

🔧 Fix Applied

Replace the problematic call with namespace-specific synchronization:
// Solution: only sync target namespace
syncDataService.syncAllByNamespaceId(DataEventTypeEnum.REFRESH, namespace);

📊 Impact

- Before: Cross-namespace event pollution
- After: Proper namespace isolation
- Affected Component: Rule import functionality
- Severity: Medium (violates namespace isolation)

✅ Testing

- Import rules to namespace A - only A receives events
- Namespace B and C clients remain unaffected
- WebSocket event filtering works correctly
- No performance impact on other namespaces

📁 Files Modified

- shenyu-admin/src/main/java/com/woo/shenyu/admin/controller/ConfigsExportImportController.java

🏷️ Labels

- bug
- namespace
- websocket
- data-sync
- isolation

## 🚀 **Pull Request Title**
fix: resolve namespace isolation issue in rule import functionality

<!-- Describe your PR here; e.g. Fixes #issueNo -->

<!--
Thank you for proposing a pull request. This template will guide you through the essential steps necessary for a pull request.
-->
Make sure that:

- [ ] You have read the [contribution guidelines](https://shenyu.apache.org/community/contributor-guide).
- [ ] You submit test cases (unit or integration tests) that back your changes.
- [ ] Your local test passed `./mvnw clean install -Dmaven.javadoc.skip=true`.

  🐛 Bug Fix - Commit Message

  fix: resolve namespace isolation issue in rule import functionality

  The rule import process was incorrectly triggering REFRESH events for all namespaces
  instead of only the target namespace, causing cross-namespace event pollution.

  **Problem:**
  - When importing rules to namespace A, all namespaces (A, B, C...) received REFRESH events
  - This was caused by using `syncAll()` which broadcasts to all namespaces
  - Violated namespace isolation principle

  **Solution:**
  - Replace `syncAll()` with `syncAllByNamespaceId()` in import controller
  - Ensure only the target namespace receives REFRESH events
  - Maintain proper namespace isolation during rule import operations

  **Files Changed:**
  - shenyu-admin/src/main/java/com/woo/shenyu/admin/controller/ConfigsExportImportController.java

  **Testing:**
  - ✅ Import rules to namespace A - only namespace A receives events
  - ✅ Other namespaces (B, C) are unaffected
  - ✅ Namespace isolation is maintained

  📋 GitHub Issue Description

  # Bug Report: Cross-Namespace Event Pollution During Rule Import

  ## 🐛 **Bug Description**
  When importing rules to a specific namespace, the system incorrectly triggers REFRESH events for rules in ALL namespaces instead of only the target namespace.

  ## 🔍 **Root Cause Analysis**
  The issue is in `ConfigsExportImportController.java` line 146:
  ```java
  // Problem: broadcasts to ALL namespaces
  syncDataService.syncAll(DataEventTypeEnum.REFRESH);

  The syncAll() method:
  1. Fetches rules from ALL namespaces via ruleService.listAll()
  2. Groups by namespace and sends events to each namespace
  3. Causes namespace B to receive REFRESH events when importing to namespace A

  🔧 Fix Applied

  Replace the problematic call with namespace-specific synchronization:
  // Solution: only sync target namespace
  syncDataService.syncAllByNamespaceId(DataEventTypeEnum.REFRESH, namespace);

  📊 Impact

  - Before: Cross-namespace event pollution
  - After: Proper namespace isolation
  - Affected Component: Rule import functionality
  - Severity: Medium (violates namespace isolation)

  ✅ Testing

  - Import rules to namespace A - only A receives events
  - Namespace B and C clients remain unaffected
  - WebSocket event filtering works correctly
  - No performance impact on other namespaces

  📁 Files Modified

  - shenyu-admin/src/main/java/com/woo/shenyu/admin/controller/ConfigsExportImportController.java

  🏷️ Labels

  - bug
  - namespace
  - websocket
  - data-sync
  - isolation

  ## 🚀 **Pull Request Title**
  fix: resolve namespace isolation issue in rule import functionality
@liuqian1990 liuqian1990 changed the title Update ConfigsExportImportController.java [fix] fix config import Jul 11, 2025
moremind
moremind previously approved these changes Jul 15, 2025
@moremind moremind added this to the 2.7.0.2 milestone Jul 15, 2025
@Aias00
Copy link
Contributor

Aias00 commented Jul 16, 2025

hi, fix ci, pls

@Aias00 Aias00 merged commit 2627a12 into apache:master Jul 19, 2025
60 of 62 checks passed
@Aias00
Copy link
Contributor

Aias00 commented Jul 19, 2025

hi, add my wechat: aias00

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.

3 participants