Hi,
I have a Grafana setup using a PostgreSQL database (grafana-db) to store the Grafana configuration (dashboards etc.) and another PostgreSQL database (the to be data source) for storing data to be displayed (monitoring-db).
I would like to create a script to automatically provision the grafana-db with users, organizations, but also data sources. For this, I understand, that I need to encrypt the data source password and provide it the (correct) encrypted form. What I understand from Configure database encryption | Grafana documentation, there is the “main key” (secret_key setting in the configuration file), data keys, and the actual, encrypted, password (data source password, stored in data_source.secure_json_data?). I searched the Grafana source code, was able to find the information on how to extract the key_id from a base64 encoded “secret” - but what exactly is the secrets table now? How does it relate to secure_json_data, how does it relate to the other stuff?
And, decrypting the payload of both, secure_json_data and secrets entry using the decrypted data_key does not reveal anything readable.
In the source code, it looks like that secure_json_data is actually ignored for decrypting the values, it looks like it is taken from the secrets table, or am I wrong here?
It would be great if someone could describe the way how encryption/decryption is done in a more detailed way as it is currently in the documentation. Most important would be the clarification of the actual roles of the elements mentioned above. Why do we have two sources of secrets, data_source.secure_json_data and secrets.value? The values start identically, but have different length etc. Both seem to refer to the same key in data_keys, but what’s with the remaining stuff which I coulnd decrypt yet?
Thanks for you help!
Best regards
Matthias
- What Grafana version and what operating system are you using?
11.4.0 in Docker (on Ubuntu 24.10, but doesn’t matter I guess)
- What are you trying to achieve?
I want to provision a Grafana instances’ users, orgs and data sources purely using the database.
- How are you trying to achieve it?
I’m currently at the level of being confused about the different sources of encrypted data and their relation to each other.