Skip to content

CFE-885:Feature route external certificate validation#407

Merged
openshift-merge-bot[bot] merged 4 commits intoopenshift:masterfrom
chiragkyal:feature/route-externalcertificate-validation
Apr 30, 2024
Merged

CFE-885:Feature route external certificate validation#407
openshift-merge-bot[bot] merged 4 commits intoopenshift:masterfrom
chiragkyal:feature/route-externalcertificate-validation

Conversation

@chiragkyal
Copy link
Member

@chiragkyal chiragkyal commented Nov 30, 2023

Description

Updates route validations based on openshift/enhancements#1307 which introduces a new field in the route API externalCertificate behind the TP feature gate.

Changes

  • ValidateRoute() has been updated to pass additional args (secrets lister and subjectaccessreviewer) to validate externalCertificate and the rbac required.
  • ValidateHostUpdate() has also been updated since updating route host/subdomain is also affected by updating
    certificates on the route.
  • ValidateHostExternalCertificate() has been introduced as part of the validations done during route updates, this function specifically checks if the user has the correct permissions on the custom-host sub-resource. Additional details can be found on the EP.

Follow up from: openshift/library-go#1625
Featuregate wiring : #382

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Nov 30, 2023
@openshift-ci-robot
Copy link

openshift-ci-robot commented Nov 30, 2023

@chiragkyal: This pull request references CFE-885 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the sub-task to target the "4.15.0" version, but no target version was set.

Details

In response to this:

Description

Updates route validations based on openshift/enhancements#1307 which introduces a new field in the route API externalCertificate behind the TP feature gate.

Changes

  • ValidateRoute() has been updated to pass additional args (secrets lister and subjectaccessreviewer) to validate externalCertificate and the rbac required.
  • ValidateHostUpdate() has also been updated since updating route host/subdomain is also affected by updating
    certificates on the route.
  • ValidateHostExternalCertificate() has been introduced as part of the validations done during route updates, this function specifically checks if the user has the correct permissions on the custom-host sub-resource. Additional details can be found on the EP.

Follow up from: openshift/library-go#1625

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 30, 2023
@openshift-ci openshift-ci bot requested review from bparees and knobunc November 30, 2023 12:10
@chiragkyal
Copy link
Member Author

Continue : #385

@chiragkyal chiragkyal force-pushed the feature/route-externalcertificate-validation branch from 49d5243 to 532bd3b Compare November 30, 2023 13:28
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 30, 2023
@chiragkyal
Copy link
Member Author

/cc @alebedev87

@openshift-ci openshift-ci bot requested a review from alebedev87 November 30, 2023 13:31
@chiragkyal
Copy link
Member Author

/assign @alebedev87

@chiragkyal
Copy link
Member Author

/assign @vrutkovs

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 25, 2024
@openshift-ci-robot
Copy link

openshift-ci-robot commented Feb 8, 2024

@chiragkyal: This pull request references CFE-885 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.16.0" version, but no target version was set.

Details

In response to this:

Description

Updates route validations based on openshift/enhancements#1307 which introduces a new field in the route API externalCertificate behind the TP feature gate.

Changes

  • ValidateRoute() has been updated to pass additional args (secrets lister and subjectaccessreviewer) to validate externalCertificate and the rbac required.
  • ValidateHostUpdate() has also been updated since updating route host/subdomain is also affected by updating
    certificates on the route.
  • ValidateHostExternalCertificate() has been introduced as part of the validations done during route updates, this function specifically checks if the user has the correct permissions on the custom-host sub-resource. Additional details can be found on the EP.

Follow up from: openshift/library-go#1625
Featuregate wiring : #382

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@chiragkyal chiragkyal force-pushed the feature/route-externalcertificate-validation branch from d4a6cd5 to 230d388 Compare February 8, 2024 17:48
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 8, 2024
@chiragkyal chiragkyal force-pushed the feature/route-externalcertificate-validation branch from ac0a1da to a391162 Compare February 16, 2024 09:22
@chiragkyal chiragkyal force-pushed the feature/route-externalcertificate-validation branch 3 times, most recently from ab26c65 to 5234209 Compare April 7, 2024 16:00
@chiragkyal
Copy link
Member Author

chiragkyal commented Apr 11, 2024

Looks like the CIs are failing due to Kube 1.29 rebase issue.
There is a open PR for kube bump: #421

@chiragkyal
Copy link
Member Author

Created a PR #425 for Kube 1.29 bump, which should unblock this PR.

Signed-off-by: chiragkyal <ckyal@redhat.com>
Signed-off-by: chiragkyal <ckyal@redhat.com>
@chiragkyal chiragkyal force-pushed the feature/route-externalcertificate-validation branch from 5234209 to dfe5716 Compare April 18, 2024 06:11
@Miciah
Copy link
Contributor

Miciah commented Apr 20, 2024

I ran make update with this branch checked out on my system, and it did update pkg/openapi/zz_generated.openapi.go. Miciah@084ea84 has the result.

@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Apr 22, 2024
@chiragkyal
Copy link
Member Author

I had my forked repo cloned into ~/go/src/github.com/chiragkyal/openshift-apiserver and openapi-gen was not working as expected. After moving that fork into ~/go/src/github.com/openshift/openshift-apiserver, make update did change the same file what @Miciah suggested.

@Miciah
Copy link
Contributor

Miciah commented Apr 22, 2024

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Apr 22, 2024
@chiragkyal
Copy link
Member Author

/test e2e-aws-ovn-serial

Copy link
Contributor

@p0lyn0mial p0lyn0mial left a comment

Choose a reason for hiding this comment

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

Are you planing to add an e2e test for this functionality ?

