patch before_request.py to allow workspace creation with EDIT permission

This commit is contained in:
wbsong111
2026-04-27 16:58:04 +09:00
parent 5fac7175a5
commit 547dc58e8b
3 changed files with 721 additions and 12 deletions
+113 -12
View File
@@ -231,6 +231,7 @@ extraArgs:
appName: "oidc-auth"
uvicornOpts: "--timeout-keep-alive 600"
allowedHosts: "mlflow.example.org"
corsAllowedOrigins: "https://mlflow.example.org" # CORS 허용 Origin
log:
enabled: false # uvicornOpts 사용 시 반드시 false (gunicorn/uvicorn 충돌 방지)
@@ -272,26 +273,46 @@ extraVolumeMounts:
---
### 3.7 OIDC Auth Middleware 패치
### 3.7 before_request.py 패치
`mlflow-oidc-auth` 플러그인의 `auth_middleware.py`를 차트에 포함된 버전으로 교체한다.
워크스페이스 지원(`x-mlflow-workspace` 헤더 처리) 등 업스트림 수정 사항을 반영한다.
`mlflow-oidc-auth` v7.0.3의 `hooks/before_request.py` line 520에 권한 체크 오류가 있다.
workspace에서 실험·모델 생성 시 MANAGE(`can_manage`)를 요구하지만,
`OIDC_WORKSPACE_DEFAULT_PERMISSION: "EDIT"`으로 자동 부여된 EDIT 권한은
`can_update=True, can_manage=False`이므로 EDIT 사용자가 항상 403을 받는다.
```yaml
oidcAuthPatch:
enabled: true
mountPath: "/usr/local/lib/python3.11/site-packages/mlflow_oidc_auth/middleware/auth_middleware.py"
#### 수정 내용 (`files/before_request.py` line 520)
```python
# 원본 (버그)
if ws_perm is None or not ws_perm.can_manage:
return responses.make_forbidden_response()
# 패치 (수정)
if ws_perm is None or not ws_perm.can_update:
return responses.make_forbidden_response()
```
파일 소스: `files/auth_middleware.py`
#### ConfigMap 생성
> **Python 버전 확인**: 컨테이너 이미지의 Python 버전이 다를 경우 `mountPath`를 수정한다.
```sh
kubectl create configmap mlflow-hooks-patch -n mlflow \
--from-file=before_request.py=manifests/helm/mlflow/1.9.0/files/before_request.py
```
패치 파일 소스: `files/before_request.py`
> **Python 버전 확인**: 컨테이너 이미지의 Python 버전이 다를 경우 `extraVolumeMounts`의 `mountPath`를 수정한다.
> `paasup/mlflow:v3.11.1-oidc` 이미지의 실제 Python 버전은 **3.10**이므로 경로는 `python3.10`을 사용한다.
>
> ```sh
> kubectl exec -n mlflow <pod> -- python -c \
> "import mlflow_oidc_auth.middleware.auth_middleware as m; print(m.__file__)"
> "import mlflow_oidc_auth.hooks.before_request as m; print(m.__file__)"
> ```
> **업스트림 이슈**: 이 동작이 의도된 설계인지 여부를 mlflow-oidc-auth 저장소에 문의했다.
> → [Issue #240](https://github.com/mlflow-oidc/mlflow-oidc-auth/issues/240)
> 업스트림에서 수정이 반영되면 이 패치는 제거한다.
---
### 3.8 Ingress 설정
@@ -319,7 +340,87 @@ ingress:
---
### 3.9 PostgreSQL 설정
### 3.9 CORS 설정
브라우저가 MLflow API를 cross-origin으로 호출할 때 발생하는 `Cross-origin request blocked`를 해결하기 위해 두 가지 설정이 필요하다.
#### MLflow 서버 네이티브 설정
`extraArgs.corsAllowedOrigins`으로 `--cors-allowed-origins` 플래그를 전달한다.
```yaml
extraArgs:
corsAllowedOrigins: "https://mlflow.example.org"
```
여러 origin을 허용할 경우 쉼표로 구분한다.
```yaml
corsAllowedOrigins: "https://mlflow.example.org,https://other.example.org"
```
#### Kong Ingress CORS 플러그인
Kong이 CORS preflight(OPTIONS) 요청을 처리하고 응답 헤더를 보완하도록 KongPlugin을 추가한다.
```sh
kubectl apply -f - <<EOF
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: mlflow-cors
namespace: mlflow
plugin: cors
config:
origins:
- "https://mlflow.example.org"
methods:
- GET
- POST
- PUT
- DELETE
- OPTIONS
- PATCH
headers:
- Accept
- Authorization
- Content-Type
credentials: true
max_age: 3600
EOF
```
Ingress에 플러그인을 연결한다.
```yaml
ingress:
annotations:
konghq.com/plugins: mlflow-cors
```
#### 동작 검증
```sh
curl -sk -X OPTIONS https://mlflow.example.org/api/2.0/mlflow/experiments/list \
-H "Origin: https://mlflow.example.org" \
-H "Access-Control-Request-Method: GET" \
-D - -o /dev/null | grep -i access-control
```
정상 응답 예시:
```
access-control-allow-origin: https://mlflow.example.org
access-control-allow-credentials: true
access-control-allow-methods: GET,POST,PUT,DELETE,OPTIONS,PATCH
```
> **주의**: 브라우저 콘솔에서 403 응답이 `Cross-origin request blocked`로 표시되는 경우가 있다.
> 응답 헤더에 `Access-Control-Allow-Origin`이 존재하면 CORS 자체는 정상이며, 실제 원인은 MLflow 권한(403) 문제이다.
---
### 3.10 PostgreSQL 설정
내장 PostgreSQL을 사용한다.
@@ -346,7 +447,7 @@ extraEnvVars:
---
### 3.10 S3 (MinIO) 설정
### 3.11 S3 (MinIO) 설정
```yaml
artifactRoot: