Aserto Authorization Policy
This policy will authorize requests using Aserto. If the request is not authorized, a 403 response will be returned.
This policy is designed to be highly customizable in order to tailor the
authorization requests to the specific needs of your application. You can use
the default authorization context, or you can programmatically add attributes to
the request using the setAuthorizationContext
method.
Using this policy in conjunction with an authorization policy will automatically
set the identity_context
for the user in the request.
Beta
This policy is in beta. You can use it today, but it may change in non-backward compatible ways before the final release.
Configuration
The configuration shows how to configure the policy in the 'policies.json' document.
Policy Options
The options for this policy are specified below. All properties are optional unless specifically marked as required.
allowUnauthorizedRequests
<boolean> -Indicates whether the request should continue if authorization fails. Default isDefaults tofalse
which means unauthorized users will automatically receive a 403 response.false
.tenantId
<string> (Required) -The Aserto Tenant ID.authorizerApiKey
<string> (Required) -The Aserto API key.authorizerApiUrl
<string> -The Aserto Authorizer API URL.Defaults to"https://authorizer.prod.aserto.com"
.policyName
<string> -The policy instance name.Defaults to"api-auth"
.serviceName
<string> (Required) -Canonicalized service name.userSubPropertyPath
<string> -The path to the user's sub property in the request.Defaults to".sub"
.
Using the Policy
Authorization Attributes#
There are two options for authorization attributes in the Aserto Policy. You can
use the default attributes or you can programmatically add attributes to the
request using the setAuthorizationContext
method.
Default Attributes#
If you don't set any attributes, the policy will automatically use the following authorization context.
The identity_context
will be set to the user's sub. The user
property value
can be customized by setting the userSubPropertyPath
option. For example, if
you want to get the user's email address and you have set an email
property on
the API Key Metadata, you can set the value to .data.email
. Similarly, you can
select values on JWT tokens by setting the value to .data.claim
.
The resource_context
will be set to the object_type
and relation
properties as shown in the example below. The object_id
will be set to a
concatenation of the service name, request method, and route path.
The policy_context
will be set to the decisions
and path
properties as
shown in the example below.
The policy_instance
will be set to the authorizerPolicyName
property set in
the policies options
.
Programmatically Setting Attributes#
For the more robust customization of the authorization request, you can set authorization context programmatically. This is done by running a custom inbound policy before the authorization policy. The custom policy can set any attribute on the authorization request.
Below is an example of how you could set the resource_context.id
attribute to
the value of the id
route parameter.
Read more about how policies work