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

Enable Server Side Authentication when using the Kubernetes Proxy #16649

Merged
merged 3 commits into from Apr 4, 2023

Conversation

RubenV-dev
Copy link
Contributor

@RubenV-dev RubenV-dev commented Feb 28, 2023

Hey, I just made a Pull Request!

Current State:

The Kubernetes Proxy requires authentication headers as part of its request in order to display k8s resource information.
The KubernetesAuthTranslatorGenerator class uses a static class method to instantiate a variety of different auth translators depending on the authProvider that is provided.

Suggested Change:

Move the dependency of kubernetesAuthTranslator creation to the plugin that requires it and provide it via a translatorMap parameter to the KubernetesAuthTranslatorGenerator
Provide Backstages Integrator access to k8s operations by default without the need to negotiate k8s tokens client-side. This will allow users to consume plugins with complex k8s logic without having kubectl access themselves.

With these suggested changes a user can create a kind cluster to test. Provision a high powered service account token.

and use:

curl -H 'X-Kubernetes-Cluster: kind-cluster' localhost:7007/api/kubernetes/proxy/api/v1/namespaces

to see all the namespaces on that kind cluster without the need of supplying authentication headers.

✔️ Checklist

  • A changeset describing the change and affected packages. (more info)
  • Added or updated documentation
  • Tests for new functionality and regression tests for bug fixes
  • Screenshots attached (for UI changes)
  • All your commits have a Signed-off-by line in the message. (more info)

@backstage-goalie
Copy link
Contributor

backstage-goalie bot commented Feb 28, 2023

Changed Packages

Package Name Package Path Changeset Bump Current Version
@backstage/plugin-kubernetes-backend plugins/kubernetes-backend minor v0.10.0-next.1

@github-actions
Copy link
Contributor

github-actions bot commented Feb 28, 2023

Uffizzi Ephemeral Environment Deploying

☁️ https://app.uffizzi.com/github.com/backstage/backstage/pull/16649

⚙️ Updating now by workflow run 4558169106.

What is Uffizzi? Learn more!

Copy link
Member

@jamieklassen jamieklassen left a comment

Choose a reason for hiding this comment

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

A neat improvement here that might be nice to declare in a changeset is that KubernetesBuilder now has a method (currently named setAuthTranslatorMap) which allows integrators to bring their own KubernetesAuthTranslators without forking this plugin.

Furthermore, can we maybe rename KubernetesAuthTranslatorGenerator? Since it's no longer a factory function, it's not really "generating" anything -- rather it's dispatching calls to its decorateClusterDetailsWithAuth method to particular translators based on their name. Maybe DispatchingKubernetesAuthTranslator, DelegatingKubernetesAuthTranslator, or maybe even just the plural KubernetesAuthTranslators in keeping with the plural KubernetesAuthProviders in the frontend?

@benjdlambert
Copy link
Member

@mclarke47 do you wanna take a look at this? 🙏

@github-actions
Copy link
Contributor

This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If the PR was closed and you want it re-opened, let us know and we'll re-open the PR so that you can continue the contribution!

@github-actions github-actions bot added the stale label Mar 14, 2023
@RubenV-dev
Copy link
Contributor Author

@benjdlambert @mclarke47 removing stale label?

@github-actions github-actions bot removed the stale label Mar 14, 2023
Copy link
Member

@benjdlambert benjdlambert left a comment

Choose a reason for hiding this comment

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

Looking pretty good to me, just one thing to fix.

I wonder if any of these docs need updating https://github.com/backstage/backstage/blob/36e81329174addc261646bae19eeead8d5a0fd93/docs/features/kubernetes/proxy.md also?

plugins/kubernetes-backend/package.json Outdated Show resolved Hide resolved
@jamieklassen
Copy link
Member

While we're here, it does seem like a good idea to remove this disclaimer in the docs:

Until some security and permission decisions are made (see [this
conversation](https://github.com/backstage/backstage/pull/13026/files#r1029376939)
for context), contributors consuming the proxy endpoint in their plugin code are
responsible for negotiating their own bearer token out-of-band. This requires
knowing some auth details about the cluster being contacted -- in practice, only
clusters with [client side auth
providers](https://backstage.io/docs/features/kubernetes/authentication#client-side-providers) can reasonably be reached.

And maybe add some discussion of KubernetesAuthTranslator in the 'How it works' section:

## How it works
The proxy will interpret the
[`X-Kubernetes-Cluster`
header](https://backstage.io/docs/reference/plugin-kubernetes-backend.header_kubernetes_cluster)
as the name of the cluster to target. This name will be compared to each cluster
returned by all the configured [cluster
locators](https://backstage.io/docs/features/kubernetes/configuration#clusterlocatormethods)
-- the first cluster whose [`name` field](https://backstage.io/docs/features/kubernetes/configuration#clustersname) matches
the value in the header will be targeted.
Then the request will be forwarded verbatim (but with the endpoint's base URL
prefix stripped) to the cluster.

@github-actions github-actions bot added the documentation Improvements or additions to documentation label Mar 20, 2023
@RubenV-dev
Copy link
Contributor Author

I added a small section under 'How it works' to explain that each request is now decorated with auth by default in this current state. Also removed disclaimer under the 'Authentication section'.

@RubenV-dev RubenV-dev force-pushed the server-side-auth-proxy branch 2 times, most recently from 7798c1c to 859d545 Compare March 21, 2023 17:18
…e a translator map as a parameter to use when decorating cluster details

Signed-off-by: Ruben Vallejo <rvallejo@vmware.com>
…r provided by the KubernetesFanOutHandler constructor

Signed-off-by: Ruben Vallejo <rvallejo@vmware.com>
Signed-off-by: Ruben Vallejo <rvallejo@vmware.com>
@RubenV-dev RubenV-dev requested a review from a team as a code owner March 29, 2023 21:21
@RubenV-dev
Copy link
Contributor Author

RubenV-dev commented Mar 29, 2023

@benjdlambert just wanted to check in to see if there were any other changes you wanted me to address?

@benjdlambert
Copy link
Member

Thanks! Seems like @backstage/kubernetes-maintainers are happy so gonna merge this and get it in the -next release today! 🙏

@benjdlambert benjdlambert merged commit b9327d6 into backstage:master Apr 4, 2023
18 checks passed
@github-actions
Copy link
Contributor

github-actions bot commented Apr 4, 2023

Thank you for contributing to Backstage! The changes in this pull request will be part of the 1.13.0 release, scheduled for Tue, 18 Apr 2023.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants