Skip to content

Access control via sub claim #86

@uniqueg

Description

@uniqueg

Currently, anyone with a valid access token can access all the resources in the service. While this may sometimes be desirable, there are many situations where only specific people should be able to a given resource.

For now, the easiest way of granting access control to specific endpoints is by recording a user's identity when registering a resource and then, when access to that resource is requested, check that the person requesting the resource is the same person that registered it. This can be done via the JWT's sub claim. If a user then supplies a valid token and the correct sub claim, they will get access. If the sub claim does not match, a 403 response should be returned.

The solution to be implemented should allow some level of controlling this behavior to cover as many use cases as possible. For example, a user might want to register a tool and then only that user should be able to modify or delete that resource. However, the user may want everyone to be able to access the tool, perhaps even without providing an access token at all.

The solution should also consider later extension by checking for other specific claims in a token, e.g., those that confer some form of group membership.

Code repetition should be avoided, and usage as simple as possible. The information on who registered which resources should always be recorded in the database. The logic to check if the sub claim matches the one recorded could, for example, be implemented as a decorator that wraps the endpoints that should be protected against access by unauthorized users. If implemented in a sufficiently abstract manner, the code could also be put into FOCA (preferable) and corresponding config options could be implemented (e.g., a dictionary of controller functions/classes and access control configurations) there.

Before starting to implement this, please draw up a detailed plan on how you plan to implement the feature so that we can discuss if/how to improve the design with respect to usability, general applicability, extensibility and the possibility to migrate the solution to FOCA so that other services can make use of it, too.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions