M #-: Add new guacamole config handling (#4647)

* Adds `guacamole` config block to `fireedge-server.conf`.
This commit is contained in:
vichansson authored and GitHub committed 2026-10-27 16:56:46 +01:00
1 parent ce4d1b79c8
commit e87261a2fc
3 files changed
+121 -44

No files matched your search

+50
View File
@@ -61,6 +61,56 @@ guacd:
port: 4822
host: 'localhost'
# Guacamole connection defaults for VNC, SSH and RDP.
# Priority (last wins): common -> protocol -> VM/NIC -> browser -> enforced.
# Browser options are limited to display/terminal settings and rangeports.
# enforced settings cannot be overridden by VM/NIC settings or the browser.
# Within enforced, protocol settings override common values.
# Add other options using their Guacamole parameter names:
# https://guacamole.apache.org/doc/gug/configuring-guacamole.html
guacamole:
common:
width: 1024
height: 768
dpi: 96
rdp:
port: 3389
# Disable audio and microphone
disable-audio: true
enable-audio-input: false
# Display and performance
resize-method: display-update
enable-wallpaper: false
enable-theming: false
enable-font-smoothing: false
enable-full-window-drag: false
enable-desktop-composition: false
enable-menu-animations: false
disable-bitmap-caching: false
disable-offscreen-caching: false
disable-glyph-caching: false
vnc:
port: 5900
ssh:
port: 22
# Server policy, applied whenever a Guacamole connection opens
enforced:
common:
disable-copy: true
disable-paste: true
enable-sftp: false
rdp:
# Requires NLA credentials and a trusted guest certificate
security: nla
ignore-cert: false
enable-drive: false
enable-printing: false
# Local zone in a Federation setup
# This attribute must point to the Zone ID of the local OpenNebula to which this FireEdge belongs to.
default_zone:
@@ -26,7 +26,7 @@ const {
executeCommand,
getSunstoneAuth,
} = require('server/utils/server')
const { getSunstoneConfig } = require('server/utils/yml')
const { getSunstoneConfig, getFireedgeConfig } = require('server/utils/yml')
const { Actions: userActions } = require('server/utils/constants/commands/user')
const { Actions: vmActions } = require('server/utils/constants/commands/vm')
const { createTokenServerAdmin } = require('server/routes/api/auth/utils')
@@ -174,16 +174,22 @@ const generateGuacamoleSession = (
}
: undefined
const guacamoleConfig = getFireedgeConfig().guacamole
const connection = {
// Keep the protocol outside connection settings: the bridge flattens
// that object before the server applies its enforced parameters.
protocol: ensuredType,
...(tunnelHost && { tunnel: tunnelHost }),
connection: {
type: ensuredType,
settings: {
security: 'any',
'ignore-cert': 'true',
'enable-drive': 'true',
'create-drive-path': 'true',
...settings,
...guacamoleConfig?.common,
...guacamoleConfig?.[ensuredType],
...Object.fromEntries(
Object.entries(settings).filter(([, value]) => value !== undefined)
),
...guacamoleConfig?.enforced?.common,
...guacamoleConfig?.enforced?.[ensuredType],
},
},
}
@@ -259,9 +265,13 @@ const getVncSettings = (vmInfo) => {
const data = [].concat(...[vmInfo.HISTORY_RECORDS?.HISTORY ?? []])
const lastRecord = data[data.length - 1]
config.hostname = lastRecord?.HOSTNAME ?? 'localhost'
config.hostname = lastRecord?.HOSTNAME
config.port = vmInfo.TEMPLATE?.GRAPHICS?.PORT ?? '5900'
if (!config.hostname) {
return { error: 'Wrong configuration. Cannot find the VNC host' }
}
config.port = vmInfo.TEMPLATE?.GRAPHICS?.PORT
config.password = vmInfo.TEMPLATE?.GRAPHICS?.PASSWD ?? null
return config
@@ -297,7 +307,7 @@ const getSshSettings = (vmInfo, authUser) => {
return { error: 'Wrong configuration. Cannot find a NIC with SSH' }
}
config.port ??= vmInfo.TEMPLATE?.CONTEXT?.SSH_PORT ?? '22'
config.port ??= vmInfo.TEMPLATE?.CONTEXT?.SSH_PORT
if (vmInfo.TEMPLATE?.CONTEXT?.SSH_PUBLIC_KEY) {
config['private-key'] = authUser?.TEMPLATE?.SSH_PRIVATE_KEY
@@ -323,34 +333,30 @@ const getRdpSettings = (vmInfo) => {
if (!config.hostname) {
return { error: 'Wrong configuration. Cannot find a NIC with RDP' }
}
config.security = vmInfo.TEMPLATE?.CONTEXT?.RDP_SECURITY ?? 'rdp'
config.port = vmInfo.TEMPLATE?.CONTEXT?.RDP_PORT ?? '3389'
config.security = vmInfo.TEMPLATE?.CONTEXT?.RDP_SECURITY
config.port = vmInfo.TEMPLATE?.CONTEXT?.RDP_PORT
config.username = vmInfo.TEMPLATE?.CONTEXT?.USERNAME
config.password = vmInfo.TEMPLATE?.CONTEXT?.PASSWORD
config['server-layout'] = nicWithRdp?.RDP_SERVER_LAYOUT
config['resize-method'] = nicWithRdp?.RDP_RESIZE_METHOD ?? 'display-update'
config['disable-audio'] =
nicWithRdp?.RDP_DISABLE_AUDIO?.toLowerCase() === 'yes'
config['enable-audio-input'] =
nicWithRdp?.RDP_ENABLE_AUDIO_INPUT?.toLowerCase() === 'yes'
config['enable-wallpaper'] =
nicWithRdp?.RDP_ENABLE_WALLPAPER?.toLowerCase() === 'yes'
config['enable-theming'] =
nicWithRdp?.RDP_ENABLE_THEMING?.toLowerCase() === 'yes'
config['enable-font-smoothing'] =
nicWithRdp?.RDP_ENABLE_FONT_SMOOTHING?.toLowerCase() === 'yes'
config['enable-full-window-drag'] =
nicWithRdp?.RDP_ENABLE_FULL_WINDOW_DRAG?.toLowerCase() === 'yes'
config['enable-desktop-composition'] =
nicWithRdp?.RDP_ENABLE_DESKTOP_COMPOSITION?.toLowerCase() === 'yes'
config['enable-menu-animations'] =
nicWithRdp?.RDP_ENABLE_MENU_ANIMATIONS?.toLowerCase() === 'yes'
config['disable-bitmap-caching'] =
nicWithRdp?.RDP_DISABLE_BITMAP_CACHING?.toLowerCase() === 'yes'
config['disable-offscreen-caching'] =
nicWithRdp?.RDP_DISABLE_OFFSCREEN_CACHING?.toLowerCase() === 'yes'
config['disable-glyph-caching'] =
nicWithRdp?.RDP_DISABLE_GLYPH_CACHING?.toLowerCase() === 'yes'
config['resize-method'] = nicWithRdp?.RDP_RESIZE_METHOD
const flags = [
'disable-audio',
'enable-audio-input',
'enable-wallpaper',
'enable-theming',
'enable-font-smoothing',
'enable-full-window-drag',
'enable-desktop-composition',
'enable-menu-animations',
'disable-bitmap-caching',
'disable-offscreen-caching',
'disable-glyph-caching',
]
flags.forEach((flag) => {
const value = nicWithRdp?.[`RDP_${flag.toUpperCase().replace(/-/g, '_')}`]
if (value !== undefined) config[flag] = value.toLowerCase() === 'yes'
})
return config
}
@@ -31,7 +31,7 @@ genPathResources()
genFireedgeKey()
const formatError = 'Error: %s'
const allowedConnectionTypes = new Set(['vnc', 'ssh', 'rdp', 'telnet'])
const allowedConnectionTypes = new Set(['vnc', 'ssh', 'rdp'])
const maxTokenLength = 64 * 1024
/**
* Object console error log.
@@ -63,15 +63,6 @@ const clientOptions = {
'dpi',
'rangeports',
],
telnet: [
'color-scheme',
'font-name',
'font-size',
'width',
'height',
'dpi',
'rangeports',
],
},
log: {
level: 'ERRORS',
@@ -125,6 +116,7 @@ const verifyGuacamoleClient = ({ req } = {}) => {
const connectionSettings = settings?.connection?.settings
if (!allowedConnectionTypes.has(connectionType)) return false
if (settings.protocol !== connectionType) return false
if (
!connectionSettings ||
typeof connectionSettings !== 'object' ||
@@ -154,6 +146,29 @@ const clientCallbacks = {
return callback(new Error('Token expired'))
}
if (!allowedConnectionTypes.has(settings?.protocol)) {
return callback(new Error('Invalid Guacamole protocol'))
}
// Apply current server policy after the bridge merges token/query values.
const enforced = getFireedgeConfig().guacamole?.enforced
settings.connection = {
...settings.connection,
...enforced?.common,
...enforced?.[settings.protocol],
}
// The bridge treats false/0 as absent. Send scalar values as Guacamole
// strings so explicit YAML booleans and numeric values survive unchanged.
settings.connection = Object.fromEntries(
Object.entries(settings.connection).map(([key, value]) => [
key,
typeof value === 'boolean' || typeof value === 'number'
? String(value)
: value,
])
)
let rangePorts = [5900, 65535]
if (settings?.connection?.rangeports) {
rangePorts = settings?.connection?.rangeports.split(':').map(Number)
@@ -230,6 +245,12 @@ const guacamole = (appServer) => {
clientOptions,
clientCallbacks
)
// Replace the dependency's hardcoded port/display defaults. "args" is
// the Guacamole handshake opcode, not a configurable connection parameter.
guacamoleServer.clientOptions.connectionDefaultSettings =
Object.fromEntries(
[...allowedConnectionTypes].map((type) => [type, { args: 'connect' }])
)
guacamoleServer.on('error', (_, error) => {
writeInLogger(error, {
format: formatError,