Harbor
repository·main·Indexed 10 days ago
https://github.com/goharbor/harborAn open-source, cloud-native registry that stores and manages Docker and Helm images. It extends Docker Distribution with enterprise-grade features including Role Based Access Control (RBAC), policy-based replication, vulnerability scanning, identity management via LDAP/AD and OIDC, and image lifecycle management.
What's inside Harbor
- Harbor UI is the web interface for Harbor. It is built using the Clarity Design System and the Angular framework.
Use cases for the Job Service
mainThe Job Service supports several job types and management actions:
Job Types
- Generic: Executed immediately if resources are available; executes only once.
- Scheduled: Executed after a specified delay.
- Periodic: Repeatedly executed based on a specified interval (cron-like).
- Unique: Jobs submitted with a
uniqueflag to prevent duplicate jobs with the same name/arguments from existing in the queue simultaneously.
Management Actions
- Stop: Stop a running job.
- Cancel: Cancel a scheduled or running job.
- Retry: Retry a failed job (must meet retry criteria).
- Stats/Logs: Retrieve job statistics or execution logs (log availability depends on the logger implementation).
- Health Check: Check the health status of the job service (no authentication required).
Harbor Core Features Overview
mainHarbor is a trusted cloud-native registry that extends Docker Distribution with enterprise-grade security and management features:
- Cloud Native Registry: Supports both container images and Helm charts.
- Role Based Access Control (RBAC): Manage permissions via 'projects' for images and charts.
- Policy Based Replication: Synchronize images/charts between registries using filters (repository, tag, label) with automatic retries.
- Vulnerability Scanning: Regular scanning and policy checks to prevent deployment of vulnerable images.
- Identity Management: Supports LDAP/AD integration and OpenID Connect (OIDC) for Single Sign-On (SSO).
- Image Lifecycle Management: Includes image deletion and garbage collection to free up space.
- Content Trust: Supports Notary for signing images to guarantee authenticity.
- Auditing: Tracks all repository operations through logs.
- API & UI: Provides a RESTful API with Swagger UI and a graphical user portal.
Track the Harbor project roadmap
mainThe most up-to-date description of items in the Harbor release pipeline is maintained on the Harbor Project board. The board uses separate swim lanes for each release to track progress. Users and contributors should use this board as a reference to understand the project's direction and to ensure new contributions do not conflict with long-term plans.How to implement a Cancellable or Stoppable Job
mainBy default, jobs run until completion or failure. To support
stopandcancelactions, you must manually check for operation commands at specific execution points within yourRunmethod logic.For Cancellable Jobs
Check for the
cancelsignal and returnerrs.JobCancelledError()to exit gracefully:if cmd, ok := ctx.OPCommand(); ok { if cmd == opm.CtlCommandCancel { return errs.JobCancelledError() } }For Stoppable Jobs
Check for the
stopsignal and returnerrs.JobStoppedError()to exit gracefully:if cmd, ok := ctx.OPCommand(); ok { if cmd == opm.CtlCommandStop { return errs.JobStoppedError() } }if cmd, ok := ctx.OPCommand(); ok { if cmd == opm.CtlCommandCancel { return errs.JobCancelledError() } if cmd == opm.CtlCommandStop { return errs.JobStoppedError() } }Important considerations for Harbor backups and restores
mainWhen using the
contrib/backup-restorescripts, keep the following in mind:- Warning: These scripts are provided as-is in the
contrib/backup-restoredirectory. They are not officially maintained or supported by the Harbor project. Use them at your own risk. - Backup Consistency: To ensure a consistent backup, stop the Harbor instance or ensure minimal write activity during the process.
- Database Image Tag: In production, use a specific tag for the
--db-imageoption in both backup and restore scripts to ensure consistency. - Custom Deployments: If your Harbor deployment uses non-default data paths, you must use the appropriate command-line options (e.g.,
--db-path,--registry-path) to point to the correct locations. - Testing: Always test the backup and restore process in a non-production environment before relying on it for critical data.
- Warning: These scripts are provided as-is in the
How job execution and sub-jobs work
mainThe Job Service tracks relationships between jobs using parent-child hierarchies. When a job launches a new job via the
ctx.LaunchJobmethod, the new job is treated as a sub-job (execution) of the caller.Key tracking properties:
- Parent Jobs: If a job has sub-jobs, its stats include an
executionslist containing the IDs of all sub-jobs and amultiple_executionsflag set totrue. - Sub-jobs (Executions): Each sub-job contains an
upstream_job_idproperty that points back to the ID of its parent job.
Job Kinds:
- Generic: Standard jobs.
- Scheduled: Jobs that run after a specific
schedule_delay(in seconds). - Periodic: A job template that is not run directly. Instead, the service clones the template to create real running jobs. Each execution of a periodic job has a unique ID but links to the template via
upstream_job_id.
func (j *Job) Run(ctx job.Context, params job.Parameters) error{ // Launching a sub-job (execution) of the current job subJob, err := ctx.LaunchJob(models.JobRequest{}) // ... return nil }- Parent Jobs: If a job has sub-jobs, its stats include an
Use the harbor-backup script to back up Harbor
mainThe
harbor-backupscript provides a way to back up Harbor components including the PostgreSQL database, Container Registry data, Chart Museum data, Redis data, Secret keys, and theharbor.ymlconfiguration.Prerequisites:
- Docker: The
dockerCLI must be installed and accessible. - Permissions: You need
sudoordockergroup permissions. - Stopped Harbor: You must stop your Harbor instance completely before running the backup to avoid data inconsistencies.
Workflow:
- Make the script executable:
chmod +x harbor-backup. - Stop the Harbor instance.
- Run the script with desired options:
./harbor-backup [OPTIONS].
By default, the backup is created in a directory named
harbor_backupin the current working directory. If--no-archiveis not used, a compressedharbor_backup.tar.gzwill be created inside that directory.# Example: Backup with custom paths and no tarball archive ./harbor-backup \ --db-path /custom/db/path \ --registry-path /custom/registry/path \ --backup-dir /mnt/backups/harbor_daily \ --no-archive- Docker: The
Install Cosign (v2.0+) for signature verification
mainTo verify Harbor release artifacts, you must install Cosign (version 2.0 or later). Use the following commands based on your operating system:
macOS
Use Homebrew to install from the Sigstore tap.
Linux
Download the amd64 binary, make it executable, and move it to your path.
Windows (PowerShell)
Download the amd64 executable using
Invoke-WebRequest.After installation, verify it by running
cosign version.# macOS brew install sigstore/tap/cosign # Linux curl -LO https://github.com/sigstore/cosign/releases/latest/download/cosign-linux-amd64 chmod +x cosign-linux-amd64 sudo mv cosign-linux-amd64 /usr/local/bin/cosign # Windows (PowerShell) Invoke-WebRequest -Uri "https://github.com/sigstore/cosign/releases/latest/download/cosign-windows-amd64.exe" -OutFile "cosign.exe" # Verify installation cosign versionRun the Chart Migrating Tool via Docker
mainTo execute the migration, run the compiled Docker image using the following command structure. You must provide the location of your existing chart data, the Harbor CA certificate (if using HTTPS), the Harbor hostname, and the admin password.
Required Parameters:
{{your_chart_data_location}}: The local path to your chart storage (typically thechart_storagedirectory inside Harbor'sdata_volume).{{harbor_ca_cert_location}}: The path to the CA certificate required to connect to Harbor via HTTPS.{{harbor_hostname}}: The hostname of your Harbor instance.{{harbor_admin_password}}: The password for the Harbor admin user.
docker run -it --rm \ -v {{your_chart_data_location}}:/chart_storage \ -v {{harbor_ca_cert_location}}:/usr/local/share/ca-certificates/harbor_ca.crt \ goharbor/migrate-chart:0.1.0 \ --hostname {{harbor_hostname}} \ --password {{harbor_admin_password}}Configure Nginx proxy for Harbor UI backend
mainWhen deploying the Harbor UI via Nginx, you must modify the
nginx.conffile to ensure that requests for the API, client, and chart repository are proxied to a valid backend server address.Update the following location block in your
nginx.conf:location ~ ^/(api|c|chartrepo)/ { proxy_pass ${an available back-end server addr}; }Deploy Harbor using Docker Machine
mainYou can deploy Harbor to cloud providers (like DigitalOcean, AWS, or Azure) or on-premises environments using Docker Machine. This process involves creating a virtual machine, configuring DNS, setting up the Harbor configuration file, and using
docker-composeto build and run the containers on the remote machine.Workflow Steps:
- Create the Virtual Machine: Use
docker-machine createwith your preferred driver and access token. - Configure DNS: Retrieve the machine's IP address using
docker-machine ipand create a DNS entry at your provider pointing to that IP. - Prepare Configuration:
- Copy
Deploy/harbor.yml.tmptoDeploy/harbor.yml. - Update the
hostnamefield inDeploy/harbor.ymlto match your domain (e.g.,harbor.mydomain.com). - Run the
preparescript (as described in the Harbor Installation Guide).
- Copy
- Activate Environment: Use
eval $(docker-machine env <machine_name>)to point your local Docker CLI to the remote machine. - Transfer Configuration Files: Create the directory structure on the remote machine and use
docker-machine scpto copy the localconfigdirectory to the remote machine. - Build and Run: Execute
docker-compose buildfollowed bydocker-compose up -dfrom within theDeploydirectory.
# 1. Create the machine docker-machine create --driver digitalocean --digitalocean-access-token <youraccesstoken> harbor.mydomain.com # 2. Get IP for DNS configuration docker-machine ip harbor.mydomain.com # 3. Activate the machine environment eval $(docker-machine env harbor.mydomain.com) # 4. Transfer config files (example using remote path structure) docker-machine ssh harbor.mydomain.com 'mkdir -p /home/<yourusername>/src/harbor/Deploy/config' docker-machine scp -r ./config harbor.mydomain.com:$PWD # 5. Build and start docker-compose build docker-compose up -d- Create the Virtual Machine: Use