diff options
author | Daniel Baumann <daniel.baumann@open-infrastructure.net> | 2017-06-27 07:54:18 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@open-infrastructure.net> | 2017-06-29 06:24:45 +0000 |
commit | 9043fe8236f6106eaab10ed4170bdf04050d1eca (patch) | |
tree | de0e8945d7ed6b734120567f456da549c1916e65 | |
parent | Executing auto commands only when cnt.auto=true and cnt.container-server matc... (diff) | |
download | compute-tools-9043fe8236f6106eaab10ed4170bdf04050d1eca.tar.xz compute-tools-9043fe8236f6106eaab10ed4170bdf04050d1eca.zip |
Adding CONTAINER_COMMANDS_ENABLE variable for container-shell to add support for allowing certain container commands for a specific container-shell invocation only.
Use case: Allow some people (via their SSH key) to only execute some
but not all commands, e.g. container start and container-stop but
not container create and container remove.
Signed-off-by: Daniel Baumann <daniel.baumann@open-infrastructure.net>
-rwxr-xr-x | bin/container-shell | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/bin/container-shell b/bin/container-shell index 17c0849..c27a0e3 100755 --- a/bin/container-shell +++ b/bin/container-shell @@ -85,10 +85,34 @@ Shell () then echo "'${COMMAND}': no such ${PROGRAM} command" >&2 return - else - echo - sudo ${PROGRAM} ${COMMAND} ${OPTIONS} || true fi + + if [ -n "${CONTAINER_COMMANDS_ENABLE}" ] + then + COMMAND_ALLOWED="" + + for CONTAINER_COMMAND in ${CONTAINER_COMMANDS_ENABLE} + do + case "${CONTAINER_COMMAND}" in + ${COMMAND}|all|about|logout|exit|help) + COMMAND_ALLOWED="true" + ;; + esac + done + + case "${COMMAND_ALLOWED}" in + true) + ;; + + *) + echo "'${COMMAND}': command not allowed for current user" >&2 + return + ;; + esac + fi + + echo + sudo ${PROGRAM} ${COMMAND} ${OPTIONS} || true } trap 'echo' EXIT HUP INT QUIT TERM |