Skip to content

Commit dd1d2b5

Browse files
authored
Merge pull request #16 from objectql/copilot/add-permission-metadata-implementation
2 parents b615e8b + d9f0be2 commit dd1d2b5

7 files changed

Lines changed: 1129 additions & 85 deletions

File tree

docs/spec/permission.md

Lines changed: 16 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# Permission & Security Metadata
22

3-
Permission metadata defines access control rules for objects, fields, actions, and views. It implements role-based access control (RBAC) and field-level security.
3+
Permission metadata defines access control rules for objects, fields, actions, and views using Role-Based Access Control (RBAC) and field-level security.
44

55
## 1. Overview
66

7-
ObjectQL's permission system provides:
7+
ObjectQL's permission system provides a pure RBAC model with:
88

9+
- **Role-based access control**: Define roles and assign permissions to roles
910
- **Object-level permissions**: Control CRUD operations on entire objects
1011
- **Field-level security**: Hide/protect sensitive fields from unauthorized users
1112
- **Record-level rules**: Dynamic filtering based on ownership, sharing, or custom rules
@@ -269,69 +270,7 @@ sharing_rules:
269270
update: true
270271
```
271272

272-
## 7. Profile-Based Permissions
273-
274-
Organize permissions into profiles for easier management.
275-
276-
```yaml
277-
profiles:
278-
# System Administrator
279-
- name: system_admin
280-
label: System Administrator
281-
description: Full system access
282-
object_permissions:
283-
"*": [create, read, update, delete, view_all, modify_all]
284-
field_permissions:
285-
"*": [read, update]
286-
287-
# Standard User
288-
- name: standard_user
289-
label: Standard User
290-
description: Regular user access
291-
object_permissions:
292-
projects: [create, read, update]
293-
tasks: [create, read, update, delete]
294-
reports: [read]
295-
field_permissions:
296-
projects.budget: [read]
297-
tasks.*: [read, update]
298-
299-
# Read-Only
300-
- name: read_only
301-
label: Read Only
302-
description: View-only access
303-
object_permissions:
304-
"*": [read]
305-
field_permissions:
306-
"*": [read]
307-
```
308-
309-
## 8. Permission Sets
310-
311-
Grant additional permissions beyond a user's profile.
312-
313-
```yaml
314-
permission_sets:
315-
# Financial Data Access
316-
- name: finance_access
317-
label: Financial Data Access
318-
description: Grant access to financial fields
319-
field_permissions:
320-
"*.budget": [read, update]
321-
"*.cost": [read, update]
322-
"*.revenue": [read, update]
323-
324-
# API Integration Access
325-
- name: api_access
326-
label: API Access
327-
description: Allow API access
328-
api_permissions:
329-
enabled: true
330-
rate_limit: 10000
331-
allowed_operations: [create, read, update]
332-
```
333-
334-
## 9. Action Permissions
273+
## 7. Action Permissions
335274

336275
Control execution of custom actions.
337276

@@ -358,7 +297,7 @@ action_permissions:
358297
requests_per_hour: 10
359298
```
360299

361-
## 10. View Permissions
300+
## 8. View Permissions
362301

363302
Control access to specific views.
364303

@@ -380,9 +319,9 @@ view_permissions:
380319
visible_to: [admin]
381320
```
382321

383-
## 11. Data Security Features
322+
## 9. Data Security Features
384323

385-
### 11.1 Row-Level Security
324+
### 9.1 Row-Level Security
386325

387326
Automatically filter queries based on permissions.
388327

@@ -408,7 +347,7 @@ row_level_security:
408347
value: $current_user.department_id
409348
```
410349

411-
### 11.2 Field Masking
350+
### 9.2 Field Masking
412351

413352
Mask sensitive data for unauthorized users.
414353

@@ -430,7 +369,7 @@ field_masking:
430369
visible_to: [admin, hr]
431370
```
432371

433-
### 11.3 Audit Trail
372+
### 9.3 Audit Trail
434373

435374
Track permission changes and access.
436375

@@ -456,9 +395,9 @@ audit:
456395
notify: [security_team]
457396
```
458397

459-
## 12. Implementation
398+
## 10. Implementation
460399

461-
### 12.1 Permission Check API
400+
### 10.1 Permission Check API
462401

463402
```typescript
464403
// Check if user can perform operation
@@ -479,7 +418,7 @@ const canViewSalary = await objectql.checkFieldPermission({
479418
});
480419
```
481420

482-
### 12.2 Permission Context
421+
### 10.2 Permission Context
483422

484423
Hooks and actions receive permission context:
485424

@@ -492,25 +431,25 @@ beforeUpdate: async ({ user, permissions }) => {
492431
}
493432
```
494433

495-
## 13. Best Practices
434+
## 11. Best Practices
496435

497436
1. **Principle of Least Privilege**: Grant minimum necessary permissions
498-
2. **Role Hierarchy**: Use role inheritance to simplify management
437+
2. **Define Clear Roles**: Create well-defined roles that match organizational structure
499438
3. **Test Permissions**: Validate permission rules with different user roles
500439
4. **Document Rules**: Add clear descriptions to all permission rules
501440
5. **Regular Audits**: Review permissions regularly for compliance
502441
6. **Separation of Duties**: Prevent conflicts of interest with permission design
503442
7. **Default Deny**: Deny access unless explicitly granted
504443

505-
## 14. Security Considerations
444+
## 12. Security Considerations
506445

507446
1. **SQL Injection**: All permission filters use parameterized queries
508447
2. **Privilege Escalation**: Validate permission changes require admin access
509448
3. **Session Management**: Permissions cached per session, invalidated on role change
510449
4. **API Security**: Rate limiting on permission checks to prevent DoS
511450
5. **Audit Logging**: All permission denials logged for security analysis
512451

513-
## 15. Related Specifications
452+
## 13. Related Specifications
514453

515454
- [Objects & Fields](./object.md) - Data model definition
516455
- [Actions](./action.md) - Custom operations

0 commit comments

Comments
 (0)