templates: improve refusing to run unprivileged

For all templates except lxc-ubuntu-cloud and lxc-download, detect not
only --mapped-uid but also --mapped-gid and error out.  Detecting will
not be done after -- parameter because of non-option parameters.

Also, change the mode of lxc-archlinux.in 100755 to 100644.

Signed-off-by: TAMUKI Shoichi <tamuki@linet.gr.jp>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
This commit is contained in:
TAMUKI Shoichi 2014-02-06 19:38:39 +09:00 committed by Stéphane Graber
parent 35f746711b
commit c63c04fcaf
15 changed files with 45 additions and 30 deletions

View File

@ -1,8 +1,9 @@
#!/bin/bash
# Detect use under userns (unsupported)
for arg in $*; do
if [ "$arg" == "--mapped-uid" ]; then
for arg in "$@"; do
[ "$arg" == "--" ] && break
if [ "$arg" == "--mapped-uid" -o "$arg" == "--mapped-gid" ]; then
echo "This template can't be used for unprivileged containers." 1>&2
echo "You may want to try the \"download\" template instead." 1>&2
exit 1

View File

@ -25,8 +25,9 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
# Detect use under userns (unsupported)
for arg in $*; do
if [ "$arg" == "--mapped-uid" ]; then
for arg in "$@"; do
[ "$arg" == "--" ] && break
if [ "$arg" == "--mapped-uid" -o "$arg" == "--mapped-gid" ]; then
echo "This template can't be used for unprivileged containers." 1>&2
echo "You may want to try the \"download\" template instead." 1>&2
exit 1

5
templates/lxc-archlinux.in Executable file → Normal file
View File

@ -26,8 +26,9 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
# Detect use under userns (unsupported)
for arg in $*; do
if [ "$arg" == "--mapped-uid" ]; then
for arg in "$@"; do
[ "$arg" == "--" ] && break
if [ "$arg" == "--mapped-uid" -o "$arg" == "--mapped-gid" ]; then
echo "This template can't be used for unprivileged containers." 1>&2
echo "You may want to try the \"download\" template instead." 1>&2
exit 1

View File

@ -21,8 +21,9 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
# Detect use under userns (unsupported)
for arg in $*; do
if [ "$arg" == "--mapped-uid" ]; then
for arg in "$@"; do
[ "$arg" == "--" ] && break
if [ "$arg" == "--mapped-uid" -o "$arg" == "--mapped-gid" ]; then
echo "This template can't be used for unprivileged containers." 1>&2
echo "You may want to try the \"download\" template instead." 1>&2
exit 1

View File

@ -73,8 +73,9 @@ lxc_network_link=lxcbr0
# should be able to use EITHER. Give preference to /etc/os-release for now.
# Detect use under userns (unsupported)
for arg in $*; do
if [ "$arg" == "--mapped-uid" ]; then
for arg in "$@"; do
[ "$arg" == "--" ] && break
if [ "$arg" == "--mapped-uid" -o "$arg" == "--mapped-gid" ]; then
echo "This template can't be used for unprivileged containers." 1>&2
echo "You may want to try the \"download\" template instead." 1>&2
exit 1

View File

@ -22,8 +22,9 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# Detect use under userns (unsupported)
for arg in $*; do
if [ "$arg" == "--mapped-uid" ]; then
for arg in "$@"; do
[ "$arg" == "--" ] && break
if [ "$arg" == "--mapped-uid" -o "$arg" == "--mapped-gid" ]; then
echo "This template can't be used for unprivileged containers." 1>&2
echo "You may want to try the \"download\" template instead." 1>&2
exit 1

View File

@ -21,8 +21,9 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
# Detect use under userns (unsupported)
for arg in $*; do
if [ "$arg" == "--mapped-uid" ]; then
for arg in "$@"; do
[ "$arg" == "--" ] && break
if [ "$arg" == "--mapped-uid" -o "$arg" == "--mapped-gid" ]; then
echo "This template can't be used for unprivileged containers." 1>&2
echo "You may want to try the \"download\" template instead." 1>&2
exit 1

View File

@ -73,8 +73,9 @@ lxc_network_link=lxcbr0
# should be able to use EITHER. Give preference to /etc/os-release for now.
# Detect use under userns (unsupported)
for arg in $*; do
if [ "$arg" == "--mapped-uid" ]; then
for arg in "$@"; do
[ "$arg" == "--" ] && break
if [ "$arg" == "--mapped-uid" -o "$arg" == "--mapped-gid" ]; then
echo "This template can't be used for unprivileged containers." 1>&2
echo "You may want to try the \"download\" template instead." 1>&2
exit 1

View File

@ -14,8 +14,9 @@
#
# Detect use under userns (unsupported)
for arg in $*; do
if [ "$arg" == "--mapped-uid" ]; then
for arg in "$@"; do
[ "$arg" == "--" ] && break
if [ "$arg" == "--mapped-uid" -o "$arg" == "--mapped-gid" ]; then
echo "This template can't be used for unprivileged containers." 1>&2
echo "You may want to try the \"download\" template instead." 1>&2
exit 1

View File

@ -27,8 +27,9 @@
#
# Detect use under userns (unsupported)
for arg in $*; do
if [ "$arg" == "--mapped-uid" ]; then
for arg in "$@"; do
[ "$arg" == "--" ] && break
if [ "$arg" == "--mapped-uid" -o "$arg" == "--mapped-gid" ]; then
echo "This template can't be used for unprivileged containers." 1>&2
echo "You may want to try the \"download\" template instead." 1>&2
exit 1

View File

@ -26,8 +26,9 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
# Detect use under userns (unsupported)
for arg in $*; do
if [ "$arg" == "--mapped-uid" ]; then
for arg in "$@"; do
[ "$arg" == "--" ] && break
if [ "$arg" == "--mapped-uid" -o "$arg" == "--mapped-gid" ]; then
echo "This template can't be used for unprivileged containers." 1>&2
echo "You may want to try the \"download\" template instead." 1>&2
exit 1

View File

@ -28,8 +28,9 @@
#
# Detect use under userns (unsupported)
for arg in $*; do
if [ "$arg" == "--mapped-uid" ]; then
for arg in "$@"; do
[ "$arg" == "--" ] && break
if [ "$arg" == "--mapped-uid" -o "$arg" == "--mapped-gid" ]; then
echo "This template can't be used for unprivileged containers." 1>&2
echo "You may want to try the \"download\" template instead." 1>&2
exit 1

View File

@ -29,8 +29,9 @@
# lxc-ubuntu script
# Detect use under userns (unsupported)
for arg in $*; do
if [ "$arg" == "--mapped-uid" ]; then
for arg in "$@"; do
[ "$arg" == "--" ] && break
if [ "$arg" == "--mapped-uid" -o "$arg" == "--mapped-gid" ]; then
echo "This template can't be used for unprivileged containers." 1>&2
echo "You may want to try the \"download\" template instead." 1>&2
exit 1

View File

@ -21,8 +21,9 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
# Detect use under userns (unsupported)
for arg in $*; do
if [ "$arg" == "--mapped-uid" ]; then
for arg in "$@"; do
[ "$arg" == "--" ] && break
if [ "$arg" == "--mapped-uid" -o "$arg" == "--mapped-gid" ]; then
echo "This template can't be used for unprivileged containers." 1>&2
echo "You may want to try the \"download\" template instead." 1>&2
exit 1

View File

@ -25,8 +25,9 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
# Detect use under userns (unsupported)
for arg in $*; do
if [ "$arg" == "--mapped-uid" ]; then
for arg in "$@"; do
[ "$arg" == "--" ] && break
if [ "$arg" == "--mapped-uid" -o "$arg" == "--mapped-gid" ]; then
echo "This template can't be used for unprivileged containers." 1>&2
echo "You may want to try the \"download\" template instead." 1>&2
exit 1