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 4. Service Accounts
4.1. Overview 링크 복사링크가 클립보드에 복사되었습니다!
When a person uses the command line or web console, their API token authenticates them to the OpenShift API. However, when a regular user’s credentials are not available, it is common for components to make API calls independently. For example:
- Replication controllers make API calls to create or delete pods
- Applications inside containers could make API calls for discovery purposes
- External applications could make API calls for monitoring or integration purposes
Service accounts provide a flexible way to control API access without sharing a regular user’s credentials.
4.2. Usernames and groups 링크 복사링크가 클립보드에 복사되었습니다!
Every service account has an associated username that can be granted roles, just like a regular user. The username is derived from its project and name: system:serviceaccount:<project>:<name>
For example, to add the view role to the robot service account in the top-secret project:
oc policy add-role-to-user view system:serviceaccount:top-secret:robot
$ oc policy add-role-to-user view system:serviceaccount:top-secret:robot
Every service account is also a member of two groups:
- system:serviceaccounts, which includes all service accounts in the system
- system:serviceaccounts:<project>, which includes all service accounts in the specified project
For example, to allow all service accounts in all projects to view resources in the top-secret project:
oc policy add-role-to-group view system:serviceaccounts -n top-secret
$ oc policy add-role-to-group view system:serviceaccounts -n top-secret
To allow all service accounts in the managers project to edit resources in the top-secret project:
oc policy add-role-to-group edit system:serviceaccounts:managers -n top-secret
$ oc policy add-role-to-group edit system:serviceaccounts:managers -n top-secret
4.3. Default service accounts and roles 링크 복사링크가 클립보드에 복사되었습니다!
Three service accounts are automatically created in every project:
- builder is used by build pods. It is given the system:image-builder role, which allows pushing images to any image stream in the project using the internal Docker registry.
- deployer is used by deployment pods and is given the system:deployer role, which allows viewing and modifying replication controllers and pods in the project.
- default is 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 image stream in the project using the internal Docker registry.
4.4. Managing service accounts 링크 복사링크가 클립보드에 복사되었습니다!
Service accounts are API objects that exist within each project. They can be created or deleted like any other API object.
4.5. Managing service account credentials 링크 복사링크가 클립보드에 복사되었습니다!
As soon as a service account is created, two secrets are automatically added to it:
- an API token
- credentials for the internal Docker registry
These can be seen by describing the service account:
The system ensures that service accounts always have an API token and internal Docker registry credentials.
The generated API token and Docker registry credentials do not expire, but they can be revoked by deleting the secret. When the secret is deleted, a new one is automatically generated to take its place.
4.6. Managing allowed secrets 링크 복사링크가 클립보드에 복사되었습니다!
In addition to providing API credentials, a pod’s service account determines which secrets the pod is allowed to use.
Pods use secrets in two ways:
- image pull secrets, providing credentials used to pull images for the pod’s containers
- mountable secrets, injecting the contents of secrets into containers as files
To allow a secret to be used as an image pull secret by a service account’s pods, run oc secrets add --for=pull serviceaccount/<serviceaccount-name> secret/<secret-name>
To allow a secret to be mounted by a service account’s pods, run oc secrets add --for=mount serviceaccount/<serviceaccount-name> secret/<secret-name>
This example creates and adds secrets to a service account:
4.7. Using a service account’s credentials inside a container 링크 복사링크가 클립보드에 복사되었습니다!
When a pod is created, it specifies a service account (or uses the default service account), and is allowed to use that service account’s API credentials and referenced secrets.
A file containing an API token for a pod’s service account is automatically mounted at /var/run/secrets/kubernetes.io/serviceaccount/token
That token can be used to make API calls as the pod’s service account. This example calls the users/~ API to get information about the user identified by the token:
4.8. Using a service account’s credentials externally 링크 복사링크가 클립보드에 복사되었습니다!
The same token can be distributed to external applications that need to authenticate to the API.
Use oc describe secret <secret-name>
to view a service account’s API token: