Compare commits

..

1 Commits

Author SHA1 Message Date
Thomas Moraine
239db19d92 docs(backups): document BodyTimeoutError in backup troubleshooting
Extend the "HTTP connection has timed out" section to cover
BodyTimeoutError (UND_ERR_BODY_TIMEOUT), which reports the same
inactivity timeout, and explain that it is not a network, credentials
or repository failure.

Add a subsection for full backups failing while delta backups succeed
on VMs with large disks or a lot of free space, pointing to #9181.

The previous anchor is kept so existing links still work.
2026-11-16 12:46:27 +01:00
113 changed files with 345 additions and 5592 deletions

View File

@@ -44,39 +44,3 @@ obfuscated.token = 'qux'
merge(obfuscated, original)
// → { username: 'foo', password: 'bar', token: 'qux' }
```
### `redact(value, [isSensitive], [options])`
> Recursively replace sensitive entries with the same special tag as `obfuscate()`, whatever their type.
>
> Unlike `obfuscate()`, it uses a broader list of sensitive keys (`isExportSensitiveParam`) because redacted values are never merged back: it is meant for data leaving XO, such as support dumps or audit records. Keys are kept so that the structure stays usable.
Options:
- `replacement`: the special tag of `obfuscate()` by default
- `urls`: whether to also apply `redactUrls()` to the other strings, `false` by default
```js
import { redact } from '@vates/obfuscate'
redact({ username: 'foo', password: 'bar', cluster_token: { value: 'baz' } })
// → {
// username: 'foo',
// password: 'obfuscated-q3oi6d9X8uenGvdLnHk2',
// cluster_token: 'obfuscated-q3oi6d9X8uenGvdLnHk2',
// }
redact({ error: 'cannot mount nfs://user:pass@host/path' }, undefined, { replacement: '*', urls: true })
// → { error: 'cannot mount nfs://*@host/path' }
```
### `redactUrls(string, [replacement])`
> Replace the credentials and the sensitive query parameters (e.g. `encryptionKey`) of the URLs in a string, wherever they are (e.g. in an error message).
```js
import { redactUrls } from '@vates/obfuscate'
redactUrls('s3://KEY:secret@s3.lan/bucket?encryptionKey=foo', '*')
// → 's3://*@s3.lan/bucket?encryptionKey=*'
```

View File

@@ -61,42 +61,6 @@ merge(obfuscated, original)
// → { username: 'foo', password: 'bar', token: 'qux' }
```
### `redact(value, [isSensitive], [options])`
> Recursively replace sensitive entries with the same special tag as `obfuscate()`, whatever their type.
>
> Unlike `obfuscate()`, it uses a broader list of sensitive keys (`isExportSensitiveParam`) because redacted values are never merged back: it is meant for data leaving XO, such as support dumps or audit records. Keys are kept so that the structure stays usable.
Options:
- `replacement`: the special tag of `obfuscate()` by default
- `urls`: whether to also apply `redactUrls()` to the other strings, `false` by default
```js
import { redact } from '@vates/obfuscate'
redact({ username: 'foo', password: 'bar', cluster_token: { value: 'baz' } })
// → {
// username: 'foo',
// password: 'obfuscated-q3oi6d9X8uenGvdLnHk2',
// cluster_token: 'obfuscated-q3oi6d9X8uenGvdLnHk2',
// }
redact({ error: 'cannot mount nfs://user:pass@host/path' }, undefined, { replacement: '*', urls: true })
// → { error: 'cannot mount nfs://*@host/path' }
```
### `redactUrls(string, [replacement])`
> Replace the credentials and the sensitive query parameters (e.g. `encryptionKey`) of the URLs in a string, wherever they are (e.g. in an error message).
```js
import { redactUrls } from '@vates/obfuscate'
redactUrls('s3://KEY:secret@s3.lan/bucket?encryptionKey=foo', '*')
// → 's3://*@s3.lan/bucket?encryptionKey=*'
```
## Contributions
Contributions are _very_ welcomed, either on the documentation or on

View File

