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

Implements GEP 709 - ReferencePolicy #741

Merged

Conversation

youngnick
Copy link
Contributor

What type of PR is this?

/kind feature
/kind documentation

What this PR does / why we need it:

This implements the design from GEP 709.

It adds a couple of extra things we missed in the GEP, that I noticed while implementing:

  • Condition Reason for Gateway status and an explanation of how the status must work.
  • Adds an ObjectReference type for cross-namespace references, to keep the existing LocalObjectReference type more similar to the core one.

Which issue(s) this PR fixes:

Fixes #709

Does this PR introduce a user-facing change?:

Added a ReferencePolicy object for controlling cross-namespace references.

@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. kind/documentation Categorizes issue or PR as related to documentation. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Aug 2, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: youngnick

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:

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

@k8s-ci-robot k8s-ci-robot requested review from hbagdi and jpeach August 2, 2021 04:03
@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 2, 2021
apis/v1alpha2/object_reference_types.go Show resolved Hide resolved
```
### Conformance Level

ReferencePolicy support is a "CORE" coformance level for the following
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
ReferencePolicy support is a "CORE" coformance level for the following
ReferencePolicy support is a "Core" conformance level for the following

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure which is better here, but we should be consistent. Our docs around conformance levels use all caps, but usually the spec does not. Do we have a strong preference one way or the other?

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 lifted this phrasing from one of the other GEPs - I don't mind changing, but if so, we should change the others as well.

apis/v1alpha2/httproute_types.go Outdated Show resolved Hide resolved
apis/v1alpha2/referencepolicy_types.go Outdated Show resolved Hide resolved
// +kubebuilder:object:root=true
// +kubebuilder:resource:categories=gateway-api,shortName=refpol
// +kubebuilder:storageversion
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
Copy link
Contributor

Choose a reason for hiding this comment

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

We can revisit this, but the age doesn't seem particularly useful?

Copy link
Member

Choose a reason for hiding this comment

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

I think it's a pretty standard column for k8s resources. I think it could be helpful to know when a resource was created.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1, should be on all resources.

1. Resource names are intentionally excluded from this policy for simplicity and because they rarely provide any meaningful protection.
A user that is able to write to resources of a certain kind within a namespace can always rename
resources or change the structure of the resources to match a given policy.
1. A single Namespace is allowed per "From" struct.
Copy link
Contributor

Choose a reason for hiding this comment

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

is "all"/"any" not a common use case? I see the concerns of making it too permissive but generally APIs offer some way to be fairly permissive, even if its not easy.

Copy link
Member

Choose a reason for hiding this comment

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

I think that's probably something we'll want to add in the future, but I'd rather start with something more restrictive that we can choose to open up if it's absolutely needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to both the comments above

Copy link
Member

@robscott robscott left a comment

Choose a reason for hiding this comment

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

Thanks for the work on this @youngnick! Mostly LGTM.

apis/v1alpha2/referencepolicy_types.go Outdated Show resolved Hide resolved
These references are only considered valid if a ReferencePolicy in the target namespace explicitly allows it.

The following example shows how a HTTPRoute in namespace `foo` can reference a Service in namespace `bar`.
In this example a ReferencePolicy in the `bar` namespace explicitly allows references to Services from HTTPRoutes in the `foo` namespace.
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Much of our markdown is wrapped at 80 chars. I don't think this is a firm requirement, but the shorter lines can make reviews slightly easier.

1. Resource names are intentionally excluded from this policy for simplicity and because they rarely provide any meaningful protection.
A user that is able to write to resources of a certain kind within a namespace can always rename
resources or change the structure of the resources to match a given policy.
1. A single Namespace is allowed per "From" struct.
Copy link
Member

Choose a reason for hiding this comment

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

I think that's probably something we'll want to add in the future, but I'd rather start with something more restrictive that we can choose to open up if it's absolutely needed.

site-src/v1alpha2/references/cross-namespace-references.md Outdated Show resolved Hide resolved
site-src/v1alpha2/references/cross-namespace-references.md Outdated Show resolved Hide resolved
site-src/v1alpha2/references/cross-namespace-references.md Outdated Show resolved Hide resolved
site-src/v1alpha2/references/cross-namespace-references.md Outdated Show resolved Hide resolved
@@ -1,7 +1,7 @@
# GEP-709: Cross Namespace References from Routes

* Issue: [#709](https://github.com/kubernetes-sigs/gateway-api/issues/709)
* Status: Implementable
* Status: Implemented
Copy link
Member

Choose a reason for hiding this comment

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

👏 Good catch!

Copy link
Contributor

@hbagdi hbagdi left a comment

Choose a reason for hiding this comment

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

Great stuff! Thanks Nick.

apis/v1alpha2/httproute_types.go Outdated Show resolved Hide resolved
apis/v1alpha2/object_reference_types.go Show resolved Hide resolved
apis/v1alpha2/referencepolicy_types.go Show resolved Hide resolved
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`

// ReferencePolicy identifies kinds of resources in other namespaces that are
// trusted to reference the specified kinds of resources in the local namespace.
Copy link
Contributor

Choose a reason for hiding this comment

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

local is good but same might reduce the scope of confusion.

Suggested change
// trusted to reference the specified kinds of resources in the local namespace.
// trusted to reference the specified kinds of resources in the same namespace as the policy.

apis/v1alpha2/referencepolicy_types.go Show resolved Hide resolved
site-src/v1alpha2/references/cross-namespace-references.md Outdated Show resolved Hide resolved
1. Resource names are intentionally excluded from this policy for simplicity and because they rarely provide any meaningful protection.
A user that is able to write to resources of a certain kind within a namespace can always rename
resources or change the structure of the resources to match a given policy.
1. A single Namespace is allowed per "From" struct.
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to both the comments above

site-src/v1alpha2/references/cross-namespace-references.md Outdated Show resolved Hide resolved
site-src/v1alpha2/references/cross-namespace-references.md Outdated Show resolved Hide resolved
@youngnick
Copy link
Contributor Author

Okay, thanks for the reviews everyone, updated. I think I got all the actions I could. Please take another look!

//
// Support: Core
//
// +kubebuilder:validation:MinLength=1
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I missed this in the GEP, but we can't enforce a min length of 1 for Group. We have to support "" for core.

Comment on lines 133 to 136
// * HTTPRoute
// * TCPRoute
// * TLSRoute
// * UDPRoute
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should remove these until we actually implement Route inclusion?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

