-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 k8s service registration case where Vault fails to unlabel itself as a leader #21642
Conversation
I re-applied this patch on top of the 1.14.0+ent tag on the vault-enterprise repo, and anyone reviewing (with access to the enterprise repo) can save the repro script as an executable file repro.sh and run the following to test: VAULT_LICENSE=...
kind create cluster
kubectl create secret generic vault-license --from-literal="vault.hclic=${VAULT_LICENSE}"
gh run download --repo hashicorp/vault-enterprise --name vault-enterprise_default_linux_arm64_1.14.0+ent_0e81b9fed2383bfdfd3a9b926893fb1f1c5470ca.docker.tar 5544311282
docker image load --input vault-enterprise_default_linux_arm64_1.14.0+ent_0e81b9fed2383bfdfd3a9b926893fb1f1c5470ca.docker.tar
kind load docker-image hashicorp/vault-enterprise:1.14.0-ent
./repro.sh Without my fix, it consistently reproduces within 2 tries. With my fix, I've retried 20 times with no reproduction. |
I'm confused as to why this change is necessary. From what I can tell, we only keep the HA lock in two instances: when we restore a raft snapshot, and possible when enabling a replication secondary. Ah, but update-primary is almost the same thing as enabling a replication secondary, so that makes sense then, given the repro. My misgiving is that this seems inconsistent. If we're keeping the HA lock, why should we change the service registration state? For raft at least, holding the HA lock is synonymous with being the leader. |
This gets to the core of where I get a bit lost. On line 692 just above, we set I guess the obvious other candidate fix would be to unlabel ourselves when we relinquish the HA lock instead of when we set |
Based on |
There are two levels in Vault that have an understanding as to active status: the physical-ha layer, and the Core layer. When we call sealInternalWithOptions with keepHALock=true, the idea is that we need to rebuild a Core because something fundamental has changed (snapshot has been restored, secondary mode has been enabled) and there's no other mechanism to flush our state. While it's true that we won't be an active node - indeed, we'll be sealed for a bit - we're expecting that once we get unsealed we'll remain the active node as we were prior. And we know that no one else will be the active node either until we resume, assuming nothing goes wrong. Ok, I read the jira and now I have a better idea as to motivation. I'm not opposed to this change, and I think it's safe. A part of me wants to push instead for getting rid of keepHALock, since I'm not sure how necessary it is, and it adds complexity. But that's a riskier change, so maybe let's go with what you have for now. |
Thanks! |
This bug only ever occurs on enterprise, as we only ever call
sealInternalWithOptions
withkeepHALock
astrue
in enterprise, and sokeepHALockOnStepDown
is always 0 in OSS. When we step down as a leader but keep the HA lock, we should still unlabel ourselves as leader in k8s, but that happens inclearLeader
, so before this fix if we keep the HA lock we'll never unlabel ourselves. Essentially, this change ensures we more closely track the core'sstandby
state variable in that case.I'm not sure about automated testing yet. I've been using the following script for reproducing the issue locally.
Repro script