Skip to content

Commit 212f59e

Browse files
committed
update the AUTHORIZATION.md AI-generated readme to reflect the gcs changes
1 parent ea05506 commit 212f59e

File tree

1 file changed

+119
-19
lines changed

1 file changed

+119
-19
lines changed

AUTHORIZATION.md

Lines changed: 119 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The authorization system provides fine-grained access control for bot commands b
1111
- **Indexed Organization Data**: Uses pre-computed indexes for O(1) lookups and fast authorization checks
1212
- **Complete Organizational Hierarchy**: Shows full ancestry chain including teams, organizations, pillars, and team groups
1313
- **Multiple Authorization Levels**: Support for user UID, team membership, and organization-based permissions
14-
- **Hot Reload**: Automatic updates when organizational data or authorization config changes
14+
- **Hot Reload**: Automatic updates when organizational data or authorization config changes (supports local files and GCS)
1515
- **Enhanced Troubleshooting**: Comprehensive `whoami` command showing complete organizational context
1616
- **Fallback Safety**: Graceful degradation when authorization service is unavailable
1717
- **Modular Architecture**: Clean separation between core data service and Slack-specific authorization logic
@@ -28,32 +28,76 @@ The authorization system provides fine-grained access control for bot commands b
2828
│ │ │
2929
▼ ▼ ▼
3030
┌─────────────────┐ ┌──────────────────┐ ┌──────────────────┐
31-
Comprehensive │ │ Fast Indexed │ │ Auth Config │
32-
Index Dump │ │ Lookups │ │ (YAML Rules) │
33-
(comprehensive_ │ │ (O(1) queries) │ │
34-
index_dump.json)│ │ │ │
31+
Data Sources │ │ Fast Indexed │ │ Auth Config │
32+
• Local Files │ │ Lookups │ │ (YAML Rules) │
33+
• GCS Bucket │ │ (O(1) queries) │ │ • Hot Reload
34+
• Hot Reload │ │ • DataSource API │ │ • File Watching
3535
└─────────────────┘ └──────────────────┘ └──────────────────┘
3636
```
3737

38+
### DataSource Architecture
39+
40+
The system now uses a pluggable DataSource architecture:
41+
42+
- **FileDataSource**: Local JSON files with file watching
43+
- **GCSDataSource**: Google Cloud Storage with polling for updates
44+
- **Extensible**: Easy to add new sources (S3, HTTP, databases, etc.)
45+
3846
### Package Structure
3947

4048
- **`pkg/orgdata-core/`**: Reusable core package for organizational data access
41-
- **`pkg/orgdata/`**: Slack-specific wrapper around core package
49+
- Supports multiple data sources (files, GCS)
50+
- Build with `-tags gcs` for cloud storage support
51+
- Hot reload with configurable check intervals
52+
- **`pkg/orgdata/`**: Slack-specific wrapper around core package
4253
- **`pkg/slack/`**: Slack command handlers with authorization middleware
4354

4455
## Setup
4556

46-
### 1. Command Line Flags
57+
### 1. Configuration Options
4758

48-
Add these flags when running the CI Chat Bot:
59+
#### Option A: Local Files (Development)
4960

5061
```bash
5162
./ci-chat-bot \
52-
--orgdata-paths="/path/to/orgdata.json" \
63+
--orgdata-paths="/path/to/comprehensive_index_dump.json" \
5364
--authorization-config="/path/to/authorization.yaml" \
5465
[other flags...]
5566
```
5667

68+
#### Option B: Google Cloud Storage (Production)
69+
70+
```bash
71+
# Build with GCS support
72+
make BUILD_FLAGS="-tags gcs" build
73+
74+
# Run with GCS backend
75+
./ci-chat-bot \
76+
--gcs-enabled=true \
77+
--gcs-bucket="resolved-org" \
78+
--gcs-object-path="orgdata/comprehensive_index_dump.json" \
79+
--gcs-project-id="openshift-crt-mce" \
80+
--gcs-check-interval="5m" \
81+
--authorization-config="/path/to/authorization.yaml" \
82+
[other flags...]
83+
```
84+
85+
#### Option C: Using Development Scripts
86+
87+
```bash
88+
# Quick start with GCS (recommended)
89+
./hack/run-with-gcs.sh
90+
91+
# Local file development
92+
export ORGDATA_PATHS="/path/to/comprehensive_index_dump.json"
93+
./hack/run.sh
94+
95+
# See all options
96+
make help-ci-chat-bot
97+
```
98+
99+
📖 **For detailed setup instructions, see: `hack/DEVELOPMENT.md`**
100+
57101
### 2. Organizational Data Format
58102

59103
The system now uses indexed JSON data generated by the Python `orglib` indexing system. The data structure includes pre-computed indexes for fast lookups:
@@ -219,6 +263,14 @@ This shows:
219263
2. The system automatically reloads within 60 seconds
220264
3. Test changes with `@bot whoami`
221265
266+
**Update Organizational Data:**
267+
1. **Local Files**: Edit JSON file, automatic reload via file watching
268+
2. **GCS**: Upload new file to bucket, automatic reload via polling
269+
```bash
270+
gcloud storage cp comprehensive_index_dump.json gs://resolved-org/orgdata/
271+
```
272+
3. **Check interval**: Configurable via `--gcs-check-interval` (default: 5 minutes)
273+
222274
**Add New Commands:**
223275
1. Add authorization rule to config file
224276
2. Wrap command handler with authorization middleware
@@ -248,10 +300,22 @@ Slack-specific wrapper around the core package:
248300
// Create the service (same as before)
249301
service := orgdata.NewIndexedOrgDataService()
250302

251-
// Load data
303+
// Option 1: Load from local files
252304
err := service.LoadFromFiles([]string{"comprehensive_index_dump.json"})
253305

254-
// Use the service
306+
// Option 2: Load from GCS (requires -tags gcs)
307+
gcsConfig := orgdata.GCSConfig{
308+
Bucket: "resolved-org",
309+
ObjectPath: "orgdata/comprehensive_index_dump.json",
310+
ProjectID: "openshift-crt-mce",
311+
CheckInterval: 5 * time.Minute,
312+
}
313+
err := service.LoadFromGCS(ctx, gcsConfig)
314+
315+
// Start hot reload watcher
316+
err = service.StartGCSWatcher(ctx, gcsConfig)
317+
318+
// Use the service (same API regardless of data source)
255319
teams := service.GetTeamsForSlackID("U123ABC456")
256320
orgs := service.GetUserOrganizations("U123ABC456")
257321
```
@@ -281,9 +345,11 @@ The `AuthorizedCommandHandler` wrapper:
281345
### Common Issues
282346

283347
**"Authorization service not configured"**
284-
- Check `--orgdata-paths` and `--authorization-config` flags
285-
- Verify file paths exist and are readable
286-
- Check logs for data loading errors
348+
- **Local files**: Check `--orgdata-paths` and `--authorization-config` flags
349+
- **GCS**: Verify `--gcs-enabled=true` and GCS configuration flags
350+
- **Build**: Ensure binary built with `-tags gcs` for GCS support
351+
- **Authentication**: Run `gcloud auth login` or set service account credentials
352+
- **Logs**: Check for data loading errors, GCS authentication failures
287353

288354
**User not found in org data**
289355
- Verify user's Slack UID is in the organizational data
@@ -297,10 +363,41 @@ The `AuthorizedCommandHandler` wrapper:
297363

298364
## Data Sources
299365

300-
The system can load organizational data from:
301-
- Local JSON files (`--orgdata-paths`)
302-
- Kubernetes ConfigMaps (in production)
303-
- Multiple files (automatically merged)
366+
The system can load organizational data from multiple sources:
367+
368+
### Local Files
369+
```bash
370+
--orgdata-paths="/path/to/comprehensive_index_dump.json"
371+
```
372+
- **Best for**: Development, testing
373+
- **Hot Reload**: File watching (automatic)
374+
- **Dependencies**: None
375+
376+
### Google Cloud Storage
377+
```bash
378+
--gcs-enabled=true \
379+
--gcs-bucket="resolved-org" \
380+
--gcs-object-path="orgdata/comprehensive_index_dump.json" \
381+
--gcs-project-id="openshift-crt-mce"
382+
```
383+
- **Best for**: Production, cross-cluster deployments
384+
- **Hot Reload**: Configurable polling (default: 5 minutes)
385+
- **Dependencies**: Requires `-tags gcs` build flag
386+
- **Authentication**: Application Default Credentials or service account JSON
387+
388+
### Development Scripts
389+
```bash
390+
# GCS backend with sensible defaults
391+
./hack/run-with-gcs.sh
392+
393+
# Local file backend
394+
export ORGDATA_PATHS="/path/to/file.json"
395+
./hack/run.sh
396+
397+
# See all configuration options
398+
make help-ci-chat-bot
399+
cat hack/DEVELOPMENT.md
400+
```
304401

305402
## Recent Refactoring
306403

@@ -340,5 +437,8 @@ The authorization system has been refactored to use a modern, indexed data struc
340437
- **Memory efficient**: Indexed data structure optimized for fast access
341438
- **Minimal latency**: Authorization check adds <1ms to command execution
342439
- **Scalable**: Handles thousands of employees and teams efficiently
343-
- **Hot reload**: Data updates without service restart
440+
- **Hot reload**: Data updates without service restart (files + GCS)
441+
- **Multiple data sources**: Local files, GCS, extensible to S3/HTTP/databases
344442
- **Modular design**: Core package can be reused by other services (REST APIs, CLI tools, etc.)
443+
- **Production ready**: Secure GCS backend with Application Default Credentials
444+

0 commit comments

Comments
 (0)