Compliance-to-Policy (also known as C2P)
Compliance-to-Policy (C2P) is designed to bridge Compliance as Code such as Open Security Controls Assessment Language (OSCAL) and Policy as Code used by Policy Validation Point (PVP). It generates policies in native format of PVP from OSCAL Component Definitions, and turns the native assessment results of PVP into OSCAL Assessment Results and a control-level compliance posture. C2P can be used both as a command-line tool and a Python library, making it easy and flexible to integrate into your Continuous Compliance pipelines, such as GitHub Actions, Tekton Pipelines, or Agile Authoring Pipelines. Custom plugins can be implemented with a small amount of Python code.
C2P++ is C2P with an agent skill added to its policy generation, automating the production of the engine-specific policy templates. A component definition names the checks that verify each rule. C2P produces the target engine's native policy from the template that corresponds to each check. Until now those templates had to be prepared in advance. A check added to a component definition produced no policy until someone had written the template for it. In C2P++ an agent skill, skills/policy-generation, produces that engine-specific template.
- Compliance-to-Policy (C2P) is running in GitOps Pipeline, Kubernetes controller, or Python/Go environment
- C2P receives Compliance as Code, for example OSCAL Component Definition that represents mapping between controls and policies (policy names/ids)
- C2P generates policies through plugin for each policy engine
- The plugin is responsible for implementing a function that takes policy names/ids and returns policies
- Policies are delivered to policy engines by GitOps sync, the subsequence pipeline task, Kubernetes controller, or a deployment automation program
- Results are collected from policy engines by a scheduled task or Kubernetes controller
- C2P aggregates the results of policy engines by controls through plugin for each policy engine
- The plugin is responsible for implementing a function that takes the results of the policy engine and returns verdicts (pass/fail/error), reason, and/or resource name for each respective policy by its names/IDs.
- C2P produces Compliance Assessment Results, for example OSCAL Assessment Results that represents the assessment results of each control
That chain run for real, step by step, is the end-to-end walkthrough on Kubernetes: one NIST SP 800-53 control to a compliance posture against a live cluster, with the captured output of every command. There is a recording of the demo as well.
Goals
Provide seamless integration with compliance frameworks and existing policy engines, and enable to use heterogeneous policy engines in compliance check operation
- Flexibility in choise of policy engines and compliance frameworks
- Provide plugins to cover various policy engines including proprietary/open source policy validation/enforcement engines, or in-house policy validation/enforcement program
- Cover various compliance frameworks not only OSCAL but also other GRC frameworks and Cloud Security Posture Management services
- Community-driven plugin extension
- Provide an efficient plugin interface and development method
Supported Compliance Frameworks
- Open Security Controls Assessment Language (OSCAL)
- OSCAL standard provides a compliance framework and the corresponding set of key compliance artifacts expressed in machine processable formats enabling all compliance documents to be treated as code and therefore processed and managed in the same manner.
Supported Policy Engines
- Kyverno (for Kubernetes resources)
- Kyverno is a policy engine designed for Kubernetes, where policies are managed as Kubernetes resources. Kyverno policies can validate, mutate, generate, and clean up Kubernetes resources.
- Two policy languages are supported, by separate plugins.
kyverno.io/v1 ClusterPolicyis the original DSL, deprecated in Kyverno 1.19 and removed in 1.20;policies.kyverno.io/v1is its CEL-based replacement. Both are generated from the same component definition, which is the argument for authoring the control rather than the policy
- ValidatingAdmissionPolicy (for Kubernetes resources)
- Upstream Kubernetes, CEL evaluated inside the API server, no controller to install. It decides at admission time only: it runs no background scan over objects that already exist and publishes no report, so C2P obtains its verdicts by replaying a workload as a server-side dry run. What CEL in the API server cannot do — fetch from a registry, read another object — is a limit on which checks an estate can express with it, which is visible in the posture as coverage rather than hidden
- Open Cluster Management Policy Framework (for Kubernetes resources)
- OCM is a multi-cluster management platform that provides governance of Kubernetes policies. Its policy framework allows for the validation and enforcement of policies across multiple clusters.
- Auditree (for any target, especially well-suited for resources of PaaS/SaaS/IaaS available through REST API.)
- Auditree is a GitOps based workflow automation that enables the collection and verification of evidence, building a long-term store of evidence in an git "evidence locker." Evidence is gathered by code scripts called "fetchers" and verified by "checks."
Roadmap:
- OPA/Gatekeeper (for Kubernetes resources)
- Ansible (for any target, especially for VMs and OnPremise hosts)
C2P in Go language
The Go verion is available in the go directory.
Install
From git repo
pip install git+https://github.com/oscal-compass/compliance-to-policy.git
You may be asked passphrase of SSH key to access to the git repo.
From source
- Clone the repository
git clone https://github.com/oscal-compass/compliance-to-policy.git - Go to
compliance-to-policycd compliance-to-policy - Install
make install
Quick demo
- Generate Kyverno Policy (C2P Compliance to Policy)
E.g.python samples_public/kyverno/compliance_to_policy.py -o /tmp/deliverable-policy$ python samples_public/kyverno/compliance_to_policy.py -o /tmp/deliverable-policy tree /tmp/deliverable-policy disallow-capabilities - disallow-capabilities.yaml allowed-base-images - 02-setup-cm.yaml - allowed-base-images.yaml - Deploy the generated policies
E.g.kubectl apply -R -f /tmp/deliverable-policy$ kubectl apply -R -f /tmp/deliverable-policy namespace/platform created configmap/baseimages created Warning: Validation failure actions enforce/audit are deprecated, use Enforce/Audit instead. clusterpolicy.kyverno.io/allowed-base-images created clusterpolicy.kyverno.io/disallow-capabilities created - Check policy results
$ kubectl get policyreport,clusterpolicyreport -A NAMESPACE NAME PASS FAIL WARN ERROR SKIP AGE kube-system policyreport.wgpolicyk8s.io/cpol-allowed-base-images 0 12 0 0 0 19s kube-system policyreport.wgpolicyk8s.io/cpol-disallow-capabilities 9 2 0 0 0 19s kyverno policyreport.wgpolicyk8s.io/cpol-allowed-base-images 0 18 0 0 0 9s kyverno policyreport.wgpolicyk8s.io/cpol-disallow-capabilities 18 0 0 0 0 9s local-path-storage policyreport.wgpolicyk8s.io/cpol-allowed-base-images 0 3 0 0 0 16s local-path-storage policyreport.wgpolicyk8s.io/cpol-disallow-capabilities 3 0 0 0 0 16s - Collect policy/cluster policy reports as PVP Raw results
kubectl get policyreport -A -o yaml > /tmp/policyreports.wgpolicyk8s.io.yaml kubectl get clusterpolicyreport -o yaml > /tmp/clusterpolicyreports.wgpolicyk8s.io.yaml - Generate Assessment Result (C2P Result to Compliance)
python samples_public/kyverno/result_to_compliance.py \ -polr /tmp/policyreports.wgpolicyk8s.io.yaml \ -cpolr /tmp/clusterpolicyreports.wgpolicyk8s.io.yaml \ > /tmp/assessment_results.json - OSCAL Assessment Results is not human readable format. You can see the merged report in markdown by a quick viewer.
e.g. kyverno.result.mdc2p tools viewer -ar /tmp/assessment_results.json -cdef ./plugins_public/tests/data/kyverno/component-definition.json -o /tmp/assessment_results.md - (Optional) Render a control-level compliance posture instead. Unlike the viewer, the posture
is a document in its own right --
jsonis thec2p-posture/v1model, andmdandhtmlare views over it -- so it can be diffed, served and re-rendered.
The posture is accountable for every check the component definition declares, so a check no engine reported is ac2p tools result2posture -ar /tmp/assessment_results.json -cdef ./plugins_public/tests/data/kyverno/component-definition.json -f html -o /tmp/posture.html # and as the c2p-posture/v1 document, which is what posture-compare reads c2p tools result2posture -ar /tmp/assessment_results.json -cdef ./plugins_public/tests/data/kyverno/component-definition.json -f json -o /tmp/posture.jsonnot-assessedrow rather than an omission, and each control carriescoveragealongside its state. Repeat-arto combine several Assessment Results into one posture. - (Optional) Compare two postures control by control, to see which controls stop being
assessed under a narrower set of engines. Both inputs are
-f jsonpostures, each produced from its own collection -- below, a second one collected withvap-celalone.c2p tools posture-compare -b /tmp/posture.json -p /tmp/posture-vap-only.json \ --baseline-label 'every engine' --posture-label 'vap-cel only' \ --condition 'when only ValidatingAdmissionPolicy is available'
Usage of C2P Plugins
- Kyverno
- Kubernetes policy engines — Kyverno DSL, Kyverno CEL and ValidatingAdmissionPolicy
- Open Cluster Management Governance Policy Framework
- Auditree
- Heterogeneous PVPs (mixing Kyverno, OCM Policy, and Auditree)
- The compliance posture —
c2p tools result2postureandposture-compare, and thec2p-posture/v1document
Usage of C2P as a library
Generate PVP Policies from Compliance
- Create
C2PConfigobject to supply compliance requirements and some metadata (See also kyverno/compliance_to_policy.py for a real example)c2p_config = C2PConfig() c2p_config.compliance = ComplianceOscal() c2p_config.compliance.component_definition = 'plugins_public/tests/data/kyverno/component-definition.json' c2p_config.pvp_name = 'Kyverno' c2p_config.result_title = 'Kyverno Assessment Results' c2p_config.result_description = 'OSCAL Assessment Results from Kyverno'
- Select a plugin for supported PVPs (
PluginKyverno,PluginOCM) and createPluginConfigobject to supply plugin specific propertiesfrom plugins_public.plugins.kyverno import PluginConfigKyverno, PluginKyverno policy_template_dir = 'plugins_public/tests/data/kyverno/policy-resources' config = PluginConfigKyverno(policy_template_dir=policy_template_dir, deliverable_policy_dir='/tmp/deliverable-policies')
- Create
C2PandPluginc2p = C2P(c2p_config) plugin = PluginKyverno(config)
- Get policy from
c2pand generate PVP policy bygenerate_pvp_policy()policy = c2p.get_policy() plugin.generate_pvp_policy(policy)
- The deliverable policies are output in '/tmp/deliverable-policies'
$ tree /tmp/deliverable-policy /tmp/deliverable-policy ├── allowed-base-images │ ├── 02-setup-cm.yaml │ └── allowed-base-images.yaml └── disallow-capabilities └── disallow-capabilities.yaml
Rule parameters
get_policy() resolves each parameter a rule declares, in this order:
- the value in the component definition's
set-parameters - the
Parameter_Value_Defaultprop - the
Parameter_Value_Alternativesprop
set-parameters wins because it is the resolved value: trestle's csv-to-oscal-cd writes
parameter values there and leaves only the id in the props, so reading the props alone yields
parameters with nothing in them.
Parameters are read from every component that is not a validation component, and a rule can
declare several by numbering the prop columns — Parameter_Id_2, Parameter_Value_Default_2,
and so on.
Behaviour change — check your generated output after upgrading. Four things differ from earlier releases, and a component definition that generated correctly before can generate different policy now:
Before Now Where the value comes from Parameter_Value_Alternativesonlyset-parameters, thenParameter_Value_Default, thenParameter_Value_AlternativesWhich components are read only the last non-validation component — the loop overwrote its accumulator each time round, so a component definition with several service components silently used one of them every non-validation component Numbered columns only the unnumbered Parameter_IdParameter_Id,Parameter_Id_2, …A parameter declared twice — the later value wins, silently, in every plugin that turns the list into a {id: value}mapping — the three Kubernetes plugins,kyvernoandocm.auditreeiterates the list instead and sees both
A parameter with no value anywhere renders as an empty string. It is logged as a warning and
substituted as ''. StrictUndefined does not catch it — the variable is defined, it is empty —
so a check written as image.startsWith({{ params.approved_registry | quote }}) becomes
image.startsWith("") and asserts nothing. Read the generated policy, and treat a parameter
warning in the log as a generation failure until the value is supplied.
Generate Compliance Assessment Results from PVP native results
-
Create
C2PConfigobject to supply compliance requirements and some metadata (See also kyverno/compliance_to_policy.py for a real example)c2p_config = C2PConfig() c2p_config.compliance = ComplianceOscal() c2p_config.compliance.component_definition = 'plugins_public/tests/data/kyverno/component-definition.json' c2p_config.pvp_name = 'Kyverno' c2p_config.result_title = 'Kyverno Assessment Results' c2p_config.result_description = 'OSCAL Assessment Results from Kyverno'
-
Select a plugin for supported PVPs (
PluginKyverno,PluginOCM) and createPluginConfigobject to supply plugin specific propertiesfrom plugins_public.plugins.kyverno import PluginConfigKyverno, PluginKyverno config = PluginConfigKyverno()
-
Create
C2PandPluginc2p = C2P(c2p_config) plugin = PluginKyverno(config)
-
Load PVP native results
policy_report_file = 'plugins_public/tests/data/kyverno/policyreports.wgpolicyk8s.io.yaml' cluster_policy_report_file = 'plugins_public/tests/data/kyverno/clusterpolicyreports.wgpolicyk8s.io.yaml' policy_report = yaml.safe_load(pathlib.Path(policy_report_file).open('r')) cluster_policy = yaml.safe_load(pathlib.Path(cluster_policy_report_file).open('r')) pvp_raw_result = RawResult(data=policy_report['items'] + cluster_policy['items'])
-
Call
generate_pvp_result()of the plugin to get a formatted PVP resultpvp_result = PluginKyverno().generate_pvp_result(pvp_raw_result)
-
Create
C2Pand callresult_to_oscal()to obtain Compliance Assessment Resultsc2p.set_pvp_result(pvp_result) oscal_assessment_results = c2p.result_to_oscal() print(oscal_assessment_results.oscal_serialize_json(pretty=True))
A cluster typically runs more than one policy engine, and each is assessed on its own. Call
add_pvp_result()once per engine instead ofset_pvp_result(), andresult_to_oscal()aggregates them into one Assessment Results document:for pvp_result in [kyverno_dsl_result, kyverno_cel_result, vap_result]: c2p.add_pvp_result(pvp_result) oscal_assessment_results = c2p.result_to_oscal()
One document per engine would make the artifact an accident of how the assessment was organised rather than a statement about the system, and anything reading it would have to know to look for several files.
Where the engines are collected by separate pipelines and aggregating in one process is not possible, each run produces its own Assessment Results and
c2p tools result2posturetakes a repeated-arto bring them back together.Every observation carries an
assessment-check-idprop as well asassessment-rule-id. One rule is routinely implemented by several PVPs, so a rule id alone cannot say which engine reported an observation, and a reader of the Assessment Results -- includingc2p tools result2posture-- has no way to attribute it. -
(Optional) you may reformat OSCAL Assessment Results in markdown style.
c2p tools viewer -ar <OSCAL Assessment Results (json)> -cdef ./plugins_public/tests/data/ocm/component-definition.json -o /tmp/assessment_results.md
How to support your own PVP in C2P
You can create a custom plugin by overriding PluginSpec and PluginConfig.
PluginSpec has two interfaces generate_pvp_policy and generate_pvp_result.
C2P framework will instantiate PluginSpec with PluginConfig.
A plugin whose generated artifact is one document per check renders it from a template, and
writing those templates is the part that needs engine knowledge rather than c2p knowledge. The
agent skill in skills/policy-generation/ covers it: the
template contract, the three Kubernetes engines and the shape each one wants, what an engine
cannot express (and why declaring no check is the right answer when it cannot), and how to
verify generated policy byte for byte.
PluginConfig
- Extend PluginConfig with custom fields as the plugin needs
from c2p.framework.plugin_spec import PluginSpec class YourPluginConfig(PluginConfig): custom_field: str = Field(..., title='Custom field for your plugin')
- Extend PluginSpec and define init with YourPluginConfig
class YourPlugin(PluginSpec): def __init__(self, config: Optional[YourPluginConfig] = None) -> None: super().__init__() self.config = config # work on config
PluginSpec.generate_pvp_policy
generate_pvp_policy()inPluginSpecaccepts one argumentpolicy: c2p.framework.models.Policy. The object has two fields (rule_setsandparameters).rule_setsandparametersare a list of Rule_Id, Check_Id, Parameter_Id, Parameter_Value, etc of the components handled by your PVP in OSCAL Component Definition.- Implement the logic to generate PVP policy from provided rule_sets and parameters.
def generate_pvp_policy(self, policy: Policy): rule_sets: List[RuleSet] = policy.rule_sets parameters: List[Parameter] = policy.parameters # generate deliverable policy from rule_sets and parameters
PluginSpec.generate_pvp_result
-
generate_pvp_result()is expected to generate the summarized raw results of your PVP per unit inPVPResultformat. This unit must be associated with a unique id called Check_Id. For example of PluginKyverno, Policy Reports is the raw results and are summarized by policy name.def generate_pvp_result(self, raw_result: RawResult) -> PVPResult: pvp_result: PVPResult = PVPResult() observations: List[ObservationByCheck] = [] polrs = list( filter( lambda x: x['apiVersion'] == 'wgpolicyk8s.io/v1alpha2' and x['kind'] == 'PolicyReport', raw_result.data ) ) cpolrs = list( filter( lambda x: x['apiVersion'] == 'wgpolicyk8s.io/v1alpha2' and x['kind'] == 'ClusterPolicyReport', raw_result.data, ) ) results = [] for polr in polrs: for result in polr['results']: results.append(result) for cpolr in cpolrs: for result in cpolr['results']: results.append(result) policy_names = list(map(lambda x: x['policy'], results)) # policy_name is used as check_id policy_names = set(policy_names) for policy_name in policy_names: observation = ObservationByCheck(check_id=policy_name, methods=['AUTOMATED'], collected=get_datetime())
-
The input argument
raw_resulthasdatafield that is serialized raw results as dict. You can define your preferable format of the data. C2P Framework will pass PVP native results to plugin with this format.
Publish plugin
- Put the plugin in plugin directory /plugins_public/plugins or Python module path when you use C2P.
Development
Developing
- Install Python
$ python --version Python 3.10.12 - Setup venv
python -m venv .venv - Install dependant modules
make install-dev - Enable detect-secret
pre-commit install
Test
$ make test
plugins_public/tests/plugins/test_kyverno.py::test_kyverno_pvp_result_to_compliance PASSED [ 25%]
plugins_public/tests/plugins/test_kyverno.py::test_kyverno_compliance_to_policy PASSED [ 50%]
plugins_public/tests/plugins/test_ocm.py::test_ocm_pvp_result_to_compliance PASSED [ 75%]
plugins_public/tests/plugins/test_ocm.py::test_ocm_compliance_to_policy
------------------------------------------------------------------------------------------ live log call -------------------------------------------------------------------------------------------
2024-04-25 05:31:48 [ INFO] The deliverable policy directory '/var/folders/yx/1mv5rdh53xd93bphsc459ht00000gn/T/tmpxtvpcrpr/deliverable-policy' is not found. Creating... (ocm.py:191)
PASSED [100%]
======================================================================================== 4 passed in 0.31s =========================================================================================
tests/c2p/framework/test_c2p.py::test_result_to_oscal PASSED [ 33%]
tests/c2p/test_cli.py::test_run PASSED [ 66%]
tests/c2p/test_cli.py::test_version PASSED [100%]
======================================================================================== 3 passed in 0.26s =========================================================================================
Cleanup caches
make clean
License & Authors
If you would like to see the detailed LICENSE click here. Consult contributors for a list of authors and maintainers for the core team.
# Copyright (c) 2024 The OSCAL Compass Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
We are a Cloud Native Computing Foundation sandbox project.
The Linux Foundation® (TLF) has registered trademarks and uses trademarks. For a list of TLF trademarks, see Trademark Usage.
OSCAL Compass is an independent open source project. It is not affiliated with, endorsed by, or sponsored by the National Institute of Standards and Technology (NIST) or any other government agency.
OSCAL Compass was originally contributed by IBM.
Metadata
Release files for compliance-to-policy 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| compliance_to_policy-1.0.0.tar.gz | 52.7 kB | With provenance | Details for compliance_to_policy-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| compliance_to_policy-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for compliance_to_policy-1.0.0-py3-none-any.whl |
Total release size: 118.3 kB
Release files / compliance_to_policy-1.0.0.tar.gz
| Download URL | compliance_to_policy-1.0.0.tar.gz |
|---|---|
| Size | 52.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3fdb1fc3286e9e891427aebe25fe7a1e1612929899c1959dc043aeb76b6138d1
|
|
BLAKE2b-256 checksum How to use checksums |
6cc3e9fd97aae7ca522695bd0945653f7ad3a513d9a81099e4b128b9dd9c2d38
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.
Transparency logRelease files / compliance_to_policy-1.0.0-py3-none-any.whl
| Download URL | compliance_to_policy-1.0.0-py3-none-any.whl |
|---|---|
| Size | 65.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
37db2a93969d8d7471d360d9a7d4de6c3af0740400125a3ed626212989bf3a1a
|
|
BLAKE2b-256 checksum How to use checksums |
89a8c13c2ff074ed0b84e44e05d5780d9d8b551c8210d525d2704e875f11ab42
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.
Transparency logSecurity for compliance-to-policy 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for compliance_to_policy-1.0.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.