Validate Authorization

User account actions over resources are tested against known policies using the Validate Authorization method. The context for the authorization is built from the user account's (the subject) JWT token or API Key.

**enforcer.validateAuthorization()** - given an intent to complete some action over a resource, test whether or not the user account defined by the current auth session has consent to complete the requested action. Uses the concept of Base Context and Derived Context to evaluate user accounts against Mesh API policies.

FieldDescriptionValid Values
actionValidation requests must declare the action that the subject intends to make on the resourceread, write
contextsAn arbitrary number of context requests offered by the Mesh API Adminsharing_intents, id_sessions, account_groups, tenant, role
policy_idPolicies are defined by Mesh Adminsapp.mesh_sharing_intents, app.mesh_acl
resourceThe fully qualified resource identifier to locate the resourceResource location path
resource_typeThe resource typeapi, storj, sxt-table, sxt-view, object-store, vnft
security_artifactOptional base64 encoded security data (table biscuits, access grants). May be required for the sharing recipient to access the resourceBase64 encoded string
Context TypeDescriptionValid Values
sharing_intentsContext check for any sharing intents made for the subject's self, tenant, role, or account groupsN/A
id_sessionsContext check for identity verification sessions (liveness checks)N/A
account_groupsContext check for groups that the subject belongs toN/A
tenantContext check for subject's tenantPublic, Private
roleContext check for the subject's roleAdmin, Service Account, Developer, User
import { initializeMeshSDK, logResponse } from "./util";
import { 
  ValidateAuthorizationResponse,
  ValidateAuthorizationRequest
} from "@instruxi-io/mesh-sdk-core";

async function main() {
    try {
        const mesh = await initializeMeshSDK();
		
        const request: ValidateAuthorizationRequest = {
            action: "read",
            contexts: [
                "sharing_intents",
                "account_groups",
                "id_sessions"
            ],
            policy_id: "app.sharing_intents",
            resource: "sj://0x92F78491093bA0dd88A419b1BF07aeb3BA9fD0dc/file.json",
            resource_type: "file"
        };
        
        let response: ValidateAuthorizationResponse = await mesh.enforcer.validateAuthorization(request);
        await logResponse('Authorization Validation', response);

    } catch (error) {
        console.error("An error occurred:", error);
    }
}

main().catch((error) => {
    console.error("Unhandled error in main function:", error);
    process.exit(1);
});

Example of validation logic

Concept Check

  • User Account Context - The user context in the Mesh API web server is defined by user account metadata. The user account's metadata is sourced from the application database (base context) from admin defined master data tables built for the web application. The
  • Base Account Context - On Mesh API, the user account's Base Account Context is the Account Address, Tenant, and Role sourced from the application database in Space and Time.
  • Derived Account Context - The Validate Authorization capability on the Enforcer allows clients to test custom authorization requests on the Mesh API by specifying additional contexts. The Enforcer is capable of Deriving additional context from metadata sourced from secondary sources of account data using the Base Context as inputs to fetch new data.
  • Open Policy Agent (OPA) - OPA offers a processing environment to evaluate policies written as Regu against account context