KAHIBARO Bookshelves
Discord Login Register

6.3. Authentication and authorization

Concepts: Authentication vs Authorization in OpenShift

OpenShift separates two closely related concerns:

  • Authentication: Who are you? (Verifying identity)
  • Authorization: What are you allowed to do? (Checking permissions)

Every request to the OpenShift API (via oc, web console, other tools) first goes through:

  1. Authentication → request gets a user identity.
  2. Authorization → access is allowed or denied based on that identity.

You will see this flow whenever you log in to the web console or use oc login.

Authentication in OpenShift

OpenShift does not manage accounts directly (like a traditional Unix /etc/passwd); it integrates with external identity providers and issues tokens.

Users, Identities, and Service Accounts

At the authentication layer, OpenShift deals with:

  • User: An OpenShift user object (e.g. alice).
  • Identity: How that user is known at an external identity provider. For example:
    • github:alice-gh
    • ldap:uid=alice,ou=People,dc=example,dc=com
  • ServiceAccount: A special type of user for applications, not humans.

Mappings:

  • An identity from a provider is linked to exactly one user in OpenShift.
  • A user can be linked to multiple identities (e.g. LDAP and GitHub).

Service accounts:

  • Are scoped to a project/namespace (e.g. system:serviceaccount:myproj:builder).
  • Are authenticated using service account tokens, usually mounted as a file inside a pod.

Authentication Methods

OpenShift supports multiple authentication methods through identity providers. Typical ones:

  • OAuth with web-based login:
    • When you access the web console, you usually go through the OpenShift OAuth server.
    • You may see a login form (local users) or be redirected to an external provider (e.g. corporate SSO).
  • Token-based login:
    • Using oc login --token=... --server=....
    • Tokens are typically OAuth access tokens issued after authentication.
  • Service Account Tokens:
    • Pods typically authenticate to the API server using a token from a mounted file, e.g.:
      • /var/run/secrets/kubernetes.io/serviceaccount/token
  • CLI interactive login:
    • oc login https://api.example.com:6443
    • You might be prompted for username/password, or a browser-based login may open, depending on configuration.

Identity Providers (IdPs)

Identity providers are configured at the cluster level. Common options include:

  • LDAP
  • Active Directory
  • GitHub / GitLab / OAuth2 providers
  • HTPasswd (simple file-based users; often in labs/demos)
  • OpenID Connect / SAML (enterprise SSO)

Conceptually, each IdP:

  1. Verifies the user’s credentials (password, SSO token, etc.).
  2. Returns identity data (username, groups, email).
  3. OpenShift maps this identity to a user object and issues an access token.

As a regular user, you mainly need to know:

  • Which authentication method your cluster uses (SSO, username/password, token).
  • How to obtain a token if you need one (for scripts, automation, etc.).

The OAuth Server and Tokens

OpenShift uses an internal OAuth server for authentication:

  • Issues access tokens after successful authentication.
  • Optionally issues refresh tokens (depending on config).
  • Can be used for:
    • Web console sessions.
    • oc CLI tokens.
    • Third-party tools that call the OpenShift API.

You can typically:

  • See who you are logged in as:
    • oc whoami
  • See your groups:
    • oc whoami --show-groups
  • View the API URL and context:
    • oc config view

Tokens should be treated as sensitive credentials:

  • Don’t commit them to Git.
  • Don’t share them.
  • Rotate/revoke them if compromised.

Authorization in OpenShift

Authorization decides whether an authenticated user or service account can perform an action (verb) on a resource.

Examples:

  • Can user alice create pods in project dev?
  • Can the builder service account read image streams?
  • Can a CI user list all projects?

OpenShift mainly uses Kubernetes RBAC, with some OpenShift-specific roles and resources.

Basic Authorization Model

Every request is evaluated as:

  • Subject: a user or service account (and its groups).
  • Action:
    • Verb: get, list, create, update, delete, patch, watch
    • Resource: pods, deployments, routes, secrets, etc.
    • Namespace/project (if namespaced).
  • The RBAC engine checks if there is a RoleBinding or ClusterRoleBinding that grants the permission.

If there is a grant → request allowed, otherwise → denied.

Roles and RoleBindings

Authorization is managed through Roles and Bindings:

  • Role:
    • A collection of rules (permissions) scoped to a namespace.
  • ClusterRole:
    • Similar but cluster-wide; can grant namespaced or cluster-level permissions.
  • RoleBinding:
    • Binds a Role to users/groups/service accounts in a specific namespace.
  • ClusterRoleBinding:
    • Binds a ClusterRole cluster-wide, possibly affecting many or all namespaces.

Example pattern:

  • Define what: edit rights to modify objects in a project.
  • Bind it to who: alice in the dev project.

Conceptually:

  • Role / ClusterRole = “permissions template”
  • RoleBinding / ClusterRoleBinding = “who gets which template, and where”

Common Built-in Roles

Typical built-in ClusterRoles you will encounter:

  • cluster-admin
    • Full control over the entire cluster.
  • admin
    • Full control over a project/namespace; can manage roles within it.
  • edit
    • Can create, modify most resources in a project, but not manage RBAC.
  • view
    • Read-only access to most resources in a project.

OpenShift adds some specialized roles, for example:

  • system:deployer, system:image-builder, etc., used by internal components.

As a developer or basic user you will mostly be assigned:

  • view, edit, or admin roles at the project level.

Checking and Understanding Your Permissions

OpenShift provides CLI tools to inspect and troubleshoot authorization:

  • See your current user:
    • oc whoami
  • See your groups:
    • oc whoami --show-groups
  • Check if you can perform an action:
    • oc auth can-i get pods
    • oc auth can-i delete pods -n other-project
    • oc auth can-i ' ' --all-namespaces (requires appropriate privileges to answer)
  • List roles in a project:
    • oc get roles
    • oc get rolebindings
  • List cluster roles:
    • oc get clusterroles
    • oc get clusterrolebindings

Typically:

  • If a command fails with “forbidden” and you suspect a permissions issue, try:
    • oc auth can-i <verb> <resource> -n <namespace>
  • If you are a project admin, you can inspect and adjust role bindings in your project.

Project Membership and Access

Projects (namespaces) use RBAC for membership and access:

  • Common pattern:
    • A user (like a project owner) is bound to admin for that project.
    • Additional users:
      • edit → developers who can change resources.
      • view → stakeholders or tools that need read-only access.
  • In many setups, groups (from your IdP) are bound to roles, e.g.:
    • Group dev-team-a gets edit on project team-a-dev.
    • Group ops-team gets view or admin across many projects.

This means:

  • Your ability to see a project in the web console or via oc get projects often depends on whether you have at least view in that project.
  • Losing a role binding can make a project “disappear” from your view even if the project still exists.

Service Accounts and Application Permissions

Service accounts are central to how applications access the API and other resources.

Key points:

  • Every namespace has default service accounts (e.g. default, builder, deployer).
  • When you create a pod or deployment, it runs under a specific service account:
    • Explicitly set via spec.serviceAccountName.
    • Or the namespace’s default if not specified.
  • That service account’s permissions (via RoleBindings/ClusterRoleBindings) define:
    • Whether the pod can read ConfigMaps, Secrets, or talk to the API server.
    • Whether it can create or modify other resources.

For secure applications:

  • Use dedicated service accounts with minimal privileges.
  • Bind roles only with the necessary permissions (principle of least privilege).
  • Avoid using overly privileged service accounts like one with admin unless absolutely required.

Labels, Groups, and External Identity

Authorization often leverages groups:

  • Groups may be:
    • Defined by the identity provider (e.g. LDAP group).
    • Created manually in OpenShift and populated with users.
  • Permissions are usually assigned to groups, not individual users, for easier management:
    • Example:
      • Group app-devs is bound to edit on a set of projects.
      • HR or IT manages actual membership in app-devs via AD/LDAP.

This decouples:

  • Identity management (in IdP) from
  • Authorization policies (in OpenShift RBAC).

Security Considerations and Good Practices

Even at an introductory level, keep in mind:

  • Protect credentials and tokens:
    • Treat oc login tokens and service account tokens like passwords.
  • Use least privilege:
    • Request view when you only need read access.
    • Avoid cluster-admin for day-to-day work.
  • Separate human and automation identities:
    • Use dedicated service accounts for automation (CI pipelines, bots).
  • Understand scope:
    • A Role and RoleBinding are namespace-scoped; ClusterRole and ClusterRoleBinding can affect the whole cluster.
  • Audit and review:
    • Periodically review which roles and bindings exist in your projects.

Practical CLI Examples (Conceptual)

You will use these types of commands in hands-on work:

  • Log in:
    • oc login https://api.example.com:6443
  • Check identity:
    • oc whoami
    • oc whoami --show-groups
  • Check capabilities:
    • oc auth can-i create pods -n myproject
  • See who has access in a project:
    • oc get rolebindings -n myproject
    • oc describe rolebinding <name> -n myproject

The exact outputs and available roles depend on how your cluster is configured and which roles your administrators have defined.

Views: 0

Comments

Please login to add a comment.

Don't have an account? Register now!

Where to Move

Move chapter:

  • ☰ 1. Course Overview
    • ☰ 1.1. What is OpenShift
      • ☰ 1.2. Why OpenShift is used in modern IT and cloud environments
        • ☰ 1.3. OpenShift vs Kubernetes
          • ☰ 1.4. Typical OpenShift use cases
            • ☰ 1.5. Structure and goals of the course
            • ☰ 2. Containers and Cloud-Native Fundamentals
              • ☰ 2.1. What is a container
                • ☰ 2.2. Containers vs virtual machines
                  • ☰ 2.3. Introduction to Docker and container images
                    • ☰ 2.4. Container registries
                      • ☰ 2.5. Basics of cloud-native applications
                      • ☰ 3. Kubernetes Fundamentals
                        • ☰ 3.1. What is Kubernetes
                          • ☰ 3.2. Kubernetes architecture
                            • ☰ 3.3. Control plane components
                              • ☰ 3.4. Worker node components
                                • ☰ 3.5. Kubernetes objects and resources
                                  • ☰ 3.6. Declarative configuration model
                                  • ☰ 4. OpenShift Architecture
                                    • ☰ 4.1. Overview of OpenShift architecture
                                      • ☰ 4.2. Control plane in OpenShift
                                        • ☰ 4.3. Nodes and machine roles
                                          • ☰ 4.4. OpenShift Operators
                                            • ☰ 4.5. OpenShift networking model
                                              • ☰ 4.6. OpenShift storage model
                                              • ☰ 5. OpenShift Installation and Deployment Models
                                                • ☰ 5.1. OpenShift deployment options
                                                  • ☰ 5.2. Installer-Provisioned Infrastructure
                                                    • ☰ 5.3. User-Provisioned Infrastructure
                                                      • ☰ 5.4. Managed OpenShift services
                                                        • ☰ 5.5. Single-node OpenShift
                                                          • ☰ 5.6. Cluster lifecycle management
                                                          • ☰ 6. Accessing and Using OpenShift
                                                            • ☰ 6.1. OpenShift web console
                                                              • ☰ 6.2. OpenShift CLI (oc)
                                                                • ☰ 6.3. Authentication and authorization
                                                                  • ☰ 6.4. Projects and namespaces
                                                                    • ☰ 6.5. Resource quotas and limits
                                                                    • ☰ 7. Building and Deploying Applications
                                                                      • ☰ 7.1. Application deployment concepts
                                                                        • ☰ 7.2. Source-to-Image (S2I)
                                                                          • ☰ 7.3. Container-based deployments
                                                                            • ☰ 7.4. DeploymentConfigs and Deployments
                                                                              • ☰ 7.5. Rolling updates and rollbacks
                                                                              • ☰ 8. Networking in OpenShift
                                                                                • ☰ 8.1. Services and service discovery
                                                                                  • ☰ 8.2. Routes and ingress
                                                                                    • ☰ 8.3. Network policies
                                                                                      • ☰ 8.4. Load balancing
                                                                                        • ☰ 8.5. External access to applications
                                                                                        • ☰ 9. Storage in OpenShift
                                                                                          • ☰ 9.1. Persistent storage concepts
                                                                                            • ☰ 9.2. Persistent Volumes
                                                                                              • ☰ 9.3. Persistent Volume Claims
                                                                                                • ☰ 9.4. StorageClasses
                                                                                                  • ☰ 9.5. Dynamic provisioning
                                                                                                    • ☰ 9.6. Stateful applications
                                                                                                    • ☰ 10. Configuration and Secrets Management
                                                                                                      • ☰ 10.1. ConfigMaps
                                                                                                        • ☰ 10.2. Secrets
                                                                                                          • ☰ 10.3. Environment variables
                                                                                                            • ☰ 10.4. Managing sensitive data
                                                                                                              • ☰ 10.5. Best practices for configuration
                                                                                                              • ☰ 11. Scaling and High Availability
                                                                                                                • ☰ 11.1. Horizontal pod autoscaling
                                                                                                                  • ☰ 11.2. Vertical scaling
                                                                                                                    • ☰ 11.3. Self-healing and pod restarts
                                                                                                                      • ☰ 11.4. High availability concepts
                                                                                                                        • ☰ 11.5. Multi-zone and multi-region clusters
                                                                                                                        • ☰ 12. Monitoring, Logging, and Observability
                                                                                                                          • ☰ 12.1. Built-in monitoring stack
                                                                                                                            • ☰ 12.2. Metrics and alerts
                                                                                                                              • ☰ 12.3. Logging architecture
                                                                                                                                • ☰ 12.4. Distributed tracing
                                                                                                                                  • ☰ 12.5. Troubleshooting applications
                                                                                                                                  • ☰ 13. Security in OpenShift
                                                                                                                                    • ☰ 13.1. Security model overview
                                                                                                                                      • ☰ 13.2. Role-Based Access Control
                                                                                                                                        • ☰ 13.3. Security Context Constraints
                                                                                                                                          • ☰ 13.4. Image security and scanning
                                                                                                                                            • ☰ 13.5. Network security
                                                                                                                                              • ☰ 13.6. Compliance and auditing
                                                                                                                                              • ☰ 14. CI/CD and DevOps with OpenShift
                                                                                                                                                • ☰ 14.1. DevOps concepts
                                                                                                                                                  • ☰ 14.2. CI/CD pipelines overview
                                                                                                                                                    • ☰ 14.3. OpenShift Pipelines (Tekton)
                                                                                                                                                      • ☰ 14.4. GitOps with Argo CD
                                                                                                                                                        • ☰ 14.5. Integrating OpenShift with external CI tools
                                                                                                                                                        • ☰ 15. Operators and Platform Services
                                                                                                                                                          • ☰ 15.1. What are Operators
                                                                                                                                                            • ☰ 15.2. Operator Lifecycle Manager
                                                                                                                                                              • ☰ 15.3. Installing and managing Operators
                                                                                                                                                                • ☰ 15.4. Common platform Operators
                                                                                                                                                                  • ☰ 15.5. Custom Operators
                                                                                                                                                                  • ☰ 16. Upgrades, Maintenance, and Operations
                                                                                                                                                                    • ☰ 16.1. OpenShift upgrade process
                                                                                                                                                                      • ☰ 16.2. Backup and restore
                                                                                                                                                                        • ☰ 16.3. Node maintenance
                                                                                                                                                                          • ☰ 16.4. Cluster troubleshooting
                                                                                                                                                                            • ☰ 16.5. Capacity planning
                                                                                                                                                                            • ☰ 17. OpenShift on HPC and Specialized Workloads
                                                                                                                                                                              • ☰ 17.1. Running batch workloads on OpenShift
                                                                                                                                                                                • ☰ 17.2. OpenShift and GPUs
                                                                                                                                                                                  • ☰ 17.3. MPI and parallel workloads in containers
                                                                                                                                                                                    • ☰ 17.4. Hybrid HPC and cloud workflows
                                                                                                                                                                                    • ☰ 18. OpenShift in Practice
                                                                                                                                                                                      • ☰ 18.1. Typical OpenShift workflows
                                                                                                                                                                                        • ☰ 18.2. Development to production lifecycle
                                                                                                                                                                                          • ☰ 18.3. Case studies from industry
                                                                                                                                                                                            • ☰ 18.4. Common pitfalls and best practices
                                                                                                                                                                                            • ☰ 19. Future Directions and Ecosystem
                                                                                                                                                                                              • ☰ 19.1. Kubernetes ecosystem overview
                                                                                                                                                                                                • ☰ 19.2. OpenShift roadmap
                                                                                                                                                                                                  • ☰ 19.3. Serverless and event-driven workloads
                                                                                                                                                                                                    • ☰ 19.4. AI and data platforms on OpenShift
                                                                                                                                                                                                    • ☰ 20. Final Project and Hands-On Exercises
                                                                                                                                                                                                      • ☰ 20.1. Deploying a containerized application
                                                                                                                                                                                                        • ☰ 20.2. Implementing CI/CD with OpenShift
                                                                                                                                                                                                          • ☰ 20.3. Securing and scaling an application
                                                                                                                                                                                                            • ☰ 20.4. Monitoring and troubleshooting report