// Support: Custom
//
// +optional
BackendRef *LocalObjectReference `json:"backendRef,omitempty"`
BackendRef *ObjectReference `json:"backendRef,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

This is on a collision course with GEP #718, but since there's not an implementation PR for that one yet, I think this one will likely make it in first.

@robscott
Copy link
Member

robscott commented Aug 6, 2021

A few small things but otherwise LGTM, thanks @youngnick!

Copy link
Contributor

@hbagdi hbagdi left a comment

Choose a reason for hiding this comment

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

LGTM, some nits.

// ObjectReference identifies an API object including its namespace.
type ObjectReference struct {
// Group is the group of the referent.
// When empty, the "core" API group is inferred.
Copy link
Contributor

Choose a reason for hiding this comment

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

So interestingly, when the field is empty, it doesn't show up in 'kubectl get'. Just leaving a note here. No action required.

apis/v1alpha2/referencepolicy_types.go Show resolved Hide resolved
Comment on lines +62 to +63
// to be an additional place that references can be valid from, or to put
// this another way, entries must be combined using OR.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I personally got more confused. Feel free to reject.

Suggested change
// to be an additional place that references can be valid from, or to put
// this another way, entries must be combined using OR.
// to be an additional place that references can be valid from.

Copy link
Member

Choose a reason for hiding this comment

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

I've gone back and forth on this, agree it's a bit confusing, but think the specific "combined using OR" may end up being helpful. Either way, we can clean this up later if it ends up being a point of confusion.

// To describes the resources that may be referenced by the resources
// described in "From". Each entry in this list must be considered to be an
// additional place that references can be valid to, or to put this another
// way, entries must be combined using OR.
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment.

Comment on lines 133 to 136
// * HTTPRoute
// * TCPRoute
// * TLSRoute
// * UDPRoute
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

site-src/v1alpha2/references/cross-namespace-references.md Outdated Show resolved Hide resolved
@robscott
Copy link
Member

robscott commented Aug 6, 2021

Fixes #582

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 6, 2021
@robscott robscott linked an issue Aug 6, 2021 that may be closed by this pull request
Nick Young added 4 commits August 8, 2021 23:43
Signed-off-by: Nick Young <ynick@vmware.com>
Signed-off-by: Nick Young <ynick@vmware.com>
Signed-off-by: Nick Young <ynick@vmware.com>
Signed-off-by: Nick Young <ynick@vmware.com>
@youngnick youngnick force-pushed the gep-709-referencepolicy branch from 37884a1 to 0ad53af Compare August 9, 2021 01:27
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 9, 2021
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 9, 2021
@youngnick youngnick force-pushed the gep-709-referencepolicy branch 2 times, most recently from 31e2f68 to 4c9e188 Compare August 9, 2021 01:36
Signed-off-by: Nick Young <ynick@vmware.com>
@youngnick youngnick force-pushed the gep-709-referencepolicy branch from 4c9e188 to e4bfd3a Compare August 9, 2021 01:39
Copy link
Member

@robscott robscott left a comment

Choose a reason for hiding this comment

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

Thanks for all the work on this @youngnick! Have a bunch of tiny nits, most are non-blocking though. Otherwise LGTM.

apis/v1alpha2/httproute_types.go Outdated Show resolved Hide resolved
//
// Note that when a namespace is specified, a ReferencePolicy object
// is required in the referent namespace to allow that namespace's
// owner to accept the reference. See the ReferencePolicy object for details.
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
// owner to accept the reference. See the ReferencePolicy object for details.
// owner to accept the reference. See the ReferencePolicy documentation for details.

// +optional
// +kubebuilder:default=""
// +kubebuilder:validation:MaxLength=253
Group *string `json:"group"`
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
Group *string `json:"group"`
Group *string `json:"group,omitempty"`

// +kubebuilder:default=Service
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
Kind *string `json:"kind"`
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
Kind *string `json:"kind"`
Kind *string `json:"kind,omitempty"`

Comment on lines +62 to +63
// to be an additional place that references can be valid from, or to put
// this another way, entries must be combined using OR.
Copy link
Member

Choose a reason for hiding this comment

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

I've gone back and forth on this, agree it's a bit confusing, but think the specific "combined using OR" may end up being helpful. Either way, we can clean this up later if it ends up being a point of confusion.

Comment on lines 27 to 28


Copy link
Member

Choose a reason for hiding this comment

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

Can probably remove these new lines.

kind: HTTPRoute
namespace: foo
to:
- group: core
Copy link
Member

Choose a reason for hiding this comment

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

Now that we're allowing "" to represent core, we should probably update our examples to match.

Suggested change
- group: core
- group: ""

Comment on lines +125 to +127
Other "ImplementationSpecific" objects and references MUST also use this flow
for cross-namespace references, except as noted in the Exceptions section
above.
Copy link
Member

Choose a reason for hiding this comment

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

More a note for me, but when I implement the Route-Gateway binding GEP, I'll need to update this to discuss the uniqueness of that relationship.

When discussing the process of creating cross-namespace object references, this
document and the documentation on the API itself refers to the object being
referred to as "the referent object", using the meaning of "referent" to be
"the person, thing, or idea that a word, phrase, or object refers to".[1](https://dictionary.cambridge.org/dictionary/english/referent)
Copy link
Member

Choose a reason for hiding this comment

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

This footnote looks a bit off in the deploy preview. Maybe either use <sup> tag or a full word like (source).
https://deploy-preview-741--kubernetes-sigs-gateway-api.netlify.app/v1alpha2/references/cross-namespace-references/

@@ -0,0 +1,127 @@
# Cross namespace references and ReferencePolicy

### Terminology note
Copy link
Member

Choose a reason for hiding this comment

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

This feels a bit out of place. Not sure how this would render with mkdocs, but maybe something like a blockquote or callout format with this content added in the Intro section right before/after "Referent" is mentioned for the first time.

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 didn't like it there either, but couldn't think of the right place to put it. I'll see how we can do a blockquote or something more inline instead.

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 I found a "Note" syntax that should work, I'll check the deploy preview.

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 added in an "admonitions" extension, that we can use with:

!!! admonition
    blockquote text is indented by four spaces

Copy link
Member

Choose a reason for hiding this comment

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

This looks perfect! Thanks for adding it in

Nick Young added 2 commits August 9, 2021 05:06
Signed-off-by: Nick Young <ynick@vmware.com>
Signed-off-by: Nick Young <ynick@vmware.com>
@youngnick youngnick force-pushed the gep-709-referencepolicy branch from 61078d8 to 677a3c0 Compare August 9, 2021 06:02
@robscott
Copy link
Member

robscott commented Aug 9, 2021

Thanks for all the work on this!

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 9, 2021
@k8s-ci-robot k8s-ci-robot merged commit 5096d25 into kubernetes-sigs:master Aug 9, 2021
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/documentation Categorizes issue or PR as related to documentation. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GEP: Enable cross namespace references from Routes Allow cross namespace references
6 participants