Download the PHP package kjdev/cedar without Composer

On this page you can find all versions of the php package kjdev/cedar. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package cedar

PHP Cedar Extension

A PHP extension that evaluates Cedar policies locally, with an API compatible with Amazon Verified Permissions (AVP) (Aws\VerifiedPermissions\VerifiedPermissionsClient). Swap an AVP client for Cedar\AuthorizationClient in your code and the request / response payloads keep the same shape — there is no AVP service call, the policies are evaluated in-process.

The Cedar evaluation engine is a snapshot of nxe-cedar (the NGINX-edge Cedar evaluator) rewritten for use inside a PHP extension. See src/cedar/UPSTREAM.md for the upstream commit and re-import policy.

Requirements

Installation

With PIE (recommended)

PIE is the modern PHP extension installer (it replaces pecl install).

PIE drives the standard phpizeconfiguremakemake install flow under the hood, taking care of locating php-config and dropping a cedar.ini into the right SAPI directory.

Manual build

Then enable the extension by adding extension=cedar.so to a PHP ini file (e.g. /etc/php.d/40-cedar.ini).

Quick start

Drop-in replacement for AWS Verified Permissions

Cedar\AuthorizationClient::isAuthorized() accepts the same request shape as Aws\VerifiedPermissions\VerifiedPermissionsClient::isAuthorized() and returns a response with the same top-level keys (decision, determiningPolicies, errors). You can therefore swap one for the other through dependency injection — a common setup is AVP in production, this extension for local development, CI, and on-prem deployments, with no changes at the call site.

Introduce a thin interface that both implementations satisfy, and wrap each concrete client in a small adapter. The adapter on the AVP side exists only to coerce Aws\Result (which implements ArrayAccess) into a plain array so the return type matches:

Wire either implementation into your container, then keep the call site identical:

The policyStoreId value is the only thing that differs between the two backends:

Inject the right value through configuration (env var, parameter, etc.) and the rest of the request payload is byte-for-byte identical.

See AVP compatibility for the per-key compatibility matrix and Unsupported features for the known gaps (entity tags, policy templates, schema validation, dynamic identity sources).

API overview

Cedar\PolicyStore

Container that holds one or more Cedar policy bundles. It corresponds to the PolicyStore concept in AVP.

Method Description
__construct(?string $policyStoreId = null) Optional explicit id; auto-generated 32-char lowercase hex when omitted.
loadFile(string $policyId, string $path): static Read a policy file via php_stream and register it under $policyId. Throws Cedar\Exception\PolicyParseException on parse errors or duplicate ids.
loadString(string $policyId, string $cedarText): static Same as loadFile but takes the source directly. Returns $this (fluent).
id(): string Returns the configured policy store id.
policyIds(): list<string> Returns the ids of every bundle currently loaded.

Cedar\AuthorizationClient

AVP-compatible evaluation client.

$options['identitySource'] (required only for isAuthorizedWithToken()):

Key Type Default Meaning
principalEntityType string (required) Cedar entity type used for the derived principal, e.g. "MyApp::User".
principalIdClaim string "sub" Claim that holds the principal id inside the verified token payload.
groupEntityType string (optional) Cedar entity type for groups (e.g. "MyApp::Group").
groupIdsClaim string (optional) Claim that holds the principal's group ids as a list of strings (e.g. "cognito:groups").

Methods:

Method Description
isAuthorized(array $params): array AVP-shaped evaluation against the bound PolicyStore.
isAuthorizedWithToken(array $params): array Like isAuthorized() but the principal (and optional group parents) come from a token payload; see Token verification below.

Request shape (AVP-compatible)

Both methods accept the same keys as the corresponding AVP API:

policyStoreId, principal (for isAuthorized()), action, and resource are required; context and entities are optional and may be omitted entirely when the policies do not reference them. A request with only the required keys is valid and evaluates normally.

AttributeValue is the same single-key union AVP uses:

Response shape

Exceptions

All three subclass \RuntimeException:

Class When
Cedar\Exception\PolicyParseException Cedar syntax error or duplicate policyId in loadFile / loadString.
Cedar\Exception\EvaluationException Allocation / engine-level failures.
Cedar\Exception\ResourceNotFoundException policyStoreId in the request does not match PolicyStore::id(). AVP raises the same-named error in this case.

Argument-shape errors (missing policyStoreId, supplying principal to isAuthorizedWithToken, etc.) surface as the engine-level Error class, not as one of the Cedar exceptions.

AVP compatibility

Aspect Compatibility
isAuthorized() request keys Complete (policyStoreId / principal / action / resource / context / entities).
AttributeValue union members Complete for everything the bundled Cedar evaluator supports (see Unsupported features for the upstream gaps).
Response keys decision / determiningPolicies / errors match exactly. Aws\Result's ArrayAccess methods (->get(...)) are not available — the response is a plain array.
isAuthorizedWithToken() API-shape compatible (policyStoreId / identityToken / accessToken / action / resource / context / entities, response includes the derived principal), but the token is expected to be a verified claims array, not a raw JWT string. See Token verification.

Beyond matching the request / response shape, what makes this extension substitutable for AVP is that the same request yields the same decision. The evaluation engine is kept logically identical to its upstream nxe-cedar snapshot (see src/cedar/UPSTREAM.md), so it inherits nxe-cedar's behavioral conformance: the C implementation is differential-tested against the upstream cedar-policy reference crate, with 100% C-vs-reference parity reported over the official Cedar integration-test corpus (see nxe-cedar's conformance notes). This parity guarantee covers only the supported subset: the unsupported features (entity tags, policy templates, schema validation, dynamic identity sources) lie outside the conformance corpus and are not part of the claim.

For a worked example of swapping AVP and this extension behind a single interface, see Drop-in replacement for AWS Verified Permissions.

Token verification is caller's responsibility

isAuthorizedWithToken() accepts the token as a decoded, verified claims array rather than as a raw JWT string. This is a deliberate design choice:

Use a dedicated PHP library — for example firebase/php-jwt or web-token/jwt-framework — to verify the JWT (signature, issuer, expiry, audience, token_use) and pass the resulting payload array to this extension:

When both identityToken and accessToken are supplied, this extension uses identityToken and ignores accessToken. This differs slightly from AVP, which accepts both and resolves the principal and claim mapping from the configured identity source and each token's token_use claim.

Unsupported features

The Cedar evaluator follows the feature set bundled from upstream nxe-cedar. The following features are not available in this release:

A malformed or unsupported AttributeValue (for example an unknown union key, or ['datetime' => 'not-a-date']) does not abort the request: the entry is skipped and an entry is appended to the response's errors[]. This matches AVP's behavior of returning a successful response with populated errors when a single attribute is broken.

Performance and persistence

The current implementation is request-scoped: every PHP-FPM request that needs to authorize re-parses the policy bundles via PolicyStore::loadFile() / loadString(). Parsing is fast for the small / medium policy sets typical of authorization rules (the Cedar grammar is small and the evaluator is hand-written C with no external dependencies), so this is normally not a hot spot.

If you need to share parsed policies across requests within a worker:

Multiple PolicyStores per client

This release supports one PolicyStore per AuthorizationClient. If you need to evaluate requests against different stores (e.g. one store per tenant), instantiate a separate AuthorizationClient for each one. A future release may accept multiple stores on the constructor and dispatch on the request's policyStoreId.

ZTS status

Both NTS and ZTS builds are supported. composer.json reports support-zts: true, and CI runs a full --enable-zts build plus make test for every PHP version in the matrix. Thread-safety notes:

Developing the extension

cedar.stub.php declares the PHP-facing API. After editing it, regenerate cedar_arginfo.h:

The test suite uses the standard .phpt format under tests/. Run a subset with:

License

This extension is released under the MIT License. The bundled Cedar evaluator under src/cedar/ retains its upstream license; see src/cedar/UPSTREAM.md.


All versions of cedar with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package kjdev/cedar contains the following files

Loading the files please wait ...