Skip to content

fix: correct permission target format to appId+env+namespace/cluster#5407

Merged
nobodyiam merged 5 commits intoapolloconfig:masterfrom
RooobinYe:fix/app-deletion-role-cleanup
Jun 16, 2025
Merged

fix: correct permission target format to appId+env+namespace/cluster#5407
nobodyiam merged 5 commits intoapolloconfig:masterfrom
RooobinYe:fix/app-deletion-role-cleanup

Conversation

@RooobinYe
Copy link
Copy Markdown
Member

@RooobinYe RooobinYe commented Jun 14, 2025

What's the purpose of this PR

Fixed the permission target ID format issue where cluster and namespace permissions were created with incorrect parameter order:

  • Fixed initClusterNamespaceRoles parameter order in AppService

This resolves the extra bug mentioned in issue #5392 where default permissions had incorrect format.

Which issue(s) this PR fixes:

Fixes #5392 extra bug

Brief changelog

Fixed

  • AppService: Fixed initClusterNamespaceRoles parameter order in app creation flow

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Read the Contributing Guide before making this pull request.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit tests to verify the code.
  • Run mvn clean test to make sure this pull request doesn't break anything.
  • Update the CHANGES log.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected the permission target format to use the pattern "appId+env+namespace/cluster" for improved accuracy.
  • Tests
    • Added new tests to verify the correct formatting of target IDs for namespaces and clusters with and without environment parameters.
  • Documentation
    • Updated release notes to document the bug fix related to permission target formatting.

Fixed the permission target ID format issue where cluster and namespace permissions were created with incorrect parameter order:

- buildClusterTargetId: now generates appId+env+clusterName (was appId+clusterName+env)
- buildNamespaceTargetId: now generates appId+env+namespaceName (was appId+namespaceName+env)
- Fixed initClusterNamespaceRoles parameter order in AppService

This resolves the extra bug mentioned in issue apolloconfig#5392 where default permissions had incorrect format.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jun 14, 2025

Walkthrough

This change updates the format of permission target IDs by adjusting the order of concatenated parameters in utility methods and their usages. It also adds new unit tests to verify the updated formatting logic and documents the bugfix in the release notes.

Changes

File(s) Change Summary
apollo-portal/src/main/java/com/ctrip/.../portal/service/AppService.java Changed parameter order for initClusterNamespaceRoles to match new target ID format.
apollo-portal/src/main/java/com/ctrip/.../portal/util/RoleUtils.java Updated buildNamespaceTargetId to concatenate parameters as appId+env+namespace.
apollo-portal/src/test/java/com/ctrip/.../portal/util/RoleUtilsTest.java Added tests for target ID formatting with and without environment and for clusters.
CHANGES.md Added a bugfix entry describing the corrected permission target format in release notes.

Sequence Diagram(s)

sequenceDiagram
    participant AppService
    participant RoleUtils
    participant RoleInitializationService

    AppService->>RoleUtils: buildNamespaceTargetId(appId, namespace, env)
    RoleUtils-->>AppService: returns "appId+env+namespace"
    AppService->>RoleInitializationService: initClusterNamespaceRoles(appId, env, cluster, userId)
Loading

Assessment against linked issues

