Require authoritative Drive ACL and inheritance proof before Greif custody
This commit is contained in:
1 parent
ff3f1350c7
commit
dbb03c7dfa
10 files changed
+2876
-10
No files matched your search
+1124
File diff suppressed because it is too large.
Load diff
+1302
File diff suppressed because it is too large.
Load diff
+128
@@ -0,0 +1,128 @@
|
||||
{
|
||||
"status": "PASS",
|
||||
"tests": 18,
|
||||
"acl_cases": {
|
||||
"inherited-outside": {
|
||||
"custody_reached": false,
|
||||
"synthetic_reads": 0,
|
||||
"provider_queries": [
|
||||
[
|
||||
"fixture-archive",
|
||||
null
|
||||
],
|
||||
[
|
||||
"fixture-archive/permissions",
|
||||
null
|
||||
],
|
||||
[
|
||||
"1quVPlAkM8lK95siVoA0YQ23I9I-0kch3",
|
||||
null
|
||||
],
|
||||
[
|
||||
"1quVPlAkM8lK95siVoA0YQ23I9I-0kch3/permissions",
|
||||
null
|
||||
],
|
||||
[
|
||||
"root",
|
||||
null
|
||||
],
|
||||
[
|
||||
"0AD1IMHKOPZB4Uk9PVA/permissions",
|
||||
null
|
||||
]
|
||||
]
|
||||
},
|
||||
"no-transport": {
|
||||
"custody_reached": false,
|
||||
"synthetic_reads": 0,
|
||||
"provider_queries": []
|
||||
},
|
||||
"missing-acl": {
|
||||
"custody_reached": false,
|
||||
"synthetic_reads": 0,
|
||||
"provider_queries": [
|
||||
[
|
||||
"fixture-archive",
|
||||
null
|
||||
],
|
||||
[
|
||||
"fixture-archive/permissions",
|
||||
null
|
||||
]
|
||||
]
|
||||
},
|
||||
"project-only": {
|
||||
"custody_reached": true,
|
||||
"synthetic_reads": 1,
|
||||
"provider_queries": [
|
||||
[
|
||||
"fixture-archive",
|
||||
null
|
||||
],
|
||||
[
|
||||
"fixture-archive/permissions",
|
||||
null
|
||||
],
|
||||
[
|
||||
"1quVPlAkM8lK95siVoA0YQ23I9I-0kch3",
|
||||
null
|
||||
],
|
||||
[
|
||||
"1quVPlAkM8lK95siVoA0YQ23I9I-0kch3/permissions",
|
||||
null
|
||||
],
|
||||
[
|
||||
"root",
|
||||
null
|
||||
],
|
||||
[
|
||||
"0AD1IMHKOPZB4Uk9PVA/permissions",
|
||||
null
|
||||
],
|
||||
[
|
||||
"fixture-archive",
|
||||
null
|
||||
],
|
||||
[
|
||||
"1quVPlAkM8lK95siVoA0YQ23I9I-0kch3",
|
||||
null
|
||||
],
|
||||
[
|
||||
"root",
|
||||
null
|
||||
]
|
||||
]
|
||||
},
|
||||
"anyone-link-page2": {
|
||||
"custody_reached": false,
|
||||
"synthetic_reads": 0,
|
||||
"provider_queries": [
|
||||
[
|
||||
"fixture-archive",
|
||||
null
|
||||
],
|
||||
[
|
||||
"fixture-archive/permissions",
|
||||
null
|
||||
],
|
||||
[
|
||||
"fixture-archive/permissions",
|
||||
"fixture-page-2"
|
||||
]
|
||||
]
|
||||
},
|
||||
"other-folder": {
|
||||
"custody_reached": false,
|
||||
"synthetic_reads": 0,
|
||||
"provider_queries": []
|
||||
}
|
||||
},
|
||||
"contract_sha256": "c3074afd0d124a6351275f3c9c33e96038d6be3e2687223033fa66573c57c94a",
|
||||
"comparison_preserved_sha256": "9d42281db903a9fc268328e40d1f54c4a037f3cf58573e6fc78c9bb63ab3788e",
|
||||
"previous_contract_sha256": "f56e0d1a0e64fb46f2af6a731730308856083bdd18cfe030ab478b0cd841d539",
|
||||
"actual_gpu_queries": 0,
|
||||
"actual_target_reads": 0,
|
||||
"actual_uploads": 0,
|
||||
"runtime_drive_credential_present": false,
|
||||
"replay_log_sha256": "a57e51c2f9bf92919bb10170c625b119253ca06f4a3658e99f865d0789594b83"
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
test_inherited_non_project_user_is_blocked (test_track_b_gino_greif_drive_acl.CustodyACL) ... ok
|
||||
test_missing_current_transport_and_missing_effective_acl_stop (test_track_b_gino_greif_drive_acl.CustodyACL) ... ok
|
||||
test_project_acl_and_entire_ancestry_positive_control (test_track_b_gino_greif_drive_acl.CustodyACL) ... ok
|
||||
test_unlisted_link_reader_is_blocked_even_on_later_page (test_track_b_gino_greif_drive_acl.CustodyACL) ... ok
|
||||
test_wrong_folder_is_rejected_before_provider_access (test_track_b_gino_greif_drive_acl.CustodyACL) ... ok
|
||||
test_all_19_columns_contribute_and_mass_is_preserved (test_track_b_gino_greif_adapter.GreifAdapter) ... ok
|
||||
test_exact_gather_on_affine_field_and_isotropic_translation (test_track_b_gino_greif_adapter.GreifAdapter) ... ok
|
||||
test_pinned_model_full_64_cpu_forward_and_small_backward (test_track_b_gino_greif_adapter.GreifAdapter) ... ok
|
||||
test_real_production_guard_idle_and_busy_with_frozen_limits (test_track_b_gino_greif_adapter.GreifAdapter) ... ok
|
||||
test_release_gate_requires_both_full_folds_and_respects_phase_cap (test_track_b_gino_greif_adapter.GreifAdapter) ... ok
|
||||
test_source_columns_and_h2_paired_domain (test_track_b_gino_greif_adapter.GreifAdapter) ... ok
|
||||
test_actual_checkpoint_preserves_optimizer_for_second_update (test_track_b_gino_greif_combined.Combined) ... ok
|
||||
test_first_cost_gate_counts_spent_and_blocks_over_budget (test_track_b_gino_greif_combined.Combined) ... ok
|
||||
test_matching_drive_checksum_is_required (test_track_b_gino_greif_combined.Combined) ... ok
|
||||
test_no_review_prevents_any_gpu_probe (test_track_b_gino_greif_combined.Combined) ... ok
|
||||
test_replays_actual_production_guard_and_stage_order (test_track_b_gino_greif_combined.Combined) ... ok
|
||||
test_scoring_decision_fixed_roster_and_named_hard_intersection (test_track_b_gino_greif_combined.Combined) ... ok
|
||||
test_two_predictions_share_exactly_one_mock_target_open (test_track_b_gino_greif_combined.Combined) ... ok
|
||||
|
||||
----------------------------------------------------------------------
|
||||
Ran 18 tests in 10.815s
|
||||
|
||||
OK
|
||||
@@ -0,0 +1,9 @@
|
||||
# GINO-Greif 保管权限差量复审
|
||||
|
||||
MeltAssist 在旧绑定 `f46f4036` 发现,只要本地回执写 `project_private=true`,缺权限或仅凭链接可读的文件都能到达留出读取。该回执现只用于绑定上传文件 ID、父目录和冻结归档,评分器从 Google Drive API 获取实际权限证据。 [原阻塞回执](https://arcticnimbus.slack.com/archives/C0C78UFKGRM/p1795092014928129) · [修订保管门](../tools/track_b_gino_greif_custody.py)
|
||||
|
||||
校验只涉及新归档、固定私有项目目录及其 My Drive 根。评分器走 HTTPS GET 读取 Google Drive v3 文件元数据及逐页权限,包括 published 视图。它核对原始二进制文件 SHA-256 和大小,核对父目录链、拥有者可见权限 ID 全集及前后文件版本,再保存实际权限证据。固定项目目录的既有只读元数据仅列已核项目拥有者,同一身份的归档及祖先 ACL 才能通过。任何 `anyone` 权限都拒绝,含 `allowFileDiscovery=false` 的凭链接访问。组、域、公开视图、项目外用户、无法核对的上级目录或中途权限变化也拒绝。 [Live ACL 实现](../tools/track_b_gino_greif_drive_acl.py) · [Drive 权限和继承](https://developers.google.com/workspace/drive/api/guides/manage-sharing) · [逐页权限 API](https://developers.google.com/workspace/drive/api/reference/rest/v3/permissions/list)
|
||||
|
||||
CPU 回放走了生产 `score()` 入口,在网络一层提供合成 API 响应。缺有效权限数据、后续页出现凭链接读权限、继承来的项目外用户及错误目录均在创建保管目录前拒绝,目标读为零。项目内权限对照先固定证据哈希,再到达合成目标读取一次。保留两套原 CPU 回放,共 18 项通过。预登记比较合同逐字一致,模型、训练、预算和评分定义沿原绑定。 [回放回执](../artifacts/track-b-gino-greif-preparation-2026-11-19/combined-review-acl-v2/cpu-replay.json)
|
||||
|
||||
当前连接器能返回经裁剪的目录权限视图,权限 ID 和继承细节没有随响应提供。当前 Horsea 运行时未配置已授权的原始只读权限查询通道。生产路径只用已有授权凭据提供的只读传输,缺此通道即停在保管门。合成验收不能替代实际项目权限放行。本次仅读取固定项目目录与直接祖先的元数据,无权限更新、上传、留出目标读取和 GPU 查询。 [Drive 只读元数据说明](https://developers.google.com/workspace/drive/api/guides/file-metadata)
|
||||
@@ -165,7 +165,9 @@ class Combined(unittest.TestCase):
|
||||
with self.assertRaises(PermissionError):
|
||||
custody.verify_drive(auth)
|
||||
save(root/'drive-readback.json',dict(receipt,sha256Checksum=sha(path)))
|
||||
self.assertEqual(custody.verify_drive(auth)['file_id'],'fixture')
|
||||
with patch.object(custody,'prove_drive_acl',return_value={'file_id':'fixture'}) as acl:
|
||||
self.assertEqual(custody.verify_drive(auth)['file_id'],'fixture')
|
||||
acl.assert_called_once_with('fixture','folder-fixture',sha(path),bundle['bytes'])
|
||||
|
||||
def test_two_predictions_share_exactly_one_mock_target_open(self):
|
||||
with TemporaryDirectory() as directory:
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
"""Exercise the real Greif custody gate with synthetic Drive API metadata."""
|
||||
|
||||
from contextlib import ExitStack
|
||||
import hashlib
|
||||
from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
import track_b_gino_greif_custody as custody
|
||||
import track_b_gino_greif_drive_acl as acl
|
||||
import track_b_gino_greif_entry as entry
|
||||
from track_b_gino_shapenet_entry import read, save, sha
|
||||
|
||||
|
||||
EVIDENCE = {}
|
||||
OWNER_EMAIL = 'fixture-owner@example.invalid'
|
||||
ARCHIVE_ID = 'fixture-archive'
|
||||
|
||||
|
||||
class CustodyACL(unittest.TestCase):
|
||||
def replay(self, mode):
|
||||
with TemporaryDirectory() as folder, ExitStack() as stack:
|
||||
root = Path(folder)
|
||||
for name in ('contract.json','models-frozen.json','predictions-frozen.json'):
|
||||
save(root/name, {})
|
||||
archive = root/'gino-greif-models-and-predictions.zip'
|
||||
archive.write_bytes(b'synthetic immutable archive')
|
||||
digest, size = sha(archive), archive.stat().st_size
|
||||
scope = dict(private_drive_folder_id=acl.PROJECT_FOLDER)
|
||||
if mode == 'other-folder':
|
||||
scope['private_drive_folder_id'] = 'out-of-scope'
|
||||
bundle = dict(path=str(archive), sha256=digest, bytes=size,contract_sha256=sha(root/'contract.json'),
|
||||
model_index_sha256=sha(root/'models-frozen.json'),
|
||||
prediction_index_sha256=sha(root/'predictions-frozen.json'))
|
||||
save(root/'drive-upload-index.json',bundle)
|
||||
# This is the assertion that formerly bypassed all permission checks.
|
||||
save(root/'drive-readback.json',dict(sha256Checksum=digest,size=str(size),
|
||||
parent_id=scope['private_drive_folder_id'],file_id=ARCHIVE_ID,project_private=True,
|
||||
contract_sha256=bundle['contract_sha256']))
|
||||
case = 'synthetic_part'
|
||||
compare = root/'comparison.json'
|
||||
reference = root/'reference.json'
|
||||
save(reference,dict(status='COMPLETE',rows=[dict(case=case)]+[
|
||||
dict(case=f'other-{i}') for i in range(551)]))
|
||||
save(compare,dict(roster=[dict(case=case,fold=0)],h2_score=dict(path=str(reference),sha256=sha(reference))))
|
||||
pilot, query = root/'pilot.json',root/'query.json'
|
||||
save(pilot,{})
|
||||
save(query,dict(rows=[dict(case=case,included=True)]))
|
||||
pins = {str(p):sha(p) for p in (pilot,query)}
|
||||
c=dict(budgets={'score_cpu_seconds':3600},comparison_contract=str(compare),comparison_contract_sha256=sha(compare))
|
||||
forecasts=[dict(case=case,fold=0,seed=s) for s in (0,1)]
|
||||
owner=dict(id='fixture-owner-id',type='user',role='owner',emailAddress=OWNER_EMAIL)
|
||||
inherited=dict(id='foreign-id',type='user',role='reader',emailAddress='foreign@example.invalid',
|
||||
permissionDetails=[dict(inherited=True,inheritedFrom=acl.PROJECT_MY_DRIVE_ROOT)])
|
||||
linked=dict(id='anyone',type='anyone',role='reader',allowFileDiscovery=False)
|
||||
calls=[]
|
||||
def provider(path, query, token):
|
||||
self.assertEqual(token,'fixture-token')
|
||||
calls.append((path, query.get('pageToken')))
|
||||
if path.endswith('/permissions'):
|
||||
self.assertEqual(query['includePermissionsForView'],'published')
|
||||
if mode=='missing-acl' and path==ARCHIVE_ID+'/permissions':
|
||||
return {}
|
||||
if mode=='anyone-link-page2' and path==ARCHIVE_ID+'/permissions':
|
||||
if query.get('pageToken')=='fixture-page-2':
|
||||
return dict(permissions=[linked])
|
||||
return dict(permissions=[owner],nextPageToken='fixture-page-2')
|
||||
if mode=='inherited-outside' and path==acl.PROJECT_MY_DRIVE_ROOT+'/permissions':
|
||||
return dict(permissions=[owner,inherited])
|
||||
return dict(permissions=[owner])
|
||||
item=dict(id=path,ownedByMe=True,trashed=False,version='1',permissionIds=[owner['id']],mimeType=acl.FOLDER_TYPE)
|
||||
if path==ARCHIVE_ID:
|
||||
return dict(item,parents=[acl.PROJECT_FOLDER],mimeType='application/zip',size=str(size),sha256Checksum=digest)
|
||||
if path==acl.PROJECT_FOLDER:
|
||||
return dict(item,parents=[acl.PROJECT_MY_DRIVE_ROOT])
|
||||
if path=='root':
|
||||
return dict(item,id=acl.PROJECT_MY_DRIVE_ROOT)
|
||||
raise AssertionError('Unexpected item outside the fixed chain')
|
||||
|
||||
stack.enter_context(patch.dict('os.environ',CUDA_VISIBLE_DEVICES=''))
|
||||
stack.enter_context(patch.object(entry,'ROOT',root))
|
||||
stack.enter_context(patch.object(entry,'authorize',return_value=(scope,0.)))
|
||||
for k,v in dict(PILOT=pilot,QUERY=query,PINS=pins).items():
|
||||
stack.enter_context(patch.object(custody,k,v))
|
||||
stack.enter_context(patch.object(custody,'frozen',return_value=([],forecasts)))
|
||||
stack.enter_context(patch.object(custody.resource,'setrlimit'))
|
||||
stack.enter_context(patch.object(acl,'PROJECT_OWNER_SHA256',hashlib.sha256(OWNER_EMAIL.encode()).hexdigest()))
|
||||
if mode=='no-transport':
|
||||
custody.os.environ.pop(acl.TOKEN_FD,None)
|
||||
else:
|
||||
stack.enter_context(patch.object(acl,'_credential',return_value='fixture-token'))
|
||||
stack.enter_context(patch.object(acl,'_get_json',side_effect=provider))
|
||||
stack.enter_context(patch.object(custody,'summary',return_value={}))
|
||||
read_target=stack.enter_context(patch.object(custody,'target_array',return_value='synthetic target'))
|
||||
|
||||
def case_reached(*_):
|
||||
proof=root/'score/drive-acl-evidence.json'
|
||||
self.assertEqual(read(root/'score/custody-start.json')['drive_acl_evidence_sha256'],sha(proof))
|
||||
read_target({},case)
|
||||
return dict(case=case)
|
||||
|
||||
reader=stack.enter_context(patch.object(custody,'one_case',side_effect=case_reached))
|
||||
if mode=='project-only':
|
||||
self.assertEqual(custody.score(c),0)
|
||||
read_target.assert_called_once()
|
||||
proof=read(root/'score/drive-acl-evidence.json')
|
||||
self.assertEqual([x['file_id'] for x in proof['chain']],
|
||||
[ARCHIVE_ID,acl.PROJECT_FOLDER,acl.PROJECT_MY_DRIVE_ROOT])
|
||||
EVIDENCE[mode] = dict(custody_reached=True,synthetic_reads=1,provider_queries=calls)
|
||||
else:
|
||||
with self.assertRaises(PermissionError):
|
||||
custody.score(c)
|
||||
reader.assert_not_called()
|
||||
read_target.assert_not_called()
|
||||
self.assertFalse((root/'score').exists())
|
||||
EVIDENCE[mode] = dict(custody_reached=False,synthetic_reads=0,provider_queries=calls)
|
||||
|
||||
def test_missing_current_transport_and_missing_effective_acl_stop(self):
|
||||
for mode in ('no-transport','missing-acl'):
|
||||
self.replay(mode)
|
||||
|
||||
def test_unlisted_link_reader_is_blocked_even_on_later_page(self):
|
||||
self.replay('anyone-link-page2')
|
||||
self.assertIn((ARCHIVE_ID+'/permissions','fixture-page-2'), EVIDENCE['anyone-link-page2']['provider_queries'])
|
||||
|
||||
def test_inherited_non_project_user_is_blocked(self):
|
||||
self.replay('inherited-outside')
|
||||
|
||||
def test_wrong_folder_is_rejected_before_provider_access(self):
|
||||
self.replay('other-folder')
|
||||
self.assertEqual(EVIDENCE['other-folder']['provider_queries'],[])
|
||||
|
||||
def test_project_acl_and_entire_ancestry_positive_control(self):
|
||||
self.replay('project-only')
|
||||
|
||||
|
||||
if __name__=='__main__':
|
||||
unittest.main()
|
||||
@@ -16,6 +16,7 @@ from phase2_h2_data import cached
|
||||
from s2_custody_common import prediction_inputs
|
||||
from s2_custody_statistics import part_metrics
|
||||
import track_b_gino_greif_entry as entry
|
||||
from track_b_gino_greif_drive_acl import prove as prove_drive_acl
|
||||
from track_b_gino_greif_prepare import PILOT, QUERY, PINS
|
||||
from track_b_gino_shapenet_entry import BASE, checked, read, save, sha
|
||||
|
||||
@@ -80,14 +81,14 @@ def verify_drive(auth):
|
||||
or bundle['prediction_index_sha256']!=sha(root/'predictions-frozen.json')):
|
||||
raise ValueError('Local archive no longer matches the fixed models and forecasts')
|
||||
receipt=read(root/'drive-readback.json')
|
||||
# Drive file metadata, recorded by the authorized connector from the private project folder.
|
||||
# Transfer bookkeeping binds the file ID to the expected archive. The
|
||||
# actual ACL and remote file identity come from the live provider.
|
||||
if (receipt.get('sha256Checksum'),receipt.get('size'),receipt.get('parent_id')) != (
|
||||
bundle['sha256'],str(bundle['bytes']),auth['private_drive_folder_id']):
|
||||
raise PermissionError('Private Drive readback SHA, size and folder are required before scoring')
|
||||
if (not receipt.get('file_id') or receipt.get('project_private') is not True
|
||||
or receipt.get('contract_sha256')!=bundle['contract_sha256']):
|
||||
raise PermissionError('Private Drive identity required before opening targets')
|
||||
return receipt
|
||||
if receipt.get('contract_sha256')!=bundle['contract_sha256']:
|
||||
raise PermissionError('Drive transfer does not match the reviewed contract')
|
||||
return prove_drive_acl(receipt.get('file_id'),auth['private_drive_folder_id'],bundle['sha256'],bundle['bytes'])
|
||||
|
||||
|
||||
def bootstrap(rows, metric, fixed_support=None):
|
||||
@@ -194,12 +195,16 @@ def score(c):
|
||||
query={r['case']:r for r in read(checked(QUERY,PINS[str(QUERY)]))['rows'] if r['included']}
|
||||
out=entry.ROOT/'score'
|
||||
out.mkdir(exist_ok=False)
|
||||
evidence=out/'drive-acl-evidence.json'
|
||||
save(evidence,dict(drive,observed_before_target_reads=True))
|
||||
save(out/'custody-start.json',dict(unix=time.time(),drive_file_id=drive['file_id'],
|
||||
manifest_sha256=sha(entry.ROOT/'predictions-frozen.json'),before_test_target_reads=True))
|
||||
drive_acl_evidence_sha256=sha(evidence), manifest_sha256=sha(entry.ROOT/'predictions-frozen.json'),
|
||||
before_test_target_reads=True))
|
||||
results=[]
|
||||
with (out/'heldout-target-access.jsonl').open('x') as log:
|
||||
for row in compare['roster']:
|
||||
results.append(one_case(pilot,query[row['case']],row,new,reference,log))
|
||||
save(out/'result.json',dict(status='COMPLETE',summary=summary(results,compare),rows=results,
|
||||
unique_test_target_reads=len(results),no_new_decode=True,drive_file_id=drive['file_id']))
|
||||
unique_test_target_reads=len(results),no_new_decode=True,drive_file_id=drive['file_id'],
|
||||
drive_acl_evidence_sha256=sha(evidence)))
|
||||
return 0
|
||||
@@ -0,0 +1,132 @@
|
||||
"""Prove the fixed project's effective ACL with live, owner-visible Drive metadata."""
|
||||
|
||||
import hashlib
|
||||
import http.client
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
from urllib.parse import urlencode
|
||||
|
||||
|
||||
PROJECT_FOLDER = '1quVPlAkM8lK95siVoA0YQ23I9I-0kch3'
|
||||
PROJECT_MY_DRIVE_ROOT = '0AD1IMHKOPZB4Uk9PVA'
|
||||
PROJECT_OWNER_SHA256 = 'feb12acc4cc98e55902b56268f726f3489d3e5baaf6aafef2fbff7e485f2a1b2'
|
||||
TOKEN_FD = 'MELTMIND_DRIVE_METADATA_TOKEN_FD'
|
||||
HOST = 'www.googleapis.com'
|
||||
FOLDER_TYPE = 'application/vnd.google-apps.folder'
|
||||
FILE_FIELDS = 'id,parents,driveId,mimeType,ownedByMe,trashed,permissionIds,version,size,sha256Checksum'
|
||||
ACL_FIELDS = ('nextPageToken,permissions(id,type,role,emailAddress,domain,allowFileDiscovery,deleted,view,'
|
||||
'permissionDetails(inherited,inheritedFrom,permissionType,role))')
|
||||
ID = re.compile(r'[A-Za-z0-9_-]+\Z')
|
||||
|
||||
|
||||
def _credential():
|
||||
fd = os.environ.get(TOKEN_FD, '')
|
||||
if not fd.isascii() or not fd.isdecimal() or int(fd) < 3:
|
||||
raise PermissionError('Existing authorized Drive metadata transport is unavailable')
|
||||
try:
|
||||
with os.fdopen(os.dup(int(fd)), 'rb') as source:
|
||||
token = source.readline(8193).strip().decode('ascii')
|
||||
except (OSError, ValueError, UnicodeError):
|
||||
raise PermissionError('Existing authorized Drive metadata transport is unavailable') from None
|
||||
if not token or len(token) > 8192 or any(not 33 <= ord(ch) <= 126 for ch in token):
|
||||
raise PermissionError('Drive metadata transport provided no usable credential')
|
||||
return token
|
||||
|
||||
|
||||
def _get_json(path, query, token):
|
||||
connection = http.client.HTTPSConnection(HOST, timeout=15)
|
||||
try:
|
||||
connection.request('GET', '/drive/v3/files/' + path + '?' + urlencode(query),
|
||||
headers={'Authorization': 'Bearer ' + token, 'Accept': 'application/json'})
|
||||
response = connection.getresponse()
|
||||
if response.status != 200:
|
||||
raise PermissionError(f'Authoritative Drive metadata status {response.status}')
|
||||
data = response.read(2**20 + 1)
|
||||
if len(data) > 2**20:
|
||||
raise PermissionError('Oversized Drive metadata')
|
||||
value = json.loads(data)
|
||||
if not isinstance(value, dict):
|
||||
raise PermissionError('Invalid Drive metadata response')
|
||||
return value
|
||||
except PermissionError:
|
||||
raise
|
||||
except (OSError, ValueError, http.client.HTTPException):
|
||||
raise PermissionError('Authoritative Drive metadata could not be verified') from None
|
||||
finally:
|
||||
connection.close()
|
||||
|
||||
|
||||
def _listed_permissions(file_id, token):
|
||||
query = dict(fields=ACL_FIELDS, pageSize=100, supportsAllDrives='true', includePermissionsForView='published')
|
||||
rows, seen = [], set()
|
||||
for _ in range(20):
|
||||
page = _get_json(file_id + '/permissions', query, token)
|
||||
permissions = page.get('permissions')
|
||||
if not isinstance(permissions, list):
|
||||
raise PermissionError('Missing effective Drive permissions')
|
||||
rows.extend(permissions)
|
||||
if 'nextPageToken' not in page:
|
||||
return rows
|
||||
next_page = page['nextPageToken']
|
||||
if not isinstance(next_page, str) or not next_page or next_page in seen:
|
||||
raise PermissionError('Incomplete Drive permissions pagination')
|
||||
seen.add(next_page)
|
||||
query['pageToken'] = next_page
|
||||
raise PermissionError('Incomplete Drive permissions pagination')
|
||||
|
||||
|
||||
def _member_evidence(item, token):
|
||||
rows = _listed_permissions(item['id'], token)
|
||||
provider_ids = item.get('permissionIds')
|
||||
if not rows or not isinstance(provider_ids, list) or not all(isinstance(p, str) and p for p in provider_ids):
|
||||
raise PermissionError('No complete effective Drive permissions evidence')
|
||||
matches, ids = [], set()
|
||||
for row in rows:
|
||||
if not isinstance(row, dict) or row.get('type') != 'user' or row.get('view') == 'published':
|
||||
raise PermissionError('Public, linked, group or domain Drive access is out of scope')
|
||||
email, pid, role = row.get('emailAddress'), row.get('id'), row.get('role')
|
||||
if (not isinstance(email, str) or not isinstance(pid, str) or not pid or pid in ids
|
||||
or role not in ('owner', 'writer', 'commenter', 'reader') or row.get('deleted') is True):
|
||||
raise PermissionError('Unverifiable Drive principal or role')
|
||||
principal = hashlib.sha256(email.strip().casefold().encode()).hexdigest()
|
||||
if principal != PROJECT_OWNER_SHA256:
|
||||
raise PermissionError('Drive access outside the verified project principal')
|
||||
ids.add(pid)
|
||||
matches.append(dict(id=pid,type='user',role=role,principal_sha256=principal,
|
||||
permission_details=row.get('permissionDetails', [])))
|
||||
if ids != set(provider_ids) or not any(p['role']=='owner' for p in matches):
|
||||
raise PermissionError('Owner-visible effective Drive ACL is incomplete')
|
||||
return matches
|
||||
|
||||
|
||||
def prove(file_id, folder_id, digest, size):
|
||||
if (folder_id != PROJECT_FOLDER or not isinstance(file_id, str) or not ID.fullmatch(file_id)
|
||||
or file_id in (PROJECT_FOLDER, PROJECT_MY_DRIVE_ROOT, 'root')):
|
||||
raise PermissionError('Archive must be in the fixed project folder')
|
||||
token = _credential()
|
||||
query = dict(fields=FILE_FIELDS, supportsAllDrives='true')
|
||||
lookup = ((file_id, file_id, [PROJECT_FOLDER]), (PROJECT_FOLDER, PROJECT_FOLDER, [PROJECT_MY_DRIVE_ROOT]),
|
||||
('root', PROJECT_MY_DRIVE_ROOT, []))
|
||||
observations = []
|
||||
for locator, expected_id, parents in lookup:
|
||||
item = _get_json(locator, query, token)
|
||||
if (item.get('id') != expected_id or item.get('parents', []) != parents or item.get('driveId')
|
||||
or item.get('ownedByMe') is not True or item.get('trashed') is not False
|
||||
or not isinstance(item.get('version'), str) or not item['version'].isdecimal()):
|
||||
raise PermissionError('Drive archive or inheritance chain does not match the fixed project')
|
||||
if locator == file_id:
|
||||
if (item.get('mimeType') not in ('application/zip','application/x-zip','application/x-zip-compressed')
|
||||
or (item.get('sha256Checksum'),item.get('size')) != (digest,str(size))):
|
||||
raise PermissionError('Authoritative Drive archive bytes do not match the frozen bundle')
|
||||
elif item.get('mimeType') != FOLDER_TYPE:
|
||||
raise PermissionError('Drive inheritance parent is not a folder')
|
||||
observations.append((locator, item, _member_evidence(item, token)))
|
||||
# Require stable metadata across the three ACL reads, including each ancestor's version.
|
||||
for locator, item, _ in observations:
|
||||
if _get_json(locator, query, token) != item:
|
||||
raise PermissionError('Drive metadata changed during ACL verification')
|
||||
return dict(source='live Google Drive v3 files.get and exhaustive permissions.list',
|
||||
file_id=file_id,parent_id=folder_id,bytes=size,sha256=digest,
|
||||
chain=[dict(file_id=item['id'],version=item['version'],parents=item.get('parents', []),
|
||||
effective_permissions=permissions) for _,item,permissions in observations])
|
||||
@@ -15,7 +15,7 @@ from track_b_gino_formal_guard import guard
|
||||
from track_b_gino_shapenet_entry import BASE, checked, read, save, sha
|
||||
|
||||
|
||||
ROOT = prep.ROOT / 'combined-review'
|
||||
ROOT = prep.ROOT / 'combined-review-acl-v2'
|
||||
SOURCE = Path(__file__).resolve().parent
|
||||
ADAPTER = prep.REVIEW_ROOT / 'preparation-binding.json'
|
||||
ADAPTER_SHA = '01d6581c33a6c26d1965acb13248bdb741de892e5929fff08a7e4af431f00d0b'
|
||||
@@ -61,6 +61,7 @@ def expected_contract():
|
||||
raise ValueError('Pre-registered Greif comparison differs')
|
||||
code=dict(base['code_sha256'],**c['code_sha256'])
|
||||
for name in ('track_b_gino_greif_entry.py','track_b_gino_greif_worker.py','track_b_gino_greif_custody.py',
|
||||
'track_b_gino_greif_drive_acl.py',
|
||||
'phase2_h2_model.py','phase2_h2_data.py','s2_custody_common.py','s2_custody_statistics.py'):
|
||||
code[str(SOURCE/name)] = sha(SOURCE/name)
|
||||
return dict(handoff='h-08c2a2a5',mode='gino-greif-combined',adapter_sha256=ADAPTER_SHA,
|
||||
@@ -73,7 +74,8 @@ def expected_contract():
|
||||
run_order=['two first epochs as part of seed0 fits','reviewed cost gate','complete all four fits',
|
||||
'freeze models','form four target-free prediction sets','freeze predictions',
|
||||
'verified private Drive transfer','one controlled custody pass'],
|
||||
drive={'purpose':'immutable model and prediction bundle','git':'small SHA indexes and receipts only'},
|
||||
drive={'purpose':'immutable model and prediction bundle','git':'small SHA indexes and receipts only',
|
||||
'acl_revision':'h-17e62811 live exhaustive Drive ACL and fixed owner-only inheritance chain'},
|
||||
no_retry=True)
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user