惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
CXSECURITY Database RSS Feed - CXSecurity.com
K
Kaspersky official blog
A
Arctic Wolf
Attack and Defense Labs
Attack and Defense Labs
L
LINUX DO - 热门话题
N
News | PayPal Newsroom
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
L
Lohrmann on Cybersecurity
PCI Perspectives
PCI Perspectives
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
The Last Watchdog
The Last Watchdog
B
Blog RSS Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
W
WeLiveSecurity
Know Your Adversary
Know Your Adversary
博客园 - Franky
T
Tenable Blog
T
Tailwind CSS Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Help Net Security
Help Net Security
WordPress大学
WordPress大学
T
The Exploit Database - CXSecurity.com
www.infosecurity-magazine.com
www.infosecurity-magazine.com
博客园 - 司徒正美
阮一峰的网络日志
阮一峰的网络日志
D
Darknet – Hacking Tools, Hacker News & Cyber Security
H
Heimdal Security Blog
TaoSecurity Blog
TaoSecurity Blog
S
Security Affairs
J
Java Code Geeks
小众软件
小众软件
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Apple Machine Learning Research
Apple Machine Learning Research
NISL@THU
NISL@THU
O
OpenAI News
The Cloudflare Blog
月光博客
月光博客
Google Online Security Blog
Google Online Security Blog
V
V2EX
罗磊的独立博客
美团技术团队
博客园 - 三生石上(FineUI控件)
Security Latest
Security Latest
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
C
Cyber Attacks, Cyber Crime and Cyber Security
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Cyberwarzone
Cyberwarzone
L
LINUX DO - 最新话题
Hacker News - Newest:
Hacker News - Newest: "LLM"
大猫的无限游戏
大猫的无限游戏

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
Building Pre-Execution Gates: Three Architectural Patterns
Fuzentry™ · 2026-05-13 · via DEV Community

So you've decided pre-execution gates belong in your architecture. Good choice. Now you need to actually build one. The question isn't whether you need a gate, it's what shape should it take in your codebase.

There are three main patterns engineers use, and each has a different profile of complexity, flexibility, and maintainability. The right one depends on how dynamic your rules are and how much they're likely to change.

Pattern 1: Decision Table (Simple, Explicit, Limited)

This is the pattern to start with. Your rules are explicit in code, organized in a table structure, and evaluated deterministically.

The idea: define your rules as data, then write an evaluator that walks through them in order.

# Rules are data, not scattered logic
AUTHORIZATION_RULES = [
    {
        "condition": lambda action, user: (
            action["operation"] == "delete_data" and 
            user.role != "admin"
        ),
        "allowed": False,
        "reason": "Only admins can delete data"
    },
    {
        "condition": lambda action, user: (
            action["operation"] == "export_data" and 
            user.department != action["target_department"]
        ),
        "allowed": False,
        "reason": "Cannot export data across departments"
    },
    {
        "condition": lambda action, user: (
            action["operation"] == "transfer" and 
            action["amount"] > 100000 and 
            user.approval_level < 3
        ),
        "allowed": False,
        "reason": "Large transfers require higher approval level"
    }
]

class DecisionTableGate:
    def evaluate(self, action, user):
        # Walk through rules in order until one matches
        for rule in AUTHORIZATION_RULES:
            if rule["condition"](action, user):
                return {
                    "allowed": rule["allowed"],
                    "reason": rule["reason"]
                }

        # Default: allow if no rule matched
        return {"allowed": True, "reason": "No restrictions found"}

# Usage
gate = DecisionTableGate()
result = gate.evaluate(
    action={"operation": "delete_data", "target": "customer_db"},
    user=load_user("user_123")
)

if not result["allowed"]:
    audit_log.record_refusal(action, result["reason"])
    raise PermissionDenied(result["reason"])

Enter fullscreen mode Exit fullscreen mode

Strengths:

  • Rules are visible in one place, easy to understand
  • Fast to evaluate (simple list walk)
  • Easy to debug: you can see exactly which rule matched

Weaknesses:

  • Rules are hardcoded; changing them requires a redeploy
  • Order matters (first matching rule wins), which can be confusing
  • Scales poorly once you have more than 20-30 rules
  • Hard to express complex boolean logic cleanly

Use this when: You have a small, stable set of rules that rarely change. Good for early-stage projects or very specific gate scenarios.

Pattern 2: Policy Language (Flexible, Maintainable, Operational)

This is the pattern enterprises use. You define a policy format (DSL or standard like YAML), parse it at runtime, and evaluate against it. The key advantage: operators can change policies without touching code.

Here's the idea:

