Skip to content

CLI Reference

This document provides comprehensive reference for the Sentrie command-line interface.

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.

All Sentrie commands support these global options:

OptionDescriptionDefault
--help, -hShow help information-
--version, -vShow version information-
--debugEnable debug loggingfalse
--log-levelSet log level (DEBUG, INFO, WARN, ERROR)INFO

Start the Sentrie HTTP server to evaluate policies.

Terminal window
sentrie serve [OPTIONS]
OptionTypeDefaultDescription
--portint7529Port to listen on
--pack-locationstring./Directory containing policy files
--listen[]string["local"]Address(es) to listen on
Terminal window
# Start server on default port
sentrie serve
# Start server on custom port
sentrie serve --port 8080
# Start server with custom pack location
sentrie serve --pack-location /path/to/policies
# Start server on specific addresses
sentrie serve --listen 0.0.0.0 --listen 127.0.0.1
# Start server with debug logging
sentrie serve --debug --log-level DEBUG

The serve command respects these environment variables:

VariableDescriptionDefault
SENTRIE_DEBUGEnable debug loggingfalse
SENTRIE_LOG_LEVELLog levelINFO
SENTRIE_PORTDefault port7529

When you start the server, it will:

  1. Load the policy pack from the specified location
  2. Parse and validate all .sentrie files
  3. Create an index of policies and rules
  4. Start the HTTP server on the specified port
  5. Log startup information and any errors

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 for use statements

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

The server supports graceful shutdown:

  • SIGINT (Ctrl+C): Graceful shutdown
  • SIGTERM: Graceful shutdown
  • SIGKILL: Immediate shutdown

When the server is running, it provides a REST API for policy evaluation.

http://localhost:7529

POST /decision/{namespace}/{policy}/{rule}?{runconfig_params}

Execute a specific rule with the provided facts.

  • 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)

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)
  • /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
  • runconfig_params: Optional configuration parameters for rule execution

The request body should be a JSON object containing the facts to evaluate:

{
"user": {
"id": "user123",
"role": "admin"
},
"resource": {
"id": "resource456",
"owner": "user123"
}
}

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"
}
}

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"
}
Terminal window
curl -X POST "http://localhost:7529/decision/com/example/auth/user/allow" \
-H "Content-Type: application/json" \
-d '{"user": {"id": "user123", "role": "admin"}}'
Terminal window
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"}
}'
Terminal window
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}
}'

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"

Set environment variables for configuration:

Terminal window
export SENTRIE_DEBUG=true
export SENTRIE_LOG_LEVEL=DEBUG
export SENTRIE_PORT=8080
sentrie serve

Configure logging levels and output:

Terminal window
# Debug logging
sentrie serve --debug
# Custom log level
sentrie serve --log-level WARN
# Environment variable
export SENTRIE_LOG_LEVEL=ERROR
sentrie serve
Terminal window
# Error: port 7529 is already in use
# Solution: Use a different port
sentrie serve --port 8080
Terminal window
# Error: Policy 'com/example/auth/user' not found
# Solution: Check namespace and policy names
# Make sure the policy file exists and is valid
Terminal window
# Error: Policy parsing failed
# Solution: Check the policy file syntax
# Use --debug for detailed error messages
Terminal window
# Error: Pack loading failed
# Solution: Check the pack directory exists
# Verify sentrie.pack.toml is valid

Enable debug mode for detailed logging:

Terminal window
sentrie serve --debug --log-level DEBUG

This will show:

  • Policy loading progress
  • Detailed error messages
  • Request/response logging
  • Performance metrics

The server uses memory for:

  • Policy index
  • JavaScript VM pools
  • Call memoization cache
  • Module bindings

Monitor memory usage and adjust cache sizes if needed.

The server handles concurrent requests efficiently:

  • Each request gets its own execution context
  • JavaScript VMs are pooled for reuse
  • Policy evaluation is stateless
  1. Create a policy pack:
Terminal window
mkdir my-policy-pack
cd my-policy-pack
  1. Create a policy file:
auth.sentrie
namespace com/example/auth
policy user {
rule allow = default false when user.role == "admin" {
yield true
}
export decision of allow
}
  1. Create a pack file:
sentrie.pack.toml
schema_version = "0.1.0"
name = "my-policy-pack"
version = "1.0.0"
description = "My policy pack"
[engines]
sentrie = "0.1.0"
  1. Start the server:
Terminal window
sentrie serve --pack-location . --port 8080
  1. Test the policy:
Terminal window
curl -X POST "http://localhost:8080/decision/com/example/auth/user/allow" \
-H "Content-Type: application/json" \
-d '{"user": {"role": "admin"}}'

For production deployment:

  1. Use a reverse proxy (nginx, Apache)
  2. Enable HTTPS with SSL certificates
  3. Set up monitoring and logging
  4. Configure load balancing for high availability
  5. Use environment variables for configuration
  6. Set up health checks for the API
FROM golang:1.25-alpine AS builder
WORKDIR /app
COPY . .
RUN go build -o sentrie .
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=builder /app/sentrie .
COPY --from=builder /app/policies ./policies
EXPOSE 7529
CMD ["./sentrie", "serve", "--pack-location", "./policies"]
Terminal window
# Good
sentrie serve --pack-location ./production-policies
# Bad
sentrie serve --pack-location ./p
policies/
├── auth/
│ ├── user.sentrie
│ └── admin.sentrie
├── billing/
│ └── pricing.sentrie
└── sentrie.pack.toml
production.sh
export SENTRIE_LOG_LEVEL=WARN
export SENTRIE_PORT=8080
sentrie serve --pack-location ./policies
Terminal window
# Enable debug logging to monitor performance
sentrie serve --debug --log-level DEBUG
Terminal window
# Check exit codes
if ! sentrie serve; then
echo "Failed to start server"
exit 1
fi