Harbor for Beginners, Part 9: Set Retention and Immutability Rules

Keep your project tidy and safe. Set a retention rule to auto-clean old versions (preview it with a dry run), put it on a schedule, then lock important tags with an immutability rule so they can never change.

Harbor for Beginners · Part 9 of 12

Registries get messy. Every build pushes another version, and before long a project is full of old images nobody needs, while the one tag that must never change is one careless push away from being overwritten. Harbor has two rules for exactly this, and they live together on the Policy tab. One cleans up, the other locks down.

Two rules, opposite jobs

RuleWhat it does
Tag retentionAutomatically keeps the versions you want and deletes the rest, so the project does not grow forever.
Tag immutabilityLocks chosen tags so they can never be overwritten or deleted, even by you.

You will usually want both: retention to stay tidy, immutability to protect your releases.

Set up tag retention

Open your project and click the Policy tab. You start on Tag Retention, with no rules yet.

The Tag Retention tab with no rules
The Tag Retention tab, empty to start.
  1. Click Add Rule.
  2. In the dialog, leave For the repositories on matching ** (every repo). For the rule itself, choose retain the most recently pushed # artifacts and set the count to 5. Leave Tags on matching **. Click Add.
    The Add Tag Retention Rule dialog set to retain the 5 most recent artifacts
    The rule: keep the 5 most recently pushed versions in every repository.
  3. Your rule now shows in plain English at the top of the tab.

Always dry run first

Never let a retention rule loose without previewing it. Click Dry Run. It calculates exactly what it would delete and deletes nothing. When the run finishes with Success, you can trust the rule.

The retention rule added, with a successful dry run in the runs table
Rule added, and a dry run completed with Success. Nothing was deleted, it just showed what would be.

With only a version or two in your project, a keep-5 rule has nothing to remove yet, so the dry run reports no deletions. That is correct. Retention only starts trimming once a repository holds more versions than the number you set.

Run it on a schedule

A rule you have to trigger by hand is easy to forget. Give it a schedule so it cleans up on its own.

  1. Next to Schedule, click Edit.
  2. Pick a cadence from the dropdown, Daily is a sensible default. There is also Hourly, Weekly, or a Custom schedule.
  3. Click Save.
The schedule dropdown showing None, Hourly, Daily, Weekly, Custom
Set it to run on a schedule, and the cleanup happens without you.

Lock tags with immutability

Retention removes old versions. Immutability does the opposite job, it protects the versions that must never change. Switch to the Tag Immutability tab.

The Tag Immutability tab with no rules
The Tag Immutability tab, also empty to start.
  1. Click Add Rule.
  2. Leave For the repositories on matching **. For Tags, choose matching and enter a pattern like v* so every tag that starts with v is protected. Click Add.
    The Add Tag Immutability Rule dialog matching tags v*
    Lock every tag matching v*, across all repositories.
  3. The rule appears, and your v1 and v2 tags are now frozen.
The immutability rule added, matching tags v star
The immutability rule in place. Tags starting with v can no longer change.

What immutability blocks

Once a tag is immutable, Harbor refuses two things on it: overwriting it with a different image, and deleting it. If you try to push a new image over hello-world:v1 now, the push is rejected with a message that the tag is immutable. That is exactly what you want for a released version, so nobody can quietly swap out what v1 means after the fact.

Quick recap

  1. Both rules live on the project’s Policy tab.
  2. Retention keeps the most recent versions and clears out the rest. Always dry run first, then put it on a schedule.
  3. Immutability locks chosen tags so they cannot be overwritten or deleted.
  4. Use retention to stay tidy and immutability to protect your releases.

Harbor for Beginners, Part 9 of 12. Product names belong to their owners.

About The Author


Discover more from Journal of Intelligent Infrastructure – By Dr Pranay Jha

Subscribe to get the latest posts sent to your email.

Leave a Reply

Your email address will not be published. Required fields are marked *

Architect’s Toolkit

About the Author

Dr. Pranay Jha is a Cloud and AI Consultant with 18+ years of experience in hybrid cloud, virtualization, and enterprise infrastructure transformation. He specializes in VMware technologies, multi-cloud strategy, and Generative AI solutions. He holds a PhD in Computer Applications with research focused on Cloud and AI, has published multiple research papers, and has been a VMware vExpert since 2016 and a VMUG Community Leader.

Discover more from Journal of Intelligent Infrastructure - By Dr Pranay Jha

Subscribe now to keep reading and get access to the full archive.

Continue reading