0

We have multiple Kubernetes clusters across our company. To get the kubectl config content we use Dex to login and copy/paste the content to our local confi for kubectl.

I want to make this automated and so run a bunch of command to get the content using curl.

I couldn't work out how by checking the requests responses. Please help me if anyone knows how.

xbmono
  • 2,084
  • 2
  • 30
  • 50

1 Answers1

0

I found how to do it. So we need to make two calls. First one retrieves the login page in which we can grab the request id:

the_id=$(curl -s -v -L "https://login.${cluster}" | grep -Po 'action="(.*)"')

The above searches in the response for attribute action= where it tells you where to submit the request

Then use the_id in the next call:

konfig=$(curl --insecure POST -H 'Content-Type: application/x-www-form-urlencoded' -d "login=$username&password=$password" -v -L "${cluster}${the_id}" | grep -Pzo '(?s)id=".*?</')

This command will return a HTML page in which you can find the config. Obviously for you it can be different response but fetching the request id from the first call is the key that I missed to begin with.

xbmono
  • 2,084
  • 2
  • 30
  • 50