Skip to content

MM-67108: Auto-generate Encryption Key on upgrade if missing#218

Merged
nevyangelova merged 2 commits intomasterfrom
MM-67108-auto-generate-encryption-key
Jan 15, 2026
Merged

MM-67108: Auto-generate Encryption Key on upgrade if missing#218
nevyangelova merged 2 commits intomasterfrom
MM-67108-auto-generate-encryption-key

Conversation

@nevyangelova
Copy link
Contributor

Summary

When upgrading to v1.7.0 users would see an error if the Encryption Key was not set. This change auto generates a valid 32-character key if it's missing or invalid and saves it to the plugin config.

QA steps

  • Start with Confluence plugin v1.6.0 or any version before the Encryption Key was required
  • Ensure the Encryption Key field is empty in System Console → Plugins → Confluence
  • Upgrade to the new plugin version (with this fix)

Expected: Plugin activates successfully without errors
Check System Console → Plugins → Confluence - Encryption Key should now be auto-populated

Ticket Link

https://mattermost.atlassian.net/browse/MM-67108

When upgrading to v1.7.0+, users would see an error if the Encryption Key
was not set. This change auto-generates a valid 32-character key if it's
missing or invalid, and saves it to the plugin config.

- Added generateRandomKey() helper function
- Added savePluginConfig() to persist auto-generated keys
- Existing valid keys are not overwritten
- Plugin now starts successfully on upgrade without manual intervention
@nevyangelova nevyangelova requested a review from a team as a code owner January 13, 2026 13:22
@nevyangelova nevyangelova added 2: Dev Review Requires review by a core committer 3: QA Review Requires review by a QA tester labels Jan 13, 2026
Copy link
Member

@jwilander jwilander left a comment

Choose a reason for hiding this comment

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

Looks good. I would like to see us starting to add unit tests to integrations but I won't block the PR on it as there's hardly any unit tests in the plugin at all.

- Test generateRandomKey() generates correct length and unique keys
- Test OnConfigurationChange auto-generates key when missing
- Test existing valid keys are not overwritten
@nevyangelova
Copy link
Contributor Author

@jwilander Opus helped generate the test quite quickly! Ran them and they look good, and I can't think of a missing case, let me know if you want to see another example?

@jwilander
Copy link
Member

Great! The only other case I can think of is a negative integer being passed to generateRandomKey

@nevyangelova
Copy link
Contributor Author

@jwilander thanks for the suggestion! I considered adding validation for negative integers but generateRandomKey is a private function only called internally with a hardcoded value of 32 i don't see a code path where a negative or zero value could be passed.

Copy link

@ogi-m ogi-m left a comment

Choose a reason for hiding this comment

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

LGTM! Verified the key gets auto-generated on upgrade

@ogi-m ogi-m added 4: Reviews Complete All reviewers have approved the pull request and removed 2: Dev Review Requires review by a core committer 3: QA Review Requires review by a QA tester labels Jan 15, 2026
@nevyangelova nevyangelova merged commit 999f3fe into master Jan 15, 2026
7 checks passed
@nevyangelova nevyangelova deleted the MM-67108-auto-generate-encryption-key branch January 15, 2026 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4: Reviews Complete All reviewers have approved the pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants