# Secret for basic auth could not be found

**URL:** <https://community.traefik.io/t/secret-for-basic-auth-could-not-be-found/10020>\
**Category:** Traefik v2\
**Tags:** kubernetes-crd\
**Created:** [March 11, 2021, 10:55pm UTC](https://community.traefik.io/t/secret-for-basic-auth-could-not-be-found/10020 "2021-03-11T22:55:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cbergmann](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/cbergmann/32/3529_2.png) [@cbergmann](https://community.traefik.io/u/cbergmann)\
**Post date:** [March 11, 2021, 10:55pm UTC](https://community.traefik.io/t/secret-for-basic-auth-could-not-be-found/10020/1 "2021-03-11T22:55:56Z")

</div>

Hi, I am trying to add basic auth to my ingress exposing my longhorn UI. All this runs on a k3s Cluster.

I Create the secret with the following yaml:

```auto
apiVersion: v1
kind: Secret
metadata:
  name: longhorn-auth
  namespace: longhorn-system
data:
  users: |2
    base64encodedsecrets

```

And these are my Middleware and ingress configuration:

```auto
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: ingressauth
  namespace: longhorn-system
spec:
  basicAuth:
    secret: loghorn-auth
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt-prod
    kubernetes.io/ingress.class: traefik
    traefik.ingress.kubernetes.io/router.middlewares: longhorn-system-ingressauth@kubernetescrd
  name: longhorn-ingress
  namespace: longhorn-system
spec:
  rules:
  - host: longhorn.example.com
    http:
      paths:
      - backend:
          service:
            name: longhorn-frontend
            port:
              number: 80
        path: /
        pathType: Prefix
  tls:
  - hosts:
    - longhorn.example.com
    secretName: longhorn-cert

```

Without the last annotation I can access the longhorn UI but it is unprotected. With this configuration I get an 404 Error with my browser and the log states the following:

```auto
time="2021-03-11T22:54:38Z" level=error msg="Error while reading basic auth middleware: failed to load auth credentials: secret 'longhorn-system/loghorn-auth' not found" middlewareName=longhorn-system-ingressauth providerName=kubernetescrd

```

Moving the secret to the same namespace as traefik also does not work. Can you guess why it can not find the secret.

Thanks  
Clemens

---

<div class="post-metadata">

**Author:** ![jakubhajek](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/jakubhajek/32/3389_2.png) [@jakubhajek](https://community.traefik.io/u/jakubhajek)\
**Post date:** [March 12, 2021, 10:18am UTC](https://community.traefik.io/t/secret-for-basic-auth-could-not-be-found/10020/2 "2021-03-12T10:18:28Z")

</div>

hi @cbergmann

> [@cbergmann](#):
>
> ```auto
> spec:
> basicAuth:
> secret: loghorn-auth
> 
> ```

I think, here is a typo.

You defined the secret `longhorn-auth` and in the middleware, you refer to the not existing K8S secret, that's why Traefik throws the error message.

The annotations should look according to the following template:  
`<namespace>-<object>@<provider>`

> **[Traefik Configuration Discovery Overview - Traefik](https://doc.traefik.io/traefik/providers/overview/#provider-namespace)**
>
> Configuration discovery in Traefik is achieved through Providers. The providers are infrastructure components. Read the documentation to learn more.

Can you please confirm the solution? Thanks!

---

<div class="post-metadata">

**Author:** ![cbergmann](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/cbergmann/32/3529_2.png) [@cbergmann](https://community.traefik.io/u/cbergmann)\
**Post date:** [March 12, 2021, 11:54am UTC](https://community.traefik.io/t/secret-for-basic-auth-could-not-be-found/10020/3 "2021-03-12T11:54:31Z")

</div>

Hi @jakubhajek,

sorry. you are right. There was a missing 'n'. sorry for the noise.
