Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion AgileConfig.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.6.33801.468
Expand Down Expand Up @@ -60,6 +60,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AgileConfig.Server.Applicat
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AgileConfig.Server.ApplicationTests", "test\AgileConfig.Server.ApplicationTests\AgileConfig.Server.ApplicationTests.csproj", "{0AF33559-2F97-4F77-B8E4-859B6A341BA8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AgileConfig.Server.Data.MongodbTests", "test\AgileConfig.Server.Data.MongodbTests\AgileConfig.Server.Data.MongodbTests.csproj", "{CE8930D4-1D11-4DD1-8A43-45AEA1072113}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -154,6 +156,10 @@ Global
{0AF33559-2F97-4F77-B8E4-859B6A341BA8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0AF33559-2F97-4F77-B8E4-859B6A341BA8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0AF33559-2F97-4F77-B8E4-859B6A341BA8}.Release|Any CPU.Build.0 = Release|Any CPU
{CE8930D4-1D11-4DD1-8A43-45AEA1072113}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CE8930D4-1D11-4DD1-8A43-45AEA1072113}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CE8930D4-1D11-4DD1-8A43-45AEA1072113}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CE8930D4-1D11-4DD1-8A43-45AEA1072113}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -181,6 +187,7 @@ Global
{899F5AAE-2C6F-4F0A-9358-6F5C7D0412DC} = {1D2FD643-CB85-40F9-BC8A-CE4A39E9F43E}
{CA724F53-FA58-44CC-B0E7-5FD05CF5E63E} = {1D2FD643-CB85-40F9-BC8A-CE4A39E9F43E}
{0AF33559-2F97-4F77-B8E4-859B6A341BA8} = {F277EC27-8C0E-4490-9645-F5F3244F9246}
{CE8930D4-1D11-4DD1-8A43-45AEA1072113} = {F277EC27-8C0E-4490-9645-F5F3244F9246}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7F10DB58-5B6F-4EAC-994F-14E8046B306F}
Expand Down
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,40 @@ sudo docker run \

After the docker instance has successfully started you can visit http://localhost:5000 .

#### Connect to MongoDB with a private CA (self-signed certificate)

When the MongoDB server certificate is signed by a private CA (for example a self-hosted replica set),
pass that CA to AgileConfig. Otherwise the driver fails with
`The remote certificate is invalid because of errors in the certificate chain: UntrustedRoot`.

Two equivalent ways:

```shell
# 1) connection string option, the same form mongosh and the other official drivers accept
-e db__conn="mongodb://user:pwd@mdb1.example.com:27017/db?replicaSet=rs0&authSource=admin&tls=true&tlsCAFile=/certs/ca.crt" \
-v /host/path/ca.crt:/certs/ca.crt:ro \

# 2) dedicated setting, keeps the connection string portable across environments
-e db__tls__caFile=/certs/ca.crt \
-v /host/path/ca.crt:/certs/ca.crt:ro \
```

| Setting | Environment variable | Description |
|---|---|---|
| `db:tls:caFile` | `db__tls__caFile` | Path of the CA file (PEM or DER). A relative path resolves against the application directory. Mount the file into the container first. |
| `db:tls:ca` | `db__tls__ca` | Inline CA content: PEM (write line breaks as `\n`) or Base64 encoded DER. Useful when the certificate is injected as a secret instead of a file. |
| `db:tls:allowInvalidHostnames` | `db__tls__allowInvalidHostnames` | Skip the host name check only; chain validation still applies. |
| `db:tls:allowInvalidCertificates` | `db__tls__allowInvalidCertificates` | Skip certificate validation completely. Debug only. |
| `db:tls:checkCertificateRevocation` | `db__tls__checkCertificateRevocation` | Check CRL / OCSP while building the chain from `caFile` / `ca`. |

> - When none of them is set, the behavior is identical to previous versions (the OS trust store is used).
> - The boolean options default to `false` and never enable TLS on their own. When custom TLS settings are effective (for example a CA is configured), TLS is enabled automatically unless the connection string explicitly says `tls=false` (or `ssl=false`), which always wins.
> - Rebuilt certificate chains keep the serverAuth (`1.3.6.1.5.5.7.3.1`) usage constraint, so a certificate that only allows clientAuth is still rejected.
> - Per environment override: `db:env:{TEST|STAGING|PROD}:tls:*`; a missing key falls back to `db:tls:*`.
> - `tlsCAFile`, `tlsAllowInvalidCertificates` and `tlsAllowInvalidHostnames` (including the legacy `ssl` prefix) are recognized by AgileConfig and stripped from the connection string before it reaches the .NET driver, which does not support them natively. All other options are passed through.
> - Client certificates (mTLS, `tlsCertificateKeyFile`) are not supported yet; a clear error is returned.
> - The private CA is additional trust: certificates already trusted by the OS still work.

## use client
install client lib from nuget:
```
Expand Down
60 changes: 58 additions & 2 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ AgileConfig的节点都是无状态的,所以可以横向部署多个节点来
有同学说你这样没什么卵用,数据库还是单点的,一旦数据库崩了,同样GG。但是数据库有数据库的高可用技术,比如mysql的binlog等等。至于数据库的高可用还是让数据库自己搞定吧。从架构上看携程的apollo数据库也是单点的。
## 部署服务端
## 初始化数据库
用户只需要手工建一个空库,所有的表在第一次启动的时候都会自动生成。目前支持sqlserver,mysql,sqlite, PostgreSql,Oracle 五种数据库。
用户只需要手工建一个空库,所有的表在第一次启动的时候都会自动生成。目前支持sqlserver,mysql,sqlite, PostgreSql,Oracle,MongoDB 六种数据库。
provider对照:
sqlserver = SqlServer
mysql = MySql
Expand All @@ -128,7 +128,7 @@ sudo docker run \
```
通过docker建立一个agile_config实例,其中有3个环境变量需要配置:
1. adminConsole 配置程序是否为管理控制台。如果为true则启用控制台功能,访问该实例会出现管理界面。
2. db__provider 配置程序的数据库类型。目前程序支持:sqlserver,mysql,sqlite, PostgreSql,Oracle 五种数据库。
2. db__provider 配置程序的数据库类型。目前程序支持:sqlserver,mysql,sqlite, PostgreSql,Oracle,MongoDB 六种数据库。
3. db__conn 配置数据库连接串

> 💥注意:如果通过IIS或者别的方式部署,请自行从主页上的[releases](https://github.com/dotnetcore/AgileConfig/releases)页面下载最新的部署包。如果自己使用源码编译,请先编译react-ui-antd项目把dist内的产物复制到apisite项目的wwwroot/ui目录下。调试的时候需要复制到bin目录下。
Expand Down Expand Up @@ -184,6 +184,62 @@ services:
networks:
net0:
```
### 连接启用 TLS 的 MongoDB(私有 CA / 自签证书)
MongoDB 使用私有 CA 签发服务端证书时(例如自建的三节点副本集),必须把这份 CA 交给 AgileConfig,否则会报
`The remote certificate is invalid because of errors in the certificate chain: UntrustedRoot`。

支持两种写法,任选其一。

**方式一:连接串参数**(与 `mongosh` 等官方客户端写法一致)

```shell
-e db__conn="mongodb://user:pwd@mdb1.example.com:27017/db?replicaSet=rs0&authSource=admin&tls=true&tlsCAFile=/certs/ca.crt" \
-v /host/path/ca.crt:/certs/ca.crt:ro \
```

**方式二:独立配置项**(推荐,连接串可以在不同环境间复用)

```shell
-e db__tls__caFile=/certs/ca.crt \
-v /host/path/ca.crt:/certs/ca.crt:ro \
```

完整示例:

```shell
sudo docker run \
--restart=always \
--name agile_config \
-e TZ=Asia/Shanghai \
-e adminConsole=true \
-e db__provider=mongodb \
-e db__conn="mongodb://root:password@mdb1.example.com:27017,mdb2.example.com:27017,mdb3.example.com:27017/AgileConfig?replicaSet=rs0&authSource=admin&tls=true" \
-e db__tls__caFile=/certs/ca.crt \
-v /host/path/ca.crt:/certs/ca.crt:ro \
-p 2371:5000 \
-d kklldog/agile_config:latest
```

配置项说明:

| 配置项 | 环境变量 | 说明 |
|---|---|---|
| `db:tls:caFile` | `db__tls__caFile` | CA 证书文件路径,支持 PEM / DER。相对路径基于程序目录解析。容器内必须先挂载该文件 |
| `db:tls:ca` | `db__tls__ca` | 直接内联 CA 内容。可为 PEM(换行写成 `\n`),也可为 Base64 编码的 DER,适合证书以 Secret 注入、无法挂载文件的场景 |
| `db:tls:allowInvalidHostnames` | `db__tls__allowInvalidHostnames` | 只跳过主机名校验,证书链校验仍然生效 |
| `db:tls:allowInvalidCertificates` | `db__tls__allowInvalidCertificates` | 完全跳过证书校验,仅用于排查问题,生产环境不要开启 |
| `db:tls:checkCertificateRevocation` | `db__tls__checkCertificateRevocation` | 使用 `caFile` / `ca` 建立证书链时是否检查 CRL / OCSP |

> 💥注意:
> - 未配置以上任何一项时,程序行为与旧版本完全一致(使用操作系统的默认信任库),不需要修改已有部署。
> - 三个布尔项默认就是 `false`,不会单独触发 TLS;只有自定义 TLS 配置真正生效时(例如配置了 CA),才会在连接串未显式写 `tls=false` 的情况下自动启用 TLS。连接串里显式的 `tls=false`(或 `ssl=false`)始终优先。
> - 重建证书链时会保留服务端用途约束(serverAuth `1.3.6.1.5.5.7.3.1`),仅包含 clientAuth 用途的证书仍会被拒绝。
> - 每个环境可以单独覆盖:`db:env:{TEST|STAGING|PROD}:tls:*`,未配置的项自动回退到全局 `db:tls:*`。
> - 连接串里的 `tlsCAFile`、`tlsAllowInvalidCertificates`、`tlsAllowInvalidHostnames`(含 `ssl` 前缀的旧写法)会被 AgileConfig 识别并从连接串中剥离后再交给 .NET 驱动——.NET 驱动本身不支持这些参数,其余参数原样透传。
> - 客户端证书(mTLS,`tlsCertificateKeyFile`)暂不支持,配置该参数会得到明确的错误提示。
> - `ca.crt` 只包含公钥,可以安全分发。容器内**只挂载 `ca.crt`**,不要挂载 CA 私钥或服务端私钥。
> - 私有 CA 是**追加信任**:操作系统已信任的公共证书依然可以连接,同一份配置可以在公网托管 MongoDB 与自建集群之间切换。

### 初始化管理员密码
第一次运行程序需要初始化超级管理员密码,超管用户名固定为 admin
![](https://static.xbaby.xyz/%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_20220821020958.png)
Expand Down
34 changes: 34 additions & 0 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,40 @@ sudo docker run \

After the docker instance has successfully started you can visit http://localhost:5000 .

#### Connect to MongoDB with a private CA (self-signed certificate)

When the MongoDB server certificate is signed by a private CA (for example a self-hosted replica set),
pass that CA to AgileConfig. Otherwise the driver fails with
`The remote certificate is invalid because of errors in the certificate chain: UntrustedRoot`.

Two equivalent ways:

```shell
# 1) connection string option, the same form mongosh and the other official drivers accept
-e db__conn="mongodb://user:pwd@mdb1.example.com:27017/db?replicaSet=rs0&authSource=admin&tls=true&tlsCAFile=/certs/ca.crt" \
-v /host/path/ca.crt:/certs/ca.crt:ro \

# 2) dedicated setting, keeps the connection string portable across environments
-e db__tls__caFile=/certs/ca.crt \
-v /host/path/ca.crt:/certs/ca.crt:ro \
```

| Setting | Environment variable | Description |
|---|---|---|
| `db:tls:caFile` | `db__tls__caFile` | Path of the CA file (PEM or DER). A relative path resolves against the application directory. Mount the file into the container first. |
| `db:tls:ca` | `db__tls__ca` | Inline CA content: PEM (write line breaks as `\n`) or Base64 encoded DER. Useful when the certificate is injected as a secret instead of a file. |
| `db:tls:allowInvalidHostnames` | `db__tls__allowInvalidHostnames` | Skip the host name check only; chain validation still applies. |
| `db:tls:allowInvalidCertificates` | `db__tls__allowInvalidCertificates` | Skip certificate validation completely. Debug only. |
| `db:tls:checkCertificateRevocation` | `db__tls__checkCertificateRevocation` | Check CRL / OCSP while building the chain from `caFile` / `ca`. |

> - When none of them is set, the behavior is identical to previous versions (the OS trust store is used).
> - The boolean options default to `false` and never enable TLS on their own. When custom TLS settings are effective (for example a CA is configured), TLS is enabled automatically unless the connection string explicitly says `tls=false` (or `ssl=false`), which always wins.
> - Rebuilt certificate chains keep the serverAuth (`1.3.6.1.5.5.7.3.1`) usage constraint, so a certificate that only allows clientAuth is still rejected.
> - Per environment override: `db:env:{TEST|STAGING|PROD}:tls:*`; a missing key falls back to `db:tls:*`.
> - `tlsCAFile`, `tlsAllowInvalidCertificates` and `tlsAllowInvalidHostnames` (including the legacy `ssl` prefix) are recognized by AgileConfig and stripped from the connection string before it reaches the .NET driver, which does not support them natively. All other options are passed through.
> - Client certificates (mTLS, `tlsCertificateKeyFile`) are not supported yet; a clear error is returned.
> - The private CA is additional trust: certificates already trusted by the OS still work.

## use client
install client lib from nuget:
```
Expand Down
14 changes: 14 additions & 0 deletions src/AgileConfig.Server.Apisite/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@
"db": {
"provider": "", //sqlite,mysql,sqlserver,npgsql,oracle,mongodb
"conn": "",
// MongoDB only. Validates a server certificate that is signed by a private / self-signed CA.
// The defaults below do not enable TLS and do not change the driver behavior; the OS trust
// store is used unless a CA or an option that needs the custom validator is configured.
// Environment variables: db__tls__caFile, db__tls__ca, db__tls__allowInvalidHostnames, ...
// Per environment override: db:env:{env}:tls:*
"tls": {
"caFile": "", // Path of the CA file (PEM or DER). Relative paths resolve against the app directory.
// In Docker mount it first: -v /host/ca.crt:/certs/ca.crt:ro and set db__tls__caFile=/certs/ca.crt
"ca": "", // Inline CA content: PEM (use \n for line breaks), or Base64 encoded DER.
// Useful when the certificate cannot be mounted as a file (e.g. injected as a secret).
"allowInvalidCertificates": false, // false is the default and never enables TLS by itself. Debug only.
"allowInvalidHostnames": false, // false is the default and never enables TLS by itself.
"checkCertificateRevocation": false // false is the default and never enables TLS by itself.
},
"env": {
"TEST": {
"provider": "", //sqlite,mysql,sqlserver,npgsql,oracle
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FreeSql" Version="3.5.303" />
<PackageReference Include="MongoDB.Bson" Version="3.10.0" />
<PackageReference Include="MongoDB.Bson" Version="3.13.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
Expand All @@ -10,7 +10,11 @@
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="10.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="10.0.0" />
<PackageReference Include="MongoDB.Analyzer" Version="2.0.0" />
<PackageReference Include="MongoDB.Driver" Version="3.10.0" />
<PackageReference Include="MongoDB.Driver" Version="3.13.0" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="AgileConfig.Server.Data.MongodbTests" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading
Loading