How to Create and Manage Users and Groups in OpenShift – EX280 Series 2 (Lesson 9)

Last updated: November 2026

In this lesson, we will explore how to create and manage users and groups in OpenShift Container Platform.

You will also have practical ex280 exam practice questions and answers to prepare you for the ex280 exam.

Understanding The Subject Matter

When an OpenShift cluster is installed, a default administrative account called kubeadmin is created. This account has the cluster-admin role, which provides full administrative access to the cluster.

However, in a real-world environment, you will normally have multiple users accessing the cluster. Some users may need administrative privileges, while others may only need permission to create applications, manage resources within a project, or view workloads.

To manage these users effectively, OpenShift provides authentication and authorization mechanisms. We can also create groups to simplify permission management by assigning roles to groups rather than configuring every user individually.

In this tutorial, we will focus on the HTPasswd identity provider and use it to create and manage OpenShift users.

By the end of this lesson, you will understand how to:

  • Understand OpenShift authentication and authorization.
  • Configure an HTPasswd identity provider.
  • Create users and authenticate them into the cluster.
  • Assign cluster-admin privileges to a user.
  • Add new users to an existing HTPasswd identity provider.
  • Change a user’s password.
  • Delete users and their associated identities.
  • Create groups and assign permissions to them.

1. Understanding Authentication and Authorization in OpenShift

Before creating users, it is important to understand the difference between authentication and authorization.

Authentication is the process of verifying the identity of a user. It answers the question: Who are you?

Authorization determines what an authenticated user is allowed to do. For example, can the user create a Deployment, delete a Pod, view cluster nodes, or administer the entire cluster?

OpenShift uses an authentication mechanism to establish user identities and Role-Based Access Control (RBAC) to determine what those users can access.

1.1 Understanding the kubeadmin user

When OpenShift is installed, a kubeadmin account is created with the cluster-admin role.

The password is automatically generated during installation and is provided through the installation output or the installation credentials.

The kubeadmin account is intended for initial cluster administration. It is not a normal user created through an identity provider.

For production environments, Red Hat recommends configuring an identity provider and creating another cluster administrator before removing the kubeadmin account.

Important: Do not remove the kubeadmin account until you have successfully tested another account with cluster-admin privileges. Removing it without another working cluster administrator can leave you unable to administer the cluster and may require reinstalling it.

1.2 Understanding the OpenShift OAuth server

OpenShift authentication is handled through its built-in OAuth server, which is managed by the Authentication Operator.

The OAuth server allows users to obtain access tokens that they use to authenticate against the OpenShift API.

OpenShift supports different identity providers, including:

  • HTPasswd
  • LDAP
  • GitHub
  • GitLab
  • Google
  • OpenID Connect

The appropriate identity provider depends on the organization’s authentication requirements.

For this demonstration, we will configure an HTPasswd identity provider.

1.3 What is HTPasswd?

HTPasswd is a utility used to create and manage username and password entries in a flat file.

The passwords are stored as password hashes rather than ordinary readable text.

OpenShift can use this file through an HTPasswd identity provider to authenticate users.

Our demonstration will use the following users:

UsernamePurpose
tekneedInitial user and cluster administrator
tekneed2Additional user
tekneed3User added later

We will use the identity provider name cluster-users.

ACTION TIME

2. Prepare the HTPasswd Utility

To configure HTPasswd authentication, we first need the htpasswd utility.

On Red Hat Enterprise Linux, this utility is provided by the httpd-tools package.

Install it using:

[victor@sno ~]$ sudo dnf install httpd-tools -y

Verify that the utility is available:

[victor@sno ~]$ htpasswd

Usage:
        htpasswd [-cimB25dpsDv] [-C cost] passwordfile username
        htpasswd -b[cmB25dpsDv] [-C cost] passwordfile username password
        htpasswd -n[imB25dps] [-C cost] username

The exact help output may vary depending on the installed version.

We will use the following options:

OptionDescription
-cCreates a new password file
-BUses bcrypt password hashing
-bTakes the password as a command-line argument

For this tutorial, we will use -cB and allow the utility to prompt for passwords. This avoids placing passwords directly in shell commands and shell history.

3. Create the HTPasswd File and Users

The first step is to create an HTPasswd file containing our user credentials.

We will store the file under /tmp for this demonstration.

Create the first user:

[victor@sno ~]$ htpasswd -cB /tmp/htpasswd tekneed

New password:
Re-type new password:
Adding password for user tekneed

The -c option creates a new file, while -B forces bcrypt password hashing.

Next, add another user to the same file:

[victor@sno ~]$ htpasswd -B /tmp/htpasswd tekneed2

New password:
Re-type new password:
Adding password for user tekneed2

Notice that we did not use the -c option this time.

This is important because using -c again would create a new file and overwrite the existing entries.

Let us inspect the file:

[victor@sno ~]$ cat /tmp/htpasswd

tekneed:$2y$05$................................
tekneed2:$2y$05$................................

We now have two users in the HTPasswd file.

Note: Although the password file contains hashed passwords, protect it as sensitive information. Do not publish it or leave it accessible to unauthorized users.

4. Create a Secret to Store the HTPasswd File

OpenShift does not read the local HTPasswd file directly. We need to create a Secret containing the file and store that Secret in the openshift-config namespace.

First, ensure that you are logged in as a cluster administrator.

[victor@sno ~]$ oc whoami
kubeadmin

Create the Secret:

[victor@sno ~]$ oc create secret generic htpass-secret \
  --from-file=htpasswd=/tmp/htpasswd \
  -n openshift-config

secret/htpass-secret created

There are a few important details in this command:

  • secret generic creates a generic Kubernetes Secret.
  • htpass-secret is the name of the Secret.
  • --from-file=htpasswd=/tmp/htpasswd creates a Secret data key named htpasswd from the local file.
  • -n openshift-config specifies the namespace where the Secret is created.

The Secret data key must be named htpasswd because that is the key we will reference in the OAuth configuration.

Verify that the Secret exists:

[victor@sno ~]$ oc get secret htpass-secret -n openshift-config

NAME           TYPE     DATA   AGE
htpass-secret  Opaque   1      10s

We have successfully created the Secret.

5. Configure the HTPasswd Identity Provider

Now that the Secret has been created, the next step is to configure OpenShift OAuth to use it.

The OAuth configuration is a cluster-scoped resource named cluster.

First, inspect the existing OAuth configuration:

[victor@sno ~]$ oc get oauth cluster -o yaml

You can also save the existing configuration to a file:

[victor@sno ~]$ oc get oauth cluster -o yaml > oauth.yaml

Open the file:

[victor@sno ~]$ vi oauth.yaml

Locate the spec section.

We need to add an identity provider configuration under spec.identityProviders.

The following is the HTPasswd configuration we want to add:

apiVersion: config.openshift.io/v1
kind: OAuth
metadata:
  name: cluster
spec:
  identityProviders:
    - name: cluster-users
      mappingMethod: claim
      type: HTPasswd
      htpasswd:
        fileData:
          name: htpass-secret

Let us understand the important parameters:

  • name: cluster-users defines the name of the identity provider.
  • mappingMethod: claim determines how identities are mapped to OpenShift User objects.
  • type: HTPasswd specifies the identity provider type.
  • fileData.name: htpass-secret references the Secret containing the HTPasswd file.

Important: If your OAuth resource already contains identity providers, do not replace or remove them unintentionally. Add the new HTPasswd entry to the existing identityProviders list while preserving the other configuration.

Also, the YAML above is a focused example of the relevant configuration. When editing an existing cluster resource, retain its other required fields and settings.

Save the file and apply the updated OAuth configuration:

[victor@sno ~]$ oc apply -f oauth.yaml

oauth.config.openshift.io/cluster configured

The Authentication Operator will reconcile the configuration and update the OAuth server.

Check the Authentication Operator:

[victor@sno ~]$ oc get clusteroperator authentication

NAME             VERSION   AVAILABLE   PROGRESSING   DEGRADED
authentication   4.x.x     True        False         False

The version and status output will depend on your cluster.

You can also check the authentication Pods:

[victor@sno ~]$ oc get pods -n openshift-authentication

Wait for the OAuth server Pods to become ready before testing authentication.

6. Authenticate Using the New User

Now that the HTPasswd identity provider has been configured, we can try logging in with the first user.

Use:

[victor@sno ~]$ oc login -u tekneed

Enter the password when prompted.

Example:

[victor@sno ~]$ oc login -u tekneed

Authentication required for https://api.example.com:6443
Username: tekneed
Password:
Login successful.

The actual login output will depend on your cluster.

Check which user is currently authenticated:

[victor@sno ~]$ oc whoami
tekneed

The user has successfully authenticated.

However, authentication does not automatically grant administrative privileges.

Let us see what happens when the new user attempts to access cluster resources:

[victor@sno ~]$ oc get pods

Error from server (Forbidden): pods is forbidden: User "tekneed" cannot list resource "pods" in API group "" in the namespace "default"

The exact error can vary depending on the current project and the user’s permissions.

This demonstrates the difference between authentication and authorization.

The user has successfully logged in, but does not yet have permission to list Pods.

7. Grant Cluster-Admin Privileges to a User

Let us now assign the cluster-admin role to the tekneed user.

First, log back in using an account that already has cluster-admin privileges.

For this demonstration, we will use kubeadmin.

[victor@sno ~]$ oc login -u kubeadmin

Enter the administrator password.

Verify the authenticated user:

[victor@sno ~]$ oc whoami

kubeadmin

We can now assign the cluster-admin role to tekneed:

[victor@sno ~]$ oc adm policy add-cluster-role-to-user cluster-admin tekneed
clusterrole.rbac.authorization.k8s.io/cluster-admin added: "tekneed"

The command assigns the cluster-admin ClusterRole to the specified user.

Be careful: cluster-admin provides extensive privileges across the entire cluster. It should only be assigned to users who genuinely require full administrative access.

Now log in as tekneed again:

[victor@sno ~]$ oc login -u tekneed

Check the current user:

[victor@sno ~]$ oc whoami
tekneed

Try listing Pods:

[victor@sno ~]$ oc get pods

The command should now work, provided the user has successfully received the cluster-admin role.

We can also try:

[victor@sno ~]$ oc get services
[victor@sno ~]$ oc get nodes
[victor@sno ~]$ oc get projects

The user can now perform cluster-level operations because the cluster-admin role has been assigned.

8. Verify OpenShift Users and Identities

OpenShift maintains User and Identity objects to represent authenticated users and their associated identity-provider accounts.

A user who has not authenticated through an identity provider may not yet have a corresponding User object.

To list users:

[victor@sno ~]$ oc get users

To list identities:

[victor@sno ~]$ oc get identities

For the cluster-users identity provider, an identity will have a name in the following format:

cluster-users:tekneed

The provider name is prefixed to the username to form the identity name.

You can inspect a particular identity using:

[victor@sno ~]$ oc get identity cluster-users:tekneed -o yaml

This helps you understand how OpenShift associates an authenticated identity with a User object.

9. Add Another User to the HTPasswd Identity Provider

We have already created two users in our original HTPasswd file:

  • tekneed
  • tekneed2

Let us test the second user.

[victor@sno ~]$ oc login -u tekneed2

Enter the password when prompted.

Check the authenticated user:

[victor@sno ~]$ oc whoami
tekneed2

The user has successfully logged in.

However, this user does not have cluster-admin privileges because we only assigned that role to tekneed.

To create another user after the identity provider has been configured, we need to update the existing HTPasswd file stored in the Secret.

First, log in as a cluster administrator.

Extract the HTPasswd file from the Secret:

[victor@sno ~]$ oc extract secret/htpass-secret \
  --to=/tmp \
  -n openshift-config

output:

[victor@sno ~]$ oc extract secret/htpass-secret --to=/tmp -n openshift-config
/tmp/htpasswd

The file is now available locally.

Inspect it if necessary:

[victor@sno ~]$ cat /tmp/htpasswd

Next, add a third user named tekneed3:

[victor@sno ~]$ htpasswd -B /tmp/htpasswd tekneed3

New password:
Re-type new password:
Adding password for user tekneed3

We have now added tekneed3 to the local HTPasswd file.

9.1 Update the HTPasswd Secret

Adding a user to the local file does not automatically update the Secret in OpenShift.

We must replace the Secret with the updated file.

Run:

