Closed vchaplygim closed 1 year ago
Thanks for reporting! I have a fix that should work here, can you test it and confirm?
https://github.com/DataDog/managed-kubernetes-auditing-toolkit/pull/9
Looks like a success fix, thank you
Example on first cluster:
2023/07/12 12:31:13 Testing if IMDSv1 and IMDSv2 are accessible from pods by creating a pod that attempts to access it 2023/07/12 12:31:26 IMDSv2 is not accessible to pods in your cluster: unable to establish a network connection to the IMDS 2023/07/12 12:31:29 IMDSv1 is not accessible to pods in your cluster: able to establish a network connection to the IMDS, but no credentials were returned
Example on second cluster:
2023/07/12 12:29:46 Testing if IMDSv1 and IMDSv2 are accessible from pods by creating a pod that attempts to access it 2023/07/12 12:29:55 IMDSv1 is not accessible to pods in your cluster: able to establish a network connection to the IMDS, but no credentials were returned 2023/07/12 12:29:55 IMDSv2 is accessible: any pod can retrieve credentials for the AWS role example-persistent-node-00000000000
May be:
If you see "IMDSv2 is accessible: any pod can retrieve credentials for the AWS role", it may be can check next command (more information about instancedata data retrieval here):
Create temporary pod with curl bash $ kubectl run --rm -i --tty imdspod --image=alpine/curl --restart=Never -- sh
Create temporary token for auth IMDSv2
bash
$ TOKEN=curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"
Get the top-level metadata items bash $ curl -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data/
Retrieve temporary credentials for the IAM role eksctl-mkat-cluster-nodegroup-ng-NodeInstanceRole-AXWUFF35602Z bash curl http://169.254.169.254/latest/meta-data/iam/security-credentials/eksctl-mkat-cluster-nodegroup-ng-NodeInstanceRole-AXWUFF35602Z
I tried the AWS Instance Metadata Service (IMDS) test. It shows that there is accessible
mkat eks test-imds-access 2023/07/11 15:34:32 Testing if IMDS is accessible to pods by creating a pod that attempts to access it 2023/07/11 15:34:55 IMDS is accessible and allows any pod to retrieve credentials for the AWS role
But if you try to pull the metadata (https://blog.christophetd.fr/privilege-escalation-in-aws-elastic-kubernetes-service-eks-by-compromising-the-instance-role-of-worker-nodes/), it says that 401 Unathorized.
# curl -o - -I http://169.254.169.254/latest/meta-data/iam/info HTTP/1.1 401 Unauthorized Content-Length: 0 Date: Tue, 11 Jul 2023 12:41:52 GMT Server: EC2ws Connection: close Content-Type: text/plain
So most likely because AWS has a patched version of IMDSv2 in which you can get metadata only by token (link1 and link2 proofs).
What could be the reason for this behavior? Perhaps it is worth finding the cause and fixing it?