CLI Reference
CLI Reference
Section titled “CLI Reference”This document provides comprehensive reference for the Sentrie command-line interface.
Overview
Section titled “Overview”Sentrie provides a command-line interface for running policy servers and managing policy packs. The CLI is built on top of the cling framework and provides a consistent, user-friendly experience.
Global Options
Section titled “Global Options”All Sentrie commands support these global options:
| Option | Description | Default |
|---|---|---|
--help, -h | Show help information | - |
--version, -v | Show version information | - |
--debug | Enable debug logging | false |
--log-level | Set log level (DEBUG, INFO, WARN, ERROR) | INFO |
Commands
Section titled “Commands”Start the Sentrie HTTP server to evaluate policies.
Syntax
Section titled “Syntax”sentrie serve [OPTIONS]Options
Section titled “Options”| Option | Type | Default | Description |
|---|---|---|---|
--port | int | 7529 | Port to listen on |
--pack-location | string | ./ | Directory containing policy files |
--listen | []string | ["local"] | Address(es) to listen on |
Examples
Section titled “Examples”# Start server on default portsentrie serve
# Start server on custom portsentrie serve --port 8080
# Start server with custom pack locationsentrie serve --pack-location /path/to/policies
# Start server on specific addressessentrie serve --listen 0.0.0.0 --listen 127.0.0.1
# Start server with debug loggingsentrie serve --debug --log-level DEBUGEnvironment Variables
Section titled “Environment Variables”The serve command respects these environment variables:
| Variable | Description | Default |
|---|---|---|
SENTRIE_DEBUG | Enable debug logging | false |
SENTRIE_LOG_LEVEL | Log level | INFO |
SENTRIE_PORT | Default port | 7529 |
Server Behavior
Section titled “Server Behavior”When you start the server, it will:
- Load the policy pack from the specified location
- Parse and validate all
.sentriefiles - Create an index of policies and rules
- Start the HTTP server on the specified port
- Log startup information and any errors
Pack Loading
Section titled “Pack Loading”The server looks for policy files in the specified directory:
- Policy files:
*.sentrie- Sentrie policy files - Pack file:
sentrie.pack.toml- Pack metadata (optional) - JavaScript modules:
*.js- JavaScript modules forusestatements
Error Handling
Section titled “Error Handling”If the server encounters errors during startup:
- Policy parsing errors: Server will not start, errors are logged
- Pack loading errors: Server will not start, errors are logged
- Port binding errors: Server will not start, error is logged
- Runtime errors: Server continues running, errors are logged
Graceful Shutdown
Section titled “Graceful Shutdown”The server supports graceful shutdown:
- SIGINT (Ctrl+C): Graceful shutdown
- SIGTERM: Graceful shutdown
- SIGKILL: Immediate shutdown
HTTP API
Section titled “HTTP API”When the server is running, it provides a REST API for policy evaluation.
Base URL
Section titled “Base URL”http://localhost:7529Endpoints
Section titled “Endpoints”Decision Execution
Section titled “Decision Execution”POST /decision/{namespace}/{policy}/{rule}?{runconfig_params}
Execute a specific rule with the provided facts.
Path Parameters
Section titled “Path Parameters”namespace: The namespace containing the policy (can contain multiple segments separated by ’/’)policy: The policy name (second to last segment in the path)rule: The rule name to execute (last segment in the path)
Path Structure
Section titled “Path Structure”The path follows this pattern: /decision/{namespace}/{policy}/{rule} where:
- The last segment is the rule name
- The second to last segment is the policy name
- Everything before that is the namespace (can contain multiple
/-separated segments)
Examples
Section titled “Examples”/decision/sh/sentra/auth/v1/user/allow→ namespace:sh/sentra/auth/v1, policy:user, rule:allow/decision/org/department/team/policy/rule→ namespace:org/department/team, policy:policy, rule:rule
Query Parameters
Section titled “Query Parameters”runconfig_params: Optional configuration parameters for rule execution
Request Body
Section titled “Request Body”The request body should be a JSON object containing the facts to evaluate:
{ "user": { "id": "user123", "role": "admin" }, "resource": { "id": "resource456", "owner": "user123" }}Response
Section titled “Response”The response is a JSON object containing the decision and any attachments:
{ "decision": true, "attachments": { "reason": "User is admin", "timestamp": "2025-01-27T10:00:00Z" }}Error Responses
Section titled “Error Responses”400 Bad Request
{ "error": "Invalid request body", "message": "Expected JSON object"}404 Not Found
{ "error": "Policy not found", "message": "Policy 'com/example/auth/user' not found"}500 Internal Server Error
{ "error": "Policy evaluation failed", "message": "Error in rule 'allow': division by zero"}Example Requests
Section titled “Example Requests”Simple Authorization
Section titled “Simple Authorization”curl -X POST "http://localhost:7529/decision/com/example/auth/user/allow" \ -H "Content-Type: application/json" \ -d '{"user": {"id": "user123", "role": "admin"}}'Resource Access Control
Section titled “Resource Access Control”curl -X POST "http://localhost:7529/decision/com/example/resources/document/canRead" \ -H "Content-Type: application/json" \ -d '{ "user": {"id": "user123", "role": "user"}, "document": {"id": "doc456", "owner": "user123"} }'Complex Policy with Attachments
Section titled “Complex Policy with Attachments”curl -X POST "http://localhost:7529/decision/com/example/billing/pricing/calculatePrice" \ -H "Content-Type: application/json" \ -d '{ "user": {"id": "user123", "isPremium": true}, "product": {"id": "prod789", "price": 100.0} }'Configuration
Section titled “Configuration”Pack Configuration
Section titled “Pack Configuration”Create a sentrie.pack.toml file in your pack directory:
schema_version = "0.1.0"name = "my-policy-pack"version = "1.0.0"description = "My policy pack"license = "MIT"repository = "https://github.com/myorg/my-policy-pack"
[engines]sentrie = "0.1.0"
[authors]"John Doe" = "john@example.com"
[permissions]fs_read = ["/etc/passwd"]net = ["http://example.com"]
[metadata]"custom" = "value"Environment Configuration
Section titled “Environment Configuration”Set environment variables for configuration:
export SENTRIE_DEBUG=trueexport SENTRIE_LOG_LEVEL=DEBUGexport SENTRIE_PORT=8080sentrie serveLogging Configuration
Section titled “Logging Configuration”Configure logging levels and output:
# Debug loggingsentrie serve --debug
# Custom log levelsentrie serve --log-level WARN
# Environment variableexport SENTRIE_LOG_LEVEL=ERRORsentrie serveTroubleshooting
Section titled “Troubleshooting”Common Issues
Section titled “Common Issues”Port Already in Use
Section titled “Port Already in Use”# Error: port 7529 is already in use# Solution: Use a different portsentrie serve --port 8080Policy Not Found
Section titled “Policy Not Found”# Error: Policy 'com/example/auth/user' not found# Solution: Check namespace and policy names# Make sure the policy file exists and is validInvalid Policy Syntax
Section titled “Invalid Policy Syntax”# Error: Policy parsing failed# Solution: Check the policy file syntax# Use --debug for detailed error messagesPack Loading Failed
Section titled “Pack Loading Failed”# Error: Pack loading failed# Solution: Check the pack directory exists# Verify sentrie.pack.toml is validDebug Mode
Section titled “Debug Mode”Enable debug mode for detailed logging:
sentrie serve --debug --log-level DEBUGThis will show:
- Policy loading progress
- Detailed error messages
- Request/response logging
- Performance metrics
Performance Tuning
Section titled “Performance Tuning”Memory Usage
Section titled “Memory Usage”The server uses memory for:
- Policy index
- JavaScript VM pools
- Call memoization cache
- Module bindings
Monitor memory usage and adjust cache sizes if needed.
Concurrent Requests
Section titled “Concurrent Requests”The server handles concurrent requests efficiently:
- Each request gets its own execution context
- JavaScript VMs are pooled for reuse
- Policy evaluation is stateless
Examples
Section titled “Examples”Complete Example
Section titled “Complete Example”- Create a policy pack:
mkdir my-policy-packcd my-policy-pack- Create a policy file:
namespace com/example/auth
policy user { rule allow = default false when user.role == "admin" { yield true }
export decision of allow}- Create a pack file:
schema_version = "0.1.0"name = "my-policy-pack"version = "1.0.0"description = "My policy pack"
[engines]sentrie = "0.1.0"- Start the server:
sentrie serve --pack-location . --port 8080- Test the policy:
curl -X POST "http://localhost:8080/decision/com/example/auth/user/allow" \ -H "Content-Type: application/json" \ -d '{"user": {"role": "admin"}}'Production Deployment
Section titled “Production Deployment”For production deployment:
- Use a reverse proxy (nginx, Apache)
- Enable HTTPS with SSL certificates
- Set up monitoring and logging
- Configure load balancing for high availability
- Use environment variables for configuration
- Set up health checks for the API
Docker Deployment
Section titled “Docker Deployment”FROM golang:1.25-alpine AS builderWORKDIR /appCOPY . .RUN go build -o sentrie .
FROM alpine:latestRUN apk --no-cache add ca-certificatesWORKDIR /root/COPY --from=builder /app/sentrie .COPY --from=builder /app/policies ./policiesEXPOSE 7529CMD ["./sentrie", "serve", "--pack-location", "./policies"]Best Practices
Section titled “Best Practices”1. Use Descriptive Names
Section titled “1. Use Descriptive Names”# Goodsentrie serve --pack-location ./production-policies
# Badsentrie serve --pack-location ./p2. Organize Policies
Section titled “2. Organize Policies”policies/├── auth/│ ├── user.sentrie│ └── admin.sentrie├── billing/│ └── pricing.sentrie└── sentrie.pack.toml3. Use Environment Variables
Section titled “3. Use Environment Variables”export SENTRIE_LOG_LEVEL=WARNexport SENTRIE_PORT=8080sentrie serve --pack-location ./policies4. Monitor Performance
Section titled “4. Monitor Performance”# Enable debug logging to monitor performancesentrie serve --debug --log-level DEBUG5. Handle Errors Gracefully
Section titled “5. Handle Errors Gracefully”# Check exit codesif ! sentrie serve; then echo "Failed to start server" exit 1fi