|
| 1 | +--- |
| 2 | +weight: 20 |
| 3 | +--- |
| 4 | + |
| 5 | +# Harbor Connector |
| 6 | + |
| 7 | +The Harbor connector is a platform-agnostic connector that you can use to connect to any Harbor registry. |
| 8 | + |
| 9 | +You can use the Harbor Connector to securely perform container image operations in CICD pipelines, or use it in kubernetes workloads to perform image operations without credentials. |
| 10 | + |
| 11 | +Additionally, you can centralize the management of Harbor access configurations across namespaces, avoiding the need to repeat the Harbor credentials in each namespace. |
| 12 | + |
| 13 | +## Overview |
| 14 | + |
| 15 | +This document covers: |
| 16 | + |
| 17 | +- **Integration Requirements**: Prerequisites for target Harbor registries |
| 18 | +- **Creating Harbor connector** |
| 19 | +- **Advanced Features**: Proxy capabilities and configuration capabilities about Harbor connector |
| 20 | + |
| 21 | +## Integration Requirements |
| 22 | + |
| 23 | +**Harbor Registries Prerequisites** |
| 24 | + |
| 25 | +- Supports Harbor 2.x versions |
| 26 | + |
| 27 | +## Creating a simple Harbor connector |
| 28 | + |
| 29 | +Here's how to create a basic Harbor Connector: |
| 30 | + |
| 31 | +```yaml |
| 32 | +# Harbor Connector |
| 33 | +apiVersion: connectors.alauda.io/v1alpha1 |
| 34 | +kind: Connector |
| 35 | +metadata: |
| 36 | + name: harbor-connector |
| 37 | +spec: |
| 38 | + connectorClassName: harbor |
| 39 | + address: https://harbor.example.com |
| 40 | +``` |
| 41 | +
|
| 42 | +## Fields Reference |
| 43 | +
|
| 44 | +**spec.connectorClassName**: |
| 45 | +
|
| 46 | +`harbor` (constant), specifies the ConnectorClass name for Harbor integration. |
| 47 | + |
| 48 | +**spec.address**: |
| 49 | + |
| 50 | +Target Harbor registry address, for example: `https://harbor.example.com`. |
| 51 | + |
| 52 | +**spec.auth(optional)**: |
| 53 | + |
| 54 | +specifies the authentication method of the Harbor registry |
| 55 | + |
| 56 | +- `spec.auth.name`: should be `basicAuth` for Harbor connector. |
| 57 | + |
| 58 | +- `spec.auth.secretRef`: specifies the secret that contains the authentication information of the Harbor registry, the secret should be created in the same namespace as the connector. If your Harbor registry does not require authentication, you can omit this field. secret type must be `kubernetes.io/basic-auth`. |
| 59 | + |
| 60 | +**Optional Metadata fields**: |
| 61 | + |
| 62 | +- `cpaas.io/description`: Description information for the Harbor connector, for example: |
| 63 | + |
| 64 | + ```yaml |
| 65 | + apiVersion: connectors.alauda.io/v1alpha1 |
| 66 | + kind: Connector |
| 67 | + metadata: |
| 68 | + name: harbor-connector |
| 69 | + annotations: |
| 70 | + cpaas.io/description: "Connect to team development Harbor registry" |
| 71 | + ``` |
| 72 | + |
| 73 | +## Connector Capabilities |
| 74 | + |
| 75 | +### Authentication Methods |
| 76 | + |
| 77 | +The Harbor Connector supports the following authentication methods: |
| 78 | + |
| 79 | +- **Basic Authentication**: Username and password authentication, secret type must be `kubernetes.io/basic-auth`. |
| 80 | + |
| 81 | +if your Harbor registry does not require authentication, you can omit this field. |
| 82 | + |
| 83 | +#### Token Permissions Required \{#token_permissions_required} |
| 84 | + |
| 85 | +The required permissions for the configured credential depend on how you intend to use it in your Pods/Pipelines. |
| 86 | + |
| 87 | +For example: |
| 88 | +- **Image pull and push operations**: If you need to pull and push images using this connector, the credentials must have both read and write permissions for the target Harbor registry. |
| 89 | +- **API operations**: Configure permissions based on the operations you need to perform. When configuring credentials, ensure the account has permission to access user information (/users/current). |
| 90 | + |
| 91 | +For security best practices, we recommend creating credentials with minimal required permissions. When additional privileges are needed, create separate Connectors with more privileged secret and use namespace isolation to control which users can access each Connector. |
| 92 | + |
| 93 | +### Proxy and Configuration Capabilities |
| 94 | + |
| 95 | +The Harbor Connector provides proxy capabilities to enable secure access to Harbor registries. |
| 96 | + |
| 97 | +To enable clients to access Harbor registries without directly handling credentials, the Harbor ConnectorClass provides a proxy server that automatically injects authentication information. |
| 98 | + |
| 99 | +Clients with access to the connector can use this proxy server to access Harbor registries without needing to configure credentials on the client side. |
| 100 | + |
| 101 | +#### Proxy Address |
| 102 | + |
| 103 | +When creating a Harbor connector, the system will automatically create a Service for proxying access to the Harbor registry. |
| 104 | + |
| 105 | +The system will record the proxy address in the `status.proxy.httpAddress` field. |
| 106 | + |
| 107 | +For example: |
| 108 | + |
| 109 | +```yaml |
| 110 | +apiVersion: connectors.alauda.io/v1alpha1 |
| 111 | +kind: Connector |
| 112 | +metadata: |
| 113 | + name: harbor-connector |
| 114 | +spec: |
| 115 | + # . . . |
| 116 | +status: |
| 117 | + conditions: |
| 118 | + # . . . |
| 119 | + proxy: |
| 120 | + httpAddress: |
| 121 | + url: http://c-harbor-connector.default.svc.cluster.local |
| 122 | +``` |
| 123 | + |
| 124 | +#### Forward Proxy |
| 125 | + |
| 126 | +You can mount proxy information into Pods using CSI, and then use the proxy information through environment variables or configuration files. |
| 127 | + |
| 128 | +```yaml |
| 129 | +volumes: |
| 130 | +- name: proxyconfig |
| 131 | + csi: |
| 132 | + readOnly: true |
| 133 | + driver: connectors-csi |
| 134 | + volumeAttributes: |
| 135 | + connector.name: "harbor" |
| 136 | +``` |
| 137 | + |
| 138 | +Then, before executing container operations, use the proxy information through environment variables or configuration files. |
| 139 | + |
| 140 | +```bash |
| 141 | +export http_proxy=$(cat /{mount-path}/http.proxy) |
| 142 | +export https_proxy=$(cat /{mount-path}/https.proxy) |
| 143 | +export HTTP_PROXY=$http_proxy |
| 144 | +export HTTPS_PROXY=$https_proxy |
| 145 | +export no_proxy=localhost,127.0.0.1 |
| 146 | +export NO_PROXY=$no_proxy |
| 147 | +echo "Using proxy: http_proxy=$http_proxy, https_proxy=$https_proxy, no_proxy=$no_proxy" |
| 148 | +``` |
| 149 | + |
| 150 | +#### Reverse Proxy |
| 151 | + |
| 152 | +When using a reverse proxy, you need to modify the target image address to the proxy address. |
| 153 | + |
| 154 | +Example: |
| 155 | +harbor.example.com/test/abc:v1 → c-harbor-connector.default.svc.cluster.local/namespaces/harbor-connector-demo/connectors/harbor-connector/test/abc:v1 |
| 156 | + |
| 157 | +Additionally, you need to mount the configuration files into the Pod and configure the proxy address in `insecure-registries`. The default configuration files `buildkitd.toml` and `config.json` are provided. |
| 158 | + |
| 159 | +The OCI Connector created based on the OCI Connector type provides the following configurations: |
| 160 | + |
| 161 | +**config**: Configuration information required by Docker CLI. |
| 162 | + |
| 163 | +- Provides the `config.json` configuration file. |
| 164 | +- Contains the authentication information required to access the proxy. |
| 165 | + |
| 166 | +For example: |
| 167 | + |
| 168 | +```json |
| 169 | +// config.json |
| 170 | +
|
| 171 | +{ |
| 172 | + "auths": { |
| 173 | + "<proxy address of the connector>": { |
| 174 | + "auth": "<authentication information required to access the connector proxy>" |
| 175 | + } |
| 176 | + } |
| 177 | +} |
| 178 | +``` |
| 179 | + |
| 180 | +**buildkitd**: Configuration information required by the BuildKit Daemon. |
| 181 | + |
| 182 | +- Provides the `buildkitd.toml` configuration file. |
| 183 | +- In the configuration file, the current connector will be set as `insecure-registries` by default. |
| 184 | + |
| 185 | +For example: |
| 186 | + |
| 187 | +```yaml |
| 188 | +insecure-entitlements = [ "network.host", "security.insecure" ] |
| 189 | +[registry."<proxy address of the connector>"] |
| 190 | + http = true |
| 191 | +``` |
| 192 | + |
| 193 | + |
| 194 | +## Further Reading |
| 195 | + |
| 196 | +- [Harbor Connector Quick Start](../quick_start) |
| 197 | +- [Harbor Connector How To Guides](../how_to) |
0 commit comments