liveBook · Manning

Type safety

As explained in Authorization in Action

Strong typing is a language property in which values and operations obey enforced type rules that prevent invalid combinations.

An authorization rule can fail dangerously when it compares incompatible values, references an undefined attribute, or confuses entity types. Type safety prevents these mistakes by enforcing valid combinations before policies reach production. section 7.4.1 section 7.4.3

Cedar is statically validated and strongly typed. A schema defines entities, actions, attributes, and relationships; policies are checked against that schema before evaluation. This contrasts with relying on runtime checks alone: mistakes such as comparing a string with a number or mixing incompatible set types are caught earlier. section 7.4.1 section 9.2

Type safety supports authorization policy work in several connected ways:

  • Validates contextual values, including IP addresses, timestamps, durations, decimals, strings, numbers, sets, and records. section 7.4.1
  • Checks that attributes exist on the referenced entity type, so an expression such as resource.owner cannot silently target an incompatible object. section 7.4.3
  • Keeps namespaces distinct, requiring fully qualified names across boundaries and preventing accidental comparisons between entities such as Employee and Document. section 7.4.3
  • Improves maintainability and analysis by pairing structured entities with predictable policy logic that tools can inspect for conflicts, coverage gaps, and unexpected grants. section 7.4.2 section 7.6

A typed authorization check

A policy may safely test context.device.ip == ip("192.168.0.10") when the value has the expected IP type. It cannot perform an IP check on a timestamp, compare an Employee with a Document, or use resource.owner where that attribute is not defined; the policy fails type checking instead of producing an unpredictable authorization result. section 7.4.1 section 7.4.3

resource.owner == principal

Inspect a typed relationship expression that compares the principal with the resource owner. section 7.4.2

How Authorization in Action covers it

How deep it goes
Descends from typed primitives through schema-checked attributes, namespaces, and entity references, stopping at policy validation rather than runtime behavior.
Examples
Uses IP checks, ownership expressions, namespace-qualified entities, and invalid Employee, Document, timestamp, and attribute references.
What it assumes
Assumes familiarity with authorization requests, while defining schemas, entities, actions, attributes, and typed policy expressions.
What you can do after
Diagnose policy mistakes before deployment and maintain authorization rules with schema validation and analysis tooling.
How it connects
Connects schemas, namespaces, entity models, relationships, policy analysis, and real-time authorization.

Also explained in

Compare how 8 books explain type safety →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Authorization in Action. The section links point to the parts of the book it draws on.