Cloud: data model, security rules, and the authorization gate
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 38/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- firebase, typescript
- Lĩnh vực
- authentication, cloud, databases, security, testing-qa
Hướng nghiên cứu
Start with firestore.rules and storage.rules, then inspect the first-sign-in flow and the rules unit tests using @firebase/rules-unit-testing; review dependencies #787 and #788 first. Done means the listed data model, provisioning and authorization behavior work, all specified negative cases are covered, and scoped mutation coverage reaches at least 80%.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
Define the Firestore/Storage data model and the security rules that are the entire
authorization boundary for this milestone, plus the first-sign-in provisioning flow.
Provisioning is admin-only, but requires no Cloud Function: because identity is Google-only,
"admin adds a user" is just a Firestore write to an allowlist, and the security rule decides
whether a first-time user may create their own user document.
Data model
config/defaults { quotaBytes: 26214400, maxFiles: 2000, maxFileBytes: 5242880 }
allowlist/{lowercasedEmail} { addedBy, addedAt, note }
allowedDomains/{domain} { addedBy, addedAt } // e.g. "adventuresinlua.com"
users/{uid} { email, displayName, role: 'user'|'admin', disabled,
quotaBytes, maxFiles, createdAt, lastSeenAt }
users/{uid}/drive/manifest { entries: { "<encPath>": {s,h,b,r?} }, usedBytes, fileCount, rev }
users/{uid}/content/{encPath} { c: string } // text <= 256 KB
gs://.../users/{uid}/blobs/{encPath} // binary, or text > 256 KB
encPath is encodeURIComponent(path) — Firestore document IDs cannot contain /. Guard the
illegal . and .. document-ID cases and the 1500-byte ID limit.
Separation of authority
This is the property the whole security model rests on:
- A user may write their own manifest and content. Rules validate those writes against limits
read fromusers/{uid}. - A user may never write their own
quotaBytes,maxFiles,role, ordisabled. Those are
admin-only, which is what keeps the admin panel a set of plain Firestore writes. usedBytesandfileCountlive on the manifest, not the user doc, precisely so the user
can update them without being able to touch their own limits.
Authorization flow
- User completes Google sign-in (#788).
- Client reads
users/{uid}. Exists anddisabled != true-> authorized. - Absent -> client attempts to create it. The rule permits creation only when
allowlist/{lowercasedEmail}orallowedDomains/{emailDomain}exists, and pinsquotaBytes,
maxFiles, androle: 'user'to the values inconfig/defaults. - Creation denied -> show exactly
"{EMAIL} is not authorized."and callsignOut().
The client-side check is a UX affordance. The security rule is the real gate. An
unauthorized person still ends up with a Firebase Auth record; rules must deny them all data.
Acceptance criteria
-
firestore.rulesandstorage.rulesimplement the model above - First sign-in by an allowlisted email self-provisions
users/{uid}with defaults fromconfig/defaults - First sign-in by an email on an allowed domain self-provisions identically
- Unauthorized sign-in shows exactly
"{EMAIL} is not authorized."and signs the user out -
disabled: trueblocks all data access - Admin bootstrap documented (hand-edit
role: 'admin'in the console after first sign-in) - Rules unit tests via
@firebase/rules-unit-testingcover the negative cases:- non-allowlisted email cannot create
users/{uid} - email on a non-allowed domain cannot create
users/{uid} - a user cannot raise their own
quotaBytesormaxFiles - a user cannot set
role: 'admin'on themselves - a user cannot read or write another uid's manifest, content, or blobs
- a disabled user is denied
- an unauthenticated request is denied everywhere
- non-allowlisted email cannot create
- Scoped mutation coverage >= 80%
Implementation notes
- Firestore rules can
get()other documents, and Storage rules can call
firestore.get()— that is what lets Storage enforce per-user limits read from Firestore
rather than trusting client input. Note each such call costs a document read. - Rules string functions include
.split(), so the email domain can be derived in-rule from
request.auth.token.email. - Because the rules are the authorization boundary, a suite of passing positive tests proves
nothing on its own. The negative cases above are the point of this issue.
Depends on
- #787
- #788
Branching
This issue is part of the Cloud Accounts & Storage
milestone, which uses feat/cloud as its integration branch.
Branch from feat/cloud, and open the PR against feat/cloud. Never against main.
Create the branch (the --base flag also sets the default PR target for this branch):
gh issue develop <number> --base feat/cloud --checkout
Open the PR:
python3 scripts/issue-review.py <number> --base feat/cloud \
--summary "<summary>" --test-plan "<test-plan>"
feat/cloud merges to main in a single PR once the milestone is complete.
Why both flags are required: gh issue develop without --base branches from the repository
default branch (main), and scripts/issue-review.py falls back to main when --base is
omitted — both for the gh pr create target and for the changed-file list in the PR body.
- Ngôn ngữ chính
- TypeScript
- Star
- 1
- Fork
- 0
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của jcollard/LuaInTheWeb
-
tech-debt
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
jcollard/LuaInTheWeb#752 ·
-
tech-debt
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 68/100
jcollard/LuaInTheWeb#690 ·
-
tech-debt
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
jcollard/LuaInTheWeb#590 ·
-
tech-debt
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
jcollard/LuaInTheWeb#518 ·
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
jcollard/LuaInTheWeb#235 ·
Tất cả issue của jcollard/LuaInTheWeb
Issue tương tự
-
[Bug]: Fix for unicode filenamesĐang mở🐛 bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
LibreChat-AI/LibreChat#17733 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
TypeStrong/typedoc#3150 ·
-
accessibility bug good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Normalize image-source MIME types before SVG dispatchCó thể đã có người làm @HarsH-1877 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
tscircuit/image-utils#58 · 1 bình luận ·
-
Add API: BlockVectra Data APIĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 2 ngày