Spaces:
Sleeping
Sleeping
fix: make security.log path writable on HF Spaces (user 1000)
Browse files- Dockerfile +1 -0
- utils/auth.py +7 -1
Dockerfile
CHANGED
|
@@ -17,6 +17,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
| 17 |
# HF Spaces runs as user id 1000 with read/write to /app
|
| 18 |
RUN useradd -m -u 1000 user
|
| 19 |
WORKDIR /app
|
|
|
|
| 20 |
|
| 21 |
# Copy requirements first for layer caching
|
| 22 |
COPY --chown=user:user requirements.txt .
|
|
|
|
| 17 |
# HF Spaces runs as user id 1000 with read/write to /app
|
| 18 |
RUN useradd -m -u 1000 user
|
| 19 |
WORKDIR /app
|
| 20 |
+
RUN chown -R user:user /app
|
| 21 |
|
| 22 |
# Copy requirements first for layer caching
|
| 23 |
COPY --chown=user:user requirements.txt .
|
utils/auth.py
CHANGED
|
@@ -14,7 +14,13 @@ _api_key_header = APIKeyHeader(name="X-API-Key", auto_error=False)
|
|
| 14 |
# Security logger — writes to a dedicated security.log file
|
| 15 |
# ---------------------------------------------------------------------------
|
| 16 |
_security_log = logging.getLogger("ai-server.security")
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
_security_handler.setFormatter(
|
| 19 |
logging.Formatter("%(asctime)s | %(levelname)s | %(message)s")
|
| 20 |
)
|
|
|
|
| 14 |
# Security logger — writes to a dedicated security.log file
|
| 15 |
# ---------------------------------------------------------------------------
|
| 16 |
_security_log = logging.getLogger("ai-server.security")
|
| 17 |
+
_security_log_path = os.getenv("SECURITY_LOG_PATH", "security.log")
|
| 18 |
+
try:
|
| 19 |
+
_security_handler: logging.Handler = logging.FileHandler(
|
| 20 |
+
_security_log_path, encoding="utf-8"
|
| 21 |
+
)
|
| 22 |
+
except (PermissionError, OSError):
|
| 23 |
+
_security_handler = logging.StreamHandler()
|
| 24 |
_security_handler.setFormatter(
|
| 25 |
logging.Formatter("%(asctime)s | %(levelname)s | %(message)s")
|
| 26 |
)
|