$ c2pcli ocm -h
C2P CLI OCM plugin
Usage:
c2pcli ocm [command]
Available Commands:
oscal2policy Compose deliverable OCM Policies from OSCAL
result2oscal Generate OSCAL Assessment Results from OCM Policy statuses
tools Tools
Flags:
-h, --help help for ocm
Use "c2pcli ocm [command] --help" for more information about a command.
- Install Policy Generator Plugin
- Prepare OCM Policy Resources
- You can use policy-resources for test
- You can also use Policy Collection. Please see C2P Decomposer
- Create OSCAL Component Definition
- Use example one. In real cases, a user writes OSCAL by Authoring tool like Trestle)
- Run oscal2policy to generate OCM Policies from OSCAL
- Deploy generated OCM Policies to OCM Hub
- Get OCM Policies from OCM Hub
- Run result2oscal to generate OSCAL Assessment Results from the OCM Policy Results
- Prettify OSCAL Assessment Results
- Use C2P tools. In real cases, it's responsible of GRC tools.
- Prerequisites
- OCM is configured to manage two k8s clusters (cluster1 and cluster2) and installed Policy Governance Framework.
- Namespace
c2p
is created in OCM Hub - The managed clusters are labeled
my-cluster=true
and bound toc2p
namespace$ clusteradm get clustersets <ManagedClusterSet> └── <default> │ ├── <BoundNamespace> │ ├── <Status> 2 ManagedClusters selected │ ├── <Clusters> [cluster1 cluster2] └── <global> │ ├── <BoundNamespace> │ ├── <Status> 2 ManagedClusters selected │ ├── <Clusters> [cluster1 cluster2] └── <myclusterset> └── <BoundNamespace> c2p └── <Status> 2 ManagedClusters selected └── <Clusters> [cluster1 cluster2]
- Run oscal2policy to generate OCM Policies from OSCAL
c2pcli ocm oscal2policy -c ./docs/ocm/c2p-config.yaml -o /tmp/ocm-policies
- The generated ocm-policies directory looks like ./final-outputs/ocm-policies
- Deploy the generated OCM Policies to OCM Hub
kubectl create -f /tmp/ocm-policies
- Wait for policies to be delivered
$ kubectl get policy -A NAMESPACE NAME REMEDIATION ACTION COMPLIANCE STATE AGE c2p policy-deployment inform NonCompliant 5m15s c2p policy-high-scan inform NonCompliant 5m15s c2p policy-install-kyverno-from-manifests enforce Compliant 5m14s c2p policy-kyverno-require-labels NonCompliant 5m14s cluster1 c2p.policy-deployment inform NonCompliant 2m15s cluster1 c2p.policy-high-scan inform NonCompliant 2m15s cluster1 c2p.policy-install-kyverno-from-manifests enforce Compliant 2m14s cluster1 c2p.policy-kyverno-require-labels NonCompliant 2m11s cluster2 c2p.policy-deployment inform NonCompliant 2m15s cluster2 c2p.policy-high-scan inform NonCompliant 2m15s cluster2 c2p.policy-install-kyverno-from-manifests enforce Compliant 2m14s cluster2 c2p.policy-kyverno-require-labels NonCompliant 2m11s
- Get OCM Policy Results (Policy, PolicySet, PlacementDecision) from OCM Hub
mkdir -p /tmp/results kubectl get policies.policy.open-cluster-management.io -A -o yaml > /tmp/results/policies.policy.open-cluster-management.io.yaml kubectl get policysets.policy.open-cluster-management.io -A -o yaml > /tmp/results/policysets.policy.open-cluster-management.io.yaml kubectl get placementdecisions.cluster.open-cluster-management.io -A -o yaml > /tmp/results/placementdecisions.cluster.open-cluster-management.io.yaml
- Run result2oscal to generate OSCAL Assessment Results from the OCM Policy Results
c2pcli ocm result2oscal -c ./docs/ocm/c2p-config.yaml --results /tmp/results -o /tmp/assessment-results.json
- Prettify OSCAL Assessment Results in .md format
c2pcli ocm tools oscal2posture -c ./docs/ocm/c2p-config.yaml --assessment-results /tmp/assessment-results.json -o /tmp/compliance-posture.md
- You can view the compliance posture like ./final-outputs/compliance-posture.md
c2p-gitops-sample.mp4
Setup Github Repos
- Create two repositories (one is configuration repository that's used for pipeline from OSCAL to Policy and another is evidence repository that's used for pipeline from OCM statuses to Compliance result)
- For example, c2p-for-ocm-pipeline01-config and c2p-for-ocm-pipeline01-evidence
- Create Github Personal Access Token having following permissions
- Repository permission of
Contents
,Pull Requests
, andWorkflows
with read-and-write against both the configuration repository and the evidence repository.
- Repository permission of
- Fork C2P repository (yana1205/compliance-to-policy.git) and checkout
template
- Set required parameters for github action to initialize your configuration and evidence repo
- Go to Settings tab
- Go to
Actions
underSecrets and variables
- Create
New repository secret
- Name: PAT
- Secret: Created Github Personal Access Token
- Go to
Variables
tab to createNew repository variable
- Create
CONFIGURATION_REPOSITORY
variable- Name: CONFIGURATION_REPOSITORY
- Value:
<configuration repository org>/<configuration repository name> (e.g. yana1205/c2p-for-ocm-pipeline01-config)
- Create
EVIDENCE_REPOSITORY
variable- Name: EVIDENCE_REPOSITORY
- Value:
<evidence repository org>/<evidence repository name> (e.g. yana1205/c2p-for-ocm-pipeline01-evidence)
- Run Action
Initialize repositories
with branchtemplate
- Go to the configuration repository and create
New repository secret
- Name: PAT
- Secret: Created Github Personal Access Token
- Go to the evidence repository and create
New repository secret
- Name: PAT
- Secret: Created Github Personal Access Token
Run oscal-to-pocliy
- Go to the configuration repository
- Go to
Actions
tab - Run
OSCAL to Policy
- This action generates manifests from OSCAL and then generate a PR of changes for a directory
ocm-policy-manifests
containing the generated manifests.
- This action generates manifests from OSCAL and then generate a PR of changes for a directory
- Merge the PR
Integrate with GitOps
- Sync
ocm-policy-manifests
directory with your OCM Hub by OCM GitOps (OCM Channel and Subscription addon)
Deploy collector to your OCM Hub
- Apply RBAC for collector
kubectl apply -f https://raw.githubusercontent.com/yana1205/compliance-to-policy/redesign.0622/scripts/collect/rbac.yaml
- Create Secret for Github access
e.g.
kubectl -n c2p create secret generic --save-config collect-ocm-status-secret --from-literal=user=<github user> --from-literal=token=<github PAT> --from-literal=org=<evidence org name> --from-literal=repo=<evidence repo name>
kubectl -n c2p create secret generic --save-config collect-ocm-status-secret --from-literal=user=yana1205 --from-literal=token=github_pat_xxx --from-literal=org=yana1205 --from-literal=repo=c2p-for-ocm-pipeline01-evidence
- Deploy collector cronjob
kubectl apply -f https://raw.githubusercontent.com/IBM/compliance-to-policy/main/scripts/collect/cronjob.yaml
Cleanup
kubectl delete -f https://raw.githubusercontent.com/IBM/compliance-to-policy/main/scripts/collect/cronjob.yaml
kubectl -n c2p delete secret collect-ocm-status-secret
kubectl delete -f https://raw.githubusercontent.com/IBM/compliance-to-policy/main/scripts/collect/rbac.yaml
Decompose OCM poicy collection to kubernetes resources composing each OCM policy (we call it policy resource).
- Clone Policy Collection
git clone --depth 1 https://github.com/open-cluster-management-io/policy-collection.git /tmp/policy-collection
- Run C2P Decomposer
go run ./cmd/decompose/decompose.go --policy-collection-dir=/tmp/policy-collection --out=/tmp/c2p-output
- Decomposed policy resources are ouput in
/tmp/c2p-output/decomposed/resources
Individual decomposed resource contains k8s manifests and configuration files (policy-generator.yaml and kustomization.yaml) for PolicyGenerator.$ tree -L 1 /tmp/c2p-output/decomposed /tmp/c2p-output/decomposed ├── _sources └── resources
$ tree -L 3 /tmp/c2p-output/decomposed/resources /tmp/c2p-output/decomposed/resources ├── add-chrony │ ├── add-chrony-worker │ │ └── MachineConfig.50-worker-chrony.0.yaml │ ├── kustomization.yaml │ └── policy-generator.yaml ├── add-tvk-license │ ├── add-tvk-license │ │ └── License.triliovault-license.0.yaml │ ├── kustomization.yaml
Compose OCM Policy from policy resources from compliance information (for example, compliance.yaml)
- Run C2P Composer
go run cmd/compose-by-c2pcr/main.go --c2pcr ./cmd/compose-by-c2pcr/c2pcr.yaml --out /tmp/c2p-output
- Composed OCM policies are output in
/tmp/c2p-output
$ tree /tmp/c2p-output /tmp/c2p-output ├── add-chrony │ ├── add-chrony-worker │ │ └── MachineConfig.50-worker-chrony.0.yaml │ ├── kustomization.yaml │ └── policy-generator.yaml ├── install-odf-lvm-operator │ ├── kustomization.yaml │ ├── odf-lvmcluster │ │ └── LVMCluster.odf-lvmcluster.0.yaml │ ├── policy-generator.yaml │ └── policy-odf-lvm-operator │ ├── Namespace.openshift-storage.0.yaml │ ├── OperatorGroup.openshift-storage-operatorgroup.0.yaml │ └── Subscription.lvm-operator.0.yaml ├── kustomization.yaml ├── policy-generator.yaml └── policy-sets.yaml
- Build image
make docker-build docker-push IMG=<controller image>
- Create KinD cluster
kind create cluster
- Install (if you use OCM, install-ocm-related-crds may fail since the required CRDs are already there.)
make install make install-ocm-related-crds
- Deploy
make deploy IMG=<controller image>
- Create CR
kubectl apply -f ./config/samples/compliance-to-policy_v1alpha1_compliancedeployment.yaml -n compliance-to-policy-system
- Check if Policy, PlacmenetBinding/Rule are created
kubectl get policies,placementbindings,placementrules -n compliance-high
- Cleanup
make undeploy make uninstall