langflow icon indicating copy to clipboard operation
langflow copied to clipboard

Can't store secret key global variables on Railway deployment (Fernet key must be 32 url-safe base64-encoded bytes)

Open brylie opened this issue 1 year ago • 5 comments

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:

  1. Deploy to RENDER
  2. Open the Langfoow UI
  3. Go to Settings -> Global Variables
  4. Try to add a credential variable, such as an API key
  5. See error

brylie avatar Jun 27 '24 05:06 brylie

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:

  1. Ensure your secret key is correctly padded using the add_padding function.
  2. 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.

dosubot[bot] avatar Jun 27 '24 05:06 dosubot[bot]

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.

image image

carlosrcoelho avatar Jul 18 '24 14:07 carlosrcoelho

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?

brylie avatar Jul 18 '24 16:07 brylie

@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 avatar Jul 20 '24 08:07 brylie

@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.

rodgermoore avatar Jul 22 '24 18:07 rodgermoore

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

nicoloboschi avatar Jul 30 '24 12:07 nicoloboschi