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

[kubernetes-backend] support caFile on clusters defined in app-config #15005

Merged
merged 2 commits into from Dec 12, 2022

Conversation

jamieklassen
Copy link
Member

@jamieklassen jamieklassen commented Dec 2, 2022

Hey, I just made a Pull Request!

Resolves #13768

I tested this out locally using the following steps:

  1. I created a kind cluster with kind create cluster
  2. I wrote out the CA for that cluster to a local file with
    kubectl config view --raw -o jsonpath='{.clusters[?(@.name == "kind-kind")].cluster.certificate-authority-data}' | base64 -d > kind.pem
  3. I ran kubectl apply -f backstage.yml where backstage.yml is:
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: backstage
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: backstage
      template:
        metadata:
          labels:
            app: backstage
        spec:
          containers:
          - image: nginx
            imagePullPolicy: Always
            name: nginx
  4. I created kubernetes.yaml in the root of this repo:
    apiVersion: backstage.io/v1alpha1
    kind: Component
    metadata:
      name: demo-backstage
      annotations:
        'backstage.io/kubernetes-label-selector': 'app=backstage'
    spec:
      type: service
      lifecycle: stable
      owner: user:guest
  5. I have app-config.local.yaml:
    kubernetes:
      clusterLocatorMethods:
        - type: config
          clusters:
            - url: https://127.0.0.1:<port of kind apiserver>
              name: kind
              authProvider: serviceAccount
              serviceAccountToken: <token for SA with the role at https://backstage.io/docs/features/kubernetes/configuration#role-based-access-control>
              caFile: ../../kind.pem
    catalog:
      locations:
        - type: file
          target: ../../kubernetes.yaml
  6. I run yarn start-backend
  7. In another terminal, I run
    curl localhost:7007/api/kubernetes/services/demo-backstage \
      -H 'content-type: application/json' \
      -d '{"entity":{"metadata":{"annotations":{"backstage.io/kubernetes-label-selector":"app=backstage"}}}}'
    And objects are successfully returned!

Before this change, the same sequence of steps would result in

{
  "error": "unable to verify the first certificate"
}

✔️ 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) backend only
  • All your commits have a Signed-off-by line in the message. (more info)

Jamie Klassen added 2 commits December 2, 2022 16:05
Signed-off-by: Jamie Klassen <jklassen@vmware.com>
Signed-off-by: Jamie Klassen <jklassen@vmware.com>
@github-actions github-actions bot added the documentation Improvements or additions to documentation label Dec 2, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Dec 2, 2022

Changed Packages

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

@jamieklassen jamieklassen changed the title K8s cluster cafile [kubernetes-backend] support caFile on clusters defined in app-config Dec 2, 2022
@jamieklassen
Copy link
Member Author

@jpeach interested to know if this satisfies your intended use case -- if so, is it clear enough how to do so (e.g. mounting k8s secrets into the pod where Backstage is running, pointing to those mount points in the app-config appropriately)? Do you think there should be any further docs or contrib/ examples?

@mclarke47 I only have the config clusterLocator reading this property -- somehow this feels like more of a "static config"-type feature and it seemed weird for entities in the catalog to contain references to filesystem paths on the Backstage host. It wouldn't be hard to add this to the catalog clusterLocator too though.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2022

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 stale and removed stale labels Dec 9, 2022
Copy link
Member

@freben freben left a comment

Choose a reason for hiding this comment

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

Thanks!

@@ -54,6 +54,10 @@ export interface Config {
skipTLSVerify?: boolean;
/** @visibility frontend */
skipMetricsLookup?: boolean;
/** @visibility secret */
caData?: string;
/** @visibility secret */
Copy link
Member

Choose a reason for hiding this comment

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

Maybe didn't have to make the path as such be a secret? 🤔 But I'm fine either way, not sure that it's anybody's business to see this outside of the backend code that actually needs it

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 actually don't really understand how these comments work and was following my nose LOL. Is there a value for "only the backend needs it but it's not necessarily secret"?

@freben freben merged commit 903d29a into backstage:master Dec 12, 2022
@github-actions
Copy link
Contributor

Thank you for contributing to Backstage! The changes in this pull request will be part of the 1.9.0 release, scheduled for Tue, 20 Dec 2022.

@jhested
Copy link

jhested commented Feb 16, 2024

I will just allow myself to make a little comment here, as I was struggling for days to get the plugin to use the correct certificate.

It turned out that the environment variable 'GLOBAL_AGENT_FORCE_GLOBAL_AGENT' defaults to true which resulted in the certificate never being used, because the global-agent was used instead.

Everything worked after setting GLOBAL_AGENT_FORCE_GLOBAL_AGENT to false

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.

Support the caFile file in the Kubernetes plugin configuration
4 participants