prisma1 icon indicating copy to clipboard operation
prisma1 copied to clipboard

prisma cli's endpoint parser is wrongly parsing the URLs other than localhost

Open pantharshit00 opened this issue 7 years ago • 49 comments

Describe the bug Prisma CLI is parsing regular local private URLs as cloud workspace URLs and deploy to any server other than localhost is broken right now with the following error if you are logged in. When you are logged out it is just asking you to login:

ERROR: No cluster could be found for workspace '*' and cluster 'default'
  1 # Specifies the HTTP endpoint of your Prisma API.

{
  "data": {
    "generateClusterToken": null
  },
  "errors": [
    {
      "message": "No cluster could be found for workspace '*' and cluster 'default'",
      "locations": [
        {
          "line": 3,
          "column": 9
        }
      ],
      "path": [
        "generateClusterToken"
      ],
      "code": 222
    }
  ],
  "status": 200
}

This is regression is introduced by the following commit: https://github.com/prisma/prisma/commit/67bb5094010e76e23849458fc211a474e1a40479#diff-6fed8e800217d7823362a8550f1047a2R50

To Reproduce Steps to reproduce the behavior:

  1. Make the following prisma.yml file
# Specifies the HTTP endpoint of your Prisma API.
endpoint: http://prisma:4466

# Defines your models, each model is mapped to the database as a collection.
datamodel: datamodel.prisma
  1. Run `prisma deploy
  2. See error

Expected behavior CLI should parse the URLs correctly for non localhost urls as well

Versions (please complete the following information):

  • Prisma Server: 1.28.5
  • prisma CLI: 1.28.5
  • OS: MacOS 10.14.3

pantharshit00 avatar Mar 19 '19 12:03 pantharshit00

@pantharshit00 Checking your PRISMA_MANAGEMENT_API_SECRET and endpoint path. If you use DigitalOcean, Please check your endpoint have a PORT.

I try to add env PRISMA_MANAGEMENT_API_SECRET and edit port on endpoint prisma.yml.

colevels avatar Mar 19 '19 12:03 colevels

@vistriter I am not sure what you are referring from that comment. This is a confirmed bug regarding the parser. If you have version lower than 1.28.4 it will work fine

pantharshit00 avatar Mar 19 '19 13:03 pantharshit00

Thanks @pantharshit00, I was losing my mind trying to debug this one. Great time to start dabbling in setting up a prisma server!

ardeaf avatar Mar 19 '19 17:03 ardeaf

With Prisma Server and Prisma CLI 1.29.0, when prisma deploy:

Authenticating...
Opening https://app.prisma.io/cli-auth?secret=[SECRET] in the browser

Could not open the authentication link, maybe this is an environment without a browser. Please open this url in your browser to authenticate: https://app.prisma.io/cli-auth?secret=[SECRET]

Is this related?

With Prisma CLI 1.28.5, the deploy worked!

nunovieira avatar Mar 20 '19 12:03 nunovieira

Assuming that server is always protected by a secret, this is the current behavior:

Logged in without management secret

Local server + localhost - Invalid token - which is correct behavior Local server + proxy or prisma:4466 - ERROR: Workspace * does not exist ❌ correct: Invalid token Demo server - deploy works Private server hosted by Prisma - deploy works Self hosted server - deploy works Self hosted server (not connected to Prisma cloud) - ERROR: No cluster could be found for workspace '*' and cluster 'default' ❌correct: Invalid token

Logged in with management secret

Local server + localhost - deploy works Local server + proxy or prisma:4466 - ERROR: Workspace * does not exist ❌ correct: deploy should work Demo server - deploy works Private server hosted by Prisma - ERROR: Token is issued in the future (iat) ❌ correct: deploy should work 🤔 but this is a separate issue from the one we are facing here Self hosted server - deploy works Self hosted server (not connected to Prisma cloud) - ERROR: Workspace * does not exist ❌correct: deploy should work

Logged out with management secret

Local server + localhost - deploy works Local server + proxy or prisma:4466 - Asks to login ❌ correct: deploy should work Private server hosted by Prisma - Asks to login ❌ correct: deploy should work Self hosted server - Asks to login ❌ correct: deploy should work


This breaks three things:

  1. localhost servers not deployed using localhost i.e. either using http://prisma:466 or a proxy using nginx or something and the workaround is to use localhost for now while we fix it.

  2. CI setups where login is not possible, there is no workaround except downgrading to a stable version.

  3. Self hosted servers but not connected to Prisma cloud when you are logged in. I don't think that an advisable workaround is available except to downgrade to a stable version.


We would fix these issues shortly.

divyenduz avatar Mar 20 '19 13:03 divyenduz

For anyone looking at the same issue looking for a workaround, restoring "prisma" package version alone might not work. These versions in my package.json worked for me:

    "prisma": "1.26.6",
    "prisma-cli-engine": "1.26.6",

ronalddddd avatar Mar 21 '19 08:03 ronalddddd

For anyone looking at the same issue looking for a workaround, restoring "prisma" package version alone might not work. These versions in my package.json worked for me:

    "prisma": "1.26.6",
    "prisma-cli-engine": "1.26.6",

1.28.3 works fine too

uxname avatar Mar 21 '19 09:03 uxname

This is fixed in 1.29.1, please install it using npm install -g prisma

divyenduz avatar Mar 21 '19 09:03 divyenduz

Unfortunately, I am still getting an error with 1.29.1. A few days ago, after updating prisma and then running prisma deploy, it opened up my web browser to get me to log into prisma.io. I created an account, though I am currently not using any prisma.io cloud services. prisma deploy then would error. I reverted my version, and waited for this fix to go through. I updated to 1.29.1 today and I am still getting the following error. Is there something trying to connect me to prisma.io, even though I am not using it? Is there a way to delete the credentials that are being stored if so? Thanks!

$ prisma deploy
ERROR: No cluster could be found for workspace '*' and cluster 'default'
{
  "data": {
    "generateClusterToken": null
  },
  "errors": [
    {
      "message": "No cluster could be found for workspace '*' and cluster 'default'",
      "locations": [
        {
          "line": 3,
          "column": 9
        }
      ],
      "path": [
        "generateClusterToken"
      ],
      "code": 222
    }
  ],
  "status": 200
}

I am using a plain docker-compose.yml for local development:

version: '3'
services:
  prisma:
    image: prismagraphql/prisma:1.29.1
    restart: always
    ports:
    - "4466:4466"
    environment:
      PRISMA_CONFIG: |
        port: 4466
        # uncomment the next line and provide the env var PRISMA_MANAGEMENT_API_SECRET=my-secret to activate cluster security
        # managementApiSecret: my-secret
        databases:
          default:
            connector: postgres
            host: postgres
            user: prisma
            password: prisma
            # rawAccess: true
            port: 5432
            migrations: true
  postgres:
    image: postgres:10.5
    restart: always
    environment:
      POSTGRES_USER: prisma
      POSTGRES_PASSWORD: prisma
    volumes:
      - postgres:/var/lib/postgresql/data
    ports:
      - "42333:5432"
volumes:
  postgres:

Environment:

Linux
Node: 10.15.3

ZenSoftware avatar Mar 21 '19 16:03 ZenSoftware

@ZenSoftware Can you please share your prisma.yml file?

pantharshit00 avatar Mar 21 '19 16:03 pantharshit00

Oh yes of course. Here is my prisma.yml file:

endpoint: http://0.0.0.0:4466 # Docker
datamodel: database/model.graphql

# seed:
#   import: database/seed.graphql

generate:
  - generator: typescript-client
    output: apps/api/src/app/prisma/client
  - generator: graphql-schema
    output: database/generated/

ZenSoftware avatar Mar 21 '19 16:03 ZenSoftware

@ZenSoftware : Is there a specific reason that you are referring to localhost as 0.0.0.0? That looks incorrect to me. Changing the endpoint to endpoint: http://localhost:4466 or endpoint: http://127.0.0.1:4466 should fix it.

divyenduz avatar Mar 21 '19 16:03 divyenduz

@divyenduz Ah yes, you are correct. Changing it to localhost or 127.0.0.1 resolved the issue for me. My apologies. I only started using docker over the last 2 weeks. I actually had suspicions that using 0.0.0.0 was incorrect. Strange that it worked for me using prisma < 1.28.3. But everything is working smoothly now.

ZenSoftware avatar Mar 21 '19 20:03 ZenSoftware

Yes, < 1.28.3 had a code path that would make this work incorrectly till the token resolution at least, I am not sure how it resolved to localhost correctly though, if it did.

divyenduz avatar Mar 21 '19 23:03 divyenduz

i encounter this with a specific reason: deploy prisma on one machine, but development with another pc in a local network. set the endpoint with ip address, so the playground works fine without manual adjust.

openefit avatar Mar 23 '19 11:03 openefit

I have the issue that if I set anything other than endpoint: http://0.0.0.0:4466 I get the error:

Could not connect to server at http://127.0.0.1:4466. Please check if your server is running.

The fact that 0.0.0.0 works indicates that the container is at least running correctly (as docker ps would confirm).

This is why I had hoped that keeping 0.0.0.0 would be supported for local installations / installations to one's own server.

NOTE: I'm using Windows + WSL. That might make some things more complicated. :)

[EDIT] After digging a little bit deeper into Docker and its networking, as well as thinking logically about the problem, I was able to configure everything correctly. So this problem no longer applies to me here. Just FYI.

SvenSchoene avatar Mar 25 '19 22:03 SvenSchoene

Why did this ticket close? My ci/cd broken since (and including) 1.28.4

My .gitlab-ci.yml:

server test:
  stage: test
  image: docker
  services:
  - docker:dind
  before_script:
    - apk add --no-cache py-pip nodejs nodejs-npm
    - pip install docker-compose
    - "echo \"DOCKER_HOST: $DOCKER_HOST\""
    - cd server && docker-compose up -d
    - echo "Hacky waity for 33 s" && sleep 33
  script:
    - NODE_ENV='test' npm run test
  after_script:
    - ls && cd server && docker-compose down -v

$DOCKER_HOST shows as tcp://docker:2375

my package.json > scripts:-

"test": "cross-env-shell PRISMA_ENDPOINT=http://docker:4466/test/default \"prisma deploy -f && jest\"",

Outputs

Authenticating...
Opening https://app.prisma.io/cli-auth?secret=$2a$08$RLMtZlfgFhCWChiDPBXXX. in the browser

Could not open the authentication link, maybe this is an environment without a browser. Please open this url in your browser to authenticate: https://app.prisma.io/cli-auth?secret=$2a$08$RLMtZlfgFhCWChiDPBXXX.

but works in 1.28.3 and below.

ViableClanMember avatar Mar 26 '19 07:03 ViableClanMember

@ViableClanMember Can you please try version 1.29.1? We have fixed the bug in that version

pantharshit00 avatar Mar 26 '19 12:03 pantharshit00

What about deployment to a server that is not localhost? My ci is deploying to my servers which are of course not in localhost and i get the same error with 1.29.1

brafdlog avatar Mar 26 '19 16:03 brafdlog

Yep, same error 1.29.1 here. Sorry I didn't specify that earlier.

ViableClanMember avatar Mar 26 '19 17:03 ViableClanMember