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

[FIXED] Restore of encrypted filestore with no main key could cause dataloss #4301

Merged
merged 1 commit into from Jul 12, 2023

Conversation

derekcollison
Copy link
Member

When restoring a filestore with no key generator but it was encrypted, fail to restore.

Signed-off-by: Derek Collison derek@nats.io

…, fail to restore.

Signed-off-by: Derek Collison <derek@nats.io>
@derekcollison derekcollison requested a review from a team as a code owner July 12, 2023 01:24
Copy link
Member

@neilalexander neilalexander left a comment

Choose a reason for hiding this comment

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

In principle LGTM, but I wanted to be sure why this works, so I enabled server logging on the new TestJetStreamClusterBadEncryptKey.

What happens is that EnableJetStream() skips over all of the streams that it cannot decrypt and continues to start up. It's actually the setupMetaGroup() call that returns an error on creating the file store for the _meta_ group:

=== RUN   TestJetStreamClusterBadEncryptKey
[INF] Starting nats-server
[INF]   Version:  2.9.20-beta
[INF]   Git:      [not set]
[INF]   Cluster:  JSC
[INF]   Name:     S-3
[INF]   Node:     Z2sYEJH3
[INF]   ID:       NCRLBZHG3ZXJN5O74BXUMIWIDALGYMIXILHIRNFI6RPBNKYUXU4RBM7Y
[WRN] Plaintext passwords detected, use nkeys or bcrypt
[INF] Using configuration file: /var/folders/l7/w_j8hk_d59l_nw0hknw3c2q40000gn/T/TestJetStreamClusterBadEncryptKey2097575401/006/739122146
[INF] Starting JetStream
[INF]     _ ___ _____ ___ _____ ___ ___   _   __  __
[INF]  _ | | __|_   _/ __|_   _| _ \ __| /_\ |  \/  |
[INF] | || | _|  | | \__ \ | | |   / _| / _ \| |\/| |
[INF]  \__/|___| |_| |___/ |_| |_|_\___/_/ \_\_|  |_|
[INF] 
[INF]          https://docs.nats.io/jetstream
[INF] 
[INF] ---------------- JETSTREAM ----------------
[INF]   Max Memory:      256.00 MB
[INF]   Max Storage:     2.00 GB
[INF]   Store Directory: "/var/folders/l7/w_j8hk_d59l_nw0hknw3c2q40000gn/T/TestJetStreamClusterBadEncryptKey2097575401/005/jetstream"
[INF] -------------------------------------------
[WRN]   Error decrypting our stream metafile: encryption not enabled
[WRN]   Error decrypting our stream metafile: encryption not enabled
[WRN]   Error decrypting our stream metafile: encryption not enabled
[WRN]   Error decrypting our stream metafile: encryption not enabled
[WRN]   Error decrypting our stream metafile: encryption not enabled
[WRN]   Error decrypting our stream metafile: encryption not enabled
[WRN]   Error decrypting our stream metafile: encryption not enabled
[WRN]   Error decrypting our stream metafile: encryption not enabled
[WRN]   Error decrypting our stream metafile: encryption not enabled
[WRN]   Error decrypting our stream metafile: encryption not enabled
[INF] Starting JetStream cluster
[INF] Creating JetStream metadata controller
/var/folders/l7/w_j8hk_d59l_nw0hknw3c2q40000gn/T/TestJetStreamClusterBadEncryptKey2097575401/005/jetstream/$SYS/_js_/_meta_/meta.key
[ERR] Error creating filestore: encrypted store encountered with no main key
[FTL] Can't start JetStream: encrypted store encountered with no main key
FAIL    github.com/nats-io/nats-server/v2/server        4.246s

... which is fine for clustered mode as we can't skip creating _meta_, but we don't call setupMetaGroup() when running in standalone mode. That probably means that this fix won't do anything for standalone JetStream servers where we'll end up continuing startup without any streams loaded.

@derekcollison
Copy link
Member Author

Will make logs more descriptive at the very least I think.

Do you think we should bail if a stream fails?

Copy link
Member

@neilalexander neilalexander left a comment

Choose a reason for hiding this comment

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

LGTM for now, will add a backlog item to revisit in 2.10.

@derekcollison derekcollison merged commit 9cfe8b8 into main Jul 12, 2023
2 checks passed
@derekcollison derekcollison deleted the no-key-recover branch July 12, 2023 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants