From b2f1bdda1cc53bbe5c60c11f85cc0ed879a9c1a4 Mon Sep 17 00:00:00 2001 From: Zoey Rose Date: Mon, 23 Nov 2026 00:23:12 -0600 Subject: [PATCH 1/3] ci: authenticate released dependency readiness checks Client validation ran the readiness check without a token. Since main moved to the modern atrinik-protocol 0.2.1 pin, each check reads 17 public GitHub API documents, and the Linux job ran it twice: 34 unauthenticated calls per run against the runner's shared 60/hour budget. PR #81 failed both jobs with HTTP 403 rate limit exceeded. Pass the workflow's read-only token to the readiness step only. Let `ready --output` seal the sanitized documents it fetched, as `metadata` already does, and hand that file to tools/validate.sh so its second check runs offline and its Cargo steps never receive the token. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/validate.yml | 11 +++++++- README.md | 3 +++ tools/released_dependencies.py | 20 ++++++++++----- tools/test_released_dependencies.py | 39 +++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 7 deletions(-) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 75e42a8..9a82a02 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -18,8 +18,14 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 + # Modern pins read public GitHub release metadata. Authenticate only this + # step with the workflow's read-only token so the check does not depend on + # the shared 60/hour unauthenticated budget, and seal the sanitized + # documents for tools/validate.sh, whose Cargo steps never get the token. - 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 +48,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 @@ -50,6 +57,8 @@ jobs: steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - 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..67de1be 100644 --- a/README.md +++ b/README.md @@ -128,5 +128,8 @@ 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` reads that release metadata with the workflow's read-only +token in the readiness step only; the Linux job seals the sanitized documents +for `tools/validate.sh`, so its Cargo steps never receive the token. 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..23d5770 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): + """Seal the sanitized public documents this host process fetched for offline reuse.""" + 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..60ce51f 100644 --- a/tools/test_released_dependencies.py +++ b/tools/test_released_dependencies.py @@ -697,6 +697,45 @@ def fetch(url): with patch.object(updater, 'run', return_value='a' * 40): updater.load_metadata(output, root, policy) + def test_ready_output_seals_fetched_documents_for_offline_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): + updater.main() + self.assertEqual(fetch.call_count, 1) + data = output.read_text() + self.assertNotIn('fixture-read-token', data) + self.assertNotIn('synthetic-private-clone-token', data) + 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): + updater.main() + network.assert_not_called() + self.assertEqual(lock_check.call_args.args[1][NAME]['identity'], + {'id': 123, 'full_name': DEP['repository'], 'private': False}) + 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} From f2c148bff877cf3bd543318fe3b8d64ce5ff5241 Mon Sep 17 00:00:00 2001 From: Zoey Rose Date: Mon, 23 Nov 2026 00:35:35 -0600 Subject: [PATCH 2/3] ci: drop persisted checkout credentials and correct readiness wording Both validation checkouts kept the default persist-credentials, which leaves the workflow token in a Git credentials file that later steps can read. Nothing after checkout needs authenticated Git: the steps use only local history, and Cargo uses registry sources. Turn persistence off so the readiness step is the only one that gets the token. Say that the cached readiness check makes no GitHub API calls rather than that it runs offline, since it still downloads release assets and checks crates.io. Describe the cache as a create-only write, not a seal. Have the readiness fixture assert the exact cached document and the printed result. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/validate.yml | 12 ++++++++---- README.md | 8 +++++--- tools/released_dependencies.py | 2 +- tools/test_released_dependencies.py | 22 ++++++++++++++-------- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 9a82a02..f8fdb08 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -15,13 +15,15 @@ jobs: runs-on: ubuntu-24.04 timeout-minutes: 35 steps: + # Later steps use only local Git, so the token is not left in Git config. - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 - # Modern pins read public GitHub release metadata. Authenticate only this - # step with the workflow's read-only token so the check does not depend on - # the shared 60/hour unauthenticated budget, and seal the sanitized - # documents for tools/validate.sh, whose Cargo steps never get the token. + 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 env: GITHUB_READ_TOKEN: ${{ github.token }} @@ -56,6 +58,8 @@ 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 }} diff --git a/README.md b/README.md index 67de1be..ae5121f 100644 --- a/README.md +++ b/README.md @@ -128,8 +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` reads that release metadata with the workflow's read-only -token in the readiness step only; the Linux job seals the sanitized documents -for `tools/validate.sh`, so its Cargo steps never receive the token. +`Client validation` gives the workflow's read-only token only to its readiness +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 23d5770..a11f277 100644 --- a/tools/released_dependencies.py +++ b/tools/released_dependencies.py @@ -132,7 +132,7 @@ def load_metadata(path, root, policy): def write_metadata(root, policy, path): - """Seal the sanitized public documents this host process fetched for offline reuse.""" + """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' diff --git a/tools/test_released_dependencies.py b/tools/test_released_dependencies.py index 60ce51f..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,7 +699,7 @@ def fetch(url): with patch.object(updater, 'run', return_value='a' * 40): updater.load_metadata(output, root, policy) - def test_ready_output_seals_fetched_documents_for_offline_readiness(self): + 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: @@ -716,22 +718,26 @@ def source(dependency, version): 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): + 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) - data = output.read_text() - self.assertNotIn('fixture-read-token', data) - self.assertNotIn('synthetic-private-clone-token', data) + 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): + 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'], - {'id': 123, 'full_name': DEP['repository'], 'private': False}) + 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() From 453c226a34a071b5e25474bca6452a427cf637c0 Mon Sep 17 00:00:00 2001 From: Zoey Rose Date: Mon, 23 Nov 2026 00:39:51 -0600 Subject: [PATCH 3/3] docs(ci): make readiness token wording exact Later validation steps still fetch the public advisory database over anonymous network Git, so say they need no authenticated Git rather than only local Git. Checkout itself also uses the workflow token, so say the readiness step is the only step after checkout that gets it. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/validate.yml | 2 +- README.md | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index f8fdb08..3a620ad 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -15,7 +15,7 @@ jobs: runs-on: ubuntu-24.04 timeout-minutes: 35 steps: - # Later steps use only local Git, so the token is not left in Git config. + # 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 diff --git a/README.md b/README.md index ae5121f..a7caf61 100644 --- a/README.md +++ b/README.md @@ -128,10 +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` gives the workflow's read-only token only to its readiness -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 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.