3

I am trying out GitLab AutoDevOps, and trying to understand how CI/CD variables work.

In the Settings UI I can set create file and environment variables.

enter image description here

According to the documentation, if an variable is prefixed with K8S_SECRET_ then it appears magically in the deployment. I can get this to work for env variables, but not for file variables. In this context I have two questions:

  • If this is supported, how do I do it?
  • If this not supported, what would you recommend as a work around? Specifically, I need to be able to mount ssh keys in my pod.

Thanks!

Nick
  • 1,882
  • 11
  • 16
mikelong
  • 3,694
  • 2
  • 35
  • 40

1 Answers1

0

No, it is not supported. You can't use File type variables with K8S_SECRET_ . These is a workaround.

  1. remove first (-----BEGIN RSA PRIVATE KEY-----) and last line (-----END RSA PRIVATE KEY-----)

  2. Add the rest key as K8S_SECRET_ Variable Type. For an example K8S_SECRET_SECRET_KEY

  3. This will make your key available in your application as an environment variable. Important thing to notice the new line(\n) will be converted to space.

  4. Use a script similar to following in the deployment file.

    command: ["/bin/bash", "-c"] args: - | mkdir -p /home/certs cd /home/certs echo $SECRET_KEY > secret.key sed -i 's/ /\n/g' secret.key sed -i '1s/^/-----BEGIN RSA PRIVATE KEY-----\n/' secret.key sed -i -e '$a-----END RSA PRIVATE KEY-----' secret.key
Rohit Bohara
  • 323
  • 4
  • 14