I am looking to deploy my Streamlit app to Digital Ocean but there’s a problem.
My app uses st.login() which gets my login credentials from secrets I stored in the secrets.toml file. However, there’s no place for me to upload my secrets file securely within Digital Ocean.
I can’t assign the credentials to environmental variables because Streamlit’s st.login() looks specifically for a secrets.toml file.
I don’t want to hard code my secrets in a secrets.toml file when I deploy my app, so what should I do?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hi Draco,
One simple workaround on DigitalOcean (especially if you’re using a Droplet) is to upload your
secrets.toml
file after deployment via SSH. You can place it in~/.streamlit/secrets.toml
on the server and make sure that file is not tracked in your Git repo.Basically:
SSH into your Droplet.
Create the folder:
mkdir -p ~/.streamlit
Upload your
secrets.toml
securely, eg:scp secrets.toml root@your_droplet_ip:~/.streamlit/secrets.toml
This keeps your secrets file out of your repo and allows Streamlit to find it where it expects it.
Alternatively, if you’re using App Platform, you might want to refactor your code to pull secrets from environment variables instead, since App Platform lets you manage those securely.
Hope that this helps!
- Bobby
Heya,
Since
st.secrets
(notst.login()
— I assume you meantst.secrets["key"]
) specifically loads from asecrets.toml
file and not environment variables, here’s how you can securely manage this for deployment:Solution: Use a secure
secrets.toml
during deployment via environment-aware scriptingHere’s a practical and secure approach:
secrets.toml
out of version control.gitignore
:secrets.toml
during deployment from environment variablesInstead of uploading the file, create it during the deployment process using a script (e.g., in your
Dockerfile
,cloud-init
, or startup script). Here’s how:Example deployment shell script:
Set the
STREAMLIT_USERNAME
andSTREAMLIT_PASSWORD
as environment variables in DigitalOcean (via the App Platform UI if using that, or in your shell if you’re using a droplet).