diff --git a/ci-scripts/template-vars.yaml b/ci-scripts/template-vars.yaml index 157e6ee..9a48943 100644 --- a/ci-scripts/template-vars.yaml +++ b/ci-scripts/template-vars.yaml @@ -1,6 +1,8 @@ files: &UNIVERSAL_CHANGE_FILES - src/common/** - src/common/startup_scripts/** + - src/common/scripts/** + - src/common/scripts/kasm_hook_scripts/** - src/ubuntu/install/audio/** - src/ubuntu/install/audio_input/** - src/ubuntu/install/cleanup/** @@ -18,6 +20,7 @@ files: &UNIVERSAL_CHANGE_FILES - src/ubuntu/install/squid/** - src/ubuntu/install/tools/** - src/ubuntu/install/webcam/** + - src/ubuntu/install/recorder/** - ci-scripts/** - .gitlab-ci.yml diff --git a/dockerfile-kasm-core b/dockerfile-kasm-core index 2e1a2c5..69e0556 100644 --- a/dockerfile-kasm-core +++ b/dockerfile-kasm-core @@ -87,12 +87,16 @@ RUN bash $INST_SCRIPTS/gamepad/install_gamepad.sh && rm -rf $INST_SCRIPTS/gamepa COPY ./src/ubuntu/install/webcam $INST_SCRIPTS/webcam/ RUN bash $INST_SCRIPTS/webcam/install_webcam.sh && rm -rf $INST_SCRIPTS/webcam/ -### Install Printer +### Install Printer Service COPY ./src/ubuntu/install/printer $INST_SCRIPTS/printer/ COPY ./src/ubuntu/install/printer/start_cups.sh /etc/cups/start_cups.sh RUN bash $INST_SCRIPTS/printer/install_printer.sh && rm -rf $INST_SCRIPTS/printer COPY ./src/ubuntu/install/printer/resources/*.ppd /etc/cups/ppd/ +### Install Recorder Service +COPY ./src/ubuntu/install/recorder $INST_SCRIPTS/recorder/ +RUN bash $INST_SCRIPTS/recorder/install_recorder.sh && rm -rf $INST_SCRIPTS/recorder + ### Install custom cursors COPY ./src/ubuntu/install/cursors $INST_SCRIPTS/cursors/ RUN bash $INST_SCRIPTS/cursors/install_cursors.sh && rm -rf $INST_SCRIPTS/cursors/ @@ -140,6 +144,11 @@ ENV HOME=/home/kasm-user WORKDIR $HOME RUN mkdir -p $HOME && chown -R 1000:0 $HOME +### Create user exclusively for session recording purposes +RUN (groupadd -g 1001 kasm-recorder \ + && useradd -M -u 1001 -g 1001 kasm-recorder \ + && usermod -a -G kasm-recorder) ; exit 0 + ### FIX PERMISSIONS ## Objective is to change the owner of non-home paths to root, remove write permissions, and set execute where required # these files are created on container first exec, by the default user, so we have to create them since default will not have write perm RUN touch $STARTUPDIR/wm.log \ @@ -159,6 +168,7 @@ RUN touch $STARTUPDIR/wm.log \ && chmod 755 $STARTUPDIR/gamepad/kasm_gamepad_server \ && chmod 755 $STARTUPDIR/webcam/kasm_webcam_server \ && chmod 755 $STARTUPDIR/printer/kasm_printer_service \ + && chmod 755 $STARTUPDIR/recorder/kasm_recorder_service \ && chmod 755 $STARTUPDIR/generate_container_user \ && chmod +x $STARTUPDIR/jsmpeg/kasm_audio_out-linux \ && rm -rf $STARTUPDIR/install \ diff --git a/dockerfile-kasm-core-alpine b/dockerfile-kasm-core-alpine index 8654d58..d97b5b9 100644 --- a/dockerfile-kasm-core-alpine +++ b/dockerfile-kasm-core-alpine @@ -89,12 +89,16 @@ RUN bash $INST_SCRIPTS/gamepad/install_gamepad.sh && rm -rf $INST_SCRIPTS/gamepa COPY ./src/ubuntu/install/webcam $INST_SCRIPTS/webcam/ RUN bash $INST_SCRIPTS/webcam/install_webcam.sh && rm -rf $INST_SCRIPTS/webcam/ -### Install Printer +### Install Printer Service COPY ./src/ubuntu/install/printer $INST_SCRIPTS/printer/ COPY ./src/ubuntu/install/printer/start_cups.sh /etc/cups/start_cups.sh RUN bash $INST_SCRIPTS/printer/install_printer.sh && rm -rf $INST_SCRIPTS/printer COPY ./src/ubuntu/install/printer/resources/*.ppd /etc/cups/ppd/ +### Install Recorder Service +COPY ./src/ubuntu/install/recorder $INST_SCRIPTS/recorder/ +RUN bash $INST_SCRIPTS/recorder/install_recorder.sh && rm -rf $INST_SCRIPTS/recorder + ### Copy built Squid COPY --from=squid_builder /usr/local/squid /usr/local/squid @@ -134,6 +138,11 @@ ENV HOME /home/kasm-user WORKDIR $HOME RUN mkdir -p $HOME && chown -R 1000:0 $HOME +### Create user exclusively for session recording purposes +RUN (groupadd -g 1001 kasm-recorder \ + && useradd -M -u 1001 -g 1001 kasm-recorder \ + && usermod -a -G kasm-recorder) ; exit 0 + ### FIX PERMISSIONS ## Objective is to change the owner of non-home paths to root, remove write permissions, and set execute where required # these files are created on container first exec, by the default user, so we have to create them since default will not have write perm RUN touch $STARTUPDIR/wm.log \ @@ -154,6 +163,7 @@ RUN touch $STARTUPDIR/wm.log \ && chmod 755 $STARTUPDIR/webcam/kasm_webcam_server \ && chmod 755 $STARTUPDIR/generate_container_user \ && chmod 755 $STARTUPDIR/printer/kasm_printer_service \ + && chmod 755 $STARTUPDIR/recorder/kasm_recorder_service \ && chmod +x $STARTUPDIR/jsmpeg/kasm_audio_out-linux \ && rm -rf $STARTUPDIR/install \ && mkdir -p $STARTUPDIR/kasmrx/Downloads \ diff --git a/dockerfile-kasm-core-centos b/dockerfile-kasm-core-centos index 70ab0c9..64d5544 100644 --- a/dockerfile-kasm-core-centos +++ b/dockerfile-kasm-core-centos @@ -91,12 +91,16 @@ RUN bash $INST_SCRIPTS/gamepad/install_gamepad.sh && rm -rf $INST_SCRIPTS/gamepa COPY ./src/ubuntu/install/webcam $INST_SCRIPTS/webcam/ RUN bash $INST_SCRIPTS/webcam/install_webcam.sh && rm -rf $INST_SCRIPTS/webcam/ -### Install Printer +### Install Printer Service COPY ./src/ubuntu/install/printer $INST_SCRIPTS/printer/ COPY ./src/ubuntu/install/printer/start_cups.sh /etc/cups/start_cups.sh RUN bash $INST_SCRIPTS/printer/install_printer.sh && rm -rf $INST_SCRIPTS/printer COPY ./src/ubuntu/install/printer/resources/*.ppd /etc/cups/ppd/ +### Install Recorder Service +COPY ./src/ubuntu/install/recorder $INST_SCRIPTS/recorder/ +RUN bash $INST_SCRIPTS/recorder/install_recorder.sh && rm -rf $INST_SCRIPTS/recorder + ### Copy built Squid COPY --from=squid_builder /usr/local/squid /usr/local/squid @@ -136,6 +140,11 @@ ENV HOME /home/kasm-user WORKDIR $HOME RUN mkdir -p $HOME && chown -R 1000:0 $HOME +### Create user exclusively for session recording purposes +RUN (groupadd -g 1001 kasm-recorder \ + && useradd -M -u 1001 -g 1001 kasm-recorder \ + && usermod -a -G kasm-recorder) ; exit 0 + ### FIX PERMISSIONS ## Objective is to change the owner of non-home paths to root, remove write permissions, and set execute where required # these files are created on container first exec, by the default user, so we have to create them since default will not have write perm RUN touch $STARTUPDIR/wm.log \ @@ -156,6 +165,7 @@ RUN touch $STARTUPDIR/wm.log \ && chmod 755 $STARTUPDIR/webcam/kasm_webcam_server \ && chmod 755 $STARTUPDIR/generate_container_user \ && chmod 755 $STARTUPDIR/printer/kasm_printer_service \ + && chmod 755 $STARTUPDIR/recorder/kasm_recorder_service \ && chmod +x $STARTUPDIR/jsmpeg/kasm_audio_out-linux \ && rm -rf $STARTUPDIR/install \ && mkdir -p $STARTUPDIR/kasmrx/Downloads \ diff --git a/dockerfile-kasm-core-fedora b/dockerfile-kasm-core-fedora index 8309d1a..e11d733 100644 --- a/dockerfile-kasm-core-fedora +++ b/dockerfile-kasm-core-fedora @@ -99,12 +99,16 @@ RUN bash $INST_SCRIPTS/gamepad/install_gamepad.sh && rm -rf $INST_SCRIPTS/gamepa COPY ./src/ubuntu/install/webcam $INST_SCRIPTS/webcam/ RUN bash $INST_SCRIPTS/webcam/install_webcam.sh && rm -rf $INST_SCRIPTS/webcam/ -### Install Printer +### Install Printer Service COPY ./src/ubuntu/install/printer $INST_SCRIPTS/printer/ COPY ./src/ubuntu/install/printer/start_cups.sh /etc/cups/start_cups.sh RUN bash $INST_SCRIPTS/printer/install_printer.sh && rm -rf $INST_SCRIPTS/printer COPY ./src/ubuntu/install/printer/resources/*.ppd /etc/cups/ppd/ +### Install Recorder Service +COPY ./src/ubuntu/install/recorder $INST_SCRIPTS/recorder/ +RUN bash $INST_SCRIPTS/recorder/install_recorder.sh && rm -rf $INST_SCRIPTS/recorder + ### Copy built Squid COPY --from=squid_builder /usr/local/squid /usr/local/squid @@ -144,6 +148,11 @@ ENV HOME /home/kasm-user WORKDIR $HOME RUN mkdir -p $HOME && chown -R 1000:0 $HOME +### Create user exclusively for session recording purposes +RUN (groupadd -g 1001 kasm-recorder \ + && useradd -M -u 1001 -g 1001 kasm-recorder \ + && usermod -a -G kasm-recorder) ; exit 0 + ### FIX PERMISSIONS ## Objective is to change the owner of non-home paths to root, remove write permissions, and set execute where required # these files are created on container first exec, by the default user, so we have to create them since default will not have write perm RUN touch $STARTUPDIR/wm.log \ @@ -164,6 +173,7 @@ RUN touch $STARTUPDIR/wm.log \ && chmod 755 $STARTUPDIR/webcam/kasm_webcam_server \ && chmod 755 $STARTUPDIR/generate_container_user \ && chmod 755 $STARTUPDIR/printer/kasm_printer_service \ + && chmod 755 $STARTUPDIR/recorder/kasm_recorder_service \ && chmod +x $STARTUPDIR/jsmpeg/kasm_audio_out-linux \ && rm -rf $STARTUPDIR/install \ && mkdir -p $STARTUPDIR/kasmrx/Downloads \ diff --git a/dockerfile-kasm-core-oracle b/dockerfile-kasm-core-oracle index 42bdfcb..3718606 100644 --- a/dockerfile-kasm-core-oracle +++ b/dockerfile-kasm-core-oracle @@ -114,12 +114,16 @@ RUN bash $INST_SCRIPTS/gamepad/install_gamepad.sh && rm -rf $INST_SCRIPTS/gamepa COPY ./src/ubuntu/install/webcam $INST_SCRIPTS/webcam/ RUN bash $INST_SCRIPTS/webcam/install_webcam.sh && rm -rf $INST_SCRIPTS/webcam/ -### Install Printer +### Install Printer Service COPY ./src/ubuntu/install/printer $INST_SCRIPTS/printer/ COPY ./src/ubuntu/install/printer/start_cups.sh /etc/cups/start_cups.sh RUN bash $INST_SCRIPTS/printer/install_printer.sh && rm -rf $INST_SCRIPTS/printer COPY ./src/ubuntu/install/printer/resources/*.ppd /etc/cups/ppd/ +### Install Recorder Service +COPY ./src/ubuntu/install/recorder $INST_SCRIPTS/recorder/ +RUN bash $INST_SCRIPTS/recorder/install_recorder.sh && rm -rf $INST_SCRIPTS/recorder + ### Copy built Squid COPY --from=squid_builder /usr/local/squid /usr/local/squid @@ -163,6 +167,11 @@ ENV HOME /home/kasm-user WORKDIR $HOME RUN mkdir -p $HOME && chown -R 1000:0 $HOME +### Create user exclusively for session recording purposes +RUN (groupadd -g 1001 kasm-recorder \ + && useradd -M -u 1001 -g 1001 kasm-recorder \ + && usermod -a -G kasm-recorder) ; exit 0 + ### FIX PERMISSIONS ## Objective is to change the owner of non-home paths to root, remove write permissions, and set execute where required # these files are created on container first exec, by the default user, so we have to create them since default will not have write perm RUN touch $STARTUPDIR/wm.log \ @@ -183,6 +192,7 @@ RUN touch $STARTUPDIR/wm.log \ && chmod 755 $STARTUPDIR/webcam/kasm_webcam_server \ && chmod 755 $STARTUPDIR/generate_container_user \ && chmod 755 $STARTUPDIR/printer/kasm_printer_service \ + && chmod 755 $STARTUPDIR/recorder/kasm_recorder_service \ && chmod +x $STARTUPDIR/jsmpeg/kasm_audio_out-linux \ && rm -rf $STARTUPDIR/install \ && mkdir -p $STARTUPDIR/kasmrx/Downloads \ diff --git a/dockerfile-kasm-core-suse b/dockerfile-kasm-core-suse index f5997c6..2d1490f 100644 --- a/dockerfile-kasm-core-suse +++ b/dockerfile-kasm-core-suse @@ -89,12 +89,16 @@ RUN bash $INST_SCRIPTS/gamepad/install_gamepad.sh && rm -rf $INST_SCRIPTS/gamepa COPY ./src/ubuntu/install/webcam $INST_SCRIPTS/webcam/ RUN bash $INST_SCRIPTS/webcam/install_webcam.sh && rm -rf $INST_SCRIPTS/webcam/ -### Install Printer +### Install Printer Service COPY ./src/ubuntu/install/printer $INST_SCRIPTS/printer/ COPY ./src/ubuntu/install/printer/start_cups.sh /etc/cups/start_cups.sh RUN bash $INST_SCRIPTS/printer/install_printer.sh && rm -rf $INST_SCRIPTS/printer COPY ./src/ubuntu/install/printer/resources/*.ppd /etc/cups/ppd/ +### Install Recorder Service +COPY ./src/ubuntu/install/recorder $INST_SCRIPTS/recorder/ +RUN bash $INST_SCRIPTS/recorder/install_recorder.sh && rm -rf $INST_SCRIPTS/recorder + ### Copy built Squid COPY --from=squid_builder /usr/local/squid /usr/local/squid @@ -138,6 +142,11 @@ ENV HOME /home/kasm-user WORKDIR $HOME RUN mkdir -p $HOME && chown -R 1000:0 $HOME +### Create user exclusively for session recording purposes +RUN (groupadd -g 1001 kasm-recorder \ + && useradd -M -u 1001 -g 1001 kasm-recorder \ + && usermod -a -G kasm-recorder) ; exit 0 + ### FIX PERMISSIONS ## Objective is to change the owner of non-home paths to root, remove write permissions, and set execute where required # these files are created on container first exec, by the default user, so we have to create them since default will not have write perm RUN touch $STARTUPDIR/wm.log \ @@ -158,6 +167,7 @@ RUN touch $STARTUPDIR/wm.log \ && chmod 755 $STARTUPDIR/webcam/kasm_webcam_server \ && chmod 755 $STARTUPDIR/generate_container_user \ && chmod 755 $STARTUPDIR/printer/kasm_printer_service \ + && chmod 755 $STARTUPDIR/recorder/kasm_recorder_service \ && chmod +x $STARTUPDIR/jsmpeg/kasm_audio_out-linux \ && rm -rf $STARTUPDIR/install \ && mkdir -p $STARTUPDIR/kasmrx/Downloads \ diff --git a/src/common/scripts/kasm_hook_scripts/kasm_recorder_lifecycle_root.sh b/src/common/scripts/kasm_hook_scripts/kasm_recorder_lifecycle_root.sh new file mode 100644 index 0000000..80a3603 --- /dev/null +++ b/src/common/scripts/kasm_hook_scripts/kasm_recorder_lifecycle_root.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +action=$1 + +pid=$(pgrep -f '^/dockerstartup/recorder/kasm_recorder_service') + +case $action in + "stop"|"pause") + if [ -z "$pid" ]; then + echo "No recording process found." + exit 0 + fi + + kill -s SIGINT $pid + while [ ! -f "/tmp/kasm_recorder.ack" ]; do + sleep 1 + done + ;; + "resume") + if [ ! -z "$pid" ]; then + echo "Recording process already running." + exit 0 + fi + kill `pgrep -f "kasm_recorder_startup.sh"` + /dockerstartup/kasm_recorder_startup.sh & + ;; + *) + echo "Usage: $0 {stop|pause|resume}" + exit 1 + ;; +esac \ No newline at end of file diff --git a/src/common/scripts/kasm_hook_scripts/kasm_recorder_startup.sh b/src/common/scripts/kasm_hook_scripts/kasm_recorder_startup.sh new file mode 100755 index 0000000..7a71b15 --- /dev/null +++ b/src/common/scripts/kasm_hook_scripts/kasm_recorder_startup.sh @@ -0,0 +1,18 @@ +#!/bin/bash +set -e + +mkdir -p /opt/kasm/recordings +sudo chown kasm-recorder:kasm-recorder /opt/kasm/recordings +sudo chmod 700 /opt/kasm/recordings + +# wait until X display is avaiable and allow the recorder to connect to it +while ! xhost +SI:localuser:kasm-recorder 2>/dev/null; do + sleep 1 +done + +rm -rf /tmp/kasm_recorder.ack + +while [ ! -f "/tmp/kasm_recorder.ack" ]; do + runuser -m kasm-recorder -c "$STARTUPDIR/recorder/kasm_recorder_service --debug 1 --directory /opt/kasm/recordings/ --log /tmp/recorder.log" || true + sleep 1 +done diff --git a/src/ubuntu/install/recorder/install_recorder.sh b/src/ubuntu/install/recorder/install_recorder.sh new file mode 100644 index 0000000..6bc0f0d --- /dev/null +++ b/src/ubuntu/install/recorder/install_recorder.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +### every exit != 0 fails the script +set -e + +COMMIT_ID="b9f195d8aac56b3127be9083470bddc360e30377" +BRANCH="main" +COMMIT_ID_SHORT=$(echo "${COMMIT_ID}" | cut -c1-6) + +ARCH=$(arch | sed 's/aarch64/arm64/g' | sed 's/x86_64/amd64/g') + +mkdir -p $STARTUPDIR/recorder +wget -qO- https://kasmweb-build-artifacts.s3.amazonaws.com/kasm_recorder_service/${COMMIT_ID}/kasm_recorder_service_${ARCH}_${BRANCH}.${COMMIT_ID_SHORT}.tar.gz | tar -xvz -C $STARTUPDIR/recorder/ +echo "${BRANCH}:${COMMIT_ID}" > $STARTUPDIR/recorder/kasm_recorder_service.version