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

feat: secure workspace services #1045

Merged
merged 6 commits into from
Sep 17, 2021

Conversation

sparkoo
Copy link
Member

@sparkoo sparkoo commented Sep 1, 2021

What does this PR do?

Secures workspace services with devworkspace engine on OpenShift.

There is a slight change in exposing logic. The ingresses/routes are not merged into one when exposing same port.

Beside that, it also always deploys with gateway on kubernetes when devworkspaces are enabled.

How it works?

Nowdays, workspace service is open to the cluster. It exposes all workspace ports and communication goes directly to target container, so anyone in the cluster can access it.

This patch adds traefik container into workspace pod and narrows the service to only single port (targeting to the traefik) for all endpoints that exposes on subpath. That means that all communication that is coming to the workspace service, must go through the traefik. The traefik is configured so it checks the requests with kube-rbac-proxy (in main che-gateway) using forwardAuth middleware (https://doc.traefik.io/traefik/middlewares/http/forwardauth/). Kube-rbac-proxy is checking whether token in authorization header can access the service in workspace's namespace. If this check is OK, traefik route the request to correct port inside the workspace pod.

Screenshot/screencast of this PR

What issues does this PR fix or reference?

eclipse-che/che#20190

How to test this PR?

  1. deploy with che-operator image quay.io/mvala/che-operator:gh20190-secureWsServicesTraefik
  2. start a workspace with user1 and get the service name
  3. start a workspace with user2 and try curl to the service of user1's workspace. It is now not possible without user1's token in authorization header

PR Checklist

As the author of this Pull Request I made sure that:

Reviewers

Reviewers, please comment how you tested the PR when approving it.

@openshift-ci
Copy link

openshift-ci bot commented Sep 1, 2021

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

@sparkoo sparkoo force-pushed the gh20190-secureWsServicesTraefik branch 2 times, most recently from a41d73c to 9b56256 Compare September 7, 2021 20:39
@sparkoo sparkoo force-pushed the gh20190-secureWsServicesTraefik branch from 9b56256 to 02d7589 Compare September 9, 2021 12:47
@sparkoo sparkoo force-pushed the gh20190-secureWsServicesTraefik branch from 02d7589 to b86d5bf Compare September 9, 2021 14:20
@sparkoo sparkoo force-pushed the gh20190-secureWsServicesTraefik branch from 0a38a1f to f0a939c Compare September 9, 2021 15:30
@sparkoo sparkoo changed the title Gh20190 secure ws services traefik feat: Gh20190 secure ws services traefik Sep 9, 2021
@sparkoo sparkoo force-pushed the gh20190-secureWsServicesTraefik branch from acf4983 to b1e4f86 Compare September 10, 2021 17:26
@sparkoo sparkoo marked this pull request as ready for review September 13, 2021 10:47
@sparkoo sparkoo force-pushed the gh20190-secureWsServicesTraefik branch from 24495e1 to 8427238 Compare September 15, 2021 06:50
Signed-off-by: Michal Vala <mvala@redhat.com>
@sparkoo sparkoo force-pushed the gh20190-secureWsServicesTraefik branch from 8427238 to 78b6367 Compare September 15, 2021 07:16
Signed-off-by: Michal Vala <mvala@redhat.com>
Signed-off-by: Michal Vala <mvala@redhat.com>
Signed-off-by: Michal Vala <mvala@redhat.com>
@sparkoo
Copy link
Member Author

sparkoo commented Sep 15, 2021

/retest

@sparkoo sparkoo changed the title feat: Gh20190 secure ws services traefik feat: secure workspace services Sep 15, 2021
Copy link
Contributor

@metlos metlos left a comment

Choose a reason for hiding this comment

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

I've not tested it in a running cluster yet, but here's a couple of small comments...

controllers/devworkspace/solver/che_routing.go Outdated Show resolved Hide resolved
@@ -360,7 +360,7 @@ func DefaultPullPolicyFromDockerImage(dockerImage string) string {
}

func GetSingleHostExposureType(cr *orgv1.CheCluster) string {
if util.IsOpenShift {
if util.IsOpenShift || cr.Spec.DevWorkspace.Enable {
Copy link
Contributor

@tolusha tolusha Sep 15, 2021

Choose a reason for hiding this comment

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

Why do we need this changes?
So, it means that gateway will be default for k8s when devworkspace is enabled.

Copy link
Contributor

Choose a reason for hiding this comment

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

Exactly. There was the agreement on the last cabal that we're doing that, if I remember correctly.

Copy link
Contributor

Choose a reason for hiding this comment

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

Then DefaultOpenShiftSingleHostExposureType const has no sense anymore.
Let's remove it and just return gateway

Copy link
Member Author

Choose a reason for hiding this comment

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

there will be only gateway with devworkspaces. native does not really work with native auth. Everything we want to protect with oauth-proxy and kube-rbac-proxy has to go through the gateway.

@skabashnyuk
Copy link
Contributor

@sparkoo can you describe in the description how in general protection has been made.

Signed-off-by: Michal Vala <mvala@redhat.com>
Signed-off-by: Michal Vala <mvala@redhat.com>
@sparkoo
Copy link
Member Author

sparkoo commented Sep 16, 2021

@sparkoo can you describe in the description how in general protection has been made.

added "How it works" paragraph

@sparkoo
Copy link
Member Author

sparkoo commented Sep 16, 2021

/retest

@metlos
Copy link
Contributor

metlos commented Sep 16, 2021

Btw I've read the description again and am I correct in saying that the request is checked using kube-rbac-proxy also in the workspace pod (essentially again?). This is important so that we guard against in-cluster access by other users. I thought I saw it in the code but I understood your description otherwise. Could you please clarify?

@sparkoo
Copy link
Member Author

sparkoo commented Sep 16, 2021

Btw I've read the description again and am I correct in saying that the request is checked using kube-rbac-proxy also in the workspace pod (essentially again?). This is important so that we guard against in-cluster access by other users. I thought I saw it in the code but I understood your description otherwise. Could you please clarify?

Yes, it's now checked twice. First in main che-gateway https://github.com/eclipse-che/che-operator/pull/1045/files#diff-ebca2eefe12f7ba4a722c53d574ba1b2adee412909da8cdbc974c8f7fcbfb02fR468 then second time in workspace gateway https://github.com/eclipse-che/che-operator/pull/1045/files#diff-ebca2eefe12f7ba4a722c53d574ba1b2adee412909da8cdbc974c8f7fcbfb02fR554

Copy link
Member

@sleshchenko sleshchenko left a comment

Choose a reason for hiding this comment

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

Nothing really meaningful I can bring after reviewing changes.
Works fine for user1/user2 scenario
Screenshot_20210917_130846

but seems cluster admin is able to open any workspace, I assume it's expected but it should be made clear in the documentation, because it's a change from the previous auth model

@@ -533,7 +702,7 @@ func determineEndpointScheme(gatewayEnabled bool, e dw.Endpoint) string {
upgradeToSecure := e.Secure

// gateway is always on HTTPS, so if the endpoint is served through the gateway, we need to use the TLS'd variant.
if gatewayEnabled && e.Attributes.GetString(urlRewriteSupportedEndpointAttributeName, nil) == "true" {
if e.Attributes.GetString(urlRewriteSupportedEndpointAttributeName, nil) == "true" {
Copy link
Member

Choose a reason for hiding this comment

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

that's such a huge file... Not really related to the PR but it deserves refactoring.

}

func (c *CheRoutingSolver) cheSpecObjects(cheManager *v2alpha1.CheCluster, routing *dwo.DevWorkspaceRouting, workspaceMeta solvers.DevWorkspaceMetadata) (solvers.RoutingObjects, error) {
func (c *CheRoutingSolver) cheSpecObjects(cheCluster *v2alpha1.CheCluster, routing *dwo.DevWorkspaceRouting, workspaceMeta solvers.DevWorkspaceMetadata) (solvers.RoutingObjects, error) {
Copy link
Member

Choose a reason for hiding this comment

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

maybe it makes sense to move this method and its dependency to a separate file. But makes sense to move it out of the PR, since it would not make this PR reviewing easier

@openshift-ci
Copy link

openshift-ci bot commented Sep 17, 2021

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: metlos, sleshchenko, sparkoo, tolusha

The full list of commands accepted by this bot can be found 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

@sparkoo sparkoo merged commit 2ad6c4f into eclipse-che:main Sep 17, 2021
@sparkoo sparkoo deleted the gh20190-secureWsServicesTraefik branch September 17, 2021 10:37
@che-bot che-bot added this to the 7.37 milestone Sep 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants