Hi friends, new to workers for platforms

Hi friends, new to workers for platforms! What is the story on letting users manage secrets for their workers they upload? Like if my user wants to access their own database from their worker what is best practice for managing that? Thank you for the help!
3 Replies
Schmime
Schmime•2mo ago
Right now Im thinking in the UI where a user can upload their code, you would also have a section where they can add secrets, and I would use the cloudflare API to attach those secrets to the script?
Beny
Beny•2mo ago
It all depends on your use case, but adding secrets through API is a good way to add database info into the worker for the script to use. You could also make use of the outbound worker and handle the db connection outside the user script for better security. For secrets you would add them via the API like this:
PUT https://api.cloudflare.com/client/v4/accounts/{account_id}/workers/dispatch/namespaces/{namespace}/scripts/{script_name}/secrets
Content-Type: application/json
X-Auth-Key: YOUR-API-KEY

{
"name": "DB_PASSWORD",
"text": "secretPassword123",
"type": "secret_text"
}
PUT https://api.cloudflare.com/client/v4/accounts/{account_id}/workers/dispatch/namespaces/{namespace}/scripts/{script_name}/secrets
Content-Type: application/json
X-Auth-Key: YOUR-API-KEY

{
"name": "DB_PASSWORD",
"text": "secretPassword123",
"type": "secret_text"
}
Schmime
Schmime•2mo ago
@Beny thank you for replying! Just to clarify I was thinking about how a user accesses their own database, not my database 🙂