Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Prevent issues with missing or mismatching encryption key #8332

Merged

Conversation

ivov
Copy link
Contributor

@ivov ivov commented Jan 15, 2024

  • If N8N_ENCRYPTION_KEY does not match configFile.encryptionKey, fail to init main
  • If N8N_ENCRYPTION_KEY is missing on worker, fail to init worker
  • If credential decryption fails when attempting to edit a credential, surface better error message
  • If HTTPRN execution fails due to cred decryption error, block execution
  • Tests

Story: https://linear.app/n8n/issue/PAY-1184

@n8n-assistant n8n-assistant bot added core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team labels Jan 15, 2024
@Joffcom
Copy link
Member

Joffcom commented Jan 15, 2024

@ivov would this fix #8287?

@ivov
Copy link
Contributor Author

ivov commented Jan 15, 2024

@ivov would this fix #8287?

This PR will make it more evident that there is a mismatch, but the root cause of this user's mismatch is likely what Adi mentioned: #8287 (comment)

@ivov ivov marked this pull request as ready for review January 15, 2024 15:32
const { encryptionKey, tunnelSubdomain } = settings;

if (process.env.N8N_ENCRYPTION_KEY && encryptionKey !== process.env.N8N_ENCRYPTION_KEY) {
throw new ApplicationError(
Copy link
Contributor

Choose a reason for hiding this comment

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

Existing behavior is to take precedence in the config file - should we throw and prevent starting or just warn the users about it?

Copy link
Contributor Author

@ivov ivov Jan 16, 2024

Choose a reason for hiding this comment

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

I was following this:

also, we need to add a check when there is an encryption key in .n8n/config and it does not match the one being passed in via N8N_ENCRYPTION_KEY, and fail to start the application.

Copy link

cypress bot commented Jan 16, 2024

Passing run #3783 ↗︎

0 331 5 0 Flakiness 0

Details:

🌳 🖥️ browsers:node18.12.0-chrome107 🤖 ivov 🗃️ e2e/*
Project: n8n Commit: 65af207fe0
Status: Passed Duration: 03:21 💡
Started: Jan 16, 2024 5:13 PM Ended: Jan 16, 2024 5:16 PM

Review all test suite changes for PR #8332 ↗︎

Copy link
Contributor

✅ All Cypress E2E specs passed

@ivov ivov merged commit d4c93b1 into master Jan 16, 2024
32 checks passed
@ivov ivov deleted the pay-1184-executions-dont-fail-when-credentials-cant-be-decrypted branch January 16, 2024 17:25
@github-actions github-actions bot mentioned this pull request Jan 17, 2024
@janober
Copy link
Member

janober commented Jan 17, 2024

Got released with n8n@1.25.0

@Dasio
Copy link

Dasio commented Feb 5, 2024

Hello,
I'm loading encryption key only from config file, not from env. And this MR broke it. Because it checks only if environment variable is set, which in my case is empty.

@krynble
Copy link
Contributor

krynble commented Feb 6, 2024

Thanks for the comment @Dasio - we discussed it privately but for completeness' sake, we made this change to assert that users would always provide the encryption key in a reliable way; the config file is generated at runtime if not existing, which could lead to issues with workers, so in order to prevent this, we added this check.

Sorry for the trouble, you should change the settings to provide the encryption key via environment variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team Released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants