Skip to content

prisma2 needs a more security conscious installation method for binaries #938

Closed as not planned

Description

@LongLiveCHIEF

related #931 #834

There are several concerns with the way binaries are being installed for the Query Engine, Migration Engine, and prisma-fmt utility.

First, they require use of --unsafe-perm when running npm install. In today's IT platforms, apps are explicitly disallowed the ability to switch users, or run as root.

Secondly, these are being distributed as tar.gz files from an amazon s3 bucket, instead of a legitimate package repository, which includes gpg key checking.

GPG key checking is a must. . I need to have some way to verify the binary I'm downloading is compiled from the source code I expect it to be compiled from.

Third, there needs to be a way to configure a proxy/mirror in front of these binaries, since many environment this technology will be used in is also disallowed from connecting directly to the internet, and tends to only have connections to package repositories that are lazy proxy-mirrors that can scan software as it comes in. A good open source example of such technology, making it easy to use in testing scenarios for this feature requirement, is Sonatypes Nexus Repository Manager.

At the moment, users have no control over what prisma binaries are being added to their system, and that's a huge security risk, and in many cases makes this tool impossible to use due to platform or machine actively managed policy tools.

Activity

  1. changed the title [-]prisma2 needs a more security minded installation method for binaries[/-] [+]prisma2 needs a more security conscious installation method for binaries[/+] on Nov 14, 2019
  2. LongLiveCHIEF commented on Nov 14, 2019

    @LongLiveCHIEF
    Author

    Also, I'd be happy to contribute a PR for this, just want to have an agreement from prisma team on what acceptance criteria for this are.

    I'm super excited about trying out prisma2, but right now this issue is keeping me from even running hello-world type of exercises.

  3. LongLiveCHIEF commented on Nov 15, 2019

    @LongLiveCHIEF
    Author

    The postinstall script for prisma2 could first check for a PRISMA_QUERY_ENGINE_PATH, (same for migration and fmt), and that environment var could either be a system path or a URI. If that exists it would either skip download (if it's a system path), or use the given URL to download.

    Secondly, if the above variable isn't found, it could check for a PRISMA_BINARY_MIRROR_URL, and if that is found, then it would inject that into the host of the download binary, and the real host would be the first fragment in the uri path after the string passed by the PRISMA_BINARY_MIRROR_URL.

    Finally, regardless of whether any of those variables are set (either explicitly, or as NPM_CONFIG_PRISMA_...), the postinstall script should check connection for the resolved url host, before attempting to download the binary, and should throw a hard failure causing npm install to fail and exit if the endpoint can't be reached.

    An potentiakl alternative solution would be to package these binaries and host them in a package repository so the native OS package managers for linux can download them, which would provide built-in gpg key checking. Obviously that doesn't work with Windows and Mac, but for that we could likely use github releases api, which would also allow for verifying gpg signatures (See: Creating Signed GitHub Releases

    I'm also working as we speak on a Pull Request that will take each tag of node and compile the binaries from scratch and then skip the post-install step of npm install prisma2. This will provide a dockerized prisma2 cli that is compiled directly from source code.

    This image could easily be injected with the above described env variables as build args, and easily consume NPM_CONFIG_REGISTRY, making it compatible with VPN's that don't allow open-ended internet connections and use repository managers to manager external dependencies.

  4. LongLiveCHIEF commented on Nov 15, 2019

    @LongLiveCHIEF
    Author

    @pantharshit00 @dpetrick The current docs in docs/core/generators/photon.md tell us that in order to compile our own binaries we should check out the prisma/prisma project and checkout the alpha branch and run cargo on it.

    However, the most recent commit on that branch 1d95a48 removed all the rust code, and all it said was that it was moved to another repository. the commit message didn't link an issue with more information, so I don't know where this code was moved to.

    Was this code redone in go-lang and needs to be compiled with go now, or did it move to another repository? I have had any luck in finding it, so I'm stuck on the plans mentioned above until I can answer this question.

    Can either you answer this one for me?

  5. LongLiveCHIEF commented on Nov 15, 2019

    @LongLiveCHIEF
    Author
  6. LongLiveCHIEF commented on Nov 15, 2019

    @LongLiveCHIEF
    Author

    another thought: I recently learned that visual studio code extensions are built with a globally installed npm package called vsce. That cli tool looks at the package.json engines field of an extension for a version dependency of the vscode platform that the extension is built for.

    I wonder if we can do something similar with the prisma2 cli, specifying either individual binaries, or the engine as a whole.

    example...

    //photon's package.json
    
    {
      "private": true,
      "engines": {
        "prisma" : "< 1.0.0",
        "prisma-fmt": "< 1.0.0",
        "migration-engine": "< 1.0.0",
        "introspection-engine": "< 1.0.0"
      }
    }

    ...and I just realized i learned how vsce uses the engine field because I needed to compile the vscode-prisma extension from source 🤦‍♂️

  7. timsuchanek commented on Nov 16, 2019

    @timsuchanek
    Contributor

    Thanks for all the research and posting your thoughts on this @LongLiveCHIEF!

    I'll answer in reverse chronological order :)

    1. Regarding pinning the version in the package.json, we're doing that here already:

      https://github.com/prisma/prisma2/blob/master/cli/prisma2/package.json#L21

      As of now we want all engine versions to be the same. The hash you see there will soon be replaced with a version hash instead.

    2. Yes, prisma/prisma-engine is the correct repo for the Rust code. We should update our docs.

    3. Moving to Github signed releases is an interesting idea. We just recently revamped our build setup using S3, so this won't happen in the coming weeks, we first need to consider all advantages/disadvantages and possible solutions using S3.

    4. The PRISMA_QUERY_ENGINE_PATH should for sure be taken into account when downloading the binary. If it's provided, there is indeed no need to download it. No matter when we will download the binary, this is a nice optimization we can perform.

    5. What exactly are you working on in the Pull Request? Be aware, that this involves multiple different parts of the system and first needs to be approved by at least 3 Prisma engineers involved with this part of the system. Before you implement something that we won't merge, let's first get in sync, what solution we want.
      We don't want you to waste your time.
      As this is very involved logic that has many angles to it (not an isolated standalone PR), we, in general, are careful with this, even if we achieved consensus, I hope you understand that.

    But I'm sure we will find a great way how you can contribute to this topic and it's very exciting to see your engagement around this! 🚀

  8. LongLiveCHIEF commented on Nov 16, 2019

    @LongLiveCHIEF
    Author

    We don't want you to waste your time.

    Totally understand, that's why I've been chatty with my posts.

    All I've done at the moment is work on a Dockerfile that compiles the binaries from the docker-engine project in a way that accepts build args for common firewall/VPN scenarios, so I can get back to learning prisma2.

    I wasn't planning on doing anything more than that until I got responses from your team on the various issues I've commented on (which you've done!) I was just digging around in the issues and repos to compare what I'm seeing in builds in different distros.

    Here's a link to my branch: https://github.com/LongLiveCHIEF/prisma2/tree/add-docker-prisma2-cli-images

  9. LongLiveCHIEF commented on Nov 17, 2019

    @LongLiveCHIEF
    Author

    So I've got my dockerfile "finished", and the end result is dissapointing.

    This whole thing is extremely overcomplicated. I've defined binary path via env variables, and using lift and generate commands completely ignores those paths.

    At this point, I can't tell if that's a bug, or if I'm just doing something wrong, because the advanced docs for the binaries say the env vars don't change the download behaviors... just the path.

    What exactly is that supposed to mean? The docs say the env vars for that can be relative paths, but if download behavior isn't changed, then that means its going to try to fetch over https binaries that are already local?

    I'm also confused about the combination of providing a path to the binaries and the name of the binary to be provided.

    CLI binaries can only be overridden by a path to a custom binary. It does not alter download behavior, it just overrides the binary path provided for respective commands. This means that using known binaries is not possible.

    So here again I compiled my own binaries, and overrode the path, but it is still looking for the native binary for my platform instead of the one specified by the override. (to see what I mean, clone my branch and then run make buster)

    It kinda feels like my problem is I'm just naming the query engine binary incorrectly.

    Am I right that I need to name it something very specific, based on the glibc-ssl installed on my platform? I can sorta glean that from the available binaries table

    Part of the "overcomplication" feeling might just be because you guys are making really quick progress, and docs might lag from changes by a week or two, and they sometimes have information that should all be in one place distributed across 3 different repos.

    My end goal is to build a binary from self-defined mirrors of the upstream sources, and prevent the need to use npm i --unsafe-perms and prevent the cli from attempting to download new binaries.

    I think I'm basically there, with the dockerfile i've built, aliasing the run of that image to prisma2 in my dev environment. I think I'm just missing something simple (like needing a specific binary name) and it will work and solve the challenge of using behind a VPN (as described in #834)

  10. 2 remaining items

  11. janpio commented on May 29, 2021

    @janpio
    Contributor

    Internal note: The individual concerns in this issue should be split into separate issues.

  12. LongLiveCHIEF commented on May 29, 2021

    @LongLiveCHIEF
    Author

    I believe the 3rd issue has been resolved with supported env vars to specify a prisma download host mirror.

  13. janpio commented on May 12, 2023

    @janpio
    Contributor

    Uh pretty old issue that is still hanging around - let's fix that by one by one responding to the concerns raised and how we actually have the tools in place to make them not a problem:

    First, they require use of --unsafe-perm when running npm install. In today's IT platforms, apps are explicitly disallowed the ability to switch users, or run as root.

    Fortunately npm did away with that, and it is not required any more for Prisma in any way that I am aware of.

    Secondly, these are being distributed as tar.gz files from an amazon s3 bucket, instead of a legitimate package repository, which includes gpg key checking.

    GPG key checking is a must. . I need to have some way to verify the binary I'm downloading is compiled from the source code I expect it to be compiled from.

    Prisma downloads its own checksum files with the engines, and then checks the archive and unzipped file against these.
    Currently there is no way to provide ones own checksums, but that is just because no one has ever asked for that.

    If there is some need to add more capabilities to this functionality, please create an issue.

    Third, there needs to be a way to configure a proxy/mirror in front of these binaries, since many environment this technology will be used in is also disallowed from connecting directly to the internet, and tends to only have connections to package repositories that are lazy proxy-mirrors that can scan software as it comes in. A good open source example of such technology, making it easy to use in testing scenarios for this feature requirement, is Sonatypes Nexus Repository Manager.

    PRISMA_ENGINES_MIRROR can set the domain at which Prisma CLI send the requests to download: https://www.prisma.io/docs/reference/api-reference/environment-variables-reference#prisma_engines_mirror This can be used with a custom repository, or something that caches what we provide under binaries.prisma.sh.

    The postinstall script for prisma2 could first check for a PRISMA_QUERY_ENGINE_PATH, (same for migration and fmt), and that environment var could either be a system path or a URI. If that exists it would either skip download (if it's a system path), or use the given URL to download.

    All the different engine file paths can be overridden with local environment variables, which leads to us also skip the downloads: https://www.prisma.io/docs/reference/api-reference/environment-variables-reference#custom-engine-file-locations (PRISMA_QUERY_ENGINE_LIBRARY and similar).

    Secondly, if the above variable isn't found, it could check for a PRISMA_BINARY_MIRROR_URL, and if that is found, then it would inject that into the host of the download binary, and the real host would be the first fragment in the uri path after the string passed by the PRISMA_BINARY_MIRROR_URL.

    Don't think our solution works exactly like that as we just replace the host with the provided mirror URL, but usually that should be fine. If not, please open a new issue.

    Finally, regardless of whether any of those variables are set (either explicitly, or as NPM_CONFIG_PRISMA_...), the postinstall script should check connection for the resolved url host, before attempting to download the binary, and should throw a hard failure causing npm install to fail and exit if the endpoint can't be reached.

    If the download fails, the postinstall script should fail. We don't need a separate check for that, as downloading the file and then failing has the same result as doing an additional check that fails - just without the overhead of doing an additonal check for all users (which 99.999% will not have any connection problems).

    An potentiakl alternative solution would be to package these binaries and host them in a package repository so the native OS package managers for linux can download them, which would provide built-in gpg key checking. Obviously that doesn't work with Windows and Mac, but for that we could likely use github releases api, which would also allow for verifying gpg signatures (See: Creating Signed GitHub Releases

    We did not get further feedback from anyone that this owuld be useful or needed. If that is indeed the case, please open a new issue and we are happy to take a look.

    another thought: I recently learned that visual studio code extensions are built with a globally installed npm package called vsce. That cli tool looks at the package.json engines field of an extension for a version dependency of the vscode platform that the extension is built for.

    I wonder if we can do something similar with the prisma2 cli, specifying either individual binaries, or the engine as a whole.

    Each Prisma CLI version expects exactly one version of the engine files. The files themselves differ depending on the platform, OpenSSL and so on - but generally we pin the engines that are used now. There is no dynamic component in Prisma CLI that chooses between different versions. We can only pin the CLI to a new version of the engines by releasing a new version of the CLI.

    This whole thing is extremely overcomplicated. I've defined binary path via env variables, and using lift and generate commands completely ignores those paths.
    At this point, I can't tell if that's a bug, or if I'm just doing something wrong, because the advanced docs for the binaries say the env vars don't change the download behaviors... just the path.

    That should not be the case, and if that was a bug some time ago I am pretty sure it has been fixed. If not, please open a new issue.

    My end goal is to build a binary from self-defined mirrors of the upstream sources, and prevent the need to use npm i --unsafe-perms and prevent the cli from attempting to download new binaries.

    I think with the information provided above this should today fully be possible.

  14. added a commit that references this issue on Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions