
Configure Self Hosted GitLab Repository Mirroring
Got a project?
Let's discuss your project
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.
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
- 1Open the AWS Management Console.
- 2Navigate to IAM.
- 3Select the IAM user used for repository access.
- 4Open the Security credentials tab.
- 5Scroll to AWS CodeCommit SSH keys.
- 6Upload the generated public key.
AWS assigns an SSH Key ID similar to:
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:
1which gitlab-rails
Start the Rails console:
1sudo gitlab-rails console
Step 5: Find the Project
Replace the project number with your GitLab project ID.
1project = Project.find(PROJECT_ID)
Example:
1project = Project.find(25)
Retrieve the repository mirror:
1mirror = project.remote_mirrors.first
Step 6: Inspect Mirror Credentials
To understand which methods are available:
1mirror.methods.grep(/credential|user|password|update|save/)
You can also inspect the credentials object:
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 UsUpdate the mirror with the correct SSH Key ID.
1mirror.credentials.user = "YOUR_AWS_SSH_KEY_ID"
Example:
1mirror.credentials.user = "APKAEIBAERJR2EXAMPLE"
Save the changes:
1mirror.save!
If no errors are returned, the mirror configuration has been updated successfully.
Verify Repository Mirroring
After saving the new SSH Key ID:
- 1Open your GitLab project.
- 2Navigate to Settings → Repository → Mirroring repositories.
- 3Trigger a manual update or push a commit.
- 4Verify 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.

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
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
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
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
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
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
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
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
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