🔒 Exclude authenticated Git remotes from image provenance
This commit is contained in:
parent
412a12cfe5
commit
88992d7e61
@ -94,3 +94,5 @@
|
||||
`verify-parity` 不再把Ready/非空当结果一致:实际切换还须携带绑定当前已发布头与事实代次的新旧结果摘要、组织/供应商权限范围摘要及授权/拒绝结果,覆盖五角色、计数/看板/作业记录、正常/旧数据/日期边界/删除/返工/撤权/跨供应商/跨组织。合成证据仅用于本地验证,不能充当线上对照。后台首次准备和结果就绪只表示各自阶段,不代表已经分流或源库降载。
|
||||
|
||||
用户本轮仅授权本地修复和隔离验证,**不启动生产同步,不建生产索引,不切查询入口**。新维护窗口、镜像和具体回退仍在完整发布门禁后列入最终计划确认。
|
||||
|
||||
镜像构建统一设置 `BUILDX_GIT_INFO=0`,保留显式 commit 标签和来源记录,禁止自动收集可能含认证信息的 Git remote。API 构建脚本强制覆盖该变量;手工投影器/构建器命令也必须设置。上传后只读核验远端构建证明无带认证的 URL;存在则隔离该摘要,不部署,另列精确清理与凭证处置范围。
|
||||
|
||||
@ -7,6 +7,10 @@
|
||||
# Prints IMAGE=<registry/repository@sha256:...> for `release.py prepare --image`.
|
||||
set -euo pipefail
|
||||
|
||||
# Git remotes may contain credentials. Keep explicit commit stamps, but never
|
||||
# let Buildx attach the authenticated remote URL to metadata or attestations.
|
||||
export BUILDX_GIT_INFO=0
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
DOCKER="${DOCKER:-docker}"
|
||||
PLATFORM="${PLATFORM:-linux/amd64}"
|
||||
|
||||
@ -965,12 +965,12 @@
|
||||
},
|
||||
{
|
||||
"name": "release-config-guards",
|
||||
"paths": ["^scripts/release\\.py$", "^tests/release/test_release\\.py$"],
|
||||
"paths": ["^scripts/release\\.py$", "^tests/release/test_release\\.py$", "^scripts/release-build-api-image\\.sh$", "^tests/release/test_release_build_image\\.py$"],
|
||||
"frontend": [],
|
||||
"go": {},
|
||||
"task": [
|
||||
{
|
||||
"argv": ["python3", "-m", "unittest", "discover", "-s", "tests/release", "-p", "test_release.py"],
|
||||
"argv": ["python3", "-m", "unittest", "discover", "-s", "tests/release", "-p", "test_release*.py"],
|
||||
"tests": true
|
||||
}
|
||||
]
|
||||
|
||||
54
tests/release/test_release_build_image.py
Normal file
54
tests/release/test_release_build_image.py
Normal file
@ -0,0 +1,54 @@
|
||||
"""Exercise the release build wrapper with a fake Docker; never use a registry."""
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
|
||||
|
||||
class ReleaseBuildCredentialSafety(unittest.TestCase):
|
||||
def test_authenticated_git_info_is_disabled_without_losing_commit_proof(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
(root / 'scripts').mkdir()
|
||||
(root / 'docs/release').mkdir(parents=True)
|
||||
shutil.copyfile(ROOT / 'scripts/release-build-api-image.sh', root / 'scripts/build.sh')
|
||||
(root / 'docs/release/api-runtime.json').write_text(json.dumps({'image': 'example.invalid/runtime@sha256:' + 'a' * 64}))
|
||||
(root / 'Dockerfile.api').write_text('FROM scratch\n')
|
||||
def git(*args):
|
||||
return subprocess.check_output(['git', '-C', str(root), *args], stderr=subprocess.PIPE, text=True).strip()
|
||||
git('init', '-q')
|
||||
git('add', '.')
|
||||
git('-c', 'user.name=Synthetic', '-c', 'user.email=synthetic@example.invalid',
|
||||
'-c', 'core.hooksPath=/dev/null', 'commit', '-qm', 'fixture')
|
||||
commit = git('rev-parse', 'HEAD')
|
||||
git('remote', 'add', 'origin', 'https://synthetic:fixture-only@example.invalid/repository.git')
|
||||
fake = root / 'docker-fake'
|
||||
fake.write_text('''#!/usr/bin/env python3
|
||||
import json,os,sys
|
||||
from pathlib import Path
|
||||
args=sys.argv[1:]
|
||||
Path(os.environ['CAPTURE']).write_text(json.dumps({'gitInfo':os.environ.get('BUILDX_GIT_INFO'),'args':args}))
|
||||
Path(args[args.index('--metadata-file')+1]).write_text(json.dumps({'containerimage.digest':'sha256:'+'b'*64}))
|
||||
''')
|
||||
fake.chmod(0o700)
|
||||
capture = root / 'capture.json'
|
||||
metadata = root / 'metadata.json'
|
||||
env = {**os.environ, 'DOCKER': str(fake), 'CAPTURE': str(capture), 'BUILDX_GIT_INFO': '1'}
|
||||
subprocess.run(['bash', str(root / 'scripts/build.sh'), 'example.invalid/approved/api', str(metadata)],
|
||||
cwd=root, env=env, capture_output=True, text=True, check=True)
|
||||
actual = json.loads(capture.read_text())
|
||||
self.assertEqual(actual['gitInfo'], '0')
|
||||
self.assertIn('DROBOTICFLOW_BUILD_COMMIT=' + commit, actual['args'])
|
||||
self.assertIn('--push', actual['args'])
|
||||
proof = json.loads(Path(str(metadata) + '.provenance.json').read_text())
|
||||
self.assertEqual(proof['commit'], commit)
|
||||
self.assertEqual(proof['imageDigest'], 'sha256:' + 'b' * 64)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Loading…
x
Reference in New Issue
Block a user