Configure Self Hosted GitLab Repository Mirroring

Configure Self Hosted GitLab Repository Mirroring

Cloud/Devops
July 30, 2026
6-8 min

Share blog

Introduction

Self hosted GitLab Repository Mirroring is a powerful feature that automatically synchronizes repositories between GitLab and external Git providers. When the destination is AWS services such as AWS CodeCommit, authentication is commonly performed using an AWS IAM user’s Git credentials over SSH.

In this guide, we’ll walk through the process of configuring repository mirroring by generating an SSH key, associating it with an AWS IAM user, and updating GitLab’s mirror credentials through the Rails console.

Prerequisites

Before starting, ensure you have:

  • A self-managed GitLab instance
  • An AWS account
  • An IAM user with permission to access the target Git repository
  • SSH access to the GitLab server
  • Administrator access to GitLab

Step 1: Generate an SSH Key

Log in to your Linux server and generate a new SSH key pair.

typescript
1ssh-keygen -t rsa -b 4096 -C "gitlab-mirror"

This command creates:

  • Private key
  • Public key

The public key will be uploaded to AWS.

Step 2: Upload the Public Key to the AWS IAM User

  • 1
    Open the AWS Management Console.
  • 2
    Navigate to IAM.
  • 3
    Select the IAM user used for repository access.
  • 4
    Open the Security credentials tab.
  • 5
    Scroll to AWS CodeCommit SSH keys.
  • 6
    Upload the generated public key.

AWS assigns an SSH Key ID similar to:

typescript
1APKAEIBAERJR2EXAMPLE

Keep this SSH Key ID. You’ll need it later.

Step 3: Configure Repository Mirroring in GitLab

Create the repository mirror from the GitLab project as usual.

If the mirror was configured with an incorrect SSH Key ID or needs updating, you can modify it directly from the GitLab Rails console.

Step 4: Access the GitLab Rails Console

Locate the GitLab Rails executable:

typescript
1which gitlab-rails

Start the Rails console:

typescript
1sudo gitlab-rails console

Step 5: Find the Project

Replace the project number with your GitLab project ID.

typescript
1project = Project.find(PROJECT_ID)

Example:

typescript
1project = Project.find(25)

Retrieve the repository mirror:

typescript
1mirror = project.remote_mirrors.first

Step 6: Inspect Mirror Credentials

To understand which methods are available:

typescript
1mirror.methods.grep(/credential|user|password|update|save/)

You can also inspect the credentials object:

typescript
1mirror.credentials

Step 7: Update the SSH Key ID

The username used for AWS CodeCommit over SSH is the SSH Key ID assigned by AWS, not the IAM username.

Update the mirror with the correct SSH Key ID.

typescript
1mirror.credentials.user = "YOUR_AWS_SSH_KEY_ID"

Example:

typescript
1mirror.credentials.user = "APKAEIBAERJR2EXAMPLE"

Save the changes:

typescript
1mirror.save!

If no errors are returned, the mirror configuration has been updated successfully.

Verify Repository Mirroring

After saving the new SSH Key ID:

  • 1
    Open your GitLab project.
  • 2
    Navigate to Settings → Repository → Mirroring repositories.
  • 3
    Trigger a manual update or push a commit.
  • 4
    Verify that synchronization completes successfully.

Common Issues

Authentication Failed

  • Verify that the SSH Key ID is correct.
  • Ensure the corresponding private key exists on the GitLab server.
  • Confirm that the public key uploaded to AWS matches the private key.

Mirror Doesn’t Sync

  • Verify the remote repository URL.
  • Check GitLab Sidekiq logs.
  • Confirm the IAM user has the required AWS CodeCommit permissions.

Permission Denied (publickey)

This usually indicates:

  • Incorrect private key
  • Incorrect SSH Key ID
  • Public key mismatch
  • Missing IAM permissions

Best Practices

  • Use a dedicated IAM user for Git repository access.
  • Rotate SSH keys periodically.
  • Grant only the minimum permissions required.
  • Test the SSH connection before enabling mirroring.
  • Regularly monitor mirror synchronization status in GitLab.

Conclusion

GitLab Repository Mirroring combined with AWS IAM authentication provides a secure and automated way to keep repositories synchronized. By generating an SSH key, uploading the public key to AWS, obtaining the AWS-assigned SSH Key ID, and updating the mirror credentials through the GitLab Rails console, you can quickly resolve authentication issues and maintain reliable repository synchronization.

This approach is especially useful when an SSH Key ID changes or an existing mirror needs to be updated without recreating the entire mirror configuration.

Blogs

Discover the latest insights and trends in technology with the Omax Tech Blog.

View All Blogs
Omax | Blog | Clean Code vs. Overengineering: Where Should Developers Draw the Line?
10-12 min
August 21, 2026

Clean Code vs. Overengineering: Where Should Developers Draw the Line?

Clean code reduces unnecessary complexity; overengineering invents it. A practical guide to using context, evidence, and the cost of change to know when to stop adding abstractions...

Read More
Omax | Blog | Kafka vs RabbitMQ vs AWS EventBridge: Choosing the Right Architecture Based on Business Requirements
10-12 min
August 21, 2026

Kafka vs RabbitMQ vs AWS EventBridge: Choosing the Right Architecture Based on Business Requirements

Compare Kafka, RabbitMQ, and AWS EventBridge based on scalability, routing, event streaming, replay, infrastructure, and business requirements to choose the right architecture...

Read More
Omax | Blog | AI Integrations for QA Engineers
15-20 min
August 20, 2026

AI Integrations for QA Engineers

Learn how QA engineers can connect AI with Jira, GitHub, Slack, Notion and other tools to improve testing, bug tracking, reporting and QA productivity...

Read More
Omax | Blog | The Ultimate Guide to Amazon SES Setup with GoDaddy DNS
8-10 min
August 18, 2026

The Ultimate Guide to Amazon SES Setup with GoDaddy DNS

Learn how to set up Amazon SES with GoDaddy DNS. Complete step-by-step guide covering Easy DKIM, SPF, DMARC, custom MAIL FROM, and exiting the SES Sandbox...

Read More
Omax | Blog | AWS DevOps Agent Setup Guide with EC2
8-10 min
August 17, 2026

AWS DevOps Agent Setup Guide with EC2

Learn how to set up AWS DevOps Agent with EC2, CloudWatch, IAM, and Agent Spaces for AI-assisted monitoring, incident investigation, and root-cause analysis...

Read More
Omax | Blog | Multi-Tenancy Patterns in DynamoDB: Silo, Pool, and Bridge Models
6-10 min
August 13, 2026

Multi-Tenancy Patterns in DynamoDB: Silo, Pool, and Bridge Models

If you've already made the jump from a relational database to DynamoDB see our guide on moving relational data from SQL to DynamoDB...

Read More
Omax | Blog | We stopped leaving the IDE to design. Here’s our Cursor → Figma flow
8-10 min
August 10, 2026

We stopped leaving the IDE to design. Here’s our Cursor → Figma flow

Cursor drafts fast, catches gaps early, and still clips fields and breaks layouts. Here's the real pros-and-cons breakdown of our workflow...

Read More
Omax | Blog | AWS DevOps Agent: How AI is Automating On-Call Incident Response
6-8 min
August 07, 2026

AWS DevOps Agent: How AI is Automating On-Call Incident Response

If you've ever been on call during a production outage, you know how stressful it can be. Alerts start firing, dashboards light up, and suddenly you're jumping between monitoring tools...

Read More
Omax | Blog | Catch Missing Images Before Deploy: A Simple Pre-Build Script for Next.js
6-10 min
August 06, 2026

Catch Missing Images Before Deploy: A Simple Pre-Build Script for Next.js

How Omax Tech added a lightweight image validation gate to Next.js 15 builds on Vercel...

Read More

Ready to Work With Us?

Most engagements start with a 20-minute conversation. No pitch, no pressure - just an honest discussion about what you're building and whether we're the right fit.