Merge pull request #8805 from RichardDorian/master
Allow custom values for chown
This commit is contained in:
@@ -16,13 +16,15 @@ main() {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case "$CHOWN_ID" in
|
||||
0 | 1000 | 2000 | 32767 | 165536 | 166536 | 167536 | 198303) ;;
|
||||
*)
|
||||
echo " ! Unsupported chown permissions. Supported values: 0, 1000, 2000, 32767 (and user namespace offset variants)" 1>&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
if [[ ! "$CHOWN_ID" =~ ^[0-9]+$ ]]; then
|
||||
echo " ! Unsupported chown permissions. Value must be a non-negative integer." 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ((CHOWN_ID > 65535 && (CHOWN_ID < 165536 || CHOWN_ID > 231071))); then
|
||||
echo " ! Unsupported chown permissions. Supported values: 0-65535 (and user namespace offset variants, 165536-231071)" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
chown -R "$CHOWN_ID:$CHOWN_ID" "${DOKKU_LIB_ROOT}/data/storage/$DIRECTORY"
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
@@ -99,7 +100,13 @@ func ResolveChownID(chownFlag string) (string, error) {
|
||||
case "false":
|
||||
return "false", nil
|
||||
default:
|
||||
return "", errors.New("Unsupported chown permissions")
|
||||
id, err := strconv.ParseUint(chownFlag, 10, 16)
|
||||
|
||||
if err != nil {
|
||||
return "", errors.New("Unsupported chown permissions")
|
||||
} else {
|
||||
chownID = fmt.Sprint(id)
|
||||
}
|
||||
}
|
||||
|
||||
userns, err := isUserNamespacesEnabled()
|
||||
|
||||
17
plugins/storage/subcommands_test.go
Normal file
17
plugins/storage/subcommands_test.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
func TestResolveChownIDRejectsOutOfBoundsValues(t *testing.T) {
|
||||
RegisterTestingT(t)
|
||||
|
||||
for _, chownFlag := range []string{"-1", "65536", "100000", "231072", "abc", "1.5", ""} {
|
||||
_, err := ResolveChownID(chownFlag)
|
||||
Expect(err).To(HaveOccurred(), "expected %q to be rejected", chownFlag)
|
||||
Expect(err.Error()).To(ContainSubstring("Unsupported chown permissions"))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user