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

🌱 Tunnel: Validate namespace/pod at the syncer side #2819

Conversation

jmprusi
Copy link
Member

@jmprusi jmprusi commented Feb 21, 2023

Summary

This PR adds an extra layer of security at the syncer side of the tunneler to ensure that the proxied requests are against a namespace owned by the syncer and a pod in upsync state.

Related issue(s)

Fixes #1975

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 21, 2023
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Feb 21, 2023

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@jmprusi jmprusi changed the title :feature: Tunnel: Validate namespace/pod at the syncer side 🌱 Tunnel: Validate namespace/pod at the syncer side Feb 21, 2023
pkg/syncer/syncer.go Outdated Show resolved Hide resolved
pkg/syncer/syncer.go Outdated Show resolved Hide resolved
pkg/syncer/syncer.go Outdated Show resolved Hide resolved
@jmprusi jmprusi force-pushed the 1975-implement-pod-access-authorization-in-the-syncer-itself branch 4 times, most recently from fbdc37a to 7889f39 Compare February 22, 2023 15:31
@jmprusi jmprusi marked this pull request as ready for review February 22, 2023 15:36
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 22, 2023
@openshift-ci openshift-ci bot requested review from davidfestal and kylape February 22, 2023 15:37
@jmprusi jmprusi force-pushed the 1975-implement-pod-access-authorization-in-the-syncer-itself branch from 7889f39 to 4ae92d9 Compare February 22, 2023 15:58
pkg/syncer/tunneler.go Outdated Show resolved Hide resolved
pkg/syncer/syncer.go Outdated Show resolved Hide resolved
@jmprusi jmprusi force-pushed the 1975-implement-pod-access-authorization-in-the-syncer-itself branch 6 times, most recently from 75a98a2 to 79c0ee4 Compare February 27, 2023 15:58
@jmprusi
Copy link
Member Author

jmprusi commented Feb 28, 2023

/retest

@jmprusi jmprusi force-pushed the 1975-implement-pod-access-authorization-in-the-syncer-itself branch 8 times, most recently from d1dd395 to ac724b1 Compare March 1, 2023 13:59
@jmprusi
Copy link
Member Author

jmprusi commented Mar 1, 2023

/retest

pkg/syncer/syncer.go Outdated Show resolved Hide resolved
pkg/syncer/tunneler.go Outdated Show resolved Hide resolved
pkg/syncer/tunneler.go Outdated Show resolved Hide resolved
pkg/syncer/tunneler.go Outdated Show resolved Hide resolved
pkg/syncer/tunneler.go Show resolved Hide resolved
pkg/syncer/tunneler.go Outdated Show resolved Hide resolved
pkg/syncer/tunneler.go Outdated Show resolved Hide resolved
pkg/syncer/tunneler.go Outdated Show resolved Hide resolved
test/e2e/framework/syncer.go Outdated Show resolved Hide resolved
test/e2e/syncer/tunnels_test.go Outdated Show resolved Hide resolved
@jmprusi jmprusi force-pushed the 1975-implement-pod-access-authorization-in-the-syncer-itself branch from ac724b1 to 5e0a7c9 Compare March 1, 2023 18:00
@jmprusi
Copy link
Member Author

jmprusi commented Mar 2, 2023

/retest

pkg/syncer/tunneler.go Outdated Show resolved Hide resolved
pkg/syncer/tunneler.go Outdated Show resolved Hide resolved
pkg/syncer/tunneler.go Outdated Show resolved Hide resolved
@jmprusi jmprusi force-pushed the 1975-implement-pod-access-authorization-in-the-syncer-itself branch from 5e0a7c9 to 585ee3c Compare March 2, 2023 10:48
@davidfestal
Copy link
Member

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Mar 2, 2023
// Ensure that requests are only for pods, and we have the required information, if not, return false.
if requestInfo.Resource != "pods" || requestInfo.Subresource == "" || requestInfo.Name == "" || requestInfo.Namespace == "" {
responsewriters.ErrorNegotiated(
errors.NewForbidden(podGVR.GroupResource(), requestInfo.Name, fmt.Errorf("only pod subresources are allowed")),
Copy link
Member

Choose a reason for hiding this comment

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

pod is not a subresource

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

obj, err := nsInformer.Get(downstreamNamespaceName)
if errors.IsNotFound(err) {
responsewriters.ErrorNegotiated(
errors.NewForbidden(namespaceGVR.GroupResource(), downstreamNamespaceName, fmt.Errorf("namespace %s does not exist", downstreamNamespaceName)),
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 want to leak that information?

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

}
if locator.SyncTarget.Name != synctargetName || string(locator.SyncTarget.UID) != syncTargetUID || locator.SyncTarget.ClusterName != string(synctargetClusterName) {
responsewriters.ErrorNegotiated(
errors.NewForbidden(namespaceGVR.GroupResource(), downstreamNamespaceName, fmt.Errorf("namespace %q is not owned by this syncer", downstreamNamespaceName)),
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 want to leak that information?

Copy link
Member

Choose a reason for hiding this comment

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

In general, we should not leak the existence of a namespace or a pod.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm returning a more generic forbidden now.

Copy link
Member

Choose a reason for hiding this comment

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

@sttts is it OK for you ?

Copy link
Member

@davidfestal davidfestal left a comment

Choose a reason for hiding this comment

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

Could we complete unit tests to cover the new cases ?

@jmprusi jmprusi force-pushed the 1975-implement-pod-access-authorization-in-the-syncer-itself branch from 585ee3c to 182b830 Compare March 6, 2023 10:05
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Mar 6, 2023
@jmprusi
Copy link
Member Author

jmprusi commented Mar 6, 2023

Could we complete unit tests to cover the new cases ?

Done, PTAL

@jmprusi jmprusi force-pushed the 1975-implement-pod-access-authorization-in-the-syncer-itself branch 2 times, most recently from 4f4d3eb to 4d0531a Compare March 6, 2023 10:17
@davidfestal
Copy link
Member

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Mar 6, 2023
pkg/syncer/tunneler.go Outdated Show resolved Hide resolved
@jmprusi jmprusi force-pushed the 1975-implement-pod-access-authorization-in-the-syncer-itself branch from 4d0531a to ec35135 Compare March 8, 2023 10:27
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Mar 8, 2023
@jmprusi
Copy link
Member Author

jmprusi commented Mar 8, 2023

/retest

@davidfestal
Copy link
Member

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Mar 8, 2023
@sttts
Copy link
Member

sttts commented Mar 8, 2023

/approve

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 8, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sttts

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

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 8, 2023
@openshift-merge-robot openshift-merge-robot merged commit 85793f9 into kcp-dev:main Mar 8, 2023
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. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

implement pod access authorization in the Syncer itself.
6 participants