Configure Gerrit for SSH

Prerequisites

The target repo must NOT already exist in P4 Server.

The source repo must not be empty.

Set up the SSH keys

  1. On the Git Connector server, log in as the root user.

  2. Create a .ssh directory:

    mkdir /var/www/.ssh

  3. Assign the owner of the directory to be he web service user for your platform:

    chown web-service-user:gconn-auth /var/www/.ssh

    where the web-service-user is either www-data for Ubuntu or apache for CentOS.

  4. Switch user from root to the web service user for your platform:

    Ubuntu CentOS
    su -s /bin/bash - www-data su -s /bin/bash - apache

    and generate the public and private SSH keys for the Git Connector instance:

    ssh-keygen -t rsa -b 4096 -C web-service-user@gitConnector.com

    where the web-service-user is either www-data for Ubuntu or apache for CentOS.

    then follow the prompts.

  5. Locate the public key:

    /var/www/.ssh/id_rsa.pub

  6. Copy this public key to the Gerrit server and add /var/www/.ssh/id_rsa.pub to the user account (p4-user) that performs clone and fetch for mirroring.
  7. Configure the webhook for mirroring:
    1. Set the environment variable GCONN_CONFIG to the absolute path to the gconn.conf file:

      export GCONN_CONFIG=/opt/perforce/git-connector/gconn.conf

    2. Add the web hook:

      gconn --mirrorhooks add graphDepotName/repoName ssh://p4-user@GerritHost.com/repoName.git

  8. Save the secret token that the --mirrorhooks command generates.

The secret token is also included in the repo spec on the P4 Server. To write the repo spec to standard output, run:

p4 repo -o {//graphDepotName/repoName}

On the Gerrit server

Update the configuration file for the Gerrit repository in the GERRIT_SITE/git/repoName/config-file,

where GERRIT_SITE represents the root directory of your Gerrit server.

[gconn]
    mirror-url = https://GitConnector.com/mirrorhooks
    token = secret-token-from-repo-spec (p4 repo -o {//graphDepot/repoName})
    git-ssh-url = upstream-url-from-repo-spec (p4 repo -o {//graph_depot/repo_name})
[gconn "http"]
    sslverify = false

Next step

Testing the mirror hook