[victor@sno ~]$ oc create secret generic htpass-secret \
  --from-file=htpasswd=/tmp/htpasswd \
  --dry-run=client -o yaml \
  -n openshift-config | oc replace -f -

This command generates an updated Secret manifest and replaces the existing Secret.

output:

secret/htpass-secret replaced

The OAuth server will reconcile the updated Secret.

We can now test the new user:

[victor@sno ~]$ oc login -u tekneed3 -p Password

.

Create and Manage Users and Groups in OpenShift

Check the current user:

[victor@sno ~]$ oc whoami
tekneed3

The new user should now be able to authenticate.

Remember that adding a user to HTPasswd does not automatically assign any roles or permissions. You must configure RBAC separately.

10. Change an Existing User’s Password

Now let us change the password for tekneed2.

As usual, we need to perform this operation as a cluster administrator.

Extract the current HTPasswd file:

[victor@sno ~]$ oc extract secret/htpass-secret \
  --to=/tmp \
  -n openshift-config

Change the password for tekneed2:

[victor@sno ~]$ htpasswd -B /tmp/htpasswd tekneed2

New password:
Re-type new password:
Updating password for user tekneed2

The utility updates the password hash for the specified user.

Update the Secret with the modified HTPasswd file:

[victor@sno ~]$ oc create secret generic htpass-secret \
  --from-file=htpasswd=/tmp/htpasswd \
  --dry-run=client -o yaml \
  -n openshift-config | oc replace -f -

secret/htpass-secret replaced

The Secret now contains the updated password hash.

Try authenticating as tekneed2 using the new password:

[victor@sno ~]$ oc login -u tekneed2

Enter the new password when prompted.

If authentication succeeds, the password update has worked.

11. Delete a User from the HTPasswd Identity Provider

We can also remove a user from the HTPasswd identity provider.

For this demonstration, we will delete tekneed3.

First, log in as a cluster administrator and extract the HTPasswd file:

[victor@sno ~]$ oc extract secret/htpass-secret \
  --to=/tmp \
  -n openshift-config

Remove tekneed3 from the local HTPasswd file:

[victor@sno ~]$ htpasswd -D /tmp/htpasswd tekneed3
Deleting password for user tekneed3

Verify the file:

[victor@sno ~]$ cat /tmp/htpasswd

The entry for tekneed3 should no longer be present.

11.1 Update the Secret

We must update the Secret so that OpenShift no longer has the deleted user’s password hash:

[victor@sno ~]$ oc create secret generic htpass-secret \
  --from-file=htpasswd=/tmp/htpasswd \
  --dry-run=client -o yaml \
  -n openshift-config | oc replace -f -

secret/htpass-secret replaced

11.2 Delete the User and Identity objects

Removing a username from the HTPasswd file prevents new authentication using that credential, but it does not automatically remove the corresponding User and Identity objects.

We need to delete those objects as well.

First, inspect the identity:

[victor@sno ~]$ oc get identities

For our identity provider, the identity name is:

cluster-users:tekneed3

Delete the User object:

[victor@sno ~]$ oc delete user tekneed3

user.user.openshift.io "tekneed3" deleted

Delete the associated Identity object:

[victor@sno ~]$ oc delete identity cluster-users:tekneed3

identity.user.openshift.io "cluster-users:tekneed3" deleted

Verify that the objects have been removed:

[victor@sno ~]$ oc get users
[victor@sno ~]$ oc get identities

The deleted user and identity should no longer appear.

Important: Deleting the User object is also important because existing user tokens can remain usable until they expire if the User object is not removed. Follow your organization’s procedures for revoking access and reviewing associated permissions.

Try logging in as the deleted user:

[victor@sno ~]$ oc login -u tekneed3

Authentication should fail because the user is no longer present in the HTPasswd file.

12. Create and Manage Groups in OpenShift

So far, we have focused on creating and managing individual users.

However, managing permissions individually can become difficult when a cluster has many users.

This is where groups become useful.

An OpenShift group is a collection of users. Instead of assigning the same permissions to every user separately, we can assign a role to the group.

All members of that group can then receive the permissions granted to it.

For example, we can create a group called developers and add tekneed and tekneed2 to it.

Create the group:

[victor@sno ~]$ oc adm groups new developers tekneed tekneed2

