Can't store secret key global variables on Railway deployment (Fernet key must be 32 url-safe base64-encoded bytes)
I've deployed Langflow to Railway using the button from the README. I'm not sure what version deploys, as there doesn't seem to be any version number displayed in the Langflow UI and I can't find the Railway deployment script.
When I try to set a credential as a global variable, I get the following error:
Error creating variable Fernet key must be 32 url-safe base64-encoded bytes.
To Reproduce Steps to reproduce the behavior:
- Deploy to RENDER
- Open the Langfoow UI
- Go to Settings -> Global Variables
- Try to add a credential variable, such as an API key
- See error
To resolve the "Fernet key must be 32 url-safe base64-encoded bytes" error and successfully store secret key global variables on Railway deployment, you need to ensure that your secret key is properly padded to be 32 url-safe base64-encoded bytes. Here is how you can do it:
- Ensure your secret key is correctly padded using the
add_paddingfunction. - Use the padded secret key to create a Fernet instance.
Here is the relevant code snippet:
def add_padding(s):
# Calculate the number of padding characters needed
padding_needed = 4 - len(s) % 4
return s + "=" * padding_needed
def get_fernet(settings_service=Depends(get_settings_service)):
SECRET_KEY = settings_service.auth_settings.SECRET_KEY.get_secret_value()
# It's important that your secret key is 32 url-safe base64-encoded bytes
padded_secret_key = add_padding(SECRET_KEY)
fernet = Fernet(padded_secret_key)
return fernet
Make sure that your SECRET_KEY is set correctly in your settings and that it is being padded before being used to create the Fernet instance. This should resolve the error and allow you to store secret key global variables on Railway deployment [1][2][3].
To verify the version of Langflow that is currently deployed on Railway, you can use the get_version_info function from the src/backend/base/langflow/utils/version.py file. This function retrieves the version information of the Langflow package:
def get_version_info():
try:
from langflow.version import __version__ # type: ignore
version = __version__
package = "Langflow"
except ImportError:
from importlib import metadata
version = metadata.version("langflow")
package = "Langflow"
return {"version": version, "package": package}
You can call this function to get the version and package information of the deployed Langflow instance [4][5].
To continue talking to Dosu, mention @dosu.
Hi @brylie
You can set the variable as shown in the screenshot on Railway. You can refer to the documentation for the process on how to set them.
Link to set global variables: https://docs.langflow.org/settings-global-variables
If you need any support, let me know. If the issue is resolved, please let us know if this ticket can be closed.
Thanks. Per the documentation you linked, I am getting the error in the original post when setting variables in the Langflow UI. Is it not possible to set variables in the Langflow UI on Railway?
@carlosrcoelho, I've updated the steps to reproduce this issue to more clearly indicate the problem is with the Langflow global variables page. E.g. Langflow variables can be auto-inserted into component properties, so I use them frequently. Being unable to set Langflow variables is a bit confusing and problematic.
@brylie @carlosrcoelho Running into exact the same issue, not on Railway deployment but on Azure Container Instances. Would very much like this feature to work. Would like to assist to get this fixed, feel free to let me know how I could be of any assistance.
We updated the template on Railway (thanks @ogabrielluiz ) This should now work correctly. You need to start over.
@rodgermoore please open another ticket for the Azure Container issue since it's probably a different problem