KubernetesのKubeconfigからCertのexpiration dateを確認する

毎回忘れてしまうので。

まず、こんな感じでkubeconfigがあると、`certificate-authority-data`にSSLの証明書のpemファイルがbase64でエンコードされている。

```
$ cat kubeconfig 
apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURRRENDQWlpZ0F3SUJBZ0lJTjVUdTRXdVdkSVV3RFFZSktvWklodmNOQVFFTEJRQXdQakVTTUJBR0ExVUUKQ3hNSmIzQmxibk5vYVdaME1TZ3dKZ1lEVlFRREV4OXJkV0psTFdGd2FYTmxjblpsY2kxc2IyTmhiR2h2YzNRdApjMmxuYm1WeU1CNFhEVEkwTURJeU1EQTBOVFV6TjFvWERUTTBNREl4TnpBME5UVXpOMW93UGpFU01CQUdBMVVFCkN4TUpiM0JsYm5Ob2FXWjBNU2d3SmdZRFZRUURFeDlyZFdKbExXRndhWE5sY25abGNpMXNiMk5oYkdodmMzUXQKYzJsbmJtVnlNSUlCSWpBTkJna3Foa2lHOXcwQkFRRUZBQU9DQVE4QU1JSUJDZ0tDQVFFQTFDT2tDbTVzL1poaQpDVDN2SVdUTXBremlkOEpCZ2hkbUZ3TnBKaFR0OXQ3d2ZYZzVpTEgvdTRHeHkrZ3pVRW9HT2RJS0g3RnA2ZStzCmJSSGVUelIvOWk2blNTSnV1Qkh3WmY1d2RKak9Ec0xnWUppUjJYbk1WbmFPZURTMFlrczZzS0ZvOUpWTitPWk8KUHlvVUxSSnJ3RzVkejZDdm1aRmhza2M2bTBIdlBhNzBhWlNKZjdEdS84MEQ0L3EyN1ZWeFhiYkQ1N3JyTVJJcwpQbEVjdDNoRnNNcHNQdmljV3VNaVVpUGdHS2RJd05vK25xR3VRNWdQRXZveW5MUjRra2dPN3VLczRhWlZqT1NvCnhMZ0VHL2g5S1JUWW9KajNKSlpnRlcrTGVLcjZqbmc2ZFp1QlkwOWF6OHVMTkNoc2V6d3o5TXRxbjRwS3BwUnkKN3dq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XdEZ1lEVlIwUEFRSC9CQVFEQWdLa01BOEdBMVVkRXdFQi93UUZNQU1CQWY4d0hRWURWUjBPQkJZRUZEcVMKem15MkZnTWF6MGRWa2lDYXlEWTNLbjZhTUEwR0NTcUdTSWIzRFFFQkN3VUFBNElCQVFBUTZKaUdjZUVCOW5yMgpjalhmZDJzSXlUTUJNSFZ0RnF5SEpxV3diQmVmTzJhQXZZcWdyY2JKeTR6anhaQ0ZIQ083UDlEbyt6NnlzdkgzCllqV0NQQ3lrMnRtVzRQY1I5dzQrajVMN2M0QjdKc2tYYlBhRkNOR29kOUdINE9kNkFOUnl0cm9CaENjcFZtZU8KRlF3WVBGWG0xZERTdGxGaTlnY2ZnQUJPRi8xYVBKejVVaGNPMEpkMG5zbFB4U0NQaGFmK2FFT3YrTWRFZzNnKwppKzJGdml6S1paaVBpcU1KamZlNG9hSXU1MVZESUQ3ekY3U2pTWXBQY2Y5QVNJT0p3VDNOL0UvZEFYWUFUZlJLCmFjWno0RDJBVFY3TC9XZzZMcTFOVktVZnJlSU9pUVRKYjJ3SW82bEJGeE42UVVxbWJUMjJKbWx6dkVTUXNmQWcKVWVHWWxBd0sKLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=
  (snip)
```

これをbase64でデコードする。

```
$ echo LS0tLS1CRUdJTiBDRVS...(snip)...0VSVElGSUNBVEUtLS0tLQo= | base64 -d > test.pem
```

これをopensslに`-noout -subject -dates`とか`-enddate -noout`とかのオプションを付けて実行すれば`notAfter`にexpiration dateが表示される。

```
openssl x509 -noout -subject -dates  -in test.pem
subject=OU = openshift, CN = kube-apiserver-localhost-signer
notBefore=Feb 20 04:55:37 2024 GMT
notAfter=Feb 17 04:55:37 2034 GMT
```