group.user.openshift.io/developers created

Verify the group:

[victor@sno ~]$ oc get groups

NAME         USERS
developers   tekneed, tekneed2

You can also inspect the group:

[victor@sno ~]$ oc describe group developers

12.1 Assign a role to a group

Suppose we have an OpenShift project named development and want the members of the developers group to manage resources within that project.

We can assign the built-in edit role to the group:

[victor@sno ~]$ oc adm policy add-role-to-group edit developers -n development

clusterrole.rbac.authorization.k8s.io/edit added: "developers"

The edit role allows users to manage many application resources within the specified project, but it does not provide full cluster administration.

To verify the role binding:

[victor@sno ~]$ oc get rolebindings -n development

You can inspect a specific RoleBinding to confirm its subjects and assigned role.

12.2 Assign a cluster-wide viewing role to a group

If you want members of a group to have read-only access to resources across the cluster, you can assign the built-in view ClusterRole:

[victor@sno ~]$ oc adm policy add-cluster-role-to-group view developers

clusterrole.rbac.authorization.k8s.io/view added: "developers"

This grants the group the permissions included in the view ClusterRole across the cluster.

Always assign the least privilege necessary for the group’s responsibilities.

12.3 Add another user to an existing group

You can add a user to an existing group using:

[victor@sno ~]$ oc adm groups add-users developers tekneed3

Verify the group membership:

[victor@sno ~]$ oc get group developers

12.4 Remove a user from a group

To remove a user from the group:

[victor@sno ~]$ oc adm groups remove-users developers tekneed3

Verify the group again:

[victor@sno ~]$ oc get group developers

The user should no longer appear as a member.

Note: Group membership and group RBAC permissions are separate from HTPasswd authentication. Creating a group does not create user accounts, and adding a user to a group does not create their HTPasswd credentials.

13. Removing the kubeadmin Account

As mentioned earlier, OpenShift creates the kubeadmin account during installation.

Red Hat recommends removing this account after another cluster administrator has been configured and tested.

Before removing it, make sure that:

  1. An identity provider has been configured successfully.
  2. Another user has been created through that identity provider.
  3. The new user has been assigned the cluster-admin role.
  4. You have successfully logged in as that user.
  5. You have verified that the new account can perform cluster administration.
  6. You have securely stored the new administrator’s credentials.

Once these conditions have been met, log in using the new cluster administrator and remove the kubeadmin Secret:

[victor@sno ~]$ oc delete secrets kubeadmin -n kube-system

secret "kubeadmin" deleted

Warning: This operation is not easily reversible. If you remove the kubeadmin Secret without having another working cluster administrator, you may have to reinstall the cluster. Do not perform this step as a casual lab cleanup operation.

Summary

In this lesson, we learned how to create and manage users and groups in OpenShift using the HTPasswd identity provider.

We covered the following tasks:

  1. Installed the HTPasswd utility.
  2. Created an HTPasswd file containing user credentials.
  3. Created a Secret in the openshift-config namespace.
  4. Configured the HTPasswd identity provider in the cluster OAuth resource.
  5. Authenticated users into OpenShift.
  6. Assigned cluster-admin privileges to a user.
  7. Added new users to the HTPasswd file.
  8. Changed existing users’ passwords.
  9. Deleted users and their associated identities.
  10. Created groups and assigned roles to them.

One important thing to remember is that authentication and authorization are two different processes. HTPasswd allows users to authenticate, while OpenShift RBAC determines what those users are allowed to do.

For a production environment, consider integrating OpenShift with an enterprise identity provider such as LDAP or OpenID Connect, and use groups to simplify access management.

Recent EX280 Exam Questions & Answers On How To Create and Manage Users and Groups in OpenShift

For Complete Exam Practice Questions & Answer, use this link.

For EX280 Exam Tips, use this link


  1. Configure the Identity Provider for the Openshift
    ▪ Create an Htpassd Identity Provider with the name: htpass-ex280
    ▪ Create the secret for Identity provider users: htpass-idp-ex280
    ▪ Create the user account jobs with password deluges
    ▪ Create the user account wozniak with password grannies
    ▪ Create the user account collins with password culverins
    ▪ Create the user account adlerin with password artiste
    ▪ Create the user account armstrong with password spacesuits

Answer

Method 1: Imperative Approach

Step 1: Log in to the OpenShift cluster

Log in using an account with cluster administrator privileges.

[api@sno ~]$ oc login https://api.ocp4.example.com:6443

Enter the administrator username and password when prompted.

Step 2: Install the HTPasswd utility

The htpasswd utility is provided by the httpd-tools package on RHEL-based systems.

[api@sno ~]$ sudo dnf install httpd-tools -y

Verify that the utility is available:

[api@sno ~]$ htpasswd -h

Step 3: Create the HTPasswd file and user accounts

Create an HTPasswd file named htpassfile.

Add the first user:

[api@sno ~]$ htpasswd -c -B htpassfile jobs

Enter the password when prompted:

New password: deluges
Re-type new password: deluges

The -c option creates a new password file. The -B option uses bcrypt password hashing.

Add the remaining users to the same file:

[api@sno ~]$ htpasswd -B htpassfile wozniak

Enter the password:

New password: grannies
Re-type new password: grannies

Add the third user:

[api@sno ~]$ htpasswd -B htpassfile collins

Password:

culverins

Add the fourth user:

[api@sno ~]$ htpasswd -B htpassfile adlerin

Password:

artiste

Add the fifth user:

[api@sno ~]$ htpasswd -B htpassfile armstrong

Password:

spacesuits

Important: Use -c only when creating the file for the first time. Using it again would overwrite the existing user entries.

Verify the users in the file:

[api@sno ~]$ cat htpassfile

The output will contain usernames and hashed passwords, not the original plain-text passwords.

Step 4: Create the Secret for the Identity Provider

The HTPasswd file must be stored in a Secret in the openshift-config namespace.

Create the Secret named htpass-idp-ex280:

[api@sno ~]$ oc create secret generic htpass-idp-ex280 \
  --from-file=htpasswd=htpassfile \
  -n openshift-config

secret/htpass-idp-ex280 created

The key name inside the Secret is htpasswd. This is the key that the OAuth configuration will reference.

Verify the Secret:

[api@sno ~]$ oc get secret htpass-idp-ex280 \
  -n openshift-config

NAME                TYPE     DATA   AGE
htpass-idp-ex280    Opaque   1      10s

Step 5: Back up the existing OAuth configuration

The OpenShift OAuth resource controls cluster-wide authentication.

Before modifying it, save a copy of the current configuration:

[api@sno ~]$ oc get oauth cluster -o yaml > oauth-backup.yaml

Create a working copy:

[api@sno ~]$ cp oauth-backup.yaml oauth.yaml

Open the file:

[api@sno ~]$ vi oauth.yaml

Locate the spec section.

Add the HTPasswd Identity Provider under spec.identityProviders.

The configuration should resemble:

spec:
  identityProviders:
    - name: htpass-ex280
      type: HTPasswd
      mappingMethod: claim
      htpasswd:
        fileData:
          name: htpass-idp-ex280

Important: If the cluster already has other Identity Providers, preserve them. Add the new provider to the existing identityProviders list instead of replacing the entire list.

Also, do not copy the complete example over the existing OAuth resource without checking its other fields. The backup is available in oauth-backup.yaml.

Step 6: Apply the OAuth configuration

Apply the updated OAuth resource:

[api@sno ~]$ oc replace -f oauth.yaml

oauth.config.openshift.io/cluster replaced

OpenShift will begin applying the updated authentication configuration.

Step 7: Verify the OAuth configuration

Check the cluster OAuth resource:

[api@sno ~]$ oc get oauth cluster -o yaml

Confirm that the configuration contains:

- name: htpass-ex280
  type: HTPasswd
  mappingMethod: claim
  htpasswd:
    fileData:
      name: htpass-idp-ex280

This confirms that the Identity Provider references the correct Secret.

Step 8: Monitor the authentication pods

Check the authentication pods:

[api@sno ~]$ oc get pods -n openshift-authentication

Monitor them as the authentication configuration is applied:

[api@sno ~]$ watch oc get pods -n openshift-authentication

Wait until the authentication pods are running and ready.

Step 9: Verify user authentication

Log out of the current session:

[api@sno ~]$ oc logout

Log in as the first user:

[api@sno ~]$ oc login -u jobs -p deluges

Verify the logged-in username:

[api@sno ~]$ oc whoami

Expected output:

jobs

Log out:

[api@sno ~]$ oc logout

Repeat the authentication test for the remaining users.

For wozniak:

oc login -u wozniak -p grannies
oc whoami
oc logout

For collins:

oc login -u collins -p culverins
oc whoami
oc logout

For adlerin:

oc login -u adlerin -p artiste
oc whoami
oc logout

For armstrong:

oc login -u armstrong -p spacesuits
oc whoami
oc logout

Each successful login should return the corresponding username.


Method 2: Declarative Approach

The declarative approach uses YAML manifests to define the Secret and the OAuth configuration.

Step 1: Create the HTPasswd file

The HTPasswd file is generated using the htpasswd utility as described in Method 1.

htpasswd -c -B htpassfile jobs
htpasswd -B htpassfile wozniak
htpasswd -B htpassfile collins
htpasswd -B htpassfile adlerin
htpasswd -B htpassfile armstrong

Enter the required passwords when prompted.

Step 2: Create the Secret manifest

Create a file named htpass-idp-ex280.yaml:

[api@sno ~]$ vi htpass-idp-ex280.yaml

Add the following configuration:

apiVersion: v1
kind: Secret
metadata:
  name: htpass-idp-ex280
  namespace: openshift-config
type: Opaque
data:
  htpasswd: REPLACE_WITH_BASE64_HTPASSWD_FILE

The htpasswd value must contain the Base64-encoded contents of the HTPasswd file.

You can generate the encoded value with:

[api@sno ~]$ base64 -w 0 htpassfile

Copy the output into the manifest in place of the placeholder.

Security note: The HTPasswd file contains password hashes. Keep the file and the Secret manifest protected.

Apply the Secret manifest:

[api@sno ~]$ oc apply -f htpass-idp-ex280.yaml

secret/htpass-idp-ex280 created

Step 3: Update the OAuth configuration

The OAuth resource is a cluster-scoped resource that already exists. Export its current configuration:

[api@sno ~]$ oc get oauth cluster -o yaml > oauth.yaml

Edit the file:

[api@sno ~]$ vi oauth.yaml

Add the following Identity Provider configuration under spec.identityProviders:

- name: htpass-ex280
  type: HTPasswd
  mappingMethod: claim
  htpasswd:
    fileData:
      name: htpass-idp-ex280

Preserve any existing Identity Providers and other required OAuth configuration.

Apply the updated resource:

[api@sno ~]$ oc replace -f oauth.yaml

Step 4: Verify the configuration

[api@sno ~]$ oc get oauth cluster -o yaml

Confirm that the HTPasswd provider is listed and references the Secret htpass-idp-ex280.

Check the authentication pods:

[api@sno ~]$ oc get pods -n openshift-authentication

Step 5: Test authentication

Log in using one of the newly created accounts:

[api@sno ~]$ oc login -u jobs -p deluges

Verify the identity:

[api@sno ~]$ oc whoami

jobs

Repeat the test for the remaining accounts.


EX280 Exam Tips (2027)

  1. Know the HTPasswd provider type: The OAuth Identity Provider type is HTPasswd.
  2. Remember the Secret namespace: The Identity Provider Secret must be created in openshift-config.
  3. Use the correct Secret key: The Secret key must be named htpasswd when the OAuth configuration references it.
  4. Know the htpasswd options: Use -c only when creating the password file for the first time. Use -B to generate bcrypt hashes.
  5. Understand the OAuth resource: The cluster OAuth resource is named cluster and is cluster-scoped.
  6. Preserve existing Identity Providers: Adding a new provider must not accidentally remove existing authentication methods.
  7. Verify authentication: Use oc login and oc whoami to confirm that the new users can authenticate.
  8. Understand authentication versus authorization: Creating an Identity Provider and user account allows authentication. It does not automatically grant the user project or cluster permissions.

Both methods can satisfy the task. The imperative approach creates the password file and Secret using CLI commands, while the declarative approach defines the Secret and OAuth configuration using YAML manifests.

Be the first to comment

Leave a Reply

Your email address will not be published.


*