Skip to content

Add username prefix restrictions to avoid unexpected failures - #1311

Open
rajivnathan wants to merge 2 commits into
codeready-toolchain:masterfrom
rajivnathan:perfTestUsernameRestrictions
Open

Add username prefix restrictions to avoid unexpected failures#1311
rajivnathan wants to merge 2 commits into
codeready-toolchain:masterfrom
rajivnathan:perfTestUsernameRestrictions

Conversation

@rajivnathan

@rajivnathan rajivnathan commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Another approach to try to address #1308

Summary by CodeRabbit

  • Bug Fixes
    • Setup now validates username prefixes against Dev Sandbox restrictions before proceeding.
    • Invalid prefixes produce a clear error explaining the required format and transformed value.

@openshift-ci
openshift-ci Bot requested review from fbm3307 and metlos August 4, 2026 22:58
@openshift-ci openshift-ci Bot added the approved label Aug 4, 2026
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Walkthrough

Setup now validates usernamePrefix against Dev Sandbox username restrictions. Setup stops with a fatal error when validation changes the prefix and reports the transformed value and required constraints.

Changes

Username Prefix Validation

Layer / File(s) Summary
Validate username prefixes
setup/cmd/root.go
Setup uses usersignup validation for usernamePrefix. It terminates setup when the restricted value differs from the supplied prefix and reports the transformed value and naming constraints.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested labels: feature

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: enforcing username prefix restrictions to prevent setup failures.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot added the feature New feature or request label Aug 4, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@setup/cmd/root.go`:
- Around line 144-155: Update the usernamePrefix validation in the user setup
flow around usersignup.TransformUsername to validate the longest username
userRoutine will generate, reserving the separator and numeric suffix; account
for the additional suffix digit when numberOfUsers exceeds 9,999. Ensure setup
uses the same effective length constraints as host-operator, and add boundary
coverage for 15- and 16-character prefixes with 9,999 and 10,000 users.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: c8cf42d9-9418-4009-a5d3-5f96a7def76a

📥 Commits

Reviewing files that changed from the base of the PR and between dbffb75 and 8f6502a.

📒 Files selected for processing (1)
  • setup/cmd/root.go
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • codeready-toolchain/api (manual)
  • codeready-toolchain/toolchain-common (manual)
  • codeready-toolchain/host-operator (manual)
  • codeready-toolchain/toolchain-e2e (manual)
📜 Review details
⏰ Context from checks skipped due to timeout. (2)
  • GitHub Check: govulncheck
  • GitHub Check: Build & push operator bundles & dashboard image for e2e tests
🧰 Additional context used
📓 Path-based instructions (1)
**

⚙️ CodeRabbit configuration file

-Focus on major issues impacting performance, readability, maintainability and security. Avoid nitpicks and avoid verbosity.

Files:

  • setup/cmd/root.go
🔇 Additional comments (1)
setup/cmd/root.go (1)

14-14: LGTM!

Comment thread setup/cmd/root.go
Comment on lines +144 to +155
transformedUsername := usersignup.TransformUsername(usernamePrefix, []string{"openshift", "kube", "default", "redhat", "sandbox"}, []string{"admin"})
if transformedUsername != usernamePrefix {
term.Fatalf(fmt.Errorf("username prefix '%s' would be transformed to '%s' by Dev Sandbox username restrictions: "+
"must contain only lowercase alphanumeric characters or '-', "+
"must not start or end with '-', "+
"must not start with 'openshift', 'kube', 'default', 'redhat', or 'sandbox', "+
"must not end with 'admin', "+
"must not exceed 20 characters, "+
"and must not be numeric-only",
usernamePrefix, transformedUsername), "invalid username value '%s'", usernamePrefix)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

module_dir="$(go list -m -f '{{.Dir}}' github.com/codeready-toolchain/toolchain-common)"
rg -n -C 4 'TransformUsername|20|admin' "$module_dir/pkg/usersignup"
rg -n -C 4 'usernamePrefix|fmt\.Sprintf\("%s-%04d"' --glob '*.go' .

Repository: codeready-toolchain/toolchain-e2e

Length of output: 274


🏁 Script executed:

set -euo pipefail

printf '%s\n' '--- repository files ---'
fd -t f '(^go\.mod$|root\.go$|.*user.*signup.*|.*signup.*)' . | head -200

printf '%s\n' '--- relevant local references ---'
rg -n -C 8 'TransformUsername|usernamePrefix|fmt\.Sprintf\("%s-%04d"|users\.Create|curUserNum' setup go.mod go.sum 2>/dev/null || true

printf '%s\n' '--- dependency declaration ---'
cat go.mod | sed -n '1,180p'

printf '%s\n' '--- target sections ---'
sed -n '120,170p' setup/cmd/root.go
sed -n '430,480p' setup/cmd/root.go

Repository: codeready-toolchain/toolchain-e2e

Length of output: 19780


🏁 Script executed:

set -euo pipefail

printf '%s\n' '--- username transformation implementation ---'
rg -n -C 12 'func TransformUsername|TransformUsername|Max.*Username|username.*20|20.*username|username.*length' . --glob '*.go' --glob '*.md' || true

printf '%s\n' '--- username consumers and tests ---'
rg -n -C 8 'TransformUsername|Create\(.*username|username.*restriction|numeric-only|must not exceed' . --glob '*.go' --glob '*.md' || true

Repository: codeready-toolchain/toolchain-common

Length of output: 14617


🏁 Script executed:

set -euo pipefail

printf '%s\n' '--- complete TransformUsername implementation ---'
sed -n '1,130p' pkg/usersignup/usersignup.go

printf '%s\n' '--- user creation path ---'
rg -n -C 12 'func Create|func Signup|UserSignup|TransformUsername' pkg --glob '*.go'

Repository: codeready-toolchain/toolchain-common

Length of output: 50392


🏁 Script executed:

set -euo pipefail

printf '%s\n' '--- progress counter semantics ---'
sed -n '350,455p' setup/cmd/root.go

printf '%s\n' '--- users.Create implementation ---'
rg -n -C 10 'func Create|package users|users\.Create' setup . --glob '*.go' --glob '!vendor/**' | head -160

printf '%s\n' '--- generated-name boundary probe ---'
python3 - <<'PY'
for prefix_len in (14, 15, 16, 20):
    prefix = "a" * prefix_len
    for user_num in (1, 9999, 10000):
        username = f"{prefix}-{user_num:04d}"
        print(f"prefix={prefix_len:2d} user={user_num:5d} length={len(username):2d} username={username}")
PY

Repository: codeready-toolchain/toolchain-e2e

Length of output: 15240


🏁 Script executed on selected repositories:

set -euo pipefail

printf '%s\n' '--- e2e user creation ---'
sed -n '18,95p' setup/users/create_users.go

printf '%s\n' '--- host-operator username handling ---'
rg -n -C 10 'TransformUsername|CompliantUsername|IdentityClaims|UserSignup.*Name|username.*MaxLength' . --glob '*.go' | head -260

Repositories: codeready-toolchain/toolchain-e2e, codeready-toolchain/host-operator

Length of output: 23522


🏁 Script executed:

set -euo pipefail

printf '%s\n' '--- host-operator files ---'
fd -t f -e go . | head -120

printf '%s\n' '--- compliant username generation ---'
rg -n -C 12 'TransformUsername|CompliantUsername|PreferredUsername|IdentityClaims' . --glob '*.go' | head -300

Repository: codeready-toolchain/host-operator

Length of output: 29159


🏁 Script executed:

set -euo pipefail

rg -n -C 18 'usersignup\.TransformUsername|usersignup\.MaxLength|compliantUsername\s*[:=]|PreferredUsername' controllers pkg --glob '*.go' | head -260

Repository: codeready-toolchain/host-operator

Length of output: 22479


🏁 Script executed:

set -euo pipefail

rg -n -C 14 'func ForSpace|ForSpace\(' setup testsupport --glob '*.go'

Repository: codeready-toolchain/toolchain-e2e

Length of output: 29626


Validate the longest generated username.

userRoutine appends -%04d before calling users.Create. For a 16-character prefix, the generated username is 21 characters. host-operator truncates it to 20 characters, while setup waits for a Space using the untruncated name. The setup then waits for the wrong Space. Reserve the separator and numeric suffix when validating usernamePrefix, including the extra digit when numberOfUsers exceeds 9,999. Add boundary tests for 15/16-character prefixes and user counts of 9,999/10,000.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@setup/cmd/root.go` around lines 144 - 155, Update the usernamePrefix
validation in the user setup flow around usersignup.TransformUsername to
validate the longest username userRoutine will generate, reserving the separator
and numeric suffix; account for the additional suffix digit when numberOfUsers
exceeds 9,999. Ensure setup uses the same effective length constraints as
host-operator, and add boundary coverage for 15- and 16-character prefixes with
9,999 and 10,000 users.

@sonarqubecloud

sonarqubecloud Bot commented Aug 5, 2026

Copy link
Copy Markdown

@MatousJobanek MatousJobanek left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering, why not using TransformUsername when calling the ForSpace?

@openshift-ci

openshift-ci Bot commented Aug 6, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alexeykazakov, MatousJobanek, rajivnathan

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [MatousJobanek,alexeykazakov,rajivnathan]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants