1

I'm currently facing a weird issue with K8S. Indeed I'm creating a container with an envFrom statement and the env variable is pulled from a secret:

envFrom:
  - secretRef:
    name: my-super-secret

I have created the secret with the base64 encoded value, and when I echo the variable in the container it has added a space at the end, which is quite an issue since it's a password ;-)

Here's my secret:

apiVersion: v1
kind: Secret
metadata:
  name: my-super-secret
data:
  DB_PASSWORD: base64encodedvalue

Does anyone could provide me with some guidance here ? I absolutely can't figure out what's happening here ...

moulip
  • 111
  • 1
  • 13

1 Answers1

4

How did you encode the value?

Using this (on Mac)

echo -n "base64encodedvalue" | base64
YmFzZTY0ZW5jb2RlZHZhbHVl

I can access my values just fine in my Containers, without a trailing space.

echo YmFzZTY0ZW5jb2RlZHZhbHVl | base64 -d
base64encodedvalue

Source: https://kubernetes.io/docs/tasks/configmap-secret/managing-secret-using-kubectl/

bymo
  • 344
  • 1
  • 10
  • Hi, first thank you for tour answer. I do the same but without the -n. But when I decode the secret there is no trailing space. It seems that it comes when the env variable is injected. However, I will give a try to your fix. – moulip Jun 18 '21 at 10:15
  • 1
    The -n should fix your issue. As from the echo man page: "-n Do not print the trailing newline character. This may also be achieved by appending `\c' to the end of the string." – bymo Jun 18 '21 at 10:27