rpk: warn when role name is not RFC 1123-compliant#30325
Draft
rpk: warn when role name is not RFC 1123-compliant#30325
Conversation
Adds a stderr warning to `rpk security role create` when the role name isn't a valid DNS-1123 subdomain. The warning is informational only -- the role is still created and the command exits 0. The Redpanda Kubernetes operator binds a RedpandaRole CR's role name to its metadata.name, which the Kubernetes API server validates against RFC 1123. Roles like "MyRole" or "App_Service" cannot be adopted by an operator-managed CR and require a manual rename (create new role, copy members, recreate ACLs, delete old) before migration. Surfacing this constraint at create time gives operators a chance to choose operator- friendly names up front. A warning rather than a hard rejection avoids breaking existing users with non-compliant names. Stdout is unchanged so JSON/YAML formatters and scripted callers parsing stdout aren't affected.
r-vasquez
reviewed
Apr 28, 2026
Per @r-vasquez review on PR #30325: - Drop the validateRoleNameForK8s wrapper and its tests; the wrapper added no logic over validation.IsDNS1123Subdomain, so testing it just exercised the upstream function. Call IsDNS1123Subdomain directly at the use site. - Collapse the multi-line warning into a single Fprintf with a raw string template, joining messages with strings.Join.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a stderr warning to
rpk security role createwhen the role name isn't a valid DNS-1123 subdomain. The warning is informational only — the role is still created, exit code stays 0, and stdout is unchanged.Compliant names produce no warning.
What "RFC 1123 compliant" means here
The check uses the DNS-1123 subdomain rule from
k8s.io/apimachinery— the same rule the Kubernetes API server applies tometadata.nameon every object. In short:a–z), digits (0–9), hyphens (-), and dots (.)Examples
my-roleMyRolepaymentsPaymentsteam.read-onlyApp_Serviceapp.staging.us-eastmy rolerole01-fooanalytics-prodfoo-arole!kafka.connect.sinkb2b-eventsauth.v2.readteam..readThe general guidance is: if you'd be comfortable using the name as a hostname segment, it's compliant. If it has uppercase, underscores, spaces, or other punctuation, it isn't.
Motivation
Customers migrating from helm-only Redpanda installs to operator-managed installs have hit a wall when their existing roles have mixed-case or otherwise non-RFC-1123 names. The Redpanda Kubernetes operator binds a
RedpandaRoleCR's role name to itsmetadata.name, which the Kubernetes API server validates against RFC 1123. Roles likeMyRoleorApp_Servicecannot be adopted by an operator-managed CR — there is no way to even create such a CR, since the API server rejects themetadata.nameoutright.The current workaround for migration is a per-role manual sequence: create a new lowercase role, copy members, recreate ACLs that referenced the old principal, then delete the old role. Surfacing this constraint at role-create time gives operators of pre-operator clusters a chance to pick operator-friendly names up front, even if they don't intend to migrate today, and avoids the rename dance later.
Why warning, not rejection
A hard rejection would be a breaking change for every existing Redpanda user with non-compliant role names — not just operator users. Anyone managing roles via
rpkor the Admin API directly today would suddenly see role-create calls fail on upgrade.This change is purely additive. Stdout-consuming callers (e.g. scripts using
--format json) are unaffected because the warning is stderr-only. Existing CI/CD pipelines continue to work.If a stricter mode is desired down the road, this validator is the natural spot to gate it behind a cluster property or an opt-in
rpkflag.Implementation notes
k8s.io/apimachinery/pkg/util/validation.IsDNS1123Subdomain— same rule the K8s API server applies, so the warning is consistent with what the operator's CR validation will actually reject.apimachineryis already an rpk dependency (used byrpk debug bundle); nogo.modchange.publicapi) and self-hosted (adminapi) create paths are covered, since the warning fires before the branch.Test plan
go test ./src/go/rpk/pkg/cli/security/role -run TestValidateRoleNameForK8s— 11 cases covering compliant names, uppercase, leading/trailing hyphens, underscore, space, empty, and >253 charsgo build ./...clean across the rpk modulerpk security role create my-role→ no warning, role createdrpk security role create MyRole→ warning on stderr, role still created, exit 0rpk security role create my-role --format json→ JSON on stdout unchangedOut of scope
rpk security rolesubcommands. The warning only makes sense at create time; assigns/describes/lists referencing an existing non-compliant role would be redundant noise.