# policies.yaml (loaded at startup, reloadable)
policies:
  - id: admin_only_delete
    effect: Deny
    conditions:
      operation_matches: "delete.*"
      user_role_not_in: ["admin", "superuser"]
    reason: "Only admins can perform delete operations"

  - id: department_isolation
    effect: Deny
    conditions:
      operation_matches: "export.*"
      user_department_not_equals: "resource.department"
    reason: "Cannot export data outside your department"

  - id: approval_threshold
    effect: Deny
    conditions:
      operation_matches: "transfer"
      resource_amount_gt: 100000
      user_approval_level_lt: 3
    reason: "Transfers over 100k require approval level 3 or higher"

Enter fullscreen mode Exit fullscreen mode

Now your gate parses and evaluates this:

import yaml
from typing import Any, Dict

class PolicyLanguageGate:
    def __init__(self, policy_file: str):
        with open(policy_file) as f:
            self.policies = yaml.safe_load(f).get("policies", [])

    def evaluate(self, action: Dict[str, Any], user: Any) -> Dict[str, Any]:
        # Walk through policies in order
        for policy in self.policies:
            if self._matches_conditions(policy["conditions"], action, user):
                return {
                    "allowed": policy["effect"] == "Allow",
                    "policy_id": policy["id"],
                    "reason": policy["reason"]
                }

        # Default: allow if no deny policy matched
        return {"allowed": True, "reason": "No restrictions"}

    def _matches_conditions(self, conditions: Dict, action: Dict, user: Any) -> bool:
        # Each condition must match for the policy to apply
        for key, value in conditions.items():
            if not self._evaluate_condition(key, value, action, user):
                return False
        return True

    def _evaluate_condition(self, condition_type: str, condition_value: Any, 
                            action: Dict, user: Any) -> bool:
        # Helper to evaluate individual conditions
        if condition_type == "operation_matches":
            import re
            return bool(re.match(condition_value, action.get("operation", "")))
        elif condition_type == "user_role_not_in":
            return user.role not in condition_value
        elif condition_type == "user_department_not_equals":
            # Handle reference to resource properties
            target = condition_value.replace("resource.", "")
            return user.department != action.get(target)
        elif condition_type == "resource_amount_gt":
            return action.get("amount", 0) > condition_value
        elif condition_type == "user_approval_level_lt":
            return user.approval_level < condition_value
        return True

# Usage
gate = PolicyLanguageGate("policies.yaml")
result = gate.evaluate(action, user)

if not result["allowed"]:
    audit_log.record_refusal(
        action, 
        result["reason"],
        policy_id=result.get("policy_id")
    )
    raise PermissionDenied(result["reason"])

Enter fullscreen mode Exit fullscreen mode

Strengths:

  • Policies live outside code; update them without redeploying
  • Policies are human-readable; easier to review and audit
  • Scales well to 100+ rules
  • Each policy is clearly documented with its reason

Weaknesses:

  • More moving parts; another system to monitor and maintain
  • Policy language needs documentation so operators understand syntax
  • Debugging can be harder if operators write confusing policies
  • Need a reload mechanism (watch the file, or expose an API)

Use this when: You have dozens of rules that change frequently, or when non-engineers (security/compliance teams) need to manage rules.

Pattern 3: Policy Engine (Powerful, Complex, Enterprise)

This is what large organizations use. You adopt or build a policy engine that handles complex boolean logic, role hierarchies, attribute-based access control (ABAC), and caching.

The idea: separate your policy language from its evaluation. Use a mature engine that handles the hard parts.

Here's a simplified example using an open-source style approach:

from typing import Dict, List, Any

class Attribute:
    """Represents a value that can be compared in policy expressions"""
    def __init__(self, name: str, value: Any):
        self.name = name
        self.value = value