Objective Addressed Explanation
Correct permission target format to prevent role confusion after app deletion and recreation (#5392)
Ensure role initialization uses the right target ID format for clusters and namespaces (#5392)
Add or update tests to verify new target ID formatting logic (#5392)

Suggested labels

lgtm

Suggested reviewers

  • nobodyiam
  • spaceluke

Poem

A hop, a skip, a string reformed,
With env and name now neatly conformed.
Bugs in the roles, now swept away,
As rabbits code and tests hold sway.
Release notes penned, the fix is clear—
Apollo hops ahead this year! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between be96d6b and c0fc329.

📒 Files selected for processing (1)
  • CHANGES.md (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • CHANGES.md
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build (8)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

- Add tests for buildNamespaceTargetId with and without env parameter
- Add tests for buildClusterTargetId method
- Verify correct parameter order: appId+env+namespaceName/clusterName
- Ensure the bug fix for permission format is properly tested
@RooobinYe
Copy link
Copy Markdown
Member Author

修改后:
图片

Add entry for PR apolloconfig#5407 to Apollo 2.5.0 changelog documenting the fix
for permission target format issue (appId+env+namespace/cluster order).
@RooobinYe RooobinYe marked this pull request as ready for review June 14, 2025 10:13
@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jun 14, 2025
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppService.java (1)

173-175: Duplicate logic – consider extracting to helper

Identical call inside the loop duplicates the logic above.
Minor, but extracting to a private method (or re-using createAppInRemote) clarifies intent and eases future changes.

apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/util/RoleUtilsTest.java (1)

41-56: Consolidate repetitive assertions via parameterised test

The three test methods have near-identical structure.
JUnit 5’s @ParameterizedTest (or JUnit 4’s Parameterized) would collapse this duplication and make future cases trivial to add.

Example sketch (JUnit 5):

@ParameterizedTest
@CsvSource({
  "app1,application,,app1+application",
  "app1,application,LOCAL,app1+LOCAL+application",
  "test-app,config,DEV,test-app+DEV+config"
})
void buildNamespaceTargetId(String appId, String ns, String env, String expected) {
  assertEquals(expected, RoleUtils.buildNamespaceTargetId(appId, ns, StringUtils.isBlank(env)?null:env));
}

Not blocking, but improves maintainability.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 17084ea and be96d6b.

📒 Files selected for processing (4)
  • CHANGES.md (1 hunks)
  • apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppService.java (2 hunks)
  • apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/RoleUtils.java (1 hunks)
  • apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/util/RoleUtilsTest.java (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/util/RoleUtilsTest.java (1)
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/RoleUtils.java (1)
  • RoleUtils (25-124)
🔇 Additional comments (2)
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppService.java (1)

145-147:

Details

✅ Verification successful

Good catch on parameter order – ensure all call-sites are aligned

The reorder now matches the (appId, env, clusterName, operator) signature.
Please run a quick scan to confirm no other invocations still use the old (appId, clusterName, env, …) order.


🏁 Script executed:

#!/bin/bash
# Find potential mis-ordered calls (env looks like a constant CLUSTER_NAME_DEFAULT etc.)
rg --line-number --context 2 $'initClusterNamespaceRoles\\([^,]+,[^,]+ConfigConsts\\.CLUSTER_NAME_DEFAULT' src/main/java

Length of output: 173


🏁 Script executed:

#!/bin/bash
# Search for all invocations of initClusterNamespaceRoles across Java files
rg --color=never --line-number --context 2 'initClusterNamespaceRoles' -g '*.java' .

Length of output: 8856


All initClusterNamespaceRoles invocations use the new parameter order

I scanned every call site of initClusterNamespaceRoles and confirmed they all now follow the (appId, env, clusterName, operator) signature. No instances of the old (appId, clusterName, env, …) order remain.

CHANGES.md (1)

17-18: Entry looks good

Release note clearly documents the behavioural change.

Comment on lines 109 to 111
public static String buildNamespaceTargetId(String appId, String namespaceName, String env) {
return STRING_JOINER.join(appId, namespaceName, env);
return STRING_JOINER.join(appId, env, namespaceName);
}
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.

💡 Verification agent

🧩 Analysis chain

Guard against blank env to avoid double separators

Joiner.skipNulls() omits null but not empty strings.
If callers pass "" (quite common when a variable is trimmed but not null-checked), the result will be
appId++namespaceName, producing an invalid target id and breaking ACL look-ups.

-  return STRING_JOINER.join(appId, env, namespaceName);
+  return STRING_JOINER.join(appId, StringUtils.isBlank(env) ? null : env, namespaceName);

(Use the existing org.apache.commons.lang3.StringUtils or your util of choice.)


🏁 Script executed:

#!/bin/bash
# Locate RoleUtils.java to confirm its path
echo "Searching for RoleUtils.java..."
fd --hidden --max-depth 4 RoleUtils.java

# Find definition of STRING_JOINER in RoleUtils.java
echo -e "\nDefinition of STRING_JOINER:"
rg -n "STRING_JOINER" apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/RoleUtils.java

# Show context around buildNamespaceTargetId method
echo -e "\nContext around buildNamespaceTargetId:"
rg -n "public static String buildNamespaceTargetId" -n apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/RoleUtils.java -A3

# Check for skipNulls usage in RoleUtils.java
echo -e "\nskipNulls occurrences:"
rg -n "skipNulls" apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/RoleUtils.java || echo "No skipNulls found in RoleUtils.java"

Length of output: 2364


Guard blank env in buildNamespaceTargetId to avoid double separators

Joiner.skipNulls() omits nulls but not empty strings—passing "" produces appId++namespaceName. Wrap env in a blank‐check so empty values are treated as null:

  • File: apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/RoleUtils.java
  • Lines: 109–111
@@ apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/RoleUtils.java:109
-  public static String buildNamespaceTargetId(String appId, String namespaceName, String env) {
-    return STRING_JOINER.join(appId, env, namespaceName);
-  }
+  public static String buildNamespaceTargetId(String appId, String namespaceName, String env) {
+    return STRING_JOINER.join(
+        appId,
+        StringUtils.isBlank(env) ? null : env,
+        namespaceName
+    );
+  }

• Make sure you have import org.apache.commons.lang3.StringUtils; at the top.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public static String buildNamespaceTargetId(String appId, String namespaceName, String env) {
return STRING_JOINER.join(appId, namespaceName, env);
return STRING_JOINER.join(appId, env, namespaceName);
}
public static String buildNamespaceTargetId(String appId, String namespaceName, String env) {
return STRING_JOINER.join(
appId,
StringUtils.isBlank(env) ? null : env,
namespaceName
);
}
🤖 Prompt for AI Agents
In
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/RoleUtils.java
around lines 109 to 111, the buildNamespaceTargetId method uses
STRING_JOINER.skipNulls() which does not skip empty strings, causing double
separators if env is blank. Fix this by checking if env is blank using
StringUtils.isBlank(env) and passing null instead of an empty string to
STRING_JOINER.join. Also ensure the import for
org.apache.commons.lang3.StringUtils is present at the top of the file.

Copy link
Copy Markdown
Member

@nobodyiam nobodyiam left a comment

Choose a reason for hiding this comment

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

Please also fix the conflicts.

image

Comment thread apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/RoleUtils.java Outdated
RooobinYe and others added 2 commits June 15, 2025 13:08
…rd compatibility

The previous change to buildNamespaceTargetId parameter order from
appId+namespaceName+env to appId+env+namespaceName would break existing
permission data stored in the database, causing permission checks to fail.

Reverted to original appId+namespaceName+env format to ensure backward
compatibility with existing deployments.
@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Jun 15, 2025
@RooobinYe
Copy link
Copy Markdown
Member Author

RooobinYe commented Jun 15, 2025

The erroneous modification has been reverted.

tldr: This PR fixes an incorrect parameter passed during a function call, which caused a database format error.

Please Take A Look, thank you.

Copy link
Copy Markdown
Member

@hezhangjian hezhangjian left a comment

Choose a reason for hiding this comment

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

LGTM

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jun 16, 2025
Copy link
Copy Markdown
Member

@nobodyiam nobodyiam left a comment

Choose a reason for hiding this comment

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

LGTM

@nobodyiam nobodyiam merged commit 7f69966 into apolloconfig:master Jun 16, 2025
8 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jun 16, 2025
@nobodyiam nobodyiam added this to the 2.5.0 milestone Feb 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

删除应用,没有同步删除ModifyNamespacesInCluster和ReleaseNamespacesInCluster的角色

3 participants