fix(ci): prepare fail-closed exact-SHA code-only Stage release

This commit is contained in:
Canina Automation committed 2026-10-26 16:42:08 +00:00
1 parent af32ec14e1
commit 52a7aebb51
6 files changed
+141 -10

No files matched your search

+17 -2
View File
@@ -12,10 +12,24 @@ import secrets
import stat
def provision(source: Path, output: Path) -> None:
def provision(source: Path, output: Path, repair_empty: bool = False) -> None:
for path in (source, output):
if any(parent.is_symlink() for parent in (path, *path.parents)):
raise ValueError('Unsafe runtime path')
if repair_empty and source.exists():
info = source.lstat()
if not stat.S_ISREG(info.st_mode) or info.st_nlink != 1:
raise ValueError('Unsafe runtime file')
if info.st_size == 0:
backup = source.with_name(source.name + '.empty-before-provision')
os.link(source, backup)
temporary = source.with_name(source.name + '.new-private')
fd = os.open(temporary, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600)
with os.fdopen(fd, 'w') as stream:
stream.write('REVALIDATION_SECRET=' + secrets.token_urlsafe(48) + '\n')
stream.flush()
os.fsync(stream.fileno())
os.replace(temporary, source)
if not source.exists():
fd = os.open(source, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600)
with os.fdopen(fd, 'w') as stream:
@@ -41,13 +55,14 @@ def provision(source: Path, output: Path) -> None:
def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--environment', choices=('stage', 'prod'), required=True)
parser.add_argument('--repair-empty', action='store_true')
parser.add_argument('--source', type=Path, required=True)
parser.add_argument('--output', type=Path, required=True)
args = parser.parse_args()
if os.environ.get('GITHUB_ACTIONS', os.environ.get('GITEA_ACTIONS')) != 'true':
parser.error('Provisioning requires serialized CI deployment')
try:
provision(args.source, args.output)
provision(args.source, args.output, repair_empty=args.repair_empty)
except (ValueError, OSError):
parser.exit(1, 'ERROR: revalidation provisioning failed; no secret values logged\n')