Skip to content

Comments

Add entriesAdditions and allowedImportAdditions for policy imports#2347

Open
thjaeckle wants to merge 5 commits intoeclipse-ditto:masterfrom
beyonnex-io:feature/2221-policy-imports-enhancements
Open

Add entriesAdditions and allowedImportAdditions for policy imports#2347
thjaeckle wants to merge 5 commits intoeclipse-ditto:masterfrom
beyonnex-io:feature/2221-policy-imports-enhancements

Conversation

@thjaeckle
Copy link
Member

@thjaeckle thjaeckle commented Feb 18, 2026

Resolves: #2221

Introduce entriesAdditions on policy imports to allow importing policies to additively merge subjects and resources into imported policy entries. Template policies control what can be extended via allowedImportAdditions (enum-backed, secure-by-default: empty set means no additions allowed).

New model types: EntryAddition, EntriesAdditions, AllowedImportAddition enum. Write-time validation ensures entriesAdditions labels are declared in entries. Merge-time logic in PolicyImporter silently skips disallowed additions.

The PR also adds HTTP endpoints for:

  • /api/2/policies/{policyId}/entries/{label}/allowedImportAdditions
  • /api/2/policies/{policyId}/entries/{label}/importable (was existing before in the policy model, however no extra endpoint was yet provided)
  • /api/2/policies/{policyId}/imports/{importedPolicyId}/entries (was existing before in the policy model, however no extra endpoint was yet provided)
  • /api/2/policies/{policyId}/imports/{importedPolicyId}/entriesAdditions

As adding those separate endpoints and providing also model classes to map requests/responses adds a lot of boilerplate code, the PR got quite big..

…clipse-ditto#2221)

Introduce `entriesAdditions` on policy imports to allow importing policies
to additively merge subjects and resources into imported policy entries.
Template policies control what can be extended via `allowedImportAdditions`
(enum-backed, secure-by-default: empty set means no additions allowed).

New model types: EntryAddition, EntriesAdditions, AllowedImportAddition enum.
Write-time validation ensures entriesAdditions labels are declared in entries.
Merge-time logic in PolicyImporter silently skips disallowed additions.

Includes OpenAPI schema updates, documentation, and comprehensive tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@thjaeckle thjaeckle added this to the 3.9.0 milestone Feb 18, 2026
@thjaeckle thjaeckle self-assigned this Feb 18, 2026
@thjaeckle thjaeckle marked this pull request as draft February 20, 2026 07:56
thjaeckle and others added 3 commits February 20, 2026 09:24
…ction

All code paths that reconstructed PolicyEntry objects (builder, ImmutablePolicy
mutations, command/event strategies, placeholder substitution, gateway route)
were using 3-arg or 4-arg factory methods that silently dropped the new
allowedImportAdditions field. Upgraded all call sites to the 5-arg
PoliciesModelFactory.newPolicyEntry() overload and added unit tests verifying
preservation through each code path.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…mportable

Add endpoints for managing policy import entries, entriesAdditions,
entryAddition, allowedImportAdditions, and entry importable type.
Includes signal classes, command/event strategies, gateway routes,
protocol adapter mappings, OpenAPI docs, and unit tests.

Also fix OpenAPI validation errors in PermissionCheckRequest,
PermissionCheckResponse, and WoT validation config response schemas.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@thjaeckle thjaeckle marked this pull request as ready for review February 23, 2026 10:59
@thjaeckle
Copy link
Member Author

System tests run: https://github.com/eclipse-ditto/ditto/actions/runs/22302981477

Inlcuding added tests from eclipse-ditto/ditto-testing#22

Copy link
Contributor

@alstanchev alstanchev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the one comment looks great 👍

@hu-ahmed
Copy link
Contributor

I noticed an issue in the importable API validation.

PUT /api/2/policies/{id}/entries/{label}/importable returns 500 for invalid payload values, but this should be a 400 Bad Request validation error.

Repro:

control case (valid -> 204)

curl -g -sS -i -X PUT
-H "Authorization: Bearer $TOKEN"
-H 'Content-Type: application/json'
--data '"never"'
'http://127.0.0.1:8080/api/2/policies/org.eclipse.pr2347%3Aimported-retest/entries/template/importable'

failing case (invalid -> currently 500, should be 400)

curl -g -sS -i -X PUT
-H "Authorization: Bearer $TOKEN"
-H 'Content-Type: application/json'
--data '"bogus"'
'http://127.0.0.1:8080/api/2/policies/org.eclipse.pr2347%3Aimported-retest/entries/template/importable'

@hu-ahmed
Copy link
Contributor

hu-ahmed commented Feb 24, 2026

I noticed another issue in allowedImportAdditions validation.

PUT /api/2/policies/{id}/entries/{label}/allowedImportAdditions accepts invalid enum values silently, but it should return a 400 Bad Request validation error.

Repro:

control case (valid -> 204)

curl -g -sS -i -X PUT
-H "Authorization: Bearer $TOKEN"
-H 'Content-Type: application/json'
--data '["subjects"]'
'http://127.0.0.1:8080/api/2/policies/org.eclipse.pr2347%3Arepro-allowed-additions/entries/template/allowedImportAdditions'

failing case (invalid -> currently 204, should be 400)

curl -g -sS -i -X PUT
-H "Authorization: Bearer $TOKEN"
-H 'Content-Type: application/json'
--data '["subjects","bogus"]'
'http://127.0.0.1:8080/api/2/policies/org.eclipse.pr2347%3Arepro-allowed-additions/entries/template/allowedImportAdditions'
verify stored value after invalid PUT
curl -g -sS -i
-H "Authorization: Bearer $TOKEN"
'http://127.0.0.1:8080/api/2/policies/org.eclipse.pr2347%3Arepro-allowed-additions/entries/template/allowedImportAdditions'

…ditions values

Replace IllegalArgumentException (500) with PolicyEntryInvalidException (400)
for invalid importable type values, and reject unknown allowedImportAdditions
enum values instead of silently dropping them.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@thjaeckle
Copy link
Member Author

Thanks @hu-ahmed for catching both issues! 👍

Fixed in b6b48b9:

  • PUT .../importable with invalid values now returns 400 instead of 500
  • PUT .../allowedImportAdditions with invalid enum values now returns 400 instead of silently dropping them

Also added regression tests for both cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Enhance policy imports in a way to enhance the imported policy entries, e.g. providing additional subjects

3 participants