logto-io / logto

🧑‍🚀 The better identity infrastructure for developers and the open-source alternative to Auth0.
https://logto.io
Mozilla Public License 2.0
8.66k stars 439 forks source link

Enable running as "rootless" on kubernetes (problem with alteration-scripts writability) #6327

Closed bpow closed 1 month ago

bpow commented 3 months ago

What problem did you meet?

I am working on an example helm chart to run logto on kubernetes (k8s). To reduce risks of privilege escalation many k8s clusters are configured to run in "rootless" containers, i.e., running as a non-zero uid (in some cases an arbitrarily-assigned uid-- for instance openshift clusters are set up this way).

I've already mapped /etc/logto/packages/core/connectors as a mounted directory so this running uid can make changes there.

I'm currently running into an issue with trying npm run cli -- db seed --swe because it copies alteration scripts into /etc/logto/packages/cli/alteration-scripts (so they have context of required dependencies). I can't even just mount that in k8s as a writable directory because the current code wants to remove that directory if it already exists (even if it is empty).

Describe what you'd like Logto to have

The ability to run from docker image in a "rootless" container as described above.

I may run into other issues as I work through this, but for the alteration-scripts, a few approaches that might address this:

I'll try a few of these to see which might actually work, but would welcome any ideas about which might be better.

This is related to #5961, of course.

xiaoyijun commented 3 months ago

Hi @bpow , I understand the issue you're facing with rootless containers. we'll find a better long-term solution, you could try modifying the Logto source code as a temporary fix.

The code that deletes the alteration-scripts folder is in packages/cli/src/commands/database/alteration/utils.ts

await fs.rm(localAlterationDirectory, { force: true, recursive: true });