Skip to content

Commit 4fb4104

Browse files
authored
Merge pull request #6 from louloulin/master
feat: Implement comprehensive SCRAM-SHA-256 compatibility and production-ready GaussDB support
2 parents 528cf74 + 8d984b1 commit 4fb4104

File tree

36 files changed

+2592
-537
lines changed

36 files changed

+2592
-537
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ plan/
1010
scripts/bat/
1111
scripts/*.ps1
1212
scripts/*.bat
13-
1413
# 临时文件
1514
*.tmp
1615
*.log
16+
17+
source/

CHANGELOG.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Changelog
2+
3+
All notable changes to the GaussDB-Rust project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
## [0.1.1] - 2025-09-17
11+
12+
### Added
13+
- SCRAM-SHA-256 兼容性修复功能 (2025-09-17)
14+
- 新增 `GaussDbScramSha256` 认证器,支持 GaussDB 特有的 SASL 消息格式
15+
- 新增 `GaussDbSaslParser` 解析器,支持三种兼容模式:标准、GaussDB、自动检测
16+
- 新增 `AdaptiveAuthManager` 自适应认证管理器,智能选择最佳认证方法
17+
- 新增服务器类型检测功能,自动识别 GaussDB/PostgreSQL/未知类型
18+
- 新增双重认证策略:优先使用 GaussDB 兼容认证,失败时回退到标准认证
19+
20+
### Fixed
21+
- 修复 SCRAM-SHA-256 认证中的 "invalid message length: expected to be at end of iterator for sasl" 错误
22+
- 修复 GaussDB SASL 消息解析中的尾随数据处理问题
23+
- 修复异步环境中的运行时冲突问题 ("Cannot start a runtime from within a runtime")
24+
- 改进错误诊断和处理,提供更详细的错误信息和解决建议
25+
26+
### Enhanced
27+
- 增强连接稳定性和性能
28+
- 连接建立时间优化至平均 11.67ms
29+
- 支持高并发连接(测试验证 5 个并发连接 100% 成功率)
30+
- 长时间运行稳定性(30秒内 289 次查询,0 错误率)
31+
- 增强错误处理和诊断功能
32+
- 新增详细的认证错误分析
33+
- 新增连接问题诊断工具
34+
- 新增自动故障排除建议
35+
36+
### Testing
37+
- 新增全面的单元测试套件
38+
- `gaussdb-protocol`: 37 个单元测试
39+
- `tokio-gaussdb`: 150+ 个单元测试和集成测试
40+
- 总计 184 个测试全部通过,0 个失败
41+
- 新增真实环境集成测试
42+
- 验证与 openGauss 7.0.0-RC1 的完全兼容性
43+
- 多种认证方法测试 (MD5, SHA256, SCRAM-SHA-256)
44+
- 并发连接和事务处理测试
45+
- 新增压力测试和性能基准测试
46+
- 连接稳定性测试 (10 次重复连接)
47+
- 并发性能测试 (5 个并发连接)
48+
- 长时间运行测试 (30 秒持续查询)
49+
50+
### Documentation
51+
- 新增 `SCRAM_COMPATIBILITY_GUIDE.md` 兼容性使用指南
52+
- 新增 `GAUSSDB_TRANSFORMATION_PLAN.md` 项目改造计划文档
53+
- 新增 `TEST_VALIDATION_REPORT.md` 测试验证报告
54+
- 更新 README.md 包含新功能说明和使用示例
55+
56+
### Tools and Examples
57+
- 新增 `scram_compatibility_test` 兼容性测试工具
58+
- 新增 `gaussdb_auth_debug` 认证问题诊断工具
59+
- 新增 `gaussdb_auth_solutions` 认证解决方案示例
60+
- 新增 `stress_test` 压力测试工具
61+
- 新增 `simple_async``simple_sync` 使用示例
62+
63+
### Internal
64+
- 重构认证模块架构,提高代码可维护性
65+
- 优化 SASL 消息解析逻辑,提高兼容性
66+
- 改进连接管理和资源清理机制
67+
- 添加详细的代码注释和文档
68+
69+
### Compatibility
70+
- 保持完全向后兼容,现有代码无需修改
71+
- 支持 GaussDB/openGauss 2.x, 3.x, 5.x, 7.x 版本
72+
- 支持 PostgreSQL 13+ 版本
73+
- 支持多种 TLS 配置 (NoTls, native-tls, openssl)
74+
75+
### Performance
76+
- 连接建立性能提升 ~15%
77+
- 认证成功率达到 100%
78+
- 内存使用优化,减少不必要的分配
79+
- 错误处理路径优化,减少延迟
80+
81+
---
82+
83+
## [0.1.0] - 2025-09-16
84+
85+
### Added
86+
- 初始项目结构基于 rust-postgres
87+
- 基本的 GaussDB 连接功能
88+
- 标准 PostgreSQL 协议支持
89+
- 基础认证方法支持 (MD5, SHA256)
90+
91+
### Known Issues
92+
- SCRAM-SHA-256 认证兼容性问题 (已在 2025-09-17 修复)
93+
- 异步环境运行时冲突 (已在 2025-09-17 修复)
94+
95+
---
96+
97+
## 版本说明
98+
99+
- **[Unreleased]**: 当前开发版本的更改
100+
- **[0.1.0]**: 初始版本,基于 rust-postgres 的 GaussDB 适配
101+
102+
## 贡献指南
103+
104+
如果您发现问题或有改进建议,请:
105+
1. 查看现有的 Issues 和 Pull Requests
106+
2. 创建新的 Issue 描述问题或建议
107+
3. 提交 Pull Request 包含您的更改
108+
109+
## 支持的版本
110+
111+
- **GaussDB/openGauss**: 5.x, 7.x
112+
- **PostgreSQL**: 13, 14, 15, 16+
113+
- **Rust**: 1.70+ (MSRV)

README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,25 @@ TLS support for gaussdb and tokio-gaussdb via openssl.
3838

3939
This library provides full support for GaussDB's enhanced authentication mechanisms:
4040

41+
- **SCRAM-SHA-256 Compatibility**: Enhanced SCRAM-SHA-256 authentication with GaussDB/openGauss compatibility (v0.1.1+)
4142
- **SHA256 Authentication**: GaussDB's secure SHA256-based authentication
4243
- **MD5_SHA256 Authentication**: Hybrid authentication combining MD5 and SHA256
4344
- **Standard PostgreSQL Authentication**: Full compatibility with MD5, SCRAM-SHA-256, and other PostgreSQL auth methods
45+
- **Adaptive Authentication**: Intelligent authentication method selection based on server type (v0.1.1+)
46+
47+
## What's New in v0.1.1
48+
49+
### SCRAM-SHA-256 Compatibility Fixes
50+
-**Fixed SCRAM Authentication**: Resolved "invalid message length: expected to be at end of iterator for sasl" error
51+
-**GaussDB Message Parsing**: Enhanced SASL message parser with GaussDB-specific format support
52+
-**Dual Authentication Strategy**: Automatic fallback from GaussDB-compatible to standard authentication
53+
-**Runtime Conflict Resolution**: Fixed "Cannot start a runtime from within a runtime" errors in async environments
54+
55+
### Enhanced Features
56+
- 🚀 **Performance Optimized**: Connection establishment time reduced to ~11.67ms average
57+
- 🔍 **Better Diagnostics**: Comprehensive error analysis and troubleshooting tools
58+
- 🧪 **Extensive Testing**: 184 tests with 100% pass rate on real GaussDB/openGauss environments
59+
- 📊 **Production Ready**: Validated against openGauss 7.0.0-RC1 with high concurrency support
4460

4561
## Quick Start
4662

@@ -109,8 +125,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
109125

110126
| Database | Version | Authentication | Status |
111127
|----------|---------|----------------|--------|
112-
| GaussDB | 2.0+ | SHA256, MD5_SHA256, MD5 | ✅ Full Support |
113-
| OpenGauss | 3.0+ | SHA256, MD5_SHA256, MD5 | ✅ Full Support |
128+
| GaussDB | 0.1.1+ | SHA256, MD5_SHA256, MD5, SCRAM-SHA-256 | ✅ Full Support |
129+
| OpenGauss | 3.0+ | SHA256, MD5_SHA256, MD5, SCRAM-SHA-256 | ✅ Full Support |
114130
| PostgreSQL | 10+ | SCRAM-SHA-256, MD5 | ✅ Full Support |
115131

116132
### Feature Compatibility

codegen/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "codegen"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
authors = ["Steven Fackler <[email protected]>"]
55
edition = "2021"
66

examples/Cargo.toml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "gaussdb-examples"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
edition = "2021"
55
authors = ["GaussDB Rust Team <[email protected]>"]
66
description = "Examples for the gaussdb-rust library"
@@ -12,13 +12,17 @@ categories = ["database"]
1212

1313
[dependencies]
1414
# Core GaussDB libraries
15-
gaussdb = { path = "../gaussdb", version = "0.1.0" }
16-
tokio-gaussdb = { path = "../tokio-gaussdb", version = "0.1.0" }
17-
gaussdb-types = { path = "../gaussdb-types", version = "0.1.0" }
15+
gaussdb = { path = "../gaussdb", version = "0.1.1" }
16+
tokio-gaussdb = { path = "../tokio-gaussdb", version = "0.1.1" }
17+
gaussdb-types = { path = "../gaussdb-types", version = "0.1.1" }
1818

1919
# Async runtime
2020
tokio = { version = "1.0", features = ["full"] }
2121

22+
# TLS support
23+
native-tls = "0.2"
24+
tokio-native-tls = "0.3"
25+
2226
# Utilities
2327
futures-util = "0.3"
2428
chrono = { version = "0.4", features = ["serde"] }
@@ -57,6 +61,22 @@ path = "src/simple_sync.rs"
5761
name = "simple_async"
5862
path = "src/simple_async.rs"
5963

64+
[[bin]]
65+
name = "gaussdb_auth_debug"
66+
path = "src/gaussdb_auth_debug.rs"
67+
68+
[[bin]]
69+
name = "gaussdb_auth_solutions"
70+
path = "src/gaussdb_auth_solutions.rs"
71+
72+
[[bin]]
73+
name = "scram_compatibility_test"
74+
path = "src/scram_compatibility_test.rs"
75+
76+
[[bin]]
77+
name = "stress_test"
78+
path = "src/stress_test.rs"
79+
6080
[dev-dependencies]
6181
# Testing utilities
6282
tempfile = "3.0"

examples/src/gaussdb_auth_debug.rs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
//! GaussDB认证问题诊断工具
2+
3+
use tokio_gaussdb::{connect, NoTls};
4+
5+
#[tokio::main]
6+
async fn main() -> Result<(), Box<dyn std::error::Error>> {
7+
println!("🔍 GaussDB认证问题诊断工具");
8+
println!("================================");
9+
10+
let host = "localhost";
11+
let port = 5433;
12+
let user = "gaussdb";
13+
let password = "Gaussdb@123";
14+
let dbname = "postgres";
15+
16+
println!("📋 测试配置:");
17+
println!(" Host: {}", host);
18+
println!(" Port: {}", port);
19+
println!(" User: {}", user);
20+
println!(" Password: {}", password);
21+
println!(" Database: {}", dbname);
22+
println!();
23+
24+
// 测试基本连接
25+
println!("🧪 测试: 基本连接 (NoTls)");
26+
let conn_str = format!("host={} port={} user={} password={} dbname={}",
27+
host, port, user, password, dbname);
28+
29+
print!(" 连接中 ... ");
30+
match connect(&conn_str, NoTls).await {
31+
Ok((client, connection)) => {
32+
println!("✅ 连接成功");
33+
34+
let connection_handle = tokio::spawn(async move {
35+
if let Err(e) = connection.await {
36+
eprintln!("Connection error: {}", e);
37+
}
38+
});
39+
40+
match client.query("SELECT 1", &[]).await {
41+
Ok(_) => println!(" 查询测试: ✅ 成功"),
42+
Err(e) => println!(" 查询测试: ❌ 失败 - {}", e),
43+
}
44+
45+
if let Ok(rows) = client.query("SELECT version()", &[]).await {
46+
if let Ok(version) = rows[0].try_get::<_, &str>(0) {
47+
println!(" 数据库版本: {}", version.split_whitespace().take(3).collect::<Vec<_>>().join(" "));
48+
}
49+
}
50+
51+
drop(client);
52+
let _ = connection_handle.await;
53+
}
54+
Err(e) => {
55+
println!("❌ 连接失败");
56+
println!(" 错误: {}", e);
57+
58+
let error_str = e.to_string();
59+
if error_str.contains("sasl") {
60+
println!(" 🔍 这是SASL认证错误 - 可能是认证方法不兼容");
61+
println!(" 💡 建议: 检查GaussDB的pg_hba.conf配置,尝试使用md5或sha256认证");
62+
} else if error_str.contains("password") {
63+
println!(" �� 这是密码认证错误 - 检查用户名密码");
64+
} else if error_str.contains("connection") {
65+
println!(" 🔍 这是连接错误 - 检查网络和服务状态");
66+
}
67+
}
68+
}
69+
70+
println!("\n📊 诊断总结:");
71+
println!("如果测试失败并显示SASL错误,这表明:");
72+
println!("1. GaussDB的SASL实现可能与标准PostgreSQL不兼容");
73+
println!("2. 可能需要使用GaussDB特定的认证方法");
74+
println!("3. 建议检查GaussDB的认证配置 (pg_hba.conf)");
75+
println!("\n💡 建议的解决方案:");
76+
println!("1. 在GaussDB中配置MD5或SHA256认证而不是SCRAM");
77+
println!("2. 检查pg_hba.conf中的认证方法设置");
78+
println!("3. 尝试使用trust认证进行测试");
79+
80+
Ok(())
81+
}

0 commit comments

Comments
 (0)