Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow datasource credentials to be passed by client #446

Closed
Sytten opened this issue Apr 5, 2020 · 2 comments · Fixed by #480
Closed

Allow datasource credentials to be passed by client #446

Sytten opened this issue Apr 5, 2020 · 2 comments · Fixed by #480
Assignees
Labels
docs Documentation creation, updates or corrections

Comments

@Sytten
Copy link

Sytten commented Apr 5, 2020

Problem

In production, we store secrets in a vault for secrets and we do not expose them as environment variables. The service requests a secret from the vault (database credentials) and receives them if authorized, those secrets are stored in memory only and could be unique for this service (the hashicorp Vault can generate database credentials on the fly). We thus need to tell the connection string at runtime when creating the client, which happens just after retrieving the secrets.

Solution

It seems like there is an undocumented way to pass a datasource to the client. It might be a way to override the datasource specified in the schema?

Additional context

Eventually we will also need the same way of securely passing the secret to the migration, most likely by having a programmatic access to the migrate up (if we don't already).

@Sytten
Copy link
Author

Sytten commented Apr 5, 2020

I believe this could also be useful to @Errorname with the prisma multi-tenant extension.

@Errorname
Copy link

I used the undocumented way to pass a datasource to the client in a previous version of prisma-multi-tenant. But now, I find it simplier to add an env in the schema:

  url = env("DATABASE_URL")

And then dynamically change the ENV before instantiating:

process.env.DATABASE_URL = 'whatever_url'
const prisma = new Prisma()

@janpio janpio assigned janpio and nikolasburk and unassigned janpio Apr 14, 2020
@janpio janpio transferred this issue from prisma/prisma Jun 12, 2020
@mhwelander mhwelander added the docs Documentation creation, updates or corrections label Jun 16, 2020
@mhwelander mhwelander linked a pull request Jun 17, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation creation, updates or corrections
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants