Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions .github/workflows/challenge-supply-chain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ on:
required: false
default: false
type: boolean
enable_runtime_https_smoke:
description: GitHub runner에서 GCP Runtime HTTPS API로 임시 배포 검증 실행 여부
required: false
default: false
type: boolean
runtime_api_url:
description: TLS 인증서를 검증할 Runtime API HTTPS 주소
required: false
default: ""
type: string
runtime_ci_team_id:
description: Provisioner가 CI 토큰에 할당한 전용 팀 UUID
required: false
default: ""
type: string
runtime_target_id:
description: Secure Provisioner Registry에 등록된 K3s target_id
required: false
Expand All @@ -55,6 +70,8 @@ on:
required: false
AWS_CD_ARTIFACT_BUCKET:
required: false
RUNTIME_API_TOKEN:
required: false
# 이전 caller 호환용입니다. Runtime smoke에서는 사용하지 않습니다.
GHCR_PULL_SECRET_ARN:
required: false
Expand Down Expand Up @@ -719,3 +736,80 @@ jobs:
"") echo "정리할 staging 경로가 없습니다" ;;
*) echo "예상하지 못한 staging 경로입니다" >&2; exit 1 ;;
esac

k3s-smoke-https:
needs:
- validate
- aggregate
if: >-
inputs.publish_images &&
inputs.enable_runtime_https_smoke &&
github.event_name != 'pull_request' &&
needs.aggregate.result == 'success' &&
needs.validate.outputs.is_server == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: DevSecOps 도구 가져오기
uses: actions/checkout@v4
with:
repository: MSG-CTF/msgctf-devsecops
ref: ${{ needs.validate.outputs.devsecops_sha }}
path: .msgctf-ci

- name: 발행 bundle 가져오기
uses: actions/download-artifact@v4
with:
name: ${{ needs.aggregate.outputs.publish_bundle_name }}
path: dist

- name: GCP Runtime smoke 설정 생성
env:
RUNTIME_API_URL: ${{ inputs.runtime_api_url }}
RUNTIME_CI_TEAM_ID: ${{ inputs.runtime_ci_team_id }}
RUNTIME_TARGET_ID: ${{ inputs.runtime_target_id }}
SMOKE_KEY: ${{ github.repository_id }}:${{ github.run_id }}:${{ github.run_attempt }}:${{ needs.validate.outputs.challenge_slug }}
run: |
set -euo pipefail
case "$RUNTIME_API_URL" in https://*) ;; *) echo "Runtime HTTPS URL이 필요합니다" >&2; exit 1 ;; esac
test -n "$RUNTIME_CI_TEAM_ID" || { echo "runtime_ci_team_id가 필요합니다" >&2; exit 1; }
test -n "$RUNTIME_TARGET_ID" || { echo "runtime_target_id가 필요합니다" >&2; exit 1; }
instance_id="$(python3 -c 'import os, uuid; print(uuid.uuid5(uuid.NAMESPACE_URL, os.environ["SMOKE_KEY"]))')"
jq -n \
--arg target_id "$RUNTIME_TARGET_ID" \
--arg instance_id "$instance_id" \
--arg team_id "$RUNTIME_CI_TEAM_ID" \
'{target_id: $target_id, instance_id: $instance_id, team_id: $team_id}' \
> dist/runtime-smoke-config.json

- name: GCP Runtime HTTPS smoke 실행
env:
RUNTIME_API_URL: ${{ inputs.runtime_api_url }}
RUNTIME_API_TOKEN: ${{ secrets.RUNTIME_API_TOKEN }}
run: |
set -euo pipefail
test -n "$RUNTIME_API_TOKEN" || { echo "RUNTIME_API_TOKEN Secret이 필요합니다" >&2; exit 1; }
umask 077
token_file="$(mktemp)"
trap 'rm -f "$token_file"' EXIT INT TERM
printf '%s' "$RUNTIME_API_TOKEN" > "$token_file"
python3 .msgctf-ci/scripts/runtime_api_smoke_runner.py \
--artifact dist/artifact-v2.json \
--config dist/runtime-smoke-config.json \
--api-url "$RUNTIME_API_URL" \
--token-file "$token_file" \
--timeout 300 --cleanup-timeout 300 \
| tee dist/runtime-smoke-result.txt
result="$(sed -n 's/^MSGCTF_RUNTIME_SMOKE_RESULT=//p' dist/runtime-smoke-result.txt | tail -n 1)"
if [ -z "$result" ] || ! printf '%s\n' "$result" | jq -e '.create_status == "SUCCEEDED" and .delete_status == "SUCCEEDED"' >/dev/null; then
echo "Secure Provisioner 생성·삭제 결과를 확인할 수 없습니다" >&2
exit 1
fi
{
echo "## GCP Secure Provisioner HTTPS smoke 결과"
echo
echo '```json'
printf '%s\n' "$result" | jq
echo '```'
} >> "$GITHUB_STEP_SUMMARY"
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ DevSecOps는 `artifact-v2.json`과 GHCR digest image를 발행하고, Backend po

