The user wants a comprehensive design for a Domain-Specific Language (DSL) focused on "Temporal Access Control Policies."
This request involves four distinct components:
- Syntax Design: How the language looks and reads.
- Evaluation Engine: How the policies are processed and decided.
- Audit Traceability: How decisions are logged and made traceable.
- Integration Roadmap: How to implement this into an existing system.
1. Syntax Design:
- Goal: Needs to be readable by humans (perhaps policy admins) but structured enough for machines.
- Concepts: Subjects (who), Resources (what), Actions (how), and Time (when).
- Temporal nuances: Recurring schedules (9-5 M-F), absolute ranges (start date to end date), durations, specific events (e.g., "during incident #123"), constraints (e.g., "max 2 hours").
- Structure: I should propose a specific format. YAML/JSON are too verbose. A custom grammar (EBNF) or a fluent API style is better. Let's go with a declarative, block-structured syntax, similar to HashiCorp's HCL or a simplified SQL-like syntax.
- Keywords:
GRANT, DENY, SUBJECT, RESOURCE, ACTION, WHEN, DURATION, CONDITION.
2. Evaluation Engine:
- Architecture: Policy Decision Point (PDP) and Policy Information Point (PIP).
- Algorithm: Needs to handle conflicts (Deny usually overrides Allow) and merging logic.
- Temporal Logic: This is the tricky part.
- The engine needs to parse the time syntax into intervals.
- It needs the current context time (tnow).
- It needs to handle time zones correctly (crucial).
- Evaluation steps:
- Retrieve policies applicable to Subject/Resource/Action.
- Filter by time constraints.
- Calculate the decision.
- Return decision + remaining duration (useful for session tokens).
3. Audit Traceability:
- Why? Compliance (SOC2, HIPAA, GDPR) requires knowing why access was granted at a specific time.
- Mechanism: Immutable logs.
- Content: Timestamp, Subject ID, Resource ID, Decision (Allow/Deny), Policy ID (which rule triggered it), Context (IP, device).
- Advanced feature: "Proofs." Storing a hash of the policy state at the time of evaluation so the decision can be re-verified later.
4. Integration Roadmap:
- Phase 1: DSL & Parser: Write the grammar (ANTLR or similar).
- Phase 2: Core Engine: Logic implementation.
- Phase 3: Wrapper/API: gRPC/REST wrapper.
- Phase 4: Integrations: Middleware for Nginx/Kong, SDKs for Python/Go/Java.
- Phase 5: Management UI: For non-technical users to generate the DSL.
Refining the DSL (The "TACL" Language):
Let's call it "TACL" (Temporal Access Control Language).
- Feature: "Just-In-Time" (JIT) access. "I need access for 1 hour."
- Feature: "Business Hours" restrictions.
Structuring the Response:
I will organize the response into the four requested sections.
- Language Specification (TACL): Syntax, types, examples.
- Evaluation Engine (The "Temporal Resolver"): Architecture, algorithm, conflict resolution.
- Audit & Traceability: Immutable logging, cryptographic receipts.
- Integration Roadmap: Phased approach.
Self-Correction during drafting:
- Initial thought: Use simple strings for time like "9am".
- Correction: Must handle Timezones. The syntax needs explicit timezone support or rely on a configured default.
- Initial thought: Just check "Is allowed?".
- Correction: The engine should also answer "When is this allowed next?" and "How long is it valid for?" (TTL). This is vital for token issuance.
Drafting the Content:
-
Syntax: Use a C-like/block style.
POLICY "Contractor_Access"
GRANT read, write
ON resources::s3://bucket/*
TO group::contractors
WHEN (
time.between("09:00", "17:00", "America/New_York")
AND date.weekday IN [Mon, Tue, Wed, Thu, Fri]
)
MAX_DURATION 4h
REQUIRE_APPROVAL 1
-
Engine: Needs a concept of "Time Intervals" sets.
- Intersection of Policy Time and Request Time.
-
Audit: Needs "Deterministic Replay". If I look at a log from 2023, I must be able to fetch the policy version active at that exact moment to understand why it was allowed. Version Control is key here.
Let's polish the specific sections and generate the output.
This design outlines TACL (Temporal Access Control Language), a Domain-Specific Language (DSL) designed to express fine-grained authorization policies where time is a first-class citizen.
1. Syntax Design (The TACL Grammar)
The syntax is declarative, inspired by SQL and IAM policy languages, but extended with temporal logic operators. It follows a SUBJECT -> ACTION -> RESOURCE structure with a mandatory TEMPORAL clause.
Core Structure
POLICY <PolicyName>
ON <ResourcePattern>
GRANT <ActionSet>
TO <SubjectSet>
[WHERE <ContextualConstraints>]
VALID <TemporalExpression>
[CLOCK <Timezone>] // Defaults to UTC
[GRACE <Duration>]; // Extends access slightly for network latency
Temporal Expression Types
The VALID clause supports several temporal primitives:
- Absolute Interval:
FROM "2023-10-01" TO "2023-12-31"
- Recurring Schedule (Cron-like):
SCHEDULE "0 9 * * 1-5" (9 AM Mon-Fri)
- Relative/Duration:
FOR "PT2H" (Access granted for 2 hours from request time)
- JIT (Just-In-Time) Approval:
APPROVED FOR "PT4H" (Requires an approval ticket to activate for 4 hours)
- Business Hours Logic:
DURING "BusinessHours_US_East"
Example Policies
A. The "9-to-5" Contractor Policy
POLICY ContractorReadOnly
ON "s3://confidential-data/finance/*"
GRANT READ
TO role::Contractor
VALID SCHEDULE "0 9-17 * * MON-FRI"
CLOCK "America/New_York";
B. The "Break-Glass" Emergency Access
POLICY EmergencyDatabaseAccess
ON "db::production.*"
GRANT ALL
TO group::DBA
VALID APPROVED FOR "PT1H"
WHERE context.risk_score < 5;
C. The "Quarter-End" Maintenance Window
POLICY MaintenanceWindow
ON "service::payment-gateway"
GRANT WRITE, EXEC
TO role::DevOps
VALID
EVERY "0 22 * * *" // Daily at 10 PM
AND IN MONTH (Mar, Jun, Sep, Dec) // Only quarter ends
AND IN WEEKEND; // Custom calendar logic
2. Evaluation Engine
The engine acts as a Policy Decision Point (PDP). Unlike standard RBAC, evaluation is stateless regarding user sessions; time is evaluated at trequest (or projected for tfutur).
The Resolution Algorithm
- Filtering: Identify all policies where
Subject and Resource match the request.
- Context Expansion: Load environmental variables (Source IP, Device Trust, Current Risk Score).
- Temporal Intersection: This is the core differentiator.
- Input: Request Time (Tr), Policy Validity Set (Pv).
- Logic: Does exist within the allowed intervals defined by ?
Handling Timezones
The engine stores all times internally as UTC Unix Timestamps.
- Policy Clock: "America/New_York"
- Request Time: 10:00 AM EST
- Engine translates Request Time to UTC -> Verify against UTC schedule.
Output Structure
The engine returns a JSON object:
{
"decision": "PERMIT",
"policy_id": "ContractorReadOnly",
"valid_until": "2023-10-27T17:00:00Z", // When the session expires
"refresh_token_hint": "2023-10-28T09:00:00Z" // When they can access again
}
3. Audit Traceability
In temporal access control, knowing when a decision was made is as important as why. Standard logs are insufficient because the state of time changes constantly.
The "Time-Travel" Audit Log
We need an immutable ledger (e.g., AWS QLDB or a Blockchain-inspired append-only store) that captures the Evaluation Context.
Log Entry Schema:
{
"correlation_id": "uuid-1234",
"timestamp_request": "2023-10-27T14:02:00.00Z",
"decision": "GRANT",
"evaluation_snapshot": {
"active_policies": ["id-1", "id-5"],
"resolved_timezone": "UTC-4",
"calendar_exceptions": ["Holiday:None"]
},
"ttl": 25500 // Seconds until access expires
}
Replayability (Forensics)
The system must support Deterministic Replay.
- Scenario: An audit reveals a user accessed data at 5:01 PM, but the policy ended at 5:00 PM.
- Mechanism: The auditor inputs the specific
correlation_id. The engine reloads the specific policy versions active at that timestamp and re-runs the evaluation.
- Reasoning: If the result differs from the log, the system has been tampered with. If it matches, it proves the system state (e.g., a "Grace Period" of 60 seconds) justified the access.
4. Integration Roadmap
Phase 1: The Sidecar (Enforcement Layer)
- Goal: Decouple the language from the application code.
- Implementation: Deploy an Open Policy Agent (OPA) or custom Golang microservice as a sidecar.
- Integration: The application forwards auth requests to
localhost:8181/v1/data/tacl/allow.
- Benefit: Zero code changes in the legacy application; only configuration changes.
Phase 2: The JIT Provisioner
- Goal: Handle "Just-In-Time" and "Approved FOR" policies.
- Mechanism:
- User requests access via UI.
- TACL engine identifies requirement for
APPROVED tag.
- Engine triggers workflow (Slack/Email) to Manager.
- Manager approves -> TACL Engine issues a Short-Lived Credential (e.g., a signed JWT or AWS STS token) valid only for the duration specified in the policy (e.g., 1 hour).
- Integration: Integration with Identity Providers (Okta/Auth0) for the token signing.
Phase 3: The Sync Connector
- Goal: Handle Recurring Schedules (
9-5 Daily).
- Problem: Checking a schedule on every HTTP request is CPU intensive (O(n) complexity on policy count).
- Solution: A background worker "compiles" temporal policies into cacheable allow-lists.
- Action: At 8:55 AM, the worker grants the user role in the target system (e.g., adds to AWS IAM Group).
- Action: At 5:05 PM, the worker revokes the role.
- Benefit: High performance; the target system uses native RBAC, but managed dynamically by TACL.
Phase 4: IDE & Simulator
- Goal: Developer experience.
- Tooling: A VS Code plugin for TACL.
- Features:
- Syntax highlighting.
- Time Machine Slider: A UI slider allowing the dev to scrub through time (Next 24h, Next 30 days) to visualize when policies are active or inactive. This visualizes the "Effective Permission Set" over time.