feat(deploy): 운영 이미지를 Gitea 레지스트리에서 받고 권한을 줄인다
운영 backend·frontend는 imagePullPolicy: Never로 노드에 직접 넣은 이미지를
쓴다. 2026-11-09 디스크 사고 때 kubelet 이미지 GC가 그 이미지를 지웠고,
다시 받을 곳이 없어 hyeonworks.com이 내려갔다. redis는 움직이는 태그
redis:7-alpine이다. 세 파드 모두 우선순위가 0이고 securityContext가
비어 있다(k3s 성숙도 점검 2026-11-11, 7.2·7.5절).
- backend·frontend 이미지를 git.learn.hyeonworks.com/donghyeon.kang/
tech-log-{backend:46b1cc7,frontend:7a4e201}로, pull을 IfNotPresent로
바꾼다. 태그는 지금 운영과 같다.
- redis를 지금 운영이 쓰는 이미지의 digest로 고정한다.
- 세 파드에 priorityClassName platform-critical과 seccomp
RuntimeDefault를 둔다.
- backend는 uid 1000, redis는 uid 999로 runAsNonRoot이고 권한을 모두
버리며 allowPrivilegeEscalation: false다.
- frontend는 allowPrivilegeEscalation: false만 둔다. nginx 공식 이미지는
root로 80번을 열고 worker를 내리므로, non-root와 drop ALL은 이미지를
비특권 nginx로 바꾼 뒤에 한다(README에 남은 일로 적음).
버린 대안: frontend에도 drop ALL을 두는 것. nginx가 80번을 열고 사용자를
바꾸는 데 필요한 권한까지 빠져 뜨지 못한다.
위험·한계: 두 이미지가 레지스트리에 올라가기 전에 적용하면 파드가
ErrImagePull로 멈춘다. README가 적용 전 확인을 요구한다. backend는
Recreate라 1분 안팎 멈추고, redis 재시작으로 로그인 세션이 풀린다.
아직 적용하지 않았다.
검증: kubectl diff는 위 칸들만 바뀐다고 보여 준다. kubectl apply
--dry-run=server는 통과하고, frontend에 PSA restricted 경고(non-root,
drop ALL)만 낸다. desktop Docker에서 같은 조건으로 띄워 봤다. redis는
uid 999·cap-drop ALL·no-new-privileges로 PONG을 돌려준다. backend는
uid 1000으로 Tomcat과 DB 연결 시도까지 권한 오류 없이 뜬다. frontend는
no-new-privileges와 기본 seccomp에서 /config.json 200이다. 이 repo의
pnpm 게이트는 돌리지 않았다(YAML과 README만 바뀜).
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
# hyeonworks.com 운영 매니페스트
|
||||
|
||||
`hyeonworks-prod` namespace의 앱 쪽 객체 정본이다(소유자 결정 2026-11-11: 앱 쪽은 tech-log repo
|
||||
`deploy/`). 플랫폼 쪽(Namespace, techlog DB Role·Database, 다른 namespace의 NetworkPolicy·Probe·
|
||||
경보·대시보드)은 platform-core `services/tenants/techlog`가 맡는다. `hyeonworks-secrets` Secret은
|
||||
Git 밖에서 만든다.
|
||||
|
||||
| 파일 | 객체 |
|
||||
| --- | --- |
|
||||
| `backend-*.yaml` | `techlog-backend` Deployment, Service `techlog-backend`·`techlog-management`, ServiceMonitor, ConfigMap `techlog-logging` |
|
||||
| `redis-*.yaml` | 세션 저장소 `redis` Deployment·Service(저장 안 함, 재시작하면 로그인이 풀린다) |
|
||||
| `frontend-*.yaml` | `techlog-frontend` Deployment·Service |
|
||||
| `ingress.yaml` | `hyeonworks.com` 경로: `/api`·`/oauth2`·`/login`·`/logout` → backend, 나머지 → frontend |
|
||||
| `network-policies.yaml` | namespace 안 기본 거부와 허용 여섯 |
|
||||
|
||||
## 이미지와 실행 사용자
|
||||
|
||||
| 컨테이너 | 이미지 | pull | 사용자 |
|
||||
| --- | --- | --- | --- |
|
||||
| backend | `git.learn.hyeonworks.com/donghyeon.kang/tech-log-backend:46b1cc7` | `IfNotPresent` | uid 1000(이미지의 `app`), 권한 전부 버림 |
|
||||
| frontend | `git.learn.hyeonworks.com/donghyeon.kang/tech-log-frontend:7a4e201` | `IfNotPresent` | root(nginx). `allowPrivilegeEscalation: false`만 |
|
||||
| redis | `redis@sha256:c5d34a98…`(지금 운영이 쓰는 `redis:7-alpine`의 digest) | `IfNotPresent` | uid 999(이미지의 `redis`), 권한 전부 버림 |
|
||||
|
||||
- 예전에는 `imagePullPolicy: Never`로 노드에 직접 넣은 이미지를 썼다. 2026-11-09 디스크 사고 때
|
||||
kubelet 이미지 GC가 그 이미지를 지웠고, 다시 받을 곳이 없어 운영이 내려갔다. 이제 Gitea 컨테이너
|
||||
레지스트리에서 다시 받는다.
|
||||
- 세 파드 모두 `priorityClassName: platform-critical`(platform-core `services/priority-classes`)이고
|
||||
seccomp는 `RuntimeDefault`다.
|
||||
- **frontend non-root는 남은 일이다.** nginx 공식 이미지는 root로 시작해 80번을 열고 worker를
|
||||
`nginx`로 내린다. 권한을 버리거나 non-root로 돌리려면 이미지를 비특권 nginx(8080)로 바꾸고 Service
|
||||
`targetPort`와 probe를 같이 바꿔야 한다.
|
||||
|
||||
## 적용
|
||||
|
||||
전제(하나라도 없으면 적용하지 않는다):
|
||||
|
||||
1. 두 이미지가 Gitea 레지스트리에 있다. 익명 pull이 되는지 노드에서 확인한다.
|
||||
`sudo k3s crictl pull git.learn.hyeonworks.com/donghyeon.kang/tech-log-backend:46b1cc7`
|
||||
(frontend도 같다). 미리 받아 두면 backend(Recreate)가 멈추는 시간이 짧아진다.
|
||||
2. PriorityClass `platform-critical`이 있다: `kubectl get priorityclass platform-critical`.
|
||||
3. Secret `hyeonworks-prod/hyeonworks-secrets`가 있다.
|
||||
|
||||
```bash
|
||||
curl -s -o /dev/null -w '%{http_code}\n' https://hyeonworks.com/
|
||||
kubectl diff -k deploy/production
|
||||
kubectl apply -k deploy/production
|
||||
kubectl -n hyeonworks-prod rollout status deploy/techlog-backend deploy/techlog-frontend deploy/redis
|
||||
curl -s -o /dev/null -w '%{http_code}\n' https://hyeonworks.com/
|
||||
curl -s -o /dev/null -w '%{http_code}\n' https://hyeonworks.com/api/v1/public/home
|
||||
```
|
||||
|
||||
- backend는 `Recreate`라 새 파드가 준비될 때까지 API가 멈춘다(1분 안팎).
|
||||
- redis가 다시 시작되면 로그인 세션이 모두 풀린다.
|
||||
|
||||
되돌리기: `kubectl -n hyeonworks-prod rollout undo deploy/<이름>`. 그 뒤 이 폴더를 되돌리는 커밋을 만든다.
|
||||
@@ -122,8 +122,8 @@ spec:
|
||||
value: redis.hyeonworks-prod.svc.cluster.local:6379
|
||||
- name: APP_TRACING_ENABLED
|
||||
value: 'true'
|
||||
image: tech-log-backend:46b1cc7
|
||||
imagePullPolicy: Never
|
||||
image: git.learn.hyeonworks.com/donghyeon.kang/tech-log-backend:46b1cc7
|
||||
imagePullPolicy: IfNotPresent
|
||||
livenessProbe:
|
||||
failureThreshold: 3
|
||||
httpGet:
|
||||
@@ -167,12 +167,23 @@ spec:
|
||||
- mountPath: /etc/techlog-logging
|
||||
name: logging-config
|
||||
readOnly: true
|
||||
securityContext:
|
||||
allowPrivilegeEscalation: false
|
||||
capabilities:
|
||||
drop:
|
||||
- ALL
|
||||
dnsPolicy: ClusterFirst
|
||||
restartPolicy: Always
|
||||
schedulerName: default-scheduler
|
||||
securityContext: {}
|
||||
securityContext:
|
||||
runAsNonRoot: true
|
||||
runAsUser: 1000
|
||||
runAsGroup: 1000
|
||||
seccompProfile:
|
||||
type: RuntimeDefault
|
||||
terminationGracePeriodSeconds: 30
|
||||
volumes:
|
||||
- configMap:
|
||||
name: techlog-logging
|
||||
name: logging-config
|
||||
priorityClassName: platform-critical
|
||||
|
||||
@@ -21,8 +21,8 @@ spec:
|
||||
spec:
|
||||
automountServiceAccountToken: false
|
||||
containers:
|
||||
- image: docker.io/library/tech-log-frontend:7a4e201
|
||||
imagePullPolicy: Never
|
||||
- image: git.learn.hyeonworks.com/donghyeon.kang/tech-log-frontend:7a4e201
|
||||
imagePullPolicy: IfNotPresent
|
||||
livenessProbe:
|
||||
failureThreshold: 3
|
||||
httpGet:
|
||||
@@ -56,8 +56,13 @@ spec:
|
||||
memory: 32Mi
|
||||
terminationMessagePath: /dev/termination-log
|
||||
terminationMessagePolicy: File
|
||||
securityContext:
|
||||
allowPrivilegeEscalation: false
|
||||
dnsPolicy: ClusterFirst
|
||||
restartPolicy: Always
|
||||
schedulerName: default-scheduler
|
||||
securityContext: {}
|
||||
securityContext:
|
||||
seccompProfile:
|
||||
type: RuntimeDefault
|
||||
terminationGracePeriodSeconds: 30
|
||||
priorityClassName: platform-critical
|
||||
|
||||
@@ -24,7 +24,7 @@ spec:
|
||||
- ''
|
||||
- --appendonly
|
||||
- 'no'
|
||||
image: redis:7-alpine
|
||||
image: docker.io/library/redis@sha256:c5d34a98396a4775e223c74e929162c35c5a2182901ba26b50ade939941ce14b
|
||||
imagePullPolicy: IfNotPresent
|
||||
livenessProbe:
|
||||
exec:
|
||||
@@ -59,8 +59,19 @@ spec:
|
||||
memory: 64Mi
|
||||
terminationMessagePath: /dev/termination-log
|
||||
terminationMessagePolicy: File
|
||||
securityContext:
|
||||
allowPrivilegeEscalation: false
|
||||
capabilities:
|
||||
drop:
|
||||
- ALL
|
||||
dnsPolicy: ClusterFirst
|
||||
restartPolicy: Always
|
||||
schedulerName: default-scheduler
|
||||
securityContext: {}
|
||||
securityContext:
|
||||
runAsNonRoot: true
|
||||
runAsUser: 999
|
||||
runAsGroup: 999
|
||||
seccompProfile:
|
||||
type: RuntimeDefault
|
||||
terminationGracePeriodSeconds: 30
|
||||
priorityClassName: platform-critical
|
||||
|
||||
Reference in New Issue
Block a user