Skip to content

[patch] auto-sanitize registry prefix to comply with RFC 1123#2471

Merged
durera merged 2 commits into
masterfrom
mascore-15322
Jul 14, 2026
Merged

[patch] auto-sanitize registry prefix to comply with RFC 1123#2471
durera merged 2 commits into
masterfrom
mascore-15322

Conversation

@Jeel-Oza

Copy link
Copy Markdown
Contributor

Summary

Auto-sanitize the registry prefix to comply with RFC 1123 naming rules, preventing validation errors and OpenShift API rejections caused by invalid characters in the prefix.


Problem

When users run mas configure-airgap, mas mirror-images, or mas mirror-redhat with a registry prefix containing characters such as /, \, uppercase letters, or spaces, one of two failures occurs:

1. CLI validation failurevalidate_registry_prefix rejects the prefix with exit 1:

Invalid registry prefix 'test/test'
REGISTRY_PREFIX must be a lowercase RFC 1123 subdomain...

2. OpenShift API failure — if validation is bypassed, the ocp_idms Ansible role builds an invalid IDMS resource name which OpenShift rejects:

Invalid value: "mas-ibm-catalog-test/test": a lowercase RFC 1123 subdomain must consist of
lower case alphanumeric characters, '-', or '.', and must start and end with an alphanumeric character

Solution

Introduce a new sanitize_registry_prefix() function in image/cli/mascli/functions/internal/utils that automatically normalises the prefix before validation:

Input Output Transformation
test/test test-test / replaced with -
test_test test-test _ replaced with -
MyPrefix myprefix uppercase converted to lowercase
test--test test-test consecutive dashes collapsed
-test- test leading/trailing - stripped
MY/folder/path my-folder-path combined transformations

If the value changes during sanitization, a yellow informational note is printed:

Note: Registry prefix 'test/test' is not RFC 1123 compliant and has been automatically changed to 'test-test'
      Make sure your images were also mirrored using 'test-test'

Valid prefixes pass through unchanged with no output.


Also Fixed

Pre-existing bash syntax bug in configure_airgap — spaces around = in variable assignments caused command not found errors in interactive mode:

# Before (broken)
REGISTRY_PRIVATE_URL = "${REGISTRY_PRIVATE_HOST}:${REGISTRY_PRIVATE_PORT}"

# After (fixed)
REGISTRY_PRIVATE_URL="${REGISTRY_PRIVATE_HOST}:${REGISTRY_PRIVATE_PORT}"

Files Changed

File Change
image/cli/mascli/functions/internal/utils Added sanitize_registry_prefix()
image/cli/mascli/functions/configure_airgap Sanitize before validate (x2), fix assignment bug (x2)
image/cli/mascli/functions/mirror_images Sanitize before validate
image/cli/mascli/functions/mirror_images_common Sanitize before validate
image/cli/mascli/functions/mirror_redhat Sanitize before validate (x2)

Testing

Manually tested end-to-end on an OCP cluster with a local Docker registry:

  • mas mirror-images --prefix "test/test" → sanitized to test-test, mirroring proceeded with correct target path host:5000/test-test/cpopen/...
  • mas configure-airgap --prefix "test/jeel123" → sanitized to test-jeel123, IDMS resource created as mas-ibm-catalog-test-jeel123
  • Valid prefixes (test-test, abc.123) → pass through unchanged, no warning printed
  • Empty prefix → no change, no warning

Screenshot 2026-07-13 at 16 20 11 Screenshot 2026-07-13 at 16 38 23 Screenshot 2026-07-13 at 16 38 35 Screenshot 2026-07-13 at 16 39 35 Screenshot 2026-07-13 at 16 45 15 Screenshot 2026-07-13 at 20 23 19

@Jeel-Oza Jeel-Oza requested a review from terc1997 July 14, 2026 10:53
@Jeel-Oza Jeel-Oza self-assigned this Jul 14, 2026
@Jeel-Oza Jeel-Oza requested a review from a team as a code owner July 14, 2026 10:53
@durera

durera commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

FYI, you might want to look at the mirror command ... these updates are to the deprecated image mirroring functions that will soon be removed.

@durera durera merged commit c85863b into master Jul 14, 2026
11 checks passed
@durera durera deleted the mascore-15322 branch July 14, 2026 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants