dokploy icon indicating copy to clipboard operation
dokploy copied to clipboard

API tokens in Dokploy are currently instance-wide

Open aboutrax opened this issue 6 months ago • 2 comments

What problem will this feature address?

Any external tool that integrates with Dokploy via API token must be granted more privilege than it actually needs. For example, a secret sync tool that only needs to update environment variables for a single application currently receives read/write access to every service, every project, and every admin operation on the instance.

This violates the principle of least privilege and makes it harder to safely hand out tokens to third-party tools, CI pipelines, or self-hosted integrations without accepting unnecessary risk.

Describe the solution you'd like

Allow API tokens to be scoped at creation time:

Scope Description
Instance (current) Full access — unchanged for admin use cases
Project Access limited to a specific project and its services
Service Access limited to a specific application or compose service

Optionally, scoped tokens could also be restricted by operation type (read-only vs read-write) for finer-grained control.

Describe alternatives you've considered

None

Additional context

Why this matters

Without scoped tokens, integrating Dokploy with external tooling always carries unnecessary blast radius. If a scoped token is leaked or misused, the damage is contained to the resource it was issued for rather than the entire instance.

This came up while building Infibridge, a self-hosted webhook bridge that syncs Infisical secrets to Dokploy. Users must currently provide an instance-wide API token, which is documented as a known limitation. Scoped tokens would eliminate that concern entirely.

Willingness to contribute

Happy to discuss the API design or contribute if the Dokploy team is open to it.

Will you send a PR to implement it?

Yes

aboutrax avatar May 28 '26 11:05 aboutrax

+1, and linking #3932, which asks for the read-only half of this.

Our use case is AI coding agents and CI jobs that call the Dokploy API. Most of them only need to read state and logs, and maybe redeploy one app. Today the key carries the full power of its user, so the only containment is a dedicated member user with narrow project/service access. That user can still edit env vars, change domains, and redeploy anything it can see, so there is no way to hand out a read-only key.

A possible shape that reuses what's already there:

  1. Scope is stored on the key. better-auth's apiKey plugin already supports permissions: Record<string, string[]> on create/update, and verifyApiKey can check them. Dokploy's user.createApiKey doesn't expose that field yet.
  2. Reuse the custom role statements in packages/server/src/lib/access-control.ts (service: ["create", "read", "delete"], deployment: ["read", "create", "cancel"], envVars: ["read", "write"], logs: ["read"], ...). They're built with better-auth's createAccessControl, which uses the same Record<string, string[]> shape as key permissions, so keys and roles would share one vocabulary.
  3. Effective access = user permissions intersected with key permissions. A key can only narrow its owner's access, never widen it. One catch: checks on enterprise-only resources are skipped for the static owner/admin/member roles today, so key scopes would need their own check instead of relying on that path.
  4. Optional resource scope per key: a list of project, environment, or service IDs, checked the same way as accessedProjects/accessedServices.
  5. Keys without a scope keep today's behavior, so existing integrations don't break.

The smallest useful step would be a single "read-only" flag on the key that rejects every mutation for that key. That alone covers log readers, dashboards, and monitoring agents.

Happy to help test this.

hamidzr avatar Nov 04 '26 17:11 hamidzr

My initial implementation is much simpler. It consist of selecting the services that the api can access like when assigning services to a member. What you propose is much complete and I like your suggestions. I'm a bit busy right now, but as soon as I have some free time, I’ll work on it.

aboutrax avatar Nov 15 '26 20:11 aboutrax