set/get secret value do not work properly
I have found the following issues when testing secrets (for Ceph storage pools)
setValuewill clip the passed keyvirshretrieves the data base64 transposed
const Promise = require('bluebird'),
exec = Promise.promisify(require('child_process').exec),
virt = require('libvirt'),
uuid = require('uuid');
let secretUUID = uuid.v4(),
secretXml = `<secret ephemeral="no" private="no"><uuid>${secretUUID}</uuid><usage type="ceph">` +
'<name>client.test secret</name></usage></secret>',
key = 'do not tell anyone',
secret;
let hv = virt.createHypervisor('qemu:///system');
hv.connectAsync()
.then(() => hv.defineSecretAsync(secretXml))
.then(_secret => {
secret = _secret;
secret.setValueAsync(key);
})
.then(() => secret.getValueAsync())
.then(value => console.log(`setValue('${key}'), while getValue() returns '${value}'`))
.then(() => exec(`virsh secret-get-value ${secretUUID}`))
.then(stdout => console.log(`virsh reads the secret value as '${stdout.trim()}', which is base64 transposed of the cropped key`))
.then(() => secret.undefineAsync())
.then(() => hv.disconnectAsync());
@oferb1 okay the SetValue bug is fixed in fcb1637a250e456a9d91aac615117136a6f44076. I'm not sure what you mean in the second part of your question: that virsh returns the value base64 encoded? The test I added here shows that setValue will have the same getValue, so I might make the argument that base64 encoding/decoding is up to the end user in this case (and a weird implementation detail of virsh)
Thanks - I confirmed that it works, and was able to set a secret, and define a Ceph pool using it.
Still when I use virsh to read the value, I get it base64 transposed - weird...
Still not sure what you mean about "transposed" in this case. Can you use node-libvirt to check if virsh is converting to base64 on the way in or out? like store it with virsh and read with node-libvirt and visa versa
virsh set value
# virsh secret-set-value a14408e2-e147-4ce9-b081-fd56ffab8e48 AQAGE8hYGi8fFxAAS7c7XdFda/ZblwlF9Z5p/A==
Secret value set
node-libvirt get value
hv.lookupSecretByUUIDAsync('a14408e2-e147-4ce9-b081-fd56ffab8e48').then(secret => secret.getValueAsync()).then(console.log)
Promise {
_bitField: 0,
_fulfillmentHandler0: undefined,
_rejectionHandler0: undefined,
_promise0: undefined,
_receiver0: undefined }
> �X/K�;]�]k�[� E��i�
node libvirt set-value
hv.lookupSecretByUUIDAsync('a14408e2-e147-4ce9-b081-fd56ffab8e48').then(secret => secret.setValueAsync('AQAGE8hYGi8fFxAAS7c7XdFda/ZblwlF9Z5p/A=='))
virsh get value
# virsh secret-get-value a14408e2-e147-4ce9-b081-fd56ffab8e48
QVFBR0U4aFlHaThmRnhBQVM3YzdYZEZkYS9aYmx3bEY5WjVwL0E9PQ==
# virsh secret-get-value a14408e2-e147-4ce9-b081-fd56ffab8e48 | base64 -d
AQAGE8hYGi8fFxAAS7c7XdFda/ZblwlF9Z5p/A==