SwanseaUniversityMedical / DARE-Teleport

0 stars 0 forks source link

`TASK [dare.common.vault_init_config : unseal each vault pod until threshold is reached]` if Vault is not initialised #92

Closed mikej888 closed 1 year ago

mikej888 commented 1 year ago

Issue encountered while running DARE-SeRP-Dev-Deployment Version: 43f688f (Thu Sep 14 17:15:42 2023 +0100) main branch.

Running monolithic_mk8s_example/1-vm-setup-and-deploy.yaml sometimes failed at:

$ ansible-playbook -i vmware-host.yaml 1-vm-setup-and-deploy.yaml -v
...
TASK [dare.common.vault_init_config : unseal each vault pod until threshold is reached] ***
failed: [single_host] (item=0) => {"ansible_loop_var": "item",
"changed": true, "item": "0", "rc": 2, "return_code": 2, "stderr":
"Error unsealing: Error making API request.\n\nURL: PUT
http://127.0.0.1:8200/v1/sys/unseal\nCode: 400. Errors:\n\n* Vault is
not initialized\n", "stderr_lines": ["Error unsealing: Error making
API request.", "", "URL: PUT http://127.0.0.1:8200/v1/sys/unseal",
"Code: 400. Errors:", "", "* Vault is not initialized"], "stdout": "",
"stdout_lines": []}

A workaround that has worked is the following. Back up dare.common collection vault_init_config role init.yml task:

$ cp ~/.ansible/collections/ansible_collections/dare/common/roles/vault_init_config/tasks/init.yml ~/.ansible/collections/ansible_collections/dare/common/roles/vault_init_config/tasks/init.yml.bak

Edit ~/.ansible/collections/ansible_collections/dare/common/roles/vault_init_config/tasks/init.yml to

  1. Remove task to initialise Vault, as it's already initialised.
  2. Remove task to set a fact with output from the above.
  3. Remove task to save unseal keys to a file, as it's already been done.
  4. Add a new task to set a fact with the contents of output/vault/root-unseal.json from the Ansible control node (these correspond to the outputs of the Vault initialisation). i.e.:
    
    ---
alee-x commented 1 year ago

Hi @mikej888 ,

I'm a bit confused by this. The error message indicates that Vault isn't initialised, but you mention

Remove task to initialise Vault, as it's already initialised.

the unseal task set is also only accessible via the init task set, so it follows that Vault must have been initialised for ansible to get to the unseal.yml tasks.

if it's a timing issue (i.e. ansible making the unseal request too quickly after vault is initialised) then I suppose we can just add a step to pause for 5-10 seconds to wait for it. @JossWhittle any thoughts?

mikej888 commented 1 year ago

Hi @alee-x, I found the message contradictory too. It happened a few times. However, rerunning the playbook as-is definitiely failed as it complained that the Vault was already initialised.

I searched for '"Error unsealing" "Vault is not initialized"' and found that others have had comparable issues...

However, nothing springs out as being a satisfactory explanation with a solution. The Vault version that was installed is 1.13.1.

mikej888 commented 1 year ago

Fixed by @alee-x in #106, #107, #108, #109.