This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.이 콘텐츠는 선택한 언어로 제공되지 않습니다.
Chapter 13. Using service accounts in applications
13.1. Service accounts overview 링크 복사링크가 클립보드에 복사되었습니다!
A service account is an OpenShift Container Platform account that allows a component to directly access the API. Service accounts are API objects that exist within each project. Service accounts provide a flexible way to control API access without sharing a regular user’s credentials.
When you use the OpenShift Container Platform CLI or web console, your API token authenticates you to the API. You can associate a component with a service account so that they can access the API without using a regular user’s credentials. For example, service accounts can allow:
- Replication controllers to make API calls to create or delete pods.
- Applications inside containers to make API calls for discovery purposes.
- External applications to make API calls for monitoring or integration purposes.
Each service account’s user name is derived from its project and name:
system:serviceaccount:<project>:<name>
system:serviceaccount:<project>:<name>
Every service account is also a member of two groups:
- system:serviceaccounts
- Includes all service accounts in the system.
- system:serviceaccounts:<project>
- Includes all service accounts in the specified project.
Each service account automatically contains two secrets:
- An API token
- Credentials for the OpenShift Container Registry
The generated API token and registry credentials do not expire, but you can revoke them by deleting the secret. When you delete the secret, a new one is automatically generated to take its place.
13.2. Default service accounts 링크 복사링크가 클립보드에 복사되었습니다!
Your OpenShift Container Platform cluster contains default service accounts for cluster management and generates more service accounts for each project.
13.2.1. Default cluster service accounts 링크 복사링크가 클립보드에 복사되었습니다!
Several infrastructure controllers run using service account credentials. The following service accounts are created in the OpenShift Container Platform infrastructure project (openshift-infra
) at server start, and given the following roles cluster-wide:
Service Account | Description |
---|---|
|
Assigned the |
|
Assigned the |
|
Assigned the |
13.2.2. Default project service accounts and roles 링크 복사링크가 클립보드에 복사되었습니다!
Three service accounts are automatically created in each project:
Service Account | Usage |
---|---|
|
Used by build pods. It is given the |
|
Used by deployment pods and given the |
| Used to run all other pods unless they specify a different service account. |
All service accounts in a project are given the system:image-puller
role, which allows pulling images from any imagestream in the project using the internal container image registry.
13.3. Creating service accounts 링크 복사링크가 클립보드에 복사되었습니다!
You can create a service account in a project and grant it permissions by binding it to a role.
Procedure
Optional: To view the service accounts in the current project:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow To create a new service account in the current project:
oc create sa <service_account_name>
$ oc create sa <service_account_name>
1 serviceaccount "robot" created
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- To create a service account in a different project, specify
-n <project_name>
.
Optional: View the secrets for the service account:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
13.4. Using a service account’s credentials externally 링크 복사링크가 클립보드에 복사되었습니다!
You can distribute a service account’s token to external applications that must authenticate to the API.
In order to pull an image, the authenticated user must have get
rights on the requested imagestreams/layers
. In order to push an image, the authenticated user must have update
rights on the requested imagestreams/layers
.
By default, all service accounts in a project have rights to pull any image in the same project, and the builder service account has rights to push any image in the same project.
Procedure
View the service account’s API token:
oc describe secret <secret-name>
$ oc describe secret <secret-name>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow For example:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Log in using the token that you obtained:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Confirm that you logged in as the service account:
oc whoami
$ oc whoami system:serviceaccount:top-secret:robot
Copy to Clipboard Copied! Toggle word wrap Toggle overflow