prisma cli's endpoint parser is wrongly parsing the URLs other than localhost
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:
- 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
- Run `prisma deploy
- 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
prismaCLI: 1.28.5- OS: MacOS 10.14.3
@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.
@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
Thanks @pantharshit00, I was losing my mind trying to debug this one. Great time to start dabbling in setting up a prisma server!
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!
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:
-
localhostservers not deployed usinglocalhosti.e. either usinghttp://prisma:466or a proxy usingnginxor something and the workaround is to uselocalhostfor now while we fix it. -
CI setups where login is not possible, there is no workaround except downgrading to a stable version.
-
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.
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",
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
This is fixed in 1.29.1, please install it using npm install -g prisma
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 Can you please share your prisma.yml file?
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 : 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 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.
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.
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.
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.
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 Can you please try version 1.29.1? We have fixed the bug in that version
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
Yep, same error 1.29.1 here. Sorry I didn't specify that earlier.