authentik icon indicating copy to clipboard operation
authentik copied to clipboard

Policy bindings API: writing back the `target` returned by reads fails since 2026.11 ("object does not exist")

Open ikob opened this issue 2 days ago • 0 comments

Describe the bug

Since 2026.11.0, the policy bindings API no longer accepts the target value that it returns on reads, when the target is a model with its own primary key, such as a flow stage binding.

Reads return the target's own pk (for example fsb_uuid). Writes resolve target by the PolicyBindingModel pk (pbm_uuid), so writing back the value from a read fails with 400. This comes from #26666, which replaced the subclass pk lookup in PolicyBindingModelForeignKey.to_internal_value with get_subclass(pk=data). That assumes the pk is shared across the inheritance chain, but Flow, FlowStageBinding, Device, RequestRule, RequestRuleBinding and UserExpirationRule declare their own primary keys. I reproduced it with flow stage bindings only.

The admin UI is not affected, because it sends policybindingmodel_ptr_id for flows. API clients that send a target they read, and blueprints that use !Find on a flow stage binding as a target, are affected.

How to reproduce

With a policy bound to a flow stage binding:

  1. GET /api/v3/policies/bindings/?policy=<policy pk>. The binding's target is the flow stage binding's pk.
  2. PATCH /api/v3/policies/bindings/<binding pk>/ with {"policy": "<policy pk>", "target": "<target from step 1>", "enabled": true}. The result is 400: {"target": ["Invalid pk \"…\" - object does not exist."]}. A POST with the same target fails the same way.
  3. The same request with target set to the flow stage binding's policybindingmodel_ptr_id returns 200, and a following read still returns the flow stage binding's pk as target.

In a blueprint, target: !Find [authentik_flows.flowstagebinding, …] on a policy binding fails validation with the same error, while !KeyOf works.

Expected behavior

A binding read from the API can be written back unchanged: writes accept the target's own pk, as in 2026.8.3, or reads and writes both use pbm_uuid.

Additional context

  • Our Ansible playbook sends this PATCH (with the target from a read). It worked on 2026.8.3 and failed with the 400 above after upgrading to 2026.11.0.
  • Separately, a PATCH that omits target (for example {"enabled": true}) returns 500, because PolicyBindingSerializer.validate() calls attrs.get("target").supported_policy_binding_targets(). validate() is unchanged since 2026.8.3, so this may not be new.
  • #28032 changes how targets are read, not this lookup.

Deployment Method

Kubernetes

Version

2026.11.0

Relevant log output

AttributeError: 'NoneType' object has no attribute 'supported_policy_binding_targets'
  File "/authentik/policies/api/bindings.py", line 88, in validate

AI disclosure

I used Claude Code (Claude Opus 5.5) to trace the cause in the code, reproduce it on my 2026.11.0 test deployment and draft this issue. I reviewed the text.

ikob avatar Dec 04 '26 13:12 ikob