Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable gs-root-shell.service to automatically configure the secret #104

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions examples/systemd-root-shell/gs-root-shell.service
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
[Unit]
Description=Global Socket Root Shell
After=network.target
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
Restart=always
RestartSec=10
RestartSteps=10
RestartMaxDelaySec=30m
WorkingDirectory=/root
ExecStart=gs-netcat -k /etc/systemd/gs-root-shell-key.txt -il
ExecStartPre=gs-init-secret /etc/gsocket/gs-root-shell-key
ExecStart=gs-netcat -k /etc/gsocket/gs-root-shell-key -il

[Install]
WantedBy=multi-user.target
2 changes: 1 addition & 1 deletion tools/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ gs_netcat_SOURCES = 4_gs-netcat.c utils.c socks.c console.c ids.c event_mgr.c pk
gs_netcat_LDADD = ../lib/libgsocket.a @LDADD_STATIC@
gs_netcat_CFLAGS = @CFLAGS_STATIC@

dist_bin_SCRIPTS = blitz gs-sftp gs-mount gsocket
dist_bin_SCRIPTS = blitz gs-sftp gs-mount gsocket gs-init-secret

gsocket_uchroot_dso_so_0_SOURCES = gsocket_uchroot_dso.c
gsocket_uchroot_dso_so_0_CFLAGS = -shared -fPIC
Expand Down
33 changes: 33 additions & 0 deletions tools/gs-init-secret
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
set -eu

if [[ $# -eq 2 ]]; then
>&2 echo "ERROR: Must provide exactly one argument"
exit 1
fi

SECRET_FILE="${1}"

if [[ -f "${SECRET_FILE}" ]]; then
SECRET_FILE_PERMS="$(stat -c %a "${SECRET_FILE}")"
if [[ ${SECRET_FILE_PERMS} != [0-9][0-9]0 ]]; then
>&2 echo "ERROR: ${SECRET_FILE} has world-permissions set (${SECRET_FILE_PERMS})"
exit 1
fi

exit
fi

TARGET_DIR="$(dirname "${SECRET_FILE}")"
if [[ ! -d "${TARGET_DIR}" ]]; then
mkdir -p "${TARGET_DIR}"
fi

MY_TMPDIR=$(mktemp -d --tmpdir="${TMPDIR:-/tmp}")
trap 'rm -rf ${MY_TMPDIR}' EXIT

SECRET_FILE_TMP="${MY_TMPDIR}/secret"

gs-netcat -g > "${SECRET_FILE_TMP}"

install --mode=400 "${SECRET_FILE_TMP}" "${SECRET_FILE}"