Skip to content

Commit 87c2965

Browse files
rm3lgazarenkov
andauthored
Image Mirror Support for Dynamic Plugins (#3601) (#3690)
* mirrors * mirrors * mirrors * bundle * fix * fix * merge * fix * mirrors format * bundle Co-authored-by: Gennady Azarenkov <gazarenkov@gmail.com>
1 parent c29242c commit 87c2965

20 files changed

Lines changed: 840 additions & 23 deletions

File tree

‎Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ OLM_VERSION ?= auto
1212
# Enable operator dynamic plugins processing (default: true)
1313
OPERATOR_DP_PROCESSING ?= true
1414
# Install dynamic plugins image (required when OPERATOR_DP_PROCESSING=true)
15-
RELATED_IMAGE_plugin_installer ?= quay.io/rhdh-community/rhdh-plugin-installer:next
15+
RELATED_IMAGE_plugin_installer ?= quay.io/rhdh-community/rhdh-plugin-installer:latest
1616
PROFILE_SHORT := $(shell echo $(PROFILE) | cut -d. -f1)
1717

1818
# VERSION defines the project version for the bundle.

‎bundle/backstage.io/manifests/backstage-operator.clusterserviceversion.yaml‎

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎bundle/rhdh/manifests/backstage-operator.clusterserviceversion.yaml‎

Lines changed: 10 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎cmd/plugin-fetch/main.go‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ const (
2222
OutputDirEnvVar = "OUTPUT_DIR" // Output directory (default: /dynamic-plugins-root)
2323
DockerConfigEnvVar = "DOCKER_CONFIG" // Path to dockerconfigjson file
2424
CAFileEnvVar = "CA_FILE" // Path to CA certificate file
25-
InsecureEnvVar = "INSECURE" // Skip TLS verification (true/false)
25+
InsecureEnvVar = "INSECURE" // Enable plain HTTP protocol (true/false). WARNING: Exposes credentials.
26+
SkipTLSVerifyEnvVar = "SKIP_TLS_VERIFY" // Skip TLS certificate verification for HTTPS (true/false)
2627
PluginModeEnvVar = "PLUGIN_MODE" // Enable plugin mode: validate annotation and extract plugin subdirectory (default: true)
2728
ParallelEnvVar = "PARALLEL" // Number of parallel downloads (default: 4)
2829
LockFileEnvVar = "LOCK_FILE" // Lock file path (default: OUTPUT_DIR/install-dynamic-plugins.lock)
@@ -54,6 +55,7 @@ func main() {
5455
dockerConfig := utils.StringEnvVar(DockerConfigEnvVar, "")
5556
caFile := utils.StringEnvVar(CAFileEnvVar, "")
5657
insecure := utils.BoolEnvVar(InsecureEnvVar, false)
58+
skipTLSVerify := utils.BoolEnvVar(SkipTLSVerifyEnvVar, false)
5759
pluginMode := utils.BoolEnvVar(PluginModeEnvVar, true)
5860
parallel := utils.IntEnvVar(ParallelEnvVar, 4)
5961
if parallel <= 0 {
@@ -103,6 +105,9 @@ func main() {
103105
if insecure {
104106
baseOciOpts = append(baseOciOpts, fetcher.WithInsecure())
105107
}
108+
if skipTLSVerify {
109+
baseOciOpts = append(baseOciOpts, fetcher.WithSkipTLSVerify())
110+
}
106111
if caFile != "" {
107112
caCert, err := os.ReadFile(caFile)
108113
if err != nil {

‎config/manager/deployment.yaml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ spec:
100100
name: default-config
101101
- mountPath: /plugin-deps
102102
name: plugin-deps
103+
- mountPath: /plugins-mirror
104+
name: mirror-config
105+
readOnly: true
103106
- mountPath: /tmp
104107
name: tmp
105108

@@ -113,5 +116,9 @@ spec:
113116
configMap:
114117
name: plugin-deps
115118
optional: true
119+
- name: mirror-config
120+
configMap:
121+
name: plugin-registry-mirror
122+
optional: true
116123
- name: tmp
117124
emptyDir: {}

‎dist/backstage.io/install.yaml‎

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/rhdh/install.yaml‎

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/admin.md‎

Lines changed: 94 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,105 @@ When creating the Backstage CR, the Operator will try to create a Backstage Pod,
6767
Also, if Backstage CR configured with *EnabledLocalDb*, it will create a PostgreSQL container pod, configured in *(db-statefulset.yaml).spec.template.spec.Containers[].image*
6868

6969
By default, the Backstage Operator is configured to use publicly available images.
70-
If you plan to deploy to a [restricted environment](https://docs.openshift.com/container-platform/4.14/operators/admin/olm-restricted-networks.html),
70+
If you plan to deploy to a [restricted environment](https://docs.redhat.com/en/documentation/openshift_container_platform/4.22/html/disconnected_environments/olm-restricted-networks),
7171
you will need to configure your cluster or network to allow these images to be pulled.
7272
For the list of related images deployed by the Operator, see the `RELATED_IMAGE_*` env vars or `relatedImages` section of the [CSV](../bundle/manifests/backstage-operator.clusterserviceversion.yaml).
73-
See also https://docs.openshift.com/container-platform/4.14/operators/admin/olm-restricted-networks.html
73+
See also https://docs.redhat.com/en/documentation/openshift_container_platform/4.22/html/disconnected_environments/olm-restricted-networks
74+
75+
#### Plugin Registry Mirroring
76+
77+
In air-gapped environments, Backstage dynamic plugins distributed as OCI artifacts need to be mirrored to internal registries. The Backstage Operator supports optional plugin registry mirroring that automatically transforms plugin package URLs to use your internal mirror registries.
78+
79+
The mirror configuration uses the same format and matching rules as OpenShift's [ImageDigestMirrorSet (IDMS)](https://docs.redhat.com/en/documentation/openshift_container_platform/4.22/html/images/image-configuration-classic#images-configuration-registry-mirror_image-configuration) and [ImageTagMirrorSet (ITMS)](https://docs.redhat.com/en/documentation/openshift_container_platform/4.22/html/images/image-configuration-classic#images-configuration-registry-mirror_image-configuration), making it familiar to OpenShift administrators and allowing direct reuse of existing IDMS/ITMS configurations.
80+
81+
**Important:** Unlike OpenShift's IDMS (digest-only) and ITMS (tag-only) which only mirror specific pull types, the operator's mirror configuration works for **both tag-based** (`:v1.0`) **and digest-based** (`@sha256:...`) plugin references. This is because the operator performs application-level URL transformation before the init container pulls plugins, rather than container runtime-level mirroring like IDMS/ITMS.
82+
83+
**How it works:**
84+
85+
- The operator reads mirror configuration from an optional ConfigMap mounted at `/plugins-mirror/mirrors.yaml`
86+
- Plugin package URLs with `oci://` prefix are transformed using IDMS-style matching rules before being written to the init container's package list
87+
- Only OCI URLs are transformed - npm packages, HTTP URLs, and file paths remain unchanged
88+
- The transformed URLs are visible in the Backstage CR status under `status.plugins`
89+
90+
**Configuration:**
91+
92+
1. Create a ConfigMap named `plugin-registry-mirror` in the operator's namespace (usually `backstage-system` or `rhdh-operator`):
93+
94+
```yaml
95+
apiVersion: v1
96+
kind: ConfigMap
97+
metadata:
98+
name: plugin-registry-mirror
99+
namespace: rhdh-operator # Must be in operator namespace
100+
data:
101+
mirrors.yaml: |
102+
# Mirror configuration for plugin OCI images
103+
# Works for both tag-based (:v1.0) and digest-based (@sha256:...) references
104+
imageMirrors:
105+
# Mirror quay.io to internal registry
106+
- source: quay.io
107+
mirrors:
108+
- my-registry.example.com/quay-mirror
109+
110+
# Mirror Red Hat registry
111+
- source: registry.redhat.io
112+
mirrors:
113+
- my-registry.example.com/redhat-mirror
114+
115+
# Multiple mirrors (first is used, others ignored)
116+
- source: ghcr.io
117+
mirrors:
118+
- primary-mirror.example.com/ghcr
119+
- backup-mirror.example.com/ghcr
120+
```
121+
122+
2. Restart the operator pod to load the configuration:
123+
124+
```bash
125+
kubectl rollout restart deployment rhdh-operator -n rhdh-operator
126+
```
127+
128+
3. Verify the transformed URLs in your Backstage CR status:
129+
130+
```bash
131+
kubectl get backstage my-backstage -o jsonpath='{.status.plugins}' | jq
132+
```
133+
134+
**Mirroring rules (based on IDMS):**
135+
136+
- **Most specific namespace match**: When multiple sources match a plugin URL, the longest/most specific source wins. For example, if you have both `quay.io` and `quay.io/rhdh` configured, a plugin from `oci://quay.io/rhdh/plugin:1.0` will use the `quay.io/rhdh` mirror configuration.
137+
- **Only OCI URLs are mirrored**: Plugins specified as `oci://registry.example.com/plugin:tag` or `oci://registry.example.com/plugin@sha256:...` are transformed. npm packages (`@scope/package`), HTTP URLs (`https://...`), and file paths are not affected.
138+
- **First mirror is used**: If multiple mirrors are specified for a source, only the first one is used (fallback support may be added in future versions).
139+
140+
**For OpenShift users with existing IDMS/ITMS:**
141+
142+
You can copy mirror entries from your existing ImageDigestMirrorSet or ImageTagMirrorSet:
143+
144+
```bash
145+
# Extract entries from IDMS
146+
oc get imagedigestmirrorset rhdh-plugins -o jsonpath='{.spec.imageDigestMirrors}' | \
147+
yq -P 'imageMirrors: .' > mirrors.yaml
148+
149+
# OR extract entries from ITMS
150+
oc get imagetagmirrorset rhdh-plugins -o jsonpath='{.spec.imageTagMirrors}' | \
151+
yq -P 'imageMirrors: .' > mirrors.yaml
152+
153+
# Create ConfigMap from the mirror configuration
154+
oc create configmap plugin-registry-mirror \
155+
--from-file=mirrors.yaml \
156+
-n rhdh-operator
157+
```
158+
159+
**Important notes:**
160+
161+
- The ConfigMap must be created **before** the operator starts, or the operator must be restarted after creating/updating the ConfigMap
162+
- Configuration changes require operator pod restart (acceptable for air-gap scenarios where mirrors rarely change)
163+
- If the ConfigMap doesn't exist, no mirroring is applied (default behavior)
164+
- The operator deployment already includes the volume mount configuration with `optional: true`, so the operator will start successfully whether or not the ConfigMap exists
74165

75166

76167
### Installing Operator on Openshift cluster
77-
https://docs.openshift.com/container-platform/4.15/operators/admin/olm-adding-operators-to-cluster.html
168+
https://docs.redhat.com/en/documentation/openshift_container_platform/4.22/html/operators/administrator-tasks#olm-adding-operators-to-a-cluster
78169

79170
## Memory Optimization for Large Clusters
80171

‎docs/dynamic-plugins.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ spec:
136136

137137
#### Skip TLS Verification (Development Only)
138138

139+
For development registries with self-signed certificates, you can skip certificate verification:
140+
139141
```yaml
140142
apiVersion: rhdh.redhat.com/v1alpha5
141143
kind: DevHubPluginCatalog
@@ -148,6 +150,12 @@ spec:
148150
skipTLSVerify: true
149151
```
150152

153+
**Security Note:**
154+
- Connection remains encrypted (HTTPS)
155+
- Only certificate validation is skipped
156+
- Not recommended for production use
157+
- Prefer using `certificateAuthority` for self-signed certificates
158+
151159
#### Proxy Settings
152160

153161
The operator respects standard proxy environment variables when fetching catalogs:

‎internal/controller/spec_preprocessor.go‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ func (r *BackstageReconciler) preprocessSpec(ctx context.Context, backstage api.
153153
result.DynamicPlugins = *cm
154154
}
155155

156+
// Get mirror configuration from mounted file
157+
result.Mirrors, err = model.GetMirrorConfig()
158+
if err != nil {
159+
return result, fmt.Errorf("failed to read mirror configuration: %w", err)
160+
}
161+
156162
hash := sha256.New()
157163
hash.Write(hashingData)
158164
result.WatchingHash = fmt.Sprintf("%x", hash.Sum(nil))

0 commit comments

Comments
 (0)