gashirar's blog

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

What is client-go credential plugins

はじめに

マネージドサービスの認証周りとkubectlとの連携がわからなかったのでそれの忘備録です。 kubeconfigのexecでなにかしらやってるのは知ってたのですが、もうちょっとちゃんと見ようという感じです。

元ページ

Authenticating - Kubernetes

client-go credential plugins

概要

kubectlやkubeletなど、client-goを使用するツールは外部コマンドを実行して認証情報を受け付けるための機能がある。
外部コマンドによって生成された認証情報を処理するため、webhook token authenticatorがサーバ側に必要。

ユースケース

LDAP認証の外部サービスを実行する際の流れを考える。

  1. 開発者がkubectlを叩く
  2. Credential pluginがLDAPの資格情報を使って外部サービスに通信してToken生成。
  3. Credential pluginがclient-goにTokenを渡す。
  4. kubectlはCredential PluginからもらったTokenをAPI ServerへのBearer Tokenとして利用する。
  5. API ServerはWebhook Token Authenticatorを使って、外部サービスにTokenが正しいかどうかをみてもらう
  6. 外部サービスがTokenを検証し、usergroupを返す

f:id:gashirar:20200610000620p:plain

設定

kubeconfigのuserのところに呼び出すコマンドを設定できる。

apiVersion: v1
kind: Config
users:
- name: my-user
  user:
    exec:
      # Command to execute. Required.
      command: "example-client-go-exec-plugin"

      # API version to use when decoding the ExecCredentials resource. Required.
      #
      # The API version returned by the plugin MUST match the version listed here.
      #
      # To integrate with tools that support multiple versions (such as client.authentication.k8s.io/v1alpha1),
      # set an environment variable or pass an argument to the tool that indicates which version the exec plugin expects.
      apiVersion: "client.authentication.k8s.io/v1beta1"

      # Environment variables to set when executing the plugin. Optional.
      env:
      - name: "FOO"
        value: "bar"

      # Arguments to pass when executing the plugin. Optional.
      args:
      - "arg1"
      - "arg2"

入力と出力フォーマット

kubeconfigで設定したコマンドはExecCredential Objectを標準出力にだす。
kubecltExecCredential Objectのstatusにあるクレデンシャルをつかう。

個人メモ

多分上記の6番目のところでUserとGroupを得ているような気がします。
User名はマネージドサービスごとのIAM的サービスに紐づくIDだったりするんでしょうが、Groupも似たような感じでしょうか。
TokenReviewとか使ってもうちょっと情報の整理が必要そう。

参考

KubernetesのToken Review API - Qiita

Implementing a custom Kubernetes authentication method