Skip to content

Conversation

@nihongye
Copy link
Contributor

What is the purpose of the change

Fix a security gap in Nacos 3.x where AI-related gRPC requests (e.g., AbstractMcpRequest, AbstractAgentRequest) are not properly authenticated, even when authentication is enabled. This change ensures that all incoming AI protocol requests go through the standard auth pipeline by adding a dedicated resource parser and registering it in the gRPC auth service.

Without this fix, unauthenticated clients could potentially access AI services if the gRPC port is exposed — a risk especially in multi-tenant or public-facing environments.

Related Issue: #13824

Brief changelog

  • Added AiGrpcResourceParser to parse namespace, group, and resource name from AbstractMcpRequest and AbstractAgentRequest.
  • Registered AiGrpcResourceParser under SignType.AI in GrpcProtocolAuthService.
  • Enhanced AiGrpcClient to initialize SecurityProxy with periodic token refresh (fix missing login scheduling).
  • Added comprehensive unit tests:
    • GrpcProtocolAuthServiceTest: added test cases for MCP and Agent request parsing.
    • AiGrpcResourceParserTest: implemented parameterized tests covering full context, null namespace, and empty name scenarios.

Verifying this change

  1. Unit Tests: All new and existing tests pass:
    mvn clean install -DskipITs

✅ GrpcProtocolAuthServiceTest.testParseResourceWithMcpType
✅ GrpcProtocolAuthServiceTest.testParseResourceWithAgentType
✅ AiGrpcResourceParserTest.testParse (parameterized across 9 cases)

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

  • Make sure there is a Github issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a Github issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Format the pull request title like [ISSUE #123] Fix UnknownException when host config not exist. Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add integration-test in test module.
  • Run mvn -B clean package apache-rat:check findbugs:findbugs -Dmaven.test.skip=true to make sure basic checks pass. Run mvn clean install -DskipITs to make sure unit-test pass. Run mvn clean test-compile failsafe:integration-test to make sure integration-test pass.

@CLAassistant
Copy link

CLAassistant commented Sep 17, 2025

CLA assistant check
All committers have signed the CLA.

@github-actions
Copy link

Thanks for your this PR. 🙏
Please check again for your PR changes whether contains any usage/api/configuration change such as Add new API , Add new configuration, Change default value of configuration.
If so, please add or update documents(markdown type) in docs/next/ for repository nacos-group/nacos-group.github.io


感谢您提交的PR。 🙏
请再次查看您的PR内容,确认是否包含任何使用方式/API/配置参数的变更,如:新增API新增配置参数修改默认配置等操作。
如果是,请确保在提交之前,在仓库nacos-group/nacos-group.github.io中的docs/next/目录下添加或更新文档(markdown格式)。

@nihongye nihongye force-pushed the fix_ai_grpc_auth_13824 branch from c0f1a13 to 5803eff Compare September 17, 2025 12:07
…requests

Resolves alibaba#13824

This commit adds support for authentication of AI-related gRPC requests
(AbstractMcpRequest and AbstractAgentRequest) in the Nacos auth module.

Key changes:
- Implement AiGrpcResourceParser to extract namespace, group and resource name
  from AI protocol requests.
- Register AiGrpcResourceParser under SignType.AI in GrpcProtocolAuthService.
- Add comprehensive unit tests using parameterized testing to cover both
  MCP and Agent request types, including edge cases (null/empty fields).
- Fix missing security token refresh in AiGrpcClient by initializing
  SecurityProxy with scheduled login task.

Ensures that all incoming AI gRPC requests are properly authenticated
when security is enabled, closing a previous authorization gap.
@nihongye nihongye force-pushed the fix_ai_grpc_auth_13824 branch from 5803eff to 86aa56e Compare September 18, 2025 01:56
@KomachiSion KomachiSion merged commit 006ffca into alibaba:develop Sep 18, 2025
3 checks passed
@KomachiSion KomachiSion added kind/bug Category issues or prs related to bug. area/Client Related to Nacos Client SDK labels Sep 18, 2025
@KomachiSion KomachiSion added this to the 3.1.0 milestone Sep 18, 2025
@wuyfee
Copy link

wuyfee commented Sep 18, 2025

$\color{red}{FAILURE}$
DETAILS
✅ - docker: success
❌ - deploy (standalone & cluster & standalone_auth): failure
❌ - e2e-java-test (standalone & cluster & standalone_auth): skipped
❌ - e2e-go-test (standalone & cluster): skipped
❌ - e2e-cpp-test (standalone & cluster): skipped
❌ - e2e-csharp-test (standalone & cluster): skipped
❌ - e2e-nodejs-test (standalone & cluster): skipped
❌ - e2e-python-test (standalone & cluster): skipped
✅ - clean (standalone & cluster & standalone_auth): success

@wuyfee
Copy link

wuyfee commented Sep 18, 2025

$\color{red}{FAILURE}$
DETAILS
✅ - docker: success
❌ - deploy (standalone & cluster & standalone_auth): failure
❌ - e2e-java-test (standalone & cluster & standalone_auth): skipped
❌ - e2e-go-test (standalone & cluster): skipped
❌ - e2e-cpp-test (standalone & cluster): skipped
❌ - e2e-csharp-test (standalone & cluster): skipped
❌ - e2e-nodejs-test (standalone & cluster): skipped
❌ - e2e-python-test (standalone & cluster): skipped
✅ - clean (standalone & cluster & standalone_auth): success

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/Client Related to Nacos Client SDK kind/bug Category issues or prs related to bug.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants