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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ All notable changes to RustFS Operator are documented in this file. The format i

### Added

- Full mutual TLS (client-to-Pod and Pod-to-Pod) support when `caTrust.clientCaSecretRef` is
configured with cert-manager, including client certificate/key volume projections, automatic
`client auth` usage on managed default certificates, mTLS-aware container probes, and operator
admin/STS client certificate authentication.
- Optional `rustfs-tenant` Helm chart for a Tenant and separate API/Console Ingress
or HTTPRoute resources, with backend TLS policies, native YAML/Kustomize examples,
and networking lifecycle documentation. Existing CRDs and controller behavior are unchanged.
Expand Down
33 changes: 28 additions & 5 deletions crates/rustfs-admin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use std::{collections::BTreeMap, time::Duration};

use reqwest::{Certificate, Client as HttpClient, Response, StatusCode};
use reqwest::{Certificate, Client as HttpClient, Identity, Response, StatusCode};

/// admin_ops: tenant admin operations (user/policy APIs).
#[path = "admin_ops.rs"]
Expand Down Expand Up @@ -576,13 +576,36 @@ impl RustfsAdminClient {
secret_key: impl Into<String>,
ca_pem: &[u8],
) -> Result<Self, RustfsClientError> {
let certs = Certificate::from_pem_bundle(ca_pem)
.map_err(|_| RustfsClientError::InvalidTenantTlsCa)?;
Self::new_with_base_url_tls_material(base_url, access_key, secret_key, Some(ca_pem), None)
}

