gashirar's blog

ウイスキーがすき/美味しいものがすき/k8sがすき

kubeadm alpha kubeconfig userでユーザを払い出す

はじめに

Kubeadmで環境を構築した際、cluster-adminなUserのkubeconfigファイルはMaster Nodeの/etc/kubernetes/admin.confに出力されます。
それ以外にX.509 Client Certificate BasedなUserを払い出したい場合はMaster上のCAなどでいろいろやる必要があると思っていたのですが、kubeadmに生成するためのサブコマンドが含まれていました。

kubeadm alpha kubeconfig userコマンド

特定のUserを指定してkubeconfigファイルを生成してくれるコマンドになります。

--helpについては下記の通り。

Output a kubeconfig file for an additional user.

Alpha Disclaimer: this command is currently alpha.

Usage:
  kubeadm alpha kubeconfig user [flags]

Examples:
  # Output a kubeconfig file for an additional user named foo
  kubeadm alpha kubeconfig user --client-name=foo

Flags:
      --apiserver-advertise-address string   The IP address the API server is accessible on
      --apiserver-bind-port int32            The port the API server is accessible on (default 6443)
      --cert-dir string                      The path where certificates are stored (default "/etc/kubernetes/pki")
      --client-name string                   The name of user. It will be used as the CN if client certificates are created
  -h, --help                                 help for user
      --org strings                          The orgnizations of the client certificate. It will be used as the O if client certificates are created
      --token string                         The token that should be used as the authentication mechanism for this kubeconfig, instead of client certificates

Global Flags:
      --add-dir-header           If true, adds the file directory to the header
      --log-file string          If non-empty, use this log file
      --log-file-max-size uint   Defines the maximum size a log file can grow to. Unit is megabytes. If the value is 0, the maximum file size is unlimited. (default 1800)
      --rootfs string            [EXPERIMENTAL] The path to the 'real' host root filesystem.
      --skip-headers             If true, avoid header prefixes in the log messages
      --skip-log-headers         If true, avoid headers when opening log files
  -v, --v Level                  number for the log level verbosity

Usageでは kubeadm alpha kubeconfig user --client-name=fooとありますが、Groupを指定したい場合は--orgオプションを使うことでOrganizationsに追加することができます。

例)barbaz Groupに属するfoo Userのkubeconfigの生成

kubeadm alpha kubeconfig user --client-name=foo --org=bar --rog=baz

おわりに

マネージドサービスを利用する場合、この辺りの処理はclient-go credentials pluginで各種IAMサービスと連携してやってくれてるのでありがたいですね。

Authenticating | Kubernetes

オンプレで組もうとするとこの辺りも作りこみが必要なので、今回調べたX.509 Client Certificateな仕組みであったりStatic Tokenな仕組みであったりの作りこみは必要そうです。