mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-04-27 13:57:58 +08:00
## Summary Fixes MinIO SSL/TLS support in two places: the MinIO **client** connection and the **health check** used by the Admin/Service Health dashboard. Both now respect the `secure` and `verify` settings from the MinIO configuration. Closes #13158 Closes #13159 --- ## Problem **#13158 – MinIO client:** The client in `rag/utils/minio_conn.py` was hardcoded with `secure=False`, so RAGFlow could not connect to MinIO over HTTPS even when `secure: true` was set in config. There was also no way to disable certificate verification for self-signed certs. **#13159 – MinIO health check:** In `api/utils/health_utils.py`, the MinIO liveness check always used `http://` for the health URL. When MinIO was configured with SSL, the health check failed and the dashboard showed "timeout" even though MinIO was reachable over HTTPS. --- ## Solution ### MinIO client (`rag/utils/minio_conn.py`) - Read `MINIO.secure` (default `false`) and pass it into the `Minio()` constructor so HTTPS is used when configured. - Add `_build_minio_http_client()` that reads `MINIO.verify` (default `true`). When `verify` is false, return an `urllib3.PoolManager` with `cert_reqs=ssl.CERT_NONE` and pass it as `http_client` to `Minio()` so self-signed certificates are accepted. - Support string values for `secure` and `verify` (e.g. `"true"`, `"false"`). ### MinIO health check (`api/utils/health_utils.py`) - Add `_minio_scheme_and_verify()` to derive URL scheme (http/https) and the `verify` flag from `MINIO.secure` and `MINIO.verify`. - Update `check_minio_alive()` to use the correct scheme, pass `verify` into `requests.get(..., verify=verify)`, and use `timeout=10`. ### Config template (`docker/service_conf.yaml.template`) - Add commented optional MinIO keys `secure` and `verify` (and env vars `MINIO_SECURE`, `MINIO_VERIFY`) so deployers know they can enable HTTPS and optional cert verification. ### Tests - **`test/unit_test/utils/test_health_utils_minio.py`** – Tests for `_minio_scheme_and_verify()` and `check_minio_alive()` (scheme, verify, status codes, timeout, errors). - **`test/unit_test/utils/test_minio_conn_ssl.py`** – Tests for `_build_minio_http_client()` (verify true/false/missing, string values, `CERT_NONE` when verify is false). --- ## Testing - Unit tests added/updated as above; run with the project's test runner. - Manually: configure MinIO with HTTPS and `secure: true` (and optionally `verify: false` for self-signed); confirm client operations work and the Service Health dashboard shows MinIO as alive instead of timeout.
64 lines
2.5 KiB
Python
64 lines
2.5 KiB
Python
#
|
|
# Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
#
|
|
"""
|
|
Unit tests for MinIO client SSL/secure configuration (_build_minio_http_client).
|
|
Covers issue #13158.
|
|
"""
|
|
import ssl
|
|
from unittest.mock import patch
|
|
|
|
|
|
class TestBuildMinioHttpClient:
|
|
"""Test _build_minio_http_client helper."""
|
|
|
|
@patch("rag.utils.minio_conn.settings")
|
|
def test_returns_none_when_verify_true(self, mock_settings):
|
|
mock_settings.MINIO = {"verify": True}
|
|
from rag.utils.minio_conn import _build_minio_http_client
|
|
client = _build_minio_http_client()
|
|
assert client is None
|
|
|
|
@patch("rag.utils.minio_conn.settings")
|
|
def test_returns_none_when_verify_missing(self, mock_settings):
|
|
mock_settings.MINIO = {}
|
|
from rag.utils.minio_conn import _build_minio_http_client
|
|
client = _build_minio_http_client()
|
|
assert client is None
|
|
|
|
@patch("rag.utils.minio_conn.settings")
|
|
def test_returns_pool_manager_when_verify_false(self, mock_settings):
|
|
mock_settings.MINIO = {"verify": False}
|
|
from rag.utils.minio_conn import _build_minio_http_client
|
|
client = _build_minio_http_client()
|
|
assert client is not None
|
|
assert hasattr(client, "connection_pool_kw")
|
|
assert client.connection_pool_kw.get("cert_reqs") == ssl.CERT_NONE
|
|
|
|
@patch("rag.utils.minio_conn.settings")
|
|
def test_returns_pool_manager_when_verify_string_false(self, mock_settings):
|
|
mock_settings.MINIO = {"verify": "false"}
|
|
from rag.utils.minio_conn import _build_minio_http_client
|
|
client = _build_minio_http_client()
|
|
assert client is not None
|
|
assert client.connection_pool_kw.get("cert_reqs") == ssl.CERT_NONE
|
|
|
|
@patch("rag.utils.minio_conn.settings")
|
|
def test_returns_none_when_verify_string_1(self, mock_settings):
|
|
mock_settings.MINIO = {"verify": "1"}
|
|
from rag.utils.minio_conn import _build_minio_http_client
|
|
client = _build_minio_http_client()
|
|
assert client is None
|