0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

oc login 時に userid/password の代わりに service account の Token を代わりに使用する

Last updated at Posted at 2025-09-19

0. はじめに

SA (Service Account) は、OpenShift 上で Pod の起動などに使用されるアカウントです。

SA も権限を持った「アカウント」なので、Userid / Password でのログイン「アカウント」と同じ事ができます。

ここでは oc login を userid / password の代わりに、SA (正確には SA に割り当てられる token) を使って行ってみます。

1. 実験

SA (Service Account) を作成するプロジェクトを作成

oc new-project my-sa-project

SA (Service Account) 名 my-service-account を作成します

oc create sa my-service-account

SA (Service Account) my-service-account に、cluster-admin の権限を付けます。

oc adm policy add-cluster-role-to-user cluster-admin -z my-service-account

SA (Service Acccount) my-service-account に対する Token を作成します。
--duration=315576000s は、10年(うるう年考慮)を指定しています。

export TOKEN=`oc create token my-service-account --duration=315576000s`

--duration を指定しない場合は、1時間の token が作成されました。
Token は JWT(Jason Web Token)形式なので、デコードすると expire の日付を確認する事ができます。

2.確認

実際に Token を使ってみます。

$ oc login --token $TOKEN https://api.my-cluster.3314.p3.openshiftapps.com:443

oc whoami で確認してみると、Service Account である事がわかります。

$ oc whoami
system:serviceaccount:my-sa-project:my-service-account
$ 
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?