Harden security: Switch to non-root user and sanitize error responses#12429
Harden security: Switch to non-root user and sanitize error responses#12429RinZ27 wants to merge 7 commits intoinfiniflow:mainfrom
Conversation
|
Great PR, thank you! |
Lynn-Inf
left a comment
There was a problem hiding this comment.
To pass the Ruff check, you can log the exception locally before returning. For example, adding logging.error(str(e)) where the e variable is already in scope will satisfy the linter while preserving our error handling logic.
|
Thanks for the thorough review. I've updated the PR to address the security and logging concerns. Key changes:
Let me know if there's anything else that needs attention. |
|
@Lynn-Inf @KevinHuSh Just a quick heads-up: I've implemented the server-side logging and refined the Docker permissions as discussed. The CI should be back to green now. Mind taking another look when you have a moment? Thanks! |
|
@RinZ27 |
|
Thanks @Lynn-Inf and @asiroliu for the review and for catching the Nginx permission issue! I'm glad the error handling part is merged. Regarding the Docker non-root user changes, I understand why it was reverted to keep the build stable. The Nginx permission error ( If you're still interested in hardening the container security, I can open a separate PR to address just the Dockerfile changes. I'll make sure to adjust the Nginx configuration and directory permissions (e.g., |
|
This is fantastic to hear, thank you for your understanding and continued initiative! We greatly appreciate you offering to see this through. To keep the changes consolidated, could you please update the original PR/branch with the refined non-root user setup? Your approach of properly adjusting Nginx configurations and directory permissions (like Please feel free to push the additional commits to the existing branch. We'll review the entire set once you signal it's ready. Thanks again for driving this! |
|
Thanks @Lynn-Inf, good call on the Nginx permissions. I've updated the PR to include the non-root fixes. Switched Nginx to listen on 8080/8443 and moved the PID file to Compose configs are updated to map to the new internal ports. CI should be happy now. |
08df996 to
9f13725
Compare
Lynn-Inf
left a comment
There was a problem hiding this comment.
Something went wrong in CI. It seems that ragflow service can't find packages in venv.
Traceback (most recent call last):
File "/ragflow/rag/svr/task_executor.py", line 26, in <module>
from api.db import PIPELINE_SPECIAL_PROGRESS_FREEZE_TASK_TYPES
File "/ragflow/api/db/__init__.py", line 18, in <module>
from strenum import StrEnum
ModuleNotFoundError: No module named 'strenum'
Traceback (most recent call last):
File "/ragflow/rag/svr/sync_data_source.py", line 35, in <module>
from flask import json
ModuleNotFoundError: No module named 'flask'
Traceback (most recent call last):
File "/ragflow/admin/server/admin_server.py", line 25, in <module>
from flask import Flask
ModuleNotFoundError: No module named 'flask'
Traceback (most recent call last):
File "/ragflow/api/ragflow_server.py", line 22, in <module>
from plugin import GlobalPluginManager
File "/ragflow/plugin/__init__.py", line 1, in <module>
from .plugin_manager import PluginManager
File "/ragflow/plugin/plugin_manager.py", line 4, in <module>
import pluginlib
ModuleNotFoundError: No module named 'pluginlib'
|
Thanks @Lynn-Inf for the feedback. It looks like the switch to the non-root user is causing issues with locating the packages in the virtual environment. I'll investigate the |
|
I've pushed a fix for the The root cause was that Changes:
This should get the CI back to green and ensure the services can find their packages when running as the |
3d815d6 to
9f4f1e0
Compare
57da018 to
8436d56
Compare
8436d56 to
f42bf9b
Compare
f42bf9b to
a922d81
Compare
a922d81 to
15c6846
Compare
|
|
I've pushed another fix to address the The issue was that Fix:
This ensures that the application correctly resolves |
|
Resolved the latest merge conflict in The upstream |
|
I've updated Instead of relying on This guarantees that the process sees the correct home directory regardless of how |
|
I've refactored Changes:
This should bypass any potential |
|
Hi @KevinHuSh @Lynn-Inf, I've decided to close this PR for now. After several attempts to harden the container by switching to a non-root user, it's clear that I sincerely apologize for the extensive commit history and for consuming so much of your CI I'd rather close this now to keep your project history clean and avoid further noise. I may Thank you for your patience and the thorough reviews. Best of luck with the release! |

Caught a couple of low-hanging security issues while poking around the admin routes and Docker setup.
First, the production Docker image was running as root. I've added a dedicated
ragflowuser and updated the permissions so we're not handing out root access by default—standard practice to minimize the blast radius if anything goes wrong.Second, I noticed we were piping raw exception strings (
str(e)) directly back to the client in several admin routes. That's a bit risky since it can leak internal paths or stack traces. I've sanitized those to return a generic "Internal Server Error" while keeping theAdminExceptionmessages intact since those seem intended for the user.Let me know if this looks good to you guys!