Skip to content

Commit 7515bb3

Browse files
committed
update README
1 parent 753adfd commit 7515bb3

File tree

1 file changed

+152
-40
lines changed

1 file changed

+152
-40
lines changed

AUTHORIZATION.md

Lines changed: 152 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,43 @@ This document describes the organizational data-based authorization system integ
44

55
## Overview
66

7-
The authorization system provides fine-grained access control for bot commands based on organizational data. It integrates with hierarchical organizational structures and supports multiple authorization levels including user-specific, team-based, and organization-based permissions.
7+
The authorization system provides fine-grained access control for bot commands based on organizational data. It now uses a modern, indexed data structure that provides fast lookups and comprehensive organizational hierarchy information. The system supports multiple authorization levels including user-specific, team-based, and organization-based permissions.
88

99
## Key Features
1010

11-
- **Hierarchical Organization Data**: Processes nested organizational structures with teams and employees
11+
- **Indexed Organization Data**: Uses pre-computed indexes for O(1) lookups and fast authorization checks
12+
- **Complete Organizational Hierarchy**: Shows full ancestry chain including teams, organizations, pillars, and team groups
1213
- **Multiple Authorization Levels**: Support for user UID, team membership, and organization-based permissions
1314
- **Hot Reload**: Automatic updates when organizational data or authorization config changes
14-
- **Enhanced Troubleshooting**: Comprehensive `whoami` command showing user permissions and available commands
15+
- **Enhanced Troubleshooting**: Comprehensive `whoami` command showing complete organizational context
1516
- **Fallback Safety**: Graceful degradation when authorization service is unavailable
17+
- **Modular Architecture**: Clean separation between core data service and Slack-specific authorization logic
1618

1719
## Architecture
1820

1921
```
2022
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
21-
│ Organizational │ │ Authorization │ │ Slack Commands │
22-
│ Data (JSON) │───▶│ Service │───▶│ & Handlers │
23+
│ Indexed Org │ │ Core Data │ │ Slack-Specific │
24+
│ Data (JSON) │───▶│ Service │───▶│ Authorization │
25+
│ (Python orglib) │ │ (orgdata-core) │ │ Service │
2326
└─────────────────┘ └──────────────────┘ └─────────────────┘
24-
│ │
25-
│ │
26-
▼ ▼
27-
┌─────────────────┐ ┌──────────────────┐
28-
│ OrgDataService │ │ Auth Config │
29-
│ (Indexing & │ │ (YAML Rules) │
30-
│ Fast Lookups) │ │ │
31-
└─────────────────┘ └──────────────────┘
27+
│ │ │
28+
│ │ │
29+
▼ ▼ ▼
30+
┌─────────────────┐ ┌──────────────────┐ ┌──────────────────┐
31+
│ Comprehensive │ │ Fast Indexed │ │ Auth Config │
32+
│ Index Dump │ │ Lookups │ │ (YAML Rules) │
33+
│ (comprehensive_ │ │ (O(1) queries) │ │ │
34+
│ index_dump.json)│ │ │ │ │
35+
└─────────────────┘ └──────────────────┘ └──────────────────┘
3236
```
3337

38+
### Package Structure
39+
40+
- **`pkg/orgdata-core/`**: Reusable core package for organizational data access
41+
- **`pkg/orgdata/`**: Slack-specific wrapper around core package
42+
- **`pkg/slack/`**: Slack command handlers with authorization middleware
43+
3444
## Setup
3545

3646
### 1. Command Line Flags
@@ -46,36 +56,74 @@ Add these flags when running the CI Chat Bot:
4656

4757
### 2. Organizational Data Format
4858

49-
The system expects hierarchical JSON data with this structure:
59+
The system now uses indexed JSON data generated by the Python `orglib` indexing system. The data structure includes pre-computed indexes for fast lookups:
5060

5161
```json
5262
{
53-
"name": "Top Level Organization",
54-
"group": {
55-
"type": {"name": "org"},
56-
"resolved_roles": [
57-
{
58-
"people": [
59-
{
60-
"uid": "employee_id",
61-
"slack_uid": "U123ABC456",
62-
"display_name": "John Doe",
63-
"email": "[email protected]",
64-
"job_title": "Senior Engineer"
65-
}
66-
]
63+
"metadata": {
64+
"generated_at": "2025-08-13T15:00:00Z",
65+
"data_version": "v1.0",
66+
"total_employees": 150,
67+
"total_orgs": 25,
68+
"total_teams": 45
69+
},
70+
"lookups": {
71+
"employees": {
72+
"employee_uid": {
73+
"uid": "employee_uid",
74+
"full_name": "John Doe",
75+
"email": "[email protected]",
76+
"job_title": "Senior Engineer",
77+
"slack_uid": "U123ABC456"
78+
}
79+
},
80+
"teams": {
81+
"team_name": {
82+
"uid": "team_uid",
83+
"name": "Team Name",
84+
"type": "team",
85+
"group": {
86+
"resolved_people_uid_list": ["employee_uid1", "employee_uid2"]
87+
}
6788
}
68-
]
89+
},
90+
"orgs": {
91+
"org_name": {
92+
"uid": "org_uid",
93+
"name": "Organization Name",
94+
"type": "org",
95+
"group": {
96+
"resolved_people_uid_list": ["employee_uid1", "employee_uid2"]
97+
}
98+
}
99+
}
69100
},
70-
"children": [
71-
{
72-
"name": "Team Name",
73-
"group": {
74-
"type": {"name": "team"},
75-
"resolved_roles": [...]
101+
"indexes": {
102+
"membership": {
103+
"membership_index": {
104+
"employee_uid": [
105+
{"name": "team_name", "type": "team"},
106+
{"name": "org_name", "type": "org"}
107+
]
108+
},
109+
"relationship_index": {
110+
"teams": {
111+
"team_name": {
112+
"ancestry": {
113+
"orgs": ["parent_org1", "parent_org2"],
114+
"pillars": ["pillar_name"],
115+
"team_groups": ["team_group_name"]
116+
}
117+
}
118+
}
119+
}
120+
},
121+
"slack_id_mappings": {
122+
"slack_uid_to_uid": {
123+
"U123ABC456": "employee_uid"
76124
}
77125
}
78-
]
126+
}
79127
}
80128
```
81129

@@ -155,8 +203,12 @@ rules:
155203
@bot whoami
156204
```
157205
This shows:
158-
- Your employee information
159-
- Organizational memberships (teams, groups, organizations with their types)
206+
- Your employee information (UID, name, email, job title)
207+
- Complete organizational hierarchy including:
208+
- Direct team memberships
209+
- Organizations you belong to through team membership
210+
- Pillars and team groups in your ancestry chain
211+
- Full organizational context
160212
- Specific commands you can execute
161213
- How you get access to each command
162214
@@ -171,6 +223,39 @@ This shows:
171223
1. Add authorization rule to config file
172224
2. Wrap command handler with authorization middleware
173225
226+
## Package Structure
227+
228+
### Core Package (`pkg/orgdata-core/`)
229+
230+
The core package provides reusable organizational data functionality:
231+
232+
- **`types.go`**: Core data structures (Employee, Team, Org, etc.)
233+
- **`interface.go`**: Service interface for data access
234+
- **`service.go`**: Implementation with fast indexed lookups
235+
- **`README.md`**: Comprehensive documentation
236+
237+
### Slack Package (`pkg/orgdata/`)
238+
239+
Slack-specific wrapper around the core package:
240+
241+
- **`types.go`**: Type re-exports for backward compatibility
242+
- **`interface.go`**: Slack service wrapper with `NewIndexedOrgDataService()`
243+
- **`auth.go`**: Authorization service using the core package
244+
245+
### Usage
246+
247+
```go
248+
// Create the service (same as before)
249+
service := orgdata.NewIndexedOrgDataService()
250+
251+
// Load data
252+
err := service.LoadFromFiles([]string{"comprehensive_index_dump.json"})
253+
254+
// Use the service
255+
teams := service.GetTeamsForSlackID("U123ABC456")
256+
orgs := service.GetUserOrganizations("U123ABC456")
257+
```
258+
174259
## Integration Points
175260

176261
### Adding Authorization to New Commands
@@ -217,6 +302,31 @@ The system can load organizational data from:
217302
- Kubernetes ConfigMaps (in production)
218303
- Multiple files (automatically merged)
219304

305+
## Recent Refactoring
306+
307+
### What Changed
308+
309+
The authorization system has been refactored to use a modern, indexed data structure:
310+
311+
- **Before**: Used hierarchical JSON with runtime traversal
312+
- **After**: Uses pre-computed indexes for instant lookups
313+
- **Data Source**: Python `orglib` indexing system generates `comprehensive_index_dump.json`
314+
- **Architecture**: Clean separation between core data service and Slack-specific logic
315+
316+
### Benefits
317+
318+
- **Faster**: O(1) lookups instead of O(n) traversals
319+
- **Complete**: Shows full organizational hierarchy (teams → orgs → pillars → team groups)
320+
- **Maintainable**: Core package can be reused by other services
321+
- **Scalable**: Better performance with large organizational datasets
322+
323+
### Migration
324+
325+
- **No breaking changes**: All existing functionality preserved
326+
- **Same API**: `whoami` command works exactly as before
327+
- **Enhanced output**: Now shows complete organizational context
328+
- **Better performance**: Faster authorization checks
329+
220330
## Security Considerations
221331

222332
- **Fail-open design**: Commands work if authorization service fails
@@ -226,7 +336,9 @@ The system can load organizational data from:
226336

227337
## Performance
228338

229-
- **O(1) lookups**: Pre-built indexes for fast authorization checks
230-
- **Memory efficient**: Hierarchical data flattened into optimized structures
339+
- **O(1) lookups**: Pre-computed indexes enable instant authorization checks
340+
- **Memory efficient**: Indexed data structure optimized for fast access
231341
- **Minimal latency**: Authorization check adds <1ms to command execution
232342
- **Scalable**: Handles thousands of employees and teams efficiently
343+
- **Hot reload**: Data updates without service restart
344+
- **Modular design**: Core package can be reused by other services (REST APIs, CLI tools, etc.)

0 commit comments

Comments
 (0)