diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 75e42a8..3a620ad 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -15,11 +15,19 @@ jobs: runs-on: ubuntu-24.04 timeout-minutes: 35 steps: + # Later steps need no authenticated Git, so the token is not left in Git config. - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 + persist-credentials: false + # Modern pins read public GitHub release metadata. Give the workflow's + # read-only token to this step only, so the check does not depend on the + # shared 60/hour unauthenticated budget. Write the sanitized documents + # (create-only) so the tools/validate.sh check makes no GitHub API calls. - name: Check released dependency readiness - run: python3 tools/released_dependencies.py ready --root . + env: + GITHUB_READ_TOKEN: ${{ github.token }} + run: python3 tools/released_dependencies.py ready --root . --output "${RUNNER_TEMP}/release-metadata.json" - name: Install Linux native build dependencies run: tools/install-linux-native-deps.sh - name: Install pinned Rust quality tools @@ -42,6 +50,7 @@ jobs: - run: tools/validate.sh env: ADVISORY_BASE_REVISION: ${{ github.event.pull_request.base.sha }} + CRATE_RELEASE_METADATA_CACHE: ${{ runner.temp }}/release-metadata.json windows: name: Windows build and tests @@ -49,7 +58,11 @@ jobs: timeout-minutes: 35 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - name: Check released dependency readiness + env: + GITHUB_READ_TOKEN: ${{ github.token }} run: python tools/released_dependencies.py ready --root . - run: rustup toolchain install 1.97.1 --profile minimal --component clippy,rustfmt - run: cargo test --locked --workspace --all-targets diff --git a/README.md b/README.md index 0679ed3..a7caf61 100644 --- a/README.md +++ b/README.md @@ -128,5 +128,10 @@ Configure repository variable `CRATE_DEPENDENCY_UPDATE_APP_ID` and secret needs contents and pull-request write plus metadata read on client and editor. The readiness gate reports missing exact registry packages before compilation; the reviewed protocol 0.1.0 and 0.2.0 historical checksums remain supported. +`Client validation` passes the workflow's read-only token to its readiness step +but to no later step, and its checkouts do not persist Git credentials. The +Linux job writes the sanitized metadata documents (create-only) for +`tools/validate.sh`, whose own readiness check then makes no GitHub API calls. +It still downloads release assets and checks crates.io. Client's ten internal crates have `publish = false`; application GitHub releases continue through their existing workflows. diff --git a/tools/released_dependencies.py b/tools/released_dependencies.py index 5f904c0..a11f277 100644 --- a/tools/released_dependencies.py +++ b/tools/released_dependencies.py @@ -131,6 +131,16 @@ def load_metadata(path, root, policy): _OFFLINE_DOCUMENTS = True +def write_metadata(root, policy, path): + """Write (create-only) the sanitized public API documents this host process fetched.""" + value = {'schema_version': 1, 'repository': policy['repository'], + 'base': run('git', 'rev-parse', 'HEAD', cwd=root), 'documents': _DOCUMENTS} + data = json.dumps(value, sort_keys=True) + '\n' + require(len(data.encode()) <= MAX_METADATA_BYTES, 'metadata cache exceeds bound') + with path.open('x') as output: + output.write(data) + + def exact_dependencies(root, policy): for config in (root / '.cargo/config', root / '.cargo/config.toml'): if config.exists(): @@ -599,6 +609,7 @@ def main(): require(policy['schema_version'] == 1, 'unsupported dependency policy') if args.metadata_cache is not None: require(args.command not in {'metadata', 'publish'}, 'publication requires fresh host metadata verification') + require(args.command != 'ready' or args.output is None, 'readiness metadata output requires fresh host verification') load_metadata(args.metadata_cache, root, policy) if args.command == 'publish': publish(root, args.output, policy) @@ -611,12 +622,7 @@ def main(): exact_dependencies(root, policy) for dep in policy['dependencies']: source(dep) - value = {'schema_version': 1, 'repository': policy['repository'], - 'base': run('git', 'rev-parse', 'HEAD', cwd=root), 'documents': _DOCUMENTS} - data = json.dumps(value, sort_keys=True) + '\n' - require(len(data.encode()) <= MAX_METADATA_BYTES, 'metadata cache exceeds bound') - with args.output.open('x') as output: - output.write(data) + write_metadata(root, policy, args.output) return if args.command == 'verify-lock': verify_lock(root, args.output, policy) @@ -634,6 +640,8 @@ def main(): return if args.command == 'ready': lock_check(root, records) + if args.output is not None: + write_metadata(root, policy, args.output) print('Dependency readiness policy verified.') return require(args.output is not None, 'prepare requires --output') diff --git a/tools/test_released_dependencies.py b/tools/test_released_dependencies.py index 37c79a4..259563b 100644 --- a/tools/test_released_dependencies.py +++ b/tools/test_released_dependencies.py @@ -1,6 +1,8 @@ """Network-free registry, provenance and ownership failure fixtures.""" # Copyright (c) 2026 Atrinik contributors. SPDX-License-Identifier: MIT +import contextlib import hashlib +import io import json from pathlib import Path import tempfile @@ -697,6 +699,49 @@ def fetch(url): with patch.object(updater, 'run', return_value='a' * 40): updater.load_metadata(output, root, policy) + def test_ready_output_writes_fetched_documents_for_api_free_readiness(self): + identity = {'id': 123, 'full_name': DEP['repository'], 'private': False, + 'temp_clone_token': 'synthetic-private-clone-token'} + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + policy = {'schema_version': 1, 'repository': 'atrinik/client', 'dependencies': [DEP]} + (root / 'policy').mkdir() + (root / 'policy/released-dependencies.json').write_text(json.dumps(policy)) + (root / 'Cargo.toml').write_text('[workspace.dependencies]\natrinik-protocol = "=0.2.1"\n') + output = root / 'metadata.json' + record = {'name': NAME, 'version': '0.2.1', 'sha256': SHA} + def source(dependency, version): + self.assertEqual(version, '0.2.1') + updater.document('https://api.github.com/repos/' + dependency['repository']) + return record + argv = ['updater', 'ready', '--root', str(root), '--output', str(output)] + with patch('sys.argv', argv), patch.dict(updater.os.environ, {'GITHUB_READ_TOKEN': 'fixture-read-token'}, clear=True), \ + patch.object(updater, 'fetch', return_value=json.dumps(identity).encode()) as fetch, \ + patch.object(updater, 'source', side_effect=source), patch.object(updater, 'lock_check'), \ + patch.object(updater, 'run', return_value='a' * 40), \ + contextlib.redirect_stdout(io.StringIO()) as stdout: + updater.main() + self.assertEqual(stdout.getvalue(), 'Dependency readiness policy verified.\n') + self.assertEqual(fetch.call_count, 1) + sanitized = {'id': 123, 'full_name': DEP['repository'], 'private': False} + self.assertEqual(json.loads(output.read_text()), { + 'schema_version': 1, 'repository': 'atrinik/client', 'base': 'a' * 40, + 'documents': {'https://api.github.com/repos/' + DEP['repository']: sanitized}}) + def offline(dependency, version): + return dict(record, identity=updater.document('https://api.github.com/repos/' + dependency['repository'])) + with patch('sys.argv', ['updater', 'ready', '--root', str(root)]), \ + patch.dict(updater.os.environ, {'CRATE_RELEASE_METADATA_CACHE': str(output)}, clear=True), \ + patch.object(updater, 'fetch') as network, patch.object(updater, 'source', side_effect=offline), \ + patch.object(updater, 'lock_check') as lock_check, patch.object(updater, 'run', return_value='a' * 40), \ + contextlib.redirect_stdout(io.StringIO()) as stdout: + updater.main() + self.assertEqual(stdout.getvalue(), 'Dependency readiness policy verified.\n') + network.assert_not_called() + self.assertEqual(lock_check.call_args.args[1][NAME]['identity'], sanitized) + with patch('sys.argv', argv + ['--metadata-cache', str(output)]), patch.dict(updater.os.environ, {}, clear=True), \ + patch.object(updater, 'run', return_value='a' * 40), self.assertRaisesRegex(ValueError, 'fresh host verification'): + updater.main() + def test_draft_sanitization_preserves_pagination_cardinality(self): drafts = [{'draft': True, 'body': 'private draft content'}] * 30 identity = {'id': DEP['repository_id'], 'full_name': DEP['repository'], 'private': False}