umf-access 0.1.0.dev8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- umf_access/__init__.py +109 -0
- umf_access/adoption.py +41 -0
- umf_access/build/__init__.py +2 -0
- umf_access/build/approximate.py +34 -0
- umf_access/build/catalog.py +1626 -0
- umf_access/build/commands.py +394 -0
- umf_access/build/pg_privileges.py +1544 -0
- umf_access/build/privileges.py +134 -0
- umf_access/build/search.py +365 -0
- umf_access/build/unity_search.py +104 -0
- umf_access/bulk.py +227 -0
- umf_access/canonical.py +23 -0
- umf_access/capture.py +410 -0
- umf_access/catalog.py +325 -0
- umf_access/codec_support.py +427 -0
- umf_access/commands.py +93 -0
- umf_access/delta_read.py +758 -0
- umf_access/dsl/__init__.py +148 -0
- umf_access/dsl/_context.py +36 -0
- umf_access/dsl/_expressions.py +625 -0
- umf_access/dsl/_joined.py +4 -0
- umf_access/dsl/_nodes.py +207 -0
- umf_access/dsl/_query.py +5559 -0
- umf_access/dsl/_selection.py +143 -0
- umf_access/dsl/navigation.py +302 -0
- umf_access/dsl/render.py +516 -0
- umf_access/dsl/search.py +343 -0
- umf_access/engine_catalog.py +563 -0
- umf_access/generated_core.py +5 -0
- umf_access/lifecycle/__init__.py +46 -0
- umf_access/lifecycle/_darwin_process_observer.c +306 -0
- umf_access/lifecycle/approval.py +366 -0
- umf_access/lifecycle/backfills.py +79 -0
- umf_access/lifecycle/catalog.py +289 -0
- umf_access/lifecycle/cli.py +231 -0
- umf_access/lifecycle/concurrent.py +196 -0
- umf_access/lifecycle/conversion_policy.py +188 -0
- umf_access/lifecycle/correspondence.py +203 -0
- umf_access/lifecycle/generation_authority_bootstrap.py +1491 -0
- umf_access/lifecycle/generation_authority_session.py +125 -0
- umf_access/lifecycle/generation_enrollment_authority.py +1108 -0
- umf_access/lifecycle/generation_enrollment_ledger.py +698 -0
- umf_access/lifecycle/generation_ingress.py +185 -0
- umf_access/lifecycle/generation_root_registry.py +138 -0
- umf_access/lifecycle/head.py +250 -0
- umf_access/lifecycle/head_view.py +81 -0
- umf_access/lifecycle/host.py +1183 -0
- umf_access/lifecycle/ingress_custody.py +750 -0
- umf_access/lifecycle/ingress_local_postgres.py +7990 -0
- umf_access/lifecycle/ingress_store.py +1488 -0
- umf_access/lifecycle/ledger.py +276 -0
- umf_access/lifecycle/ledger_schema.py +116 -0
- umf_access/lifecycle/mixed.py +593 -0
- umf_access/lifecycle/outcome_schema.py +136 -0
- umf_access/lifecycle/owner_approval_core.py +1810 -0
- umf_access/lifecycle/owner_authority.py +472 -0
- umf_access/lifecycle/owner_bootstrap.py +2077 -0
- umf_access/lifecycle/owner_wire.py +161 -0
- umf_access/lifecycle/phase_fence.py +52 -0
- umf_access/lifecycle/phase_policy.py +422 -0
- umf_access/lifecycle/privileges.py +145 -0
- umf_access/lifecycle/probe.py +39 -0
- umf_access/lifecycle/progress.py +497 -0
- umf_access/lifecycle/roles.py +96 -0
- umf_access/lifecycle/row_originals.py +1712 -0
- umf_access/lifecycle/row_originals_creation.py +759 -0
- umf_access/lifecycle/row_originals_receipt.py +413 -0
- umf_access/lifecycle/seeds.py +99 -0
- umf_access/lifecycle/sql_containment.py +358 -0
- umf_access/lifecycle/sql_containment_cli.py +33 -0
- umf_access/lifecycle/sql_containment_parser.py +20 -0
- umf_access/lifecycle/supervisor_journal_codec.py +1251 -0
- umf_access/lifecycle/table_boundary.py +22 -0
- umf_access/lifecycle/target_custody_codec.py +788 -0
- umf_access/lifecycle/witness.py +72 -0
- umf_access/managed_actions.py +271 -0
- umf_access/managed_bulk.py +353 -0
- umf_access/managed_delta.py +150 -0
- umf_access/managed_support.py +166 -0
- umf_access/manifest_commands.py +278 -0
- umf_access/native_actions.py +1007 -0
- umf_access/native_program.py +570 -0
- umf_access/pages.py +125 -0
- umf_access/postgres_bulk.py +509 -0
- umf_access/postgres_read.py +1230 -0
- umf_access/postgres_search.py +639 -0
- umf_access/protocols.py +665 -0
- umf_access/py.typed +0 -0
- umf_access/related_keys.py +233 -0
- umf_access/reviewed.py +706 -0
- umf_access/search_catalog.py +122 -0
- umf_access/targets.py +312 -0
- umf_access/types.py +220 -0
- umf_access/unified/__init__.py +187 -0
- umf_access/unified/_binding.py +654 -0
- umf_access/unified/head_session.py +144 -0
- umf_access/unified/native_binding.py +143 -0
- umf_access/unified/operation_values.py +173 -0
- umf_access/unified/outcome_values.py +76 -0
- umf_access/unified/session_async.py +161 -0
- umf_access/unified/session_binding.py +108 -0
- umf_access/unified/session_policy.py +152 -0
- umf_access/unified/session_psycopg2.py +70 -0
- umf_access/unified/session_sqlalchemy.py +161 -0
- umf_access/unified/session_sync.py +148 -0
- umf_access/unified/table_reads.py +314 -0
- umf_access/unified/table_writes.py +193 -0
- umf_access/unity_search.py +312 -0
- umf_access/values.py +280 -0
- umf_access/verification.py +64 -0
- umf_access-0.1.0.dev8.dist-info/METADATA +15 -0
- umf_access-0.1.0.dev8.dist-info/RECORD +117 -0
- umf_access-0.1.0.dev8.dist-info/WHEEL +4 -0
- umf_access-0.1.0.dev8.dist-info/entry_points.txt +4 -0
- umf_access-0.1.0.dev8.dist-info/licenses/LICENSE-APACHE +201 -0
- umf_access-0.1.0.dev8.dist-info/licenses/LICENSE-MIT +21 -0
- umf_access-0.1.0.dev8.dist-info/licenses/LICENSE.md +239 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MIT OR Apache-2.0
|
|
2
|
+
"""Source-reparsed native table ACLs and dedicated-schema preconditions.
|
|
3
|
+
|
|
4
|
+
No grant is repaired in place and no external/PUBLIC privilege is revoked.
|
|
5
|
+
Hosts must arrange those preconditions; successful observations do not grant
|
|
6
|
+
runtime or migration admission.
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from typing import Any
|
|
11
|
+
from uuid import uuid4
|
|
12
|
+
|
|
13
|
+
from .catalog import CatalogError, _all, _execute, _installation, _one, _q
|
|
14
|
+
from .head_view import HEAD, _verify_head_view
|
|
15
|
+
from .ledger_schema import HISTORY, _verify_history_schema
|
|
16
|
+
from .outcome_schema import OUTCOMES, _verify_outcomes
|
|
17
|
+
from .roles import verify_native_role_scope
|
|
18
|
+
|
|
19
|
+
_TABLE_ACL = """SELECT x.grantor,x.grantee,x.privilege_type,x.is_grantable
|
|
20
|
+
FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace,
|
|
21
|
+
LATERAL pg_catalog.aclexplode(COALESCE(c.relacl,pg_catalog.acldefault('r',c.relowner))) x
|
|
22
|
+
WHERE n.nspname=%s AND c.relname=%s ORDER BY 1,2,3,4"""
|
|
23
|
+
|
|
24
|
+
_COLUMN_ACL = """SELECT a.attname,x.grantor,x.grantee,x.privilege_type,x.is_grantable
|
|
25
|
+
FROM pg_catalog.pg_attribute a JOIN pg_catalog.pg_class c ON c.oid=a.attrelid
|
|
26
|
+
JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace,
|
|
27
|
+
LATERAL pg_catalog.aclexplode(a.attacl) x
|
|
28
|
+
WHERE n.nspname=%s AND c.relname=%s AND a.attnum>0 AND NOT a.attisdropped ORDER BY 1,2,3,4,5"""
|
|
29
|
+
|
|
30
|
+
_EXTERNAL = """SELECT
|
|
31
|
+
pg_catalog.has_database_privilege(%s::pg_catalog.oid,pg_catalog.current_database(),'CREATE') OR
|
|
32
|
+
EXISTS(SELECT FROM pg_catalog.pg_namespace n WHERE n.nspname<>%s AND
|
|
33
|
+
n.nspname!~'^pg_' AND n.nspname<>'information_schema' AND
|
|
34
|
+
pg_catalog.has_schema_privilege(%s::pg_catalog.oid,n.oid,'CREATE')) OR
|
|
35
|
+
EXISTS(SELECT FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace
|
|
36
|
+
WHERE n.nspname<>%s AND n.nspname!~'^pg_' AND n.nspname<>'information_schema'
|
|
37
|
+
AND CASE WHEN c.relkind IN ('r','p','v','m','f') THEN
|
|
38
|
+
(pg_catalog.has_table_privilege(%s::pg_catalog.oid,c.oid,'SELECT,INSERT,UPDATE,DELETE,TRUNCATE,REFERENCES,TRIGGER,MAINTAIN')
|
|
39
|
+
OR pg_catalog.has_any_column_privilege(%s::pg_catalog.oid,c.oid,'SELECT,INSERT,UPDATE,REFERENCES')) ELSE FALSE END) OR
|
|
40
|
+
EXISTS(SELECT FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace
|
|
41
|
+
WHERE n.nspname<>%s AND n.nspname!~'^pg_' AND n.nspname<>'information_schema'
|
|
42
|
+
AND CASE WHEN c.relkind='S' THEN pg_catalog.has_sequence_privilege(%s::pg_catalog.oid,c.oid,'USAGE,SELECT,UPDATE') ELSE FALSE END) OR
|
|
43
|
+
EXISTS(SELECT FROM pg_catalog.pg_proc p JOIN pg_catalog.pg_namespace n ON n.oid=p.pronamespace
|
|
44
|
+
WHERE n.nspname!~'^pg_' AND n.nspname<>'information_schema'
|
|
45
|
+
AND pg_catalog.has_function_privilege(%s::pg_catalog.oid,p.oid,'EXECUTE')) OR
|
|
46
|
+
EXISTS(SELECT FROM pg_catalog.pg_foreign_server s WHERE pg_catalog.has_server_privilege(%s::pg_catalog.oid,s.oid,'USAGE')) OR
|
|
47
|
+
EXISTS(SELECT FROM pg_catalog.pg_foreign_data_wrapper f WHERE pg_catalog.has_foreign_data_wrapper_privilege(%s::pg_catalog.oid,f.oid,'USAGE')) OR
|
|
48
|
+
EXISTS(SELECT FROM pg_catalog.pg_largeobject_metadata l WHERE pg_catalog.has_largeobject_privilege(%s::pg_catalog.oid,l.oid,'SELECT,UPDATE'))"""
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _table_acl(connection: Any, source: dict[str, Any], table: dict[str, Any]) -> None:
|
|
52
|
+
schema = source['configuration']['schema']
|
|
53
|
+
columns = [c for c in source['expectedCatalog']['columns'] if c['table'] == table['id']]
|
|
54
|
+
if any(c['identity'] for c in columns):
|
|
55
|
+
raise CatalogError('identity-privileges-unqualified')
|
|
56
|
+
original = _q(schema)+'.'+_q(table['name'])
|
|
57
|
+
temporary = 'umf_verify_'+uuid4().hex
|
|
58
|
+
reference = _q(schema)+'.'+_q(temporary)
|
|
59
|
+
_execute(connection, 'CREATE TABLE '+reference+' ('+', '.join(c['definitionSql'] for c in columns)+')')
|
|
60
|
+
table_steps = [s for s in source['steps'] if s['kind']=='table' and s['sql'].startswith('CREATE TABLE '+original+' (')]
|
|
61
|
+
if len(table_steps) != 1:
|
|
62
|
+
raise CatalogError('source-mismatch')
|
|
63
|
+
path = table_steps[0]['sourcePath']
|
|
64
|
+
marker = ' ON TABLE '+original+' '
|
|
65
|
+
for step in source['steps']:
|
|
66
|
+
if step['kind'] != 'grant' or not (step['sourcePath']==path or step['sourcePath'].startswith(path+'/policy/')):
|
|
67
|
+
continue
|
|
68
|
+
if step['sql'].count(marker) != 1:
|
|
69
|
+
raise CatalogError('source-mismatch')
|
|
70
|
+
before, after = step['sql'].split(marker)
|
|
71
|
+
_execute(connection, before+' ON TABLE '+reference+' '+after)
|
|
72
|
+
for statement in (_TABLE_ACL, _COLUMN_ACL):
|
|
73
|
+
if _all(connection,statement,(schema,table['name'])) != _all(connection,statement,(schema,temporary)):
|
|
74
|
+
raise CatalogError('privilege-mismatch')
|
|
75
|
+
_execute(connection,'DROP TABLE '+reference)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def verify_native_privileges(connection: Any, bundle: dict[str, object], *,
|
|
79
|
+
person_roles: tuple[str, ...],
|
|
80
|
+
statement_timeout_ms: int = 30_000,
|
|
81
|
+
lock_timeout_ms: int = 5_000,
|
|
82
|
+
_approval_profile: dict[str, object] | None = None) -> dict[str, object]:
|
|
83
|
+
"""Verify source ACLs/selected roles; never admit operations or repair privileges.
|
|
84
|
+
|
|
85
|
+
Root plugin roles have no data/routine authority outside the private schema.
|
|
86
|
+
Actual people may access other plugins; their target-schema privileges must
|
|
87
|
+
come through the exact source ACL and the qualified role boundary. Identity
|
|
88
|
+
sequences remain unqualified. This is an administrative observation, not a
|
|
89
|
+
lock against privileged role/ACL changes made outside the host protocol.
|
|
90
|
+
"""
|
|
91
|
+
with _installation(connection,bundle,statement_timeout_ms=statement_timeout_ms,
|
|
92
|
+
lock_timeout_ms=lock_timeout_ms) as source:
|
|
93
|
+
verify_native_role_scope(connection,bundle,person_roles=person_roles,
|
|
94
|
+
statement_timeout_ms=statement_timeout_ms,lock_timeout_ms=lock_timeout_ms)
|
|
95
|
+
cfg=source['configuration']
|
|
96
|
+
schema, owner = cfg['schema'],cfg['ownerRole']
|
|
97
|
+
if any(column['identity'] for column in source['expectedCatalog']['columns']):
|
|
98
|
+
raise CatalogError('identity-privileges-unqualified')
|
|
99
|
+
owner_id=_one(connection,'SELECT oid FROM pg_catalog.pg_roles WHERE rolname=%s',(owner,))[0]
|
|
100
|
+
schema_id=_one(connection,'SELECT oid FROM pg_catalog.pg_namespace WHERE nspname=%s',(schema,))[0]
|
|
101
|
+
for name in (owner,cfg['personRole'],cfg['batchRole']):
|
|
102
|
+
oid=_one(connection,'SELECT oid FROM pg_catalog.pg_roles WHERE rolname=%s',(name,))[0]
|
|
103
|
+
if _one(connection,_EXTERNAL,(oid,schema,oid,schema,oid,oid,schema,oid,oid,oid,oid,oid)) != (False,):
|
|
104
|
+
raise CatalogError('external-authority-present')
|
|
105
|
+
# Fresh scratch relations may not inherit grants absent from source.
|
|
106
|
+
defaults=_all(connection,"""SELECT x.grantee,x.is_grantable FROM pg_catalog.pg_default_acl d,
|
|
107
|
+
LATERAL pg_catalog.aclexplode(d.defaclacl) x WHERE d.defaclrole=%s AND d.defaclnamespace IN (0,%s)
|
|
108
|
+
AND d.defaclobjtype IN ('r','S')""",(owner_id,schema_id))
|
|
109
|
+
if any(grantee!=owner_id or grantable for grantee,grantable in defaults):
|
|
110
|
+
raise CatalogError('default-privilege-mismatch')
|
|
111
|
+
actual=_all(connection,"""SELECT x.grantor,x.grantee,x.privilege_type,x.is_grantable
|
|
112
|
+
FROM pg_catalog.pg_namespace n,LATERAL pg_catalog.aclexplode(COALESCE(n.nspacl,pg_catalog.acldefault('n',n.nspowner))) x
|
|
113
|
+
WHERE n.oid=%s ORDER BY 1,2,3,4""",(schema_id,))
|
|
114
|
+
expected=_all(connection,"""SELECT grantor,grantee,privilege_type,is_grantable
|
|
115
|
+
FROM pg_catalog.aclexplode(pg_catalog.acldefault('n',%s::pg_catalog.oid))""",(owner_id,))
|
|
116
|
+
for name in (cfg['personRole'],cfg['batchRole']):
|
|
117
|
+
oid=_one(connection,'SELECT oid FROM pg_catalog.pg_roles WHERE rolname=%s',(name,))[0]
|
|
118
|
+
expected.append((owner_id,oid,'USAGE',False))
|
|
119
|
+
if actual != sorted(expected):
|
|
120
|
+
raise CatalogError('privilege-mismatch')
|
|
121
|
+
inventory=_all(connection,"""SELECT c.relname FROM pg_catalog.pg_class c WHERE c.relnamespace=%s
|
|
122
|
+
AND c.relkind NOT IN ('i','I') ORDER BY c.relname""",(schema_id,))
|
|
123
|
+
expected_inventory = [(t['name'],) for t in source['expectedCatalog']['tables']]
|
|
124
|
+
if _verify_outcomes(connection,source):
|
|
125
|
+
expected_inventory.append((OUTCOMES,))
|
|
126
|
+
if _verify_history_schema(connection,source):
|
|
127
|
+
expected_inventory.append((HISTORY,))
|
|
128
|
+
if not _verify_head_view(connection,source):
|
|
129
|
+
raise CatalogError('head-view-missing')
|
|
130
|
+
expected_inventory.append((HEAD,))
|
|
131
|
+
if _approval_profile is not None:
|
|
132
|
+
from .approval import APPROVAL_PROFILE, _verify_approval_relation
|
|
133
|
+
|
|
134
|
+
if _approval_profile != APPROVAL_PROFILE:
|
|
135
|
+
raise CatalogError('approval-catalog-mismatch')
|
|
136
|
+
if _verify_approval_relation(connection,source):
|
|
137
|
+
expected_inventory.append((APPROVAL_PROFILE['relation'],))
|
|
138
|
+
if inventory != sorted(expected_inventory):
|
|
139
|
+
raise CatalogError('catalog-mismatch')
|
|
140
|
+
for table in source['expectedCatalog']['tables']:
|
|
141
|
+
_execute(connection,'LOCK TABLE '+_q(schema)+'.'+_q(table['name'])+' IN ACCESS EXCLUSIVE MODE')
|
|
142
|
+
for table in source['expectedCatalog']['tables']:
|
|
143
|
+
_table_acl(connection,source,table)
|
|
144
|
+
return {'bundleDigest':source['bundleDigest'],'nativePrivilegesVerified':True,
|
|
145
|
+
'verifiedPersonRoles':list(person_roles),'lifecycleAdmission':False}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MIT OR Apache-2.0
|
|
2
|
+
"""Internal fixed catalog-query protocol shared by sync and async drivers.
|
|
3
|
+
|
|
4
|
+
Only library-owned observation generators construct queries. This is neither a
|
|
5
|
+
query authoring API nor an execution/admission capability.
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from dataclasses import dataclass
|
|
10
|
+
from typing import Any, Literal
|
|
11
|
+
|
|
12
|
+
from .catalog import _all, _execute, _one
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@dataclass(frozen=True)
|
|
16
|
+
class _Query:
|
|
17
|
+
kind: Literal['one','all','execute']
|
|
18
|
+
statement: str
|
|
19
|
+
parameters: tuple[Any, ...] = ()
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _run(connection: Any, steps: Any) -> Any:
|
|
23
|
+
"""Original Psycopg3 administrative driver for the same bounded protocol."""
|
|
24
|
+
try:
|
|
25
|
+
query = next(steps)
|
|
26
|
+
while True:
|
|
27
|
+
if query.kind == 'one':
|
|
28
|
+
value = _one(connection,query.statement,query.parameters)
|
|
29
|
+
elif query.kind == 'all':
|
|
30
|
+
value = _all(connection,query.statement,query.parameters)
|
|
31
|
+
elif query.kind == 'execute':
|
|
32
|
+
value = _execute(connection,query.statement,query.parameters)
|
|
33
|
+
else:
|
|
34
|
+
raise ValueError('unknown internal query kind')
|
|
35
|
+
query = steps.send(value)
|
|
36
|
+
except StopIteration as result:
|
|
37
|
+
return result.value
|
|
38
|
+
finally:
|
|
39
|
+
steps.close()
|