Skip to content

Webhook to check name + namespace exceeds 63 characters #117

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

Conversation

yiraeChristineKim
Copy link
Contributor

Description: No validation if name + namespace exceeds 63 characters and Policy applied via CLI or Gitops now

After fix: Error from server (Forbidden): error when creating "policy.yaml": admission webhook "policy.open-cluster-management.io.webhook" denied the request: the combined length of namespace and policy name (namespaceName.policyName) should not exceed 63 characters

This error message shows on terminal when policy name + namespace exceeds 63 characters

Ref: https://issues.redhat.com/browse/ACM-4394

labels:
app.kubernetes.io/component: manager
app.kubernetes.io/created-by: webhook
app.kubernetes.io/instance: controller-manager
app.kubernetes.io/managed-by: kustomize
app.kubernetes.io/name: deployment
app.kubernetes.io/part-of: webhook
control-plane: controller-manager
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to add any of these labels for the webhook to work? If so, let's make them a bit more specific to just our controller, if possible. Eg app.kubernetes.io/name: governance-policy-propagator

Copy link
Contributor Author

Choose a reason for hiding this comment

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

seems like woking well without label

Expect(err).ShouldNot(HaveOccurred())
})
Describe("Test name + namespace over 63", func() {
It("Should the error message is presented", func() {
Copy link
Member

Choose a reason for hiding this comment

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

Can we add another test for when the error doesn't happen? Since this is the only test running right now when the webhook is enabled, I think?

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 tried to add update case but namespace and name cannot be modified... I tried to add long namespace and short name but namespace itself has limitation so... would you give some idea?!

@yiraeChristineKim yiraeChristineKim force-pushed the ACM-3558 branch 3 times, most recently from e0378df to 6e8dd3f Compare June 26, 2023 15:20
@yiraeChristineKim yiraeChristineKim force-pushed the ACM-3558 branch 2 times, most recently from 6dab275 to 3d1fdd0 Compare July 19, 2023 13:07
@yiraeChristineKim yiraeChristineKim requested a review from mprahl July 19, 2023 13:42

var (
// log is for logging in this package.
policylog = logf.Log.WithName("policy-resource")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
policylog = logf.Log.WithName("policy-resource")
policylog = logf.Log.WithName("policy-validating-webhook")

@@ -0,0 +1,61 @@
apiVersion: v1
Copy link
Member

Choose a reason for hiding this comment

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

main.go Outdated

pflag.StringVar(&metricsAddr, "metrics-bind-address", ":8383", "The address the metric endpoint binds to.")
pflag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
pflag.BoolVar(&enableLeaderElection, "leader-elect", true,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
pflag.BoolVar(&enableWebhooks, "enable-webhooks", true,
"Enable webhook for validating namespace + name less than 63 characters")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"Enable webhook for validating namespace + name less than 63 characters")
"Enable the policy validating webhook")

Comment on lines 74 to 75
Expect(utf8.RuneCountInString(testNamespace+"."+case17PolicyReplicatedName) +
utf8.RuneCountInString("managed1")).Should(BeNumerically(">", 63))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Expect(utf8.RuneCountInString(testNamespace+"."+case17PolicyReplicatedName) +
utf8.RuneCountInString("managed1")).Should(BeNumerically(">", 63))
Expect(utf8.RuneCountInString("managed1."+testNamespace+"."+case17PolicyReplicatedName)).Should(BeNumerically(">", 63))

Copy link
Member

@mprahl mprahl left a comment

Choose a reason for hiding this comment

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

This is looking really good! Just a few minor comments.

mprahl
mprahl previously approved these changes Jul 19, 2023
@mprahl
Copy link
Member

mprahl commented Jul 19, 2023

@JustinKuli did you want to take another look at this?

- The 63 character limit validation for policy name is not working while creating a Policy via CLI.
- Policy creation - Policy name + namespace name can’t go longer than 63
From CLI, it possible to create a policy with a name like “policy-check-setupjob-setupjob-operator-installer” with no issue; but, while wanting to edit it, we can’t.
- Getting this error: “The combined length of namespace and policy nmabe (namespaceName.policyName) should not exceed 63 characters (see attached screeshot)

Ref: https://issues.redhat.com/browse/ACM-3558

Signed-off-by: Yi Rae Kim <[email protected]>
ports:
- port: 443
protocol: TCP
targetPort: 9443
Copy link
Member

Choose a reason for hiding this comment

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

Do you want to use the name (i.e. webhook-http) here instead of the port number?

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 think targetport is enough

Copy link
Contributor Author

Choose a reason for hiding this comment

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

why I change to webhook-http, http duplicated so there was kind test error

@yiraeChristineKim yiraeChristineKim requested a review from mprahl July 19, 2023 15:56
Copy link
Member

@mprahl mprahl left a comment

Choose a reason for hiding this comment

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

/hold in case @JustinKuli wants to review it again

Copy link
Member

@JustinKuli JustinKuli left a comment

Choose a reason for hiding this comment

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

LGTM

@JustinKuli
Copy link
Member

/unhold

@openshift-ci
Copy link

openshift-ci bot commented Jul 19, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JustinKuli, mprahl, yiraeChristineKim

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

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [JustinKuli,mprahl,yiraeChristineKim]

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants