How to securely pass secrets into Dockerfile at build time
devlarabar
PROOP

a year ago

Hello all, I'm wondering how it might be possible to securely pass secrets from the Railway environment variables at build time.

Specifically, in my Dockerfile, I would like to configure a private Python package index as a package source, and configure its credentials. The idea is that these will come from the Railway environment variables. But if I pass them in as ARGs, like it says to do in these Railway docs, they will be visible in the build logs, which isn't very secure.

Is there a way to accomplish this so that:

  • I can configure my private package index during build time to install dependencies

  • The credentials will not be output anywhere

I appreciate any input. Thank you!

15 Replies

devlarabar
PROOP

a year ago

N/A


a year ago

I'm 99% sure ARG lines aren't just blindly printed to stdout


Anonymous
FREE

a year ago

They are, I tested with some dummy secrets


a year ago

let's see please?


Anonymous
FREE

a year ago

1349749677112692700


Anonymous
FREE

a year ago

those came from the build args


a year ago

that's because you are passing them in as flags to a command, the ARG lines themselves aren't printed


Anonymous
FREE

a year ago

My question is then, how can I pass secrets into commands here without them being printed?


a year ago

does poetry not support reading from environment variables?


Anonymous
FREE

a year ago

It does - this is the relevant section of the Dockerfile:

ARG POETRY_HTTP_BASIC_DUMMY_USERNAME
ARG POETRY_HTTP_BASIC_DUMMY_PASSWORD
RUN poetry config http-basic.dummypypi $POETRY_HTTP_BASIC_DUMMY_USERNAME $POETRY_HTTP_BASIC_DUMMY_PASSWORD

a year ago

thats passing them in as flags, that isn't uv reading them from the env directly


Anonymous
FREE

a year ago

I'll look into this; I haven't seen a way to read directly from env variables but I may have missed it in the docs. I'll post with an update when I'm able to find more information


a year ago

sounds good!


Anonymous
FREE

a year ago

@Brody I've tested this and it doesn't seem that the Railway environment variables are available to Poetry during build. I tried accessing a real private pypi, without including the config/credentials run command, and it failed to access the pypi with an authentication error.


echohack
EMPLOYEE

a year ago

I know Brody's already helping you out here Lara but I thought I'd add my 2c.

Personally when it comes to provisioning / bootstrapping services with Secrets I use 1Password. If you're in a big environment you might want to setup their connect server, otherwise you can set up a service account. This also avoids any secret sprawl you might have, and also lets you audit usage, or roll secrets should you need to. https://developer.1password.com/docs/service-accounts/

They have integrations for the major CI providers, but you can also stand up your own connect server (I did this tonight in my railway environment) to proxy out via the sync service should you want to do it that way instead of having every request go over the wire. I bootstrapped the connect service by encoding my json payload as a base64 string and setting it to the OP_SESSION environment variable and then immediately sealing it before deploying it.

Doing this during Railway's build-time is an interesting idea, I've yet to play around with that but I don't see why it couldn't be done.

1350763329831833600
1350763330079428600


Loading...