Skip to main content

Authorizing Keycloak clients for consuming application resources

In the system context, the permissions of a consumer are defined in Keycloak. This is roughly illustrated below.

  • The provider (business application Bar) creates a realm for the business application Bar in Keycloak.
  • The provider creates clients (C1 .. C4) in its realm.
  • The provider authorizes the clients according to the role concept by adding Service Account Roles to the Keycloak client.
  • The consumers obtain an access token from Keycloak that contains the roles defined in the Keycloak client.

Shared Keycloak clients: business applications Foo (x-, y- and z-service) and Pip (v-service) access the resource res of provider Bar's a-service with read or create and read permissions; Bar's realm in Keycloak holds the clients Foo-readonly (C1), Foo-readwrite (C2), Pip (C3) and Bar (C4) with their bar_@res_#read and bar_@res_#create roles

  • x-service and y-service belong to the same business application Foo and require the same permissions → both can use the Keycloak client C1.
  • z-service also belongs to the business application Foo, but requires more rights than x-service and y-service → needs a different Keycloak client C2.
  • v-service belongs to the business application Pip → needs its own Keycloak client C3.
  • b-service belongs to the business application Bar → needs its own Keycloak client C4.

Considerations and Recommendations​

  • We authorize business applications, not microservices, because the provider does not need to know how the consuming business application is structured.
    • Refactoring the consuming business application does not change the permissions.
    • A client can be used by several microservices of the consuming business application if they need exactly the same rights.
    • If needed, the calling microservice can be identified through the trace ID (Distributed tracing).
  • Each microservice gets only the rights that it needs to perform its tasks, following the (principle of least privilege).
    • This can mean that a business application may require several Keycloak clients with different permissions.