Skip to content
docsv0.12.0

PolicyGate

Policy gate for tool authorization. Checks scopes, channel policies, and tool permissions. Supports dynamic rules via PolicyRuleProviderInterface (e.g. the host's Doctrine-backed provider). **Fail-closed on unknown channels.** A channel nobody registered no longer inherits the laxest possible policy (the old `?? []`, under which `require_auth` defaulted to false and an anonymous caller sailed through). An unregistered channel now falls back to {@see self::UNKNOWN_CHANNEL_POLICY} — `require_auth: true`, no `allow_all` — and the gate emits a learnable warning naming it. An unknown channel is treated as untrusted, never as the most permissive one.

PolicyGate::__construct()

public function __construct(Psr\Log\LoggerInterface $logger = new NullLogger()):

Parameters

Parameters of __construct()
NameTypeDescription
$loggerLoggerInterfacesink for the learnable warning emitted when an unregistered channel falls back to the fail-closed policy — defaults to a {@see NullLogger} so existing `new PolicyGate()` callers keep working unchanged

PolicyGate::setRuleProvider()

public function setRuleProvider(Milpa\ToolRuntime\Contracts\PolicyRuleProviderInterface $provider): void

Set the policy rule provider for database-driven rules.

Parameters

Parameters of setRuleProvider()
NameTypeDescription
$providerMilpa\ToolRuntime\Contracts\PolicyRuleProviderInterface

PolicyGate::getRuleProvider()

public function getRuleProvider(): ?Milpa\ToolRuntime\Contracts\PolicyRuleProviderInterface

Get the current rule provider (if set).

PolicyGate::channelPolicy()

public function channelPolicy(string $channel): array

La channel policy efectiva de un canal (lectura pura para la inspección, ADR#13) — delega en el mismo {@see policyFor()} que usa authorize()/requiresConfirmation(), así el plan renderea la MISMA política que el runtime consulta, con el mismo fail-closed para canales desconocidos.

Parameters

Parameters of channelPolicy()
NameTypeDescription
$channelstring

PolicyGate::hasRuleProvider()

public function hasRuleProvider(): bool

¿Hay un provider de reglas DB conectado? Lectura pura para la inspección (ADR#13).

PolicyGate::authorize()

public function authorize(Milpa\ToolRuntime\Contracts\ToolContext $ctx, Milpa\ToolRuntime\ToolDefinition $tool): Milpa\ToolRuntime\Policy\AuthorizationResult

Authorize a tool call.

Parameters

Parameters of authorize()
NameTypeDescription
$ctxToolContextThe execution context
$toolToolDefinitionThe tool being called

PolicyGate::requiresConfirmation()

public function requiresConfirmation(Milpa\ToolRuntime\Contracts\ToolContext $ctx, Milpa\ToolRuntime\ToolDefinition $tool): bool

Check if confirmation is required for this context + tool.

Parameters

Parameters of requiresConfirmation()
NameTypeDescription
$ctxMilpa\ToolRuntime\Contracts\ToolContext
$toolMilpa\ToolRuntime\ToolDefinition

PolicyGate::setChannelPolicy()

public function setChannelPolicy(string $channel, array $policy): void

Set custom channel policy.

Parameters

Parameters of setChannelPolicy()
NameTypeDescription
$channelstring
$policyarray<string, mixed>