Repository navigation
fix(land): prove push access only on E/F, and fence F's push on the land ref #695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7dfb9fb
fix(land): prove push access only on the stages that push
khaliqgant a158624
fix(land): fence stage F's push on the land ref
khaliqgant 4925d77
fix(land): fence F with an atomic delete of the land ref
khaliqgant d7ab5d2
docs(land): scrub a temp path from the push-fence evidence
khaliqgant 999d208
fix(land): a push that landed but failed on the client is recorded la…
khaliqgant bd2e03b
fix(land): reconcile a recreated land ref; document the delete permis…
khaliqgant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Stage F push fence: real-Git evidence | ||
|
|
||
| `fence-race.py` builds a bare remote and a clone in a temp directory, and adds a | ||
| `pre-receive` hook that moves `refs/heads/land/run` to a newer commit *after* | ||
| the advertisement and *before* the update: a newer submission arriving while | ||
| a superseded stage F pushes. | ||
|
|
||
| - `noop`: the previous fence (`<pinned>:refs/heads/land/run` with | ||
| `--force-with-lease`). Git drops the up-to-date ref from the transaction, so | ||
| the old squash lands on `main` (exit 0). This is the review finding on #695. | ||
| - `delete`: the current fence (`:refs/heads/land/run` with the lease). The | ||
| delete is a real update carrying the pinned old value, checked inside the | ||
| atomic transaction: the push fails and `main` is untouched. | ||
| - `delete`, no race: the squash lands and the land ref is deleted. | ||
|
|
||
| Run: `python3 -I examples/land/evidence/push-fence/fence-race.py` (local git only). | ||
|
|
||
| ## Permission the fence needs | ||
|
|
||
| Stage F deletes the land ref as part of the push, so the auto write grant must | ||
| allow deleting `land/*` branches (no branch rule may block their deletion). A | ||
| `--dry-run` push cannot prove branch rules, so the preflight does not check | ||
| this; a rule that blocks it ends F `needs_human` with GitHub's rejection. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| from pathlib import Path | ||
| import subprocess, tempfile, json, os, sys, shlex | ||
| SP = sys.argv[1] if len(sys.argv) > 1 else tempfile.mkdtemp(prefix="land-push-fence-") | ||
| env = os.environ.copy() | ||
| env.update({'GIT_AUTHOR_NAME':'F','GIT_AUTHOR_EMAIL':'f@example.test','GIT_COMMITTER_NAME':'F','GIT_COMMITTER_EMAIL':'f@example.test','GIT_CONFIG_GLOBAL':'/dev/null'}) | ||
| def trial(variant, race=True): | ||
| root = Path(tempfile.mkdtemp(prefix=f'fence-{variant}-', dir=SP)) | ||
| remote = root/'remote.git'; local = root/'local'; local.mkdir() | ||
| def run(*a, cwd=local, input=None): | ||
| return subprocess.check_output(['git', *a], cwd=cwd, env=env, input=input, text=True, stderr=subprocess.STDOUT).strip() | ||
| run('init', '--bare', '-q', str(remote)); run('init', '-q', '-b', 'main') | ||
| (local/'f').write_text('base\n'); run('add', '.'); run('commit', '-qm', 'base'); base = run('rev-parse', 'HEAD') | ||
| (local/'f').write_text('pinned\n'); run('commit', '-qam', 'pinned'); pinned = run('rev-parse', 'HEAD'); tree = run('rev-parse', 'HEAD^{tree}') | ||
| squash = run('commit-tree', tree, '-p', base, input='squash\n') | ||
| (local/'f').write_text('newer\n'); run('commit', '-qam', 'newer'); newer = run('rev-parse', 'HEAD') | ||
| run('remote', 'add', 'origin', str(remote)) | ||
| run('push', '-q', 'origin', f'{base}:refs/heads/main', f'{pinned}:refs/heads/land/run', f'{newer}:refs/heads/successor-source') | ||
| # Capture the ref updates the server receives on every trial; with `race`, a | ||
| # newer submission also moves the land ref after the advertisement, before the update. | ||
| hook = remote/'hooks/pre-receive' | ||
| body = '#!/bin/sh\ncat > ' + shlex.quote(str(root/'cmds.txt')) + '\n' | ||
| if race: | ||
| body += ('env -u GIT_QUARANTINE_PATH -u GIT_OBJECT_DIRECTORY -u GIT_ALTERNATE_OBJECT_DIRECTORIES git --git-dir=' | ||
| + shlex.quote(str(remote)) + ' update-ref refs/heads/land/run ' + newer + '\n') | ||
| hook.write_text(body) | ||
| hook.chmod(0o755) | ||
| lease = f'--force-with-lease=refs/heads/land/run:{pinned}' | ||
| if variant == 'noop': | ||
| cmd = ['git', 'push', '--atomic', lease, 'origin', f'{squash}:refs/heads/main', f'{pinned}:refs/heads/land/run'] | ||
| else: | ||
| cmd = ['git', 'push', '--atomic', lease, 'origin', f'{squash}:refs/heads/main', ':refs/heads/land/run'] | ||
| r = subprocess.run(cmd, cwd=local, env=env, text=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | ||
| main = run('--git-dir='+str(remote), 'rev-parse', 'refs/heads/main') | ||
| land = subprocess.run(['git', '--git-dir='+str(remote), 'rev-parse', '-q', '--verify', 'refs/heads/land/run'], env=env, text=True, stdout=subprocess.PIPE).stdout.strip() | ||
| sent = (root/'cmds.txt').read_text() if (root/'cmds.txt').exists() else '' | ||
| return {'variant': variant, 'race': race, 'exit': r.returncode, 'mainGotSquash': main == squash, | ||
| 'landRefNow': 'newer' if land == newer else ('deleted' if not land else 'pinned'), | ||
| 'landRefInTransaction': 'refs/heads/land/run' in sent, 'out': r.stdout.strip().splitlines()[-1:] } | ||
| print(subprocess.check_output(['git', '--version'], text=True).strip()) | ||
| for v in ('noop', 'delete'): | ||
| print(json.dumps(trial(v, race=True))) | ||
| print(json.dumps(trial('delete', race=False))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| git version 2.50.1 (Apple Git-155) | ||
| {"variant": "noop", "race": true, "exit": 0, "mainGotSquash": true, "landRefNow": "newer", "landRefInTransaction": false, "out": [" 00b3772..e3d0dfa e3d0dface811192c00a495144d8824d25ac1dd36 -> main"]} | ||
| {"variant": "delete", "race": true, "exit": 1, "mainGotSquash": false, "landRefNow": "newer", "landRefInTransaction": true, "out": ["error: failed to push some refs to '<tmp>/remote.git'"]} | ||
| {"variant": "delete", "race": false, "exit": 0, "mainGotSquash": true, "landRefNow": "deleted", "landRefInTransaction": true, "out": [" 0627171..c008e25 c008e25793dc225242ab98174f7542c40181010e -> main"]} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.