pub fn new_with_base_url_tls_material(
base_url: impl Into<String>,
access_key: impl Into<String>,
secret_key: impl Into<String>,
ca_pem: Option<&[u8]>,
client_cert_and_key: Option<(&[u8], &[u8])>,
) -> Result<Self, RustfsClientError> {
let mut builder = HttpClient::builder()
.connect_timeout(ADMIN_HTTP_CONNECT_TIMEOUT)
.timeout(ADMIN_HTTP_REQUEST_TIMEOUT);
for cert in certs {
builder = builder.add_root_certificate(cert);
if let Some(ca_pem) = ca_pem {
let certs = Certificate::from_pem_bundle(ca_pem)
.map_err(|_| RustfsClientError::InvalidTenantTlsCa)?;
for cert in certs {
builder = builder.add_root_certificate(cert);
}
}
if let Some((cert_pem, key_pem)) = client_cert_and_key {
let mut combined = Vec::with_capacity(cert_pem.len() + 1 + key_pem.len());
combined.extend_from_slice(cert_pem);
if !combined.ends_with(b"\n") {
combined.push(b'\n');
}
combined.extend_from_slice(key_pem);
let identity = Identity::from_pem(&combined)
.map_err(|_| RustfsClientError::TlsClientBuildFailed)?;
builder = builder.identity(identity);
}
let http_client = builder
.build()
Expand Down
2 changes: 1 addition & 1 deletion deploy/rustfs-operator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ Monitor `rustfs_operator_sts_tls_certificate_expiry_timestamp_seconds` and `rust

STS only issues credentials for TLS-enabled Tenants. For Tenant upstream calls, the operator selects the Tenant HTTPS service endpoint and trusts the CA recorded in `status.certificates.tls.caSecretRef`.

Operator STS does not present a client certificate when calling the Tenant. Tenants configured with `spec.tls.certManager.caTrust.clientCaSecretRef` continue to run with server-side mTLS enabled, but Operator STS rejects those Tenants with HTTP 400 and `TenantTlsClientCertificateUnsupported`.
When calling an mTLS-enabled Tenant (`caTrust.clientCaSecretRef`), the operator presents the Tenant's default certificate (`status.certificates.tls.serverSecretRef`) as its client certificate identity. If a Tenant requires a client certificate but `serverSecretRef` is unavailable, Operator STS rejects the request with HTTP 400 and `TenantTlsClientCertificateUnsupported`.

When `operator.serviceMonitor.enabled=true`, the chart creates scrape targets for both the operator observability endpoint and the Console API `/metrics` endpoint.

Expand Down
7 changes: 7 additions & 0 deletions docs/operator-user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,13 @@ spec:
The default certificate is projected to `rustfs_cert.pem` and `rustfs_key.pem` at `mountPath`, so RustFS can use it as the fallback certificate and for internode HTTPS. Each `hosts` value is projected as a RustFS SNI directory, for example `s3.example.com/rustfs_cert.pem` and `s3.example.com/rustfs_key.pem`.
When `certificates` is set, omitted `includeGeneratedDnsNames` is treated as `true` only on the `default: true` certificate. Non-default entries include only `hosts` and `certManager.dnsNames` unless they explicitly set `includeGeneratedDnsNames: true`.
When `enableInternodeHttps: true`, the default managed certificate must cover the RustFS peer DNS names used by the operator and `RUSTFS_VOLUMES`. Keep `includeGeneratedDnsNames` enabled, or list the required names explicitly in `hosts` or `certManager.dnsNames`. Clusters with a custom Kubernetes DNS domain should set the Helm chart `clusterDomain`; required names then use `.svc.<clusterDomain>`. External certificates must cover the headless Service FQDN (`<tenant>-hl.<namespace>.svc.<clusterDomain>`) and pod FQDNs; a wildcard such as `*.<tenant>-hl.<namespace>.svc.<clusterDomain>` covers the generated pod FQDNs.
When `caTrust.clientCaSecretRef` is configured (mTLS enabled):
- The operator sets `RUSTFS_SERVER_MTLS_ENABLE=true` on the RustFS container and uses `https://` for all peer URLs in `RUSTFS_VOLUMES`. Because RustFS serves both S3 API and internode RPC traffic on port `9000`, all TLS connections to `:9000` (both client-to-Pod and Pod-to-Pod) must present a client certificate trusted by `client_ca.crt`.
- The default certificate's `tls.crt` and `tls.key` are projected to both `rustfs_cert.pem`/`rustfs_key.pem` and `client_cert.pem`/`client_key.pem` in `mountPath`, `clientCaSecretRef` is projected to `client_ca.crt`, and the operator uses the default certificate as its client identity for admin and STS calls.
- When `manageCertificate: true` and `certManager.usages` is omitted, the operator requests `usages: ["server auth", "client auth"]` on the default `Certificate`, and verifies that the issued default certificate chains to `clientCaSecretRef` with client-authentication usage before reporting TLS Ready.
- The readiness probe checks `https://127.0.0.1:9000/health/ready` using `curl` with `--cert` and `--key` by default, while liveness and startup probes use `tcpSocket` on port `9000`. For distroless container images that do not include `curl`, you can set `TENANT_MTLS_READINESS_PROBE=tcp` on the operator Deployment or in `spec.env` to fall back to `tcpSocket` on port `9000` (note that `tcpSocket` succeeds as soon as port `9000` accepts connections and does not wait for `/health/ready` read quorum, so Pods may be marked Ready or advance a StatefulSet rollout before read quorum is established; see [rustfs/rustfs#9256](https://github.com/rustfs/rustfs/issues/9256)).
- Because `rustls` requires client trust anchors to have `basicConstraints: CA:TRUE`, use a `cert-manager` CA `Issuer` (backed by a certificate with `isCA: true`) rather than a direct leaf `selfSigned` `Issuer`.

When `certificates` is set, configure process-wide trust with top-level `caTrust` or the `caTrust` on the `default: true` certificate. The legacy `certManager.caTrust` field is only used by the single-certificate form, and `certManager.caTrust` on non-default entries is rejected.

### 7.6 Logging
Expand Down
7 changes: 7 additions & 0 deletions docs/operator-user-guide.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,13 @@ spec:
默认条目会被投影到 `mountPath` 根目录下的 `rustfs_cert.pem` 和 `rustfs_key.pem`,供 RustFS 作为 fallback 证书和节点间 HTTPS 证书使用。每个 `hosts` 值会被投影为 RustFS SNI 子目录,例如 `s3.example.com/rustfs_cert.pem` 和 `s3.example.com/rustfs_key.pem`。
配置了 `certificates` 时,省略 `includeGeneratedDnsNames` 只有在 `default: true` 证书条目中才按 `true` 处理。非默认条目只包含 `hosts` 和 `certManager.dnsNames`,除非显式设置 `includeGeneratedDnsNames: true`。
当 `enableInternodeHttps: true` 时,默认托管证书必须覆盖 operator 和 `RUSTFS_VOLUMES` 实际使用的 RustFS peer DNS 名称。应保持 `includeGeneratedDnsNames` 启用,或在 `hosts` / `certManager.dnsNames` 中显式列出必需名称。使用自定义 Kubernetes DNS 域的集群应设置 Helm chart 的 `clusterDomain`;必需名称会使用 `.svc.<clusterDomain>`。外部证书必须覆盖 headless Service FQDN(`<tenant>-hl.<namespace>.svc.<clusterDomain>`)和 pod FQDN;类似 `*.<tenant>-hl.<namespace>.svc.<clusterDomain>` 的 wildcard 可以覆盖生成的 pod FQDN。
当配置了 `caTrust.clientCaSecretRef`(启用 mTLS)时:
- Operator 会为 RustFS 容器设置 `RUSTFS_SERVER_MTLS_ENABLE=true`,并将 `RUSTFS_VOLUMES` 中的所有节点间地址切换为 `https://`。由于 RustFS 在 `9000` 端口同时承载 S3 API 与节点间 RPC 流量,所有连往 `:9000` 的 TLS 连接(包括客户端到 Pod 和 Pod 间连接)都必须提供受 `client_ca.crt` 信任的客户端证书。
- 默认证书的 `tls.crt` 和 `tls.key` 会同时投影到 `mountPath` 下的 `rustfs_cert.pem`/`rustfs_key.pem` 以及 `client_cert.pem`/`client_key.pem`;`clientCaSecretRef` 会投影为 `client_ca.crt`,且 Operator 在调用管理接口与 STS 时也会使用该默认证书作为客户端身份。
- 当 `manageCertificate: true` 且未指定 `certManager.usages` 时,默认 `Certificate` 会自动请求 `usages: ["server auth", "client auth"]`,并在标记 TLS Ready 前校验签发的默认证书具备客户端认证用途且由 `clientCaSecretRef` 信任。
- 就绪探针默认使用带 `--cert` 和 `--key` 的 `curl` 访问 `https://127.0.0.1:9000/health/ready`,存活与启动探针使用 `9000` 端口的 `tcpSocket`。对于不含 `curl` 的 distroless 容器镜像,可在 Operator Deployment 或 `spec.env` 中设置 `TENANT_MTLS_READINESS_PROBE=tcp` 以回退到 `9000` 端口的 `tcpSocket`(注意:`tcpSocket` 在 `9000` 端口接受连接后即视为成功,不会等待 `/health/ready` 读仲裁就绪,因此 Pod 可能会在读仲裁建立前被标记为 Ready 或推进 StatefulSet 滚动更新;详见 [rustfs/rustfs#9256](https://github.com/rustfs/rustfs/issues/9256))。
- 由于 `rustls` 要求客户端信任根包含 `basicConstraints: CA:TRUE`,请使用基于 CA 证书(`isCA: true`)的 `cert-manager` CA `Issuer`,而不是直接使用签发叶子证书的 `selfSigned` `Issuer`。

配置了 `certificates` 时,进程级 trust 应放在顶层 `caTrust` 或 `default: true` 证书条目的 `caTrust` 中。旧的 `certManager.caTrust` 只对单证书写法生效,非默认条目上的 `certManager.caTrust` 会被拒绝。

### 7.6 日志配置
Expand Down
110 changes: 108 additions & 2 deletions e2e/tests/cert_manager_tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ use operator::types::v1alpha1::{
status::certificate::SecretStatusRef,
tenant::Tenant,
tls::{
CaTrustSource, DEFAULT_TLS_MOUNT_PATH, RUSTFS_CA_FILE, RUSTFS_TLS_CERT_FILE,
RUSTFS_TLS_KEY_FILE, SecretKeyReference, TlsPlan,
CaTrustSource, DEFAULT_TLS_MOUNT_PATH, RUSTFS_CA_FILE, RUSTFS_CLIENT_CA_FILE,
RUSTFS_CLIENT_CERT_FILE, RUSTFS_CLIENT_KEY_FILE, RUSTFS_TLS_CERT_FILE, RUSTFS_TLS_KEY_FILE,
SecretKeyReference, TlsPlan, TlsServerCertificateMount,
},
};
use rustfs_operator_e2e::{
Expand Down Expand Up @@ -606,6 +607,111 @@ fn external_secret_tls_plan_projects_server_and_explicit_ca_into_single_tls_dire
Ok(())
}

#[test]
fn mtls_tls_plan_projects_client_identity_and_uses_tcp_and_exec_probes() -> Result<()> {
let config = E2eConfig::defaults();
let tenant = tls_e2e::managed_certificate_tenant(&config);
let pool = tenant
.spec
.pools
.first()
.expect("managed certificate fixture should have a pool");
let secret_name = tls_e2e::managed_secret_name(&config);
let tls_plan = TlsPlan::rollout_certificates(
DEFAULT_TLS_MOUNT_PATH.to_string(),
"sha256:e2e-mtls".to_string(),
vec![TlsServerCertificateMount {
secret_name: secret_name.clone(),
domains: vec![None],
ca_key: Some("ca.crt".to_string()),
}],
None,
Some(SecretKeyReference {
name: secret_name.clone(),
key: "ca.crt".to_string(),
}),
true,
false,
false,
None,
);

let statefulset = tenant.new_statefulset_with_tls_plan(pool, &tls_plan)?;
let pod_spec = statefulset
.spec
.as_ref()
.context("StatefulSet should have spec")?
.template
.spec
.as_ref()
.context("StatefulSet pod template should have spec")?;
let tls_volume = pod_spec
.volumes
.as_deref()
.unwrap_or_default()
.iter()
.find(|volume| volume.name == "rustfs-tls-server")
.context("TLS material should use the rustfs-tls-server volume")?;
let rustfs_container = pod_spec
.containers
.iter()
.find(|container| container.name == "rustfs")
.context("rustfs container should exist")?;

ensure!(
projected_secret_item(tls_volume, &secret_name, "tls.crt", RUSTFS_CLIENT_CERT_FILE,),
"mTLS projected volume should include client_cert.pem"
);
ensure!(
projected_secret_item(tls_volume, &secret_name, "tls.key", RUSTFS_CLIENT_KEY_FILE,),
"mTLS projected volume should include client_key.pem"
);
ensure!(
projected_secret_item(tls_volume, &secret_name, "ca.crt", RUSTFS_CLIENT_CA_FILE,),
"mTLS projected volume should include client_ca.crt"
);
ensure!(
rustfs_container
.liveness_probe
.as_ref()
.and_then(|probe| probe.tcp_socket.as_ref())
.is_some(),
"mTLS liveness probe should use tcpSocket"
);
let readiness_command = rustfs_container
.readiness_probe
.as_ref()
.and_then(|probe| probe.exec.as_ref())
.and_then(|exec| exec.command.as_ref())
.context("mTLS readiness probe should use exec")?;
ensure!(
readiness_command.windows(2).any(|w| {
w == [
"--cert",
&format!("{DEFAULT_TLS_MOUNT_PATH}/{RUSTFS_CLIENT_CERT_FILE}"),
]
}),
"mTLS readiness probe should present the mounted client certificate"
);
ensure!(
readiness_command.windows(2).any(|w| {
w == [
"--key",
&format!("{DEFAULT_TLS_MOUNT_PATH}/{RUSTFS_CLIENT_KEY_FILE}"),
]
}),
"mTLS readiness probe should present the mounted client key"
);
ensure!(
readiness_command
.iter()
.any(|arg| arg == "https://127.0.0.1:9000/health/ready"),
"mTLS readiness probe should check https://127.0.0.1:9000/health/ready"
);

Ok(())
}

#[test]
fn external_secret_tls_sans_cover_rendered_https_peer_hosts() -> Result<()> {
let smoke = E2eConfig::defaults();
Expand Down
85 changes: 85 additions & 0 deletions examples/cert-manager-mtls-tenant.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Minimal RustFS Tenant example for cert-manager managed mTLS (Pod-to-Pod and client-to-Pod).
#
# Notes:
# - RustFS serves both S3 API and internode RPC traffic on port 9000, so configuring
# caTrust.clientCaSecretRef enforces client certificate verification for both peer pods and S3 clients.
# - rustls requires the CA certificate in ca.crt / client_ca.crt to carry
# basicConstraints: CA:TRUE, so this example sets up a self-signed root Issuer,
# a CA Certificate (isCA: true), and a CA Issuer referenced by the Tenant.
# - Create the credentials Secret referenced by spec.credsSecret with non-default
# accesskey / secretkey values before applying in a multi-node deployment.
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
name: rustfs-selfsigned-root
namespace: rustfs-system
spec:
selfSigned: {}
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: rustfs-root-ca
namespace: rustfs-system
spec:
isCA: true
commonName: rustfs-root-ca
secretName: rustfs-root-ca-secret
privateKey:
algorithm: ECDSA
size: 256
issuerRef:
name: rustfs-selfsigned-root
kind: Issuer
group: cert-manager.io
---
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
name: rustfs-ca-issuer
namespace: rustfs-system
spec:
ca:
secretName: rustfs-root-ca-secret
---
apiVersion: rustfs.com/v1alpha1
kind: Tenant
metadata:
name: cert-manager-mtls
namespace: rustfs-system
spec:
image: rustfs/rustfs:1.0.4
credsSecret:
name: rustfs-creds

tls:
mode: certManager
mountPath: /var/run/rustfs/tls
rotationStrategy: Rollout
enableInternodeHttps: true
requireSanMatch: true
caTrust:
clientCaSecretRef:
name: rustfs-root-ca-secret
key: ca.crt
certManager:
manageCertificate: true
certificateName: cert-manager-mtls-server
secretName: cert-manager-mtls-server-tls
issuerRef:
group: cert-manager.io
kind: Issuer
name: rustfs-ca-issuer
includeGeneratedDnsNames: true

pools:
- name: primary
servers: 4
persistence:
volumesPerServer: 1
volumeClaimTemplate:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
2 changes: 1 addition & 1 deletion src/reconcile/pool_lifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ pub(super) fn expected_pool_cmd_line(
.spec
.tls
.as_ref()
.is_some_and(|tls| tls.enable_internode_https)
.is_some_and(|tls| tls.is_enabled() && tls.is_internode_https_enabled())
{
"https"
} else {
Expand Down
Loading