How to reset and retrieve forgotten Harbor admin password
search cancel

How to reset and retrieve forgotten Harbor admin password

book

Article ID: 329106

calendar_today

Updated On:

Products

VMware Tanzu Kubernetes Grid

Issue/Introduction

This article helps you to retrieve or reset the Harbor admin password in below scenarios:

  • You forgot the Harbor admin password configured initially during the Harbor tile deployment.

  •  You have updated the admin password from Harbor UI and forgot it.



Environment

VMware PKS 1.x

Resolution

To retrieve the admin password configured initially during the deployment of Harbor tile vm:

  1. Log in to Harbor instance by running:
    bosh -d harbor-container-registry-xxxxxxxxxxxxxxxxxxxx ssh

  2. Provide root privileges by running sudo -i.

  3. Set the docker environment alias by running the below command:
    alias docker='/var/vcap/packages/docker/bin/docker -H unix:///var/vcap/sys/run/docker/dockerd.sock'

  4. Run docker ps and make a note of the harbor-adminserver or harbor-core container id.

    • Harbor version <=1.7: docker exec to the harbor-adminserver container 

    • Harbor version >=1.8: docker exec to the harbor-core container

      For example:

      docker exec -it 0874fd181f8b bash
      where 0874fd181f8b is the respective CONTAINER ID

  5. Run env and make a note of HARBOR_ADMIN_PASSWORD.

Note: This is the admin password configured during initial harbor tile vm deployment. This entry does not get updated if the password is changed later from Harbor GUI.
 

To reset the admin password that was updated from Harbor UI and forgotten:

If the administrator have changed the harbor admin password from GUI and forgot it later, follow the below steps to reset back to the initial configured one.
Note: The below steps are going to modify the harbor database and need to be performed with caution. If you need help with these steps, please file a Support Request with VMware support.

  1. Run docker ps and confirm that all the containers are running.

  2. Login to the harbor-db container by running the following command:
    docker exec -it harbor-db bash

  3. Connect to the database by running  the following commands:
    psql -U postgres -d registry

  4. Run the below command to list the harbor users:
    select * from harbor_user;
    Note: Make a note of the admin user_id for the next step

  5. Run the below command to reset the admin password
    update harbor_user set salt='', password='' where user_id = 1;
    Note: This will set the admin password back to what it was initially configuring during harbor tile vm deployment.

  6. Exit from the db and container by running \q.

  7. Restart Harbor service by running:
    monit restart harbor