// RunAPIServer takes the options, starts the API server and waits until stopCh is closed or initial listening fails.
func (o *OpenShiftAPIServer) RunAPIServer(stopCh <-chan struct{}) error {
if err := features.InitializeFeatureGates(feature.DefaultMutableFeatureGate, configv1.FeatureGateRouteExternalCertificate); err != nil {
if err := features.InitializeFeatureGates(feature.DefaultMutableFeatureGate, configv1.SelfManaged, configv1.FeatureGateRouteExternalCertificate); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Assuming Hypershift runs this instance of the API server, how does it specify its own profile?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

please add a comment explaining why to this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

please add a comment explaining why to this PR.

Arbitrary choice since this binary doesn't care and teaching the operand about hypershift is not likely to end well.

AdditionalTrustedCA: caData,
RouteAllocator: routeAllocator,
AllowRouteExternalCertificates: feature.DefaultFeatureGate.Enabled(featuregate.Feature(configv1.FeatureGateRouteExternalCertificate)),
AllowRouteExternalCertificates: feature.DefaultMutableFeatureGate.Enabled(featuregate.Feature(configv1.FeatureGateRouteExternalCertificate)),
Copy link
Contributor

Choose a reason for hiding this comment

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

why did you change it ?

Copy link
Contributor

Choose a reason for hiding this comment

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

please bring back the previous version.

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like both of them carry same thing internally

https://github.com/kubernetes/kubernetes/blob/c91913924543e1d29f3f3d51354701df9df75def/staging/src/k8s.io/apiserver/pkg/util/feature/feature_gate.go#L32

Is it suggested to use DefaultFeatureGate over DefaultMutableFeatureGate ? because we've used DefaultMutableFeatureGate in kube-apiserver

Copy link
Contributor

Choose a reason for hiding this comment

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

DefaultMutableFeatureGate exposes a different interface. DefaultFeatureGate is read-only, it is not a big deal but I prefer DefaultFeatureGate.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, changed to DefaultFeatureGate


// ValidateRoute tests if required fields in the route are set.
func ValidateRoute(route *routeapi.Route, opts RouteValidationOptions) field.ErrorList {
func ValidateRoute(ctx context.Context, route *routeapi.Route, sarc routecommon.SubjectAccessReviewCreator, secretsGetter corev1client.SecretsGetter, opts routecommon.RouteValidationOptions) field.ErrorList {
Copy link
Contributor

Choose a reason for hiding this comment

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

The units we have in strategy_test are going to validate ValidateRoute and ValidateRouteUpdate, right ?

Copy link
Member Author

Choose a reason for hiding this comment

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

route := obj.(*routeapi.Route)
errs := routehostassignment.AllocateHost(ctx, route, s.sarClient, s.hostnameGenerator)
errs = append(errs, validation.ValidateRoute(route, s.routeValidationOptions())...)
errs := routehostassignment.AllocateHost(ctx, route, s.sarClient, s.hostnameGenerator, s.routeValidationOptions())
Copy link
Contributor

Choose a reason for hiding this comment

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

@benluddy why hasn't this been added as a normal admission plugin?

Copy link
Contributor

Choose a reason for hiding this comment

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

okay, it looks like this code was added in openshift/kubernetes#1904 and it seems it could be refactored.

Comment on lines 83 to 91
func routeOptionsAdapter(route *routeapi.Route) field.ErrorList {
return routevalidation.ValidateRoute(route, routevalidation.RouteValidationOptions{})
a := &authorizationclient.AuthorizationV1Client{}
return routevalidation.ValidateRoute(context.Background(), route, a.SubjectAccessReviews(), &v1.CoreV1Client{}, routecommon.RouteValidationOptions{})
}

func routeUpdateOptionsAdapter(route *routeapi.Route, oldRoute *routeapi.Route) field.ErrorList {
return routevalidation.ValidateRouteUpdate(route, oldRoute, routevalidation.RouteValidationOptions{})
a := &authorizationclient.AuthorizationV1Client{}
return routevalidation.ValidateRouteUpdate(context.Background(), route, oldRoute, a.SubjectAccessReviews(), &v1.CoreV1Client{}, routecommon.RouteValidationOptions{})
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Used by units in

(for validating object's metadata), we should be fine.

@p0lyn0mial
Copy link
Contributor

/approve
/hold

until you resolve some of the comments, also it would be nice if you could add an e2e test for this functionality.

@openshift-ci openshift-ci bot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. approved Indicates a PR has been approved by an approver from all required OWNERS files. and removed lgtm Indicates that a PR is ready to be merged. labels Apr 30, 2024
@p0lyn0mial
Copy link
Contributor

please squash the new commits into [CFE-885: Update route validation and admission to honour externalCertificate

@chiragkyal chiragkyal force-pushed the feature/route-externalcertificate-validation branch from 595df6e to 74f2fc1 Compare April 30, 2024 12:52
@chiragkyal
Copy link
Member Author

Are you planing to add an e2e test for this functionality ?

We are planning to add e2e tests while graduating this feature to GA.

Ref: https://github.com/openshift/enhancements/blob/master/enhancements/ingress/route-secret-injection-for-external-certificate-management.md#graduation-criteria

@chiragkyal
Copy link
Member Author

please squash the new commits into [CFE-885: Update route validation and admission to honour externalCertificate

Done

Are we good to unhold and merge?


// ValidateRoute tests if required fields in the route are set.
func ValidateRoute(route *routeapi.Route, opts RouteValidationOptions) field.ErrorList {
func ValidateRoute(ctx context.Context, route *routeapi.Route, sarClient routecommon.SubjectAccessReviewCreator, secretsGetter corev1client.SecretsGetter, opts routecommon.RouteValidationOptions) field.ErrorList {
Copy link
Contributor

Choose a reason for hiding this comment

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

As a final comment, create and update require a lot of SAR requests, but that was agreed upon, described in the proposal and added to the library-go code - https://github.com/thejasn/enhancements/blob/d4c7701193646105e2c60b2b996047ddfed083a4/enhancements/ingress/route-secret-injection-for-external-certificate-management.md

@p0lyn0mial
Copy link
Contributor

/hold cancel
/lgtm

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 30, 2024
@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Apr 30, 2024
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Apr 30, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: chiragkyal, Miciah, p0lyn0mial

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:

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

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Apr 30, 2024

@chiragkyal: all tests passed!

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@openshift-merge-bot openshift-merge-bot bot merged commit dd8658e into openshift:master Apr 30, 2024
@chiragkyal chiragkyal deleted the feature/route-externalcertificate-validation branch April 30, 2024 17:00
@openshift-bot
Copy link
Contributor

[ART PR BUILD NOTIFIER]

This PR has been included in build ose-openshift-apiserver-container-v4.17.0-202404302014.p0.gdd8658e.assembly.stream.el9 for distgit ose-openshift-apiserver.
All builds following this will include this PR.

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

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants