type AsertoPolicyOptions = {
// required
tenantId: string
authorizerApiKey: string
policyName: string
// required if using api-auth template
serviceName: string
// required if not using api-auth template
objectType: string
objectId: string
relation: string
}
Authorization happens downstream from authentication, so the Aserto authorization policy assumes that an authentication policy precedes it.
The subject of the authorization request is assumed to be found in request.user.data.sub
.
tenantId
: the tenant ID of the Aserto account or organizationauthorizerApiKey
: API key of the Aserto hosted authorizerpolicyName
: policy name (typicallyapi-auth
if using the API Authorization template)
If you're using the API authorization template, the only additional required parameter is:
serviceName
: name of the OpenAPI service imported into Aserto. For example, the Todo API Service gets imported with a service name oftodo
.
If you're using the API authorization template, the Aserto policy used is policy.rebac
, and is called with the following resource context:
{
"object_type": "endpoint",
"object_id": `${serviceName}:${httpMethod}:${routePath}`,
"relation": "can_invoke"
}
${serviceName}:${httpMethod}:${routePath}
is constructed in the following way:
serviceName
: required option in theAsertoPolicyOptions
httpMethod
: automatically extracted from the requestroutePath
: automatically extracted from the request
You can override any of the resource context fields via the following parameters. If serviceName
is not supplied, these parameters become required.
objectType
objectId
relation
Each of these values can be in the following formats:
"string"
: string literal"$header(HEADER_NAME)"
: retrieve the value ofrequest.headers[HEADER_NAME]
"$param(PARAM_NAME)"
: retrieve the value ofrequest.params[PARAM_NAME]
"$body(BODY_KEY_NAME)"
: retrieve the value ofrequest.body[BODY_KEY_NAME]
(this assumes a JSON body and can be a compound - likex.y.z
)
For a URL template that looks like this:
PUT /todos/{todoId}
And a request that looks like this:
PUT /todos/1 HTTP/1.1
Host: myapi.com
Authorization: Bearer <myoauthtoken>
My-Custom-Header: can_put
{
"resource": {
"type": "todo",
"id": "1"
}
}
The following option values:
{
objectType: "$body(resource.type)",
objectId: "$params(todoId)",
relation: "$header(My-Custom-Header)"
}
Will result in the following resource context:
{
"object_type": "todo",
"object_id": "1",
"relation": "can_put"
}
Questions? Join the Aserto Slack Community.