Skip to content

feat(auth): migrate from token-based to RAM signature authentication#65

Open
OhYee wants to merge 4 commits intomainfrom
feat-new-auth
Open

feat(auth): migrate from token-based to RAM signature authentication#65
OhYee wants to merge 4 commits intomainfrom
feat-new-auth

Conversation

@OhYee
Copy link
Member

@OhYee OhYee commented Mar 9, 2026

Migrate authentication mechanism from token-based approach to RAM signature authentication for enhanced security. The changes replace the existing access token system with Alibaba Cloud's Resource Access Management (RAM) signature verification, requiring users to configure access key ID and secret for API calls. Updates include implementation of RAM signature generation, modification of authentication endpoints with '-ram' suffix, and comprehensive updates to all API clients across runtime, sandbox, and toolset modules.

This migration affects all API interactions within the SDK, including data API operations, browser automation endpoints, and OpenAI integration points. The new authentication system provides improved security through signature-based verification while maintaining backward compatibility for existing configurations.

The changes also include updates to test suites to validate the new authentication flow and ensure proper handling of both authenticated and unauthenticated requests.

将身份验证机制从基于令牌的方式迁移到 RAM 签名身份验证,以提高安全性。更改将现有的访问令牌系统替换为阿里云资源访问管理 (RAM) 签名验证,要求用户为 API 调用配置访问密钥 ID 和密钥。更新包括实现 RAM 签名生成、使用 '-ram' 后缀修改身份验证端点,以及对运行时、沙箱和工具集模块中的所有 API 客户端进行全面更新。

此迁移会影响 SDK 内的所有 API 交互,包括数据 API 操作、浏览器自动化端点和 OpenAI 集成点。新的身份验证系统通过基于签名的验证提供增强的安全性,同时保持现有配置的向后兼容性。

这些更改还包括更新测试套件以验证新的身份验证流程,并确保正确处理经过身份验证和未经身份验证的请求。

Change-Id: I2585151e1acab0f476d9ba9ed909aabd212e5f2c

Thank you for creating a pull request to contribute to Serverless Devs agentrun-sdk-python code! Before you open the request please answer the following questions to help it be more easily integrated. Please check the boxes "[ ]" with "[x]" when done too.
Please select one of the PR types below to complete


Fix bugs

Bug detail

The specific manifestation of the bug or the associated issue.

Pull request tasks

  • Add test cases for the changes
  • Passed the CI test

Update docs

Reason for update

Why do you need to update your documentation?

Pull request tasks

  • Update Chinese documentation
  • Update English documentation

Add contributor

Contributed content

  • Code
  • Document

Content detail

if content_type == 'code' || content_type == 'document':
    please tell us `PR url`,like: https://github.com/Serverless-Devs/agentrun-sdk-python/pull/1
else:
    please describe your contribution in detail

Others

Reason for update

Why do you need to update your documentation?

OhYee and others added 4 commits March 9, 2026 14:43
Migrate authentication mechanism from token-based approach to RAM signature authentication for enhanced security. The changes replace the existing access token system with Alibaba Cloud's Resource Access Management (RAM) signature verification, requiring users to configure access key ID and secret for API calls. Updates include implementation of RAM signature generation, modification of authentication endpoints with '-ram' suffix, and comprehensive updates to all API clients across runtime, sandbox, and toolset modules.

This migration affects all API interactions within the SDK, including data API operations, browser automation endpoints, and OpenAI integration points. The new authentication system provides improved security through signature-based verification while maintaining backward compatibility for existing configurations.

The changes also include updates to test suites to validate the new authentication flow and ensure proper handling of both authenticated and unauthenticated requests.

将身份验证机制从基于令牌的方式迁移到 RAM 签名身份验证,以提高安全性。更改将现有的访问令牌系统替换为阿里云资源访问管理 (RAM) 签名验证,要求用户为 API 调用配置访问密钥 ID 和密钥。更新包括实现 RAM 签名生成、使用 '-ram' 后缀修改身份验证端点,以及对运行时、沙箱和工具集模块中的所有 API 客户端进行全面更新。

此迁移会影响 SDK 内的所有 API 交互,包括数据 API 操作、浏览器自动化端点和 OpenAI 集成点。新的身份验证系统通过基于签名的验证提供增强的安全性,同时保持现有配置的向后兼容性。

这些更改还包括更新测试套件以验证新的身份验证流程,并确保正确处理经过身份验证和未经身份验证的请求。

Change-Id: I2585151e1acab0f476d9ba9ed909aabd212e5f2c
Signed-off-by: OhYee <oyohyee@oyohyee.com>
…rmatting

Add explicit return None statements in ToolSet methods and improve code
formatting for better readability and consistency across the codebase.

在 ToolSet 方法中添加显式的返回语句并改进代码格式

在 ToolSet 方法中添加显式的 return None 语句,并改进代码格式以提高代码库的一致性和可读性。

Change-Id: Icd499f1ccb977bc443f690d81b0694535dc1b99a
Signed-off-by: OhYee <oyohyee@oyohyee.com>
The _get_openapi_base_url method was refactored to remove complex FC region
logic and simplify URL selection. The implementation now prioritizes
intranet URLs when available, falling back to internet URLs. This change
improves code readability and maintainability while maintaining the same
functional behavior.

Additionally, comprehensive test suites were added for RAM signature
helper functions, ControlAPI client methods, and exception handling to
ensure robust authentication and error management.

测试套件已增加以验证 RAM 签名辅助函数、ControlAPI 客户端方法和异常处理,
确保身份验证和错误管理的健壮性。

Change-Id: Ia9d8ff6d2bfd37ec858413f13686fcee8fd6d912
Signed-off-by: OhYee <oyohyee@oyohyee.com>
…endpoints

adds comprehensive RAM signature authentication support for both OpenAPI and MCP tool invocations. introduces automatic URL rewriting to -ram endpoints when targeting agentrun-data domains, dynamic signature generation per request, and proper header injection. enhances error handling with detailed logging for HTTP status failures and removes deprecated debug functions.

The implementation includes:
- httpx Auth handler for dynamic RAM signature calculation per request
- automatic URL rewriting from agentrun-data to -ram endpoints
- enhanced MCP session with RAM authentication support
- improved OpenAPI tool invocation with RAM signature injection
- better error logging for failed requests
- conditional intranet URL usage based on FC_REGION environment variable
- unified MCP URL resolution with fallback mechanisms

BREAKING CHANGE: replaces assertion-based error handling with ValueError exceptions in MCP URL resolution

feat(auth): 为 agentrun-data 端点实现 RAM 签名认证

为 OpenAPI 和 MCP 工具调用添加了全面的 RAM 签名认证支持。引入了自动 URL 重写为 -ram 端点、动态签名生成和适当的头信息注入。增强了错误处理并提供详细的 HTTP 状态失败日志,移除了已弃用的调试函数。

实现包括:
- 用于每个请求动态计算 RAM 签名的 httpx Auth 处理器
- 自动将 agentrun-data 重写为 -ram 端点的 URL
- 支持 RAM 认证的增强 MCP 会话
- 具有 RAM 签名注入的改进 OpenAPI 工具调用
- 针对失败请求的改进错误日志
- 基于 FC_REGION 环境变量的条件内网 URL 使用
- 具有回退机制的统一 MCP URL 解析

重大变更:将 MCP URL 解析中的断言错误处理替换为 ValueError 异常

BREAKING CHANGE: replaces assertion-based error handling with ValueError exceptions in MCP URL resolution

重大变更: 在 MCP URL 解析中将基于断言的错误处理替换为 ValueError 异常

Change-Id: I415cb816f44f6eca78b7165b96b1fce8fd7d3404
Co-authored-by: Copilot <copilot@github.com>
Signed-off-by: OhYee <oyohyee@oyohyee.com>
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.

1 participant