मुख्य सामग्री पर जाएँ
Skillpedia
सिक्योरिटी35k · #8098

implementing-policy-as-code-with-open-policy-agent

यह क्या करती है

यह टूल आपके कंप्यूटर सिस्टम (खासकर Kubernetes) को सुरक्षा और संगठन के नियमों का पालन करवाने में मदद करता है। यह उन कॉन्फ़िगरेशन की जाँच करता है और उन्हें ब्लॉक करता है जो तय की गई पॉलिसी के हिसाब से सही नहीं हैं।

कब इस्तेमाल करें

  • ✓जब आप चाहते हैं कि आपके सभी सिस्टम एक ही सुरक्षा नियमों का पालन करें।
  • ✓जब आपको गलत कॉन्फ़िगरेशन को आपके सिस्टम में लागू होने से रोकना हो।
  • ✓जब आपको अपनी सुरक्षा पॉलिसी का ऑडिट ट्रेल (रिकॉर्ड) चाहिए।

Skill का लिंक

https://github.com/mukul975/Anthropic-Cybersecurity-Skills/blob/main/skills/implementing-policy-as-code-with-open-policy-agent/SKILL.md

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/mukul975/Anthropic-Cybersecurity-Skills/blob/main/skills/implementing-policy-as-code-with-open-policy-agent/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

AI से क्या माँगें: उदाहरण

“Open Policy Agent को ऐसे कॉन्फ़िगर करें कि वह बिना CPU limits वाले Pods बनाने को ब्लॉक कर दे।”

हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।

यह कैसे काम करती है

आप नियम Rego नाम की भाषा में लिखते हैं और Kubernetes में उन्हें लागू करने के लिए Gatekeeper का इस्तेमाल करते हैं। यह एक दरवाज़े के पहरेदार की तरह काम करता है, जो हर नए कॉन्फ़िगरेशन को लागू होने से पहले जाँचता है।

तकनीकी सामग्री (मूल SKILL.md)

लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।

Implementing Policy as Code with Open Policy Agent

When to Use

  • When enforcing organizational security policies across Kubernetes clusters programmatically
  • When requiring admission control that blocks non-compliant resources from being created
  • When implementing policy governance that can be version-controlled, tested, and audited
  • When standardizing security rules across multiple clusters and environments
  • When needing a flexible policy engine that extends beyond Kubernetes to APIs and CI/CD

Do not use for vulnerability scanning (use Trivy/Checkov), for runtime threat detection (use Falco), or for network policy enforcement (use Kubernetes NetworkPolicy or Calico).

Prerequisites

  • Kubernetes cluster with admin access for Gatekeeper installation
  • Helm for Gatekeeper deployment
  • OPA CLI or conftest for local policy testing
  • Rego knowledge for policy authoring

Workflow

Step 1: Install OPA Gatekeeper

# Install Gatekeeper via Helm
helm repo add gatekeeper https://open-policy-agent.github.io/gatekeeper/charts
helm install gatekeeper gatekeeper/gatekeeper \
  --namespace gatekeeper-system --create-namespace \
  --set replicas=3 \
  --set audit.replicas=1 \
  --set audit.writeToRAMDisk=true

Step 2: Create Constraint Templates

# templates/k8s-required-labels.yaml
apiVersion: templates.gatekeeper.sh/v1
kind: ConstraintTemplate
metadata:
  name: k8srequiredlabels
spec:
  crd:
    spec:
      names:
        kind: K8sRequiredLabels
      validation:
        openAPIV3Schema:
          type: object
          properties:
            labels:
              type: array
              items:
                type: string
  targets:
    - target: admission.k8s.gatekeeper.sh
      rego: |
        package k8srequiredlabels
        violation[{"msg": msg}] {
          provided := {label | input.review.object.metadata.labels[label]}
          required := {label | label := input.parameters.labels[_]}
          missing := required - provided
          count(missing) > 0
          msg := sprintf("Missing required labels: %v", [missing])
        }

---
# templates/k8s-container-limits.yaml
apiVersion: templates.gatekeeper.sh/v1
kind: ConstraintTemplate
metadata:
  name: k8scontainerlimits
spec:
  crd:
    spec:
      names:
        kind: K8sContainerLimits
      validation:
        openAPIV3Schema:
          type: object
          properties:
            cpu:
              type: string
            memory:
              type: string
  targets:
    - target: admission.k8s.gatekeeper.sh
      rego: |
        package k8scontainerlimits
        violation[{"msg": msg}] {
          container := input.review.object.spec.containers[_]
          not container.resources.limits.cpu
          msg := sprintf("Container %v has no CPU limit", [container.name])
        }
        violation[{"msg": msg}] {
          container := input.review.object.spec.containers[_]
          not container.resources.limits.memory
          msg := sprintf("Container %v has no memory limit", [container.name])
        }

---
# templates/k8s-block-privileged.yaml
apiVersion: templates.gatekeeper.sh/v1
kind: ConstraintTemplate
metadata:
  name: k8sblockprivileged
spec:
  crd:
    spec:
      names:
        kind: K8sBlockPrivileged
  targets:
    - target: admission.k8s.gatekeeper.sh
      rego: |
        package k8sblockprivileged
        violation[{"msg": msg}] {
          container := input.review.object.spec.containers[_]
          container.securityContext.privileged == true
          msg := sprintf("Privileged container not allowed: %v", [container.name])
        }
        violation[{"msg": msg}] {
          container := input.review.object.spec.initContainers[_]
          container.securityContext.privileged == true
          msg := sprintf("Privileged init container not allowed: %v", [container.name])
        }

Step 3: Apply Constraints

# constraints/require-labels.yaml
apiVersion: constraints.gatekeeper.sh/v1beta1
kind: K8sRequiredLabels
metadata:
  name: require-team-labels
spec:
  enforcementAction: deny
  match:
    kinds:
      - apiGroups: [""]
        kinds: ["Namespace"]
      - apiGroups: ["apps"]
        kinds: ["Deployment", "StatefulSet"]
    excludedNamespaces:
      - kube-system
      - gatekeeper-system
  parameters:
    labels:
      - "team"
      - "environment"
      - "cost-center"

---
# constraints/block-privileged.yaml
apiVersion: constraints.gatekeeper.sh/v1beta1

…
अक्सर पूछे जाने वाले सवाल

Policy as Code क्या है?

यह सुरक्षा नियमों जैसी पॉलिसी को कोड की मदद से मैनेज और लागू करने का तरीका है, ठीक वैसे ही जैसे आप अपने सॉफ़्टवेयर कोड को मैनेज करते हैं। इससे वर्जनिंग, टेस्टिंग और ऑटोमेशन संभव होता है।

Open Policy Agent (OPA) क्या है?

यह एक open-source टूल है, जिससे आप अलग-अलग सिस्टम में पॉलिसी केंद्रीय रूप से तय और लागू कर सकते हैं।

Gatekeeper क्या है?

यह Kubernetes के अंदर OPA के साथ काम करने वाला एक हिस्सा है। यह संसाधन (resources) बनाने या बदलने की रिक्वेस्ट को रोककर तय की गई पॉलिसी से उसकी जाँच करता है।

जानकारी

लेखक का मूल विवरण

Implements policy-as-code enforcement with Open Policy Agent (OPA) and Gatekeeper for Kubernetes and CI/CD pipelines, covering writing Rego policies, deploying OPA Gatekeeper as a Kubernetes admission controller, testing policies in development, and integrating policy evaluation into deployment pipelines. Use when writing Rego policies, deploying Gatekeeper admission control, or gating CI/CD pipel

repo: mukul975/Anthropic-Cybersecurity-Skills

लोकप्रियता

GitHub स्टार
35k
रैंकिंग में स्थान
#8098
लाइसेंस
Apache-2.0
अपडेट की गई
31/8/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

मिलती-जुलती skills