@@ -57,74 +57,3 @@ function replace(value, replacement) {
return helper(value)
}
exports.replace = replace
// broader than SENSITIVE_PARAMS because redacted values are never merged back:
// meant for data leaving XO (e.g. support dumps, audit records), not for display
const EXPORT_SENSITIVE_PARAMS = [
/api[-_]?key/i, // e.g. `apikey` in the XenServer credentials of user preferences
'encryptionKey',
'privateKey',
'pw_hash',
/passphrase/i,
/password/i,
/secret/i,
/token/i,
]
const isExportSensitiveParam = name =>
EXPORT_SENSITIVE_PARAMS.some(pattern => (typeof pattern === 'string' ? pattern === name : pattern.test(name)))
exports.isExportSensitiveParam = isExportSensitiveParam
// SMB URLs (e.g. of backup repositories) contain the raw password, which can
// contain any character (e.g. `smb://user:p@ss/w@domain\\\\host\0path`), so the
// credentials are everything up to the last `@` before the path
const SMB_CREDENTIALS_RE = /^(smb:\/\/)[^\0]*@/i
// other URLs, anywhere in the string (e.g. an error message): credentials are
// URL encoded and end at the first `@`, see https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1
const URL_CREDENTIALS_RE = /([a-z][a-z\d+.-]*:\/\/)[^\s/?#@]*@/gi
// e.g. `?encryptionKey=` in a backup repository URL, same names as SENSITIVE_PARAMS
const SENSITIVE_QUERY_PARAM_RE = /([?&](?:encryptionKey|passphrase|token|[^=&#\s]*password[^=&#\s]*)=)[^&#\s]*/gi
// replaces the credentials and the sensitive query parameters of the URLs in a string
function redactUrls(string, replacement = OBFUSCATED_VALUE) {
if (!string.includes('://')) {
return string
}
return string
.replace(SMB_CREDENTIALS_RE, (_, scheme) => `${scheme}${replacement}@`)
.replace(URL_CREDENTIALS_RE, (_, scheme) => `${scheme}${replacement}@`)
.replace(SENSITIVE_QUERY_PARAM_RE, (_, param) => `${param}${replacement}`)
}
exports.redactUrls = redactUrls
// unlike replace(), also replaces non-string entries (e.g. a whole object under
// a `secret` key), keys are kept so that the structure stays usable
//
// options:
// - `replacement`: OBFUSCATED_VALUE by default
// - `urls`: whether to apply redactUrls() to the other strings, false by default
function redact(value, isSensitive = isExportSensitiveParam, { replacement = OBFUSCATED_VALUE, urls = false } = {}) {
function helper(value) {
if (typeof value === 'string') {
return urls ? redactUrls(value, replacement) : value
}
if (typeof value !== 'object' || value === null) {
return value
}
if (Array.isArray(value)) {
return value.map(helper)
}
const result = {}
for (const key of Object.keys(value)) {
result[key] = isSensitive(key) ? replacement : helper(value[key])
}
return result
}
return helper(value)
}
exports.redact = redact

View File

@@ -1,94 +0,0 @@
'use strict'
const { describe, it } = require('node:test')
const assert = require('node:assert/strict')
const { obfuscate, OBFUSCATED_VALUE, redact, redactUrls } = require('./')
describe('redact()', () => {
it('replaces sensitive entries at any depth, whatever their type, and keeps the keys', () => {
const remote = {
name: 'nas',
url: 's3://key@host/bucket',
encryptionKey: 'aes-key',
proxy: { authenticationToken: 'proxy-token' },
credentials: [{ username: 'admin', password: 'pass', secret: { value: 'chap' } }],
}
assert.deepEqual(redact(remote), {
name: 'nas',
url: 's3://key@host/bucket',
encryptionKey: OBFUSCATED_VALUE,
proxy: { authenticationToken: OBFUSCATED_VALUE },
credentials: [{ username: 'admin', password: OBFUSCATED_VALUE, secret: OBFUSCATED_VALUE }],
})
})
it('catches keys missed by obfuscate()', () => {
const plugin = { apiKey: 'k', cluster_token: 't', secretAccessKey: 's', pw_hash: 'h' }
assert.deepEqual(redact(plugin), {
apiKey: OBFUSCATED_VALUE,
cluster_token: OBFUSCATED_VALUE,
secretAccessKey: OBFUSCATED_VALUE,
pw_hash: OBFUSCATED_VALUE,
})
assert.equal(obfuscate(plugin).apiKey, 'k')
})
it('accepts a custom predicate and replacement', () => {
assert.deepEqual(
redact({ a: 1, b: { a: 2, c: 3 } }, key => key === 'a', { replacement: '*' }),
{
a: '*',
b: { a: '*', c: 3 },
}
)
})
it('redacts the URLs of the other strings with `urls`', () => {
const data = {
params: { url: 'smb://admin:p@ss@nas\\\\share' },
error: 'mount of nfs://user:pass@host/path failed',
}
assert.deepEqual(redact(data, undefined, { replacement: '*', urls: true }), {
params: { url: 'smb://*@nas\\\\share' },
error: 'mount of nfs://*@host/path failed',
})
assert.deepEqual(redact(data), data)
})
it('returns other values as is', () => {
assert.equal(redact('password'), 'password')
assert.equal(redact(null), null)
})
})
describe('redactUrls()', () => {
it('replaces the credentials of URLs, anywhere in the string', () => {
assert.equal(
redactUrls('failed to connect to https://user:p%40ss@host/ and s3://KEY:secret@s3.lan/bucket'),
`failed to connect to https://${OBFUSCATED_VALUE}@host/ and s3://${OBFUSCATED_VALUE}@s3.lan/bucket`
)
})
it('replaces the credentials of SMB URLs up to the last @ before the path', () => {
assert.equal(redactUrls('smb://user:p@ss/w@domain\\\\host\0path', '*'), 'smb://*@domain\\\\host\0path')
})
it('replaces sensitive query parameters', () => {
assert.equal(
redactUrls('s3://host/bucket?encryptionKey=k&region=eu&adminPassword=p', '*'),
's3://host/bucket?encryptionKey=*&region=eu&adminPassword=*'
)
})
it('handles replacements containing $', () => {
assert.equal(redactUrls('http://u:p@h/', '$1'), 'http://$1@h/')
})
it('returns strings without URLs as is', () => {
assert.equal(redactUrls('user:pass@host'), 'user:pass@host')
})
})

View File

@@ -18,7 +18,6 @@
"node": ">=8.10"
},
"scripts": {
"postversion": "npm publish --access public",
"test": "node --test"
"postversion": "npm publish --access public"
}
}

View File

@@ -1,48 +0,0 @@
```js
import { createClient } from '@vates/syslog'
const client = createClient('tls://syslog.company.lan', {
appName: 'my-app',
facility: 'authpriv',
})
await client.send('something happened', { msgid: 'event', severity: 'warning' })
// closes the connection once the messages already sent are delivered, the client reconnects if it is used again
client.close()
```
### `createClient(uri, options)`
`uri`: `udp://host[:port]`, `tcp://host[:port]` or `tls://host[:port]`, the default port is `514`, or `6514` for TLS.
Options:
- `appName`: application name of the messages, `node` by default
- `facility`: one of `FACILITIES` (e.g. `user`, `authpriv`, `local0`), `user` by default
- `format`: `rfc5424` (default) or `rfc3164`
- `framing` (TCP and TLS): `lf` (default, each message followed by a line feed, its own line breaks written as `\n` and `\r`) or `octet-counting` (each message prefixed by its length, required by some servers for TLS, see [RFC 5425](https://datatracker.ietf.org/doc/html/rfc5425#section-4.3))
- `hostname`: host name of the messages, `os.hostname()` by default
- `ca` (TLS): contents of PEM certificate authorities to trust, in addition to the system ones
- `allowUnauthorized` (TLS): do not check the certificate of the server, `false` by default
- `closeTimeout`: in milliseconds, how long `close()` waits for the messages already sent, `10e3` by default
- `connectTimeout`: in milliseconds, `10e3` by default
- `maxPendingBytes`: messages are rejected when more than this is waiting to be sent (e.g. the server is unreachable or does not read), `1 MiB` by default
A client uses at most one connection, opened when needed.
### `client.send(message, options)`
Returns a promise which resolves when the message has been handed to the system. Syslog has no acknowledgement: it does not mean that the server received it.
Options:
- `msgid`: message ID (RFC 5424 only)
- `severity`: one of `SEVERITIES` (e.g. `error`, `warning`, `informational`), `informational` by default
- `timestamp`: `Date` of the message, now by default
The promise rejects if the message cannot be sent, with the cause of the failure (e.g. connection refused, invalid certificate, too much data waiting).
### `client.close()`
Closes the connection, including a connection which is being established. The messages already sent are still delivered first (e.g. while the connection is being established or the host name resolved), for at most `closeTimeout`: after that, those not sent fail.

View File

@@ -1,36 +0,0 @@
.*
/benchmark/
/benchmarks/
*.bench.{,c,m}js
*.bench.{,c,m}js.map
/coverage/
/examples/
example.{,c,m}js
example.{,c,m}js.map
*.example.{,c,m}js
*.example.{,c,m}js.map
/fixture/
/fixtures/
*.fixture.{,c,m}js
*.fixture.{,c,m}js.map
*.fixtures.{,c,m}js
*.fixtures.{,c,m}js.map
/test/
/tests/
*.integ.{,c,m}js
*.integ.{,c,m}js.map
*.spec.{,c,m}js
*.spec.{,c,m}js.map
*.test.{,c,m}js
*.test.{,c,m}js.map
__snapshots__/
/docs/
/src/
eslint.config.mjs

View File

@@ -1,81 +0,0 @@
<!-- DO NOT EDIT MANUALLY, THIS FILE HAS BEEN GENERATED -->
# @vates/syslog
[![Package Version](https://badgen.net/npm/v/@vates/syslog)](https://npmjs.org/package/@vates/syslog) ![License](https://badgen.net/npm/license/@vates/syslog) [![PackagePhobia](https://badgen.net/bundlephobia/minzip/@vates/syslog)](https://bundlephobia.com/result?p=@vates/syslog) [![Node compatibility](https://badgen.net/npm/node/@vates/syslog)](https://npmjs.org/package/@vates/syslog)
> Syslog client: RFC 5424 messages over UDP, TCP or TLS, with a bounded buffer
## Install
Installation of the [npm package](https://npmjs.org/package/@vates/syslog):
```sh
npm install --save @vates/syslog
```
## Usage
```js
import { createClient } from '@vates/syslog'
const client = createClient('tls://syslog.company.lan', {
appName: 'my-app',
facility: 'authpriv',
})
await client.send('something happened', { msgid: 'event', severity: 'warning' })
// closes the connection once the messages already sent are delivered, the client reconnects if it is used again
client.close()
```
### `createClient(uri, options)`
`uri`: `udp://host[:port]`, `tcp://host[:port]` or `tls://host[:port]`, the default port is `514`, or `6514` for TLS.
Options:
- `appName`: application name of the messages, `node` by default
- `facility`: one of `FACILITIES` (e.g. `user`, `authpriv`, `local0`), `user` by default
- `format`: `rfc5424` (default) or `rfc3164`
- `framing` (TCP and TLS): `lf` (default, each message followed by a line feed, its own line breaks written as `\n` and `\r`) or `octet-counting` (each message prefixed by its length, required by some servers for TLS, see [RFC 5425](https://datatracker.ietf.org/doc/html/rfc5425#section-4.3))
- `hostname`: host name of the messages, `os.hostname()` by default
- `ca` (TLS): contents of PEM certificate authorities to trust, in addition to the system ones
- `allowUnauthorized` (TLS): do not check the certificate of the server, `false` by default
- `closeTimeout`: in milliseconds, how long `close()` waits for the messages already sent, `10e3` by default
- `connectTimeout`: in milliseconds, `10e3` by default
- `maxPendingBytes`: messages are rejected when more than this is waiting to be sent (e.g. the server is unreachable or does not read), `1 MiB` by default
A client uses at most one connection, opened when needed.
### `client.send(message, options)`
Returns a promise which resolves when the message has been handed to the system. Syslog has no acknowledgement: it does not mean that the server received it.
Options:
- `msgid`: message ID (RFC 5424 only)
- `severity`: one of `SEVERITIES` (e.g. `error`, `warning`, `informational`), `informational` by default
- `timestamp`: `Date` of the message, now by default
The promise rejects if the message cannot be sent, with the cause of the failure (e.g. connection refused, invalid certificate, too much data waiting).
### `client.close()`
Closes the connection, including a connection which is being established. The messages already sent are still delivered first (e.g. while the connection is being established or the host name resolved), for at most `closeTimeout`: after that, those not sent fail.
## Contributions
Contributions are _very_ welcomed, either on the documentation or on
the code.
You may:
- report any [issue](https://github.com/vatesfr/xen-orchestra/issues)
you've encountered;
- fork and create a pull request.
## License
[ISC](https://spdx.org/licenses/ISC) © [Vates SAS](https://vates.fr)

View File

@@ -1,311 +0,0 @@
'use strict'
const dgram = require('dgram')
const net = require('net')
const os = require('os')
const splitHost = require('split-host')
const tls = require('tls')
// https://datatracker.ietf.org/doc/html/rfc5424#section-6.2.1
const FACILITIES = {
__proto__: null,
kern: 0,
user: 1,
mail: 2,
daemon: 3,
auth: 4,
syslog: 5,
lpr: 6,
news: 7,
uucp: 8,
cron: 9,
authpriv: 10,
ftp: 11,
ntp: 12,
audit: 13,
alert: 14,
clock: 15,
local0: 16,
local1: 17,
local2: 18,
local3: 19,
local4: 20,
local5: 21,
local6: 22,
local7: 23,
}
exports.FACILITIES = Object.keys(FACILITIES)
const SEVERITIES = {
__proto__: null,
emergency: 0,
alert: 1,
critical: 2,
error: 3,
warning: 4,
notice: 5,
informational: 6,
debug: 7,
}
exports.SEVERITIES = Object.keys(SEVERITIES)
const DEFAULT_PORTS = {
tcp: 514,
// https://datatracker.ietf.org/doc/html/rfc5425#section-4.1
tls: 6514,
udp: 514,
}
// header fields must be printable ASCII characters without spaces
const toHeaderField = (value, maxLength) =>
String(value)
.replace(/[^\x21-\x7e]/g, '_')
.slice(0, maxLength) || '-'
const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
const pad2 = n => String(n).padStart(2, '0')
const FORMATTERS = {
// https://datatracker.ietf.org/doc/html/rfc5424#section-6
rfc5424: ({ appName, hostname, message, msgid, pri, timestamp }) =>
`<${pri}>1 ${timestamp.toISOString()} ${hostname} ${appName} ${process.pid} ${msgid} - ${message}`,
// https://datatracker.ietf.org/doc/html/rfc3164#section-4.1, local time without year
rfc3164: ({ appName, hostname, message, pri, timestamp }) =>
`<${pri}>${MONTHS[timestamp.getMonth()]} ${String(timestamp.getDate()).padStart(2, ' ')} ${pad2(timestamp.getHours())}:${pad2(timestamp.getMinutes())}:${pad2(timestamp.getSeconds())} ${hostname} ${appName}[${process.pid}]: ${message}`,
}
const FRAMERS = {
// https://datatracker.ietf.org/doc/html/rfc6587#section-3.4.2
//
// a line feed ends the message: the line breaks it contains are written as
// `\n` (and `\r`) so that it is received as one message, use octet-counting
// to keep them
lf: message => message.replace(/\r/g, '\\r').replace(/\n/g, '\\n') + '\n',
// https://datatracker.ietf.org/doc/html/rfc6587#section-3.4.1, required by RFC 5425 (TLS)
'octet-counting': message => `${Buffer.byteLength(message)} ${message}`,
}
const noop = Function.prototype
// connecting to a host name with several addresses (e.g. IPv4 and IPv6) fails
// with an AggregateError without message, use the messages of its errors
function withMessage(error) {
if (error.message === '' && Array.isArray(error.errors) && error.errors.length !== 0) {
error.message = error.errors.map(error => error.message).join(', ')
// the first line of the stack has been computed with the empty message
if (typeof error.stack === 'string') {
const i = error.stack.indexOf('\n')
error.stack = `${error.name}: ${error.message}${i === -1 ? '' : error.stack.slice(i)}`
}
}
return error
}
// UDP sockets: callbacks of the datagrams not yet sent (e.g. host name being
// resolved), the socket is closed once they are all called
const pendingDatagrams = new WeakMap()
function closeUdpSocket(socket, timeout) {
const pending = pendingDatagrams.get(socket)
if (pending.size === 0) {
socket.close()
return
}
pending.closing = true
// the datagrams which are still not sent then fail, so that no send() stays pending
setTimeout(() => {
if (pending.size !== 0) {
const callbacks = Array.from(pending)
pending.clear()
socket.close()
const error = new Error('the syslog client was closed before the message could be sent')
callbacks.forEach(cb => cb(error))
}
}, timeout).unref()
}
class SyslogClient {
constructor(
uri,
{
appName = 'node',
ca,
closeTimeout = 10e3,
connectTimeout = 10e3,
facility = 'user',
format = 'rfc5424',
framing = 'lf',
allowUnauthorized = false,
hostname = os.hostname(),
maxPendingBytes = 1024 * 1024,
} = {}
) {
const matches = /^(tcp|tls|udp):\/\/(.+)$/.exec(String(uri).trim())
const protocol = matches?.[1]
const { host, port = DEFAULT_PORTS[protocol] } = (matches !== null && splitHost(matches[2])) || {}
if (!host) {
throw new Error(
`invalid syslog URI: ${uri}, it should be like udp://host[:port], tcp://host[:port] or tls://host[:port]`
)
}
if (!(facility in FACILITIES)) {
throw new Error(`invalid syslog facility: ${facility}`)
}
if (!(format in FORMATTERS)) {
throw new Error(`invalid syslog format: ${format}`)
}
if (!(framing in FRAMERS)) {
throw new Error(`invalid syslog framing: ${framing}`)
}
this._appName = toHeaderField(appName, 48)
this._closeTimeout = closeTimeout
this._connectTimeout = connectTimeout
this._facility = FACILITIES[facility]
this._format = FORMATTERS[format]
this._frame = FRAMERS[framing]
this._host = host
this._hostname = toHeaderField(hostname, 255)
this._maxPendingBytes = maxPendingBytes
this._port = port
this._send = protocol === 'udp' ? this._sendUdp : this._sendStream
this._tlsOptions =
protocol === 'tls'
? {
// the `ca` option replaces the system certificate authorities
ca: ca === undefined ? undefined : [...tls.rootCertificates, ...ca],
rejectUnauthorized: !allowUnauthorized,
}
: undefined
// at most one socket at a time, created when needed
this._socket = undefined
}
// the messages already sent are still delivered (e.g. a connection which is
// being established, or a host name which is being resolved), then the socket
// is closed, at most closeTimeout later
//
// the client can still be used afterwards, it will reconnect
close() {
const socket = this._socket
if (socket === undefined) {
return
}
this._socket = undefined
if (socket instanceof net.Socket) {
// the pending writes are flushed before the connection is ended
socket.end()
const timeout = setTimeout(() => socket.destroy(), this._closeTimeout)
timeout.unref()
socket.once('close', () => clearTimeout(timeout))
} else {
closeUdpSocket(socket, this._closeTimeout)
}
}
// resolves when the message has been handed to the system, which does not
// mean that the server received it (syslog has no acknowledgement)
send(message, { msgid = '-', severity = 'informational', timestamp = new Date() } = {}) {
if (!(severity in SEVERITIES)) {
return Promise.reject(new Error(`invalid syslog severity: ${severity}`))
}
const formatted = this._format({
appName: this._appName,
hostname: this._hostname,
message: String(message),
msgid: toHeaderField(msgid, 32),
pri: this._facility * 8 + SEVERITIES[severity],
timestamp,
})
return new Promise((resolve, reject) => {
this._send(formatted, error => (error == null ? resolve() : reject(error)))
})
}
// TCP and TLS
_sendStream(message, cb) {
let socket = this._socket
if (socket === undefined) {
const tlsOptions = this._tlsOptions
const options = { host: this._host, port: this._port }
socket = this._socket =
tlsOptions === undefined ? net.connect(options) : tls.connect({ ...tlsOptions, ...options })
// a connection attempt that never completes (e.g. packets dropped by a
// firewall, or a TLS handshake without answer) must not stay around
//
// not socket.setTimeout() which is an inactivity timeout, postponed by
// each write during a TLS handshake
const connectTimeout = setTimeout(() => socket.destroy(new Error('connection timed out')), this._connectTimeout)
connectTimeout.unref()
socket.on(tlsOptions === undefined ? 'connect' : 'secureConnect', () => {
clearTimeout(connectTimeout)
// detect a server which disappeared without closing the connection
socket.setKeepAlive(true, 60e3)
})
// errors are passed to the callbacks of the pending writes
socket.on('error', noop)
socket.on('close', () => {
clearTimeout(connectTimeout)
if (this._socket === socket) {
this._socket = undefined
}
})
// do not prevent the process from stopping
socket.unref()
}
// messages are dropped when too much is waiting to be sent (e.g. the server
// is unreachable or no longer reads), instead of filling the memory, this
// also covers the messages written while the connection is being established
if (socket.writableLength > this._maxPendingBytes) {
cb(new Error('too much data waiting to be sent to the syslog server'))
return
}
// pending writes fail with a generic error when the connection fails, report its cause instead
socket.write(this._frame(message), error => cb(error == null ? error : withMessage(socket.errored ?? error)))
}
// one message per datagram, see https://datatracker.ietf.org/doc/html/rfc5426
_sendUdp(message, cb) {
let socket = this._socket
if (socket === undefined) {
socket = this._socket = dgram.createSocket(net.isIPv6(this._host) ? 'udp6' : 'udp4')
pendingDatagrams.set(socket, new Set())
// errors are passed to the callbacks of send(), a failed socket is replaced
socket.on('error', () => {
if (this._socket === socket) {
this.close()
}
})
socket.unref()
}
const pending = pendingDatagrams.get(socket)
pending.add(cb)
socket.send(message, this._port, this._host, error => {
// otherwise, already failed by closeUdpSocket()
if (pending.delete(cb)) {
if (pending.size === 0 && pending.closing) {
socket.close()
}
cb(error)
}
})
}
}
exports.createClient = (uri, opts) => new SyslogClient(uri, opts)

View File

@@ -1,286 +0,0 @@
import assert from 'node:assert/strict'
import dgram from 'node:dgram'
import fs from 'node:fs'
import net from 'node:net'
import tls from 'node:tls'
import { after, describe, it } from 'node:test'
import { setTimeout as wait } from 'node:timers/promises'
import { createClient, FACILITIES, SEVERITIES } from './index.js'
const fixture = name => fs.readFileSync(new URL(`./tests/${name}`, import.meta.url), 'utf8')
const CA = fixture('ca.pem')
const servers = []
after(() => servers.forEach(server => server.close()))
const listen = server =>
new Promise(resolve => {
servers.push(server)
server.listen(0, '127.0.0.1', () => resolve(server.address().port))
})
// stream server collecting the received data
async function createStreamServer(createServer = net.createServer) {
const server = { data: '', sockets: new Set() }
server.port = await listen(
createServer(socket => {
server.sockets.add(socket)
socket.on('close', () => server.sockets.delete(socket))
socket.on('data', data => (server.data += data))
})
)
return server
}
async function createUdpServer() {
const messages = []
const socket = dgram.createSocket('udp4').on('message', message => messages.push(message.toString()))
servers.push(socket)
await new Promise(resolve => socket.bind(0, '127.0.0.1', resolve))
return { messages, port: socket.address().port }
}
describe('createClient()', () => {
it('rejects invalid URIs and options', () => {
for (const uri of ['syslog.lan', 'http://syslog.lan', 'udp://', 'udp://:514', undefined]) {
assert.throws(() => createClient(uri), /invalid syslog URI/, String(uri))
}
assert.throws(() => createClient('udp://h', { facility: 'foo' }), /invalid syslog facility/)
assert.throws(() => createClient('udp://h', { format: 'foo' }), /invalid syslog format/)
assert.throws(() => createClient('udp://h', { framing: 'foo' }), /invalid syslog framing/)
})
it('exposes the facility and severity names', () => {
assert(FACILITIES.includes('authpriv'))
assert.equal(SEVERITIES[4], 'warning')
})
})
describe('send()', () => {
it('formats RFC 5424 messages', async () => {
const server = await createUdpServer()
const client = createClient(` udp://127.0.0.1:${server.port} `, {
appName: 'my app',
facility: 'authpriv',
hostname: 'host',
})
await client.send('{"foo":"bar"}', {
msgid: 'some event',
severity: 'warning',
timestamp: new Date('2026-01-02T03:04:05.678Z'),
})
await wait(50)
client.close()
// header fields are sanitized: no spaces
assert.deepEqual(server.messages, [
`<84>1 2026-01-02T03:04:05.678Z host my_app ${process.pid} some_event - {"foo":"bar"}`,
])
})
it('formats RFC 3164 messages', async () => {
const server = await createUdpServer()
const client = createClient(`udp://127.0.0.1:${server.port}`, {
appName: 'app',
format: 'rfc3164',
hostname: 'host',
})
await client.send('message', { timestamp: new Date(2026, 0, 2, 3, 4, 5) })
await wait(50)
client.close()
assert.deepEqual(server.messages, [`<14>Jan 2 03:04:05 host app[${process.pid}]: message`])
})
it('rejects an invalid severity', async () => {
await assert.rejects(
createClient('udp://127.0.0.1').send('message', { severity: 'foo' }),
/invalid syslog severity/
)
})
it('frames TCP messages with a line feed by default', async () => {
const server = await createStreamServer()
const client = createClient(`tcp://127.0.0.1:${server.port}`)
await client.send('foo')
await client.send('bar')
await wait(50)
client.close()
assert.match(server.data, /^<14>1 [^\n]+ - foo\n<14>1 [^\n]+ - bar\n$/)
})
it('escapes the line breaks of a message framed with a line feed', async () => {
const server = await createStreamServer()
const client = createClient(`tcp://127.0.0.1:${server.port}`)
await client.send('foo\r\nbar\nbaz')
await wait(50)
client.close()
assert.match(server.data, /^<14>1 [^\n]+ - foo\\r\\nbar\\nbaz\n$/)
})
it('frames TCP messages with octet counting', async () => {
const server = await createStreamServer()
const client = createClient(`tcp://127.0.0.1:${server.port}`, { framing: 'octet-counting' })
await client.send('foo')
await client.send('b\när')
await wait(50)
client.close()
// each message is prefixed by its length in bytes
const buffer = Buffer.from(server.data)
const messages = []
for (let offset = 0; offset < buffer.length; ) {
const space = buffer.indexOf(' ', offset)
const length = Number(buffer.toString('utf8', offset, space))
messages.push(buffer.toString('utf8', space + 1, space + 1 + length))
offset = space + 1 + length
}
assert.equal(messages.length, 2)
assert.match(messages[0], /^<14>1 .+ - foo$/)
assert.match(messages[1], /^<14>1 .+ - b\när$/s)
})
it('reconnects when the server closes the connection', async () => {
const server = await createStreamServer()
const client = createClient(`tcp://127.0.0.1:${server.port}`)
await client.send('first')
await wait(50)
server.sockets.forEach(socket => socket.destroy())
await wait(50)
await client.send('second')
await wait(50)
client.close()
assert.match(server.data, /first\n.*second\n$/s)
})
it('reports why the connection failed', async () => {
await assert.rejects(createClient('tcp://127.0.0.1:1').send('message'), { code: 'ECONNREFUSED' })
// several addresses (::1 and 127.0.0.1) fail with an AggregateError, which has no message by itself
await assert.rejects(createClient('tcp://localhost:1').send('message'), error => {
assert.match(error.message, /ECONNREFUSED/)
assert(error.stack.startsWith(`${error.name}: ${error.message}\n`))
return true
})
})
it('stops connecting after connectTimeout, with a single socket', async () => {
// accepts the TCP connection but never answers the TLS handshake
const port = await listen(net.createServer(socket => socket.resume()))
const client = createClient(`tls://127.0.0.1:${port}`, { connectTimeout: 200 })
const sockets = new Set()
const start = Date.now()
const result = client.send('message').catch(error => error)
sockets.add(client._socket)
client.send('message').catch(Function.prototype)
sockets.add(client._socket)
assert.equal((await result).message, 'connection timed out')
assert(Date.now() - start < 1e3)
assert.equal(sockets.size, 1)
})
it('drops messages when too much is waiting to be sent', async () => {
// never reads
const port = await listen(net.createServer(socket => socket.pause()))
const client = createClient(`tcp://127.0.0.1:${port}`, { closeTimeout: 200, maxPendingBytes: 64 * 1024 })
const message = 'x'.repeat(1024)
const results = []
for (let i = 0; i < 10e3; ++i) {
results.push(
client.send(message).then(
() => 'sent',
() => 'dropped'
)
)
}
await wait(500)
client.close()
assert(client._socket === undefined)
assert((await Promise.all(results)).includes('dropped'))
})
it('delivers the messages of a connection which is being established, then closes it', async () => {
const server = await createStreamServer()
const client = createClient(`tcp://127.0.0.1:${server.port}`)
const sent = client.send('message')
const socket = client._socket
client.close()
await sent
await new Promise(resolve => (socket.closed ? resolve() : socket.once('close', resolve)))
assert.match(server.data, /message\n$/)
assert(socket.destroyed)
assert.equal(client._socket, undefined)
})
it('delivers the datagrams whose host name is being resolved, then closes the socket', async () => {
const server = await createUdpServer()
const client = createClient(`udp://localhost:${server.port}`)
const sent = client.send('message')
client.close()
await sent
await wait(100)
assert.equal(server.messages.length, 1)
assert.match(server.messages[0], /message$/)
})
it('stops waiting for the pending writes after closeTimeout', async () => {
// never reads
const port = await listen(net.createServer(socket => socket.pause()))
const client = createClient(`tcp://127.0.0.1:${port}`, { closeTimeout: 200, maxPendingBytes: Infinity })
const results = []
for (let i = 0; i < 1e3; ++i) {
results.push(client.send('x'.repeat(64 * 1024)).then(Function.prototype, error => error))
}
const socket = client._socket
client.close()
const start = Date.now()
await Promise.all(results)
assert(Date.now() - start < 2e3)
assert(socket.destroyed)
})
})
describe('TLS', () => {
const createTlsServer = () =>
createStreamServer(listener =>
tls.createServer({ cert: fixture('server.pem'), key: fixture('server.key') }, listener)
)
it('trusts additional certificate authorities', async () => {
const server = await createTlsServer()
const client = createClient(`tls://localhost:${server.port}`, { ca: [CA] })
await client.send('message')
await wait(50)
client.close()
assert.match(server.data, / - message\n$/)
})
it('rejects an unknown certificate authority, unless allowUnauthorized', async () => {
const server = await createTlsServer()
await assert.rejects(createClient(`tls://localhost:${server.port}`).send('message'), {
code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE',
})
const client = createClient(`tls://localhost:${server.port}`, { allowUnauthorized: true })
await client.send('message')
client.close()
})
it('defaults to port 6514', () => {
assert.equal(createClient('tls://localhost')._port, 6514)
assert.equal(createClient('tcp://[::1]')._port, 514)
assert.equal(createClient('tcp://[::1]')._host, '::1')
})
})

View File

@@ -1,33 +0,0 @@
{
"private": false,
"name": "@vates/syslog",
"description": "Syslog client: RFC 5424 messages over UDP, TCP or TLS, with a bounded buffer",
"keywords": [
"rfc5424",
"syslog",
"tls"
],
"homepage": "https://github.com/vatesfr/xen-orchestra/tree/master/@vates/syslog",
"bugs": "https://github.com/vatesfr/xen-orchestra/issues",
"repository": {
"directory": "@vates/syslog",
"type": "git",
"url": "https://github.com/vatesfr/xen-orchestra.git"
},
"author": {
"name": "Vates SAS",
"url": "https://vates.fr"
},
"license": "ISC",
"version": "0.1.0",
"engines": {
"node": ">=18"
},
"dependencies": {
"split-host": "^2.0.0"
},
"scripts": {
"postversion": "npm publish --access public",
"test": "node --test"
}
}

View File

@@ -1,19 +0,0 @@
-----BEGIN CERTIFICATE-----
MIIDITCCAgmgAwIBAgIUGikUHbKIfotmlkV7oGy7YubSDn8wDQYJKoZIhvcNAQEL
BQAwHzEdMBsGA1UEAwwUdmF0ZXMtc3lzbG9nIHRlc3QgQ0EwIBcNMjYxMDE4MTAx
MjI1WhgPMjEyNjA5MjQxMDEyMjVaMB8xHTAbBgNVBAMMFHZhdGVzLXN5c2xvZyB0
ZXN0IENBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAn/lGtdLEE8tf
gb+hSPe8xLOlGh7ZzRiGcKjkcCbCNFNnjjOa29Lki8ksFD7Su2BWIHpxAzPhEnlQ
9xq7+M9dayM2CslQPuOfKEEyQIBWG9OggXT3kyTn0BVHNFfiGzJlyRz6fIfLf/sU
e2d9AWZhP9I53HpKaNMHyxwuzEBWFxmpv1t7LRVwhrcQjsnoZqxlukpsGyKkT4gs
TNH5/hFhZzmnvfFPhTzQvOGSvFQqgUgd5uxidDmImoRoGA9Ip3bqwMkT99euNrgc
jsxnXeV8pdtHmz4kjQRp+/YIIoh7pA73389OeBx7LC9wpZo1z+3AVKlCAGZ8V9Il
Izk3e7FXTQIDAQABo1MwUTAdBgNVHQ4EFgQUTx7dqoC2XIwpwW0MYcZsoXHqztww
HwYDVR0jBBgwFoAUTx7dqoC2XIwpwW0MYcZsoXHqztwwDwYDVR0TAQH/BAUwAwEB
/zANBgkqhkiG9w0BAQsFAAOCAQEARYUd0q9VwgmZGdhhqks1xCipBuW1eWwBa0jk
Y0jZjhxeq9F0KBMVoazRjjKoL6cwpjvUKytarnN8+kj/7U4dMPLX+/bcpEjwo1gW
DI7MtBI+e1+IohWujDtCqyAiPYpWlwlTTC4kMdfjDH4fbYNY6UHUnedPdSwN3HAp
ZtMb1RoT+gtMedpbnQJKTwxAwH5cBMjTgKeuxeHo6WWjB6evyaLjQINNGLDgLxUC
i4+o0rNYCPtJV3uqw9egDkgoAtMI9mY6snMUxaHGz2JhGzT1wu/UXPrkbFYxCYpm
BGxY36taw81Mr+6n0V1ScWhnGEgPOe3BJCYtoB964YDYfvcFLA==
-----END CERTIFICATE-----

View File

@@ -1,28 +0,0 @@
-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCL0wuMNV3AkIhP
gt4eQ9IPbOkbZiyNOgQWanaRr1P5XeEz4wbWH03MNf9gUDbR2ToGJLfxU68upFYo
uQRCRHRySdbzvhc5+OYbQ2/QvucGKaMnYuerxvENgnh2eLg5QG+Z50M8+IK+jK4t
YJjECe5nefjdtGKQf1h4xgVJp2CQW2zKyfOBqjgcB6bOISDni9+1ssWDkcgVnqyB
8o/zA11CFfO1AL0OBbpD6Fk9HZ29hODCQLOq01vIrfpV2H8S/hsik4tUtMgM10y5
7LNckDzd8LbZQiBUJ/Q63pWDN19SqAW9lsonE3aKJANvew2s/NRtU7EKIeKLvf3a
HPJH83QBAgMBAAECggEABrXXOphrTlj1XL0A5kqOkchSF9s3gUPW80Ey3Wcg2GFo
s9f18ZfdIMM45T02Q0wJtoajuAKCUFKJUsEd1uUQglVgOjB9zn2/I9DwxF+sCEn+
Yy8SQ5Z7pjCEMdnVbAR3UqdUTRBXXHgVihaWIEbifM9wCcpM1mbRJvMoaO5uIkFZ
ztlYElhFC+ITpm8Pjs/fQPNlA8DPZO3xHRSx+M0+tNw3ba7SaFvYTA2o/sMOx1Yq
pyWf7yq6kPDE3vO6NfO8uYrfkw/eNioQ3jZh9tlH/87hm1ucXFOHKxdCpabv2COJ
YIOqIcXlRbXlzVugDY6IOdBcCvUM6DdB+iyOx2m6UQKBgQDEyHoCCJZhLf7ynsmu
onmonWGojX6EwDgpvoey2Lhbr9j7gkCkx7TF+CNRN4AM4o+K9x+m8rF2aJEXKgof
GNwYPpBaUwuV2y+A9wiYtM+o9D4pTy2JPzlfyj7zWIQtOzrIkgSz9BH7QYRA51it
L0d9O6myUs2IILcXdb7gTePA0QKBgQC15qgJ4DeDq+VygQi1VW6Xn2DhiAy1frDY
etG3We+PIKYOc9XN79hI7cSXAy9DYwX7KTQJ13YDYDKNuEEGlijatxMruJv2Zvdm
5CfgNzw+QjFfOM0AXsp9/F4xiiSiUAvLJeZzN7BVPQ/7KUz6kMxtr8RorP66NSFt
zplrq6XMMQKBgQCP+EyraDT9bHV2dI4B4oU3w81LUBocbbWpdOg7BSv8iK8rc6Rv
6lxr6puMNBrPUoLKnPrfXfhQNTjRxcQZ9EoywrNCIjf7r50Vsabscnzrk6ZW+sLK
AyOq3YEo8L3jic38KDigoBT3yntEMP5D1q9rBFenS8VrruPFmjPIT7QtwQKBgQCd
To/bmo/nyuxujbBeQTeW4DoEUIfNHXcKf4yFp71IZc+1h+9KXTUKPLVac2KYQDaX
8hYSvMZOPQ77CHETpSBHpTNrCAe4m2sxC/aALMRogw33b0O6Ij+znGBJL1JnHBpW
4LvewDY6QMhlSF5OApMH+I0+iPzxQ6lZMOX0+0gywQKBgEGcCeJBvqpnSOyMdOFu
MIcLhGa2SIttij1jz7eS9zD+VeONHjmn3Atn7MRagddrYeIGy6ZHUFFsSWBbVqwB
cfT6o0GOeNx0gQn185SUBxB3Oxfg4xWBA0q0GVNFqaScKiXk1IvTj/GTuXM7rehi
HjK6iamDr8lIJE/JFdn2K8ge
-----END PRIVATE KEY-----

View File

@@ -1,20 +0,0 @@
-----BEGIN CERTIFICATE-----
MIIDMzCCAhugAwIBAgIUSGpRtJFiD61hQZBOp49sq7GLkIswDQYJKoZIhvcNAQEL
BQAwHzEdMBsGA1UEAwwUdmF0ZXMtc3lzbG9nIHRlc3QgQ0EwIBcNMjYxMDE4MTAx
MjI1WhgPMjEyNjA5MjQxMDEyMjVaMBQxEjAQBgNVBAMMCWxvY2FsaG9zdDCCASIw
DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAIvTC4w1XcCQiE+C3h5D0g9s6Rtm
LI06BBZqdpGvU/ld4TPjBtYfTcw1/2BQNtHZOgYkt/FTry6kVii5BEJEdHJJ1vO+
Fzn45htDb9C+5wYpoydi56vG8Q2CeHZ4uDlAb5nnQzz4gr6Mri1gmMQJ7md5+N20
YpB/WHjGBUmnYJBbbMrJ84GqOBwHps4hIOeL37WyxYORyBWerIHyj/MDXUIV87UA
vQ4FukPoWT0dnb2E4MJAs6rTW8it+lXYfxL+GyKTi1S0yAzXTLnss1yQPN3wttlC
IFQn9DrelYM3X1KoBb2WyicTdookA297Daz81G1TsQoh4ou9/doc8kfzdAECAwEA
AaNwMG4wLAYDVR0RBCUwI4IJbG9jYWxob3N0hwR/AAABhxAAAAAAAAAAAAAAAAAA
AAABMB0GA1UdDgQWBBTCMy+a1aPNwrF3QYPIAIR4iDazWTAfBgNVHSMEGDAWgBRP
Ht2qgLZcjCnBbQxhxmyhcerO3DANBgkqhkiG9w0BAQsFAAOCAQEAPWBHmtiuPwFb
z0DIdTOA7VvFziMyJzW0EvI2AmB2wSViPGg5OFqVOLq5+H3OJsi5yTYJaUjNpr4A
UjpMweJJlMkqwsTt/kBKpPiUQbiN7Ja2+b3mmmMhEfyMUSebcfegLNvglABhJlmv
FOwniX8J1LJ8fzxAHfF32HwqxG6vxcZOsP661WqSnkyDSuoHo/jwB4MeCZiljc8h
F4MkcaIGouTtAGMvb8V6bGNz1iWgkQVpfYP9uqKGq8eBXzd+/033RmrnqorHjYiz
38C1Gf3lhbXBQqmMY3+aEhvjSCJrLCfjMV/twDTwRp8khrkG7C9yuEqmXtbTcF1e
/+rsiTEv9A==
-----END CERTIFICATE-----

View File

@@ -7,7 +7,6 @@ import type {
XapiXoRecord,
XoAuthenticationToken,
XoBackupRepository,
XoBrowserMediaSession,
XoConfigBackupArchive,
XoGroup,
XoHost,
@@ -23,7 +22,6 @@ import type {
XoSr,
XoTask,
XoUser,
XoVdi,
XoVif,
XoVm,
XoVmBackupArchive,
@@ -437,23 +435,6 @@ export type XoApp = EventEmitter & {
>
>
getAllSchedules(): Promise<XoSchedule[]>
/** Every browser media session, whoever owns it; empty when the feature is disabled */
getAllBrowserMediaSessions(): XoBrowserMediaSession[]
getBrowserMediaSession(id: XoBrowserMediaSession['id']): XoBrowserMediaSession
/**
* Insert the ISO of a browser media session in the CD drive of a VM. Undone by `ejectBrowserMedia`,
* or when the browser disconnects.
*
* `assertBrowserMediaInsertable` reports the predictable failures synchronously, e.g. before
* starting a task.
*/
insertBrowserMedia(params: {
id: XoBrowserMediaSession['id']
vmId: XoVm['id']
}): Promise<{ vdiId: XoVdi['id'] }>
assertBrowserMediaInsertable(params: { id: XoBrowserMediaSession['id']; vmId: XoVm['id'] }): void
/** Eject the ISO of a browser media session, release its storage, and disconnect the browser */
ejectBrowserMedia(id: XoBrowserMediaSession['id']): Promise<void>
getAllUsers(opts?: { obfuscatePassword?: boolean }): Promise<XoUser[]>
getAllXenServers(): Promise<XoServer[]>
getAuthenticationTokensForUser(userId: XoUser['id']): Promise<XoAuthenticationToken[]>

View File

@@ -515,68 +515,6 @@ export type XoPlugin =
| XoUsageReportPlugin
| XoWebHooksPlugin
/**
* An ISO selected in a browser and streamed from it, which can be inserted in the CD drive of a VM
* while the browser stays connected
*/
export type XoBrowserMediaSession = {
id: Branded<'browser-media'>
/** File name of the ISO, as selected in the browser */
name: string
/** Size of the ISO, in bytes */
size: number
/** User whose browser serves the ISO */
userId: XoUser['id']
/** Timestamp of the browser connection */
createdAt: number
/** Total of the bytes read from the browser */
bytesRead: number
/** Timestamp of the last read from the browser */
lastReadAt?: number
} & (
| {
/** Not inserted in any VM */
status: 'connected'
vmId?: undefined
vdiId?: undefined
insertedAt?: undefined
/** Why the last insertion failed */
error?: string
}
| {
/** Being inserted in a VM */
status: 'inserting'
/** VM the ISO is being inserted in */
vmId: XoVm['id']
vdiId?: undefined
insertedAt?: undefined
error?: undefined
}
| {
/** Inserted in the CD drive of a VM */
status: 'inserted'
/** VM the ISO is inserted in */
vmId: XoVm['id']
/** VDI inserted in the CD drive of the VM */
vdiId: XoVdi['id']
/** Timestamp of the end of the insertion */
insertedAt: number
error?: undefined
}
| {
/** Being ejected, or a failed insertion being undone */
status: 'ejecting'
/** VM the ISO is ejected from */
vmId: XoVm['id']
/** VDI inserted in the CD drive of the VM, unless the insertion failed before */
vdiId?: XoVdi['id']
/** Timestamp of the end of the insertion, unless it failed */
insertedAt?: number
/** Why the insertion failed */
error?: string
}
)
export type XoProxy = {
id: Branded<'proxy'>
url: string
@@ -825,7 +763,6 @@ export type XoTask = {
| 'backup-job'
| 'backup-log'
| 'backup-repository'
| 'browser-media'
| 'group'
| 'plugin'
| 'proxy'
@@ -1042,7 +979,6 @@ export type NonXapiXoRecord =
| AnyXoJob
| AnyXoLog
| XoAuthenticationToken
| XoBrowserMediaSession
| XoGroup
| XoPlugin
| XoProxy

View File

@@ -9,7 +9,6 @@
- [Treeview] Fix translations of the tooltip for VM and host statuses in treeview (PR [#10643](https://github.com/vatesfr/xen-orchestra/pull/10643))
- [Web-Core/UiDropdownButton] Update dropdown buttons design (PR [#9850](https://github.com/vatesfr/xen-orchestra/pull/9850))
- [Tables] Tables are filtered as you type, half a second after the last keystroke, or right away with Enter; the "Search" button is removed (PR [#10797](https://github.com/vatesfr/xen-orchestra/pull/10797))
- [Side panels] Fix the double scrollbar when the side panel content is taller than the screen: the page header now stays in place, and the list and the side panel each scroll on their own. All scrollbars are now thin, like the side panel one (PR [#10807](https://github.com/vatesfr/xen-orchestra/pull/10807))
## **0.27.0** (2026-10-29)

View File

@@ -94,8 +94,6 @@ useUnreachableHosts()
.main {
flex: 1;
overflow: auto;
display: flex;
flex-direction: column;
background-color: var(--color-neutral-background-secondary);
}
</style>

View File

@@ -7,9 +7,7 @@
</template>
</HostPifsTable>
</UiCard>
<template #panel>
<HostPifSidePanel :pif="selectedPif" @close="selectedPif = undefined" />
</template>
<HostPifSidePanel :pif="selectedPif" @close="selectedPif = undefined" />
</VtsContentSidePanel>
</template>

View File

@@ -3,15 +3,13 @@
<UiCard class="container">
<StorageRepositoriesTable v-if="pool && host && scope" :srs :pool :scope :busy="!isReady" :error="hasError" />
</UiCard>
<template #panel>
<StorageRepositorySidePanel
v-if="pool && host && scope"
:sr="selectedSr"
:pool
:scope
@close="selectedSr = undefined"
/>
</template>
<StorageRepositorySidePanel
v-if="pool && host && scope"
:sr="selectedSr"
:pool
:scope
@close="selectedSr = undefined"
/>
</VtsContentSidePanel>
</template>

View File

@@ -1,7 +1,10 @@
<template>
<PoolHeader />
<PoolTabBar />
<RouterView />
<div class="pool-root-view">
<PoolHeader />
<PoolTabBar />
<RouterView />
</div>
</template>
<script lang="ts" setup>

View File

@@ -3,9 +3,7 @@
<UiCard class="container">
<HostsTable :hosts :busy="!isReady" :error="hasError" />
</UiCard>
<template #panel>
<HostSidePanel :host="selectedHost" @close="selectedHost = undefined" />
</template>
<HostSidePanel :host="selectedHost" @close="selectedHost = undefined" />
</VtsContentSidePanel>
</template>

View File

@@ -28,9 +28,7 @@
</template>
</PoolHostInternalNetworksTable>
</UiCard>
<template #panel>
<PoolNetworkSidePanel :network="selectedNetwork" @close="selectedNetwork = undefined" />
</template>
<PoolNetworkSidePanel :network="selectedNetwork" @close="selectedNetwork = undefined" />
</VtsContentSidePanel>
</template>

View File

@@ -3,9 +3,7 @@
<UiCard class="container">
<StorageRepositoriesTable v-if="pool" :srs="sortedSrs" :pool :scope :busy="!isReady" :error="hasError" />
</UiCard>
<template #panel>
<StorageRepositorySidePanel v-if="pool" :sr="selectedSr" :pool :scope @close="selectedSr = undefined" />
</template>
<StorageRepositorySidePanel v-if="pool" :sr="selectedSr" :pool :scope @close="selectedSr = undefined" />
</VtsContentSidePanel>
</template>

View File

@@ -9,9 +9,7 @@
</template>
</VifsTable>
</UiCard>
<template #panel>
<VifSidePanel :vif="selectedVif" @close="selectedVif = undefined" />
</template>
<VifSidePanel :vif="selectedVif" @close="selectedVif = undefined" />
</VtsContentSidePanel>
</template>

View File

@@ -3,9 +3,7 @@
<UiCard class="container">
<VdisTable v-if="vm" :vdis :vbds />
</UiCard>
<template #panel>
<VdiSidePanel :vdi="selectedVdi" :vbd="selectedVbd" @close="selectedVdi = undefined" />
</template>
<VdiSidePanel :vdi="selectedVdi" :vbd="selectedVbd" @close="selectedVdi = undefined" />
</VtsContentSidePanel>
</template>

View File

@@ -137,7 +137,7 @@ configure(
Optional dependency:
```
> yarn add @vates/syslog
> yarn add split-host syslog-client
```
Configuration:
@@ -148,25 +148,10 @@ import transportSyslog from '@xen-orchestra/log/transports/syslog'
// By default, log to udp://localhost:514
configure(transportSyslog())
// But TCP, TLS, a different host, or a different port can be used
// But TCP, a different host, or a different port can be used
configure(transportSyslog({ target: 'tcp://syslog.company.lan' }))
configure(
transportSyslog({
target: 'tls://syslog.company.lan',
// paths to PEM files of certificate authorities to trust, in addition to the system ones
certificateAuthorities: ['/etc/ssl/certs/company-ca.pem'],
// other options of `@vates/syslog`'s `createClient()`
appName: 'my-app',
facility: 'local0',
})
)
```
The namespace of each log is used as message ID. Failures to send logs are reported on the console, not with the logger.
### Helpers
#### Dedupe

View File

@@ -155,7 +155,7 @@ configure(
Optional dependency:
```
> yarn add @vates/syslog
> yarn add split-host syslog-client
```
Configuration:
@@ -166,25 +166,10 @@ import transportSyslog from '@xen-orchestra/log/transports/syslog'
// By default, log to udp://localhost:514
configure(transportSyslog())
// But TCP, TLS, a different host, or a different port can be used
// But TCP, a different host, or a different port can be used
configure(transportSyslog({ target: 'tcp://syslog.company.lan' }))
configure(
transportSyslog({
target: 'tls://syslog.company.lan',
// paths to PEM files of certificate authorities to trust, in addition to the system ones
certificateAuthorities: ['/etc/ssl/certs/company-ca.pem'],
// other options of `@vates/syslog`'s `createClient()`
appName: 'my-app',
facility: 'local0',
})
)
```
The namespace of each log is used as message ID. Failures to send logs are reported on the console, not with the logger.
### Helpers
#### Dedupe

View File

@@ -39,15 +39,7 @@ function compileFilter(filter) {
throw new TypeError('unsupported `filter`')
}
// a transport can have a `close()` method to release its resources (e.g.
// connections) when it is replaced, wrapping transports must forward it
const closeTransport = transport => {
if (typeof transport.close === 'function') {
transport.close()
}
}
module.exports = exports = function createTransport(config) {
module.exports = function createTransport(config) {
if (typeof config === 'function') {
return config
}
@@ -55,13 +47,11 @@ module.exports = exports = function createTransport(config) {
if (Array.isArray(config)) {
const transports = config.map(createTransport)
const { length } = transports
const transport = function () {
return function () {
for (let i = 0; i < length; ++i) {
transports[i].apply(this, arguments)
}
}
transport.close = () => transports.forEach(closeTransport)
return transport
}
const { type } = config
@@ -90,10 +80,7 @@ module.exports = exports = function createTransport(config) {
return orig.apply(this, arguments)
}
}
transport.close = () => closeTransport(orig)
}
return transport
}
exports.closeTransport = closeTransport

View File

@@ -1,62 +0,0 @@
'use strict'
const assert = require('node:assert/strict')
const { describe, it } = require('node:test')
const createTransport = require('./_createTransport.js')
const { createCaptureTransport } = require('./capture.js')
const { configure } = require('./configure.js')
const { dedupe } = require('./dedupe.js')
function createClosable(logs = []) {
const transport = log => {
logs.push(log)
}
transport.nCloses = 0
transport.close = () => {
++transport.nCloses
}
return transport
}
describe('closing transports', () => {
it('closes the transports of a list, through filters, capture and dedupe', () => {
const a = createClosable()
const b = createClosable()
const transport = createCaptureTransport({
level: 'info',
transport: dedupe({ transport: [a, { filter: 'foo', transport: b }, () => {}] }),
})
transport.close()
assert.equal(a.nCloses, 1)
assert.equal(b.nCloses, 1)
})
it('flushes the hidden duplicates before closing', () => {
const logs = []
const transport = dedupe({ transport: createClosable(logs) })
const log = { level: 30, message: 'foo', namespace: 'ns', data: {} }
transport(log)
transport({ ...log })
transport({ ...log })
assert.equal(logs.length, 1)
transport.close()
assert.equal(logs.length, 2)
assert.equal(logs[1].data.nDuplicates, 2)
})
it('configure() closes the replaced transport', () => {
const first = createClosable()
configure({ transport: first })
assert.equal(first.nCloses, 0)
configure({ transport: createClosable() })
assert.equal(first.nCloses, 1)
})
it('supports transports without close()', () => {
createTransport([() => {}, { transport: () => {} }]).close()
})
})

View File

@@ -7,7 +7,6 @@
const { AsyncLocalStorage } = require('node:async_hooks')
const createTransport = require('./_createTransport.js')
const { closeTransport } = createTransport
// stored in the global context so that various versions of the library can interact.
const symbol = Symbol.for('@xen-orchestra/log/capture')
@@ -34,7 +33,7 @@ exports.captureLogs = function captureLogs(onLog, fn) {
exports.createCaptureTransport = function createCaptureTransport(fallback) {
fallback = fallback === undefined ? Function.prototype : createTransport(fallback)
function captureTransport(log) {
return function captureTransport(log) {
const onLog = asyncStorage.getStore()
if (onLog !== undefined) {
onLog(log, fallback)
@@ -42,6 +41,4 @@ exports.createCaptureTransport = function createCaptureTransport(fallback) {
fallback(log)
}
}
captureTransport.close = () => closeTransport(fallback)
return captureTransport
}

View File

@@ -2,7 +2,6 @@
const createConsoleTransport = require('./transports/console')
const createTransport = require('./_createTransport')
const { closeTransport } = createTransport
const { LEVELS, resolve } = require('./levels')
// ===================================================================
@@ -19,11 +18,8 @@ global[symbol] = createTransport({
transport: createConsoleTransport(),
})
// the previous transport is closed (e.g. its connections), once replaced
const configure = config => {
const previous = global[symbol]
global[symbol] = createTransport(config)
closeTransport(previous)
}
exports.configure = configure

View File

@@ -4,7 +4,6 @@ const isEqual = require('lodash/isEqual')
const Log = require('./_Log')
const createTransport = require('./_createTransport')
const { closeTransport } = createTransport
exports.dedupe = function createDedupe({ timeout = 600e3, transport }) {
transport = createTransport(transport)
@@ -23,7 +22,7 @@ exports.dedupe = function createDedupe({ timeout = 600e3, transport }) {
n = 0
}
function dedupeLog(log) {
return function dedupeLog(log) {
if (
log.level === prev.level &&
log.message === prev.message &&
@@ -43,11 +42,4 @@ exports.dedupe = function createDedupe({ timeout = 600e3, transport }) {
prev = log
return transport(log)
}
dedupeLog.close = () => {
if (n !== 0) {
flush()
}
closeTransport(transport)
}
return dedupeLog
}

View File

@@ -1,81 +1,51 @@
'use strict'
const { basename } = require('path')
const { readFileSync } = require('fs')
const fromCallback = require('promise-toolbox/fromCallback')
// eslint-disable-next-line n/no-extraneous-require
const { createClient } = require('@vates/syslog')
const splitHost = require('split-host')
// eslint-disable-next-line n/no-extraneous-require
const { createClient, Facility, Severity, Transport } = require('syslog-client')
const { LEVELS } = require('../levels')
const LEVELS = require('../levels')
// https://github.com/paulgrove/node-syslog-client#syslogseverity
const LEVEL_TO_SEVERITY = {
[LEVELS.FATAL]: 'critical',
[LEVELS.ERROR]: 'error',
[LEVELS.WARN]: 'warning',
[LEVELS.INFO]: 'informational',
[LEVELS.DEBUG]: 'debug',
[LEVELS.FATAL]: Severity.Critical,
[LEVELS.ERROR]: Severity.Error,
[LEVELS.WARN]: Severity.Warning,
[LEVELS.INFO]: Severity.Informational,
[LEVELS.DEBUG]: Severity.Debug,
}
// `config` is either the target or an object with:
// - `target`: `udp://host[:port]`, `tcp://host[:port]` or `tls://host[:port]`, UDP if there is no protocol
// - `certificateAuthorities`: paths to PEM files of certificate authorities to trust (TLS only)
// - the other options of `@vates/syslog`'s `createClient()`
function createTransport(config) {
if (typeof config !== 'object' || config === null) {
config = { target: config }
const facility = Facility.User
function createTransport(target) {
if (typeof target === 'object') {
target = target.target
}
// eslint-disable-next-line no-unused-vars
const { certificateAuthorities, target = 'localhost', type, ...opts } = config
// a single path instead of a list is an easy mistake in a TOML configuration
if (
certificateAuthorities !== undefined &&
!(Array.isArray(certificateAuthorities) && certificateAuthorities.every(path => typeof path === 'string'))
) {
throw new TypeError(
`syslog transport: certificateAuthorities must be a list of paths, e.g. certificateAuthorities = ['/etc/ssl/certs/company-ca.pem'], got ${JSON.stringify(certificateAuthorities)}`
)
}
const client = createClient(/^[a-z]+:\/\//.test(target) ? target : `udp://${target}`, {
// like the previous implementation
appName: basename(process.title),
ca:
certificateAuthorities === undefined ? undefined : certificateAuthorities.map(path => readFileSync(path, 'utf8')),
...opts,
})
// failures must not be logged with the logger, which would send them to this
// transport again, report the first one and the recovery on the console
let nFailures = 0
const onSent = () => {
if (nFailures !== 0) {
console.error('syslog transport: recovered after %d failure(s)', nFailures)
nFailures = 0
}
}
const onError = error => {
if (nFailures++ === 0) {
console.error(
'syslog transport: failed to send logs, next failures will not be reported until it recovers',
error
)
const opts = {}
if (target !== undefined) {
if (target.startsWith('tcp://')) {
target = target.slice(6)
opts.transport = Transport.Tcp
} else if (target.startsWith('udp://')) {
target = target.slice(6)
opts.transport = Transport.Udp
}
;({ host: target, port: opts.port } = splitHost(target))
}
const transport = log =>
client
.send(log.message, {
msgid: log.namespace,
const client = createClient(target, opts)
return log =>
fromCallback(cb =>
client.log(log.message, {
facility,
severity: LEVEL_TO_SEVERITY[log.level],
timestamp: log.time,
})
.then(onSent, onError)
// called by `configure()` when this transport is replaced
transport.close = () => client.close()
return transport
)
}
module.exports = exports = createTransport

View File

@@ -1,82 +0,0 @@
'use strict'
const assert = require('node:assert/strict')
const dgram = require('node:dgram')
const { describe, it } = require('node:test')
const net = require('node:net')
const createTransport = require('./syslog.js')
const Log = require('../_Log.js')
const { dedupe } = require('../dedupe.js')
describe('syslog transport', () => {
it('rejects certificateAuthorities which is not a list of paths', () => {
for (const certificateAuthorities of ['/etc/ssl/certs/ca.pem', { ca: '/etc/ssl/certs/ca.pem' }, [42]]) {
assert.throws(
() => createTransport({ target: 'tls://localhost', certificateAuthorities }),
/certificateAuthorities must be a list of paths, e\.g\. certificateAuthorities = \['/
)
}
})
it('closes its client', async () => {
const server = dgram.createSocket('udp4')
await new Promise(resolve => server.bind(0, '127.0.0.1', resolve))
const received = new Promise(resolve => server.once('message', resolve))
try {
const transport = createTransport(`udp://127.0.0.1:${server.address().port}`)
await transport({ level: 30, message: 'foo', namespace: 'ns', time: new Date() })
assert.match(String(await received), / ns - foo$/)
transport.close()
} finally {
server.close()
}
})
// the summary of the duplicates is sent when the transport is replaced, e.g.
// on a configuration change, and must not be lost by the closing client
describe('delivers the summary flushed by dedupe when closed', () => {
const logTwice = transport => {
const log = new Log(undefined, 30, 'ns', 'foo')
transport(log)
transport(log)
transport(log)
transport.close()
}
it('over UDP, while the host name is being resolved', async () => {
const server = dgram.createSocket('udp4')
await new Promise(resolve => server.bind(0, '127.0.0.1', resolve))
const messages = []
server.on('message', message => messages.push(String(message)))
try {
logTwice(dedupe({ transport: createTransport(`udp://localhost:${server.address().port}`) }))
await new Promise(resolve => setTimeout(resolve, 300))
// UDP doesn't guarantee message order
assert.equal(messages.length, 2)
assert.ok(messages.some(message => message.endsWith(' ns - foo')))
assert.ok(messages.some(message => message.endsWith(' ns - duplicates of the previous log were hidden')))
} finally {
server.close()
}
})
it('over TCP, while the connection is being established', async () => {
let data = ''
const server = net.createServer(socket => socket.on('data', chunk => (data += chunk)))
await new Promise(resolve => server.listen(0, '127.0.0.1', resolve))
try {
logTwice(dedupe({ transport: createTransport(`tcp://127.0.0.1:${server.address().port}`) }))
await new Promise(resolve => setTimeout(resolve, 300))
const lines = data.split('\n').filter(Boolean)
assert.equal(lines.length, 2)
assert.match(lines[1], /duplicates of the previous log were hidden$/)
} finally {
server.close()
}
})
})
})

View File

@@ -26,28 +26,3 @@ export function detectLocalAddress(host, port = 1) {
})
})
}
/**
* Every address `hostRef` may connect from: its management address, and the ones of its PIFs, a
* storage network included.
*
* @param {object} xapi
* @param {string} hostRef
* @param {string} [hostAddress] - its management address, if already known
* @returns {Promise<string[]>}
*/
export async function getHostAddresses(xapi, hostRef, hostAddress) {
const addresses = new Set([hostAddress ?? (await xapi.getField('host', hostRef, 'address'))])
for (const pifRef of await xapi.getField('host', hostRef, 'PIFs')) {
const { IP, IPv6 } = await xapi.getRecord('PIF', pifRef)
if (IP !== '') {
addresses.add(IP)
}
// with their prefix length, e.g. `fd00::1/64`, and canonicalized like the remote address of a
// socket, e.g. `fd00:0:0::1` becomes `fd00::1`
for (const address of IPv6) {
addresses.add(new URL(`http://[${address.split('/')[0]}]`).hostname.slice(1, -1))
}
}
return [...addresses]
}

View File

@@ -20,8 +20,7 @@ const defaultExec = (command, args) => execFileAsync(command, args, { timeout: E
// enabled by default, so it must stay out of the way of the installs it cannot apply to: rather
// than failing the mounts, no rule is opened, and whatever firewall there is decides
// iptables-legacy fails on the xtables lock before telling so
const NOT_ROOT_RE = /you must be root|can't open lock file .*: Permission denied/i
const NOT_ROOT_RE = /you must be root/i
// ufw not installed, or not enabled: it deletes its chains when stopped
const MISSING_CHAIN_RE = /No chain\/target\/match by that name|does not exist/i
// a rule already gone, dropped by any change made to ufw meanwhile

View File

@@ -99,13 +99,6 @@ describe('createUfwFirewall', () => {
'iptables v1.8.9 (nf_tables): Could not fetch rule set generation id: Permission denied (you must be root)\n',
}),
],
[
'iptables-legacy runs without root',
Object.assign(new Error('Command failed'), {
code: 4,
stderr: "Fatal: can't open lock file /run/xtables.lock: Permission denied\n",
}),
],
]) {
it(`opens nothing, without failing, when ${what}`, async () => {
const exec = async () => {

View File

@@ -2,7 +2,7 @@ import { randomUUID } from 'node:crypto'
import { asyncEach } from '@vates/async-each'
import { createLogger } from '@xen-orchestra/log'
import { OC_MOUNT } from './_utils.mjs'
import { cacheLabel, OC_MOUNT } from './_utils.mjs'
const { debug, info, warn } = createLogger('xo:mixins:LiveMount')
@@ -24,20 +24,17 @@ const IMAGE_FORMAT_RAW = 'raw'
* `SR.introduce`, not `SR.create`: create would scan, and a scan introduces the
* VDI itself with an sm_config we could no longer amend.
*/
export async function introduceSr(
$defer,
{ xapi, hostRef, deviceConfig, id, nameLabel, nameDescription, smConfig = {} }
) {
export async function introduceSr($defer, { xapi, hostRef, deviceConfig, id, nameLabel, diskPath }) {
const srUuid = randomUUID()
const srRef = await xapi.call(
'SR.introduce',
srUuid,
nameLabel ?? `[XO live mount] ${id.slice(0, 8)}`,
nameDescription,
`mount of ${diskPath}`,
SR_TYPE,
'user',
false, // not shared: this mount serves a single host
smConfig // set with the SR itself, so that the SR cannot exist without it
{}
)
$defer.onFailure(() => xapi.call('SR.forget', srRef))
@@ -86,16 +83,16 @@ export async function forgetSr(xapi, srRef) {
* `readOnly` states the intent, but this driver ignores it either way —
* `RAWVDI.introduce()` ends in `_db_introduce()`, which builds the record from
* the driver's own VDI object, the same reason the resulting uuid is not the
* one asked for. The LUN itself is what actually enforces it: a read-only
* `BlockDevice` is reported write-protected, and writes are refused.
* one asked for. The LUN itself is what actually enforces it: a read-only one
* advertises it to the guest, and refuses writes.
*/
export async function introduceVdi({ xapi, srRef, SCSIid, size, id, nameLabel, nameDescription, readOnly }) {
export async function introduceVdi({ xapi, srRef, SCSIid, size, diskPath, id, nameLabel, nameDescription, readOnly }) {
const uuid = randomUUID()
await xapi.call(
'VDI.introduce',
uuid,
nameLabel,
nameDescription,
nameLabel ?? `${cacheLabel(diskPath)}.raw`,
nameDescription ?? `mount of ${diskPath}`,
srRef,
'user',
false, // sharable
@@ -129,6 +126,6 @@ export async function introduceVdi({ xapi, srRef, SCSIid, size, id, nameLabel, n
await xapi.setFieldEntry('VDI', vdiRef, 'other_config', OC_MOUNT, id)
return vdi.uuid
}
warn('no VDI found for the introduced LUN', { SCSIid, srRef, nameLabel })
throw new Error(`no VDI found for the introduced LUN when trying to mount ${nameLabel}`)
warn('no VDI found for the introduced LUN', { SCSIid, srRef, diskPath })
throw new Error(`no VDI found for the introduced LUN when tryng to mount ${diskPath}`)
}

View File

@@ -49,7 +49,7 @@ export async function probeScsiId({ xapi, hostRef, deviceConfig, address }) {
} catch (error) {
if (error.code === PROBE_NO_TARGET_ERROR) {
const wrapped = new Error(
`the host cannot reach the iSCSI target at ${address}:${deviceConfig.port}, check iscsi.advertisedAddress and the firewalls between them, and set iscsi.restrictToHost = false if the host reaches this appliance through a NAT`
`the host cannot reach the iSCSI target at ${address}:${deviceConfig.port}, check iscsi.advertisedAddress and the firewalls between them`
)
wrapped.cause = error
throw wrapped

View File

@@ -7,30 +7,17 @@ import { openDiskChain } from '@xen-orchestra/backup-archive/disks'
import { noSuchObject } from 'xo-common/api-errors.js'
import { randomBytes } from 'node:crypto'
import { cacheLabel } from './_utils.mjs'
import { createCache } from './_cache.mjs'
import { detectLocalAddress, getHostAddresses } from './_address.mjs'
import { detectLocalAddress } from './_address.mjs'
import { createUfwFirewall } from './_firewall.mjs'
import { createChapCredentials, probeScsiId } from './_target.mjs'
import { forgetSr, introduceSr, introduceVdi } from './_sr.mjs'
import { cacheLabel } from './_utils.mjs'
const { info, warn } = createLogger('xo:mixins:LiveMount')
/** @typedef {import('@vates/types').Xapi} Xapi */
/**
* A block device served through an iSCSI target, as returned by {@link LiveMount#serveBlockDevice}.
*
* @typedef {object} ServedBlockDevice
* @property {string} id
* @property {string} address - address of the target, as handed to the host
* @property {number} port
* @property {string} iqn
* @property {Record<string, string>} deviceConfig - of an `iscsi` SR on this target, without `SCSIid`
* @property {Set<string>} refusedAddresses - connections refused by `iscsi.restrictToHost` came from these
* @property {() => Promise<void>} close - stops serving, and closes the firewall rule if any
*/
/**
* The XAPI names of what a mount creates, as the user sees them. Each one falls back to a name
* derived from the disk path.
@@ -42,28 +29,25 @@ const { info, warn } = createLogger('xo:mixins:LiveMount')
*/
/**
* A mount, as built by `#createMount`.
* A mount, as built by `#createDiskMount`.
*
* @typedef {object} DiskMount
* @property {string} id
* @property {string} address
* @property {number} port
* @property {string} iqn
* @property {string} [diskPath] - unset for a block device mounted by {@link LiveMount#mountBlockDevice}
* @property {string} diskPath
* @property {string} srRef
* @property {string} srUuid
* @property {string} vdiUuid
* @property {ServedBlockDevice} served
* @property {import('@vates/iscsi').IscsiTarget} target
* @property {Xapi} xapi - replaced by any newer connection to the same pool, see {@link LiveMount#watchConnection}
* @property {string} [poolUuid] - pool of `xapi`, unknown if it was not connected
* @property {{ device: object, lun: object, poolUuid?: string, vbdRef: string, vdiRef: string, xapi: Xapi }} [cache] - local VDI the disk is materialized into, in the pool running this appliance; its `xapi` is replaced like the mount's one
* @property {{ source: string, port: number, id: string }} [firewallRule] - opened by `iscsi.manageFirewall`
* @property {() => Promise<void>} [release]
* @property {() => Promise<void>} [beforeUnmount]
*/
// names the IQN and the LUN serial of the targets serving a backup disk
const DEFAULT_KIND = 'live-mount'
// the firewalls `iscsi.manageFirewall` can drive
const FIREWALLS = {
ufw: createUfwFirewall,
@@ -225,7 +209,21 @@ export default class LiveMount extends EventEmitter {
* holds the cache SR; defaults to `xapi`, when this appliance runs in the pool of the target host
* @returns {Promise<{ id: string, srUuid: string, vdiUuid: string, iqn: string, address: string, port: number }>}
*/
mountDisk = defer(async ($defer, params) => {
async mountDisk(params) {
const mount = await this.#createDiskMount(params)
this.#mounts.set(mount.id, mount)
this.#watchVdi(mount)
return {
id: mount.id,
srUuid: mount.srUuid,
vdiUuid: mount.vdiUuid,
iqn: mount.iqn,
address: mount.address,
port: mount.port,
}
}
#createDiskMount = defer(async ($defer, params) => {
const { cacheSrUuid, diskPath, handler, hostRef, release, vmUuid, xapi, xapiLabels = {} } = params
const { cacheXapi = xapi } = params
if (this.#firewallError !== undefined) {
@@ -234,8 +232,23 @@ export default class LiveMount extends EventEmitter {
if (cacheSrUuid !== undefined && vmUuid === undefined) {
throw new Error('vmUuid is required to create a live mount cache')
}
// the cache is named after the mount, before its target exists
const config = this.#app.config
// `iscsi.advertisedAddress` overrides auto-detection; unset, the address
// reachable *from* the target host is guessed by asking the OS which
// local address it would route through to reach it — usually right, but
// not guaranteed to be reachable *back* from the host (NAT, asymmetric
// routing), which is what the override is for.
const firewall = this.#firewall
let address = config.getOptional('iscsi.advertisedAddress')
const hostAddress =
address === undefined || firewall !== undefined ? await xapi.getField('host', hostRef, 'address') : undefined
if (address === undefined) {
address = await this.#detectAddress(hostAddress)
}
const id = randomBytes(16).toString('hex')
const iqn = `iqn.2026-07.tech.vates.xo:live-mount-${id}`
const chap = createChapCredentials(id)
// the chain must keep its block allocation tables: they tell which blocks
// are allocated, and reading an unallocated one throws
@@ -262,258 +275,85 @@ export default class LiveMount extends EventEmitter {
cache = { device, lun, poolUuid: cacheXapi.pool?.uuid, vbdRef, vdiRef, xapi: cacheXapi }
}
return this.#mount({
cache,
diskPath,
hostRef,
id,
const target = this.#createTarget({
chap,
host: config.getOptional('iscsi.bindAddress'),
identity: { serial: `xo-live-mount-${id}` },
iqn,
lun,
// a cached disk is writable: `lun.readOnly` makes its VDI read/write
nameDescription: xapiLabels.vdiNameDescription ?? `mount of ${diskPath}`,
nameLabel: xapiLabels.srNameLabel,
release,
vdiNameLabel: xapiLabels.vdiNameLabel ?? `${cacheLabel(diskPath)}.raw`,
xapi,
port: 0, // ephemeral: one target per mount
})
})
// opens the LUN, so its capacity is readable afterwards
await target.listen()
$defer.onFailure(() => target.close())
const { port } = target.address()
/**
* Like {@link LiveMount#mountDisk}, for any block device: serve it and attach it to a host as an
* SR holding a single VDI. Undone by {@link LiveMount#unmountBlockDevice}.
*
* The LUN is closed with the target. Its `readOnly` flag decides whether the VDI is read-only.
*
* @param {object} params
* @param {import('@vates/iscsi').BlockDevice} params.lun
* @param {object} params.xapi - XAPI connection of the pool owning `hostRef`
* @param {string} params.hostRef - opaque ref of the host the device is attached to as an SR
* @param {string} params.kind - names the IQN and the serial of the LUN, e.g. `browser-media`
* @param {string} params.nameLabel - name of the created SR and VDI
* @param {string} params.nameDescription - description of the created SR and VDI
* @param {Record<string, string>} [params.smConfig] - `sm_config` of the SR, set when it is introduced
* @param {Partial<import('@vates/iscsi').IscsiTargetOptions>} [params.targetOptions] - e.g. `maxTransferLength`
* @param {() => Promise<void>} [params.beforeUnmount] - called first on unmount, whatever triggers it,
* e.g. to eject the VDI while the target can still answer the host: if it fails, the device stays
* mounted, and the unmount can be retried
* @param {() => Promise<void>} [params.release] - called on unmount, once the target is closed
* @returns {Promise<{ id: string, srUuid: string, vdiUuid: string, iqn: string, address: string, port: number }>}
*/
async mountBlockDevice({ nameLabel, ...params }) {
if (this.#firewallError !== undefined) {
throw this.#firewallError
// scoped to the host's management address: the one the advertised address is detected from,
// so the one it connects from — unless `iscsi.advertisedAddress` points at another network
let firewallRule
if (firewall !== undefined) {
await this.#purgeFirewall()
const rule = { source: hostAddress, port, id }
// none opened when there is no firewall to drive on this install: nothing to close then
if (await firewall.open(rule)) {
firewallRule = rule
$defer.onFailure(() => firewall.close(rule))
}
}
return this.#mount({ ...params, nameLabel, vdiNameLabel: nameLabel })
}
async #mount(params) {
const mount = await this.#createMount(params)
this.#mounts.set(mount.id, mount)
this.#watchVdi(mount)
const deviceConfig = {
chapuser: chap.user,
chappassword: chap.secret,
port: String(port),
target: address,
targetIQN: iqn,
}
const SCSIid = await probeScsiId({ xapi, hostRef, deviceConfig, address })
const fullDeviceConfig = { ...deviceConfig, SCSIid }
const { srRef, srUuid } = await introduceSr($defer, {
xapi,
hostRef,
deviceConfig: fullDeviceConfig,
id,
nameLabel: xapiLabels.srNameLabel,
diskPath,
})
const vdiUuid = await introduceVdi({
xapi,
srRef,
SCSIid,
size: lun.getSize(),
diskPath,
id,
nameLabel: xapiLabels.vdiNameLabel,
nameDescription: xapiLabels.vdiNameDescription,
readOnly: cache === undefined,
})
info('mounted', { id, address, port, srUuid, vdiUuid, diskPath, cached: cache !== undefined })
const poolUuid = xapi.pool?.uuid
return {
id: mount.id,
srUuid: mount.srUuid,
vdiUuid: mount.vdiUuid,
iqn: mount.iqn,
address: mount.address,
port: mount.port,
address,
cache,
disk,
diskPath,
firewallRule,
id,
iqn,
poolUuid,
port,
release,
srRef,
srUuid,
target,
vdiUuid,
xapi,
}
}
/**
* Serve `lun` through a new iSCSI target, for `hostRef` to attach it: the target listens on an
* ephemeral port, requires CHAP, and only accepts connections from the addresses of the host,
* unless `iscsi.restrictToHost` is `false`. With `iscsi.manageFirewall`, its port is opened to
* the host until it is closed.
*
* `id`, `chap` and `port` serve a target again under the identity of a previous one, e.g. so that
* a host still logged in to a target that went away can complete its I/O and detach cleanly.
*
* @param {object} params
* @param {import('@vates/iscsi').BlockDevice} params.lun - closed with the target
* @param {object} params.xapi - XAPI connection of the pool owning `hostRef`
* @param {string} params.hostRef - opaque ref of the host the target is meant for
* @param {string} [params.kind] - names the IQN and the serial of the LUN, defaults to `live-mount`
* @param {string} [params.id] - random by default
* @param {{ user: string, secret: string }} [params.chap] - random by default
* @param {number} [params.port] - ephemeral by default
* @param {Partial<import('@vates/iscsi').IscsiTargetOptions>} [params.targetOptions]
* @returns {Promise<ServedBlockDevice>}
*/
serveBlockDevice = defer(
async (
$defer,
{
lun,
xapi,
hostRef,
kind = DEFAULT_KIND,
id = randomBytes(16).toString('hex'),
chap = createChapCredentials(id),
port: requestedPort = 0,
targetOptions,
}
) => {
if (this.#firewallError !== undefined) {
throw this.#firewallError
}
const config = this.#app.config
// `iscsi.advertisedAddress` overrides auto-detection; unset, the address
// reachable *from* the target host is guessed by asking the OS which
// local address it would route through to reach it — usually right, but
// not guaranteed to be reachable *back* from the host (NAT, asymmetric
// routing), which is what the override is for.
const hostAddress = await xapi.getField('host', hostRef, 'address')
const address = config.getOptional('iscsi.advertisedAddress') ?? (await this.#detectAddress(hostAddress))
// the host is the only expected initiator: nothing else may take the connection slots of the
// target, which only CHAP would keep from logging in otherwise. Behind a NAT, the host connects
// from another address, which is what `iscsi.restrictToHost = false` is for
const allowedInitiatorAddresses =
config.getOptional('iscsi.restrictToHost') === false
? undefined
: await getHostAddresses(xapi, hostRef, hostAddress)
// what the host connected from instead, to tell why it cannot reach the target
const refusedAddresses = new Set()
const iqn = `iqn.2026-07.tech.vates.xo:${kind}-${id}`
const target = this.#createTarget({
...targetOptions,
allowedInitiatorAddresses,
onConnectionRefused: address => refusedAddresses.add(address),
chap,
host: config.getOptional('iscsi.bindAddress'),
identity: { serial: `xo-${kind}-${id}` },
iqn,
lun,
port: requestedPort,
})
// opens the LUN, so its capacity is readable afterwards
await target.listen()
$defer.onFailure(() => target.close())
const { port } = target.address()
// scoped to the host's management address: the one the advertised address is detected from,
// so the one it connects from — unless `iscsi.advertisedAddress` points at another network
const firewall = this.#firewall
let firewallRule
if (firewall !== undefined) {
await this.#purgeFirewall()
const rule = { source: hostAddress, port, id }
// none opened when there is no firewall to drive on this install: nothing to close then
if (await firewall.open(rule)) {
firewallRule = rule
$defer.onFailure(() => firewall.close(rule))
}
}
return {
address,
deviceConfig: {
chapuser: chap.user,
chappassword: chap.secret,
port: String(port),
target: address,
targetIQN: iqn,
},
id,
iqn,
port,
refusedAddresses,
close: async () => {
// stop serving first, so no I/O is left in flight
try {
await target.close()
} finally {
if (firewallRule !== undefined) {
await firewall.close(firewallRule)
}
}
},
}
}
)
#createMount = defer(
async (
$defer,
{
lun,
xapi,
hostRef,
kind,
id: requestedId,
cache,
nameLabel,
nameDescription,
vdiNameLabel,
smConfig,
targetOptions,
diskPath,
beforeUnmount,
release,
}
) => {
const served = await this.serveBlockDevice({ lun, xapi, hostRef, kind, id: requestedId, targetOptions })
$defer.onFailure(() => served.close())
const { address, deviceConfig, id, iqn, port } = served
let SCSIid
try {
SCSIid = await probeScsiId({ xapi, hostRef, deviceConfig, address })
} catch (error) {
const [refused] = served.refusedAddresses
if (refused === undefined) {
throw error
}
throw new Error(
`the host connected to the iSCSI target from ${refused}, which is not one of its addresses, e.g. through a NAT: set iscsi.restrictToHost = false`,
{ cause: error }
)
}
const fullDeviceConfig = { ...deviceConfig, SCSIid }
const { srRef, srUuid } = await introduceSr($defer, {
xapi,
hostRef,
deviceConfig: fullDeviceConfig,
id,
nameLabel,
nameDescription,
smConfig,
})
const vdiUuid = await introduceVdi({
xapi,
srRef,
SCSIid,
size: lun.getSize(),
id,
nameLabel: vdiNameLabel,
nameDescription,
readOnly: lun.readOnly === true,
})
info('mounted', { id, address, port, srUuid, vdiUuid, diskPath, cached: cache !== undefined })
const poolUuid = xapi.pool?.uuid
return {
address,
beforeUnmount,
cache,
diskPath,
id,
iqn,
poolUuid,
port,
release,
served,
srRef,
srUuid,
vdiUuid,
xapi,
}
}
)
})
/**
* Tear a mount down as soon as its VDI disappears from the pool.
@@ -602,7 +442,8 @@ export default class LiveMount extends EventEmitter {
return
}
// a VDI is removed once and for all, and a mount introduces exactly one: nothing else will ever
// come for this uuid. Still watched until the unmount goes through, which stops watching it
// come for this uuid
this.#mountIdsByVdiUuid.delete(uuid)
info('the live mounted VDI was removed, unmounting', { id: mountId, vdiUuid: uuid })
this.unmountDisk(mountId).catch(error => {
warn('failed to unmount after the VDI was removed', { error, id: mountId })
@@ -627,19 +468,6 @@ export default class LiveMount extends EventEmitter {
// a coded error, so a remote caller (XO driving a proxy) can tell it apart from a failed call
noSuchObject(id, 'live-mount')
}
// the stop hook, a removed VDI and the owner of the mount may all unmount it at once: they share
// the same unmount
mount.unmounting ??= this.#unmount(id, mount).finally(() => {
mount.unmounting = undefined
})
return mount.unmounting
}
async #unmount(id, mount) {
if (mount.beforeUnmount !== undefined) {
// nothing is released yet: on failure, the mount stays as it is, so the unmount can be retried
await mount.beforeUnmount()
}
// drop it first, so a failing teardown cannot be retried against a
// half-released mount
this.#mounts.delete(id)
@@ -647,7 +475,7 @@ export default class LiveMount extends EventEmitter {
// not the deletion this mixin reacts to
this.#unwatchVdi(mount)
const { cache, xapi, srRef, served, release } = mount
const { cache, firewallRule, xapi, srRef, target, release } = mount
const errors = []
const step = async (what, fn) => {
@@ -660,7 +488,11 @@ export default class LiveMount extends EventEmitter {
}
await step('forget the SR', () => forgetSr(xapi, srRef))
await step('stop serving', () => served.close())
// stop serving first, so no I/O is left in flight
await step('close the target', () => target.close())
if (firewallRule !== undefined) {
await step('close the firewall rule', () => this.#firewall.close(firewallRule))
}
if (cache !== undefined) {
// already closed by the target, which owns the LUN — unless closing the target failed before
// getting there, and an open descriptor would then block the unplug and leak the VDI
@@ -687,28 +519,17 @@ export default class LiveMount extends EventEmitter {
info('unmounted', { id, srUuid: mount.srUuid })
}
/**
* Detach a block device mounted by {@link LiveMount#mountBlockDevice} and stop serving it.
*
* @param {string} id
*/
unmountBlockDevice(id) {
return this.unmountDisk(id)
}
/** Live disk mounts, in creation order, without the other block devices; a cached one also reports how much of the disk is local. */
/** Live disk mounts, in creation order; a cached one also reports how much of the disk is local. */
listMountedDisks() {
return [...this.#mounts.values()]
.filter(mount => mount.diskPath !== undefined)
.map(({ id, srUuid, vdiUuid, diskPath, iqn, address, port, cache }) => ({
id,
srUuid,
vdiUuid,
diskPath,
iqn,
address,
port,
cache: cache?.lun.getMaterialized(),
}))
return [...this.#mounts.values()].map(({ id, srUuid, vdiUuid, diskPath, iqn, address, port, cache }) => ({
id,
srUuid,
vdiUuid,
diskPath,
iqn,
address,
port,
cache: cache?.lun.getMaterialized(),
}))
}
}

View File

@@ -138,9 +138,6 @@ const makeXapi = ({
if (type === 'host' && field === 'address') {
return '10.20.30.40' // the host's own management address, as XAPI reports it
}
if (type === 'host' && field === 'PIFs') {
return ['OpaqueRef:pif-management', 'OpaqueRef:pif-storage']
}
return 'sr-uuid'
},
// `@xen-orchestra/xapi` exposes these as methods, not as `call()`s, so they need their own
@@ -177,11 +174,6 @@ const makeXapi = ({
},
async getRecord(type, ref) {
calls.push(['getRecord', type, ref])
if (type === 'PIF') {
return ref === 'OpaqueRef:pif-management'
? { IP: '10.20.30.40', IPv6: ['fd00::40/64'] }
: { IP: '10.99.0.40', IPv6: [] }
}
// the driver derives the VDI uuid from the LUN serial, so it differs from
// the one we asked for
return { uuid: nVdis > 1 ? `vdi-uuid-${nVdis}` : 'vdi-uuid', sm_config: vdiSmConfig ?? { SCSIid: SCSI_ID } }
@@ -218,7 +210,6 @@ const makeMixin = ({
listenError,
advertisedAddress = '192.168.1.8',
manageFirewall,
restrictToHost,
firewall = makeFirewall(),
// thrown by the successive opens of the cache device, in order
cacheDeviceOpenErrors = [],
@@ -238,9 +229,6 @@ const makeMixin = ({
if (path === 'iscsi.manageFirewall') {
return manageFirewall
}
if (path === 'iscsi.restrictToHost') {
return restrictToHost
}
assert.equal(path, 'iscsi.bindAddress', `unexpected config key ${path}`)
return config[path]
},
@@ -493,218 +481,6 @@ describe('mountDisk', () => {
})
})
describe('serveBlockDevice', () => {
const lun = { open: async () => {}, getSize: () => 1024 * 1024, getBlockSize: () => 512 }
it('only accepts the addresses of the host, storage networks included', async () => {
const { mixin, target } = makeMixin()
await mixin.serveBlockDevice({ lun, xapi: makeXapi(), hostRef: HOST_REF })
assert.deepEqual(target.options.allowedInitiatorAddresses, ['10.20.30.40', 'fd00::40', '10.99.0.40'])
})
it('names the address the host connected from when the probe fails because of it', async () => {
const { mixin, target } = makeMixin()
const xapi = makeXapi({ probeError: new XapiError('SR_BACKEND_FAILURE_141', []) })
const listen = target.listen
target.listen = async () => {
await listen()
// the host connects through a NAT
target.options.onConnectionRefused('192.168.1.254')
}
await assert.rejects(
mixin.mountBlockDevice({ lun, xapi, hostRef: HOST_REF, kind: 'test', nameLabel: 'x', nameDescription: '' }),
/from 192\.168\.1\.254, which is not one of its addresses.*restrictToHost = false/
)
})
it('accepts any address when iscsi.restrictToHost is false, e.g. behind a NAT', async () => {
const { mixin, target } = makeMixin({ restrictToHost: false })
await mixin.serveBlockDevice({ lun, xapi: makeXapi(), hostRef: HOST_REF })
assert.equal(target.options.allowedInitiatorAddresses, undefined)
})
it('serves again under the identity of a previous target', async () => {
const { mixin, target } = makeMixin()
const chap = { user: 'xo-cafebabe', secret: '0123456789abcdef' }
const served = await mixin.serveBlockDevice({
lun,
xapi: makeXapi(),
hostRef: HOST_REF,
kind: 'browser-media',
id: 'cafebabe',
chap,
port: 45678,
})
assert.equal(target.options.port, 45678)
assert.equal(target.options.chap, chap)
assert.equal(target.options.iqn, 'iqn.2026-07.tech.vates.xo:browser-media-cafebabe')
assert.equal(served.iqn, target.options.iqn)
assert.deepEqual(served.deviceConfig, {
chapuser: chap.user,
chappassword: chap.secret,
port: '34567', // as the target reports it
target: '192.168.1.8',
targetIQN: served.iqn,
})
await served.close()
assert.equal(target.closed, true)
})
it('closes the firewall rule with the target', async () => {
const firewall = makeFirewall()
const { mixin } = makeMixin({ manageFirewall: 'ufw', firewall })
const served = await mixin.serveBlockDevice({ lun, xapi: makeXapi(), hostRef: HOST_REF, id: 'cafebabe' })
await served.close()
const rule = { source: '10.20.30.40', port: 34567, id: 'cafebabe' }
assert.deepEqual(
firewall.calls.filter(([method]) => method !== 'purge'),
[
['open', rule],
['close', rule],
]
)
})
})
describe('mountBlockDevice', () => {
const makeLun = ({ readOnly } = {}) => ({
closed: false,
readOnly,
open: async () => {},
getSize: () => 790626304,
getBlockSize: () => 512,
})
it('names the target, the SR and the VDI after the caller, and follows the read-only flag of the LUN', async () => {
const { mixin, target } = makeMixin()
const xapi = makeXapi()
let released = false
const result = await mixin.mountBlockDevice({
lun: makeLun({ readOnly: true }),
xapi,
hostRef: HOST_REF,
kind: 'browser-media',
nameLabel: 'debian-13.5.0-amd64-netinst.iso',
nameDescription: 'streamed from a browser',
smConfig: { 'xo:browser-media': 'session-id' },
targetOptions: { maxTransferLength: 1024 * 1024 },
release: async () => {
released = true
},
})
assert.match(result.iqn, /^iqn\.2026-07\.tech\.vates\.xo:browser-media-[0-9a-f]{32}$/)
assert.equal(target.options.identity.serial, `xo-browser-media-${result.id}`)
assert.equal(target.options.maxTransferLength, 1024 * 1024)
const srIntroduce = xapi.calls.find(([method]) => method === 'SR.introduce')
assert.equal(srIntroduce[2], 'debian-13.5.0-amd64-netinst.iso')
assert.equal(srIntroduce[3], 'streamed from a browser')
const vdiIntroduce = xapi.calls.find(([method]) => method === 'VDI.introduce')
assert.equal(vdiIntroduce[2], 'debian-13.5.0-amd64-netinst.iso')
assert.equal(vdiIntroduce[3], 'streamed from a browser')
assert.equal(vdiIntroduce[7], true) // read_only
assert.equal(vdiIntroduce[13], 790626304)
assert.deepEqual(srIntroduce[7], { 'xo:browser-media': 'session-id' }) // sm_config, set atomically
await mixin.unmountBlockDevice(result.id)
assert.equal(target.closed, true)
assert.equal(released, true)
assert.ok(xapi.calls.some(([method]) => method === 'SR.forget'))
})
it('calls beforeUnmount before forgetting the SR, and keeps the mount when it fails', async () => {
const { mixin, target } = makeMixin()
const xapi = makeXapi()
let failing = true
const order = []
const { id } = await mixin.mountBlockDevice({
lun: makeLun({ readOnly: true }),
xapi,
hostRef: HOST_REF,
kind: 'browser-media',
nameLabel: 'iso',
nameDescription: '',
beforeUnmount: async () => {
order.push(['beforeUnmount', xapi.calls.some(([method]) => method === 'SR.forget')])
if (failing) {
throw new Error('VBD.eject failed')
}
},
})
await assert.rejects(mixin.unmountBlockDevice(id), /VBD\.eject failed/)
// nothing released: forgetting the SR now could leave the host with a datapath on it
assert.ok(!xapi.calls.some(([method]) => method === 'SR.forget'))
assert.equal(target.closed, false)
// a block device is not a disk
assert.deepEqual(mixin.listMountedDisks(), [])
failing = false
await mixin.unmountBlockDevice(id)
assert.deepEqual(order, [
['beforeUnmount', false],
['beforeUnmount', false],
])
assert.ok(xapi.calls.some(([method]) => method === 'SR.forget'))
assert.equal(target.closed, true)
assert.deepEqual(mixin.listMountedDisks(), [])
})
it('shares a single unmount between concurrent callers, e.g. the stop hook and the owner', async () => {
const { mixin } = makeMixin()
const xapi = makeXapi()
let nBeforeUnmount = 0
const { id } = await mixin.mountBlockDevice({
lun: makeLun({ readOnly: true }),
xapi,
hostRef: HOST_REF,
kind: 'browser-media',
nameLabel: 'iso',
nameDescription: '',
beforeUnmount: async () => {
++nBeforeUnmount
await new Promise(resolve => setTimeout(resolve, 10))
},
})
let nUnmounted = 0
mixin.on('unmounted', () => ++nUnmounted)
await Promise.all([mixin.unmountBlockDevice(id), mixin.unmountBlockDevice(id)])
assert.equal(nBeforeUnmount, 1)
assert.equal(nUnmounted, 1)
assert.equal(xapi.calls.filter(([method]) => method === 'SR.forget').length, 1)
})
it('introduces a writable VDI for a writable LUN', async () => {
const { mixin } = makeMixin()
const xapi = makeXapi()
await mixin.mountBlockDevice({
lun: makeLun(),
xapi,
hostRef: HOST_REF,
kind: 'test',
nameLabel: 'disk',
nameDescription: '',
})
assert.equal(xapi.calls.find(([method]) => method === 'VDI.introduce')[7], false)
})
})
describe('unmountDisk', () => {
it('unplugs, forgets, closes the target and releases the caller resources', async () => {
const { mixin, target } = makeMixin()

View File

@@ -73,12 +73,6 @@ port = 443
# in. Set to `false` to leave the firewall of this proxy alone.
manageFirewall = 'ufw'
# The iSCSI target of each mount only accepts connections from the addresses of
# the host it is attached to (its management address and the ones of its PIFs),
# so that nothing else can occupy its connection slots. Set to `false` when the
# hosts reach this proxy through a NAT, which hides their own addresses.
#restrictToHost = true
[logs]
# Display all logs matching this filter, regardless of their level
#filter = 'xo:backups:*'

View File

@@ -1,123 +0,0 @@
import {
Example,
Extension,
Get,
Path,
Post,
Query,
Request,
Response,
Route,
Security,
SuccessResponse,
Tags,
} from 'tsoa'
import { inject } from 'inversify'
import { provide } from 'inversify-binding-decorators'
import type { Request as ExRequest } from 'express'
import type { XoBrowserMediaSession } from '@vates/types'
import {
asynchronousActionResp,
badRequestResp,
noContentResp,
notFoundResp,
unauthorizedResp,
type Unbrand,
} from '../open-api/common/response.common.mjs'
import {
browserMedia,
browserMediaIds,
partialBrowserMedia,
} from '../open-api/oa-examples/browser-media.oa-example.mjs'
import { taskLocation } from '../open-api/oa-examples/task.oa-example.mjs'
import type { SendObjects } from '../helpers/helper.type.mjs'
import { XoController } from '../abstract-classes/xo-controller.mjs'
import type { CreateActionReturnType } from '../abstract-classes/base-controller.mjs'
import { RestApi } from '../rest-api/rest-api.mjs'
/**
* An ISO selected in a browser, which serves it over a WebSocket: see `POST /vms/{id}/actions/insert_browser_iso`.
*
* Experimental, restricted to administrators.
*/
@Route('browser-media')
@Security('*')
@Response(badRequestResp.status, badRequestResp.description)
@Response(unauthorizedResp.status, unauthorizedResp.description)
@Tags('browser-media')
@provide(BrowserMediaController)
export class BrowserMediaController extends XoController<XoBrowserMediaSession> {
constructor(@inject(RestApi) restApi: RestApi) {
super('browser-media', restApi)
}
// --- abstract methods
async getAllCollectionObjects(): Promise<XoBrowserMediaSession[]> {
return this.restApi.xoApp.getAllBrowserMediaSessions()
}
async getCollectionObject(id: XoBrowserMediaSession['id']): Promise<XoBrowserMediaSession> {
return this.restApi.xoApp.getBrowserMediaSession(id)
}
/**
* Restricted to administrators.
*
* Every browser media session, whoever owns it.
*
* @example fields "name,status,vmId"
* @example filter "status:inserted"
* @example limit 42
*/
@Example(browserMediaIds)
@Example(partialBrowserMedia)
@Extension('x-mcp-exposure', 'allow')
@Get('')
async getBrowserMediaSessions(
@Request() req: ExRequest,
@Query() fields?: string,
@Query() ndjson?: boolean,
@Query() markdown?: boolean,
@Query() filter?: string,
@Query() limit?: number
): Promise<SendObjects<Partial<Unbrand<XoBrowserMediaSession>>>> {
return this.sendObjects(Object.values(await this.getObjects({ filter })), req, { limit })
}
/**
* Restricted to administrators.
*
* @example id "3f1d0c9e8b7a6f5e4d3c2b1a09f8e7d6"
*/
@Example(browserMedia)
@Extension('x-mcp-exposure', 'allow')
@Get('{id}')
@Response(notFoundResp.status, notFoundResp.description)
getBrowserMediaSession(@Path() id: string): Promise<Unbrand<XoBrowserMediaSession>> {
return this.getObject(id as XoBrowserMediaSession['id'])
}
/**
* Restricted to administrators.
*
* Eject the ISO if it is inserted, release its storage, and disconnect the browser serving it.
*
* @example id "3f1d0c9e8b7a6f5e4d3c2b1a09f8e7d6"
*/
@Example(taskLocation)
@Extension('x-mcp-exposure', 'confirm')
@Post('{id}/actions/eject')
@SuccessResponse(asynchronousActionResp.status, asynchronousActionResp.description)
@Response(noContentResp.status, noContentResp.description)
@Response(notFoundResp.status, notFoundResp.description)
ejectBrowserMedia(@Path() id: string, @Query() sync?: boolean): CreateActionReturnType<void> {
const sessionId = id as XoBrowserMediaSession['id']
const { vmId } = this.restApi.xoApp.getBrowserMediaSession(sessionId)
return this.createAction<void>(() => this.restApi.xoApp.ejectBrowserMedia(sessionId), {
sync,
statusCode: noContentResp.status,
taskProperties: { name: 'eject browser media', objectId: sessionId, params: { vmId } },
})
}
}

View File

@@ -1,23 +0,0 @@
export const browserMediaIds = ['/rest/v0/browser-media/3f1d0c9e8b7a6f5e4d3c2b1a09f8e7d6']
export const partialBrowserMedia = [
{
name: 'debian-13.5.0-amd64-netinst.iso',
status: 'inserted',
href: '/rest/v0/browser-media/3f1d0c9e8b7a6f5e4d3c2b1a09f8e7d6',
},
]
export const browserMedia = {
id: '3f1d0c9e8b7a6f5e4d3c2b1a09f8e7d6',
name: 'debian-13.5.0-amd64-netinst.iso',
size: 790626304,
userId: '722d17b9-699b-49d2-8193-be1ac573d3de',
status: 'inserted',
createdAt: 1791699889013,
bytesRead: 24150016,
lastReadAt: 1791699920635,
vmId: '613f541c-4bed-fc77-7ca8-2db6b68f079c',
vdiId: '49d1f713-059d-4aa0-02ec-6c92eaff0a5c',
insertedAt: 1791699912916,
}

View File

@@ -26,7 +26,6 @@ import type {
XapiVmStats,
XenApiVm,
XoAlarm,
XoBrowserMediaSession,
XoVmBackupJob,
XoHost,
XoTask,
@@ -748,67 +747,6 @@ export class VmController extends XapiXoController<XoVm> {
})
}
/**
* Experimental, restricted to administrators.
*
* Insert an ISO streamed from a browser in the CD drive of the VM: nothing is uploaded, and nothing is installed on
* the hosts. The ISO stays inserted for as long as the browser serving it stays connected, and is read: then it is
* ejected, see `POST /browser-media/{id}/actions/eject`. Meanwhile, the VM cannot migrate nor be suspended.
*
* The VM must be halted, or running with an empty CD drive. A halted VM without CD drive gets a bootable one, which
* is removed with the ISO if the VM is halted by then, and is otherwise left empty. A VM protected by HA is refused,
* since the ISO is attached to a single host.
*
* The browser serves the ISO over a WebSocket to `/api/browser-media`, authenticated by the `token` cookie of an
* administrator:
* 1. it sends `{"name": string, "size": number}`, the size being a multiple of 512 bytes between 32 KiB and 128 GiB;
* 2. it receives `{"session": string}`, the id of the browser media session, to pass as `browserMediaId`;
* 3. then it receives read requests `{"id": number, "offset": number, "length": number}` (at most 1 MiB), each
* answered by a binary message: `id` as a big-endian uint32, followed by exactly `length` bytes of the ISO.
*
* Closing the WebSocket ejects the ISO. The server closes it with code `4400` on a protocol error, `4408` once the
* ISO is not read anymore, `4410` once it is ejected, and `4503` when the feature is unavailable.
*
* @example id "f07ab729-c0e8-721c-45ec-f11276377030"
* @example body { "browserMediaId": "3f1d0c9e8b7a6f5e4d3c2b1a09f8e7d6" }
*/
@Example(taskLocation)
@Extension('x-mcp-exposure', 'confirm')
@Post('{id}/actions/insert_browser_iso')
@Middlewares(json())
@SuccessResponse(asynchronousActionResp.status, asynchronousActionResp.description)
@Response(createdResp.status, 'ISO inserted')
@Response(forbiddenOperationResp.status, forbiddenOperationResp.description)
@Response(notFoundResp.status, notFoundResp.description)
@Response(
incorrectStateResp.status,
'The session or the VM is in the wrong state, or the VM already has an ISO streamed from a browser'
)
insertBrowserIso(
@Path() id: string,
@Body() body: { browserMediaId: string },
@Query() sync?: boolean
): CreateActionReturnType<{ vdiId: XoVdi['id'] }> {
const vmId = id as XoVm['id']
const params = { id: body.browserMediaId as XoBrowserMediaSession['id'], vmId }
// reported as such rather than as a failed task
this.restApi.xoApp.assertBrowserMediaInsertable(params)
const action = async () => {
const result = await this.restApi.xoApp.insertBrowserMedia(params)
if (sync) {
this.setHeader('Location', `${BASE_URL}/vdis/${result.vdiId}`)
}
return result
}
return this.createAction<{ vdiId: XoVdi['id'] }>(action, {
sync,
statusCode: createdResp.status,
taskProperties: { name: 'insert browser ISO', objectId: vmId, params: body },
})
}
/**
* Required privilege:
* - resource: vm, action: clone

View File

@@ -777,10 +777,8 @@ export default class Esxi extends EventEmitter {
}
// the cards are read from the devices and not from the vmx: they carry the key the inventory names
// them by, the vmx only has the address of a generated MAC, and lists the cards which are not present.
// In the whole `config` they are the `device` elements themselves, not wrapped in a `VirtualDevice`
// as the value of `config.hardware.device` is
const networks = parseDevices({ VirtualDevice: config.hardware?.device }).nics.map(
// them by, the vmx only has the address of a generated MAC, and lists the cards which are not present
const networks = parseDevices(config.hardware?.device).nics.map(
({ key, label, macAddress, addressType, network }) => ({
key,
label,

View File

@@ -1334,34 +1334,37 @@ createType="vmfs"
RW 67108864 VMFS "vm-000001-flat.vmdk"
`
const VMXNET3 = {
attributes: { 'xsi:type': 'VirtualVmxnet3' },
key: '4000',
deviceInfo: { label: 'Network adapter 1' },
macAddress: '00:0c:29:00:00:01',
addressType: 'generated',
backing: { network: moRef('Network', 'network-13') },
}
const E1000E = {
attributes: { 'xsi:type': 'VirtualE1000e' },
key: '4001',
deviceInfo: { label: 'Network adapter 2' },
macAddress: '00:50:56:00:00:02',
addressType: 'manual',
}
// in the whole `config`, the devices are the repeated `device` elements of the hardware: the
// `ArrayOfVirtualDevice` holding `VirtualDevice` elements is only the value of
// `config.hardware.device` read on its own
const config = (vmPathName, device) => ({
const config = vmPathName => ({
attributes: { 'xsi:type': 'VirtualMachineConfigInfo' },
name: 'a vm',
guestId: 'ubuntu64Guest',
guestFullName: 'Ubuntu Linux (64-bit)',
firmware: 'efi',
files: { vmPathName },
hardware: { memoryMB: '2048', numCPU: '2', device },
hardware: {
memoryMB: '2048',
numCPU: '2',
device: {
attributes: { 'xsi:type': 'ArrayOfVirtualDevice' },
VirtualDevice: [
{
attributes: { 'xsi:type': 'VirtualVmxnet3' },
key: '4000',
deviceInfo: { label: 'Network adapter 1' },
macAddress: '00:0c:29:00:00:01',
addressType: 'generated',
backing: { network: moRef('Network', 'network-13') },
},
{
attributes: { 'xsi:type': 'VirtualE1000e' },
key: '4001',
deviceInfo: { label: 'Network adapter 2' },
macAddress: '00:50:56:00:00:02',
addressType: 'manual',
},
],
},
},
})
const RUNTIME = { attributes: { 'xsi:type': 'VirtualMachineRuntimeInfo' }, powerState: 'poweredOn' }
@@ -1377,13 +1380,8 @@ RW 67108864 VMFS "vm-000001-flat.vmdk"
* @param {object} [options]
* @param {string} [options.vmPathName] - `files.vmPathName` reported for the VM
* @param {number} [options.vmsdStatus] - status of the response to the vmsd request
* @param {object | object[]} [options.device] - `hardware.device` of the config of the VM
*/
const transferableEsxi = async ({
vmPathName = '[ds main] a.vm/a.vm.vmx',
vmsdStatus = 404,
device = [VMXNET3, E1000E],
} = {}) => {
const transferableEsxi = async ({ vmPathName = '[ds main] a.vm/a.vm.vmx', vmsdStatus = 404 } = {}) => {
const requested = []
const { esxi } = await connectedEsxi({
responses: {
@@ -1398,7 +1396,7 @@ RW 67108864 VMFS "vm-000001-flat.vmdk"
}
return pathSet[0] === 'runtime'
? propertyOf('VirtualMachine', 'vm-1', 'runtime', RUNTIME)
: propertyOf('VirtualMachine', 'vm-1', 'config', config(vmPathName, device))
: propertyOf('VirtualMachine', 'vm-1', 'config', config(vmPathName))
},
},
fetch: async (url, options) => {
@@ -1461,18 +1459,6 @@ RW 67108864 VMFS "vm-000001-flat.vmdk"
])
})
it('reads the card of a VM with a single device', async function () {
// the SOAP library returns a lone element as the element itself
const { esxi } = await transferableEsxi({ device: VMXNET3 })
const { networks } = await esxi.getTransferableVmMetadata('vm-1')
assert.deepEqual(
networks.map(({ key, macAddress }) => ({ key, macAddress })),
[{ key: '4000', macAddress: '00:0c:29:00:00:01' }]
)
})
it('treats a missing vmsd as a VM without snapshot', async function () {
const { esxi } = await transferableEsxi()

View File

@@ -585,9 +585,9 @@ dependencies = [
[[package]]
name = "rustls-webpki"
version = "0.103.17"
version = "0.103.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3a0760a887c14823fca5a1c970b01d47c328c696c0c64829d1df50e8f853fd5"
checksum = "f3c3cf1d8b1e7d4927e2d154c3fcb02979afb9939629c62cd9048d4f07b60ac2"
dependencies = [
"aws-lc-rs",
"ring",
@@ -803,7 +803,7 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "vectura"
version = "0.2.1"
version = "0.2.0"
dependencies = [
"aws-lc-rs",
"clap",

View File

@@ -1,6 +1,6 @@
[package]
name = "vectura"
version = "0.2.1"
version = "0.2.0"
edition = "2024"
description = "Standalone client for VMware's NFC disk-read protocol"
# The license of the Xen Orchestra application components, see LICENSE.md at

View File

@@ -17,13 +17,14 @@
color-scheme: dark;
}
--scrollbar-width: 0.7rem;
--scrollbar-border: 0.2rem;
--scrollbar-width: 1.4rem;
--scrollbar-border: 0.4rem;
--scrollbar-thumb-color: var(--color-brand-item-active);
--scrollbar-track-color: var(--color-brand-background-selected);
/* Firefox/Gecko and Chrome versions >= 121 */
scrollbar-color: var(--scrollbar-thumb-color) var(--scrollbar-track-color);
scrollbar-width: auto;
/* Chrome/Webkit */
@@ -43,10 +44,6 @@
}
}
* {
scrollbar-width: thin;
}
a {
color: var(--color-brand-txt-base);
}
@@ -82,6 +79,18 @@ pre {
text-decoration: underline;
}
.scrollbar-small {
scrollbar-width: thin;
&::-webkit-scrollbar {
--scrollbar-width: 0.7rem;
}
&::-webkit-scrollbar-thumb {
--scrollbar-border: 0.2rem;
}
}
.em-dash-prefix::before {
content: '\2014'; /* em dash — */
margin-inline-end: 0.8rem;

View File

@@ -7,10 +7,7 @@
toggling: isToggling,
}"
>
<div class="content">
<slot />
</div>
<slot name="panel" />
<slot />
</div>
</template>
@@ -20,11 +17,6 @@ import { useUiStore } from '@core/stores/ui.store.ts'
import { refAutoReset } from '@vueuse/core'
import { computed, watch } from 'vue'
defineSlots<{
default(): any
panel(): any
}>()
const panelStore = usePanelStore()
const uiStore = useUiStore()
@@ -41,23 +33,20 @@ const columnTransition = `grid-template-columns ${PANEL_TRANSITION_DURATION}ms`
<style scoped lang="postcss">
.vts-content-side-panel {
flex: 1;
min-height: 0;
display: grid;
grid-template-columns: minmax(0, 1fr) 0;
grid-template-rows: minmax(0, 1fr);
overflow: hidden;
&:not(.mobile) {
display: grid;
grid-template-columns: minmax(0, 1fr) 0;
align-items: start;
overflow-x: clip;
min-height: min-content;
.content {
overflow-y: auto;
}
&.has-panel-column {
grid-template-columns: minmax(0, 1fr) v-bind('panelStore.cssWidth');
}
&.has-panel-column {
grid-template-columns: minmax(0, 1fr) v-bind('panelStore.cssWidth');
}
&.toggling:not(.mobile) {
transition: v-bind(columnTransition);
&.toggling {
transition: v-bind(columnTransition);
}
}
}
</style>

View File

@@ -1,13 +1,16 @@
<!-- v5 -->
<template>
<div class="vts-side-panel" :class="{ mobile: uiStore.isSmall }">
<div class="vts-side-panel-sticky" :class="{ mobile: uiStore.isSmall }">
<VtsResizeHandle v-if="showResizeHandle" position="start" :resizable="panelStore" />
<VtsPanel
:closable="hasSelection"
:close-icon="uiStore.isSmall ? 'fa:angle-left' : 'action:close-cancel-clear'"
class="panel"
class="vts-side-panel"
:style="{ transform }"
:class="{ locked: panelStore.isLocked && !uiStore.isSmall }"
:class="{
locked: panelStore.isLocked && !uiStore.isSmall,
mobile: uiStore.isSmall,
}"
@close="handleClose"
>
<template v-if="slots.actions" #actions>
@@ -107,28 +110,32 @@ function handleClose() {
</script>
<style scoped lang="postcss">
.vts-side-panel-sticky:not(.mobile) {
position: sticky;
top: 0;
align-self: start;
}
.vts-side-panel {
.panel {
width: v-bind('panelStore.cssWidth');
transition: v-bind(transformTransition);
}
width: v-bind('panelStore.cssWidth');
transition: v-bind(transformTransition);
&:not(.mobile) {
position: relative;
--panel-viewport-height: calc(100dvh - 5.6rem);
--panel-min-height: calc(100dvh - 16.6rem);
.panel {
height: 100%;
overflow: hidden;
min-height: var(--panel-min-height);
max-height: var(--panel-viewport-height);
overflow: hidden;
:deep(> .content) {
flex: 1 1 auto;
min-height: 0;
overflow-y: auto;
}
:deep(> .content) {
flex: 1 1 auto;
min-height: 0;
overflow-y: auto;
}
}
&.mobile .panel {
&.mobile {
z-index: 1010;
position: fixed;
width: 100dvw;

View File

@@ -45,6 +45,7 @@ const slots = defineSlots<{
flex-direction: column;
padding: 0.8rem;
gap: 0.8rem;
scrollbar-width: thin;
}
&.error {

View File

@@ -597,7 +597,6 @@
"job:arg:pif-ids-required": "At least one PIF ID is required",
"job:arg:pool-id-required": "Pool ID is required",
"job:arg:port-required-for-tcp-udp": "Port is required for TCP and UDP",
"job:arg:priority-invalid": "Priority must be an integer from {min} to {max}",
"job:arg:protocol-required": "Protocol is required",
"job:arg:sr-id-required": "SR ID is required",
"job:arg:sr-vdi-required": "SR VDI is required",
@@ -1443,7 +1442,6 @@
"traffic-rules:error-plugin:check-doc": "the SDN controller documentation",
"traffic-rules:format-warning": "Configuration error: Traffic rules are not in the expected format. Please {check-doc} on how to migrate them.",
"traffic-rules:format-warning:check-doc": "check the latest documentation",
"traffic-rules:no-free-priority": "No priority left below the other rules of {network}",
"traffic-rules:no-traffic-rules-detected": "No traffic rules detected",
"traffic-rules:position-on-network": "{position} rule on this network.",
"traffic-rules:rule-ordinal-suffixes": "one:st, two:nd, few:rd, other:th",

View File

@@ -597,7 +597,6 @@
"job:arg:pif-ids-required": "Au moins un ID de PIF est obligatoire",
"job:arg:pool-id-required": "L'ID de pool est obligatoire",
"job:arg:port-required-for-tcp-udp": "Le port est obligatoire pour TCP et UDP",
"job:arg:priority-invalid": "La priorité doit être un entier de {min} à {max}",
"job:arg:protocol-required": "Le protocole est obligatoire",
"job:arg:sr-id-required": "L'ID de SR est obligatoire",
"job:arg:sr-vdi-required": "Le VDI doit avoir un SR",
@@ -1443,7 +1442,6 @@
"traffic-rules:error-plugin:check-doc": "la documentation du contrôleur SDN",
"traffic-rules:format-warning": "Erreur de configuration : les règles de trafic ne sont pas au format attendu. Veuillez {check-doc} la plus récente pour savoir comment les migrer.",
"traffic-rules:format-warning:check-doc": "consulter la documentation",
"traffic-rules:no-free-priority": "Aucune priorité libre sous les autres règles de {network}",
"traffic-rules:no-traffic-rules-detected": "Aucune règle de trafic détectée",
"traffic-rules:position-on-network": "{position} règle sur ce réseau.",
"traffic-rules:rule-ordinal-suffixes": "one:re, other:e",

View File

@@ -1,5 +1,5 @@
<template>
<VtsInputWrapper :label :message="messages" wrap-message>
<VtsInputWrapper :label :message="messages">
<VtsSelect :id accent="brand">
<template v-if="slots.option" #default="slotProps">
<slot name="option" v-bind="slotProps" />

View File

@@ -1,61 +0,0 @@
import {
type FrontXoNetwork,
useXoNetworkCollection,
} from '@/modules/network/remote-resources/use-xo-network-collection.ts'
import { useTrafficRules } from '@/modules/traffic-rules/composables/traffic-rules.composable.ts'
import { getNewTrafficRulePriority } from '@/modules/traffic-rules/utils/xo-traffic-rule.util.ts'
import { type FrontXoVif, useXoVifCollection } from '@/modules/vif/remote-resources/use-xo-vif-collection.ts'
import { toComputed } from '@core/utils/to-computed.util.ts'
import type { TrafficRuleTargetType } from '@vates/types'
import { computed, type MaybeRefOrGetter } from 'vue'
export function useNewTrafficRulePriority(
rawTargetType: MaybeRefOrGetter<TrafficRuleTargetType>,
rawTargetId: MaybeRefOrGetter<FrontXoNetwork['id'] | FrontXoVif['id'] | undefined>,
rawIsPrioritySupported: MaybeRefOrGetter<boolean>
) {
const targetType = toComputed(rawTargetType)
const targetId = toComputed(rawTargetId)
const isPrioritySupported = toComputed(rawIsPrioritySupported)
const { useGetNetworkById } = useXoNetworkCollection()
const { vifs, getVifById } = useXoVifCollection()
const targetNetworkId = computed<FrontXoNetwork['id'] | undefined>(() => {
if (targetId.value === undefined) {
return undefined
}
if (targetType.value === 'network') {
return targetId.value as FrontXoNetwork['id']
}
return getVifById(targetId.value as FrontXoVif['id'])?.$network
})
const targetNetwork = useGetNetworkById(() => targetNetworkId.value)
const targetNetworkVifs = computed(() => vifs.value.filter(vif => vif.$network === targetNetworkId.value))
const { trafficRules: targetNetworkRules } = useTrafficRules(targetNetworkVifs, () =>
targetNetwork.value ? [targetNetwork.value] : []
)
const newRulePriority = computed(() => {
if (!isPrioritySupported.value) {
return undefined
}
return getNewTrafficRulePriority(targetNetworkRules.value)
})
const hasFreePriority = computed(() => {
if (!isPrioritySupported.value) {
return true
}
return newRulePriority.value !== undefined
})
return { targetNetwork, newRulePriority, hasFreePriority }
}

View File

@@ -1,115 +0,0 @@
import type {
FrontXoNetwork,
useXoNetworkCollection,
} from '@/modules/network/remote-resources/use-xo-network-collection.ts'
import { useNewTrafficRulePriority } from '@/modules/traffic-rules/composables/use-new-traffic-rule-priority.composable.ts'
import type { FrontXoVif, useXoVifCollection } from '@/modules/vif/remote-resources/use-xo-vif-collection.ts'
import type { useXoVmCollection } from '@/modules/vm/remote-resources/use-xo-vm-collection.ts'
import { createNetwork } from '@/test/create-network.ts'
import { createVif } from '@/test/create-vif.ts'
import { mountComposable } from '@/test/mount-composable.ts'
import { SDN_CONTROLLER_OF_RULES_KEY, type TrafficRuleTargetType } from '@vates/types'
import { computed, type MaybeRefOrGetter, toValue } from 'vue'
const { collections } = vi.hoisted(() => ({
collections: { networks: [] as FrontXoNetwork[], vifs: [] as FrontXoVif[] },
}))
// The collections would open SSE subscriptions
vi.mock(import('@/modules/network/remote-resources/use-xo-network-collection.ts'), () => ({
useXoNetworkCollection: (() => {
const getNetworkById = (id: FrontXoNetwork['id'] | undefined) =>
collections.networks.find(network => network.id === id)
return {
getNetworkById,
useGetNetworkById: (rawId: MaybeRefOrGetter<FrontXoNetwork['id'] | undefined>) =>
computed(() => getNetworkById(toValue(rawId))),
}
}) as unknown as typeof useXoNetworkCollection,
}))
vi.mock(import('@/modules/vif/remote-resources/use-xo-vif-collection.ts'), () => ({
useXoVifCollection: (() => ({
vifs: computed(() => collections.vifs),
getVifById: (id: FrontXoVif['id']) => collections.vifs.find(vif => vif.id === id),
})) as unknown as typeof useXoVifCollection,
}))
vi.mock(import('@/modules/vm/remote-resources/use-xo-vm-collection.ts'), () => ({
useXoVmCollection: (() => ({
getVmById: () => ({ name_label: 'VM' }),
})) as unknown as typeof useXoVmCollection,
}))
function withRules(...priorities: number[]) {
const rules = priorities.map(priority =>
JSON.stringify({ allow: true, direction: 'from', ipRange: '10.0.0.1', protocol: 'ICMP', priority })
)
return { [SDN_CONTROLLER_OF_RULES_KEY]: JSON.stringify(rules) }
}
const network = createNetwork({ id: 'network-1' as FrontXoNetwork['id'], other_config: withRules(500) })
const otherNetwork = createNetwork({ id: 'network-2' as FrontXoNetwork['id'], other_config: withRules(100) })
const vif = createVif({ id: 'vif-1' as FrontXoVif['id'], $network: network.id, other_config: withRules(300) })
const otherVif = createVif({ id: 'vif-2' as FrontXoVif['id'], $network: otherNetwork.id, other_config: withRules(50) })
beforeEach(() => {
collections.networks = [network, otherNetwork]
collections.vifs = [vif, otherVif]
})
function mountPriority(
targetType: TrafficRuleTargetType,
targetId: FrontXoNetwork['id'] | FrontXoVif['id'] | undefined,
isPrioritySupported = true
) {
return mountComposable(() => useNewTrafficRulePriority(targetType, targetId, isPrioritySupported)).wrapper.vm
}
describe('newRulePriority', () => {
it('goes below the network and VIF rules of the target network', () => {
expect(mountPriority('network', network.id).newRulePriority).toBe(290)
})
it('looks at the network of the target VIF', () => {
expect(mountPriority('VIF', vif.id).newRulePriority).toBe(290)
})
it('ignores the rules of the other networks', () => {
expect(mountPriority('network', otherNetwork.id).newRulePriority).toBe(40)
})
it('is undefined when the priority is not supported', () => {
expect(mountPriority('network', network.id, false).newRulePriority).toBeUndefined()
})
})
describe('targetNetwork', () => {
it('is the network of the target VIF', () => {
expect(mountPriority('VIF', vif.id).targetNetwork).toEqual(network)
})
})
describe('hasFreePriority', () => {
it('is true when a priority is left below the rules of the network', () => {
expect(mountPriority('network', network.id).hasFreePriority).toBe(true)
})
it('is false when a rule of the network has the lowest allowed priority', () => {
collections.vifs = [createVif({ id: vif.id, $network: network.id, other_config: withRules(1) })]
expect(mountPriority('network', network.id).hasFreePriority).toBe(false)
})
it('is true when the priority is not supported', () => {
collections.vifs = [createVif({ id: vif.id, $network: network.id, other_config: withRules(1) })]
expect(mountPriority('network', network.id, false).hasFreePriority).toBe(true)
})
it('is true without a target', () => {
expect(mountPriority('network', undefined).hasFreePriority).toBe(true)
})
})

View File

@@ -6,7 +6,6 @@ import { getNetworkIcon } from '@/modules/network/utils/xo-network.util.ts'
import { useXoPifCollection } from '@/modules/pif/remote-resources/use-xo-pif-collection.ts'
import { type FrontXoPool, useXoPoolCollection } from '@/modules/pool/remote-resources/use-xo-pool-collection.ts'
import { useDirectionLabels } from '@/modules/traffic-rules/composables/direction-labels.composable.ts'
import { useNewTrafficRulePriority } from '@/modules/traffic-rules/composables/use-new-traffic-rule-priority.composable.ts'
import { vmToTargetOption } from '@/modules/traffic-rules/form/target-option.util.ts'
import {
type BaseTrafficRuleFormData,
@@ -94,12 +93,6 @@ export function useNewTrafficRuleForm(
return parentNetwork ? parentNetwork.PIFs.length > 0 : false
})
const { targetNetwork, newRulePriority, hasFreePriority } = useNewTrafficRulePriority(
() => formData.targetType,
() => formData.targetId,
canCreateNetworkRule
)
const poolNetworks = computed(() =>
networks.value.filter(network => network.$pool === poolId.value && network.PIFs.length > 0)
)
@@ -144,10 +137,6 @@ export function useNewTrafficRuleForm(
onSubmit: () => ({
targetId: {
required: withMessage(required, () => (isVifTarget.value ? t('vif-required') : t('network-required'))),
freePriority: withMessage(
() => hasFreePriority.value,
() => t('traffic-rules:no-free-priority', { network: targetNetwork.value?.name_label ?? '' })
),
},
vmId: {
requiredIf: withMessage(requiredIf(isVifTarget), () => t('vm-required')),
@@ -254,17 +243,11 @@ export function useNewTrafficRuleForm(
return undefined
}
const payload: TrafficRulePayload = {
return {
...buildBaseRulePayload(),
targetType: formData.targetType,
targetId: formData.targetId,
}
if (newRulePriority.value !== undefined) {
payload.priority = newRulePriority.value
}
return payload
}
return {

View File

@@ -1,8 +1,4 @@
import { payloadsArg } from '@/modules/traffic-rules/jobs/xo-traffic-rule-create-args.ts'
import {
MAX_TRAFFIC_RULE_PRIORITY,
MIN_TRAFFIC_RULE_PRIORITY,
} from '@/modules/traffic-rules/utils/xo-traffic-rule.util.ts'
import { useXoTaskUtils } from '@/shared/composables/xo-task-utils.composable.ts'
import { fetchPost } from '@/shared/utils/fetch.util.ts'
import { defineJob, JobError, JobRunningError } from '@core/packages/job'
@@ -25,7 +21,6 @@ export type TrafficRulePayload = {
protocol: TrafficRuleProtocol
ipRange: string
port: number | null
priority?: number
}
export const useXoTrafficRuleCreateJob = defineJob('traffic-rule.create', [payloadsArg], () => {
@@ -74,17 +69,6 @@ export const useXoTrafficRuleCreateJob = defineJob('traffic-rule.create', [paylo
if (TRAFFIC_RULE_PROTOCOLS_WITH_PORT.includes(payload.protocol) && payload.port === undefined) {
throw new JobError(t('job:arg:port-required-for-tcp-udp'))
}
if (payload.priority !== undefined) {
const isInteger = Number.isInteger(payload.priority)
const isInRange =
payload.priority >= MIN_TRAFFIC_RULE_PRIORITY && payload.priority <= MAX_TRAFFIC_RULE_PRIORITY
if (!isInteger || !isInRange) {
throw new JobError(
t('job:arg:priority-invalid', { min: MIN_TRAFFIC_RULE_PRIORITY, max: MAX_TRAFFIC_RULE_PRIORITY })
)
}
}
})
},
}

View File

@@ -1,99 +0,0 @@
import {
type TrafficRulePayload,
useXoTrafficRuleCreateJob,
} from '@/modules/traffic-rules/jobs/xo-traffic-rule-create.job.ts'
import {
MAX_TRAFFIC_RULE_PRIORITY,
MIN_TRAFFIC_RULE_PRIORITY,
} from '@/modules/traffic-rules/utils/xo-traffic-rule.util.ts'
import type { useXoTaskUtils } from '@/shared/composables/xo-task-utils.composable.ts'
import type { fetchPost } from '@/shared/utils/fetch.util.ts'
import { t } from '@/test/i18n.ts'
import { mountComposable } from '@/test/mount-composable.ts'
import type { XoNetwork } from '@vates/types'
const { post, monitorTask } = vi.hoisted(() => ({
post: vi.fn(),
monitorTask: vi.fn(),
}))
vi.mock(import('@/shared/utils/fetch.util.ts'), () => ({
fetchPost: post as unknown as typeof fetchPost,
}))
// The task collection would open an SSE subscription
vi.mock(import('@/shared/composables/xo-task-utils.composable.ts'), () => ({
useXoTaskUtils: (() => ({ monitorTask })) as unknown as typeof useXoTaskUtils,
}))
beforeEach(() => {
post.mockReset()
monitorTask.mockReset()
post.mockResolvedValue({ taskId: 'task-1' })
monitorTask.mockResolvedValue(undefined)
})
function createPayload(overrides: Partial<TrafficRulePayload> = {}): TrafficRulePayload {
return {
targetType: 'network',
targetId: 'network-1' as XoNetwork['id'],
allow: true,
direction: 'from',
protocol: 'ICMP',
ipRange: '192.168.1.0/24',
port: null,
...overrides,
}
}
function mountCreateJob(payloads: TrafficRulePayload[]) {
return mountComposable(() => useXoTrafficRuleCreateJob(() => payloads)).wrapper.vm
}
describe('run', () => {
it('sends the priority of the rule', async () => {
await mountCreateJob([createPayload({ priority: 32758 })]).run()
expect(post).toHaveBeenCalledWith(
'plugins/sdn-controller/networks/network-1/actions/add_traffic_rule',
expect.objectContaining({ priority: 32758 })
)
})
it('sends no priority when the rule has none', async () => {
await mountCreateJob([createPayload()]).run()
expect(post.mock.calls[0][1]).not.toHaveProperty('priority')
})
})
describe('validate', () => {
const priorityError = t('job:arg:priority-invalid', {
min: MIN_TRAFFIC_RULE_PRIORITY,
max: MAX_TRAFFIC_RULE_PRIORITY,
})
it('can run without a priority', () => {
expect(mountCreateJob([createPayload()]).canRun).toBe(true)
})
it('can run with the lowest and the highest allowed priorities', () => {
const payloads = [
createPayload({ priority: MIN_TRAFFIC_RULE_PRIORITY }),
createPayload({ priority: MAX_TRAFFIC_RULE_PRIORITY }),
]
expect(mountCreateJob(payloads).canRun).toBe(true)
})
it.each([MIN_TRAFFIC_RULE_PRIORITY - 1, MAX_TRAFFIC_RULE_PRIORITY + 1, 10.5])(
'cannot run with the priority %s',
priority => {
const job = mountCreateJob([createPayload({ priority })])
expect(job.canRun).toBe(false)
expect(job.errorMessage).toBe(priorityError)
}
)
})

View File

@@ -6,13 +6,6 @@ import { SDN_CONTROLLER_OF_METHOD_KEY, type TrafficRule } from '@vates/types'
// OpenFlow default, applied to rules stored without a priority
const DEFAULT_TRAFFIC_RULE_PRIORITY = 32768
// XAPI reserves 0
export const MIN_TRAFFIC_RULE_PRIORITY = 1
export const MAX_TRAFFIC_RULE_PRIORITY = 65535
const TRAFFIC_RULE_PRIORITY_STEP = 10
export function isNetworkRuleSupported(pool: FrontXoPool | undefined): boolean {
const ofMethod = pool?.otherConfig[SDN_CONTROLLER_OF_METHOD_KEY]
@@ -27,25 +20,6 @@ export function getTrafficRulePriority(rule: TrafficRule): number {
return rule.priority
}
export function getNewTrafficRulePriority(networkRules: TrafficRule[]): number | undefined {
if (networkRules.length === 0) {
return DEFAULT_TRAFFIC_RULE_PRIORITY - TRAFFIC_RULE_PRIORITY_STEP
}
const priorities = networkRules.map(rule => getTrafficRulePriority(rule))
const lowestPriority = Math.min(...priorities)
if (lowestPriority >= MIN_TRAFFIC_RULE_PRIORITY + TRAFFIC_RULE_PRIORITY_STEP) {
return lowestPriority - TRAFFIC_RULE_PRIORITY_STEP
}
if (lowestPriority > MIN_TRAFFIC_RULE_PRIORITY) {
return lowestPriority - 1
}
return undefined
}
export function getTrafficRuleProtocolLabel(rule: TrafficRule): string {
if (rule.port === undefined) {
return rule.protocol

View File

@@ -1,7 +1,6 @@
import type { FrontXoNetwork } from '@/modules/network/remote-resources/use-xo-network-collection.ts'
import {
getNetworkRules,
getNewTrafficRulePriority,
getOrdinalSuffix,
getTrafficRulePriority,
getTrafficRuleProtocolLabel,
@@ -27,56 +26,6 @@ describe('getTrafficRulePriority', () => {
})
})
describe('getNewTrafficRulePriority', () => {
it('goes below the OpenFlow default on a network without rules', () => {
expect(getNewTrafficRulePriority([])).toBe(32758)
})
it('goes below the rules without a priority', () => {
expect(getNewTrafficRulePriority([createTrafficRule({ priority: undefined })])).toBe(32758)
})
it('goes below the lowest priority of the network', () => {
const rules = [createTrafficRule({ priority: 120 }), createTrafficRule({ priority: 100 })]
expect(getNewTrafficRulePriority(rules)).toBe(90)
})
it('goes below the lowest priority even when it is above the OpenFlow default', () => {
expect(getNewTrafficRulePriority([createTrafficRule({ priority: 40000 })])).toBe(39990)
})
it('goes down to the lowest allowed priority', () => {
expect(getNewTrafficRulePriority([createTrafficRule({ priority: 11 })])).toBe(1)
})
it('goes below the lowest priority among rules with and without one', () => {
const rules = [
createTrafficRule({ priority: undefined }),
createTrafficRule({ priority: 40000 }),
createTrafficRule({ priority: 500 }),
]
expect(getNewTrafficRulePriority(rules)).toBe(490)
})
it('steps down by one when there is no room for a step', () => {
expect(getNewTrafficRulePriority([createTrafficRule({ priority: 5 })])).toBe(4)
})
it('steps down by one to the lowest allowed priority', () => {
expect(getNewTrafficRulePriority([createTrafficRule({ priority: 2 })])).toBe(1)
})
it('returns undefined when a rule already has the lowest allowed priority', () => {
expect(getNewTrafficRulePriority([createTrafficRule({ priority: 1 })])).toBeUndefined()
})
it('returns undefined when a rule still has the priority 0 that XAPI reserves', () => {
expect(getNewTrafficRulePriority([createTrafficRule({ priority: 0 })])).toBeUndefined()
})
})
describe('getTrafficRuleProtocolLabel', () => {
it('returns the protocol alone when the rule has no port', () => {
expect(getTrafficRuleProtocolLabel(createTrafficRule({ protocol: 'ICMP', port: undefined }))).toBe('ICMP')

View File

@@ -3,9 +3,7 @@
<UiCard class="container">
<HostsTable :hosts :busy="!areHostsReady" :error="hasHostFetchError" />
</UiCard>
<template #panel>
<HostSidePanel :host="selectedHost" @close="selectedHost = undefined" />
</template>
<HostSidePanel :host="selectedHost" @close="selectedHost = undefined" />
</VtsContentSidePanel>
</template>

View File

@@ -3,9 +3,7 @@
<UiCard class="container">
<PoolsTable :servers />
</UiCard>
<template #panel>
<PoolSidePanel :server="selectedServer" @close="selectedServer = undefined" />
</template>
<PoolSidePanel :server="selectedServer" @close="selectedServer = undefined" />
</VtsContentSidePanel>
</template>

View File

@@ -3,9 +3,7 @@
<UiCard class="container">
<TasksList :tasks="convertedTasks" :has-error="hasTaskFetchError" :busy="!areTasksReady" />
</UiCard>
<template #panel>
<TaskSidePanel :task="selectedTask" @close="selectedTask = undefined" />
</template>
<TaskSidePanel :task="selectedTask" @close="selectedTask = undefined" />
</VtsContentSidePanel>
</template>

View File

@@ -3,9 +3,7 @@
<UiCard class="container">
<VmsTable :vms :busy="!areVmsReady" :error="hasVmFetchError" />
</UiCard>
<template #panel>
<VmSidePanel :vm="selectedVm" @close="selectedVm = undefined" />
</template>
<VmSidePanel :vm="selectedVm" @close="selectedVm = undefined" />
</VtsContentSidePanel>
</template>

View File

@@ -18,9 +18,7 @@
</UiCard>
</div>
<template #panel>
<BackupRepositorySidePanel :br="selectedBr" @close="selectedBr = undefined" />
</template>
<BackupRepositorySidePanel :br="selectedBr" @close="selectedBr = undefined" />
</VtsContentSidePanel>
</template>

View File

@@ -6,9 +6,7 @@
</UiCard>
</div>
<template #panel>
<BackupJobSidePanel :backup-job="selectedBackupJob" @close="selectedBackupJob = undefined" />
</template>
<BackupJobSidePanel :backup-job="selectedBackupJob" @close="selectedBackupJob = undefined" />
</VtsContentSidePanel>
</template>

View File

@@ -6,9 +6,7 @@
</UiCard>
</div>
<template #panel>
<BackupLogSidePanel :backup-log="selectedBackupLog" @close="selectedBackupLog = undefined" />
</template>
<BackupLogSidePanel :backup-log="selectedBackupLog" @close="selectedBackupLog = undefined" />
</VtsContentSidePanel>
</template>

View File

@@ -3,9 +3,7 @@
<UiCard class="container">
<TasksList :tasks="convertedTasks" :title="t('run')" :has-error="false" :busy="false" auto-collapse-toggle />
</UiCard>
<template #panel>
<BackupLogTaskSidePanel :task="selectedTask" @close="selectedTask = undefined" />
</template>
<BackupLogTaskSidePanel :task="selectedTask" @close="selectedTask = undefined" />
</VtsContentSidePanel>
</template>

View File

@@ -7,9 +7,7 @@
</UiCard>
</div>
<template #panel>
<PluginSidePanel :plugin="selectedPlugin" @close="selectedPlugin = undefined" />
</template>
<PluginSidePanel :plugin="selectedPlugin" @close="selectedPlugin = undefined" />
</VtsContentSidePanel>
</template>

View File

@@ -9,9 +9,7 @@
</UiCard>
</div>
<template #panel>
<UserSidePanel :user="selectedUser" @close="selectedUser = undefined" />
</template>
<UserSidePanel :user="selectedUser" @close="selectedUser = undefined" />
</VtsContentSidePanel>
</template>

View File

@@ -7,9 +7,7 @@
</template>
</PifsTable>
</UiCard>
<template #panel>
<PifSidePanel :pif="selectedPif" @close="selectedPif = undefined" />
</template>
<PifSidePanel :pif="selectedPif" @close="selectedPif = undefined" />
</VtsContentSidePanel>
</template>

View File

@@ -3,9 +3,7 @@
<UiCard class="container">
<StorageRepositoriesTable :srs :busy="!isReady" :error="hasFetchError" :scope />
</UiCard>
<template #panel>
<StorageRepositorySidePanel :sr="selectedSr" :scope @close="selectedSr = undefined" />
</template>
<StorageRepositorySidePanel :sr="selectedSr" :scope @close="selectedSr = undefined" />
</VtsContentSidePanel>
</template>

View File

@@ -3,9 +3,7 @@
<UiCard class="container">
<TasksList :tasks="convertedTasks" :has-error="hasTaskFetchError" :busy="!areTasksReady" />
</UiCard>
<template #panel>
<TaskSidePanel :task="selectedTask" @close="selectedTask = undefined" />
</template>
<TaskSidePanel :task="selectedTask" @close="selectedTask = undefined" />
</VtsContentSidePanel>
</template>
@@ -26,6 +24,7 @@ const { host } = defineProps<{
const { getTaskById, sortedTasks, hasTaskFetchError, areTasksReady } = useXoHostTasksCollection({}, () => host.id)
const selectedTask = useRouteQuery<FrontXoTask | undefined>('id', {
toData: id => getTaskById(id as FrontXoTask['id']),
toQuery: task => task?.id ?? '',

View File

@@ -3,9 +3,7 @@
<UiCard class="container">
<VmsTable :vms :busy="!areVmsReady" :error="hasVmFetchError" />
</UiCard>
<template #panel>
<VmSidePanel :vm="selectedVm" @close="selectedVm = undefined" />
</template>
<VmSidePanel :vm="selectedVm" @close="selectedVm = undefined" />
</VtsContentSidePanel>
</template>

View File

@@ -3,9 +3,7 @@
<UiCard class="container">
<PifsTable :pifs />
</UiCard>
<template #panel>
<PifSidePanel :pif="selectedPif" @close="selectedPif = undefined" />
</template>
<PifSidePanel :pif="selectedPif" @close="selectedPif = undefined" />
</VtsContentSidePanel>
</template>

View File

@@ -3,9 +3,7 @@
<UiCard class="container">
<HostsTable :hosts :busy="!areHostsReady" :error="hasHostFetchError" />
</UiCard>
<template #panel>
<HostSidePanel :host="selectedHost" @close="selectedHost = undefined" />
</template>
<HostSidePanel :host="selectedHost" @close="selectedHost = undefined" />
</VtsContentSidePanel>
</template>

View File

@@ -40,9 +40,7 @@
</template>
</NetworksTable>
</UiCard>
<template #panel>
<NetworkSidePanel :network="selectedNetwork" @close="selectedNetwork = undefined" />
</template>
<NetworkSidePanel :network="selectedNetwork" @close="selectedNetwork = undefined" />
</VtsContentSidePanel>
</template>

View File

@@ -3,9 +3,7 @@
<UiCard class="container">
<StorageRepositoriesTable :srs :scope :busy="!areSrsReady" :error="hasSrFetchError" />
</UiCard>
<template #panel>
<StorageRepositorySidePanel :sr="selectedSr" :scope @close="selectedSr = undefined" />
</template>
<StorageRepositorySidePanel :sr="selectedSr" :scope @close="selectedSr = undefined" />
</VtsContentSidePanel>
</template>

View File

@@ -3,9 +3,7 @@
<UiCard class="container">
<TasksList :tasks="convertedTasks" :has-error="hasTaskFetchError" :busy="!areTasksReady" />
</UiCard>
<template #panel>
<TaskSidePanel :task="selectedTask" @close="selectedTask = undefined" />
</template>
<TaskSidePanel :task="selectedTask" @close="selectedTask = undefined" />
</VtsContentSidePanel>
</template>
@@ -26,6 +24,7 @@ const { pool } = defineProps<{
const { getTaskById, sortedTasks, hasTaskFetchError, areTasksReady } = useXoPoolTasksCollection({}, () => pool.id)
const selectedTask = useRouteQuery<FrontXoTask | undefined>('id', {
toData: id => getTaskById(id as FrontXoTask['id']),
toQuery: task => task?.id ?? '',

View File

@@ -10,14 +10,7 @@
</template>
</TrafficRulesTable>
</UiCard>
<template #panel>
<TrafficRulesSidePanel
:rule="selectedRule"
:rules="trafficRules"
show-priority
@close="selectedRule = undefined"
/>
</template>
<TrafficRulesSidePanel :rule="selectedRule" :rules="trafficRules" show-priority @close="selectedRule = undefined" />
</VtsContentSidePanel>
</template>

View File

@@ -3,9 +3,7 @@
<UiCard class="container">
<VmsTable :vms :busy="!areVmsReady" :error="hasVmFetchError" />
</UiCard>
<template #panel>
<VmSidePanel :vm="selectedVm" @close="selectedVm = undefined" />
</template>
<VmSidePanel :vm="selectedVm" @close="selectedVm = undefined" />
</VtsContentSidePanel>
</template>

View File

@@ -3,9 +3,7 @@
<UiCard class="container">
<HostsTable :hosts :sr :busy="!isReady" :error="hasError" />
</UiCard>
<template #panel>
<HostSidePanel :host="selectedHost" @close="selectedHost = undefined" />
</template>
<HostSidePanel :host="selectedHost" @close="selectedHost = undefined" />
</VtsContentSidePanel>
</template>

View File

@@ -10,9 +10,7 @@
</template>
</TrafficRulesTable>
</UiCard>
<template #panel>
<TrafficRulesSidePanel :rule="selectedRule" :rules="trafficRules" @close="selectedRule = undefined" />
</template>
<TrafficRulesSidePanel :rule="selectedRule" :rules="trafficRules" @close="selectedRule = undefined" />
</VtsContentSidePanel>
</template>

View File

@@ -6,9 +6,7 @@
</UiCard>
</div>
<template #panel>
<BackupJobSidePanel :backup-job="selectedBackupJob" @close="selectedBackupJob = undefined" />
</template>
<BackupJobSidePanel :backup-job="selectedBackupJob" @close="selectedBackupJob = undefined" />
</VtsContentSidePanel>
</template>

View File

@@ -9,9 +9,7 @@
</template>
</VifsTable>
</UiCard>
<template #panel>
<VifSidePanel :vif="selectedVif" :vm @close="selectedVif = undefined" />
</template>
<VifSidePanel :vif="selectedVif" :vm @close="selectedVif = undefined" />
</VtsContentSidePanel>
</template>

View File

@@ -13,9 +13,7 @@
<SnapshotsTable :snapshots :vm />
</UiCard>
</div>
<template #panel>
<SnapshotSidePanel :snapshot="selectedSnapshot" @close="selectedSnapshot = undefined" />
</template>
<SnapshotSidePanel :snapshot="selectedSnapshot" @close="selectedSnapshot = undefined" />
</VtsContentSidePanel>
</template>

View File

@@ -3,9 +3,7 @@
<UiCard class="container">
<TasksList :tasks="convertedTasks" :has-error="hasTaskFetchError" :busy="!areTasksReady" />
</UiCard>
<template #panel>
<TaskSidePanel :task="selectedTask" @close="selectedTask = undefined" />
</template>
<TaskSidePanel :task="selectedTask" @close="selectedTask = undefined" />
</VtsContentSidePanel>
</template>

View File

@@ -33,9 +33,7 @@
</template>
</VdisTable>
</UiCard>
<template #panel>
<VdiSidePanel :vdi="selectedVdi" :vm @close="selectedVdi = undefined" />
</template>
<VdiSidePanel :vdi="selectedVdi" :vm @close="selectedVdi = undefined" />
</VtsContentSidePanel>
</template>

View File

@@ -7,8 +7,6 @@
- Fix authentication token validation
- [Backup/File restore] Symbolic links are no longer followed: browsing or downloading a path that goes through one is refused, and the links met inside a restored folder are skipped (PR [#9941](https://github.com/vatesfr/xen-orchestra/pull/9941))
- [Backup/Live mount] The iSCSI target of a mount only accepts connections from the host it is mounted on. **If the hosts reach XO or the proxy through a NAT**, set `iscsi.restrictToHost = false`, or live mounts fail (PR [#10426](https://github.com/vatesfr/xen-orchestra/pull/10426))
- [Plugins/audit] Redact more sensitive values from new audit records (created API tokens, credentials and encryption keys in URLs, one-time download/upload links) (PR [#10618](https://github.com/vatesfr/xen-orchestra/pull/10618))
### Enhancements
@@ -38,9 +36,6 @@
- [Backups] VM backups on S3 and Azure repositories now lock the VM's folder like on other repositories: two jobs, or a job and the cleanup that follows a deletion, no longer modify the same VM's folder at the same time, and the second one fails with "Lock file is already being held". On S3, buckets with Object Lock enabled are not locked yet (PR [#10549](https://github.com/vatesfr/xen-orchestra/pull/10549))
- [VMs] Select multiple VMs in VM tables to change their power state, snapshot or delete them at once (PR [#10780](https://github.com/vatesfr/xen-orchestra/pull/10780))
- [XO6/Backups] Add filters and actions on backup jobs (PR [#10772](https://github.com/vatesfr/xen-orchestra/pull/10772))
- [Logs] The syslog transport (`[logs.transport.syslog]` in xo-server configuration) supports TLS (`tls://`), and the facility, application name and framing can be configured (PR [#10619](https://github.com/vatesfr/xen-orchestra/pull/10619))
- [Logs] **Breaking:** logs are now sent to syslog as RFC 5424 messages, with their namespace as message ID, instead of RFC 3164 messages: set `format = 'rfc3164'` in `[logs.transport.syslog]` to keep the previous format (PR [#10619](https://github.com/vatesfr/xen-orchestra/pull/10619))
- [Plugins/audit] Forward a copy of each new audit record, as JSON, to a remote syslog server (e.g. a SIEM) over UDP, TCP or TLS, configurable in the plugin settings (PR [#10618](https://github.com/vatesfr/xen-orchestra/pull/10618))
### Bug fixes
@@ -51,9 +46,6 @@
- [V2V] Keep the MAC address of a network card set by hand on VMware, instead of generating a new one, and no longer create a network interface for a card which is not present (PR [#10597](https://github.com/vatesfr/xen-orchestra/pull/10597))
- [Replication] Fix `Cannot read properties of undefined (reading 'uuid')` error when an orphan replica snapshot exists on the target SR (PR [#10732](https://github.com/vatesfr/xen-orchestra/pull/10732))
- [XO6/Modals] Modals no longer stretch across the screen: their width is limited to a third of the screen, up to 550px (PR [#10800](https://github.com/vatesfr/xen-orchestra/pull/10800))
- [Backup/Live mount] Fix mounts failing when xo-server runs without root on a system using iptables-legacy, instead of leaving the firewall alone (PR [#10426](https://github.com/vatesfr/xen-orchestra/pull/10426))
- [Logs] Fix the syslog transport sending every log with the _informational_ severity, splitting a log with line breaks into several messages, keeping the previous connection open when the configuration changes, and accumulating connections and memory when the syslog server is unreachable or does not read (PR [#10619](https://github.com/vatesfr/xen-orchestra/pull/10619))
- [Side panels] Fix the double scrollbar when the side panel content is taller than the screen: the page header now stays in place, and the list and the side panel each scroll on their own. All scrollbars are now thin, like the side panel one (PR [#10807](https://github.com/vatesfr/xen-orchestra/pull/10807))
### Packages to release
@@ -71,14 +63,10 @@
<!--packages-start-->
- @vates/obfuscate minor
- @vates/syslog minor
- @vates/types minor
- @xen-orchestra/acl minor
- @xen-orchestra/backups minor
- @xen-orchestra/fs minor
- @xen-orchestra/log major
- @xen-orchestra/mixins minor
- @xen-orchestra/proxy minor
- @xen-orchestra/qa-test minor
- @xen-orchestra/rest-api minor
@@ -86,7 +74,6 @@
- @xen-orchestra/web minor
- @xen-orchestra/web-core minor
- xo-server minor
- xo-server-audit minor
- xo-server-load-balancer patch
- xo-web minor

View File

@@ -507,13 +507,6 @@ With a slow or distant BR, typically an S3 or Azure BR outside your network, rea
#bindAddress = '0.0.0.0'
```
- **Only the host connects.** The iSCSI target of a mount only accepts connections from the addresses of the host it is mounted on: its management address and the addresses of its PIFs, storage networks included. Any other connection is closed at once, so nothing else can keep the host from connecting. If the hosts reach Xen Orchestra through a NAT, which hides their own addresses, turn it off in the same `[iscsi]` section:
```toml
[iscsi]
restrictToHost = false
```
- **Temporary.** A live mount only lasts as long as the Xen Orchestra process serving it: restarting or updating XOA ends it, and the disk becomes unavailable to the VM. Stop using the disk before restarting or updating XOA. If Xen Orchestra stopped unexpectedly, the `[XO live mount] <VM name> (<backup date>)` SR stays behind with nothing serving it: detach the disk from the VM and forget the SR.
### Firewall of Xen Orchestra {#live-mount-firewall}
@@ -527,7 +520,7 @@ To turn it off, and manage the firewall yourself, add to the [configuration file
manageFirewall = false
```
If a firewall still blocks the hosts, the restore fails with `the host cannot reach the iSCSI target at <address>:<port>, check iscsi.advertisedAddress and the firewalls between them, …`. If they connect through a NAT, it fails with `the host connected to the iSCSI target from <address>, which is not one of its addresses, e.g. through a NAT: set iscsi.restrictToHost = false`.
If a firewall still blocks the hosts, the restore fails with `the host cannot reach the iSCSI target at <address>:<port>, check iscsi.advertisedAddress and the firewalls between them`.
How it works:

View File

@@ -146,9 +146,13 @@ On S3 repositories, the lock is an object named `xo-vm-backups/<VM UUID>.lock`,
On Azure repositories, the lock is a blob named `xo-vm-backups/<VM UUID>.lock`, which its holder leases for 60 seconds and renews every 15 seconds. If XO stops while holding it, the lease expires, and the next job can take the lock within 60 seconds.
## Error: HTTP connection has timed out
## Error: HTTP connection has timed out or BodyTimeoutError {#error-http-connection-has-timed-out}
This error occurs when XO fetches disk data from a host via an HTTP GET request, and the host (the dom0 specifically) stops responding after being asked to expose the disk to export. It's usually a symptom of an overloaded dom0: not enough resources to answer the request, or trouble attaching the disk to expose it.
Both messages report the same problem. Depending on how XO connects to the host, the backup log shows either `HTTP connection has timed out`, or `BodyTimeoutError: Body Timeout Error` (code `UND_ERR_BODY_TIMEOUT`).
This error occurs when XO fetches disk data from a host via an HTTP GET request, and the host (the dom0 specifically) stops sending data for longer than the inactivity timeout, either before the export starts or in the middle of the transfer. It's not a network, credentials or backup repository failure: XO is connected to the host, but the host sent nothing for too long, so XO stopped waiting.
It's usually a symptom of an overloaded dom0: not enough resources to answer the request, or trouble attaching the disk to expose it. If only full backups are affected, see [Full backups fail but delta backups succeed](#full-backups-fail-but-delta-backups-succeed).
:::warning
As a temporary workaround, you can raise the inactivity timeout above the default value (5 minutes) to give the host more time to respond. But you still need to diagnose the root cause of the slow host response, or the issue will come back.
@@ -170,6 +174,14 @@ httpInactivityTimeout = 1800000 # 30 mins
Then restart the `xo-server` service to apply the change.
### Full backups fail but delta backups succeed
If the error only affects full backups, on VMs that delta backups save without problems, and these VMs have large disks or a lot of free disk space, the backup repository is most likely not the cause. Look at the export compression instead.
When compression (zstd or gzip) is enabled on a full backup job, the host compresses the whole disk during the export, including its free space. While it works through large empty areas, it doesn't send any data to XO, and the inactivity timeout can expire. Delta backups don't go through this compression, so the same VMs back up fine.
This is a known issue, tracked in [issue #9181](https://github.com/vatesfr/xen-orchestra/issues/9181). Until it's fixed, you can raise the inactivity timeout as described above.
## Error: Expected values to be strictly equal
This error occurs at the end of the transfer, when XO checks the integrity of the exported VM disk to ensure it's a valid VHD file (both the VHD header and the footer of the received file are verified). The error means the check failed: the file is incomplete, most likely because the export from the dom0 stopped at some point and XO only received a partial disk.

View File

@@ -116,7 +116,6 @@ A disk can be [live mounted](../backup-features-and-settings.md#live-mount) from
- The hosts connect to the proxy over iSCSI, on a TCP port picked for each mount. If a firewall sits between the hosts and the proxy, that firewall must allow TCP connections from the hosts to the proxy.
- The address provided to the hosts is the proxy's automatically detected address. If the hosts cannot reach it, set the address in the `[iscsi]` section of the proxy configuration (`/etc/xo-proxy/config.toml`), using the same `advertisedAddress` and `bindAddress` settings as those configured for XOA.
- The proxy only accepts iSCSI connections from the host each disk is mounted on. If the hosts reach the proxy through a NAT, set `restrictToHost = false` in the same `[iscsi]` section, see [Only the host connects](../backup-features-and-settings.md#live-mount).
- If ufw is enabled on the proxy, the proxy opens the port of each mount itself, only for the host it is mounted on. This is enabled by default: set `manageFirewall = false` in the same `[iscsi]` section to turn it off. See [Firewall of Xen Orchestra](../backup-features-and-settings.md#live-mount-firewall) for how the rules behave, including when ufw is changed or the proxy crashes.
- The mount lasts as long as the proxy process: restarting or updating the proxy ends it.
- Deleting the live mounted disk, or the VM with its disks, releases the mount, as without a proxy.

View File

@@ -202,10 +202,6 @@ XO Audit Log is a plugin that records all important actions performed by users a
XO Audit Log listens to important actions performed by users and stores them in the XOA database using the [hash chain structure](https://en.wikipedia.org/wiki/Hash_chain).
### Secrets in the records
Before storing a record, the plugin removes the secrets it knows about: passwords and tokens in the parameters, created API tokens, credentials and encryption keys in URLs (e.g. backup repositories), and one-time download/upload links. Records stored by previous versions are left untouched so that the chain stays valid.
### Trustability of the records
Stored records are secured by:
@@ -226,28 +222,6 @@ The recording of the users' actions is disabled by default. To enable it:
Now, the audit plugin will record users' actions and upload the last record in the chain every day at **06:00 AM (UTC)**.
### Forwarding to a remote syslog server
To send the records to a SIEM or any other log collector, fill the `syslog` section of the plugin configuration:
- `uri`: the address of the syslog server, like `udp://syslog.company.lan`, `tcp://syslog.company.lan:1514` or `tls://syslog.company.lan` (default port is `514`, `6514` for TLS)
- `facility`: the syslog facility of the messages, `authpriv` by default
- `framing` (TCP and TLS only): `lf` (default, a line feed after each message) or `octet-counting` (required by some servers, e.g. the `syslog()` driver of syslog-ng)
- `allowUnauthorized` (TLS only): do not check the certificate of the server, e.g. when it is self-signed (prefer `certificateAuthorities`)
- `certificateAuthorities` (TLS only): paths to PEM files of additional certificate authorities to trust, e.g. when the certificate of the server is issued by an internal authority
Each new record is still stored in XO and a copy is sent as an [RFC 5424](https://datatracker.ietf.org/doc/html/rfc5424) message:
- the app name is `xo-audit`
- the message ID is the event of the record (e.g. `apiCall`, `signInFailed`)
- the content is the record as JSON, including its `id` and `previousId` hashes so that the copies can be checked against the chain stored in XO
Saving settings which cannot be used (e.g. an unreadable certificate authority file) fails with the reason. If this happens when XO starts, the records are still stored in XO but not forwarded: the error is logged, and the test button of the plugin shows it.
Forwarding is best effort: records that cannot be sent (e.g. the syslog server is unreachable, or stopped reading) are not sent again later, but they remain in XO and can be exported. Prefer TLS (or TCP on a trusted network): UDP and TCP messages are not encrypted, and UDP messages can be lost or rejected when a record is too big.
Use the test button of the plugin to send a test message to the syslog server.
## Debugging
If you can't log in, please [check the logs of `xo-server`](../../support-and-reference/troubleshooting.md#logs).

View File

@@ -45,8 +45,6 @@
},
"dependencies": {
"@vates/decorate-with": "^2.1.0",
"@vates/obfuscate": "^0.1.0",
"@vates/syslog": "^0.1.0",
"@xen-orchestra/audit-core": "^0.4.0",
"@xen-orchestra/cron": "^1.0.7",
"@xen-orchestra/log": "^0.7.2",

View File

@@ -2,19 +2,15 @@ import asyncIteratorToStream from 'async-iterator-to-stream'
import ndjson from 'ndjson'
import { alteredAuditRecord, missingAuditRecord } from 'xo-common/api-errors'
import { createGzip, createUnzip } from 'zlib'
import { readFile } from 'fs'
import { createLogger } from '@xen-orchestra/log'
import { createSchedule } from '@xen-orchestra/cron'
import { decorateClass } from '@vates/decorate-with'
import { defer } from 'golike-defer'
import { fromCallback } from 'promise-toolbox'
import { AlteredRecordError, AuditCore, MissingRecordError, NULL_ID, Storage } from '@xen-orchestra/audit-core'
import { FACILITIES } from '@vates/syslog'
import { PassThrough, pipeline, promises } from 'readable-stream'
import { createRestRoutes } from './rest-api.js'
import { redactData } from './redact.js'
import { SyslogForwarder } from './syslog.js'
const log = createLogger('xo:xo-server-audit')
@@ -196,47 +192,6 @@ export const configurationSchema = {
'Whether to save user actions in the audit log (do not enable if you are planning to perform an audit log import)',
type: 'boolean',
},
syslog: {
type: 'object',
title: 'syslog',
description: 'Forward a copy of each new record, as JSON, to a remote syslog server (RFC 5424)',
properties: {
// not `target`: xo-web considers an object with a `target` property as an
// event, which made the whole section not editable
uri: {
type: 'string',
description: 'udp://host[:port], tcp://host[:port] or tls://host[:port] (default port: 514, 6514 for TLS)',
},
facility: {
default: 'authpriv',
enum: FACILITIES,
},
framing: {
description:
'TCP and TLS only: `lf` (default, a line feed after each message) or `octet-counting` (required by some servers, e.g. the `syslog()` driver of syslog-ng)',
enum: ['lf', 'octet-counting'],
},
// not `checkCertificate` with `true` as default: xo-web displays a
// missing boolean as disabled, whatever its default
allowUnauthorized: {
title: 'Ignore certificate errors',
description:
"TLS only: do not check the server's certificate (e.g. self-signed certificate), prefer adding its certificate authority below",
type: 'boolean',
},
certificateAuthorities: {
title: 'Certificate Authorities',
description:
'TLS only: paths to the PEM files of the certificate authorities to trust, in addition to the system ones',
type: 'array',
items: {
type: 'string',
},
},
},
additionalProperties: false,
required: ['uri'],
},
},
}
@@ -258,9 +213,6 @@ class AuditXoPlugin {
this._auditCore = undefined
this._storage = undefined
this._configured = false
this._syslogError = undefined
this._syslogForwarder = undefined
this._listeners = {
'xo:audit': this._handleEvent.bind(this),
@@ -268,37 +220,7 @@ class AuditXoPlugin {
}
}
async configure({ active = false, syslog }, { loaded }) {
// created first so that an invalid configuration is rejected without altering the current one
let syslogForwarder, syslogError
if (syslog !== undefined) {
try {
const { certificateAuthorities, ...options } = syslog
syslogForwarder = new SyslogForwarder({
...options,
ca:
certificateAuthorities === undefined
? undefined
: await Promise.all(certificateAuthorities.map(path => fromCallback(readFile, path, 'utf8'))),
})
} catch (error) {
// a configuration change is rejected so that the user sees why
if (this._configured) {
throw error
}
// at startup (first configuration, from the saved one), e.g. a
// certificate authority which is no longer readable must not prevent
// the plugin from recording, only the forwarding is disabled
log.error('cannot forward records to syslog, fix the syslog settings of the plugin', { error })
syslogError = error
}
}
this._configured = true
this._syslogError = syslogError
this._syslogForwarder?.close()
this._syslogForwarder = syslogForwarder
configure({ active = false }, { loaded }) {
this._active = active
if (loaded) {
@@ -390,7 +312,6 @@ class AuditXoPlugin {
unload() {
this._removeListeners()
this._syslogForwarder?.close()
this._cleaners.forEach(cleaner => cleaner())
this._cleaners.length = 0
}
@@ -416,32 +337,21 @@ class AuditXoPlugin {
async _handleEvent(event, { userId, userIp, userName, ...data }) {
try {
if (event !== 'apiCall' || !this._blockedList[data.method]) {
const record = await this._auditCore.add(
return await this._auditCore.add(
{
userId,
userIp,
userName,
},
event,
redactData(data)
data
)
this._syslogForwarder?.forward(record)
return record
}
} catch (error) {
log.error(error)
}
}
async test() {
const forwarder = this._syslogForwarder
if (forwarder === undefined) {
// e.g. the certificate authority which was not readable at startup
throw this._syslogError ?? new Error('no syslog URI configured')
}
return forwarder.test()
}
async _getRecords({ id, maxRecords = 10e3, ndjson = false }) {
if (ndjson) {
return this._xo

Some files were not shown because too many files have changed in this diff Show More