Skip to content

Support Sprig htpasswd function #7533

Closed

Description

@alice-sawatzky

Sprig has an htpasswd template function that would be really useful for configuring basic auth.

Activity

  1. mattfarina commented on Feb 6, 2020

    @mattfarina
    Collaborator

    Can you share what version of Helm you are using? Helm v2 uses Sprig v2 which goes not have the htpasswd function. Helm v3 uses Sprig v3 which does include that function.

    Speaking as a Sprig maintainer, I would be willing to merge a backport of that function to Sprig v2 if someone wants to work on it.

  2. alice-sawatzky commented on Feb 7, 2020

    @alice-sawatzky
    Author

    So, I made a simple chart with a single template:

    {{ htpasswd "example" "password" }}
    
    % helm-2.16.1 template .
    Error: parse error in "test/templates/NOTES.txt": template: test/templates/NOTES.txt:1: function "htpasswd" not defined
    % helm-3.0.3 template . 
    Error: parse error at (test/templates/NOTES.txt:1): function "htpasswd" not defined
    

    I'd love to have htpasswd backported to v2, but it is probably worth pointing out that htpasswd doesn't appear to be available in helm v3 either

  3. bacongobbler commented on Feb 7, 2020

    @bacongobbler
    Member

    It looks like Masterminds/sprig#225 was merged only 2 weeks ago, so it's not yet in a sprig release.

    Helm 3.0.3 currently relies on Sprig 3.0.2.

    https://github.com/helm/helm/blob/v3.0.3/go.mod#L9

    Once a new release of sprig is available, we can bump Helm to the latest version aand htpasswd should become available.

  4. alice-sawatzky commented on Feb 11, 2020

    @alice-sawatzky
    Author

    i think this would be better labelled as a feature request, rather than question/support

  5. mattfarina commented on Feb 13, 2020

    @mattfarina
    Collaborator

    Oh, @technosophos merged that. Let's see about bringing this into Helm 3.2.0. I can make that happen.

  6. added this to the 3.2.0 milestone on Feb 13, 2020
  7. self-assigned this
    on Feb 13, 2020
  8. technosophos commented on Apr 14, 2020

    @technosophos
    Member

    Friendly reminder that 3.2 is right around the bend.

  9. added a commit that references this issue on Apr 16, 2020
    3b8521c
  10. nezed commented on Apr 23, 2020

    @nezed
    {{ htpasswd "user" "password" }}
    

    works since 3.2.0 🎉

  11. added a commit that references this issue on May 8, 2020
    f68c282
  12. added a commit that references this issue on Oct 2, 2020
    126d0f6
  13. bonpapajosie commented on Sep 28, 2021

    @bonpapajosie

    Hello everyone,

    Can someone help me, pls?

    i got a ingress with basic auth on my K8S:
    here is the yaml:
    apiVersion: v1
    kind: Secret
    type: Opaque
    metadata:
    name: basic-auth
    namespace: t
    data:
    auth: >-
    {{ .Values.basicAuth.authString | b64enc }}


    value.yaml

    basicAuth:
    authString: |
    htpwd1:b7NRGSot585DjHtXjlqusep
    htpwd2:fpzefczfzz585DjHtXjlquver

    But I want to do that with helm: like

    apiVersion: v1
    kind: Secret
    type: Opaque
    metadata:
    name: basic-auth
    namespace: t
    data:
    auth: >-
    {{ htpasswd .Values.basicAuth.auth1.username .Values.basicAuth.auth1.password | b64enc | quote }}
    {{ htpasswd .Values.basicAuth.auth2.username .Values.basicAuth.auth2.password | b64enc | quote }}


    value.yaml

    basicAuth:
    auth1:
    username
    password
    auth2:
    username
    password

    Can someone help, please?

  14. arthtux commented on Feb 14, 2022

    @arthtux

    Hello @bonpapajosie

    For use the multi user/password you can use this sample.

    On your ingress annotation:

        nginx.ingress.kubernetes.io/auth-type: "basic"
        nginx.ingress.kubernetes.io/auth-secret: "htpasswd-secret"
        nginx.ingress.kubernetes.io/auth-secret-type: "auth-map"
        nginx.ingress.kubernetes.io/auth-realm: "Authentication required!"

    For the secret:

    ---
    apiVersion: v1
    kind: Secret
    metadata:
      name: "htpasswd-secret"
    type: Opaque
    data:
      {{- range $user, $password := .Values.ingress.users }}
      {{ $user }}: {{ htpasswd $user $password | trimPrefix (print $user ":") | b64enc }}
      {{- end }}

    And for your values:

    ingress:
      users:
        user1: password1
        user2: password2
        ...: ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions