mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-08-03 01:15:58 -07:00
Translated ['.github/pull_request_template.md', 'src/pentesting-cloud/az
This commit is contained in:
@@ -1,80 +1,72 @@
|
||||
# Kubernetes - OPA Gatekeeper
|
||||
|
||||
**The original author of this page is** [**Guillaume**](https://www.linkedin.com/in/guillaume-chapela-ab4b9a196)
|
||||
**इस पृष्ठ के मूल लेखक हैं** [**Guillaume**](https://www.linkedin.com/in/guillaume-chapela-ab4b9a196)
|
||||
|
||||
## Definition
|
||||
|
||||
Open Policy Agent (OPA) Gatekeeper is a tool used to enforce admission policies in Kubernetes. These policies are defined using Rego, a policy language provided by OPA. Below is a basic example of a policy definition using OPA Gatekeeper:
|
||||
## परिभाषा
|
||||
|
||||
Open Policy Agent (OPA) Gatekeeper एक उपकरण है जिसका उपयोग Kubernetes में प्रवेश नीतियों को लागू करने के लिए किया जाता है। ये नीतियाँ OPA द्वारा प्रदान की गई नीति भाषा Rego का उपयोग करके परिभाषित की जाती हैं। नीचे OPA Gatekeeper का उपयोग करके नीति परिभाषा का एक बुनियादी उदाहरण दिया गया है:
|
||||
```rego
|
||||
regoCopy codepackage k8srequiredlabels
|
||||
|
||||
violation[{"msg": msg}] {
|
||||
provided := {label | input.review.object.metadata.labels[label]}
|
||||
required := {label | label := input.parameters.labels[label]}
|
||||
missing := required - provided
|
||||
count(missing) > 0
|
||||
msg := sprintf("Required labels missing: %v", [missing])
|
||||
provided := {label | input.review.object.metadata.labels[label]}
|
||||
required := {label | label := input.parameters.labels[label]}
|
||||
missing := required - provided
|
||||
count(missing) > 0
|
||||
msg := sprintf("Required labels missing: %v", [missing])
|
||||
}
|
||||
|
||||
default allow = false
|
||||
```
|
||||
|
||||
This Rego policy checks if certain labels are present on Kubernetes resources. If the required labels are missing, it returns a violation message. This policy can be used to ensure that all resources deployed in the cluster have specific labels.
|
||||
यह Rego नीति जांचती है कि क्या Kubernetes संसाधनों पर कुछ लेबल मौजूद हैं। यदि आवश्यक लेबल अनुपस्थित हैं, तो यह एक उल्लंघन संदेश लौटाती है। इस नीति का उपयोग यह सुनिश्चित करने के लिए किया जा सकता है कि क्लस्टर में तैनात सभी संसाधनों के पास विशिष्ट लेबल हों।
|
||||
|
||||
## Apply Constraint
|
||||
|
||||
To use this policy with OPA Gatekeeper, you would define a **ConstraintTemplate** and a **Constraint** in Kubernetes:
|
||||
|
||||
इस नीति का उपयोग OPA Gatekeeper के साथ करने के लिए, आपको Kubernetes में एक **ConstraintTemplate** और एक **Constraint** परिभाषित करना होगा:
|
||||
```yaml
|
||||
apiVersion: templates.gatekeeper.sh/v1beta1
|
||||
kind: ConstraintTemplate
|
||||
metadata:
|
||||
name: k8srequiredlabels
|
||||
name: k8srequiredlabels
|
||||
spec:
|
||||
crd:
|
||||
spec:
|
||||
names:
|
||||
kind: K8sRequiredLabels
|
||||
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[label]}
|
||||
missing := required - provided
|
||||
count(missing) > 0
|
||||
msg := sprintf("Required labels missing: %v", [missing])
|
||||
}
|
||||
crd:
|
||||
spec:
|
||||
names:
|
||||
kind: K8sRequiredLabels
|
||||
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[label]}
|
||||
missing := required - provided
|
||||
count(missing) > 0
|
||||
msg := sprintf("Required labels missing: %v", [missing])
|
||||
}
|
||||
|
||||
default allow = false
|
||||
default allow = false
|
||||
```
|
||||
|
||||
```yaml
|
||||
apiVersion: constraints.gatekeeper.sh/v1beta1
|
||||
kind: K8sRequiredLabels
|
||||
metadata:
|
||||
name: ensure-pod-has-label
|
||||
name: ensure-pod-has-label
|
||||
spec:
|
||||
match:
|
||||
kinds:
|
||||
- apiGroups: [""]
|
||||
kinds: ["Pod"]
|
||||
parameters:
|
||||
labels:
|
||||
requiredLabel1: "true"
|
||||
requiredLabel2: "true"
|
||||
match:
|
||||
kinds:
|
||||
- apiGroups: [""]
|
||||
kinds: ["Pod"]
|
||||
parameters:
|
||||
labels:
|
||||
requiredLabel1: "true"
|
||||
requiredLabel2: "true"
|
||||
```
|
||||
इस YAML उदाहरण में, हम लेबल की आवश्यकता के लिए एक **ConstraintTemplate** परिभाषित करते हैं। फिर, हम इस बाधा का नाम `ensure-pod-has-label` रखते हैं, जो `k8srequiredlabels` ConstraintTemplate को संदर्भित करता है और आवश्यक लेबल निर्दिष्ट करता है।
|
||||
|
||||
In this YAML example, we define a **ConstraintTemplate** to require labels. Then, we name this constraint `ensure-pod-has-label`, which references the `k8srequiredlabels` ConstraintTemplate and specifies the required labels.
|
||||
|
||||
When Gatekeeper is deployed in the Kubernetes cluster, it will enforce this policy, preventing the creation of pods that do not have the specified labels.
|
||||
जब Gatekeeper Kubernetes क्लस्टर में तैनात होता है, तो यह इस नीति को लागू करेगा, जिससे उन पॉड्स का निर्माण रोका जाएगा जिनके पास निर्दिष्ट लेबल नहीं हैं।
|
||||
|
||||
## References
|
||||
|
||||
* [https://github.com/open-policy-agent/gatekeeper](https://github.com/open-policy-agent/gatekeeper)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+12
-22
@@ -1,49 +1,43 @@
|
||||
# Kubernetes OPA Gatekeeper bypass
|
||||
|
||||
**The original author of this page is** [**Guillaume**](https://www.linkedin.com/in/guillaume-chapela-ab4b9a196)
|
||||
**इस पृष्ठ के मूल लेखक हैं** [**Guillaume**](https://www.linkedin.com/in/guillaume-chapela-ab4b9a196)
|
||||
|
||||
## Abusing misconfiguration
|
||||
## गलत कॉन्फ़िगरेशन का दुरुपयोग
|
||||
|
||||
### Enumerate rules
|
||||
### नियमों की गणना करें
|
||||
|
||||
Having an overview may help to know which rules are active, on which mode and who can bypass it.
|
||||
|
||||
#### With the CLI
|
||||
एक अवलोकन होना मददगार हो सकता है यह जानने के लिए कि कौन से नियम सक्रिय हैं, किस मोड में हैं और कौन इसे बायपास कर सकता है।
|
||||
|
||||
#### CLI के साथ
|
||||
```bash
|
||||
$ kubectl api-resources | grep gatekeeper
|
||||
k8smandatoryannotations constraints.gatekeeper.sh/v1beta1 false K8sMandatoryAnnotations
|
||||
k8smandatorylabels constraints.gatekeeper.sh/v1beta1 false K8sMandatoryLabel
|
||||
constrainttemplates templates.gatekeeper.sh/v1 false ConstraintTemplate
|
||||
```
|
||||
|
||||
**ConstraintTemplate** and **Constraint** can be used in Open Policy Agent (OPA) Gatekeeper to enforce rules on Kubernetes resources.
|
||||
|
||||
**ConstraintTemplate** और **Constraint** का उपयोग Open Policy Agent (OPA) Gatekeeper में Kubernetes संसाधनों पर नियम लागू करने के लिए किया जा सकता है।
|
||||
```bash
|
||||
$ kubectl get constrainttemplates
|
||||
$ kubectl get k8smandatorylabels
|
||||
```
|
||||
#### GUI के साथ
|
||||
|
||||
#### With the GUI
|
||||
|
||||
A Graphic User Interface may also be available to access the OPA rules with **Gatekeeper Policy Manager.** It is "a simple _read-only_ web UI for viewing OPA Gatekeeper policies' status in a Kubernetes Cluster."
|
||||
एक ग्राफिक यूजर इंटरफेस भी **Gatekeeper Policy Manager** के साथ OPA नियमों तक पहुँचने के लिए उपलब्ध हो सकता है। यह "Kubernetes क्लस्टर में OPA Gatekeeper नीतियों की स्थिति देखने के लिए एक सरल _read-only_ वेब UI है।"
|
||||
|
||||
<figure><img src="../../../images/05-constraints.png" alt=""><figcaption></figcaption></figure>
|
||||
|
||||
Search for the exposed service :
|
||||
|
||||
प्रदर्शित सेवा के लिए खोजें:
|
||||
```bash
|
||||
$ kubectl get services -A | grep gatekeeper
|
||||
$ kubectl get services -A | grep 'gatekeeper-policy-manager-system'
|
||||
```
|
||||
|
||||
### Excluded namespaces
|
||||
|
||||
As illustrated in the image above, certain rules may not be applied universally across all namespaces or users. Instead, they operate on a whitelist basis. For instance, the `liveness-probe` constraint is excluded from applying to the five specified namespaces.
|
||||
जैसा कि ऊपर की छवि में दर्शाया गया है, कुछ नियम सभी namespaces या उपयोगकर्ताओं पर सार्वभौमिक रूप से लागू नहीं हो सकते। इसके बजाय, वे एक व्हाइटलिस्ट आधार पर कार्य करते हैं। उदाहरण के लिए, `liveness-probe` प्रतिबंध को पांच निर्दिष्ट namespaces पर लागू करने से बाहर रखा गया है।
|
||||
|
||||
### Bypass
|
||||
|
||||
With a comprehensive overview of the Gatekeeper configuration, it's possible to identify potential misconfigurations that could be exploited to gain privileges. Look for whitelisted or excluded namespaces where the rule doesn't apply, and then carry out your attack there.
|
||||
Gatekeeper कॉन्फ़िगरेशन का व्यापक अवलोकन करते हुए, संभावित गलत कॉन्फ़िगरेशन की पहचान करना संभव है जिसे विशेषाधिकार प्राप्त करने के लिए शोषित किया जा सकता है। उन व्हाइटलिस्टेड या बाहर किए गए namespaces की तलाश करें जहाँ नियम लागू नहीं होता, और फिर वहाँ अपना हमला करें।
|
||||
|
||||
{{#ref}}
|
||||
../abusing-roles-clusterroles-in-kubernetes/
|
||||
@@ -51,7 +45,7 @@ With a comprehensive overview of the Gatekeeper configuration, it's possible to
|
||||
|
||||
## Abusing ValidatingWebhookConfiguration
|
||||
|
||||
Another way to bypass constraints is to focus on the ValidatingWebhookConfiguration resource : 
|
||||
प्रतिबंधों को बायपास करने का एक और तरीका ValidatingWebhookConfiguration संसाधन पर ध्यान केंद्रित करना है : 
|
||||
|
||||
{{#ref}}
|
||||
../kubernetes-validatingwebhookconfiguration.md
|
||||
@@ -61,7 +55,3 @@ Another way to bypass constraints is to focus on the ValidatingWebhookConfigurat
|
||||
|
||||
- [https://github.com/open-policy-agent/gatekeeper](https://github.com/open-policy-agent/gatekeeper)
|
||||
- [https://github.com/sighupio/gatekeeper-policy-manager](https://github.com/sighupio/gatekeeper-policy-manager)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user