aboutsummaryrefslogtreecommitdiff
path: root/tests/test-openbao-passwords.sh
blob: 5e6b115bad32245b9b48662660232693ca9b7133 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash

set -o xtrace
set -o errexit

export PYTHONUNBUFFERED=1

function install_openbao {
    if [[ $BASE_DISTRO =~ (debian|ubuntu) ]]; then
        curl -fsSLO https://github.com/openbao/openbao/releases/download/v2.4.1/bao_2.4.1_linux_amd64.deb
        sudo dpkg -i bao_2.4.1_linux_amd64.deb
        rm -f bao_2.4.1_linux_amd64.deb
    else
        sudo dnf install -y https://github.com/openbao/openbao/releases/download/v2.4.1/bao_2.4.1_linux_amd64.rpm
    fi
}

function start_openbao {
    nohup bao server --dev &
    # Give Vault some time to warm up
    sleep 10
}

function test_openbao {
    TOKEN=$(bao token create -address 'http://127.0.0.1:8200' -field token)
    echo "${TOKEN}" | bao login -address 'http://127.0.0.1:8200' -
    bao kv put -address 'http://127.0.0.1:8200' secret/foo data=bar
}

function test_writepwd {
    TOKEN=$(bao token create -address 'http://127.0.0.1:8200' -field token)
    kolla-writepwd \
        --passwords /etc/kolla/passwords.yml \
        --vault-addr 'http://127.0.0.1:8200' \
        --vault-token ${TOKEN} \
        --vault-mount-point secret
}

function test_readpwd {
    TOKEN=$(bao token create -address 'http://127.0.0.1:8200' -field token)
    cp etc/kolla/passwords.yml /tmp/passwords-openbao.yml
    kolla-readpwd \
        --passwords /tmp/passwords-openbao.yml \
        --vault-addr 'http://127.0.0.1:8200' \
        --vault-token ${TOKEN} \
        --vault-mount-point secret
}

function teardown {
    pkill bao
}

function test_openbao_passwords {
    echo "Setting up development OpenBao server..."
    source $KOLLA_ANSIBLE_VENV_PATH/bin/activate
    install_openbao
    start_openbao
    test_openbao
    echo "Write passwords to OpenBao..."
    test_writepwd
    echo "Read passwords from OpenBao..."
    test_readpwd
    echo "Cleaning up..."
    teardown
}

test_openbao_passwords