jrrribeiro commited on
Commit
9cce5d1
·
verified ·
1 Parent(s): d7af7a9

Sync app from GitHub Actions (feature/project-state-security-privacy-review)

Browse files
docs/HF_ORGANIZATION_PER_PROJECT_APP_REDESIGN_PLAN.md ADDED
@@ -0,0 +1,388 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # HF Organization-Per-Project App Redesign Plan
2
+
3
+ Status: proposed target architecture after official API review and Bucket permission spike
4
+ Created: 2026-05-26
5
+ Target branch: `feature/project-state-security-privacy-review`
6
+
7
+ ## Decision Summary
8
+
9
+ The target model is:
10
+
11
+ 1. One Hugging Face organization represents one scientific validation project.
12
+ 2. The project's private audio dataset, validation Bucket, manifest, and
13
+ members belong to that organization.
14
+ 3. The BirdNET Validator Space remains a central, reusable application outside
15
+ project organizations and owns no project data.
16
+ 4. Administrators manage projects primarily through the app, while the app
17
+ uses supported Hugging Face organization, repository, and Bucket APIs.
18
+ 5. For free organizations, organization creation and the initial invitation or
19
+ role assignment of members remain Hugging Face web-interface steps because
20
+ no supported free API flow was found for the app to perform them.
21
+
22
+ This model accepts that a trusted validator requires organization-level
23
+ `write` access within one project organization. It prevents that permission
24
+ from reaching unrelated scientific projects by isolating each project in a
25
+ separate organization.
26
+
27
+ ## Evidence Already Collected
28
+
29
+ ### Real Permission Spike In `ppbio-rabeca`
30
+
31
+ On 2026-05-25, the app investigation created:
32
+
33
+ ```text
34
+ ppbio-rabeca/birdnet-validator-permission-spike
35
+ ```
36
+
37
+ The following results were measured with separate user tokens:
38
+
39
+ | User | Organization role | Read private Bucket | Write private Bucket |
40
+ |---|---|---:|---:|
41
+ | `jrrribeiro` | `admin` | Passed | Passed |
42
+ | `jonathan2008r` | `write` | Passed | Passed |
43
+ | `jonathan2008r` | `contributor` | Passed | Failed with `403` |
44
+
45
+ Result: on a free organization, validators who persist decisions in an
46
+ administrator-created private Bucket must be trusted `write` members.
47
+
48
+ ### Official HfApi / Hub API Review
49
+
50
+ The official Python API and the installed `huggingface_hub` client expose:
51
+
52
+ | Capability | Official support observed | Use in app |
53
+ |---|---:|---|
54
+ | Create private dataset repository in an organization namespace (`create_repo`) | Yes | Project initialization |
55
+ | Create private organization Bucket (`create_bucket`) | Yes | Validation state initialization |
56
+ | Read/write/list Bucket files (`batch_bucket_files`, `download_bucket_files`, `list_bucket_tree`) | Yes | Validation and recovery |
57
+ | List organization Buckets (`list_buckets(namespace=...)`) | Yes | Project discovery/health |
58
+ | Get organization overview (`get_organization_overview`) | Yes | Verify organization |
59
+ | List organization members (`list_organization_members`) | Yes | Render membership/readiness |
60
+ | Create organization | Not exposed in reviewed HfApi/docs | External HF onboarding step |
61
+ | Invite a non-member into an organization | Not provided in reviewed supported API guide | External HF onboarding step |
62
+ | Change an existing member's organization role by API | Official Hub endpoint, subscription required | Not available as free default |
63
+
64
+ The official **Programmatic User Access Control Management** guide documents:
65
+
66
+ ```text
67
+ PUT /api/organizations/{org_name}/members/{username}/role
68
+ ```
69
+
70
+ but requires:
71
+
72
+ 1. an organization subscription plan, such as Team or Enterprise;
73
+ 2. an authenticated organization member with `write` or `admin` permission;
74
+ 3. a target user who is already a member of the organization; and
75
+ 4. a fine-grained token with organization settings/member management access.
76
+
77
+ The endpoint returns `402` when the organization lacks the required
78
+ subscription. It therefore cannot be the default mechanism for free community
79
+ projects. The regular organization management documentation directs admins to
80
+ the Hugging Face Members settings interface to add members, send invites,
81
+ revoke membership, and change roles.
82
+
83
+ ## Target Ownership Model
84
+
85
+ ### Central App
86
+
87
+ ```text
88
+ jrrribeiro/BirdNET-Validator-App
89
+ ```
90
+
91
+ Responsibilities:
92
+
93
+ 1. OAuth authentication and session-bound operations.
94
+ 2. Project onboarding workflow.
95
+ 3. Data loading, validation UI, dashboards, and exports.
96
+ 4. Bucket state write batching, reconciliation, and auditing.
97
+
98
+ It must not durably own:
99
+
100
+ 1. project audio;
101
+ 2. detection tables;
102
+ 3. project validation state;
103
+ 4. project ACL as an alternate source of authorization; or
104
+ 5. administrator or validator tokens.
105
+
106
+ ### Project Organization
107
+
108
+ Example:
109
+
110
+ ```text
111
+ ppbio-rabeca/
112
+ PPBIO-RABECA private dataset repository
113
+ PPBIO-RABECA-validation-state private Storage Bucket
114
+ ```
115
+
116
+ Recommended project resources:
117
+
118
+ | Resource | Location | Purpose | Mutable? |
119
+ |---|---|---|---:|
120
+ | Audio segments | Private dataset repository | Scientific source recordings | No during validation |
121
+ | Detection index/CSV | Same private dataset | Source observations and metadata | No during validation |
122
+ | `project.json` manifest | Validation Bucket metadata prefix initially | Project discovery/configuration | Infrequent admin update |
123
+ | Validation events | Validation Bucket `events/` | Append-oriented authored decisions | Yes |
124
+ | Reconciled snapshots | Validation Bucket `snapshots/` | Fast queue/progress reads | Yes |
125
+ | Audit archives/checkpoints | Validation Bucket `archives/` | Durable reconstruction/export | Append-oriented |
126
+
127
+ The original dataset remains versioned in a dataset repository. The frequently
128
+ mutating validation state uses a Bucket to avoid Git commit pressure.
129
+
130
+ ## Organization Roles As Authorization
131
+
132
+ For the first organization-owned architecture:
133
+
134
+ | HF organization role | App role | Allowed UI capabilities |
135
+ |---|---|---|
136
+ | `admin` | Project administrator | Resource setup, integrity checks, member overview, validation, export, archival operations |
137
+ | `write` | Trusted validator | Read source dataset, write decisions, view progress, export as permitted |
138
+ | `read` | Viewer | Read project/progress only; no validation write |
139
+ | `contributor` | Viewer or unsupported state | Cannot write admin-created Bucket; never present as active validator |
140
+ | No membership/access | No project visibility | No project data access |
141
+
142
+ The app must query actual Hub access rather than treating a local invitation as
143
+ authorization. The current internal ACL/invite system becomes legacy migration
144
+ support only, then can be removed after organization mode is stable.
145
+
146
+ ## User Experience And Supported Automation
147
+
148
+ The app should present an ordinary project workflow even though Hugging Face
149
+ resources are used underneath.
150
+
151
+ ### Create Project Workspace
152
+
153
+ User-facing flow:
154
+
155
+ 1. Admin clicks **Create Project**.
156
+ 2. Admin supplies project name and the slug of an existing dedicated HF
157
+ organization.
158
+ 3. The app authenticates through OAuth and verifies the user has adequate
159
+ access to initialize resources.
160
+ 4. The app creates the private dataset repository and private validation
161
+ Bucket in that organization.
162
+ 5. The app writes the manifest and initial empty validation snapshot.
163
+ 6. The app performs readiness checks and shows the created resource identifiers.
164
+
165
+ Supported automation:
166
+
167
+ | Step | App handles it? | Notes |
168
+ |---|---:|---|
169
+ | Validate existing organization | Yes | Hub API/client |
170
+ | Validate admin can create organization resources | Yes | Attempt/preflight and explicit errors |
171
+ | Create dataset | Yes | `create_repo(..., repo_type="dataset", private=True)` |
172
+ | Create Bucket | Yes | `create_bucket(..., private=True)` |
173
+ | Write initial manifest/state | Yes | Bucket API |
174
+ | Create the organization itself | No in free supported path | Link user to HF create organization page |
175
+
176
+ ### Add Validators
177
+
178
+ The desired interface remains an app card named **Project Members**, but it
179
+ mirrors Hub authority.
180
+
181
+ Supported free-tier flow:
182
+
183
+ 1. App lists current members and translates HF roles into app capabilities.
184
+ 2. For a new validator, app explains that `write` is required and provides a
185
+ direct link/instructions to the project's organization Members page.
186
+ 3. Admin invites/adds the user through Hugging Face.
187
+ 4. Admin returns and clicks **Refresh members**; the app detects the member and
188
+ runs a readiness test.
189
+
190
+ Not supported as a free default:
191
+
192
+ 1. Sending the actual organization membership invite through a supported API;
193
+ 2. changing a member to `write` programmatically; or
194
+ 3. removing organization membership programmatically.
195
+
196
+ Optional future paid feature:
197
+
198
+ If a project organization has a qualifying subscription, the app could support
199
+ role changes for existing members through the documented Hub endpoint, with a
200
+ separately authorized fine-grained organization-management credential. This
201
+ must never be required for free use.
202
+
203
+ ## OAuth Boundary Still To Prove
204
+
205
+ The token spike proves Hub organization permission behavior, not the Space
206
+ OAuth permission granted to this app.
207
+
208
+ Official OAuth documentation confirms:
209
+
210
+ 1. OAuth scopes can apply to organization resources selected by a user at
211
+ authorization time.
212
+ 2. `read-repos`, `write-repos`, and `manage-repos` descriptions refer to
213
+ repositories; no reviewed scope description explicitly promises Bucket
214
+ write behavior.
215
+ 3. An app may request a specific organization through `orgIds=ORG_ID` in its
216
+ authorization URL.
217
+
218
+ Therefore organization mode must not be implemented as production workflow
219
+ until a Space diagnostic proves:
220
+
221
+ | Actor | Required proof using OAuth only |
222
+ |---|---|
223
+ | Admin | Detect organization, read/create project resources or access test resources, write diagnostic Bucket marker |
224
+ | Validator `write` | Read private dataset, read Bucket, write diagnostic Bucket marker |
225
+ | Validator `read` or `contributor` | Cannot submit validation state |
226
+
227
+ No manual token may be entered for that proof.
228
+
229
+ ## Data Safety Requirements
230
+
231
+ Because validators with `write` are trusted but technically broad within one
232
+ project organization:
233
+
234
+ 1. One organization must contain only one scientific project.
235
+ 2. Source audio/detection dataset must remain Git-backed and treated as
236
+ immutable once validation begins.
237
+ 3. App validation flows must never issue dataset writes for validators.
238
+ 4. Bucket decisions must include actor, timestamp, detection key, decision,
239
+ prior version, new version, and event ID.
240
+ 5. Individual validation events remain auditable until compacted into
241
+ append-oriented archives.
242
+ 6. Snapshots are derived acceleration artifacts, not the sole source of truth.
243
+ 7. Admin receives export/checkpoint tools and an integrity health view.
244
+ 8. The uploader must retain local/source backups before moving real datasets
245
+ into organization ownership.
246
+
247
+ ## Required App Refactor
248
+
249
+ ### Phase 0 - OAuth Organization/Bucket Capability Proof
250
+
251
+ Goal: close the one unresolved technical permission question.
252
+
253
+ Deliverables:
254
+
255
+ 1. Add an experimental diagnostics card available only in the feature branch.
256
+ 2. Use the active OAuth session, never manually entered tokens.
257
+ 3. Configure the existing test organization and Bucket:
258
+ `ppbio-rabeca/birdnet-validator-permission-spike`.
259
+ 4. Show read/write results and clear failure interpretation.
260
+ 5. Test both `jrrribeiro` (`admin`) and `jonathan2008r` restored to `write`.
261
+
262
+ Exit gate: both accounts write distinct diagnostic markers through OAuth.
263
+
264
+ ### Phase 1 - Organization Project Domain Model
265
+
266
+ Goal: model project ownership around an organization and resource references.
267
+
268
+ Deliverables:
269
+
270
+ 1. New manifest schema containing organization, dataset repo id, validation
271
+ Bucket id, visibility, schema version, and initialized timestamp.
272
+ 2. `OrganizationProjectService` that loads the manifest and verifies resource
273
+ availability.
274
+ 3. Membership mapper converting HF member role to application capability.
275
+ 4. Legacy internal-ACL projects continue reading until migrated; no silent
276
+ conversion.
277
+
278
+ ### Phase 2 - Project Creation Wizard
279
+
280
+ Goal: keep the current easy create-project interaction while making the
281
+ organization the durable project owner.
282
+
283
+ Deliverables:
284
+
285
+ 1. Request existing organization slug and project display name.
286
+ 2. Check organization/resource permissions using OAuth.
287
+ 3. Create private dataset and private Bucket automatically.
288
+ 4. Initialize manifest and snapshots automatically.
289
+ 5. Provide explicit incomplete-initialization recovery if any sub-step fails.
290
+ 6. Do not store project tokens.
291
+
292
+ ### Phase 3 - Membership-Based Access UX
293
+
294
+ Goal: replace misleading application invites with real HF readiness.
295
+
296
+ Deliverables:
297
+
298
+ 1. Replace **User access and invitations** with **Project Members**.
299
+ 2. List organization members and mapped app roles.
300
+ 3. Show access requirements: validators must be trusted HF `write` members.
301
+ 4. Provide a guided link to the HF Members page for add/change/remove actions
302
+ in free organizations.
303
+ 5. Add **Refresh members** and per-member readiness diagnostics.
304
+ 6. Hide validation/project resources from non-members.
305
+
306
+ ### Phase 4 - Bucket-Backed Validation As Primary Store
307
+
308
+ Goal: use already-developed fast mutable storage behavior with project-owned
309
+ organization Bucket routing.
310
+
311
+ Deliverables:
312
+
313
+ 1. Route validation event writes to the organization Bucket using acting user's
314
+ OAuth token.
315
+ 2. Route snapshots, conflict recovery, progress, and CSV/XLSX exports from
316
+ Bucket state.
317
+ 3. Enable bounded compaction/audit archives after load testing.
318
+ 4. Never fall back to filesystem, Supabase, or admin credentials when an
319
+ organization write fails.
320
+
321
+ ### Phase 5 - Dataset/Uploader Integration
322
+
323
+ Goal: allow administrators to provision the project in the app and send audio
324
+ to the created organization dataset efficiently.
325
+
326
+ Deliverables:
327
+
328
+ 1. Surface the created dataset repo id for the uploader.
329
+ 2. Update uploader/app integration documentation for organization destinations.
330
+ 3. Preserve uploader index structure used by validation loading.
331
+ 4. Add connection flow for existing organization datasets.
332
+
333
+ ### Phase 6 - Migration And Removal Of Legacy Authorization
334
+
335
+ Goal: retire fragile centrally owned state after qualification.
336
+
337
+ Deliverables:
338
+
339
+ 1. Migration preview for current Supabase/filesystem/experimental `_state`
340
+ projects.
341
+ 2. State import into organization Bucket with counts and verification report.
342
+ 3. Remove project token entry from normal UI.
343
+ 4. Disable internal invites/ACL as authority in organization mode.
344
+ 5. Keep legacy mode read-only or explicitly marked until users migrate.
345
+
346
+ ## Testing Program
347
+
348
+ ### Permission And Security Tests
349
+
350
+ 1. OAuth admin Bucket write in Space.
351
+ 2. OAuth `write` validator Bucket write in Space.
352
+ 3. OAuth `read`/`contributor` user validation write rejected.
353
+ 4. User outside organization cannot see dataset or Bucket data.
354
+ 5. App stores no OAuth/admin tokens in manifest, Bucket events, logs, or
355
+ exports.
356
+
357
+ ### Reliability Tests
358
+
359
+ 1. Two validators write concurrently.
360
+ 2. Duplicate submit is idempotent.
361
+ 3. Snapshot conflict is recovered from authored events.
362
+ 4. Restart/redeploy does not lose validation state.
363
+ 5. Export reconstructs detections plus partial or completed validations.
364
+
365
+ ### Scale Tests
366
+
367
+ 1. Simulate decisions at approximately one action every three seconds per
368
+ validator.
369
+ 2. Run multiple concurrent validators.
370
+ 3. Test event archive/compaction windows at realistic project sizes.
371
+ 4. Measure Bucket latency and Hub rate-limit responses.
372
+ 5. Confirm no dataset commits are generated by validation activity.
373
+
374
+ ## Implementation Gate
375
+
376
+ The next code change should be **Phase 0 only**. Do not begin the onboarding
377
+ refactor until the existing organization Bucket succeeds through Space OAuth
378
+ for both administrator and `write` validator.
379
+
380
+ ## Official References
381
+
382
+ - HfApi Client: <https://huggingface.co/docs/huggingface_hub/en/package_reference/hf_api>
383
+ - Storage Buckets: <https://huggingface.co/docs/hub/storage-buckets>
384
+ - Python Bucket guide: <https://huggingface.co/docs/huggingface_hub/guides/buckets>
385
+ - Organization management: <https://huggingface.co/docs/hub/organizations-managing>
386
+ - Organization access control: <https://huggingface.co/docs/hub/organizations-security>
387
+ - Programmatic User Access Control Management: <https://huggingface.co/docs/hub/programmatic-user-access-control>
388
+ - OAuth / Sign in with HF: <https://huggingface.co/docs/hub/oauth>
docs/HF_ORGANIZATION_STORAGE_BACKEND_INVESTIGATION.md CHANGED
@@ -4,6 +4,15 @@ Status: token permission spike completed; viable only with organization-wide wri
4
  Created: 2026-05-25
5
  Target branch: `feature/project-state-security-privacy-review`
6
 
 
 
 
 
 
 
 
 
 
7
  ## Purpose
8
 
9
  Evaluate whether a free Hugging Face organization owned and managed by each
 
4
  Created: 2026-05-25
5
  Target branch: `feature/project-state-security-privacy-review`
6
 
7
+ > Architecture follow-up (2026-05-26): after reviewing the official HfApi and
8
+ > programmatic access control documentation, the intended application redesign
9
+ > is maintained in
10
+ > [`HF_ORGANIZATION_PER_PROJECT_APP_REDESIGN_PLAN.md`](HF_ORGANIZATION_PER_PROJECT_APP_REDESIGN_PLAN.md).
11
+ > In free organizations, resource initialization can be automated, but initial
12
+ > member invitations and role administration remain Hub-managed onboarding
13
+ > steps; the documented programmatic member-role endpoint requires a
14
+ > subscription plan and an already existing organization member.
15
+
16
  ## Purpose
17
 
18
  Evaluate whether a free Hugging Face organization owned and managed by each