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.

Let's Build Something Great Together

Ready to transform your idea into a powerful software solution? Talk to our experts and get a free consultation.

Contact Us

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 | How to Add LiveKit Video Calling to a Next.js App
12-14 min
September 11, 2026

How to Add LiveKit Video Calling to a Next.js App

Add embedded video & audio calling to Next.js with LiveKit Cloud. Compared vs Twilio, Daily, Agora, Zoom — plus token auth, guests & recording.

Read More
Omax | Blog | We chose ECS over EKS: what we gained and what we gave up
8-10 min
September 10, 2026

We chose ECS over EKS: what we gained and what we gave up

An honest comparison of ECS vs EKS the costs, tradeoffs, and real-world reasoning behind choosing ECS for a production platform on AWS.

Read More
Omax | Blog | Upgrading Legacy Systems: From Outdated Technology to Competitive Advantage
8-10 min
September 07, 2026

Upgrading Legacy Systems: From Outdated Technology to Competitive Advantage

Learn how to upgrade legacy systems through application modernization, API integration, cloud migration, security improvements, and incremental system upgrades without disrupting business operations.

Read More
Omax | Blog | Building Distributed Tracing and Observability with AWS X-Ray
12-14 min
September 04, 2026

Building Distributed Tracing and Observability with AWS X-Ray

A practical guide to correlating requests across a multi-tier application using correlation IDs, AWS X-Ray segments, and structured logging for faster incident debugging.

Read More
Omax | Blog | Designing Before and After AI: What Really Changed
6-7 min
September 03, 2026

Designing Before and After AI: What Really Changed

A look at how AI has transformed UI/UX design from manual wireframes and slow research to AI-assisted prototyping, design-to-code, and personalization at scale.

Read More
Omax | Blog | Beyond Prompting: Managing Context and Tokens in AI Coding Tools
12-14 min
September 03, 2026

Beyond Prompting: Managing Context and Tokens in AI Coding Tools

Ever wondered why your AI coding agent starts losing context or hits a hard limit mid-task? The answer lies in tokens and the context window. Good AI coding is not about giving the model the most information. It is about giving it the right information at the right time.

Read More
Omax | Blog | What Is llms.txt? How It Helps Google, AI Search, and Agentic Browsing Find Your Website
10-12 min
August 31, 2026

What Is llms.txt? How It Helps Google, AI Search, and Agentic Browsing Find Your Website

Learn what llms.txt is, how it differs from sitemap.xml and robots.txt, and how it can help your site get found by Google, AI search tools, and AI agents.

Read More
Omax | Blog | Build an Automated Image Compression Script with Sharp and SVGO
7-8 min
August 28, 2026

Build an Automated Image Compression Script with Sharp and SVGO

Compress images from the terminal with a Node.js script powered by Sharp and SVGO a safe, two-step workflow that keeps your site fast without bloating your repo.

Read More
Omax | Blog | The Right Way to Migrate from MySQL to AWS Aurora DSQL
7-8 min
August 25, 2026

The Right Way to Migrate from MySQL to AWS Aurora DSQL

Migrating a production database is one of the highest-risk changes you can make to an application. Moving from MySQL to AWS Aurora DSQL raises the stakes further...

Read More