How to rotate all secrets / credentials

This is a disruptive procedure.

Delete all secrets & keypairs that kops is holding:

  1. kops get secrets | grep ^Secret | awk '{print $2}' | xargs -I {} kops delete secret secret {}
  2.  
  3. kops get secrets | grep ^Keypair | awk '{print $2}' | xargs -I {} kops delete secret keypair {}

Now run kops update cluster and kops update cluster —yes to regenerate the secrets & keypairs.

We need to reboot every node (using a rolling-update). We have to use —cloudonly because our keypair no longer matches.We set the interval small because nodes will stop trusting each other during the process, so there is no point in going slowly.

kops rolling-update cluster —cloudonly —master-interval=10s —node-interval=10s —force —yes

Re-export kubecfg with new settings:

kops export kubecfg

Now the service account tokens will need to be regenerated inside the cluster:

kops toolbox dump and find a master IP

Then ssh admin@${IP} and run this to delete all the service account tokens:

  1. # Delete all service account tokens in all namespaces
  2. NS=`kubectl get namespaces -o 'jsonpath={.items[*].metadata.name}'`
  3. for i in ${NS}; do kubectl get secrets --namespace=${i} --no-headers | grep "kubernetes.io/service-account-token" | awk '{print $1}' | xargs -I {} kubectl delete secret --namespace=$i {}; done
  4.  
  5. # Allow for new secrets to be created
  6. sleep 60
  7.  
  8. # Bounce pods that we know use service account tokens - you will likely have to bounce more
  9. kubectl delete pods -lk8s-app=dns-controller --namespace=kube-system
  10. kubectl delete pods -lk8s-app=kube-dns --namespace=kube-system
  11. kubectl delete pods -lk8s-app=kube-dns-autoscaler --namespace=kube-system
  12. pkill -f kube-controller-manager