How to handle secrets
Use the dedicatedsecrets field to manage security credentials, passwords, and certificates. The information in this field is encrypted and stored with per-function encryption, separately from the code for your function.
Best practices
1
Define secrets when you create the function
Use the dedicated
secrets dictionary argument during creation.2
Access secrets within your function code
The
secrets dictionary is passed as an argument to the handle() method, allowing you to access them securely at runtime.Don’t expose secrets in logs
Be cautious with the information you print or log from within your Cognite Function. Anyone withfunctions:read access in your CDF project can view the logs. Accidentally printing a secret can expose it to a wider audience than intended.
Never print or return sensitive data from your function’s handle() method. If you require output for debugging, use non-sensitive placeholder values. In general, make sure secrets and tokens can’t leak through logs or API requests other than what is intended.
Secure your dependencies
Your function is Python code built into a container. All standard software supply chain risks apply. Consider pinning packages to known-good versions. Some organizations may want to control updates to therequirements.txt files, or even use a private package repository. To use a private package repository with index_url, read about the intrinsic security implications.
Only run trusted functions
When you call a Cognite Function, it runs with the permissions of the session provided. This can be a service account, or it can be a user’s own permissions at the time they invoke a function through the CDF user interface. If the account has broad permissions, such as admin access, the function could perform any action these permissions allow. Following the principle of least privilege, invoke functions with the smallest set of permissions needed to perform the task of the function. Before invoking a function in the CDF user interface, consider:- Do I trust the author and source of this function?
- Do I have a clear understanding of the actions this function will perform?
- Am I comfortable with this function executing with my level of access?