class PolicyEngine:
    """
    Evaluates policies written in a structured language.
    Handles attributes, logical operators, and caching.
    """

    def __init__(self):
        self.policies: List[Dict] = []
        self.attribute_cache: Dict = {}

    def add_policy(self, policy: Dict):
        """Register a policy with the engine"""
        self.policies.append(policy)

    def evaluate(self, action: Dict, user: Any, resource: Dict = None) -> Dict:
        """
        Evaluate all policies against the request context.
        Returns the first matching Deny, or Allow if no Deny matched.
        """
        context = self._build_context(action, user, resource)

        for policy in self.policies:
            if self._evaluate_statement(policy.get("statement"), context):
                effect = policy.get("effect", "Allow")
                return {
                    "allowed": effect == "Allow",
                    "policy_id": policy.get("id"),
                    "reason": policy.get("reason"),
                    "matched_conditions": policy.get("statement", [])
                }

        return {"allowed": True, "reason": "No applicable policies"}

    def _build_context(self, action: Dict, user: Any, resource: Dict) -> Dict:
        """
        Build evaluation context from action, user, and resource.
        This is what the policy expressions evaluate against.
        """
        return {
            "action": action,
            "user": {
                "id": user.id,
                "role": user.role,
                "department": user.department,
                "approval_level": user.approval_level,
                "groups": user.groups
            },
            "resource": resource or {},
            "time": self._get_current_time()
        }

    def _evaluate_statement(self, statement: List[Dict], context: Dict) -> bool:
        """
        Evaluate a statement (list of conditions).
        All conditions must be true for the statement to match.
        """
        if not statement:
            return False

        for condition in statement:
            if not self._evaluate_condition(condition, context):
                return False
        return True

    def _evaluate_condition(self, condition: Dict, context: Dict) -> bool:
        """Evaluate a single condition against the context"""
        operator = condition.get("operator", "equals")
        attribute = condition.get("attribute")
        value = condition.get("value")

        # Navigate nested attributes (e.g., "user.role")
        context_value = self._get_attribute(attribute, context)

        if operator == "equals":
            return context_value == value
        elif operator == "not_equals":
            return context_value != value
        elif operator == "in":
            return context_value in value
        elif operator == "not_in":
            return context_value not in value
        elif operator == "greater_than":
            return context_value > value
        elif operator == "less_than":
            return context_value < value
        elif operator == "matches_pattern":
            import re
            return bool(re.match(value, str(context_value)))
        return False

    def _get_attribute(self, attribute_path: str, context: Dict) -> Any:
        """Navigate dot-notation attributes (e.g., 'user.role')"""
        parts = attribute_path.split(".")
        current = context
        for part in parts:
            if isinstance(current, dict):
                current = current.get(part)
            else:
                current = getattr(current, part, None)
        return current

    def _get_current_time(self) -> str:
        from datetime import datetime
        return datetime.utcnow().isoformat()

# Define policies as structured data
policies = [
    {
        "id": "deny_delete_non_admin",
        "effect": "Deny",
        "reason": "Only admins can delete",
        "statement": [
            {"attribute": "action.operation", "operator": "equals", "value": "delete"},
            {"attribute": "user.role", "operator": "not_in", "value": ["admin", "superuser"]}
        ]
    },
    {
        "id": "deny_large_transfer_low_approval",
        "effect": "Deny",
        "reason": "Large transfers require approval level 3+",
        "statement": [
            {"attribute": "action.operation", "operator": "equals", "value": "transfer"},
            {"attribute": "resource.amount", "operator": "greater_than", "value": 100000},
            {"attribute": "user.approval_level", "operator": "less_than", "value": 3}
        ]
    }
]

# Usage
engine = PolicyEngine()
for policy in policies:
    engine.add_policy(policy)

result = engine.evaluate(action, user, resource)
if not result["allowed"]:
    audit_log.record_refusal(action, result["reason"], policy_id=result["policy_id"])
    raise PermissionDenied(result["reason"])

Enter fullscreen mode Exit fullscreen mode

Strengths:

  • Handles complex boolean logic cleanly
  • Policies are data, not code or YAML magic
  • Easy to test (just pass in different contexts)
  • Scales to enterprise complexity (thousands of policies)
  • Caching support for performance

Weaknesses:

  • Most complex of the three patterns
  • Requires careful design of context and attributes
  • Testing policies is its own discipline
  • Overkill for simple scenarios

Use this when: You have complex permission models, role hierarchies, or hundreds of policies that interact with each other. When policy evaluation is a core part of your business logic.

Choosing the Right Pattern

Here's how to think about it:

  • Start with Pattern 1 (Decision Table) if you have fewer than 20 rules, they're unlikely to change, and the logic is straightforward.

  • Move to Pattern 2 (Policy Language) when rules change frequently enough that redeploys become annoying, or when non-engineers need to manage rules.

  • Consider Pattern 3 (Policy Engine) when you have role hierarchies, attribute-based access control, or policies that need to interact with each other in complex ways.

The pattern you choose is an investment decision. A policy engine is more powerful but requires more infrastructure. A decision table is simpler but brittle at scale. Most teams start with a decision table and graduate to a policy language as complexity grows.

The Pattern That Matters Most

The specific pattern matters less than the principle: separate your rules from your logic. Whether you use YAML files, a DSL, or a full policy engine, the goal is the same. Make it possible to change authorization rules without redeploying your application. Make it possible to see all your rules in one place. Make it possible to reason about whether a given action is allowed.

The team at Tailored Techworks builds these patterns at scale, often helping organizations graduate from scattered authorization logic to a unified gate architecture. If you're wrestling with how to structure this in your systems, it's worth learning from how production systems do it.

Want to dive deeper into policy architecture and governance patterns? Connect with Tailored Techworks on LinkedIn: https://www.linkedin.com/company/tailored-techworks/ - they share detailed breakdowns of architecture decisions and their tradeoffs in real systems.