Gatekeeper RHACM Integration Skill
Automates complete OPA Gatekeeper integration with RHACM following ch-stark/gatekeeper-examples. Intelligently filters gatekeeper-library based on OpenShift SCC coverage.
Core Workflow
Step 1: Cluster Discovery & Gatekeeper Check
Get cluster version:
Use: mcp__kubernetes__resources_get
Parameters: apiVersion=config.openshift.io/v1, kind=ClusterVersion, name=version
Extract: status.desired.version
Determine platform:
- ClusterVersion found →
PLATFORM=openshift, SCC_FILTERING=true
- Not found →
PLATFORM=kubernetes, SCC_FILTERING=false
Check Gatekeeper Operator installation:
Use: mcp__kubernetes__namespaces_list
Check: namespace "gatekeeper-system" or "openshift-gatekeeper-system" exists
Use: mcp__kubernetes__resources_list
Parameters: apiVersion=apps/v1, kind=Deployment, namespace=gatekeeper-system
Check: gatekeeper-controller-manager and gatekeeper-audit deployments exist and Ready
Set Gatekeeper status:
- Deployments found and Ready →
GATEKEEPER_INSTALLED=true
- Not found or not Ready →
GATEKEEPER_INSTALLED=false
Output status:
✓ Cluster Discovery Complete
Platform: OpenShift 4.18.0
Gatekeeper: Installed ✓ (or: Not Installed - will be deployed via PolicyGenerator)
SCC Filtering: Enabled
Note: If GATEKEEPER_INSTALLED=false, the PolicyGenerator will include policy-install-gatekeeper with remediationAction: enforce to automatically install Gatekeeper on target clusters. This follows the ch-stark/gatekeeper-examples pattern where Gatekeeper installation is the first policy in the dependency chain.
Step 2: SCC Analysis (OpenShift Only)
Get SCC list: mcp__kubernetes__resources_list (security.openshift.io/v1 SecurityContextConstraints)
Get pod SCC distribution: mcp__kubernetes__pods_list, extract openshift.io/scc annotation
Fetch SCC specs via WebSearch: Query "OpenShift {version} {scc_name} SCC site:docs.openshift.com"
Calculate coverage using references/SCC_GATEKEEPER_MAPPING.md:
- ≥95% coverage →
SKIP (redundant)
- <95% coverage →
INCLUDE (gap-filling)
- No SCC equivalent →
INCLUDE (always)
Step 3: Generate PolicyGenerator
Create output directory:
TRACE_ID=$(python3 skills/gatekeeper-rhacm-integration/scripts/get_trace_id.py)
mkdir -p skills/gatekeeper-rhacm-integration/assets/${TRACE_ID}
Generate files following references/POLICYGENERATOR_TEMPLATE.md:
policyGenerator.yaml - Main PolicyGenerator (exact ch-stark format)
kustomization.yaml - Only references policyGenerator.yaml
gatekeeperlibrary/kustomization.yaml - SCC-filtered library resources
Gatekeeper Installation Policy:
- Always included in PolicyGenerator (following ch-stark pattern)
policy-install-gatekeeper with remediationAction: enforce
- Uses path:
https://raw.githubusercontent.com/ch-stark/gatekeeper-examples/main/gatekeeperinstall
- All subsequent policies depend on this via
dependencies chain
- If Gatekeeper already installed, policy reports Compliant immediately
Key difference from ch-stark/gatekeeper-examples:
gatekeeperlibrary/kustomization.yaml excludes policies with ≥95% SCC coverage
- See
references/SCC_FILTERED_LIBRARY.md for excluded policies
Step 4: Deploy to Cluster
Create policies namespace:
kubectl create namespace policies --dry-run=client -o yaml | kubectl apply -f -
Set up ArgoCD and Placements (from ch-stark/gatekeeper-examples):
# Apply setupgitops files in order
for i in 01 02 03; do
curl -sL https://raw.githubusercontent.com/ch-stark/gatekeeper-examples/main/setupgitops/${i}_*.yaml | kubectl apply -f -
done
# Wait for GitOps operator
sleep 30
# Apply remaining setup files (ArgoCD, Applications, Placements)
for i in 04 05 06 07 08 09; do
curl -sL https://raw.githubusercontent.com/ch-stark/gatekeeper-examples/main/setupgitops/${i}_*.yaml | kubectl apply --validate=false -f -
done
Install PolicyGenerator plugin:
# Download latest PolicyGenerator plugin
mkdir -p ~/.config/kustomize/plugin/policy.open-cluster-management.io/v1/policygenerator
curl -sL https://github.com/open-cluster-management-io/policy-generator-plugin/releases/latest/download/darwin-arm64-PolicyGenerator \
-o ~/.config/kustomize/plugin/policy.open-cluster-management.io/v1/policygenerator/PolicyGenerator
chmod +x ~/.config/kustomize/plugin/policy.open-cluster-management.io/v1/policygenerator/PolicyGenerator
Download manifest files locally (PolicyGenerator requires local paths):
cd assets/${TRACE_ID}
# Download all ch-stark manifest directories
python3 -c "
import urllib.request, json, os
base = 'https://api.github.com/repos/ch-stark/gatekeeper-examples/contents'
dirs = ['gatekeeperinstall', 'gatekeeperconfig', 'gatekeeperchecks',
'gatekeeperconstraint', 'extracontrainttemplates',
'checkadmissionevents', 'mutation', 'hub/templates',
'hub/constraints', 'verify-deprecatedapi']
for d in dirs:
os.makedirs(d, exist_ok=True)
with urllib.request.urlopen(f'{base}/{d}') as resp:
for f in json.load(resp):
if f.get('download_url'):
with urllib.request.urlopen(f['download_url']) as r:
with open(f\"{d}/{f['name']}\", 'wb') as out:
out.write(r.read())
"
Build and apply policies:
kustomize build --enable-alpha-plugins . | kubectl apply -n policies -f -
Label clusters for Gatekeeper deployment:
# Label managed clusters to receive Gatekeeper policies
kubectl label managedcluster local-cluster gatekeeper=true
kubectl label managedcluster <cluster-name> gatekeeper=true
Verify deployment:
# Check policies
kubectl get policies -n policies
# Check placements
kubectl get placement -n policies
# Check policy compliance (after MCH fully installed)
kubectl get policies -n policies -o custom-columns="NAME:.metadata.name,COMPLIANT:.status.compliant"
Trigger Phrases
- "Integrate Gatekeeper with RHACM"
- "Deploy gatekeeper-library to OpenShift with ACM"
- "Set up OPA Gatekeeper following ch-stark/gatekeeper-examples"
- "Enforce Gatekeeper policies on my cluster"
- "Apply the PolicyGenerator to my RHACM hub"
Key Sources
| Source |
Purpose |
| ch-stark/gatekeeper-examples |
PolicyGenerator structure, deployment patterns |
| gatekeeper-library |
ConstraintTemplates and Constraints |
references/POLICYGENERATOR_TEMPLATE.md |
Exact policyGenerator.yaml template |
references/SCC_GATEKEEPER_MAPPING.md |
SCC field to gatekeeper policy mapping |
references/SCC_FILTERED_LIBRARY.md |
Pre-computed OpenShift exclusion list |
Output Structure
assets/${TRACE_ID}/
├── policyGenerator.yaml # Main PolicyGenerator (local paths)
├── kustomization.yaml # generators: [policyGenerator.yaml]
├── gatekeeperlibrary/ # SCC-filtered gatekeeper-library
│ └── kustomization.yaml
├── gatekeeperinstall/ # Downloaded: Gatekeeper Operator subscription
├── gatekeeperconfig/ # Downloaded: Gatekeeper configuration
├── gatekeeperchecks/ # Downloaded: Gatekeeper health checks
├── gatekeeperconstraint/ # Downloaded: Constraint instances
├── extracontrainttemplates/ # Downloaded: Additional templates
├── checkadmissionevents/ # Downloaded: Admission event monitoring
├── mutation/ # Downloaded: Mutation policies
├── hub/
│ ├── templates/ # Downloaded: Hub-specific templates
│ └── constraints/ # Downloaded: Hub-specific constraints
├── verify-deprecatedapi/ # Downloaded: Deprecated API validation
└── DEPLOYMENT_REPORT.md # Summary report
Note: Manifest files are downloaded locally because the PolicyGenerator plugin does not support remote URLs. ArgoCD handles remote URL fetching when using GitOps workflow.
Troubleshooting
| Issue |
Cause |
Fix |
| Gatekeeper not installing |
OperatorPolicy has remediationAction: inform |
Change to enforce in gatekeeperinstall/gatekeepersubscription.yaml |
| ConstraintTemplate error: "unknown field" |
Invalid fields in template (listKind, plural, singular, scope) |
Remove extra fields, keep only kind in spec.crd.spec.names |
| Policy stuck on NonCompliant |
CRDs not cached by config-policy-controller |
Delete and recreate the policy to force refresh |
1---2name: gatekeeper-rhacm-integration3description: Automates OPA Gatekeeper integration with RHACM following ch-stark/gatekeeper-examples. Reads cluster version via MCP, compares gatekeeper-library policies against OpenShift SCCs, and generates optimized PolicyGenerator with SCC-filtered library inclusion.4---56# Gatekeeper RHACM Integration Skill78Automates complete OPA Gatekeeper integration with RHACM following [ch-stark/gatekeeper-examples](https://github.com/ch-stark/gatekeeper-examples). Intelligently filters [gatekeeper-library](https://github.com/open-policy-agent/gatekeeper-library) based on OpenShift SCC coverage.910## Core Workflow1112### Step 1: Cluster Discovery & Gatekeeper Check13141. **Get cluster version**:15 ```16 Use: mcp__kubernetes__resources_get17 Parameters: apiVersion=config.openshift.io/v1, kind=ClusterVersion, name=version18 Extract: status.desired.version19 ```20212. **Determine platform**:22 - ClusterVersion found → `PLATFORM=openshift`, `SCC_FILTERING=true`23 - Not found → `PLATFORM=kubernetes`, `SCC_FILTERING=false`24253. **Check Gatekeeper Operator installation**:26 ```27 Use: mcp__kubernetes__namespaces_list28 Check: namespace "gatekeeper-system" or "openshift-gatekeeper-system" exists29 ```3031 ```32 Use: mcp__kubernetes__resources_list33 Parameters: apiVersion=apps/v1, kind=Deployment, namespace=gatekeeper-system34 Check: gatekeeper-controller-manager and gatekeeper-audit deployments exist and Ready35 ```36374. **Set Gatekeeper status**:38 - Deployments found and Ready → `GATEKEEPER_INSTALLED=true`39 - Not found or not Ready → `GATEKEEPER_INSTALLED=false`40415. **Output status**:42 ```43 ✓ Cluster Discovery Complete4445 Platform: OpenShift 4.18.046 Gatekeeper: Installed ✓ (or: Not Installed - will be deployed via PolicyGenerator)47 SCC Filtering: Enabled48 ```4950**Note**: If `GATEKEEPER_INSTALLED=false`, the PolicyGenerator will include `policy-install-gatekeeper` with `remediationAction: enforce` to automatically install Gatekeeper on target clusters. This follows the ch-stark/gatekeeper-examples pattern where Gatekeeper installation is the first policy in the dependency chain.5152### Step 2: SCC Analysis (OpenShift Only)53541. **Get SCC list**: `mcp__kubernetes__resources_list` (security.openshift.io/v1 SecurityContextConstraints)55562. **Get pod SCC distribution**: `mcp__kubernetes__pods_list`, extract `openshift.io/scc` annotation57583. **Fetch SCC specs via WebSearch**: Query "OpenShift {version} {scc_name} SCC site:docs.openshift.com"59604. **Calculate coverage** using `references/SCC_GATEKEEPER_MAPPING.md`:61 - ≥95% coverage → `SKIP` (redundant)62 - <95% coverage → `INCLUDE` (gap-filling)63 - No SCC equivalent → `INCLUDE` (always)6465### Step 3: Generate PolicyGenerator66671. **Create output directory**:68 ```bash69 TRACE_ID=$(python3 skills/gatekeeper-rhacm-integration/scripts/get_trace_id.py)70 mkdir -p skills/gatekeeper-rhacm-integration/assets/${TRACE_ID}71 ```72732. **Generate files** following `references/POLICYGENERATOR_TEMPLATE.md`:74 - `policyGenerator.yaml` - Main PolicyGenerator (exact ch-stark format)75 - `kustomization.yaml` - Only references policyGenerator.yaml76 - `gatekeeperlibrary/kustomization.yaml` - SCC-filtered library resources77783. **Gatekeeper Installation Policy**:79 - Always included in PolicyGenerator (following ch-stark pattern)80 - `policy-install-gatekeeper` with `remediationAction: enforce`81 - Uses path: `https://raw.githubusercontent.com/ch-stark/gatekeeper-examples/main/gatekeeperinstall`82 - All subsequent policies depend on this via `dependencies` chain83 - If Gatekeeper already installed, policy reports Compliant immediately84854. **Key difference from ch-stark/gatekeeper-examples**:86 - `gatekeeperlibrary/kustomization.yaml` excludes policies with ≥95% SCC coverage87 - See `references/SCC_FILTERED_LIBRARY.md` for excluded policies8889### Step 4: Deploy to Cluster90911. **Create policies namespace**:92 ```bash93 kubectl create namespace policies --dry-run=client -o yaml | kubectl apply -f -94 ```95962. **Set up ArgoCD and Placements** (from ch-stark/gatekeeper-examples):97 ```bash98 # Apply setupgitops files in order99 for i in 01 02 03; do100 curl -sL https://raw.githubusercontent.com/ch-stark/gatekeeper-examples/main/setupgitops/${i}_*.yaml | kubectl apply -f -101 done102103 # Wait for GitOps operator104 sleep 30105106 # Apply remaining setup files (ArgoCD, Applications, Placements)107 for i in 04 05 06 07 08 09; do108 curl -sL https://raw.githubusercontent.com/ch-stark/gatekeeper-examples/main/setupgitops/${i}_*.yaml | kubectl apply --validate=false -f -109 done110 ```1111123. **Install PolicyGenerator plugin**:113 ```bash114 # Download latest PolicyGenerator plugin115 mkdir -p ~/.config/kustomize/plugin/policy.open-cluster-management.io/v1/policygenerator116 curl -sL https://github.com/open-cluster-management-io/policy-generator-plugin/releases/latest/download/darwin-arm64-PolicyGenerator \117 -o ~/.config/kustomize/plugin/policy.open-cluster-management.io/v1/policygenerator/PolicyGenerator118 chmod +x ~/.config/kustomize/plugin/policy.open-cluster-management.io/v1/policygenerator/PolicyGenerator119 ```1201214. **Download manifest files locally** (PolicyGenerator requires local paths):122 ```bash123 cd assets/${TRACE_ID}124125 # Download all ch-stark manifest directories126 python3 -c "127 import urllib.request, json, os128 base = 'https://api.github.com/repos/ch-stark/gatekeeper-examples/contents'129 dirs = ['gatekeeperinstall', 'gatekeeperconfig', 'gatekeeperchecks',130 'gatekeeperconstraint', 'extracontrainttemplates',131 'checkadmissionevents', 'mutation', 'hub/templates',132 'hub/constraints', 'verify-deprecatedapi']133 for d in dirs:134 os.makedirs(d, exist_ok=True)135 with urllib.request.urlopen(f'{base}/{d}') as resp:136 for f in json.load(resp):137 if f.get('download_url'):138 with urllib.request.urlopen(f['download_url']) as r:139 with open(f\"{d}/{f['name']}\", 'wb') as out:140 out.write(r.read())141 "142 ```1431445. **Build and apply policies**:145 ```bash146 kustomize build --enable-alpha-plugins . | kubectl apply -n policies -f -147 ```1481496. **Label clusters for Gatekeeper deployment**:150 ```bash151 # Label managed clusters to receive Gatekeeper policies152 kubectl label managedcluster local-cluster gatekeeper=true153 kubectl label managedcluster <cluster-name> gatekeeper=true154 ```1551567. **Verify deployment**:157 ```bash158 # Check policies159 kubectl get policies -n policies160161 # Check placements162 kubectl get placement -n policies163164 # Check policy compliance (after MCH fully installed)165 kubectl get policies -n policies -o custom-columns="NAME:.metadata.name,COMPLIANT:.status.compliant"166 ```167168## Trigger Phrases169170- "Integrate Gatekeeper with RHACM"171- "Deploy gatekeeper-library to OpenShift with ACM"172- "Set up OPA Gatekeeper following ch-stark/gatekeeper-examples"173- "Enforce Gatekeeper policies on my cluster"174- "Apply the PolicyGenerator to my RHACM hub"175176## Key Sources177178| Source | Purpose |179|--------|---------|180| [ch-stark/gatekeeper-examples](https://github.com/ch-stark/gatekeeper-examples) | PolicyGenerator structure, deployment patterns |181| [gatekeeper-library](https://github.com/open-policy-agent/gatekeeper-library) | ConstraintTemplates and Constraints |182| `references/POLICYGENERATOR_TEMPLATE.md` | Exact policyGenerator.yaml template |183| `references/SCC_GATEKEEPER_MAPPING.md` | SCC field to gatekeeper policy mapping |184| `references/SCC_FILTERED_LIBRARY.md` | Pre-computed OpenShift exclusion list |185186## Output Structure187188```189assets/${TRACE_ID}/190├── policyGenerator.yaml # Main PolicyGenerator (local paths)191├── kustomization.yaml # generators: [policyGenerator.yaml]192├── gatekeeperlibrary/ # SCC-filtered gatekeeper-library193│ └── kustomization.yaml194├── gatekeeperinstall/ # Downloaded: Gatekeeper Operator subscription195├── gatekeeperconfig/ # Downloaded: Gatekeeper configuration196├── gatekeeperchecks/ # Downloaded: Gatekeeper health checks197├── gatekeeperconstraint/ # Downloaded: Constraint instances198├── extracontrainttemplates/ # Downloaded: Additional templates199├── checkadmissionevents/ # Downloaded: Admission event monitoring200├── mutation/ # Downloaded: Mutation policies201├── hub/202│ ├── templates/ # Downloaded: Hub-specific templates203│ └── constraints/ # Downloaded: Hub-specific constraints204├── verify-deprecatedapi/ # Downloaded: Deprecated API validation205└── DEPLOYMENT_REPORT.md # Summary report206```207208**Note**: Manifest files are downloaded locally because the PolicyGenerator plugin does not support remote URLs. ArgoCD handles remote URL fetching when using GitOps workflow.209210## Troubleshooting211212| Issue | Cause | Fix |213|-------|-------|-----|214| Gatekeeper not installing | OperatorPolicy has `remediationAction: inform` | Change to `enforce` in `gatekeeperinstall/gatekeepersubscription.yaml` |215| ConstraintTemplate error: "unknown field" | Invalid fields in template (listKind, plural, singular, scope) | Remove extra fields, keep only `kind` in `spec.crd.spec.names` |216| Policy stuck on NonCompliant | CRDs not cached by config-policy-controller | Delete and recreate the policy to force refresh |