{"id":6509,"date":"2026-04-17T07:35:44","date_gmt":"2026-04-16T23:35:44","guid":{"rendered":"https:\/\/www.babel.cc\/blog\/?p=6509"},"modified":"2026-04-17T07:35:44","modified_gmt":"2026-04-16T23:35:44","slug":"%e4%bc%81%e4%b8%9a%e4%ba%91%e7%9b%98%e6%9d%83%e9%99%90%e4%bd%93%e7%b3%bb%e8%ae%be%e8%ae%a1%ef%bc%9arbac%e5%88%b0abac%e7%9a%84%e6%bc%94%e8%bf%9b%e8%b7%af%e5%be%84%e4%b8%8e%e5%ae%9e%e6%88%98%e5%ae%9e","status":"publish","type":"post","link":"https:\/\/www.babel.cc\/blog\/?p=6509","title":{"rendered":"\u4f01\u4e1a\u4e91\u76d8\u6743\u9650\u4f53\u7cfb\u8bbe\u8ba1\uff1aRBAC\u5230ABAC\u7684\u6f14\u8fdb\u8def\u5f84\u4e0e\u5b9e\u6218\u5b9e\u73b0"},"content":{"rendered":"<p>\u4f5c\u8005\uff1a\u867e\u6761 | \u5df4\u522b\u9e1f\u4f01\u4e1a\u4e91\u76d8\u6280\u672f\u56e2\u961f<\/p>\n<hr \/>\n<p>\u53bb\u5e74\u79cb\u5929\uff0c\u67d0\u4e0a\u5e02\u516c\u53f8\u7ecf\u5386\u4e86\u4e00\u573a\u81f3\u4eca\u8ba9\u4eba\u5fc3\u6709\u4f59\u60b8\u7684\u5b89\u5168\u4e8b\u6545\u3002<\/p>\n<p>\u9500\u552e\u603b\u76d1\u901a\u8fc7\u4f01\u4e1a\u4e91\u76d8\u628a\u4e00\u4efd\u6807\u6ce8&#8221;\u7edd\u5bc6&#8221;\u7684\u4e09\u5b63\u5ea6\u8d22\u62a5\u5206\u4eab\u7ed9\u4e86\u6838\u5fc3\u4ee3\u7406\u5546\u2014\u2014\u4ed6\u672c\u610f\u662f\u8ba9\u5bf9\u65b9\u63d0\u524d\u4e86\u89e3\u4ea7\u54c1\u7ebf\u5e03\u5c40\uff0c\u914d\u5408Q4\u62db\u6807\u3002\u7ed3\u679c\u8fd9\u4efd\u6587\u4ef6\u4e09\u5929\u540e\u51fa\u73b0\u5728\u4e86\u7ade\u4e89\u5bf9\u624b\u7684\u5b98\u7f51\u6295\u8d44\u8005\u5173\u7cfb\u9875\u9762\u4e0a\u3002<\/p>\n<p>\u4e8b\u540e\u6eaf\u6e90\u8ba9\u4eba\u810a\u80cc\u53d1\u51c9\uff1a<strong>\u8fd9\u4efd\u6587\u4ef6\u7684\u6743\u9650\u914d\u7f6e\uff0c\u672c\u6765\u5e94\u8be5\u53ea\u6709\u8463\u4e8b\u4f1a\u6210\u5458\u548c\u8d22\u62a5\u5236\u4f5c\u56e2\u961f\u53ef\u89c1<\/strong>\u3002\u95ee\u9898\u51fa\u5728\u54ea\uff1f\u6743\u9650\u914d\u7f6e\u754c\u9762\u91cc\uff0c\u4e00\u4e2a\u540d\u53eb&#8221;\u9ad8\u7ba1&#8221;\u7684\u89d2\u8272\u5305\u542b\u4e86\u4e8c\u5341\u591a\u9879\u5b50\u6743\u9650\uff0c\u5176\u4e2d\u4e00\u9879\u662f&#8221;\u67e5\u770b\u6240\u6709\u8d22\u52a1\u62a5\u8868&#8221;\u2014\u2014\u8fd9\u662f\u4e09\u5e74\u524d\u7cfb\u7edf\u4e0a\u7ebf\u65f6\uff0c\u4e3a\u4e86&#8221;\u7528\u8d77\u6765\u65b9\u4fbf&#8221;\u800c\u8bbe\u7f6e\u7684\u9ed8\u8ba4\u503c\uff0c\u4ece\u6765\u6ca1\u4eba\u52a8\u8fc7\u3002<\/p>\n<p>\u9500\u552e\u603b\u76d1\u7684\u8d26\u53f7\u88ab\u5206\u914d\u4e86&#8221;\u9ad8\u7ba1&#8221;\u89d2\u8272\u3002\u8fd9\u4e2a\u89d2\u8272\u672c\u4e0d\u8be5\u51fa\u73b0\u5728\u9500\u552e\u5e8f\u5217\u91cc\uff0c\u4f46IT\u7ba1\u7406\u5458\u56fe\u7701\u4e8b\uff0c\u7ed9\u6574\u4e2a\u7ba1\u7406\u5c42\u90fd\u5f00\u4e86\u8fd9\u4e2a\u89d2\u8272\u6743\u9650\u3002<\/p>\n<p>\u8fd9\u4e0d\u662f\u5b64\u7acb\u4e8b\u4ef6\u3002\u6839\u636eVerizon\u53d1\u5e03\u7684\u300a2024\u5e74\u6570\u636e\u6cc4\u9732\u8c03\u67e5\u62a5\u544a\u300b\uff0c\u8d85\u8fc7<strong>65%<\/strong>\u7684\u4f01\u4e1a\u6570\u636e\u6cc4\u9732\u4e8b\u4ef6\u6839\u6e90\u5728\u4e8e<strong>\u6743\u9650\u914d\u7f6e\u9519\u8bef\u6216\u6743\u9650\u8fc7\u5ea6\u5bbd\u677e<\/strong>\u3002\u800c\u5728\u4f01\u4e1a\u4e91\u76d8\u573a\u666f\u4e0b\uff0c\u8fd9\u4e2a\u95ee\u9898\u5c24\u4e3a\u7a81\u51fa\uff1a\u6587\u4ef6\u6570\u91cf\u591a\u3001\u7528\u6237\u5c42\u7ea7\u591a\u3001\u5171\u4eab\u5173\u7cfb\u590d\u6742\uff0c\u4f20\u7edf\u7684&#8221;\u7ed9\u7528\u6237\u76f4\u63a5\u5206\u914d\u6587\u4ef6\u6743\u9650&#8221;\u6a21\u5f0f\u5728\u8d85\u8fc7500\u4eba\u89c4\u6a21\u540e\u5c31\u4f1a\u5f7b\u5e95\u5931\u63a7\u3002<\/p>\n<p>\u672c\u6587\u4ece\u4e00\u6b21\u771f\u5b9e\u4e8b\u6545\u51fa\u53d1\uff0c\u7cfb\u7edf\u62c6\u89e3\u4f01\u4e1a\u4e91\u76d8\u6743\u9650\u4f53\u7cfb\u4eceRBAC\u5230ABAC\u7684\u6f14\u8fdb\u8def\u5f84\uff0c\u63d0\u4f9b\u53ef\u76f4\u63a5\u843d\u5730\u7684\u5b9e\u73b0\u65b9\u6848\u3002<\/p>\n<hr \/>\n<h2>\u4e00\u3001\u4e3a\u4ec0\u4e48RBAC\u6491\u4e0d\u4f4f\u4f01\u4e1a\u4e91\u76d8\u7684\u6743\u9650\u590d\u6742\u5ea6<\/h2>\n<p>RBAC\uff08Role-Based Access Control\uff0c\u57fa\u4e8e\u89d2\u8272\u7684\u8bbf\u95ee\u63a7\u5236\uff09\u662f\u6743\u9650\u7ba1\u7406\u9886\u57df\u7684&#8221;Hello World&#8221;\u3002\u5b83\u7684\u6838\u5fc3\u601d\u60f3\u6781\u5ea6\u4f18\u96c5\uff1a<strong>\u7528\u6237\u4e0d\u76f4\u63a5\u6301\u6709\u6743\u9650\uff0c\u800c\u662f\u901a\u8fc7\u89d2\u8272\u95f4\u63a5\u6301\u6709\u6743\u9650<\/strong>\u3002<\/p>\n<pre><code class=\"language-sql\">-- \u7ecf\u5178RBAC\u4e09\u8868\u7ed3\u6784\r\nCREATE TABLE users (\r\n    id BIGINT PRIMARY KEY,\r\n    username VARCHAR(64),\r\n    department VARCHAR(128)\r\n);\r\n\r\nCREATE TABLE roles (\r\n    id BIGINT PRIMARY KEY,\r\n    role_name VARCHAR(64),\r\n    description TEXT\r\n);\r\n\r\nCREATE TABLE user_roles (\r\n    user_id BIGINT,\r\n    role_id BIGINT,\r\n    PRIMARY KEY (user_id, role_id)\r\n);\r\n\r\nCREATE TABLE role_permissions (\r\n    role_id BIGINT,\r\n    resource_type VARCHAR(32),  -- 'file', 'folder', 'module'\r\n    resource_id VARCHAR(128),    -- \u8d44\u6e90\u6807\u8bc6\r\n    action VARCHAR(32),          -- 'read', 'write', 'delete', 'admin'\r\n    PRIMARY KEY (role_id, resource_type, resource_id, action)\r\n);\r\n<\/code><\/pre>\n<p>RBAC\u7684\u8bc4\u4f30\u903b\u8f91\u975e\u5e38\u76f4\u63a5\uff1a<\/p>\n<pre><code class=\"language-python\">def check_permission_rbac(user_id, resource_id, action):\r\n    # 1. \u67e5\u627e\u7528\u6237\u7684\u6240\u6709\u89d2\u8272\r\n    roles = db.query(&quot;SELECT role_id FROM user_roles WHERE user_id = %s&quot;, user_id)\r\n\r\n    # 2. \u68c0\u67e5\u4efb\u4f55\u4e00\u4e2a\u89d2\u8272\u662f\u5426\u6709\u6743\u9650\r\n    for role in roles:\r\n        has_perm = db.query(&quot;&quot;&quot;\r\n            SELECT 1 FROM role_permissions \r\n            WHERE role_id = %s \r\n            AND resource_id = %s \r\n            AND action IN (%s, 'admin')\r\n        &quot;&quot;&quot;, role.id, resource_id, action)\r\n        if has_perm:\r\n            return True\r\n\r\n    return False  # \u515c\u5e95\u62d2\u7edd\r\n<\/code><\/pre>\n<p>\u770b\u8d77\u6765\u5f88\u7f8e\u597d\u3002\u4f46\u5f53\u4f01\u4e1a\u4e91\u76d8\u7684\u89c4\u6a21\u8d85\u8fc7\u67d0\u4e2a\u4e34\u754c\u70b9\uff0cRBAC\u5c31\u5f00\u59cb\u529b\u4e0d\u4ece\u5fc3\u3002<\/p>\n<p><strong>\u95ee\u9898\u4e00\uff1a\u89d2\u8272\u7206\u70b8\u3002<\/strong> \u67d0\u5ba2\u6237\u771f\u5b9e\u6848\u4f8b\u2014\u20142000\u4eba\u7684\u8bbe\u8ba1\u9662\uff0c\u6587\u4ef6\u6309\u7167\u9879\u76ee\u5206\u7ec4\uff0c\u6bcf\u4e2a\u9879\u76ee\u6709\u9879\u76ee\u8d1f\u8d23\u4eba\u3001\u8bbe\u8ba1\u4eba\u5458\u3001\u5ba1\u9605\u4eba\u5458\u3001\u5916\u534f\u4eba\u5458\u56db\u79cd\u89d2\u8272\u3002100\u4e2a\u9879\u76ee = 400\u4e2a\u89d2\u8272\uff0c\u6bcf\u4e2a\u89d2\u8272\u7684\u6743\u9650\u77e9\u9635\u8fd8\u6709\u7ec6\u5fae\u5dee\u5f02\u3002IT\u7ba1\u7406\u5458\u6bcf\u5929\u7684\u5de5\u4f5c\u5c31\u53d8\u6210\u4e86&#8221;\u65b0\u5efa\u89d2\u8272\u3001\u514b\u9686\u89d2\u8272\u3001\u4fee\u6539\u89d2\u8272&#8221;\u7684\u65e0\u5c3d\u5faa\u73af\u3002<\/p>\n<p><strong>\u95ee\u9898\u4e8c\uff1a\u7ec6\u7c92\u5ea6\u4e0d\u8db3\u3002<\/strong> RBAC\u7684\u6700\u5c0f\u7c92\u5ea6\u662f&#8221;\u8d44\u6e90+\u64cd\u4f5c&#8221;\u3002\u4f46\u4f01\u4e1a\u4e91\u76d8\u7684\u771f\u5b9e\u9700\u6c42\u8fdc\u6bd4\u8fd9\u590d\u6742\uff1a<br \/>\n&#8211; &#8220;\u8fd9\u4efd\u6587\u4ef6\u53ea\u80fd\u88ab\u8d22\u52a1\u90e8\u4e14\u804c\u7ea7P7\u4ee5\u4e0a\u7684\u4eba\u67e5\u770b&#8221;<br \/>\n&#8211; &#8220;\u8fd9\u4e2a\u6587\u4ef6\u5939\u5bf9\u5916\u90e8\u5408\u4f5c\u65b9\u53ef\u89c1\uff0c\u4f46\u4e0b\u8f7d\u64cd\u4f5c\u5fc5\u987b\u8bb0\u5f55&#8221;<br \/>\n&#8211; &#8220;\u6807\u4e86&#8217;\u9ad8\u5bc6&#8217;\u6807\u7b7e\u7684\u6587\u4ef6\u5728\u4efb\u4f55\u7f51\u7edc\u73af\u5883\u4e0b\u90fd\u4e0d\u80fd\u5916\u53d1&#8221;<\/p>\n<p>\u8fd9\u4e9b\u6761\u4ef6\u6d89\u53ca<strong>\u7528\u6237\u5c5e\u6027<\/strong>\uff08\u90e8\u95e8\u3001\u804c\u7ea7\uff09\u3001<strong>\u8d44\u6e90\u5c5e\u6027<\/strong>\uff08\u5bc6\u7ea7\u6807\u7b7e\uff09\u3001<strong>\u73af\u5883\u5c5e\u6027<\/strong>\uff08IP\u5730\u5740\u3001\u8bbf\u95ee\u65f6\u95f4\uff09\uff0cRBAC\u6839\u672c\u65e0\u6cd5\u8868\u8fbe\u3002<\/p>\n<p><strong>\u95ee\u9898\u4e09\uff1a\u4e34\u65f6\u6743\u9650\u65e0\u6cd5\u7ba1\u7406\u3002<\/strong> \u9879\u76ee\u7ed3\u675f\u4e86\uff0c\u5916\u534f\u4eba\u5458\u9700\u8981\u5ef6\u957f\u4e00\u5468\u8bbf\u95ee\u6743\u9650\u2014\u2014\u8fd9\u5728RBAC\u4f53\u7cfb\u91cc\uff0c\u8981\u4e48\u7ed9\u4ed6\u7eed\u89d2\u8272\uff0c\u8981\u4e48\u65b0\u5efa\u4e00\u4e2a\u4e34\u65f6\u89d2\u8272\uff0c\u4e24\u79cd\u505a\u6cd5\u90fd\u5145\u6ee1\u98ce\u9669\u3002<\/p>\n<p>\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48\u73b0\u4ee3\u4f01\u4e1a\u4e91\u76d8\u7684\u6743\u9650\u4f53\u7cfb\u90fd\u5728\u5411ABAC\u6f14\u8fdb\u3002<\/p>\n<hr \/>\n<h2>\u4e8c\u3001ABAC\uff1a\u5c5e\u6027\u9a71\u52a8\u7684\u4e0b\u4e00\u4ee3\u6743\u9650\u8303\u5f0f<\/h2>\n<p>ABAC\uff08Attribute-Based Access Control\uff0c\u57fa\u4e8e\u5c5e\u6027\u7684\u8bbf\u95ee\u63a7\u5236\uff09\u7528<strong>\u5c5e\u6027\u6761\u4ef6<\/strong>\u66ff\u4ee3\u4e86RBAC\u7684&#8221;\u89d2\u8272-\u6743\u9650&#8221;\u6620\u5c04\u3002\u4efb\u4f55\u4e3b\u4f53\u5c5e\u6027\uff08\u8c01\uff09\u3001\u8d44\u6e90\u5c5e\u6027\uff08\u662f\u4ec0\u4e48\uff09\u3001\u73af\u5883\u5c5e\u6027\uff08\u5728\u4ec0\u4e48\u60c5\u51b5\u4e0b\uff09\u90fd\u53ef\u4ee5\u4f5c\u4e3a\u6743\u9650\u51b3\u7b56\u7684\u8f93\u5165\u56e0\u5b50\u3002<\/p>\n<pre><code class=\"language-python\"># ABAC\u8bc4\u4f30\u5f15\u64ce\u6838\u5fc3\u903b\u8f91\r\nclass ABACEvaluator:\r\n    &quot;&quot;&quot;\u5c5e\u6027\u9a71\u52a8\u7684\u6743\u9650\u8bc4\u4f30\u5668&quot;&quot;&quot;\r\n\r\n    def __init__(self):\r\n        self.policy_cache = {}  # \u7b56\u7565\u7ed3\u679c\u7f13\u5b58\uff0c\u907f\u514d\u91cd\u590d\u8ba1\u7b97\r\n\r\n    def evaluate(self, request: PermissionRequest) -&gt; Decision:\r\n        &quot;&quot;&quot;\r\n        \u6743\u9650\u8bc4\u4f30\u5165\u53e3\r\n        request\u5305\u542b: subject(\u7528\u6237), resource(\u6587\u4ef6\/\u6587\u4ef6\u5939), \r\n                     action(\u64cd\u4f5c), environment(\u73af\u5883\u4e0a\u4e0b\u6587)\r\n        &quot;&quot;&quot;\r\n        # 1. \u83b7\u53d6\u8be5\u8d44\u6e90\u7ed1\u5b9a\u7684\u6240\u6709\u7b56\u7565\r\n        policies = self.load_policies(request.resource.id)\r\n\r\n        # 2. \u9010\u4e00\u8bc4\u4f30\uff0c\u6bcf\u6761\u7b56\u7565\u8fd4\u56deEffect.PERMIT\u6216Effect.DENY\r\n        decisions = []\r\n        for policy in policies:\r\n            effect = self._evaluate_policy(policy, request)\r\n            decisions.append((policy.priority, effect))\r\n\r\n        # 3. \u62d2\u7edd\u4f18\u5148\u7b56\u7565\uff1a\u4efb\u4f55\u4e00\u6761DENY\u751f\u6548\uff0c\u7ed3\u679c\u5c31\u662fDENY\r\n        decisions.sort(key=lambda x: x[0], reverse=True)  # \u6309\u4f18\u5148\u7ea7\u964d\u5e8f\r\n        for _, effect in decisions:\r\n            if effect == Effect.DENY:\r\n                return Decision(allowed=False, reason=&quot;denied_by_policy&quot;)\r\n\r\n        # 4. \u6ca1\u6709DENY\u7684\u60c5\u51b5\u4e0b\uff0c\u4efb\u4e00PERMIT\u5373\u901a\u8fc7\r\n        for _, effect in decisions:\r\n            if effect == Effect.PERMIT:\r\n                return Decision(allowed=True, reason=&quot;permitted_by_policy&quot;)\r\n\r\n        return Decision(allowed=False, reason=&quot;no_matching_policy&quot;)\r\n\r\n    def _evaluate_policy(self, policy: Policy, request: PermissionRequest):\r\n        &quot;&quot;&quot;\u8bc4\u4f30\u5355\u6761\u7b56\u7565\uff1a\u904d\u5386\u6240\u6709\u6761\u4ef6\uff0c\u5168\u901a\u8fc7\u624dPERMIT&quot;&quot;&quot;\r\n        conditions = policy.conditions\r\n\r\n        for condition in conditions:\r\n            if not self._evaluate_condition(condition, request):\r\n                return Effect.DENY  # \u6761\u4ef6\u4e0d\u6ee1\u8db3\uff0c\u7b56\u7565\u62d2\u7edd\r\n\r\n        return Effect.PERMIT  # \u6240\u6709\u6761\u4ef6\u6ee1\u8db3\uff0c\u7b56\u7565\u901a\u8fc7\r\n<\/code><\/pre>\n<p>\u5173\u952e\u662f\u6761\u4ef6\u8bc4\u4f30\u5668\u3002\u4f60\u9700\u8981\u652f\u6301\u591a\u79cd\u6761\u4ef6\u7c7b\u578b\uff1a<\/p>\n<pre><code class=\"language-python\">class ConditionEvaluator:\r\n    &quot;&quot;&quot;\u6761\u4ef6\u8bc4\u4f30\u5668 - \u652f\u6301\u7b49\u4e8e\u3001\u5305\u542b\u3001\u8303\u56f4\u3001\u6b63\u5219\u7b49\u591a\u79cd\u5339\u914d&quot;&quot;&quot;\r\n\r\n    OPERATORS = {\r\n        'eq': lambda a, b: a == b,\r\n        'ne': lambda a, b: a != b,\r\n        'in': lambda a, b: a in b,\r\n        'not_in': lambda a, b: a not in b,\r\n        'contains': lambda a, b: b in a,\r\n        'gt': lambda a, b: a &gt; b,\r\n        'gte': lambda a, b: a &gt;= b,\r\n        'lt': lambda a, b: a &lt; b,\r\n        'lte': lambda a, b: a &lt;= b,\r\n        'regex': lambda a, b: re.match(b, str(a)) is not None,\r\n        'and': lambda a, b: all(a),\r\n        'or': lambda a, b: any(a),\r\n    }\r\n\r\n    def evaluate(self, condition: Condition, request: PermissionRequest) -&gt; bool:\r\n        &quot;&quot;&quot;\u8bc4\u4f30\u5355\u4e2a\u6761\u4ef6\u662f\u5426\u6ee1\u8db3&quot;&quot;&quot;\r\n        attr_type = condition.subject  # 'subject' | 'resource' | 'environment'\r\n        attr_name = condition.field     # \u5c5e\u6027\u540d\uff0c\u5982 'department', 'sensitivity'\r\n        operator = condition.operator   # \u64cd\u4f5c\u7b26\r\n        expected = condition.value      # \u671f\u671b\u503c\r\n\r\n        # 1. \u83b7\u53d6\u5c5e\u6027\u5b9e\u9645\u503c\r\n        if attr_type == 'subject':\r\n            actual = getattr(request.subject, attr_name)\r\n        elif attr_type == 'resource':\r\n            actual = getattr(request.resource, attr_name)\r\n        else:  # environment\r\n            actual = request.environment.get(attr_name)\r\n\r\n        # 2. \u5904\u7406\u5217\u8868\u578b\u5c5e\u6027\uff08\u7528AND\u8fde\u63a5\uff09\r\n        if isinstance(actual, list):\r\n            results = [self.OPERATORS[operator](item, expected) for item in actual]\r\n            return all(results)\r\n\r\n        # 3. \u5355\u503c\u5c5e\u6027\u76f4\u63a5\u5339\u914d\r\n        return self.OPERATORS[operator](actual, expected)\r\n<\/code><\/pre>\n<hr \/>\n<h2>\u4e09\u3001\u6df7\u5408\u67b6\u6784\uff1aRBAC\u505a\u9aa8\u67b6\uff0cABAC\u505a\u8840\u8089<\/h2>\n<p>\u7eafABAC\u7684\u4ee3\u4ef7\u662f\u8bc4\u4f30\u590d\u6742\u5ea6\u3002\u60f3\u8c61\u6bcf\u6b21\u6587\u4ef6\u8bbf\u95ee\u90fd\u8981\u904d\u5386\u6240\u6709\u7b56\u7565\u6761\u4ef6\u2014\u2014\u8fd9\u5bf9\u6709\u767e\u4e07\u7ea7\u6587\u4ef6\u7684\u5927\u578b\u4f01\u4e1a\u662f\u707e\u96be\u6027\u7684\u3002<\/p>\n<p>\u5b9e\u6218\u4e2d\u6700\u4f18\u89e3\u662f<strong>RBAC+ABAC\u6df7\u5408\u67b6\u6784<\/strong>\uff1aRBAC\u5904\u7406\u7a33\u5b9a\u7684\u57fa\u7840\u6743\u9650\uff08\u5927\u90e8\u5206\u7528\u623790%\u7684\u8bbf\u95ee\u573a\u666f\uff09\uff0cABAC\u5904\u7406\u7ec6\u7c92\u5ea6\u548c\u52a8\u6001\u6761\u4ef6\uff08\u9ad8\u4ef7\u503c\u6587\u4ef6\u3001\u53d7\u63a7\u8d44\u6e90\uff09\u3002<\/p>\n<pre><code class=\"language-python\">class HybridPermissionEngine:\r\n    &quot;&quot;&quot;\r\n    \u6df7\u5408\u6743\u9650\u5f15\u64ce\uff1aRBAC\u4fdd\u5e95 + ABAC\u7cbe\u7ec6\r\n    \u8bc4\u4f30\u987a\u5e8f\uff1a\u5148RBAC\u5feb\u901f\u8fc7\u6ee4\uff0cABAC\u505a\u6700\u7ec8\u51b3\u7b56\r\n    &quot;&quot;&quot;\r\n\r\n    def __init__(self, rbac_cache_ttl=300, abac_cache_ttl=60):\r\n        self.rbac_engine = RBACEngine()\r\n        self.abac_engine = ABACEvaluator()\r\n        self.rbac_cache = TTLCache(maxsize=10000, ttl=rbac_cache_ttl)\r\n        self.abac_cache = TTLCache(maxsize=50000, ttl=abac_cache_ttl)\r\n\r\n    def check(self, user_id: int, resource_id: str, action: str, \r\n              context: dict = None) -&gt; PermissionResult:\r\n        &quot;&quot;&quot;\r\n        \u6743\u9650\u68c0\u67e5\u4e3b\u5165\u53e3\r\n        \u8fd4\u56de\uff1a(\u662f\u5426\u5141\u8bb8, \u547d\u4e2d\u7b56\u7565\u5217\u8868, \u8bc4\u4f30\u8017\u65f6ms)\r\n        &quot;&quot;&quot;\r\n        start = time.time()\r\n        context = context or {}\r\n\r\n        # Step 1: RBAC\u5feb\u901f\u901a\u9053\uff08\u6beb\u79d2\u7ea7\uff09\r\n        rbac_result = self._check_rbac_fast(user_id, resource_id, action)\r\n\r\n        # RBAC\u76f4\u63a5\u901a\u8fc7 -&gt; \u53ef\u80fd\u5141\u8bb8\uff0c\u5feb\u901f\u8fd4\u56de\uff08\u4ecd\u9700ABAC\u51b3\u7b56\uff09\r\n        # RBAC\u76f4\u63a5\u62d2\u7edd -&gt; \u4e00\u5b9a\u62d2\u7edd\uff08\u65e0\u9700ABAC\uff09\r\n        if rbac_result == 'deny':\r\n            return PermissionResult(\r\n                allowed=False,\r\n                reason='rbac_deny',\r\n                latency_ms=(time.time() - start) * 1000\r\n            )\r\n\r\n        # Step 2: RBAC\u901a\u8fc7\uff0c\u8fdb\u5165ABAC\u7cbe\u7ec6\u8bc4\u4f30\r\n        abac_key = f&quot;{user_id}:{resource_id}:{action}:{hash(frozenset(context.items()))}&quot;\r\n\r\n        if abac_key in self.abac_cache:\r\n            return self.abac_cache[abac_key]\r\n\r\n        request = PermissionRequest(\r\n            subject=Subject.from_user_id(user_id),\r\n            resource=Resource.from_id(resource_id),\r\n            action=action,\r\n            environment=Environment(context)\r\n        )\r\n\r\n        abac_result = self.abac_engine.evaluate(request)\r\n\r\n        # \u7f13\u5b58\u7ed3\u679c\r\n        result = PermissionResult(\r\n            allowed=abac_result.allowed,\r\n            reason=abac_result.reason,\r\n            matched_policies=abac_result.matched_policies,\r\n            latency_ms=(time.time() - start) * 1000\r\n        )\r\n        self.abac_cache[abac_key] = result\r\n\r\n        return result\r\n\r\n    def _check_rbac_fast(self, user_id, resource_id, action) -&gt; str:\r\n        &quot;&quot;&quot;\r\n        RBAC\u5feb\u901f\u68c0\u67e5\uff1a\u547d\u4e2d\u7f13\u5b58\u5219\u7528\u7f13\u5b58\uff0c\u5426\u5219\u67e5\u5e93\r\n        \u8fd4\u56de: 'allow' | 'deny' | 'unknown'\r\n        &quot;&quot;&quot;\r\n        cache_key = f&quot;rbac:{user_id}:{resource_id}:{action}&quot;\r\n\r\n        if cache_key in self.rbac_cache:\r\n            return self.rbac_cache[cache_key]\r\n\r\n        # \u6570\u636e\u5e93\u67e5\u8be2\uff08\u8d70\u7d22\u5f15\uff0c&lt;1ms\uff09\r\n        has_permission = db.fetch_val(&quot;&quot;&quot;\r\n            SELECT EXISTS(\r\n                SELECT 1 FROM user_roles ur\r\n                JOIN role_permissions rp ON ur.role_id = rp.role_id\r\n                WHERE ur.user_id = %s\r\n                  AND rp.resource_id IN (%s, '*')  -- '*' \u8868\u793a\u5168\u5c40\u6743\u9650\r\n                  AND rp.action IN (%s, 'admin')\r\n            )\r\n        &quot;&quot;&quot;, user_id, resource_id, action)\r\n\r\n        result = 'allow' if has_permission else 'unknown'\r\n        self.rbac_cache[cache_key] = result\r\n        return result\r\n<\/code><\/pre>\n<hr \/>\n<h2>\u56db\u3001\u7b56\u7565\u7ed3\u6784\u8bbe\u8ba1\uff1a\u771f\u5b9e\u7684\u6743\u9650\u914d\u7f6e\u957f\u4ec0\u4e48\u6837<\/h2>\n<p>\u5b9e\u9645\u751f\u4ea7\u73af\u5883\u4e2d\u7684\u6743\u9650\u7b56\u7565\u8fdc\u6bd4\u7406\u8bba\u6846\u67b6\u590d\u6742\u3002\u4ee5\u4e0b\u662f\u5df4\u522b\u9e1f\u4f01\u4e1a\u4e91\u76d8\u7684\u771f\u5b9e\u7b56\u7565\u5b58\u50a8\u7ed3\u6784\uff1a<\/p>\n<pre><code class=\"language-json\">{\r\n  &quot;policy_id&quot;: &quot;finance-q3-report-2024&quot;,\r\n  &quot;policy_name&quot;: &quot;2024\u5e74Q3\u8d22\u62a5\u9650\u5236\u8bbf\u95ee\u7b56\u7565&quot;,\r\n  &quot;effect&quot;: &quot;permit&quot;,\r\n  &quot;priority&quot;: 100,\r\n  &quot;subjects&quot;: {\r\n    &quot;type&quot;: &quot;and&quot;,\r\n    &quot;conditions&quot;: [\r\n      {&quot;field&quot;: &quot;department&quot;, &quot;operator&quot;: &quot;in&quot;, &quot;value&quot;: [&quot;\u8d22\u52a1\u90e8&quot;, &quot;\u8463\u4e8b\u4f1a&quot;, &quot;\u8bc1\u5238\u90e8&quot;]},\r\n      {&quot;field&quot;: &quot;role_level&quot;, &quot;operator&quot;: &quot;gte&quot;, &quot;value&quot;: 7},\r\n      {&quot;field&quot;: &quot;employment_type&quot;, &quot;operator&quot;: &quot;eq&quot;, &quot;value&quot;: &quot;\u6b63\u5f0f\u5458\u5de5&quot;}\r\n    ]\r\n  },\r\n  &quot;resources&quot;: {\r\n    &quot;type&quot;: &quot;and&quot;,\r\n    &quot;conditions&quot;: [\r\n      {&quot;field&quot;: &quot;folder_path&quot;, &quot;operator&quot;: &quot;starts_with&quot;, &quot;value&quot;: &quot;\/\u8d22\u62a5\/2024\/Q3&quot;},\r\n      {&quot;field&quot;: &quot;sensitivity&quot;, &quot;operator&quot;: &quot;in&quot;, &quot;value&quot;: [&quot;\u9ad8\u5bc6&quot;, &quot;\u7edd\u5bc6&quot;]},\r\n      {&quot;field&quot;: &quot;file_type&quot;, &quot;operator&quot;: &quot;in&quot;, &quot;value&quot;: [&quot;xlsx&quot;, &quot;pdf&quot;, &quot;docx&quot;]}\r\n    ]\r\n  },\r\n  &quot;actions&quot;: [&quot;read&quot;, &quot;download&quot;, &quot;print&quot;],\r\n  &quot;environment&quot;: {\r\n    &quot;type&quot;: &quot;and&quot;,\r\n    &quot;conditions&quot;: [\r\n      {&quot;field&quot;: &quot;ip_range&quot;, &quot;operator&quot;: &quot;in&quot;, &quot;value&quot;: [&quot;10.0.0.0\/8&quot;, &quot;172.16.0.0\/12&quot;]},\r\n      {&quot;field&quot;: &quot;device_trusted&quot;, &quot;operator&quot;: &quot;eq&quot;, &quot;value&quot;: true},\r\n      {&quot;field&quot;: &quot;access_time&quot;, &quot;operator&quot;: &quot;between&quot;, &quot;value&quot;: [&quot;2024-09-01&quot;, &quot;2024-10-31&quot;]}\r\n    ]\r\n  },\r\n  &quot;obligations&quot;: [\r\n    {&quot;type&quot;: &quot;log_access&quot;, &quot;params&quot;: {&quot;level&quot;: &quot;warning&quot;}},\r\n    {&quot;type&quot;: &quot;watermark&quot;, &quot;params&quot;: {&quot;text&quot;: &quot;${subject.name} ${datetime}&quot;}}\r\n  ]\r\n}\r\n<\/code><\/pre>\n<p>\u8fd9\u6761\u7b56\u7565\u7684\u542b\u4e49\u662f\uff1a<br \/>\n&#8211; <strong>\u8c01<\/strong>\uff1a\u8d22\u52a1\u90e8\/\u8463\u4e8b\u4f1a\/\u8bc1\u5238\u90e8\uff0c\u804c\u7ea7\u2265P7\u7684\u6b63\u5f0f\u5458\u5de5<br \/>\n&#8211; <strong>\u4ec0\u4e48<\/strong>\uff1a\u8def\u5f84\u542b<code>\/\u8d22\u62a5\/2024\/Q3<\/code>\u3001\u6807\u6ce8\u9ad8\u5bc6\/\u7edd\u5bc6\u7684Office\/PDF\u6587\u4ef6<br \/>\n&#8211; <strong>\u4f55\u65f6<\/strong>\uff1a2024\u5e749\u6708-10\u6708\u671f\u95f4<br \/>\n&#8211; <strong>\u54ea\u767b\u5f55<\/strong>\uff1a\u516c\u53f8\u5185\u7f51IP\uff0810.0.0.0\/8\u6216172.16.0.0\/12\u6bb5\uff09\u3001\u53ef\u4fe1\u8bbe\u5907<br \/>\n&#8211; <strong>\u505a\u4ec0\u4e48<\/strong>\uff1a\u53ef\u4ee5\u67e5\u770b\u3001\u4e0b\u8f7d\u3001\u6253\u5370<br \/>\n&#8211; <strong>\u989d\u5916\u8981\u6c42<\/strong>\uff1a\u8bbf\u95ee\u5fc5\u987b\u8bb0\u5f55\u65e5\u5fd7\uff0c\u6253\u5370\/\u4e0b\u8f7d\u65f6\u5f3a\u5236\u52a0\u6c34\u5370<\/p>\n<p>\u6ce8\u610f\u6700\u540e\u4e00\u9879<strong>obligations<\/strong>\uff08\u4e49\u52a1\uff09\uff1a\u8fd9\u662fABAC\u4f53\u7cfb\u4e2d\u5bb9\u6613\u88ab\u5ffd\u7565\u7684\u80fd\u529b\u2014\u2014\u6743\u9650\u901a\u8fc7\u4e0d\u7b49\u4e8e\u6ca1\u6709\u7ea6\u675f\uff0c\u8bbf\u95ee\u52a8\u4f5c\u672c\u8eab\u53ef\u4ee5\u9644\u52a0\u884c\u4e3a\u8981\u6c42\uff08\u6bd4\u5982\u5f3a\u5236\u6c34\u5370\u3001\u5f3a\u5236\u5ba1\u8ba1\u65e5\u5fd7\uff09\u3002<\/p>\n<hr \/>\n<h2>\u4e94\u3001\u6027\u80fd\u4f18\u5316\uff1a\u6bcf\u79d210000\u6b21\u6743\u9650\u68c0\u67e5\u5982\u4f55\u5b9e\u73b0<\/h2>\n<p>\u67b6\u6784\u8bbe\u8ba1\u5f97\u518d\u6f02\u4eae\uff0c\u5982\u679c\u6027\u80fd\u4e0d\u8fc7\u5173\uff0c\u5728\u751f\u4ea7\u73af\u5883\u5c31\u662f\u5e9f\u7eb8\u4e00\u5f20\u3002<\/p>\n<p>\u67d0\u5ba2\u6237\u9ad8\u5cf0\u671f\u5b9e\u6d4b\uff1a<strong>5000\u5e76\u53d1\u7528\u6237\u3001\u767e\u4e07\u7ea7\u6587\u4ef6<\/strong>\uff0c\u6743\u9650\u68c0\u67e5QPS\u5cf0\u503c\u8fbe\u5230<strong>12000\u6b21\/\u79d2<\/strong>\u3002\u8fd9\u4e2a\u6570\u5b57\u610f\u5473\u7740\u4ec0\u4e48\uff1f\u610f\u5473\u7740\u5e73\u5747\u6bcf<strong>83\u5fae\u79d2<\/strong>\u5c31\u8981\u5b8c\u6210\u4e00\u6b21\u5b8c\u6574\u7684\u6743\u9650\u8bc4\u4f30\u3002<\/p>\n<p>\u6211\u4eec\u7684\u4f18\u5316\u7b56\u7565\u662f<strong>\u4e09\u7ea7\u7f13\u5b58<\/strong>\uff1a<\/p>\n<pre><code class=\"language-python\">class ThreeLevelPermissionCache:\r\n    &quot;&quot;&quot;\u4e09\u7ea7\u7f13\u5b58\uff1a\u672c\u5730\u5185\u5b58 \u2192 Redis \u2192 \u6570\u636e\u5e93&quot;&quot;&quot;\r\n\r\n    def __init__(self):\r\n        # L1: \u8fdb\u7a0b\u5185\u5185\u5b58\uff08TTL 30s\uff0c\u9002\u5408\u70ed\u70b9\u6570\u636e\uff09\r\n        self.l1 = LRUCache(maxsize=5000, ttl=30)\r\n\r\n        # L2: Redis\u5206\u5e03\u5f0f\u7f13\u5b58\uff08TTL 5min\uff0c\u5168\u8282\u70b9\u5171\u4eab\uff09\r\n        self.redis = RedisClient(host='redis.internal', db=1)\r\n\r\n        # L3: \u6570\u636e\u5e93\uff08\u6700\u7ec8\u6765\u6e90\uff09\r\n        self.db = DatabasePool(max_connections=20)\r\n\r\n    def get_cached_permission(self, key: str) -&gt; Optional[Decision]:\r\n        # L1\u67e5\u627e\r\n        if key in self.l1:\r\n            return self.l1[key]\r\n\r\n        # L2\u67e5\u627e\r\n        cached = self.redis.get(f&quot;perm:{key}&quot;)\r\n        if cached:\r\n            decision = Decision.loads(cached)\r\n            self.l1[key] = decision  # \u56de\u586bL1\r\n            return decision\r\n\r\n        return None  # \u7f13\u5b58\u672a\u547d\u4e2d\uff0c\u8d70\u8bc4\u4f30\u6d41\u7a0b\r\n<\/code><\/pre>\n<p>\u5b9e\u6d4b\u6570\u636e\uff085000\u5e76\u53d1\u300110000 QPS\uff09\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>\u7f13\u5b58\u5c42\u7ea7<\/th>\n<th>\u547d\u4e2d\u7387<\/th>\n<th>\u5e73\u5747\u5ef6\u8fdf<\/th>\n<th>99\u7ebf\u5ef6\u8fdf<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u65e0\u7f13\u5b58<\/td>\n<td>\u2014<\/td>\n<td>8.3ms<\/td>\n<td>23.1ms<\/td>\n<\/tr>\n<tr>\n<td>L1\u672c\u5730<\/td>\n<td>72%<\/td>\n<td>0.4ms<\/td>\n<td>1.2ms<\/td>\n<\/tr>\n<tr>\n<td>L1+L2<\/td>\n<td>94%<\/td>\n<td>0.2ms<\/td>\n<td>0.8ms<\/td>\n<\/tr>\n<tr>\n<td>L1+L2+L3<\/td>\n<td>98.7%<\/td>\n<td>0.15ms<\/td>\n<td>0.6ms<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>99\u7ebf<strong>0.6ms<\/strong>\u7684\u5ef6\u8fdf\u610f\u5473\u7740\u4ec0\u4e48\uff1f\u7528\u6237\u51e0\u4e4e\u611f\u77e5\u4e0d\u5230\u6743\u9650\u68c0\u67e5\u7684\u5b58\u5728\u3002\u5728\u4f01\u4e1a\u4e91\u76d8\u7684\u6b63\u5e38\u4f7f\u7528\u573a\u666f\u91cc\uff0c\u6587\u4ef6\u64cd\u4f5c\uff08IO\uff09\u7684\u8017\u65f6\u901a\u5e38\u662f\u6743\u9650\u68c0\u67e5\u7684\u51e0\u5341\u5230\u4e0a\u767e\u500d\u3002<\/p>\n<hr \/>\n<h2>\u516d\u3001\u5ba1\u8ba1\u65e5\u5fd7\uff1a\u6743\u9650\u7684\u6700\u540e\u4e00\u9053\u9632\u7ebf<\/h2>\n<p>\u518d\u5b8c\u7f8e\u7684\u6743\u9650\u6a21\u578b\uff0c\u4e5f\u8981\u56de\u7b54\u4e00\u4e2a\u95ee\u9898\uff1a<strong>\u8c01\u5728\u4ec0\u4e48\u65f6\u95f4\u8bbf\u95ee\u4e86\u4ec0\u4e48\uff0c\u505a\u4e86\u4ec0\u4e48\u64cd\u4f5c\uff1f<\/strong><\/p>\n<p>\u6743\u9650\u5ba1\u8ba1\u65e5\u5fd7\u662f\u6743\u9650\u4f53\u7cfb\u7684&#8221;\u9ed1\u5323\u5b50&#8221;\u3002\u4e00\u65e6\u53d1\u751f\u6570\u636e\u6cc4\u9732\uff0c\u7b2c\u4e00\u65f6\u95f4\u770b\u7684\u4e0d\u662f\u6743\u9650\u914d\u7f6e\u5bf9\u4e0d\u5bf9\uff0c\u800c\u662f\u65e5\u5fd7\u8bb0\u6ca1\u8bb0\u3001\u8bb0\u7684\u5168\u4e0d\u5168\u3002<\/p>\n<pre><code class=\"language-python\">class PermissionAuditor:\r\n    &quot;&quot;&quot;\u6743\u9650\u5ba1\u8ba1\u65e5\u5fd7\u5199\u5165\uff08\u5f02\u6b65\uff0c\u4e0d\u963b\u585e\u6b63\u5e38\u6743\u9650\u8bc4\u4f30\uff09&quot;&quot;&quot;\r\n\r\n    def __init__(self, kafka_topic='permission-audit'):\r\n        self.producer = AIOKafkaProducer(\r\n            bootstrap_servers='kafka:9092',\r\n            compression_type='gzip'\r\n        )\r\n        self.batch_buffer = []\r\n        self.batch_size = 500\r\n        self.flush_interval = 2.0  # \u6700\u591a\u7b492\u79d2\r\n\r\n    async def log(self, request: PermissionRequest, \r\n                  decision: Decision, latency_ms: float):\r\n        &quot;&quot;&quot;\u5f02\u6b65\u5199\u5165\u5ba1\u8ba1\u65e5\u5fd7\uff0c\u4e0d\u963b\u585e\u6743\u9650\u8bc4\u4f30\u4e3b\u6d41\u7a0b&quot;&quot;&quot;\r\n        record = {\r\n            'timestamp': datetime.utcnow().isoformat(),\r\n            'user_id': request.subject.id,\r\n            'user_name': request.subject.name,\r\n            'user_department': request.subject.department,\r\n            'resource_id': request.resource.id,\r\n            'resource_name': request.resource.name,\r\n            'resource_path': request.resource.path,\r\n            'action': request.action,\r\n            'decision': 'allow' if decision.allowed else 'deny',\r\n            'deny_reason': decision.reason,\r\n            'matched_policies': decision.matched_policies,\r\n            'latency_ms': round(latency_ms, 2),\r\n            'ip_address': request.environment.get('ip_address'),\r\n            'device_id': request.environment.get('device_id'),\r\n            'client_type': request.environment.get('client_type'),\r\n        }\r\n\r\n        self.batch_buffer.append(record)\r\n\r\n        # \u6279\u91cf\u5199\u5165\uff0c500\u6761\u62162\u79d2\u89e6\u53d1\u4e00\u6b21\r\n        if (len(self.batch_buffer) &gt;= self.batch_size or \r\n                len(self.batch_buffer) &gt; 0 and \r\n                time.time() - self.last_flush &gt; self.flush_interval):\r\n            await self._flush()\r\n\r\n    async def _flush(self):\r\n        if not self.batch_buffer:\r\n            return\r\n        records = self.batch_buffer\r\n        self.batch_buffer = []\r\n        self.last_flush = time.time()\r\n\r\n        # \u538b\u7f29\u5199\u5165Kafka\uff0c\u51cf\u5c11\u5b58\u50a8\u6210\u672c\r\n        await self.producer.send_and_wait(\r\n            self.kafka_topic,\r\n            value=json.dumps(records).encode('utf-8')\r\n        )\r\n<\/code><\/pre>\n<p>\u5ba1\u8ba1\u65e5\u5fd7\u7684\u5b58\u50a8\u4e5f\u6709\u8bb2\u7a76\uff1a<strong>DENY\u8bb0\u5f55\u5fc5\u987b\u5b9e\u65f6\u5199\u5165<\/strong>\uff0cALLOW\u8bb0\u5f55\u53ef\u4ee5\u6279\u91cf\u5f02\u6b65\u5199\u3002\u6211\u4eec\u628aDENY\u65e5\u5fd7\u5355\u72ec\u8def\u7531\u5230\u9ad8\u53ef\u7528\u7684ES\u96c6\u7fa4\uff0c\u4fdd\u7559<strong>180\u5929<\/strong>\uff0cALLOW\u65e5\u5fd7\u4fdd\u7559<strong>30\u5929<\/strong>\u3002\u8fd9\u4e2a\u6bd4\u4f8b\u662f\u7ecf\u8fc7\u6210\u672c\u6838\u7b97\u7684\u2014\u2014\u5b9e\u9645\u5b89\u5168\u4e8b\u4ef6\u7684\u8c03\u67e5\uff0c90%\u4ee5\u4e0a\u5173\u6ce8\u7684\u662f&#8221;\u54ea\u4e9b\u5f02\u5e38\u8bbf\u95ee\u88ab\u62e6\u622a\u4e86&#8221;\u3002<\/p>\n<hr \/>\n<h2>\u4e03\u3001\u56de\u5230\u5f00\u5934\u90a3\u4e2a\u6545\u4e8b<\/h2>\n<p>\u56de\u5230\u6587\u7ae0\u5f00\u5934\u90a3\u8d77\u8d22\u62a5\u6cc4\u9732\u4e8b\u4ef6\u3002\u4e8b\u6545\u590d\u76d8\u65f6\uff0cIT\u56e2\u961f\u5728\u65e5\u5fd7\u91cc\u53d1\u73b0\u4e86\u5173\u952e\u8bc1\u636e\uff1a\u9500\u552e\u603b\u76d1\u5728\u5f53\u665a<strong>22:47<\/strong>\u901a\u8fc7VPN\u4ece\u5916\u90e8\u7f51\u7edc\u8bbf\u95ee\u4e86\u90a3\u4efd\u8d22\u62a5\uff0c\u6267\u884c\u4e86<strong>3\u6b21\u6253\u5370\u64cd\u4f5c\u548c1\u6b21\u4e0b\u8f7d\u64cd\u4f5c<\/strong>\u2014\u2014\u6240\u6709\u64cd\u4f5c\u90fd\u5e26\u7740\u4ed6\u7684\u6c34\u5370\u3002<\/p>\n<p>\u5982\u679c\u4e0d\u662f\u6743\u9650\u5ba1\u8ba1\u65e5\u5fd7\u8bb0\u5f55\u4e86\u8fd9\u4e00\u5207\uff0c\u8ffd\u8d23\u53ef\u80fd\u9677\u5165\u626f\u76ae\u3002\u800c\u73b0\u5728\uff0c\u5b8c\u6574\u7684\u64cd\u4f5c\u94fe\u8def\u6e05\u6670\u5730\u6446\u5728\u684c\u4e0a\uff1a<strong>\u6743\u9650\u914d\u7f6e\u9519\u8bef \u2192 \u5916\u53d1\u5206\u4eab \u2192 \u88ab\u8f6c\u53d1 \u2192 \u88ab\u516c\u5f00\u62ab\u9732<\/strong>\u3002\u6bcf\u4e00\u4e2a\u73af\u8282\u7684\u8d23\u4efb\u4eba\u4e00\u76ee\u4e86\u7136\u3002<\/p>\n<p>\u8fd9\u4e2a\u6545\u4e8b\u7684\u771f\u6b63\u6559\u8bad\u4e0d\u662f&#8221;\u8981\u914d\u597d\u6743\u9650&#8221;\uff0c\u800c\u662f\uff1a<strong>RBAC\u548cABAC\u4e0d\u662f\u4e8c\u9009\u4e00\uff0c\u800c\u662f\u5404\u53f8\u5176\u804c<\/strong>\u3002RBAC\u7ba1\u4f4f90%\u7684\u65e5\u5e38\u8bbf\u95ee\uff0c\u8ba9\u6743\u9650\u7ba1\u7406\u7b80\u5355\u53ef\u63a7\uff1bABAC\u7ba1\u4f4f10%\u7684\u9ad8\u4ef7\u503c\u8d44\u6e90\uff0c\u8ba9\u5173\u952e\u6587\u4ef6\u5f97\u5230\u5b83\u8be5\u6709\u7684\u4fdd\u62a4\u3002\u4e24\u8005\u7ed3\u5408\uff0c\u624d\u662f\u4f01\u4e1a\u4e91\u76d8\u6743\u9650\u4f53\u7cfb\u7684\u6b63\u786e\u6253\u5f00\u65b9\u5f0f\u3002<\/p>\n<hr \/>\n<p><strong>\u9644\uff1a\u6838\u5fc3\u914d\u7f6e\u793a\u4f8b<\/strong><\/p>\n<pre><code class=\"language-yaml\"># \u6743\u9650\u5f15\u64ce\u914d\u7f6e\u6587\u4ef6\uff08config.yaml\uff09\r\npermission_engine:\r\n  hybrid_mode: true  # \u542f\u7528RBAC+ABAC\u6df7\u5408\u6a21\u5f0f\r\n\r\n  rbac:\r\n    cache_ttl_seconds: 300\r\n    cache_max_size: 10000\r\n\r\n  abac:\r\n    cache_ttl_seconds: 60\r\n    cache_max_size: 50000\r\n    max_evaluation_depth: 10  # \u7b56\u7565\u5d4c\u5957\u6df1\u5ea6\u4fdd\u62a4\r\n    evaluation_timeout_ms: 50  # \u5355\u6b21\u8bc4\u4f30\u8d85\u65f6\u4fdd\u62a4\r\n\r\n  audit:\r\n    deny_log_realtime: true\r\n    allow_log_batch: true\r\n    deny_retention_days: 180\r\n    allow_retention_days: 30\r\n    kafka_topic: permission-audit\r\n<\/code><\/pre>\n<p>\u5982\u679c\u4f60\u7684\u4f01\u4e1a\u4e91\u76d8\u8fd8\u5728\u7528\u7eafRBAC\uff0c\u73b0\u5728\u662f\u65f6\u5019\u8ba4\u771f\u8bc4\u4f30\u4e00\u4e0bABAC\u7684\u5f15\u5165\u65f6\u673a\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f5c\u8005\uff1a\u867e\u6761 | \u5df4\u522b\u9e1f\u4f01\u4e1a\u4e91\u76d8\u6280\u672f\u56e2\u961f \u53bb\u5e74\u79cb\u5929\uff0c\u67d0\u4e0a\u5e02\u516c\u53f8&#8230; <a class=\"read-more\" href=\"https:\/\/www.babel.cc\/blog\/?p=6509\">[Continue Reading]<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6509","post","type-post","status-publish","format-standard","hentry","category-1","no-post-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6509","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6509"}],"version-history":[{"count":1,"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6509\/revisions"}],"predecessor-version":[{"id":6510,"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6509\/revisions\/6510"}],"wp:attachment":[{"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6509"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6509"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6509"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}