Where are environment variables stored?

Hello,

I have a python snippet which uses credentials to access a DB. After searching Knime forums, I seem to understand that there is no integration on Python to access and read credentials stored as such in a Knime WF (either from a “Credentials Input” node or from setting “Workflow Credentials”). So I am basically trying to store the credentials as environment variables. I tried (a) to store them on my local machine, but the python snippet cannot access them, (b) to store them on the Conda environment used by Knime, but they still can’t be accessed.

I don’t know where the environment variables which are accessed by a WF are stored: are they specific to each Knime WF? Is there a way to access (and modify) them through the configuration menu, or using another way?

I am also not hell-bent on using environment variables to store these credentials that the python snippet needs to access. If there is a better way to achieve what I’m trying to do using another method, please feel free to let me know.

Thank you! :slight_smile:

Hello @Berti1989,

While we plan to add support for passing encrypted credentials from KNIME to Python in the future this is not possible yet.

If you are up for storing credentials in plain text, you could feed flow variables with plain text credentials to Python or access system environment variables from Python. This would be the possible workarounds until the mentioned feature is available in KNIME.

Best,
Michael

1 Like

Thank you for your answer @MichaelRespondek :slight_smile:
Storing them in the access environment variables would be good enough for my purpose. I’m just a bit confused what environment variables the python script node can access from a Knime WF. If I use the os.getenv() method in the python script node, I access variables which seem to have more to do with the specific Knime WF I have opened, not my local machine environment variables. So I was wondering how to get past that?

As I mentioned, I tried to store them on the Conda environment used by Knime, but they still can’t be accessed by the python node, or they simply don’t appear to be more specific.

Thanks again!
Cheers

@Berti1989

Have you considered using the Python keyring library. This will allow you to put your credentials in your machines credential store (e.g. Windows Credential Manager) and then access them using the library.

You can install keyring into the KNIME conda environment using:

conda activate your_knime_conda_environment
conda install -c conda-forge keyring

Create a credential. For example, in Windows Credential Manager you can create a Windows Generic Credential with Internet or network address knimeUser; username user and password secureMe.

The within the KNIME labs node:

import keyring

password = keyring.get_password("knimeTest","user")
print(password)     # Prints secureMe in the console.

This will retrieve the password from the credential store and make it available for use within the Python labs node.

DiaAzul

1 Like