feat: unified PDP plugin — closes #2223#2640
Conversation
48bbb28 to
82e85e8
Compare
|
Thanks @yiannis2804 - cool PR. Leave it with me for a bit, I will rebase this to the latest main (as a PR that just bumped unit test coverage from ~63 to 83 was just merged) - and I have a few things I'd like to change as well. Will push the PR back to this branch in a bit, along with the feedback and list of changes. Cheers! |
Adds a single plugin entry point that orchestrates access-control decisions across multiple policy engines (Native RBAC, MAC, OPA, Cedar). - plugins/unified_pdp/unified_pdp.py — Plugin class, hooks into tool_pre_invoke and resource_pre_fetch - plugins/unified_pdp/pdp.py — PolicyDecisionPoint orchestrator - plugins/unified_pdp/pdp_models.py — Pydantic models (Subject, Resource, Context, AccessDecision, config types) - plugins/unified_pdp/adapter.py — Abstract engine adapter base class - plugins/unified_pdp/cache.py — TTL-aware decision cache - plugins/unified_pdp/engines/ — Four engine adapters: native_engine, mac_engine, opa_engine, cedar_engine - plugins/unified_pdp/default_rules.json — Starter RBAC ruleset - tests/unit/plugins/test_unified_pdp.py — 46 unit tests - plugins/config.yaml — Plugin registration (mode: disabled) - MANIFEST.in — Added recursive-include plugins *.json Combination modes: all_must_allow | any_allow | first_match Native RBAC and MAC work out of the box. OPA and Cedar require their respective sidecars (see README). Closes IBM#2223 Signed-off-by: yiannis2804 <yiannis2804@gmail.com>
13 tests covering UnifiedPDPPlugin hook methods (tool_pre_invoke, resource_pre_fetch), subject extraction (dict/string/None user), action string formatting, resource type mapping, and _build_pdp. unified_pdp.py now at 100% coverage. Remaining gaps are in OPA and Cedar engine adapters which require external sidecars to test. Signed-off-by: yiannis2804 <yiannis2804@gmail.com>
Signed-off-by: yiannis2804 <yiannis2804@gmail.com>
- Fix undefined variable eng_type in pdp.py:get_effective_permissions() - Add shutdown() lifecycle method to UnifiedPDPPlugin to properly close HTTP clients for OPA/Cedar engines - Convert tests from respx to pytest-httpx (project standard) - Add test for shutdown() method Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
- Remove unused import List from mac_engine.py - Remove unused variable first_deny from pdp.py Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
…view - Cache key now includes user_agent and context.extra to prevent incorrect cached decisions when policies depend on these fields (MAC operation override, OPA/Cedar context-based rules) - Plugin now extracts IP and user_agent from HTTP headers and passes to PDP context for policy evaluation - Plugin passes tool args to context.extra and resource metadata to resource.annotations for fine-grained policy checks - Exception handling in _evaluate_parallel/_evaluate_sequential now catches all exceptions (not just TimeoutError/PolicyEvaluationError) to prevent crashing the whole request on unexpected errors - Native RBAC docstring corrected: only JSON files are supported (not YAML) Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
Extract classification_level from tool args and resource metadata so MAC engine can make proper Bell-LaPadula decisions instead of always denying due to missing classification. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
82e85e8 to
f397ff1
Compare
|
@yiannis2804 — Thank you for this substantial contribution! The unified PDP architecture is well-designed with good separation of concerns between the plugin layer, orchestrator, engines, and cache. I've rebased the branch onto the latest Fixes Applied1. Bug: Undefined variable
|
Add missing docstrings to all public functions and methods in the unified_pdp plugin to satisfy the project's 100% docstring coverage requirement enforced by interrogate. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
Add complete Args, Returns, Raises, and Attributes documentation to all public functions and methods in the unified_pdp plugin, matching the project's docstring style with full parameter descriptions. Files updated: - adapter.py: PolicyEvaluationError, PolicyEngineAdapter methods - cache.py: _build_cache_key, _CacheEntry, DecisionCache methods - pdp.py: PolicyDecisionPoint and all evaluation/combination methods - engines/cedar_engine.py: CedarEngineAdapter and all methods - engines/mac_engine.py: MACEngineAdapter and all methods - engines/native_engine.py: NativeRBACAdapter and all methods - engines/opa_engine.py: OPAEngineAdapter and all methods - unified_pdp.py: shutdown lifecycle method Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
|
Thanks @crivetimihai — really appreciate the thorough review and improvements. Everything looks great from my side. |
Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
|
Great, looks like testing passes - merging! |
|
Thanks @crivetimihai — really appreciate the thorough review and improvements. Glad to see this merged! |
* feat: unified PDP plugin for issue IBM#2223 Adds a single plugin entry point that orchestrates access-control decisions across multiple policy engines (Native RBAC, MAC, OPA, Cedar). - plugins/unified_pdp/unified_pdp.py — Plugin class, hooks into tool_pre_invoke and resource_pre_fetch - plugins/unified_pdp/pdp.py — PolicyDecisionPoint orchestrator - plugins/unified_pdp/pdp_models.py — Pydantic models (Subject, Resource, Context, AccessDecision, config types) - plugins/unified_pdp/adapter.py — Abstract engine adapter base class - plugins/unified_pdp/cache.py — TTL-aware decision cache - plugins/unified_pdp/engines/ — Four engine adapters: native_engine, mac_engine, opa_engine, cedar_engine - plugins/unified_pdp/default_rules.json — Starter RBAC ruleset - tests/unit/plugins/test_unified_pdp.py — 46 unit tests - plugins/config.yaml — Plugin registration (mode: disabled) - MANIFEST.in — Added recursive-include plugins *.json Combination modes: all_must_allow | any_allow | first_match Native RBAC and MAC work out of the box. OPA and Cedar require their respective sidecars (see README). Closes IBM#2223 Signed-off-by: yiannis2804 <yiannis2804@gmail.com> * test: add plugin class unit tests, coverage 86% 13 tests covering UnifiedPDPPlugin hook methods (tool_pre_invoke, resource_pre_fetch), subject extraction (dict/string/None user), action string formatting, resource type mapping, and _build_pdp. unified_pdp.py now at 100% coverage. Remaining gaps are in OPA and Cedar engine adapters which require external sidecars to test. Signed-off-by: yiannis2804 <yiannis2804@gmail.com> * docs: add detailed README for unified PDP plugin Signed-off-by: yiannis2804 <yiannis2804@gmail.com> * fix(unified-pdp): fix bugs and improve tests - Fix undefined variable eng_type in pdp.py:get_effective_permissions() - Add shutdown() lifecycle method to UnifiedPDPPlugin to properly close HTTP clients for OPA/Cedar engines - Convert tests from respx to pytest-httpx (project standard) - Add test for shutdown() method Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * chore(unified-pdp): fix linting issues - Remove unused import List from mac_engine.py - Remove unused variable first_deny from pdp.py Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * fix(unified-pdp): address review findings from additional security review - Cache key now includes user_agent and context.extra to prevent incorrect cached decisions when policies depend on these fields (MAC operation override, OPA/Cedar context-based rules) - Plugin now extracts IP and user_agent from HTTP headers and passes to PDP context for policy evaluation - Plugin passes tool args to context.extra and resource metadata to resource.annotations for fine-grained policy checks - Exception handling in _evaluate_parallel/_evaluate_sequential now catches all exceptions (not just TimeoutError/PolicyEvaluationError) to prevent crashing the whole request on unexpected errors - Native RBAC docstring corrected: only JSON files are supported (not YAML) Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * fix(unified-pdp): extract classification_level for MAC engine Extract classification_level from tool args and resource metadata so MAC engine can make proper Bell-LaPadula decisions instead of always denying due to missing classification. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * docs: add docstrings for 100% interrogate coverage Add missing docstrings to all public functions and methods in the unified_pdp plugin to satisfy the project's 100% docstring coverage requirement enforced by interrogate. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * docs: add comprehensive Google-style docstrings to unified_pdp Add complete Args, Returns, Raises, and Attributes documentation to all public functions and methods in the unified_pdp plugin, matching the project's docstring style with full parameter descriptions. Files updated: - adapter.py: PolicyEvaluationError, PolicyEngineAdapter methods - cache.py: _build_cache_key, _CacheEntry, DecisionCache methods - pdp.py: PolicyDecisionPoint and all evaluation/combination methods - engines/cedar_engine.py: CedarEngineAdapter and all methods - engines/mac_engine.py: MACEngineAdapter and all methods - engines/native_engine.py: NativeRBACAdapter and all methods - engines/opa_engine.py: OPAEngineAdapter and all methods - unified_pdp.py: shutdown lifecycle method Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * docs: add __init__ docstring to PolicyEvaluationError Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> --------- Signed-off-by: yiannis2804 <yiannis2804@gmail.com> Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> Co-authored-by: Mihai Criveti <crivetimihai@gmail.com> Signed-off-by: hughhennnelly <hughhennelly06@gmail.com>
* feat: unified PDP plugin for issue IBM#2223 Adds a single plugin entry point that orchestrates access-control decisions across multiple policy engines (Native RBAC, MAC, OPA, Cedar). - plugins/unified_pdp/unified_pdp.py — Plugin class, hooks into tool_pre_invoke and resource_pre_fetch - plugins/unified_pdp/pdp.py — PolicyDecisionPoint orchestrator - plugins/unified_pdp/pdp_models.py — Pydantic models (Subject, Resource, Context, AccessDecision, config types) - plugins/unified_pdp/adapter.py — Abstract engine adapter base class - plugins/unified_pdp/cache.py — TTL-aware decision cache - plugins/unified_pdp/engines/ — Four engine adapters: native_engine, mac_engine, opa_engine, cedar_engine - plugins/unified_pdp/default_rules.json — Starter RBAC ruleset - tests/unit/plugins/test_unified_pdp.py — 46 unit tests - plugins/config.yaml — Plugin registration (mode: disabled) - MANIFEST.in — Added recursive-include plugins *.json Combination modes: all_must_allow | any_allow | first_match Native RBAC and MAC work out of the box. OPA and Cedar require their respective sidecars (see README). Closes IBM#2223 Signed-off-by: yiannis2804 <yiannis2804@gmail.com> * test: add plugin class unit tests, coverage 86% 13 tests covering UnifiedPDPPlugin hook methods (tool_pre_invoke, resource_pre_fetch), subject extraction (dict/string/None user), action string formatting, resource type mapping, and _build_pdp. unified_pdp.py now at 100% coverage. Remaining gaps are in OPA and Cedar engine adapters which require external sidecars to test. Signed-off-by: yiannis2804 <yiannis2804@gmail.com> * docs: add detailed README for unified PDP plugin Signed-off-by: yiannis2804 <yiannis2804@gmail.com> * fix(unified-pdp): fix bugs and improve tests - Fix undefined variable eng_type in pdp.py:get_effective_permissions() - Add shutdown() lifecycle method to UnifiedPDPPlugin to properly close HTTP clients for OPA/Cedar engines - Convert tests from respx to pytest-httpx (project standard) - Add test for shutdown() method Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * chore(unified-pdp): fix linting issues - Remove unused import List from mac_engine.py - Remove unused variable first_deny from pdp.py Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * fix(unified-pdp): address review findings from additional security review - Cache key now includes user_agent and context.extra to prevent incorrect cached decisions when policies depend on these fields (MAC operation override, OPA/Cedar context-based rules) - Plugin now extracts IP and user_agent from HTTP headers and passes to PDP context for policy evaluation - Plugin passes tool args to context.extra and resource metadata to resource.annotations for fine-grained policy checks - Exception handling in _evaluate_parallel/_evaluate_sequential now catches all exceptions (not just TimeoutError/PolicyEvaluationError) to prevent crashing the whole request on unexpected errors - Native RBAC docstring corrected: only JSON files are supported (not YAML) Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * fix(unified-pdp): extract classification_level for MAC engine Extract classification_level from tool args and resource metadata so MAC engine can make proper Bell-LaPadula decisions instead of always denying due to missing classification. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * docs: add docstrings for 100% interrogate coverage Add missing docstrings to all public functions and methods in the unified_pdp plugin to satisfy the project's 100% docstring coverage requirement enforced by interrogate. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * docs: add comprehensive Google-style docstrings to unified_pdp Add complete Args, Returns, Raises, and Attributes documentation to all public functions and methods in the unified_pdp plugin, matching the project's docstring style with full parameter descriptions. Files updated: - adapter.py: PolicyEvaluationError, PolicyEngineAdapter methods - cache.py: _build_cache_key, _CacheEntry, DecisionCache methods - pdp.py: PolicyDecisionPoint and all evaluation/combination methods - engines/cedar_engine.py: CedarEngineAdapter and all methods - engines/mac_engine.py: MACEngineAdapter and all methods - engines/native_engine.py: NativeRBACAdapter and all methods - engines/opa_engine.py: OPAEngineAdapter and all methods - unified_pdp.py: shutdown lifecycle method Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * docs: add __init__ docstring to PolicyEvaluationError Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> --------- Signed-off-by: yiannis2804 <yiannis2804@gmail.com> Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> Co-authored-by: Mihai Criveti <crivetimihai@gmail.com>
🔗 Related Issue
Closes #2223
This feature was developed as part of the SWENG Group 5 project (Trinity College Dublin).
📝 Summary
Adds a unified Policy Decision Point plugin that orchestrates access-control decisions across multiple policy engines (Native RBAC, MAC, OPA, Cedar) through a single gateway hook interface. The plugin hooks into
tool_pre_invokeandresource_pre_fetch, evaluates the request against enabled engines, and either passes through or blocks with aPluginViolation.🏷️ Type of Change
🧪 Verification
make lintmake testmake coverage✅ Checklist
make black isort pre-commit)📓 Notes (optional)
mode: disabled— safe default, no behaviour change until explicitly enabled.plugins/unified_pdp/README.md.all_must_allow|any_allow|first_match.