Backend 운영 환경의 `RELEASE_POLL_REPO`와 `RELEASE_POLL_GITHUB_TOKEN`은 Backend
팀이 관리합니다. CI는 Backend DB, Scheduler 또는 Broker를 직접 조작하지 않으며,
선택형 K3s smoke job만 SSM으로 Secure Provisioner API를 호출합니다.
선택형 K3s smoke job만 SSM 또는 HTTPS로 Secure Provisioner API를 호출합니다.

## Runtime K3s Smoke

Expand All @@ -289,6 +289,18 @@ Operation이 성공하면 같은 API로 즉시 삭제하고, 두 결과를 Actio
`AWS_CD_ARTIFACT_BUCKET`입니다. caller는 `runtime_target_id`도 전달해야 합니다.
자세한 설정은 [`docs/aws-k3s-cd-smoke.md`](docs/aws-k3s-cd-smoke.md)에 있습니다.

GCP Runtime HTTPS 경로는 별도 `enable_runtime_https_smoke: true`로 켭니다. caller는
`runtime_api_url`(인증서 검증 가능한 HTTPS 주소), `runtime_ci_team_id`,
`runtime_target_id`와 Secret `RUNTIME_API_TOKEN`을 전달합니다. 발행 bundle의
`artifact-v2.json`을 GitHub 호스팅 runner에서 기존 smoke runner로 실행해 create와
delete Operation 성공을 확인합니다. 토큰은 임시 파일에 넣고 종료 시 삭제합니다.
이 성공 판정은 Runtime Operation 응답 기준이며, 반환된 문제 URL의 실제 HTTP 응답과
K3s Namespace·Pod·Service 정리를 직접 확인하는 검사는 포함하지 않습니다.
Provisioner가 승인한 정확한 digest만 생성할 수 있으므로 새 digest는 정책 갱신 전
실패합니다. AWS 경로는 그대로 남으며 HTTPS 경로에 문제가 생기면 caller의
`enable_runtime_https_smoke`를 꺼서 중단합니다. 설정과 검증 절차는
[`docs/gcp-runtime-https-smoke.md`](docs/gcp-runtime-https-smoke.md)에 있습니다.

## 보안 기준

- Gitleaks는 현재 branch의 `HEAD`에 도달 가능한 전체 Git 이력과 현재 파일을 모두 검사합니다.
Expand Down
42 changes: 42 additions & 0 deletions docs/gcp-runtime-https-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# GCP Runtime HTTPS smoke

## 목적

문제 이미지 발행 후 GitHub 호스팅 runner가 GCP Secure Provisioner의 공개 HTTPS API로 승인된 WEB 이미지를 생성·조회·삭제한다. Runtime이 K3s 리소스와 보안 정책의 소유자이며 Actions에는 K3s kubeconfig나 GHCR pull 토큰을 주지 않는다.

## 호출 계약

재사용 공급망 workflow에 `enable_runtime_https_smoke`(기본 `false`), `runtime_api_url`, `runtime_ci_team_id`, 기존 `runtime_target_id`를 전달한다. 호출 저장소는 `RUNTIME_API_TOKEN`을 Actions Secret으로 제공한다. 이 토큰은 Provisioner가 전용 팀·Target·승인된 digest 및 자원 상한으로 제한하며 기존 전체 권한 서비스 토큰과 다르다. URL·팀·Target은 Actions 변수로 둔다.

발행 bundle의 `artifact-v2.json`을 기존 `runtime_api_smoke_runner.py`에 입력한다. runner는 기본 인증서 검증을 켠 HTTPS로 create → Operation 조회 → delete → Operation 조회를 수행한다. 토큰은 runner 임시 파일에만 쓰고 작업 종료 시 지운다. 결과에는 토큰이나 FLAG 원문을 넣지 않는다. 발행된 digest가 아직 Provisioner 정책에 없으면 생성이 실패하며, 이미지 정책 검토·배포 후 재실행한다. 자동 승인이나 임의 digest 허용은 하지 않는다.

## 단계적 적용과 복구

기존 AWS SSM smoke job 및 `enable_k3s_smoke_deploy` 입력은 그대로 둔다. 새 HTTPS job은 별도 플래그로만 실행한다. 먼저 승인된 Grade digest를 이용한 수동 GitHub runner 시험으로 공개 TLS·토큰·생성·삭제 Operation을 검증한다. 그다음 호출 저장소가 새 재사용 workflow 커밋을 고정하고, 발행할 digest의 정책 승인을 확인한 뒤 `ENABLE_RUNTIME_HTTPS_SMOKE=true`를 설정한다. 오류가 발생하면 이 변수만 `false`로 바꿔 자동 실행을 중단한다.

기존 검사·발행·AWS job의 실행 코드는 변경하지 않는다. 다만 HTTPS smoke가 실패하면 전체 workflow도 실패하므로, 성공한 workflow만 수집하는 Backend Poller는 해당 실행의 bundle을 등록할 수 없다. 정책 미승인 digest로 자동 job을 먼저 활성화하지 않는다.

## 검증 범위

단위 검증은 workflow 입력·secret·조건부 실행, 최소 runner 권한, HTTPS 호출, 토큰 파일 정리, AWS job 불변을 확인한다. 단위 테스트 통과는 실제 문제 접속이나 운영 격리 검증을 의미하지 않는다.

현재 runner와 자동 job이 확인하는 항목은 다음과 같다.

- Runtime API의 HTTPS 인증서 검증과 인증된 요청.
- 생성 Operation의 `SUCCEEDED`와 결과의 workload 식별자 확인.
- 반환된 endpoint의 형식과 공개 포트 계약 확인. endpoint 주소로 실제 접속하는 검사는 아니다.
- 삭제 Operation의 `SUCCEEDED` 확인. K3s 리소스를 직접 조회한 삭제 확인은 아니다.

공개 문제 URL의 HTTP 응답·healthcheck, 실행 이미지 digest 대조, K3s Namespace·Pod·Service 잔존 여부, 팀·인스턴스 격리는 별도 검증이 필요하다. 새 digest 자동 승인, Scheduler reset, PWN/gVisor, 팀 인증 게이트웨이도 이 변경에 포함하지 않는다.

## 확인된 실행 기록

2026-10-06 사전 실측은 PR 작성자의 기록이다. 기존 `runtime_api_smoke_runner.py`에 승인된 Grade Tampering digest `9ffbf476…0956d`의 시험용 artifact를 전달하고 Provisioner VM에서 공개 `https://34.67.93.98:443` 경로를 호출해 생성·삭제 Operation 성공을 확인했다. 작성자가 별도로 수행한 K3s Namespace 조회에서는 제거를 확인했다고 보고했다. 이 Namespace 확인은 runner의 자동 검사 항목이 아니다.

[GitHub 호스팅 runner 수동 시험](https://github.com/MSG-CTF/2026_MSG_CTF/actions/runs/37443357952)은 성공했다. 승인된 기존 Grade digest와 workflow에서 생성한 시험용 `artifact-v2.json`을 사용했으며, 생성·삭제 Operation 성공을 확인했다. 시험용 bundle의 `scan_result: PASS`와 revision은 테스트 입력이며, 해당 실행이 이미지를 다시 빌드·검사·발행하거나 실제 릴리스를 Backend에 등록한 것은 아니다. 이 Actions에는 문제 URL의 HTTP 접속 검사나 K3s Namespace 직접 조회 단계가 없다.

## 남은 연동 검증

- 새 자동 `k3s-smoke-https` job에 실제 발행 bundle을 입력하고 승인된 최신 digest로 실행한다.
- Runtime 담당자와 공개 URL의 응답, 실행 digest, K3s 리소스 정리를 별도 확인해 실행 기록을 남긴다.
- Backend Poller 수집·릴리스 등록과 Scheduler를 통한 인스턴스 생성은 별도 경로로 검증한다. 이 smoke는 Backend와 Scheduler를 거치지 않는다.
72 changes: 70 additions & 2 deletions tests/test_workflow_contracts.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import json
import os
import subprocess
import tempfile
import unittest
from pathlib import Path

Expand Down Expand Up @@ -110,6 +114,9 @@ def test_challenge_supply_chain_has_required_contract(self):
"publish_images",
"enable_user_files_gcs_upload",
"enable_k3s_smoke_deploy",
"enable_runtime_https_smoke",
"runtime_api_url",
"runtime_ci_team_id",
"runtime_target_id",
},
)
Expand All @@ -119,6 +126,7 @@ def test_challenge_supply_chain_has_required_contract(self):
self.assertEqual(inputs["publish_images"]["type"], "boolean")
self.assertEqual(inputs["publish_images"]["default"], "true")
self.assertEqual(inputs["enable_k3s_smoke_deploy"]["type"], "boolean")
self.assertEqual(inputs["enable_runtime_https_smoke"]["default"], "false")
self.assertEqual(inputs["runtime_target_id"]["type"], "string")
outputs = workflow["on"]["workflow_call"]["outputs"]
self.assertEqual(
Expand Down Expand Up @@ -157,7 +165,7 @@ def test_challenge_supply_chain_has_required_contract(self):
self.assertEqual(text.count("ref: ${{ inputs.devsecops_ref }}"), 1)
self.assertEqual(
text.count("ref: ${{ needs.validate.outputs.devsecops_sha }}"),
5,
6,
)
self.assertIn(
'echo "run_tag=${GITHUB_SHA}-${ARTIFACT_SCOPE}"',
Expand All @@ -176,6 +184,7 @@ def test_challenge_supply_chain_has_required_contract(self):
"package-user-files",
"upload-user-files-gcs",
"k3s-smoke-deploy",
"k3s-smoke-https",
},
)
for required in (
Expand Down Expand Up @@ -304,7 +313,7 @@ def test_branch_validation_can_disable_all_publish_and_deploy_steps(self):
self.assertIn("inputs.publish_images", step.get("if", ""))
self.assertEqual(found_steps, protected_steps)

for job_name in ("aggregate", "k3s-smoke-deploy"):
for job_name in ("aggregate", "k3s-smoke-deploy", "k3s-smoke-https"):
self.assertIn(
"inputs.publish_images",
workflow["jobs"][job_name].get("if", ""),
Expand All @@ -330,6 +339,65 @@ def test_challenge_supply_chain_keeps_production_runtime_ownership(self):
)
self.assertEqual(smoke["permissions"], {"contents": "read", "id-token": "write"})

def test_https_smoke_uses_scoped_secret_and_preserves_aws_fallback(self):
workflow = load_workflow(ROOT / ".github/workflows/challenge-supply-chain.yml")
secrets = workflow["on"]["workflow_call"]["secrets"]
self.assertIn("RUNTIME_API_TOKEN", secrets)
https_smoke = workflow["jobs"]["k3s-smoke-https"]
self.assertEqual(https_smoke["permissions"], {"contents": "read"})
self.assertIn("inputs.enable_runtime_https_smoke", https_smoke["if"])
self.assertIn("github.event_name != 'pull_request'", https_smoke["if"])
self.assertNotIn("aws", str(https_smoke).lower())
steps = https_smoke["steps"]
runner = next(step for step in steps if step.get("name") == "GCP Runtime HTTPS smoke 실행")
command = runner["run"]
self.assertIn("runtime_api_smoke_runner.py", command)
self.assertIn("--api-url", command)
self.assertIn("--token-file", command)
self.assertIn("trap", command)
self.assertIn("RUNTIME_API_TOKEN", runner["env"])
self.assertIn("k3s-smoke-deploy", workflow["jobs"])

def test_https_smoke_setup_checks_team_and_target_independently(self):
workflow = load_workflow(ROOT / ".github/workflows/challenge-supply-chain.yml")
steps = workflow["jobs"]["k3s-smoke-https"]["steps"]
setup = next(step for step in steps if step.get("name") == "GCP Runtime smoke 설정 생성")
cases = (
("", "test-target", "runtime_ci_team_id"),
("test-team", "", "runtime_target_id"),
("", "", "runtime_ci_team_id"),
("test-team", "test-target", None),
)
for team, target, missing in cases:
with self.subTest(team=team, target=target), tempfile.TemporaryDirectory() as temporary:
root = Path(temporary)
(root / "dist").mkdir()
result = subprocess.run(
["bash", "-c", setup["run"]],
cwd=root,
env={
**os.environ,
"RUNTIME_API_URL": "https://runtime.example.test",
"RUNTIME_CI_TEAM_ID": team,
"RUNTIME_TARGET_ID": target,
"SMOKE_KEY": "test-repository:1:1:web-example",
},
capture_output=True,
text=True,
timeout=10,
)
config = root / "dist/runtime-smoke-config.json"
if missing:
self.assertNotEqual(result.returncode, 0)
self.assertIn(missing, result.stderr)
self.assertFalse(config.exists())
else:
self.assertEqual(result.returncode, 0, result.stderr)
data = json.loads(config.read_text(encoding="utf-8"))
self.assertEqual(data["team_id"], team)
self.assertEqual(data["target_id"], target)
self.assertTrue(data["instance_id"])

def test_branch_validation_workflow_has_no_publish_or_deploy_permissions(self):
path = ROOT / ".github/workflows/challenge-branch-validation.yml"
self.assertTrue(path.exists(), "branch 검증 reusable workflow가 필요합니다")
Expand Down
Loading