8000 Record existing AES key sizes to prevent key regeneration by lhanusov · Pull Request #54910 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Record existing AES key sizes to prevent key regeneration - #54910

Merged
mposolda merged 1 commit into
keycloak:mainfrom
lhanusov:fix/aes-generated-key
Nov 11, 2026
Merged

mposolda merged 1 commit into
keycloak:mainfrom
lhanusov:fix/aes-generated-key

Conversation

@lhanusov
@lhanusov lhanusov commented Nov 9, 2026 •
Copy link
Copy Markdown
Contributor

Closes #54016

Co-authored by: Codex noreply@openai.com

Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues block approval of the migration intended to preserve existing AES keys.

No open issues 🎉

What changed in this PR

Addresses #54016 by recording existing AES key sizes during the 26.8.0 migration, preventing an unchanged Admin Console save from unintentionally rotating legacy keys.

Changes:

  • Derives missing secretSize values from stored AES secrets, preserving explicit sizes and skipping providers without secrets.
  • Adds integration coverage for key preservation, excluded providers, repeat migrations, and intentional rotation.
  • Documents the migration behavior in the upgrade guide.
File Description
tests/​base/​src/​test/​java/​org/​keycloak/​tests/​migration/​GeneratedAesKeySizeMigrationTest.java Tests migration and subsequent provider saves through the Admin REST API.
model/​storage-private/​src/​main/​java/​org/​keycloak/​migration/​migrators/​MigrateTo26_8_0.java Persists missing AES key sizes through the realm model.
docs/​documentation/​upgrading/​topics/​changes/​changes-26_8_0.adoc Explains how migration preserves existing AES keys.

Review effort: Balanced

@lhanusov
lhanusov force-pushed the fix/aes-generated-key branch from 973e206 to 0ef9d3c Compare November 9, 2026 14:11
Copilot AI balanced review requested due to automatic review settings November 9, 2026 14:11
@lhanusov
lhanusov force-pushed the fix/aes-generated-key branch from 0ef9d3c to 01b6685 Compare November 9, 2026 14:14
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The migration test snapshots state after migration and import validation backfills secretSize, leaving migration-time replacement of the legacy secret or key ID undetected.

1 open issue

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 9, 2026 14:14
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The tests do not exercise persisted 16-byte legacy configuration without secretSize or compare secrets and key IDs against pre-migration values, leaving key preservation during migration unverified.

1 open issue

Review effort: Balanced

@lhanusov
lhanusov force-pushed the fix/aes-generated-key branch from 01b6685 to 94dd7f5 Compare November 9, 2026 15:09
Copilot AI balanced review requested due to automatic review settings November 9, 2026 15:09
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Databases already on 26.8.x skip the backfill, leaving legacy 16-byte AES providers vulnerable to key rotation on an unchanged save.

1 open issue
1 resolved since last review

Review effort: Balanced


@Override
public void migrateRealm(KeycloakSession session, RealmModel realm) {
migrateGeneratedAesKeySizes(realm);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I second this comment. The 26.8.0 was already released, so people who already migrated to 26.8.0 will not migrate.

This migration logic should be rather added to the file for the upcoming release, which is MigrateTo26_8_3.java .

@mposolda mposolda left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@lhanusov Thanks! I've added some inline comments related to proper versions (one of them is related to the copilot comment). Besides that, it looks good!


@Override
public void migrateRealm(KeycloakSession session, RealmModel realm) {
migrateGeneratedAesKeySizes(realm);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I second this comment. The 26.8.0 was already released, so people who already migrated to 26.8.0 will not migrate.

This migration logic should be rather added to the file for the upcoming release, which is MigrateTo26_8_3.java .

testMigrationTo25_0_0();
testMigrationTo26_0_0(true);
testMigrationTo26_3_0();
testMigrationTo26_8_0(migrationRunOnServer);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should be different method. Either testMigrationTo26_8_3 or as part of the existing method testMigrationTo27_0_0 .

// ------------------------ Notable changes ------------------------ //
== Notable changes

=== Existing AES key sizes are recorded during migration
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is upgrading guide of already released version, so it does not work to add it here. In keycloak main, it should be rather added to changes-27_0_0.adoc .

Hint for the backport: once backporting this to the branch release/26.8, it would need to be changes-26_8_3.adoc inside that branch.

@mposolda mposolda self-assigned this Nov 10, 2026
@mposolda mposolda left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@lhanusov One additional thing: If the file MigrateTo26_8_3 does not exists yet, it might be probably added to the rolling-upgrades-unsupported or rolling-upgrades-supported file (according to whether the change is safe for rolling upgrades or not...

@mposolda
mposolda commented Nov 10, 2026 •
Copy link
Copy Markdown
Contributor

@lhanusov One additional thing: If the file MigrateTo26_8_3 does not exists yet, it might be probably added to the rolling-upgrades-unsupported or rolling-upgrades-supported file (according to whether the change is safe for rolling upgrades or not...

@lhanusov Sorry for false alarm :-) The files rolling-upgrades-*.json are not supposed to be updated in the main branch. However they may be added during the backport in the release/26.8 branch (as long as your PR would introduce the file MigrateTo26_8_3 inside the release/26.8 branch. Some more details: #54887 (comment)

@lhanusov
lhanusov force-pushed the fix/aes-generated-key branch from 94dd7f5 to c4e7cb5 Compare November 11, 2026 09:00
Copilot AI balanced review requested due to automatic review settings November 11, 2026 09:00
@lhanusov lhanusov changed the title Preserve existing AES keys when saving migrated providers Record existing AES key sizes to prevent key regeneration Nov 11, 2026
Closes keycloak#54016

Signed-off-by: choksi2212 <choksi2212@users.noreply.github.com>

Signed-off-by: Lukas Hanusovsky <lhanusov@redhat.com>
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the AES key-size migration and key-preservation changes.

1 open issue

Review effort: Balanced

@lhanusov
lhanusov force-pushed the fix/aes-generated-key branch from c4e7cb5 to 44968ce Compare November 11, 2026 09:04
@mposolda mposolda left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@lhanusov Thanks!

@mposolda
mposolda merged commit 08ad72f into keycloak:main Nov 11, 2026
95 of 96 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Admin console shows AES key size 32 for pre-26.7 aes-generated providers, and Save silently replaces the 128-bit key

4 participants

0