awscope 0.1.0__tar.gz
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.
- awscope-0.1.0/LICENSE +202 -0
- awscope-0.1.0/PKG-INFO +201 -0
- awscope-0.1.0/README.md +185 -0
- awscope-0.1.0/awscope/__init__.py +47 -0
- awscope-0.1.0/awscope/_doctor.py +198 -0
- awscope-0.1.0/awscope/_selftest.py +7 -0
- awscope-0.1.0/awscope/cli.py +328 -0
- awscope-0.1.0/awscope/graph.py +570 -0
- awscope-0.1.0/awscope/model.py +194 -0
- awscope-0.1.0/awscope.egg-info/PKG-INFO +201 -0
- awscope-0.1.0/awscope.egg-info/SOURCES.txt +17 -0
- awscope-0.1.0/awscope.egg-info/dependency_links.txt +1 -0
- awscope-0.1.0/awscope.egg-info/entry_points.txt +2 -0
- awscope-0.1.0/awscope.egg-info/requires.txt +3 -0
- awscope-0.1.0/awscope.egg-info/top_level.txt +1 -0
- awscope-0.1.0/pyproject.toml +44 -0
- awscope-0.1.0/setup.cfg +4 -0
- awscope-0.1.0/tests/test_awscope.py +420 -0
- awscope-0.1.0/tests/test_lint_config_agrees.py +60 -0
awscope-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
awscope-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: awscope
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: One scope graph for a company, a household and a friend group - membership inside a scope, consent links across it, and offboarding that cannot reach anyone's personal life.
|
|
5
|
+
License: Apache-2.0
|
|
6
|
+
Project-URL: Homepage, https://github.com/Aitherium/awscope
|
|
7
|
+
Project-URL: Documentation, https://github.com/Aitherium/awscope#readme
|
|
8
|
+
Project-URL: Repository, https://github.com/Aitherium/awscope.git
|
|
9
|
+
Project-URL: Issues, https://github.com/Aitherium/awscope/issues
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Provides-Extra: dev
|
|
14
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
# awscope
|
|
18
|
+
|
|
19
|
+
One scope graph for a company, a household and a friend group: **membership**
|
|
20
|
+
inside a scope, **consent links** across it, and **offboarding that cannot
|
|
21
|
+
reach anyone's personal life**.
|
|
22
|
+
|
|
23
|
+
Not on PyPI yet. Install from a checkout of the awscope source, in its directory:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install ".[dev]"
|
|
27
|
+
awscope --self-test
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## The bug this package is shaped around
|
|
31
|
+
|
|
32
|
+
The usual way to give an assistant "work and home" context is one tenant with
|
|
33
|
+
a flag on each record. Then three things go wrong, quietly:
|
|
34
|
+
|
|
35
|
+
1. **Leaving the company takes your life with it.** The household and the
|
|
36
|
+
friend group were filed under the employer's tenant, so offboarding deletes
|
|
37
|
+
or locks them.
|
|
38
|
+
2. **Sharing is a toggle, not a grant.** "Share my calendar with my family"
|
|
39
|
+
flips a flag nobody owns, nobody can expire, and nobody can revoke without
|
|
40
|
+
also revoking everything else.
|
|
41
|
+
3. **The boundary fails open.** An unknown scope, a missing record or an
|
|
42
|
+
exception mid-check reads as "no restriction".
|
|
43
|
+
|
|
44
|
+
awscope makes the first two unrepresentable in the graph, and the third
|
|
45
|
+
impossible in `check`:
|
|
46
|
+
|
|
47
|
+
- `person`, `household` and `enclave` scopes are **top-level only**, and every
|
|
48
|
+
scope carries a **realm** (`company`, `personal` or `unfiled`) fixed at
|
|
49
|
+
creation by the root of its parent chain. No move may change it, so a
|
|
50
|
+
workspace under a person can never be re-parented under an org, and no org
|
|
51
|
+
operation can walk into personal data. A store file edited by hand to do so
|
|
52
|
+
is refused on load.
|
|
53
|
+
- Crossing a boundary needs a **consent link**: directional, granted only by
|
|
54
|
+
an owner/admin of the scope whose data it exposes, capability-scoped,
|
|
55
|
+
optionally expiring, revocable one at a time, and revoked automatically when
|
|
56
|
+
the granter loses the authority to give it or leaves the org it was given to.
|
|
57
|
+
- `check` is **fail-closed**. Every path that is not an explicit allow is a
|
|
58
|
+
deny with the cause named. An exception is a deny.
|
|
59
|
+
|
|
60
|
+
## Trust boundary: awscope believes the actor you pass
|
|
61
|
+
|
|
62
|
+
Every mutation names its actor: `create_scope(..., actor=)`,
|
|
63
|
+
`add_member(..., actor=)`, `remove_member(..., actor=)`,
|
|
64
|
+
`move_scope(..., actor=)`, `grant_link(..., granted_by=)`,
|
|
65
|
+
`revoke_link(..., by=)`. awscope checks that the actor may make the change:
|
|
66
|
+
|
|
67
|
+
| mutation | the actor must be |
|
|
68
|
+
|---|---|
|
|
69
|
+
| create a top-level scope | anyone; they become its owner |
|
|
70
|
+
| create a child scope | owner/admin of the parent (or an ancestor) |
|
|
71
|
+
| add or change a member | owner/admin of the scope; only an **owner** may make or change an owner |
|
|
72
|
+
| remove a member | the member themselves, or an owner/admin of the scope |
|
|
73
|
+
| move a scope | owner/admin of the old parent and the new parent, and the realm must not change |
|
|
74
|
+
| grant a link | owner/admin of the **source** scope |
|
|
75
|
+
| revoke a link | the granter, or an owner/admin of either end |
|
|
76
|
+
|
|
77
|
+
awscope cannot know **who is calling**. The actor is a string, and the library
|
|
78
|
+
and the CLI (`--by`) take it on trust. A service that embeds awscope must
|
|
79
|
+
authenticate the caller and pass that authenticated identity, never a name
|
|
80
|
+
read from the request. "Only the source can consent" means "only an identity
|
|
81
|
+
that administers the source can consent", which is only as strong as the
|
|
82
|
+
host's authentication.
|
|
83
|
+
|
|
84
|
+
## The model
|
|
85
|
+
|
|
86
|
+
| thing | shape |
|
|
87
|
+
|---|---|
|
|
88
|
+
| `Scope` | `id, kind, name, parent_id, attrs, realm`; kind is `org`, `team`, `person`, `household`, `enclave` or `workspace` |
|
|
89
|
+
| `Membership` | `subject, scope_id, role`; role is `owner`, `admin`, `member`, `guest` or `child` |
|
|
90
|
+
| `ConsentLink` | `source_scope -> target_scope`, `grants` (`calendar.read`, `inbox.read`, `todo.write`, `context.read`), `granted_by`, `created_at`, `expires_at`, `revoked_at` |
|
|
91
|
+
|
|
92
|
+
Parents: `team` needs an `org` (or `team`) parent; `org` may sit under an
|
|
93
|
+
`org`; `workspace` may sit anywhere; personal kinds are top-level. The parent
|
|
94
|
+
chain is acyclic: a move that would close a loop is refused, and a store file
|
|
95
|
+
with one is refused on load. A move that would change a scope's realm is
|
|
96
|
+
refused the same way.
|
|
97
|
+
|
|
98
|
+
**`check(subject, acting_scope, capability, target_scope)`** allows when:
|
|
99
|
+
|
|
100
|
+
1. `subject` is a member of `target_scope` (any role), or
|
|
101
|
+
2. `subject` is owner/admin of an **ancestor** of `target_scope`, or
|
|
102
|
+
3. `subject` is a member of `acting_scope` **and** an active, unexpired link
|
|
103
|
+
`target_scope -> acting_scope` grants `capability`, granted by someone who
|
|
104
|
+
still administers `target_scope`.
|
|
105
|
+
|
|
106
|
+
Everything else denies. Capabilities match on dotted **segments**:
|
|
107
|
+
`calendar.read` never covers `calendar.readwrite`, and `calendar.*` covers
|
|
108
|
+
exactly one segment.
|
|
109
|
+
|
|
110
|
+
Membership answers "is this scope mine"; what a role may do inside a scope is
|
|
111
|
+
a policy question for [awbac](https://github.com/Aitherium/awbac).
|
|
112
|
+
`scope_path("eng")` returns `org:acme/team:eng`, which you can use as the
|
|
113
|
+
prefix of an awbac permission.
|
|
114
|
+
|
|
115
|
+
## A worked example: Acme
|
|
116
|
+
|
|
117
|
+
Acme is a company. Sam works there, has a personal scope, and a household with
|
|
118
|
+
a partner, Alex. Sam wants Alex's household assistant to see Sam's calendar,
|
|
119
|
+
and nothing else.
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
from awscope import ScopeGraph
|
|
123
|
+
|
|
124
|
+
g = ScopeGraph("scopes.json")
|
|
125
|
+
|
|
126
|
+
g.create_scope("acme", "org", "Acme", actor="dana") # dana owns acme
|
|
127
|
+
g.create_scope("eng", "team", parent_id="acme", actor="dana")
|
|
128
|
+
g.create_scope("sam", "person", actor="sam") # Sam's own scope: top-level
|
|
129
|
+
g.create_scope("sam-home", "household", actor="sam") # also top-level
|
|
130
|
+
|
|
131
|
+
g.add_member("sam", "acme", "member", actor="dana")
|
|
132
|
+
g.add_member("sam", "eng", "member", actor="dana")
|
|
133
|
+
g.add_member("alex", "sam-home", "member", actor="sam")
|
|
134
|
+
|
|
135
|
+
# Alex, acting from the household, cannot see Sam's calendar yet.
|
|
136
|
+
g.check("alex", "sam-home", "calendar.read", "sam")
|
|
137
|
+
# Decision(allowed=False, reason='denied: no consent link from sam to sam-home grants calendar.read')
|
|
138
|
+
|
|
139
|
+
# Sam (owner of the SOURCE) consents. Alex cannot grant this; Dana cannot either.
|
|
140
|
+
link = g.grant_link("sam", "sam-home", ["calendar.read"], granted_by="sam")
|
|
141
|
+
|
|
142
|
+
g.check("alex", "sam-home", "calendar.read", "sam") # allowed, via link:<id>
|
|
143
|
+
g.check("alex", "sam-home", "inbox.read", "sam") # denied: never granted
|
|
144
|
+
g.check("alex", "acme", "calendar.read", "sam") # denied: alex is not in acme
|
|
145
|
+
|
|
146
|
+
# Sam leaves Acme.
|
|
147
|
+
g.offboard("sam", "acme", actor="dana")
|
|
148
|
+
# -> removes sam from acme AND eng; sam, sam-home and the calendar link are untouched.
|
|
149
|
+
g.check("alex", "sam-home", "calendar.read", "sam") # still allowed
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Had Sam, as an `eng` admin, granted a link **from** `eng` to somewhere, the
|
|
153
|
+
same offboard would revoke it, because Sam no longer administers `eng`. Had
|
|
154
|
+
Sam shared their own calendar **with** `acme`, the offboard would revoke that
|
|
155
|
+
too: consent given to an employer ends with the job. Both are listed in the
|
|
156
|
+
returned report and printed by `awscope member rm`.
|
|
157
|
+
|
|
158
|
+
## CLI
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
export AWSCOPE_STORE=scopes.json # or --store PATH on every call
|
|
162
|
+
awscope create org acme --name Acme --by dana --init # --init: start a new store
|
|
163
|
+
awscope create team eng --parent acme --by dana
|
|
164
|
+
awscope create person sam --by sam
|
|
165
|
+
awscope create household sam-home --by sam
|
|
166
|
+
awscope member add sam acme --by dana
|
|
167
|
+
awscope member add sam eng --by dana
|
|
168
|
+
awscope member add alex sam-home --by sam
|
|
169
|
+
awscope link grant sam sam-home --grant calendar.read --by sam --ttl 2592000
|
|
170
|
+
awscope check alex sam-home calendar.read sam # ALLOW ... (via link:lnk-...)
|
|
171
|
+
awscope link list --scope sam
|
|
172
|
+
awscope member rm sam acme --by dana # cascades to eng; never to sam/sam-home
|
|
173
|
+
awscope tree
|
|
174
|
+
awscope path eng # org:acme/team:eng
|
|
175
|
+
awscope --self-test # proves check can deny
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Exit codes: **0** ok / allowed, **1** denied / refused, **2** error (no store,
|
|
179
|
+
a store path that does not exist, an unreadable or inconsistent store, bad
|
|
180
|
+
usage). A broken or missing store is 2, not 1: "denied" is routine and would
|
|
181
|
+
be shrugged off. Only `create --init` may start a new store file, so a typo in
|
|
182
|
+
the path never reads as an empty world.
|
|
183
|
+
|
|
184
|
+
## Store
|
|
185
|
+
|
|
186
|
+
`ScopeGraph()` is in memory. `ScopeGraph(path)` is one JSON file, written
|
|
187
|
+
atomically (temp file + `os.replace`), guarded by an OS file lock on
|
|
188
|
+
`path.lock` (`fcntl.flock` on POSIX, `msvcrt.locking` on Windows; it dies with
|
|
189
|
+
its process, so no lock is ever stolen), and re-read before every mutation so
|
|
190
|
+
two processes do not lose each other's writes. A refused operation leaves both memory and disk unchanged.
|
|
191
|
+
|
|
192
|
+
## Part of the Aither World
|
|
193
|
+
|
|
194
|
+
Pairs with `awbac` (what a role may do inside a scope), `awnboard` (getting
|
|
195
|
+
into a scope), `awdit` (recording every grant and revoke), `awseal` and
|
|
196
|
+
`awshare` (moving the data a link allows). Each is optional; awscope has no
|
|
197
|
+
dependencies.
|
|
198
|
+
|
|
199
|
+
## License
|
|
200
|
+
|
|
201
|
+
Apache-2.0
|
awscope-0.1.0/README.md
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# awscope
|
|
2
|
+
|
|
3
|
+
One scope graph for a company, a household and a friend group: **membership**
|
|
4
|
+
inside a scope, **consent links** across it, and **offboarding that cannot
|
|
5
|
+
reach anyone's personal life**.
|
|
6
|
+
|
|
7
|
+
Not on PyPI yet. Install from a checkout of the awscope source, in its directory:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install ".[dev]"
|
|
11
|
+
awscope --self-test
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## The bug this package is shaped around
|
|
15
|
+
|
|
16
|
+
The usual way to give an assistant "work and home" context is one tenant with
|
|
17
|
+
a flag on each record. Then three things go wrong, quietly:
|
|
18
|
+
|
|
19
|
+
1. **Leaving the company takes your life with it.** The household and the
|
|
20
|
+
friend group were filed under the employer's tenant, so offboarding deletes
|
|
21
|
+
or locks them.
|
|
22
|
+
2. **Sharing is a toggle, not a grant.** "Share my calendar with my family"
|
|
23
|
+
flips a flag nobody owns, nobody can expire, and nobody can revoke without
|
|
24
|
+
also revoking everything else.
|
|
25
|
+
3. **The boundary fails open.** An unknown scope, a missing record or an
|
|
26
|
+
exception mid-check reads as "no restriction".
|
|
27
|
+
|
|
28
|
+
awscope makes the first two unrepresentable in the graph, and the third
|
|
29
|
+
impossible in `check`:
|
|
30
|
+
|
|
31
|
+
- `person`, `household` and `enclave` scopes are **top-level only**, and every
|
|
32
|
+
scope carries a **realm** (`company`, `personal` or `unfiled`) fixed at
|
|
33
|
+
creation by the root of its parent chain. No move may change it, so a
|
|
34
|
+
workspace under a person can never be re-parented under an org, and no org
|
|
35
|
+
operation can walk into personal data. A store file edited by hand to do so
|
|
36
|
+
is refused on load.
|
|
37
|
+
- Crossing a boundary needs a **consent link**: directional, granted only by
|
|
38
|
+
an owner/admin of the scope whose data it exposes, capability-scoped,
|
|
39
|
+
optionally expiring, revocable one at a time, and revoked automatically when
|
|
40
|
+
the granter loses the authority to give it or leaves the org it was given to.
|
|
41
|
+
- `check` is **fail-closed**. Every path that is not an explicit allow is a
|
|
42
|
+
deny with the cause named. An exception is a deny.
|
|
43
|
+
|
|
44
|
+
## Trust boundary: awscope believes the actor you pass
|
|
45
|
+
|
|
46
|
+
Every mutation names its actor: `create_scope(..., actor=)`,
|
|
47
|
+
`add_member(..., actor=)`, `remove_member(..., actor=)`,
|
|
48
|
+
`move_scope(..., actor=)`, `grant_link(..., granted_by=)`,
|
|
49
|
+
`revoke_link(..., by=)`. awscope checks that the actor may make the change:
|
|
50
|
+
|
|
51
|
+
| mutation | the actor must be |
|
|
52
|
+
|---|---|
|
|
53
|
+
| create a top-level scope | anyone; they become its owner |
|
|
54
|
+
| create a child scope | owner/admin of the parent (or an ancestor) |
|
|
55
|
+
| add or change a member | owner/admin of the scope; only an **owner** may make or change an owner |
|
|
56
|
+
| remove a member | the member themselves, or an owner/admin of the scope |
|
|
57
|
+
| move a scope | owner/admin of the old parent and the new parent, and the realm must not change |
|
|
58
|
+
| grant a link | owner/admin of the **source** scope |
|
|
59
|
+
| revoke a link | the granter, or an owner/admin of either end |
|
|
60
|
+
|
|
61
|
+
awscope cannot know **who is calling**. The actor is a string, and the library
|
|
62
|
+
and the CLI (`--by`) take it on trust. A service that embeds awscope must
|
|
63
|
+
authenticate the caller and pass that authenticated identity, never a name
|
|
64
|
+
read from the request. "Only the source can consent" means "only an identity
|
|
65
|
+
that administers the source can consent", which is only as strong as the
|
|
66
|
+
host's authentication.
|
|
67
|
+
|
|
68
|
+
## The model
|
|
69
|
+
|
|
70
|
+
| thing | shape |
|
|
71
|
+
|---|---|
|
|
72
|
+
| `Scope` | `id, kind, name, parent_id, attrs, realm`; kind is `org`, `team`, `person`, `household`, `enclave` or `workspace` |
|
|
73
|
+
| `Membership` | `subject, scope_id, role`; role is `owner`, `admin`, `member`, `guest` or `child` |
|
|
74
|
+
| `ConsentLink` | `source_scope -> target_scope`, `grants` (`calendar.read`, `inbox.read`, `todo.write`, `context.read`), `granted_by`, `created_at`, `expires_at`, `revoked_at` |
|
|
75
|
+
|
|
76
|
+
Parents: `team` needs an `org` (or `team`) parent; `org` may sit under an
|
|
77
|
+
`org`; `workspace` may sit anywhere; personal kinds are top-level. The parent
|
|
78
|
+
chain is acyclic: a move that would close a loop is refused, and a store file
|
|
79
|
+
with one is refused on load. A move that would change a scope's realm is
|
|
80
|
+
refused the same way.
|
|
81
|
+
|
|
82
|
+
**`check(subject, acting_scope, capability, target_scope)`** allows when:
|
|
83
|
+
|
|
84
|
+
1. `subject` is a member of `target_scope` (any role), or
|
|
85
|
+
2. `subject` is owner/admin of an **ancestor** of `target_scope`, or
|
|
86
|
+
3. `subject` is a member of `acting_scope` **and** an active, unexpired link
|
|
87
|
+
`target_scope -> acting_scope` grants `capability`, granted by someone who
|
|
88
|
+
still administers `target_scope`.
|
|
89
|
+
|
|
90
|
+
Everything else denies. Capabilities match on dotted **segments**:
|
|
91
|
+
`calendar.read` never covers `calendar.readwrite`, and `calendar.*` covers
|
|
92
|
+
exactly one segment.
|
|
93
|
+
|
|
94
|
+
Membership answers "is this scope mine"; what a role may do inside a scope is
|
|
95
|
+
a policy question for [awbac](https://github.com/Aitherium/awbac).
|
|
96
|
+
`scope_path("eng")` returns `org:acme/team:eng`, which you can use as the
|
|
97
|
+
prefix of an awbac permission.
|
|
98
|
+
|
|
99
|
+
## A worked example: Acme
|
|
100
|
+
|
|
101
|
+
Acme is a company. Sam works there, has a personal scope, and a household with
|
|
102
|
+
a partner, Alex. Sam wants Alex's household assistant to see Sam's calendar,
|
|
103
|
+
and nothing else.
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
from awscope import ScopeGraph
|
|
107
|
+
|
|
108
|
+
g = ScopeGraph("scopes.json")
|
|
109
|
+
|
|
110
|
+
g.create_scope("acme", "org", "Acme", actor="dana") # dana owns acme
|
|
111
|
+
g.create_scope("eng", "team", parent_id="acme", actor="dana")
|
|
112
|
+
g.create_scope("sam", "person", actor="sam") # Sam's own scope: top-level
|
|
113
|
+
g.create_scope("sam-home", "household", actor="sam") # also top-level
|
|
114
|
+
|
|
115
|
+
g.add_member("sam", "acme", "member", actor="dana")
|
|
116
|
+
g.add_member("sam", "eng", "member", actor="dana")
|
|
117
|
+
g.add_member("alex", "sam-home", "member", actor="sam")
|
|
118
|
+
|
|
119
|
+
# Alex, acting from the household, cannot see Sam's calendar yet.
|
|
120
|
+
g.check("alex", "sam-home", "calendar.read", "sam")
|
|
121
|
+
# Decision(allowed=False, reason='denied: no consent link from sam to sam-home grants calendar.read')
|
|
122
|
+
|
|
123
|
+
# Sam (owner of the SOURCE) consents. Alex cannot grant this; Dana cannot either.
|
|
124
|
+
link = g.grant_link("sam", "sam-home", ["calendar.read"], granted_by="sam")
|
|
125
|
+
|
|
126
|
+
g.check("alex", "sam-home", "calendar.read", "sam") # allowed, via link:<id>
|
|
127
|
+
g.check("alex", "sam-home", "inbox.read", "sam") # denied: never granted
|
|
128
|
+
g.check("alex", "acme", "calendar.read", "sam") # denied: alex is not in acme
|
|
129
|
+
|
|
130
|
+
# Sam leaves Acme.
|
|
131
|
+
g.offboard("sam", "acme", actor="dana")
|
|
132
|
+
# -> removes sam from acme AND eng; sam, sam-home and the calendar link are untouched.
|
|
133
|
+
g.check("alex", "sam-home", "calendar.read", "sam") # still allowed
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Had Sam, as an `eng` admin, granted a link **from** `eng` to somewhere, the
|
|
137
|
+
same offboard would revoke it, because Sam no longer administers `eng`. Had
|
|
138
|
+
Sam shared their own calendar **with** `acme`, the offboard would revoke that
|
|
139
|
+
too: consent given to an employer ends with the job. Both are listed in the
|
|
140
|
+
returned report and printed by `awscope member rm`.
|
|
141
|
+
|
|
142
|
+
## CLI
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
export AWSCOPE_STORE=scopes.json # or --store PATH on every call
|
|
146
|
+
awscope create org acme --name Acme --by dana --init # --init: start a new store
|
|
147
|
+
awscope create team eng --parent acme --by dana
|
|
148
|
+
awscope create person sam --by sam
|
|
149
|
+
awscope create household sam-home --by sam
|
|
150
|
+
awscope member add sam acme --by dana
|
|
151
|
+
awscope member add sam eng --by dana
|
|
152
|
+
awscope member add alex sam-home --by sam
|
|
153
|
+
awscope link grant sam sam-home --grant calendar.read --by sam --ttl 2592000
|
|
154
|
+
awscope check alex sam-home calendar.read sam # ALLOW ... (via link:lnk-...)
|
|
155
|
+
awscope link list --scope sam
|
|
156
|
+
awscope member rm sam acme --by dana # cascades to eng; never to sam/sam-home
|
|
157
|
+
awscope tree
|
|
158
|
+
awscope path eng # org:acme/team:eng
|
|
159
|
+
awscope --self-test # proves check can deny
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Exit codes: **0** ok / allowed, **1** denied / refused, **2** error (no store,
|
|
163
|
+
a store path that does not exist, an unreadable or inconsistent store, bad
|
|
164
|
+
usage). A broken or missing store is 2, not 1: "denied" is routine and would
|
|
165
|
+
be shrugged off. Only `create --init` may start a new store file, so a typo in
|
|
166
|
+
the path never reads as an empty world.
|
|
167
|
+
|
|
168
|
+
## Store
|
|
169
|
+
|
|
170
|
+
`ScopeGraph()` is in memory. `ScopeGraph(path)` is one JSON file, written
|
|
171
|
+
atomically (temp file + `os.replace`), guarded by an OS file lock on
|
|
172
|
+
`path.lock` (`fcntl.flock` on POSIX, `msvcrt.locking` on Windows; it dies with
|
|
173
|
+
its process, so no lock is ever stolen), and re-read before every mutation so
|
|
174
|
+
two processes do not lose each other's writes. A refused operation leaves both memory and disk unchanged.
|
|
175
|
+
|
|
176
|
+
## Part of the Aither World
|
|
177
|
+
|
|
178
|
+
Pairs with `awbac` (what a role may do inside a scope), `awnboard` (getting
|
|
179
|
+
into a scope), `awdit` (recording every grant and revoke), `awseal` and
|
|
180
|
+
`awshare` (moving the data a link allows). Each is optional; awscope has no
|
|
181
|
+
dependencies.
|
|
182
|
+
|
|
183
|
+
## License
|
|
184
|
+
|
|
185
|
+
Apache-2.0
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""awscope -- the scope graph a company, a household and a friend group can share.
|
|
2
|
+
|
|
3
|
+
from awscope import ScopeGraph
|
|
4
|
+
|
|
5
|
+
g = ScopeGraph("scopes.json") # or ScopeGraph() in memory
|
|
6
|
+
g.create_scope("acme", "org", actor="dana") # dana becomes owner
|
|
7
|
+
g.create_scope("sam", "person", actor="sam")
|
|
8
|
+
g.create_scope("sam-home", "household", actor="sam")
|
|
9
|
+
g.add_member("sam", "acme", "member", actor="dana")
|
|
10
|
+
g.add_member("alex", "sam-home", "member", actor="sam")
|
|
11
|
+
|
|
12
|
+
g.grant_link("sam", "sam-home", ["calendar.read"], granted_by="sam")
|
|
13
|
+
d = g.check("alex", "sam-home", "calendar.read", "sam")
|
|
14
|
+
d.allowed, d.reason, d.via
|
|
15
|
+
|
|
16
|
+
g.offboard("sam", "acme", actor="dana") # personal scopes are untouched
|
|
17
|
+
|
|
18
|
+
Membership answers "is this mine"; a consent link, granted by the owner of the
|
|
19
|
+
data, is the only way across a scope boundary. Every check fails closed.
|
|
20
|
+
Every `actor` is host-asserted: authenticate the caller before passing it.
|
|
21
|
+
"""
|
|
22
|
+
from .graph import SCHEMA, ScopeGraph, validate
|
|
23
|
+
from .model import (
|
|
24
|
+
ADMIN_ROLES,
|
|
25
|
+
KINDS,
|
|
26
|
+
PERSONAL_KINDS,
|
|
27
|
+
REALMS,
|
|
28
|
+
ROLES,
|
|
29
|
+
ConsentLink,
|
|
30
|
+
Decision,
|
|
31
|
+
Membership,
|
|
32
|
+
RefusedError,
|
|
33
|
+
Scope,
|
|
34
|
+
ScopeError,
|
|
35
|
+
StoreError,
|
|
36
|
+
capability_covers,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
__version__ = "0.1.0"
|
|
40
|
+
|
|
41
|
+
__all__ = [
|
|
42
|
+
"ScopeGraph", "SCHEMA", "validate",
|
|
43
|
+
"Scope", "Membership", "ConsentLink", "Decision",
|
|
44
|
+
"ScopeError", "RefusedError", "StoreError",
|
|
45
|
+
"KINDS", "PERSONAL_KINDS", "REALMS", "ROLES", "ADMIN_ROLES", "capability_covers",
|
|
46
|
+
"__version__",
|
|
47
|
+
]
|