raja 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
raja-0.2.0/PKG-INFO ADDED
@@ -0,0 +1,183 @@
1
+ Metadata-Version: 2.3
2
+ Name: raja
3
+ Version: 0.2.0
4
+ Summary: Add your description here
5
+ Author: Dr. Ernie Prabhakar
6
+ Author-email: Dr. Ernie Prabhakar <ernest@quilt.bio>
7
+ Requires-Dist: pydantic>=2.7.0
8
+ Requires-Dist: pyjwt>=2.8.0
9
+ Requires-Dist: fastapi>=0.110.0
10
+ Requires-Dist: mangum>=0.17.0
11
+ Requires-Dist: aws-cdk-lib>=2.100.0 ; extra == 'aws'
12
+ Requires-Dist: boto3>=1.34.0 ; extra == 'aws'
13
+ Requires-Dist: constructs>=10.0.0 ; extra == 'aws'
14
+ Requires-Dist: mypy>=1.7.0 ; extra == 'dev'
15
+ Requires-Dist: poethepoet>=0.24.0 ; extra == 'dev'
16
+ Requires-Dist: pytest>=8.0.0 ; extra == 'dev'
17
+ Requires-Dist: pytest-cov>=4.1.0 ; extra == 'dev'
18
+ Requires-Dist: pytest-watch>=4.2.0 ; extra == 'dev'
19
+ Requires-Dist: httpx>=0.27.0 ; extra == 'dev'
20
+ Requires-Dist: ruff>=0.1.0 ; extra == 'dev'
21
+ Requires-Dist: boto3-stubs[dynamodb,secretsmanager,verifiedpermissions]>=1.34.0 ; extra == 'dev'
22
+ Requires-Dist: moto>=4.2.0 ; extra == 'test'
23
+ Requires-Dist: pytest>=8.0.0 ; extra == 'test'
24
+ Requires-Dist: pytest-cov>=4.1.0 ; extra == 'test'
25
+ Requires-Dist: httpx>=0.27.0 ; extra == 'test'
26
+ Requires-Python: >=3.12
27
+ Provides-Extra: aws
28
+ Provides-Extra: dev
29
+ Provides-Extra: test
30
+ Description-Content-Type: text/markdown
31
+
32
+ # RAJA
33
+ ![CI](https://github.com/quiltdata/raja/workflows/CI/badge.svg)
34
+ ![Integration Tests](https://github.com/quiltdata/raja/workflows/Integration%20Tests/badge.svg)
35
+ ![Coverage](https://codecov.io/gh/quiltdata/raja/branch/main/graph/badge.svg)
36
+
37
+ **Resource Authorization JWT Authority** - Compile Cedar policies into JWT tokens for deterministic authorization.
38
+
39
+ ## What is RAJA?
40
+
41
+ RAJA compiles Cedar authorization policies into JWT tokens with explicit scopes. This means:
42
+
43
+ - Authorization decisions are **deterministic** (same token + request = same result)
44
+ - Tokens are **transparent** (you can see exactly what permissions are granted)
45
+ - Enforcement is **fast** (simple scope checking, no policy evaluation)
46
+
47
+ ## Quick Start
48
+
49
+ ### Installation
50
+
51
+ ```bash
52
+ git clone https://github.com/quiltdata/raja.git
53
+ cd raja
54
+ uv sync
55
+ ```
56
+
57
+ ### Deploy to AWS (Control Plane)
58
+
59
+ ```bash
60
+ # Deploy infrastructure
61
+ poe cdk-deploy --all
62
+
63
+ # Load Cedar policies
64
+ python scripts/load_policies.py
65
+
66
+ # Compile policies to scopes
67
+ export RAJA_API_URL="https://your-api.execute-api.us-east-1.amazonaws.com/prod"
68
+ python scripts/invoke_compiler.py
69
+ ```
70
+
71
+ ### Control Plane UI
72
+
73
+ After deployment, open the API Gateway URL in your browser. The root path (`/`) renders a
74
+ simple admin UI with live data from `/principals`, `/policies`, and `/audit`.
75
+
76
+ ## How It Works
77
+
78
+ ```text
79
+ Cedar Policies → Compiler → JWT Scopes → Library Enforcement
80
+ ```
81
+
82
+ 1. **Write Cedar policies** that define who can do what
83
+ 2. **Compiler** converts policies into scope strings (e.g., `Document:doc123:read`)
84
+ 3. **Token Service** issues JWTs containing these scopes
85
+ 4. **Applications** validate tokens and check scopes locally
86
+
87
+ ## API Endpoints
88
+
89
+ When deployed to AWS, RAJA provides:
90
+
91
+ **POST /compile** - Compile Cedar policies into scopes
92
+
93
+ ```json
94
+ {}
95
+ → {"message": "Policies compiled successfully", "policies_compiled": 3}
96
+ ```
97
+
98
+ **POST /token** - Issue a JWT token
99
+
100
+ ```json
101
+ {"principal": "alice"}
102
+ → {"token": "eyJ...", "scopes": ["Document:doc123:read"]}
103
+ ```
104
+
105
+ **GET /principals** - List principals and their scopes
106
+
107
+ ```text
108
+ → {"principals": [{"principal": "alice", "scopes": [...]}]}
109
+
110
+ **GET /policies** - List Cedar policies
111
+
112
+ ```json
113
+ → {"policies": [{"policyId": "..."}]}
114
+ ```
115
+
116
+ **GET /audit** - View audit log entries
117
+ ```
118
+
119
+ ## Local Development
120
+
121
+ Use the Python library standalone (no AWS required):
122
+
123
+ ```python
124
+ from raja import AuthRequest, create_token, enforce
125
+
126
+ # Create token with scopes
127
+ token = create_token(
128
+ subject="alice",
129
+ scopes=["Document:doc123:read"],
130
+ secret="your-secret"
131
+ )
132
+
133
+ # Check authorization
134
+ decision = enforce(
135
+ token_str=token,
136
+ request=AuthRequest(resource_type="Document", resource_id="doc123", action="read"),
137
+ secret="your-secret"
138
+ )
139
+ print(decision.allowed) # True
140
+ ```
141
+
142
+ ### Run Tests
143
+
144
+ ```bash
145
+ poe test-unit # Unit tests (no AWS)
146
+ poe test # All tests
147
+ poe check-all # Format, lint, typecheck
148
+ ```
149
+
150
+ ## Scope Format
151
+
152
+ Scopes follow the pattern: `{ResourceType}:{ResourceId}:{Action}`
153
+
154
+ Examples:
155
+
156
+ - `Document:doc123:read` - Read document doc123
157
+ - `Document:*:read` - Read all documents
158
+ - `*:*:*` - Full admin access
159
+
160
+ ## Project Structure
161
+
162
+ ```text
163
+ raja/
164
+ ├── src/raja/ # Core Python library
165
+ ├── lambda_handlers/ # AWS Lambda handlers
166
+ ├── infra/ # CDK infrastructure
167
+ ├── policies/ # Sample Cedar policies
168
+ └── tests/ # Test suite
169
+ ```
170
+
171
+ ## Documentation
172
+
173
+ - **[CLAUDE.md](CLAUDE.md)** - Developer guide and architecture
174
+ - **[specs/](specs/)** - Design specifications
175
+ - **Module READMEs** - See CLAUDE.md files in subdirectories
176
+
177
+ ## Contributing
178
+
179
+ See [CLAUDE.md](CLAUDE.md) for development guidelines.
180
+
181
+ ## License
182
+
183
+ [License information to be added]
raja-0.2.0/README.md ADDED
@@ -0,0 +1,152 @@
1
+ # RAJA
2
+ ![CI](https://github.com/quiltdata/raja/workflows/CI/badge.svg)
3
+ ![Integration Tests](https://github.com/quiltdata/raja/workflows/Integration%20Tests/badge.svg)
4
+ ![Coverage](https://codecov.io/gh/quiltdata/raja/branch/main/graph/badge.svg)
5
+
6
+ **Resource Authorization JWT Authority** - Compile Cedar policies into JWT tokens for deterministic authorization.
7
+
8
+ ## What is RAJA?
9
+
10
+ RAJA compiles Cedar authorization policies into JWT tokens with explicit scopes. This means:
11
+
12
+ - Authorization decisions are **deterministic** (same token + request = same result)
13
+ - Tokens are **transparent** (you can see exactly what permissions are granted)
14
+ - Enforcement is **fast** (simple scope checking, no policy evaluation)
15
+
16
+ ## Quick Start
17
+
18
+ ### Installation
19
+
20
+ ```bash
21
+ git clone https://github.com/quiltdata/raja.git
22
+ cd raja
23
+ uv sync
24
+ ```
25
+
26
+ ### Deploy to AWS (Control Plane)
27
+
28
+ ```bash
29
+ # Deploy infrastructure
30
+ poe cdk-deploy --all
31
+
32
+ # Load Cedar policies
33
+ python scripts/load_policies.py
34
+
35
+ # Compile policies to scopes
36
+ export RAJA_API_URL="https://your-api.execute-api.us-east-1.amazonaws.com/prod"
37
+ python scripts/invoke_compiler.py
38
+ ```
39
+
40
+ ### Control Plane UI
41
+
42
+ After deployment, open the API Gateway URL in your browser. The root path (`/`) renders a
43
+ simple admin UI with live data from `/principals`, `/policies`, and `/audit`.
44
+
45
+ ## How It Works
46
+
47
+ ```text
48
+ Cedar Policies → Compiler → JWT Scopes → Library Enforcement
49
+ ```
50
+
51
+ 1. **Write Cedar policies** that define who can do what
52
+ 2. **Compiler** converts policies into scope strings (e.g., `Document:doc123:read`)
53
+ 3. **Token Service** issues JWTs containing these scopes
54
+ 4. **Applications** validate tokens and check scopes locally
55
+
56
+ ## API Endpoints
57
+
58
+ When deployed to AWS, RAJA provides:
59
+
60
+ **POST /compile** - Compile Cedar policies into scopes
61
+
62
+ ```json
63
+ {}
64
+ → {"message": "Policies compiled successfully", "policies_compiled": 3}
65
+ ```
66
+
67
+ **POST /token** - Issue a JWT token
68
+
69
+ ```json
70
+ {"principal": "alice"}
71
+ → {"token": "eyJ...", "scopes": ["Document:doc123:read"]}
72
+ ```
73
+
74
+ **GET /principals** - List principals and their scopes
75
+
76
+ ```text
77
+ → {"principals": [{"principal": "alice", "scopes": [...]}]}
78
+
79
+ **GET /policies** - List Cedar policies
80
+
81
+ ```json
82
+ → {"policies": [{"policyId": "..."}]}
83
+ ```
84
+
85
+ **GET /audit** - View audit log entries
86
+ ```
87
+
88
+ ## Local Development
89
+
90
+ Use the Python library standalone (no AWS required):
91
+
92
+ ```python
93
+ from raja import AuthRequest, create_token, enforce
94
+
95
+ # Create token with scopes
96
+ token = create_token(
97
+ subject="alice",
98
+ scopes=["Document:doc123:read"],
99
+ secret="your-secret"
100
+ )
101
+
102
+ # Check authorization
103
+ decision = enforce(
104
+ token_str=token,
105
+ request=AuthRequest(resource_type="Document", resource_id="doc123", action="read"),
106
+ secret="your-secret"
107
+ )
108
+ print(decision.allowed) # True
109
+ ```
110
+
111
+ ### Run Tests
112
+
113
+ ```bash
114
+ poe test-unit # Unit tests (no AWS)
115
+ poe test # All tests
116
+ poe check-all # Format, lint, typecheck
117
+ ```
118
+
119
+ ## Scope Format
120
+
121
+ Scopes follow the pattern: `{ResourceType}:{ResourceId}:{Action}`
122
+
123
+ Examples:
124
+
125
+ - `Document:doc123:read` - Read document doc123
126
+ - `Document:*:read` - Read all documents
127
+ - `*:*:*` - Full admin access
128
+
129
+ ## Project Structure
130
+
131
+ ```text
132
+ raja/
133
+ ├── src/raja/ # Core Python library
134
+ ├── lambda_handlers/ # AWS Lambda handlers
135
+ ├── infra/ # CDK infrastructure
136
+ ├── policies/ # Sample Cedar policies
137
+ └── tests/ # Test suite
138
+ ```
139
+
140
+ ## Documentation
141
+
142
+ - **[CLAUDE.md](CLAUDE.md)** - Developer guide and architecture
143
+ - **[specs/](specs/)** - Design specifications
144
+ - **Module READMEs** - See CLAUDE.md files in subdirectories
145
+
146
+ ## Contributing
147
+
148
+ See [CLAUDE.md](CLAUDE.md) for development guidelines.
149
+
150
+ ## License
151
+
152
+ [License information to be added]
@@ -0,0 +1,132 @@
1
+ [project]
2
+ name = "raja"
3
+ version = "0.2.0"
4
+ description = "Add your description here"
5
+ readme = "README.md"
6
+ authors = [
7
+ { name = "Dr. Ernie Prabhakar", email = "ernest@quilt.bio" }
8
+ ]
9
+ requires-python = ">=3.12"
10
+ dependencies = [
11
+ "pydantic>=2.7.0",
12
+ "PyJWT>=2.8.0",
13
+ "fastapi>=0.110.0",
14
+ "mangum>=0.17.0",
15
+ ]
16
+
17
+ [project.optional-dependencies]
18
+ dev = [
19
+ "mypy>=1.7.0",
20
+ "poethepoet>=0.24.0",
21
+ "pytest>=8.0.0",
22
+ "pytest-cov>=4.1.0",
23
+ "pytest-watch>=4.2.0",
24
+ "httpx>=0.27.0",
25
+ "ruff>=0.1.0",
26
+ "boto3-stubs[dynamodb,secretsmanager,verifiedpermissions]>=1.34.0",
27
+ ]
28
+
29
+ aws = [
30
+ "aws-cdk-lib>=2.100.0",
31
+ "boto3>=1.34.0",
32
+ "constructs>=10.0.0",
33
+ ]
34
+
35
+ test = [
36
+ "moto>=4.2.0",
37
+ "pytest>=8.0.0",
38
+ "pytest-cov>=4.1.0",
39
+ "httpx>=0.27.0",
40
+ ]
41
+
42
+ [build-system]
43
+ requires = ["uv_build>=0.9.17,<0.10.0"]
44
+ build-backend = "uv_build"
45
+
46
+ [tool.ruff]
47
+ target-version = "py312"
48
+ line-length = 100
49
+ extend-exclude = ["infra/cdk.out", "infra/cdk.out*"]
50
+
51
+ [tool.ruff.lint]
52
+ select = [
53
+ "E", # pycodestyle errors
54
+ "W", # pycodestyle warnings
55
+ "F", # pyflakes
56
+ "I", # isort
57
+ "B", # flake8-bugbear
58
+ "C4", # flake8-comprehensions
59
+ "UP", # pyupgrade
60
+ ]
61
+ ignore = []
62
+
63
+ [tool.ruff.format]
64
+ quote-style = "double"
65
+ indent-style = "space"
66
+
67
+ [tool.pytest.ini_options]
68
+ testpaths = ["tests"]
69
+ python_files = ["test_*.py"]
70
+ python_classes = ["Test*"]
71
+ python_functions = ["test_*"]
72
+ addopts = [
73
+ "--strict-markers",
74
+ "--strict-config",
75
+ "--showlocals",
76
+ ]
77
+ markers = [
78
+ "unit: Unit tests (no external dependencies)",
79
+ "integration: tests that require deployed AWS resources",
80
+ "hypothesis: tests that validate RAJA claims",
81
+ "slow: Slow-running tests",
82
+ ]
83
+
84
+ [tool.poe.tasks]
85
+ npx-verify = { cmd = "bash -lc 'command -v npx >/dev/null 2>&1 || { echo \"npx not found; install Node.js to use CDK tasks\"; exit 1; }'", help = "Verify npx is available for CDK tasks" }
86
+ format = { cmd = "ruff format src tests infra lambda_handlers", help = "Format code with ruff" }
87
+ format-check = { cmd = "ruff format src tests infra lambda_handlers --check", help = "Check formatting with ruff" }
88
+ lint-check-only = { cmd = "ruff check src tests infra lambda_handlers", help = "Lint code with ruff" }
89
+ lint = { sequence = ["format", "lint-fix", "typecheck"], help = "Format, fix lint, and run typecheck" }
90
+ lint-check = { sequence = ["format-check", "lint-check-only", "typecheck"], help = "Check formatting, lint, and typecheck" }
91
+ lint-fix = { cmd = "ruff check --fix src tests infra lambda_handlers", help = "Auto-fix lint issues" }
92
+ typecheck = { cmd = "mypy src", help = "Run type checker" }
93
+ check = { sequence = ["lint-check"], help = "Run all quality checks" }
94
+ check-all = { sequence = ["lint"], help = "Format, lint, and typecheck" }
95
+ test = { cmd = "pytest tests/ -v", help = "Run all tests" }
96
+ test-unit = { cmd = "pytest tests/unit/ -v", help = "Run unit tests only" }
97
+ test-integration = { cmd = "pytest tests/integration/ -v", help = "Run integration tests" }
98
+ test-hypothesis = { cmd = "pytest tests/hypothesis/ -v", help = "Run hypothesis validation tests" }
99
+ test-cov = { cmd = "pytest tests/ --cov=src/raja --cov-report=html --cov-report=term", help = "Run tests with coverage" }
100
+ test-watch = { cmd = "pytest-watch tests/ -- -v", help = "Run tests in watch mode" }
101
+ test-all-parallel = { parallel = ["test-unit", "test-integration"], help = "Run unit and integration tests in parallel" }
102
+ build = { cmd = "uv build", help = "Build package" }
103
+ clean = { cmd = "rm -rf dist/ build/ *.egg-info .pytest_cache .mypy_cache .ruff_cache htmlcov/", help = "Clean build artifacts" }
104
+ install = { cmd = "uv pip install -e .", help = "Install package locally" }
105
+ cdk-synth-cmd = { cmd = "cd infra && npx cdk synth", help = "Synthesize CDK stack" }
106
+ cdk-diff-cmd = { cmd = "cd infra && npx cdk diff", help = "Show CDK changes" }
107
+ cdk-deploy-cmd = { shell = "cd infra && npx cdk deploy --all --require-approval never --progress bar", help = "Deploy CDK stack" }
108
+ cdk-destroy-cmd = { cmd = "cd infra && npx cdk destroy --all --force", help = "Destroy CDK stack" }
109
+ cdk-synth = { sequence = ["npx-verify", "cdk-synth-cmd"], help = "Synthesize CDK stack" }
110
+ cdk-diff = { sequence = ["npx-verify", "cdk-diff-cmd"], help = "Show CDK changes" }
111
+ cdk-deploy = { sequence = ["npx-verify", "cdk-deploy-cmd"], help = "Deploy CDK stack" }
112
+ cdk-destroy = { sequence = ["npx-verify", "cdk-destroy-cmd"], help = "Destroy CDK stack" }
113
+ load-policies = { cmd = "python scripts/load_policies.py", help = "Load Cedar policies to AVP" }
114
+ compile-policies = { cmd = "python scripts/invoke_compiler.py", help = "Compile policies to scopes" }
115
+ seed-test-data = { cmd = "python scripts/seed_test_data.py", help = "Seed integration test principals into DynamoDB" }
116
+ docs = { cmd = "cd docs && make html", help = "Build documentation (placeholder)" }
117
+ repl = { cmd = "uv run python", help = "Start Python REPL" }
118
+ shell = { cmd = "uv run bash", help = "Start project shell" }
119
+ tag = { script = "scripts.release:create_tag", help = "Create and push a git tag for release (runs checks first)" }
120
+
121
+ [tool.mypy]
122
+ python_version = "3.12"
123
+ warn_return_any = true
124
+ warn_unused_configs = true
125
+ disallow_untyped_defs = true
126
+ disallow_any_generics = true
127
+ check_untyped_defs = true
128
+ no_implicit_optional = true
129
+ warn_redundant_casts = true
130
+ warn_unused_ignores = true
131
+ warn_no_return = true
132
+ strict_equality = true