Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Enforce maximum constraint template name length of 63 chars #248

Merged
merged 2 commits into from
Sep 29, 2022

Conversation

maxsmythe
Copy link
Contributor

Gatekeeper breaks with longer template names.

Fixes #116

Signed-off-by: Max Smythe smythe@google.com

@maxsmythe maxsmythe force-pushed the max-ct-name-length branch 2 times, most recently from f75cc38 to fefb11a Compare September 16, 2022 22:26
This is provided by controller runtime, but we want to double-check
this doesn't regress.

Fixes open-policy-agent#116

Signed-off-by: Max Smythe <smythe@google.com>
@@ -294,6 +294,15 @@ func TestClient_AddTemplate(t *testing.T) {
wantHandled: map[string]bool{handlertest.TargetName: true},
wantError: nil,
},
{
name: "Long name",
Copy link
Member

Choose a reason for hiding this comment

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

You are adding a test here, where are you adding the validation?

If at most 63 characters, then ConstraintTemplateNames can be up to 253-63=190 characters long.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The validation is already happening on K8's side, since CRD kinds have a maximum size limit. This is just double checking that the check remains in place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i.e. the apiextension validation code we're calling performs this check

Copy link
Member

Choose a reason for hiding this comment

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

I thought Constraints have a maximum name length of 63 chars, not constraint template. This test is throwing an error if the template name is greater than 63 chars?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They both need to have a max name length of 63 chars (this comes from the *PodStatus objects. Because constraint template names -> constraint CRD kinds, k8s is already enforcing this limit for us.

Copy link
Member

Choose a reason for hiding this comment

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

Will's comment in the issue confused me

If at most 63 characters, then ConstraintTemplateNames can be up to 253-63=190 characters long.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, I don't think we knew the validation code was being activated regardless

Copy link
Member

@ritazh ritazh left a comment

Choose a reason for hiding this comment

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

lgtm

@maxsmythe maxsmythe merged commit 1ed2724 into open-policy-agent:master Sep 29, 2022
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.

ConstraintTemplate have no maximum name length
2 participants