pipecd icon indicating copy to clipboard operation
pipecd copied to clipboard

Support per-method or per-resource scoping for API keys (beyond READ_ONLY/READ_WRITE)

Open Goyamjain06 opened this issue 3 months ago • 2 comments

This came up while discussing the Headlamp plugin proposal in #6706.

Right now model.APIKey.Role is a two-tier enum — READ_ONLY / READ_WRITE — set once per key at the project level. Enforcement happens per-RPC through requireAPIKey() in pkg/app/server/grpcapi/api.go, where each handler declares its own required role (e.g. ListApplications requires READ_ONLY, SyncApplication requires READ_WRITE). But there's no scoping within a role — a READ_WRITE key satisfies every READ_WRITE check unconditionally, across every RPC.

This becomes a real limitation for external integrations that only need one specific action. For example, if a Headlamp plugin (or any similar tool) just wants to call SyncApplication, the only option today is handing it a full READ_WRITE key — which also unlocks AddApplication, DeleteApplication, and everything else in that tier. There's no way to issue a key that can do less than "all of READ_WRITE."

Filing this mainly to track the idea rather than propose a full design. A couple of directions that seem reasonable on the surface:

  • An allowlist of specific RPCs/methods attached to a key, checked alongside the existing role.
  • Narrower sub-roles for common cases (e.g. a "sync-only" role) instead of a single blanket READ_WRITE.

Happy to help implement this if there's interest — just wanted to get the problem written down first in case others have opinions on the right shape for it.

Goyamjain06 avatar Aug 23 '26 06:08 Goyamjain06

webservice already does this. Each RPC carries option (model.rbac).resource and .action in the proto, protoc-gen-auth generates the authorizer from those, and JWTUnaryServerInterceptor calls it with the method name. apiservice is the one service that skips it and takes the two-value requireAPIKey check instead.

So this might be less about designing a scoping model and more about giving API keys a role the existing authorizer already understands. @khanhtc1202 is that the direction you'd want, or is apiservice deliberately kept simpler?

Ahmad-Faraj avatar Aug 26 '26 20:08 Ahmad-Faraj

I checked this on master and the direction holds, with two gaps. The generator only targets webservice (tool/codegen/protoc-gen-auth/main.go hardcodes the webservice path and the template only emits WebService method names), and Authorize takes RBAC role names while model.APIKey only stores the READ_ONLY/READ_WRITE enum, so both would need changes. Also, ProjectRBACPolicy.HasPermission in pkg/model/project.go only matches resource type and action and does not check labels, so this would give per-method scoping but not per-resource scoping.

Goyamjain06 avatar Oct 08 '26 04:10 Goyamjain06