I am getting an error with the base64 secret I am ...
# general
n
I am getting an error with the base64 secret I am trying to apply. Can anyone advise?
Copy code
const longhornSecret = new k8s.core.v1.Secret("longhorn-secret", {
  metadata: {
    name: "longhorn-auth",
    namespace: "longhorn-system",
  },
  data: {
    users: `|
    ${secretPassword}
    `
  }
}, {
  dependsOn: [longhornIngress],
  provider: k8sProvider,
})
The error is
Copy code
error: Preview failed: resource longhorn-system/longhorn-auth was not successfully created by the Kubernetes API server : failed to convert new object (longhorn-system/longhorn-auth; /v1, Kind=Secret) to proper version: unable to convert unstructured object to /v1, Kind=Secret: error decoding from json: illegal base64 data at input byte 0
s
should just be
Copy code
data: {
    users: secretPassword
  }
n
How would I add more users?
The docs I have seen, show them as being one per line
s
|
is yaml syntax for a multiline string, so you'd never use it when creating a json object (and base64 strings are always single lines anyways) > How would I add more users? this requires knowing a bit more about what you're trying to do. how are you intending the program to consume this secrets info?
can you also give a concrete example of the value of
secretPassword
n
The secretPassword is generated from the command
htpasswd -nb <username> <password> | base64
Here is an example taken from the Trafik website. https://doc.traefik.io/traefik/middlewares/http/basicauth/
Copy code
apiVersion: v1
kind: Secret
metadata:
  name: authsecret
  namespace: default
data:
  users: |2
    dGVzdDokYXByMSRINnVza2trVyRJZ1hMUDZld1RyU3VCa1RycUU4d2ovCnRlc3QyOiRhcHIxJGQ5
    aHI5SEJCJDRIeHdnVWlyM0hQNEVzZ2dQL1FObzAK
s
i'm not sure what the
2
in
|2
means, but here are a couple options that you could do. keep in mind the
data
field must take a single base64 encoded string, but there's also the option of
stringData
which can take a regular string (the base64 encoding will. be done for you)
Copy code
const secretpasswords = [
  'user1:redactedpassword',
  'user2:redactedpassword',
   ...
]

  ...
  stringData: {
    users: secretpasswords.join("\n")
  }
or
Copy code
const encodedSecretpasswords = btoa([
  'user1:redactedpassword',
  'user2:redactedpassword',
   ...
].join("\n"))

  ...
  data: {
    users: encodedSecretpasswords
  }