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.7.3. Examples of granting roles to service accounts
You can grant roles to service accounts in the same way that you grant roles to a regular user account.
You can modify the service accounts for the current project. For example, to add the
viewrole to therobotservice account in thetop-secretproject:oc policy add-role-to-user view system:serviceaccount:top-secret:robot
$ oc policy add-role-to-user view system:serviceaccount:top-secret:robotCopy to Clipboard Copied! Toggle word wrap Toggle overflow You can also grant access to a specific service account in a project. For example, from the project to which the service account belongs, use the
-zflag and specify the<service_account_name>oc policy add-role-to-user <role_name> -z <service_account_name>
$ oc policy add-role-to-user <role_name> -z <service_account_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow 重要If you want to grant access to a specific service account in a project, use the
-zflag. Using this flag helps prevent typos and ensures that access is granted to only the specified service account.To modify a different namespace, you can use the
-noption to indicate the project namespace it applies to, as shown in the following examples.For example, to allow all service accounts in all projects to view resources in the
top-secretproject:oc policy add-role-to-group view system:serviceaccounts -n top-secret
$ oc policy add-role-to-group view system:serviceaccounts -n top-secretCopy to Clipboard Copied! Toggle word wrap Toggle overflow To allow all service accounts in the
managersproject to edit resources in thetop-secretproject: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-secretCopy to Clipboard Copied! Toggle word wrap Toggle overflow