Skip to content

Unable to debug "lookup" function, as its disabled with helm template #8137

Closed

Description

@etsauer

Output of helm version:

version.BuildInfo{Version:"v3.2.1", GitCommit:"fe51cd1e31e6a202cba7dead9552a6d418ded79a", GitTreeState:"clean", GoVersion:"go1.13.10"}

Output of kubectl version:

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"13+", GitVersion:"v1.13.4+7bd2e5b", GitCommit:"7bd2e5b", GitTreeState:"clean", BuildDate:"2019-05-19T23:52:43Z", GoVersion:"go1.11.5", Compiler:"gc", Platform:"linux/amd64"}

Cloud Provider/Platform (AKS, GKE, Minikube etc.):
all

I am trying to use the "lookup" function, which is resulting in problems with my yaml formatting:

$ helm install --namespace myapp api ./charts/deploy/
Error: unable to build kubernetes objects from release manifest: error validating "": error validating data: ValidationError(Secret.metadata): unknown field "type" in io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta

The template file from which I believe the error is coming from looks like this:

---
apiVersion: v1
data:
  auth: {{ (lookup "v1" "Secret" "app2" "api-k8s-htpasswd").data.auth }}
kind: Secret
metadata:
  labels:
    k8s-app: myap-api
  name: htpasswd-secret
type: Opaque

From what I understand, the lookup function was disabled when you run helm template, as trying to process this chart results in a nil pointer error:

Error: template: deploy/templates/htpasswd-secret.yaml:4:56: executing "deploy/templates/htpasswd-secret.yaml" at <"api-k8s-htpasswd">: nil pointer evaluating interface {}.auth

I would like to have a discussion as to why I can't use helm template to debug my chart, as that, in my opinion, should be the primary purpose of having a template command.

Activity

  1. bacongobbler commented on May 15, 2020

    @bacongobbler
    Member

    Have you tried helm template --validate?

    It is intentional behaviour for lookup to return with an empty dictionary during a helm template, as it is expected that the chart renders without any cluster connection. See #7955 and #7969 for more details.

    If you want to test your chart using a live connection with the cluster, either add the --validate flag or use helm install --dry-run.

    Hope this helps.

  2. etsauer commented on May 15, 2020

    @etsauer
    Author

    Neither help template --validate nor helm install --dry-run help in debugging a function that essentially is skipped.

    The problem is that the lookup function should not simply be "skipped" if using helm template. Instead, it should handle the case where there is no active connection, and return a nil value so that those who wish to use the function still can. I shouldn't have to make changes to my chart based on whether I'm going to use helm template or helm install to process it.

    Please re-open this issue.

  3. bacongobbler commented on May 15, 2020

    @bacongobbler
    Member

    Instead, it should handle the case where there is no active connection, and return a nil value

    As shown in your error message, it is clearly returning a nil value. Your template isn’t handling that nil and assumed it was a populated object.

    nil pointer evaluating interface {}.auth

    Wrap your lookup in an if or with clause to handle the nil case.

  4. etsauer commented on May 15, 2020

    @etsauer
    Author

    @bacongobbler I get what I have to do to handle the lookup in my template. What I'm saying is that when I run helm install with my template and lookup actually returns something, I have no way of seeing the content that is generated and therefore can't troubleshoot the formatting issues, and helm install --dry-run gives me no extra information.

    Normally, I would run helm template to see what's generated, but in this case, I can't.

  5. bacongobbler commented on May 15, 2020

    @bacongobbler
    Member

    Tested and confirmed with the following:

    $ helm version
    version.BuildInfo{Version:"v3.2.1", GitCommit:"fe51cd1e31e6a202cba7dead9552a6d418ded79a", GitTreeState:"clean", GoVersion:"go1.13.10"}
    $ kubectl run nginx --image nginx
    $ helm create test-lookup
    $ cd test-lookup
    $ cat templates/deployment.yaml | head -n 6
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: {{ include "test-lookup.fullname" . }}
      labels:
        {{ with lookup "v1" "Pod" "default" "nginx" }}testing: {{ quote .metadata.name }}{{ end }}
    

    helm template --validate and helm install --dry-run both show empty output. helm install shows the correct output, of course. Perhaps #7969 unintentionally disabled the lookup function for cases where we do have cluster access.

    What's your thoughts on this, @technosophos?

  6. etsauer commented on May 15, 2020

    @etsauer
    Author
  7. etsauer commented on May 19, 2020

    @etsauer
    Author
  8. technosophos commented on May 20, 2020

    @technosophos
    Member

    Lookup is intentionally disabled for security reasons. There is no plan to change this behavior.

  9. etsauer commented on May 21, 2020

    @etsauer
    Author

    @technosophos what exactly is the security concern with the lookup plugin? I could see there being a concern if we were talking about helm v2, where tiller was still involved, but with helm 3 being all in the client side, running a lookup through helm template doesn't expose anything that the user couldn't already see with kubectl get.

  10. technosophos commented on May 21, 2020

    @technosophos
    Member

    The security disclosure: GHSA-q8q8-93cv-v6h8

  11. gmoshiko commented on May 24, 2020

    @gmoshiko

    I agree this is a vulnerability when using helm template as helm template command should not interact with the cluster at all(which make me a lot of problem as I am using systems like ArgoCD which use helm template command before deploying to the cluster), but the lookup function is not working also with install --dry-run which makes it impossible to debug and not making sense as --dry-run is expected to interact with the cluster.

    it cant be expected to debug a feature only when installing or upgrading. I'm literally using an old helm3 binary with the vulnerability so I can debug this before installing it with the latest helm3 binary.

    is there any security reason why it shouldn't work with --dry-run or helm template with --validate?

  12. technosophos commented on May 26, 2020

    @technosophos
    Member

    Dry-run is NOT expected to interact with the cluster, and this is documented. All other similar functions and capabilities are also disabled for --dry-run.

  13. 99 remaining items

  14. added a commit that references this issue on May 4, 2023
    cf327fd
  15. curlup commented on Sep 11, 2023

    @curlup

    How about using helm install --dry-run=server-lookup-only for current behavior
    and reserve helm install --dry-run=server for future "all server-side validations and majic" ?

  16. rickardp commented on Sep 16, 2023

    @rickardp

    How about using helm install --dry-run=server-lookup-only for current behavior
    and reserve helm install --dry-run=server for future "all server-side validations and majic" ?

    This was discussed for two years before being merged. Let's just celebrate that something was agreed upon 😀

  17. added 9 commits that reference this issue on Nov 6, 2023
    90ef8a5
    fde1304
    2cbf493
    204835d
    6a34dbb
    3d92dbf
    2a7c65f
    df5e473
    d6035f3
  18. added a commit that references this issue on Dec 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions