Skip to content

feat(server): reject resource names that are not RFC 1123 labels - #406

Merged
rakyll merged 1 commit into
google:mainfrom
mvanhorn:cursor/validate-resource-names-dfaf
Sep 25, 2026
Merged

rakyll merged 1 commit into
google:mainfrom
mvanhorn:cursor/validate-resource-names-dfaf

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

ax apply accepted any metadata.name. Names were only checked when the controller created the Substrate ActorTemplate / Actor, which require a lowercase RFC 1123 label, so Task-With-Caps was stored and then failed seconds later with a confusing ActorCreationFailed condition (and the template error before it is swallowed as a WARN, see #366). This moves the check to apply time.

Fixes #370

What changed

  • pkg/apis/v1alpha1: ValidateName (^[a-z0-9]([-a-z0-9]*[a-z0-9])?$, at most 63 characters, matching Substrate's k8s-short-name) and ValidateObjectMeta, which checks metadata.name and, when set, metadata.atespace (it becomes a Substrate atespace name too; empty still defaults to default in the server). ValidateTask now runs it first; new ValidateWorkspace / ValidateModel do the same for the other kinds.
  • internal/server: UpdateWorkspace and UpdateModel call the new validators and return InvalidArgument. UpdateTask already goes through ValidateTask, so it needed no change (this also keeps the diff out of the way of Replace UpdateTask with CreateTask and enforce immutability #398).
  • docs/manifests.md: one paragraph on the naming rule.

The error is phrased so it is actionable straight from the CLI:

Error: applying document 1: rpc error: code = InvalidArgument desc = metadata.name: invalid value "Task-With-Caps": must be a lowercase RFC 1123 label: at most 63 lowercase alphanumeric characters or '-', starting and ending with an alphanumeric character

Notes for review:

  • An empty name is now rejected too; previously it was saved under the key default/. The shipped examples and demo.sh all use valid names.
  • Possible follow-up, deliberately left out to keep the API rule identical to Substrate's: the controller derives <task>-tmpl-<8 hex>, so a task name longer than 49 characters still produces a template name over 63. If you'd like, I can cap task names at 49 in a follow-up.

How tested

  • go test ./... (green), go vet ./..., go mod tidy leaves go.mod / go.sum unchanged.
  • New tests: TestValidateName (valid / invalid table incl. 63 vs 64 chars, uppercase, _, ., leading / trailing -, whitespace, unicode), TestValidateObjectMeta (name and atespace cases, all three kinds), and internal/server TestUpdate_RejectsInvalidNames (Task / Workspace / Model return InvalidArgument, nothing is persisted, valid names still save). The existing TestValidateTask fixtures just gained a name.
  • End to end: built ax and ax-server from this branch, ran ax-server against a local Redis, and applied manifests with an uppercase task name, an underscore workspace name, a dotted atespace, and a valid name (first screenshot).

Evidence

ax apply rejecting invalid names and atespaces at apply time, then accepting a valid one

go test output for the new name validation tests

Demo

ax apply rejecting invalid names

Full-resolution MP4

@google-cla

google-cla Bot commented Sep 25, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

cursor Bot pushed a commit to mvanhorn/ax that referenced this pull request Sep 25, 2026
Keeps the test valid alongside metadata.name validation (google#406).

Co-authored-by: Matt Van Horn <mvanhorn@users.noreply.github.com>
@rakyll

rakyll commented Sep 25, 2026

Copy link
Copy Markdown
Member

Can you sign the CLA?

mvanhorn added a commit to mvanhorn/ax that referenced this pull request Sep 25, 2026
Keeps the test valid alongside metadata.name validation (google#406).

Co-authored-by: Matt Van Horn <mvanhorn@users.noreply.github.com>
ax apply accepted any metadata.name, but Substrate requires actor,
ActorTemplate and atespace names to be lowercase RFC 1123 labels. A name
such as Task-With-Caps was therefore stored, and only failed seconds
later with an asynchronous ActorCreationFailed condition that the user
had to dig out of ax describe or the controller logs.

Validate metadata.name (and metadata.atespace when set) against
[a-z0-9]([-a-z0-9]*[a-z0-9])? with a 63 character limit for Task,
Workspace and Model alike, and return InvalidArgument at apply time.

Fixes google#370

Co-authored-by: Matt Van Horn <mvanhorn@users.noreply.github.com>
@mvanhorn
mvanhorn force-pushed the cursor/validate-resource-names-dfaf branch from 06fe19f to 46a5012 Compare September 25, 2026 14:52
@mvanhorn

Copy link
Copy Markdown
Contributor Author

Thanks @rakyll. The CLA was already signed; the commits had the wrong author email, which I've fixed. cla/google is green now on this PR and #405.

@rakyll rakyll left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you!

@rakyll
rakyll merged commit 099f24a into google:main Sep 25, 2026
9 checks passed
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.

ax-server accepts resource names that Substrate rejects (RFC 1123); failure surfaces asynchronously as ActorCreationFailed

2 participants