Skip to content

Workbench

posit-workbench

Reports on Workbench and its Job Launcher. It prints the version (rstudio-server version needs no root)1 and the state of the rstudio-server and rstudio-launcher services. It shows rserver.conf, rsession.conf, repos.conf, r-versions, launcher.conf, and logging.conf from /etc/rstudio, and the mode of database.conf. It then checks:

  • rserver: whether anything listens on the www-address and www-port (default 8787, or 443 when ssl-enabled=1). A note appears when rserver listens on loopback only, because it then needs a reverse proxy on the same host.2
  • rserver to launcher: whether launcher-address, launcher-port, and launcher-use-ssl in rserver.conf agree with address, port, and enable-ssl in launcher.conf, and whether the launcher is listening. It flags launcher-verify-ssl-certs or launcher-sessions-callback-verify-ssl-certs when either turns certificate verification off; Posit recommends leaving both at 1 outside testing.3 It also checks whether the launcher-sessions-callback-address answers and shows the subject, issuer, and expiry of the launcher certificate.
  • The owner and mode of the secure cookie key, which Posit requires to be mode 600 and owned by the server user.4
  • r-cran-repos, r-cran-repos-url, and allow-r-cran-repos-edit, and whether the repository URLs answer.5
  • The Workbench and Launcher log directories, and free space under /var/lib/rstudio-server.

database.conf is mode 600 and owned by root,6 and rstudio-server active-sessions requires root,7 so both checks are deferred. So is reading the launcher certificate and key when your account cannot.

posit-workbench

The script needs posit-lib.sh in the same directory.

Source: scripts/posit-workbench
#!/bin/bash
#
# posit-workbench: report on Posit Workbench and its Job Launcher without root.
#
# Shows the version, services, configuration files, listening ports, the
# rserver to launcher settings, the launcher certificate, repository URLs,
# and logs. Checks that need root are printed at the end as commands for
# the sudo administrator.
#
# Usage: posit-workbench
#

# Report scripts keep going when one check fails, so -e is not set
set -uo pipefail

# shellcheck source=posit-lib.sh
. "$(dirname "$(readlink -f "$0")")/posit-lib.sh" || exit 1

readonly CONF_DIR="${POSIT_WB_CONF_DIR:-/etc/rstudio}"
readonly RSERVER="${CONF_DIR}/rserver.conf"
readonly RSESSION="${CONF_DIR}/rsession.conf"
readonly LAUNCHER="${CONF_DIR}/launcher.conf"
readonly CONF_FILES=(
  rserver.conf rsession.conf repos.conf r-versions launcher.conf logging.conf
)

#######################################
# Compare the launcher settings in rserver.conf and launcher.conf.
# Globals:
#   RSERVER
#   LAUNCHER
#######################################
launcher_report() {
  local l_addr
  local l_port
  local l_ssl
  local w_addr
  local w_port
  local w_ssl
  local k
  local v
  local callback

  header "rserver to launcher"
  if [[ ! -r "${LAUNCHER}" ]]; then
    item "launcher.conf" "not readable or not present; skipping"
    return
  fi
  l_addr="$(ini_value "${LAUNCHER}" address)"
  l_port="$(ini_value "${LAUNCHER}" port)"
  l_ssl="$(ini_value "${LAUNCHER}" enable-ssl)"
  w_addr="$(ini_value "${RSERVER}" launcher-address)"
  w_port="$(ini_value "${RSERVER}" launcher-port)"
  w_ssl="$(ini_value "${RSERVER}" launcher-use-ssl)"
  item "launcher.conf address:port" "${l_addr:-not set}:${l_port:-not set}"
  item "rserver.conf launcher" "${w_addr:-not set}:${w_port:-not set}"
  if [[ -n "${l_port}" && -n "${w_port}" && "${l_port}" != "${w_port}" ]]; then
    warn "launcher-port (${w_port}) does not match the launcher port" \
      "(${l_port})"
  fi
  item "launcher.conf enable-ssl" "${l_ssl:-not set}"
  item "rserver.conf launcher-use-ssl" "${w_ssl:-not set}"
  if [[ -n "${l_ssl}" && -n "${w_ssl}" && "${l_ssl}" != "${w_ssl}" ]]; then
    warn "enable-ssl and launcher-use-ssl differ"
  fi
  [[ -n "${l_port}" ]] && check_listen "launcher" "${l_addr:-not set}" \
    "${l_port}"
  for k in launcher-verify-ssl-certs \
    launcher-sessions-callback-verify-ssl-certs; do
    v="$(ini_value "${RSERVER}" "${k}")"
    item "${k}" "${v:-not set}"
    [[ "${v}" == "0" ]] && note "${k}=0: certificate verification is" \
      "turned off"
  done
  callback="$(ini_value "${RSERVER}" launcher-sessions-callback-address)"
  [[ -n "${callback}" ]] && http_check "callback address" "${callback}"
  cert_check "launcher certificate" \
    "$(ini_value "${LAUNCHER}" certificate-file)" \
    "$(ini_value "${LAUNCHER}" certificate-key-file)"
}

main() {
  local f
  local www_addr
  local www_port
  local key_file
  local key_rule='(Posit requires mode 600, owned by the server user)'
  local k
  local v
  local repos
  local repos_url

  report_start "Posit Workbench report"

  header "Version and services"
  if command -v rstudio-server >/dev/null 2>&1; then
    item "Version" "$(rstudio-server version 2>/dev/null || echo unknown)"
  else
    item "Version" "rstudio-server not on the PATH"
  fi
  unit_status rstudio-server
  unit_status rstudio-launcher

  header "Configuration files"
  for f in "${CONF_FILES[@]}"; do
    config_file "${f}" "${CONF_DIR}/${f}"
  done
  # database.conf holds the database password and should be mode 0600
  if [[ -e "${CONF_DIR}/database.conf" ]]; then
    item "database.conf mode" "$(file_mode "${CONF_DIR}/database.conf")"
  fi
  config_file "database.conf" "${CONF_DIR}/database.conf"

  header "Listening address"
  www_addr="$(ini_value "${RSERVER}" www-address)"
  www_port="$(ini_value "${RSERVER}" www-port)"
  check_listen "rserver" "${www_addr:-not set}" "${www_port:-8787}"
  if [[ "${www_addr}" == "127.0.0.1" ]]; then
    note "rserver listens on loopback only, so users reach it through a" \
      "reverse proxy"
  fi

  launcher_report

  header "Secure cookie key"
  key_file="$(ini_value "${RSERVER}" secure-cookie-key-file)"
  key_file="${key_file:-/etc/rstudio/secure-cookie-key}"
  item "${key_file}" "$(file_mode "${key_file}") ${key_rule}"

  header "Package repositories"
  for k in r-cran-repos r-cran-repos-url allow-r-cran-repos-edit; do
    v="$(ini_value "${RSESSION}" "${k}")"
    item "${k}" "${v:-not set}"
  done
  repos="$(ini_value "${RSESSION}" r-cran-repos)"
  repos_url="$(ini_value "${RSESSION}" r-cran-repos-url)"
  [[ -n "${repos}" ]] && http_check "r-cran-repos" "${repos%%|*}"
  [[ -n "${repos_url}" ]] && http_check "r-cran-repos-url" "${repos_url}"

  header "Logs and data"
  log_dir "Workbench logs" /var/log/rstudio/rstudio-server
  log_dir "Launcher logs" /var/log/rstudio/launcher
  dir_size "Workbench data" /var/lib/rstudio-server
  defer "Active sessions" "sudo rstudio-server active-sessions"

  print_deferred
}

main "$@"