R
Railwayβ€’13mo ago
poolnoodle93

SSL Issue: PowerSync + Postgres on Railway

Project ID: 0696700c-6952-4780-8a3d-01600989ab48 I'm trying to enable Powersync (https://www.powersync.com/), and use it to connect to my postgres DB on railway. However, when trying to connect using the TCP credentials, I get the following error: server certificate not trusted: SELF_SIGNED_CERT_IN_CHAIN. When connecting to Postgres, Powersync only has two possible modes, verify-full and verify-ca. I'm using verify-full, is there any way to get around this? I don't think verify-ca and uploading certificates is the right way to go here.
57 Replies
Percy
Percyβ€’13mo ago
Project ID: 0696700c-6952-4780-8a3d-01600989ab48
poolnoodle93
poolnoodle93OPβ€’13mo ago
I asked the Powersync team, and they told me that my only option is likely to download a CA cert, like you can do on superbase. is there any way to do this on Railway?
Brody
Brodyβ€’13mo ago
there isnt you would have to roll your own database with your own certs https://docs.railway.app/databases/bring-your-own-database
k0b13
k0b13β€’12mo ago
Hey I'm from the PowerSync team and just got everything working using the stock Railway services, didn't have to roll own database Busy bundling it all up as a template (also converted myself into a Railway fan in the process... Railway is really nice)
Brody
Brodyβ€’12mo ago
ah yes the postgres databases railway provides do come with their own self signed certs, but there isn't a way to download them like pool noodle wanted to, glad it works without having to do that!
k0b13
k0b13β€’12mo ago
If there is uptake from users we'll make the process of downloading the cert simpler in our dashboard, but for now users have two workarounds available to them which I'll document in the integration guide Here's one of them: echo | openssl s_client -showcerts -starttls postgres -connect monorail.proxy.rlwy.net:37067 -servername monorail.proxy.rlwy.net 2>/dev/null | sed -n '/BEGIN CERTIFICATE/,/END CERTIFICATE/p' | awk '/BEGIN/{i++}i==2' > railway.pem not the prettiest nor the most robust, but works for now until we streamline it on our end
Brody
Brodyβ€’12mo ago
would be even nicer if railway had some kind of file browser for the volumes so users could just go there and click download on the certs
k0b13
k0b13β€’12mo ago
I get roasted when I use "just" like that 🀣 but yes that would also work nicely πŸ™‚
Brody
Brodyβ€’12mo ago
yeah it's a bad habit 🀣 but what route are you planning on taking with your template? will the template come with a postgres database, or just (I think I'm using it correctly?) the powersync service that will be setup to automatically reference an existing postgres database that would exist in a users project
k0b13
k0b13β€’12mo ago
PowerSync integrates with existing backends and we have demo Django and NodeJS backends showing the extensions required to wire PowerSync up to your backend, so for the template it will be Postgres + NodeJS HTTP We're still working on making the PowerSync service itself self-hostable (ETA early next year) and then we could update or re-publish so that the entire stack runs on Railway
Brody
Brodyβ€’12mo ago
very cool, a full starter project
k0b13
k0b13β€’12mo ago
yeah pretty much - it will be end-to-end Flutter app that works offline syncing to Railway Postgres
Brody
Brodyβ€’12mo ago
awesome! if you need any help making the template feel free to ask, I'd also be happy to give you any feedback on the template itself once done
k0b13
k0b13β€’12mo ago
I think I'd like some feedback yes, thank you.
Brody
Brodyβ€’12mo ago
of course, just open a #βœ‹ο½œhelp thread for that and I'll be around
k0b13
k0b13β€’12mo ago
Is it OK if I send questions about the template itself here for now and then open the help thread for the final review? Question: is this valid syntax for template env vars?
k0b13
k0b13β€’12mo ago
No description
k0b13
k0b13β€’12mo ago
for the nodejs app in the template to reference the postgres database in the template
Brody
Brodyβ€’12mo ago
yep that's valid
k0b13
k0b13β€’12mo ago
Is there a way to set a Template Environment Variable to a system function that has the value of an HTTP NodeJS "Public Networking" hostname? To paraphrase - is there a way to get the public networking hostname from an environment variable?
No description
k0b13
k0b13β€’12mo ago
Thx!
k0b13
k0b13β€’12mo ago
If I want to run some once-off "post up" commands against Postgres, is the recommended way to do that still with a "temp" NodeJS service called "run once then delete me" ? example
GitHub
pulse-railway-pg-config/config-db.ts at 69d12d4b42d715edab7c1f0fdfd...
A railway.app project template. Contains a Pulse ready postgres database and set up service. Read more about pulse - prisma/pulse-railway-pg-config
Brody
Brodyβ€’12mo ago
it depends, that specific service you are talking about was just changing the wal_level, but now since databases are just services with a volume, you can provide a database with a modified start command that sets the wal_level through a command flag, so for that specific use case an init service is not needed. but what did you need to run once on the database?
k0b13
k0b13β€’12mo ago
1) set wal_level to logical 2) create a DB role "with replication" (recommended to use a separate SQL user for production, so could possibly skip this step for demo purposes) 3) GRANT SELECT to all tables for the user created in step 2 (could consider skipping as above) 4) Run DDL script to create 2x demo tables 5) CREATE PUBLICATION powersync FOR ALL TABLES; Interesting @ command flag - that will eliminate 1) at minimum. If we skip 2 and 3 and just re-use default username/password, that just leaves 4) and 5) I also need to decide whether I want the template to be a starter from which to build from, or more of a demo that is a full, working project to serve as a reference
Brody
Brodyβ€’12mo ago
could you do something like this but put it in the start command? https://github.com/railwayapp-templates/postgres-ssl/blob/main/Dockerfile.latest#L7 there's also the option of maintaining your own postgres image that sets everything up perfectly to work with powersync, but thats probably not worth it
k0b13
k0b13β€’12mo ago
Thanks - I'm going to go with "a starter project from which you can build on" rather than end-to-end demo project, so that completely removes steps 2 through 5, so I'm good no more questions πŸ™‚
Brody
Brodyβ€’12mo ago
awesome !
k0b13
k0b13β€’12mo ago
struggling a bit with the start command syntax, if I wanted to override the start command for the default postgres service from postgres --port=5432 to postgres --port=5433 (hypothetical example) what would I put into the "Custom Start Command" field under the Service Settings in the Dashboard?
GitHub
postgres-ssl/Dockerfile.latest at 0187d4fba19a15ed8062499dc2a9fdde0...
Contribute to railwayapp-templates/postgres-ssl development by creating an account on GitHub.
Brody
Brodyβ€’12mo ago
wrapper.sh postgres --port=5433
k0b13
k0b13β€’12mo ago
What's wrong with this Postgres service in my template?
No description
k0b13
k0b13β€’12mo ago
When I try to use it, the Postgres fails to launch with this error:
k0b13
k0b13β€’12mo ago
No description
Brody
Brodyβ€’12mo ago
youre trying to deploy from a repo instead of the docker image
k0b13
k0b13β€’12mo ago
is there a docker image for postgres-ssl?
Brody
Brodyβ€’12mo ago
k0b13
k0b13β€’12mo ago
Ah I see now, missed that. Thanks!
Brody
Brodyβ€’12mo ago
wrong start command too, you want wrapper.sh postgres --port=5433 -c wal_level=logical missing a volume mount on /var/lib/postgresql/data probably should have shown you this sooner, but you can fork the postgres template, modify the start command and then add your example app https://railway.app/button?code=postgres
k0b13
k0b13β€’12mo ago
nope... will kick more tires tomorrow. Forking the template works, but adding that start command I'm unable to connect to Postgres externally.
Brody
Brodyβ€’12mo ago
any logs?
k0b13
k0b13β€’12mo ago
nothing particularly exciting
k0b13
k0b13β€’12mo ago
No description
Brody
Brodyβ€’12mo ago
you changed the port postgres starts on, you need to also change the tcp port i should have caught that earlier, my bad
k0b13
k0b13β€’12mo ago
didn't change anything other than the start command, wonder if it's a bug with the form
Brody
Brodyβ€’12mo ago
im saying you need to change the tcp port too
k0b13
k0b13β€’12mo ago
grrr yeh thx thought I was still on 5432, that 5433 was just an example to figure out the start command syntax
Brody
Brodyβ€’12mo ago
oh, i thought you had some reason for running it on 5433 so i didnt question you
k0b13
k0b13β€’12mo ago
Heh serves me right. Anyway everything's working now, thanks for your help. We shipped a small update on our end too today to support the certs nicely πŸ™‚
Brody
Brodyβ€’12mo ago
awesome, let me know when you've published that template and I'll take a look!
k0b13
k0b13β€’12mo ago
When publishing what are good dimensions for the Image URL ?
No description
Brody
Brodyβ€’12mo ago
good question, I don't know lol. stick your logo in and see how it looks on the preview
k0b13
k0b13β€’12mo ago
haha ok cool
k0b13
k0b13β€’12mo ago
also (and getting into nice to haves here) is it possible to configure the template so that when someone uses it, the Private repository checkbox is checked by default?
No description
Brody
Brodyβ€’12mo ago
there isn't, that would be up to the user
k0b13
k0b13β€’12mo ago
Any recommendations for Avatar dimensions? Shows up in Template page
No description
Brody
Brodyβ€’12mo ago
I think mine is 1000x1000 and looks fine to me
k0b13
k0b13β€’12mo ago
nice
Want results from more Discord servers?
Add your server