Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

feat(prosody): use sip-outbound-call for jibri sip gateway requests

damenchoabe8abebd221
diff --git a/resources/prosody-plugins/mod_filter_iq_jibri.lua b/resources/prosody-plugins/mod_filter_iq_jibri.lua
index 8b908e2dae..0a9de713bf 100644
--- a/resources/prosody-plugins/mod_filter_iq_jibri.lua
+++ b/resources/prosody-plugins/mod_filter_iq_jibri.lua
@@ -1,9 +1,10 @@
-- Filters Jibri recording/livestreaming IQ stanzas (http://jitsi.org/protocol/jibri)
-- on the main VirtualHost. start/stop actions are allowed only when the sender's JWT
--- token grants the required feature ('recording' for file mode, 'livestreaming' for
--- stream mode), or, absent token features, when the sender holds moderator role in the
--- room. status IQs are always passed through. Blocked stanzas receive an
--- auth/forbidden error reply. Rate-limited per IP and per room.
+-- token grants the required feature ('sip-outbound-call' when a sipaddress is present,
+-- otherwise 'recording' for file mode and 'livestreaming' for stream mode), or, absent
+-- token features, when the sender holds moderator role in the room. status IQs are
+-- always passed through. Blocked stanzas receive an auth/forbidden error reply.
+-- Rate-limited per IP and per room.
-- This module is enabled under the main virtual host.
local cache = require 'util.cache';
local new_throttle = require 'util.throttle'.create;
@@ -44,8 +45,15 @@ module:hook("pre-iq/full", function(event)
return true;
end
local occupant = room:get_occupant_by_real_jid(stanza.attr.from);
- local recording_mode_lower = jibri.attr.recording_mode and jibri.attr.recording_mode:lower();
- local feature = recording_mode_lower == 'file' and 'recording' or 'livestreaming';
+ local feature;
+ -- jicofo handles any request with a non-blank sipaddress as a SIP gateway session,
+ -- whatever the recording_mode, so the feature follows the sipaddress first
+ if jibri.attr.sipaddress and jibri.attr.sipaddress:match('%S') then
+ feature = 'sip-outbound-call';
+ else
+ local recording_mode_lower = jibri.attr.recording_mode and jibri.attr.recording_mode:lower();
+ feature = recording_mode_lower == 'file' and 'recording' or 'livestreaming';
+ end
local is_allowed = is_feature_allowed(
feature,
session.jitsi_meet_context_features,
diff --git a/resources/prosody-plugins/mod_jitsi_permissions.lua b/resources/prosody-plugins/mod_jitsi_permissions.lua
index 42d02cfec1..92fd2dd89d 100644
--- a/resources/prosody-plugins/mod_jitsi_permissions.lua
+++ b/resources/prosody-plugins/mod_jitsi_permissions.lua
@@ -70,6 +70,7 @@ local function load_config()
recording = true;
transcription = true;
['outbound-call'] = true;
+ ['sip-outbound-call'] = true;
['create-polls'] = true;
['send-groupchat'] = true;
['send-private-message'] = true;
diff --git a/tests/prosody/mod_filter_iq_jibri_spec.js b/tests/prosody/mod_filter_iq_jibri_spec.js
index 3163375ca9..303ee33c04 100644
--- a/tests/prosody/mod_filter_iq_jibri_spec.js
+++ b/tests/prosody/mod_filter_iq_jibri_spec.js
@@ -188,6 +188,108 @@ describe('mod_filter_iq_jibri (feature-based authorization)', () => {
});
});
+ // ─── SIP gateway (sipaddress) ────────────────────────────────────────────
+ //
+ // jicofo starts a SIP gateway session for any request with a non-blank
+ // sipaddress, whatever the recording_mode, so such requests are gated by
+ // sip-outbound-call.
+
+ describe('SIP gateway (sipaddress)', () => {
+
+ const SIP_ADDRESS = 'sip:[email protected]';
+
+ /**
+ * Sends a Jibri IQ with the given <jibri/> attributes to the focus
+ * occupant and returns the Jibri IQs that reached the MUC component.
+ */
+ async function sendAttrsAndCollect(client, roomJid, attrs) {
+ await clearJibriIqs();
+ await client.sendJibriIqTo(`${roomJid}/focus`, attrs);
+ await new Promise(r => setTimeout(r, 300));
+
+ return getJibriIqs();
+ }
+
+ for (const action of [ 'start', 'stop' ]) {
+
+ it(`passes ${action} IQ when features['sip-outbound-call'] = true`, async () => {
+ const { client: c, room } = await setup({ context: { features: { 'sip-outbound-call': true } } });
+ const iqs = await sendAttrsAndCollect(c, room, { action,
+ sipaddress: SIP_ADDRESS });
+
+ assert.strictEqual(iqs.length, 1, 'IQ should reach the MUC');
+ assert.strictEqual(iqs[0].action, action);
+ });
+
+ it(`blocks ${action} IQ when features['sip-outbound-call'] = false`, async () => {
+ const { client: c, room } = await setup({ context: { features: { 'sip-outbound-call': false } } });
+ const iqs = await sendAttrsAndCollect(c, room, { action,
+ sipaddress: SIP_ADDRESS });
+
+ assert.strictEqual(iqs.length, 0);
+ });
+
+ it(`blocks ${action} IQ when only features.livestreaming = true`, async () => {
+ const { client: c, room } = await setup({ context: { features: { livestreaming: true } } });
+ const iqs = await sendAttrsAndCollect(c, room, { action,
+ sipaddress: SIP_ADDRESS });
+
+ assert.strictEqual(iqs.length, 0);
+ });
+
+ it(`blocks ${action} IQ when token has no context.features (non-moderator fallback)`, async () => {
+ const { client: c, room } = await setup();
+ const iqs = await sendAttrsAndCollect(c, room, { action,
+ sipaddress: SIP_ADDRESS });
+
+ assert.strictEqual(iqs.length, 0);
+ });
+ }
+
+ it('passes start IQ for a moderator that gets the default permissions', async () => {
+ // no context.features in the token, so mod_jitsi_permissions sets the defaults
+ const { client: c, room } = await setup({ context: { user: { moderator: true } } });
+ const iqs = await sendAttrsAndCollect(c, room, { action: 'start',
+ sipaddress: SIP_ADDRESS });
+
+ assert.strictEqual(iqs.length, 1);
+ });
+
+ it('blocks recording_mode=file with sipaddress when only features.recording = true', async () => {
+ const { client: c, room } = await setup({ context: { features: { recording: true,
+ 'sip-outbound-call': false } } });
+ const iqs = await sendAttrsAndCollect(c, room, { action: 'start',
+ // eslint-disable-next-line camelcase
+ recording_mode: 'file',
+ sipaddress: SIP_ADDRESS });
+
+ assert.strictEqual(iqs.length, 0);
+ });
+
+ it('passes recording_mode=file with sipaddress when only features[\'sip-outbound-call\'] = true', async () => {
+ const { client: c, room } = await setup({ context: { features: { recording: false,
+ 'sip-outbound-call': true } } });
+ const iqs = await sendAttrsAndCollect(c, room, { action: 'start',
+ // eslint-disable-next-line camelcase
+ recording_mode: 'file',
+ sipaddress: SIP_ADDRESS });
+
+ assert.strictEqual(iqs.length, 1);
+ });
+
+ it('gates a blank sipaddress by recording_mode', async () => {
+ // jicofo treats a blank sipaddress as a recording request
+ const { client: c, room } = await setup({ context: { features: { recording: true,
+ 'sip-outbound-call': false } } });
+ const iqs = await sendAttrsAndCollect(c, room, { action: 'start',
+ // eslint-disable-next-line camelcase
+ recording_mode: 'file',
+ sipaddress: ' ' });
+
+ assert.strictEqual(iqs.length, 1);
+ });
+ });
+
// ─── robustness: nil room ─────────────────────────────────────────────────
//
// mod_filter_iq_jibri calls get_room_from_jid() on the IQ target and then
diff --git a/tests/prosody/mod_jitsi_permissions_spec.js b/tests/prosody/mod_jitsi_permissions_spec.js
index 6579844ddf..1aeaf071ed 100644
--- a/tests/prosody/mod_jitsi_permissions_spec.js
+++ b/tests/prosody/mod_jitsi_permissions_spec.js
@@ -13,7 +13,7 @@ const nextRoom = () => `permissions-${++_roomCounter}@${CONFERENCE}`;
// Keys present in the default_permissions table in mod_jitsi_permissions.lua.
const DEFAULT_PERMISSION_KEYS = [
'livestreaming', 'recording', 'transcription',
- 'outbound-call', 'create-polls', 'send-groupchat', 'share-video', 'flip'
+ 'outbound-call', 'sip-outbound-call', 'create-polls', 'send-groupchat', 'share-video', 'flip'
];
/**