fix: Strictly validate service names
We previously allowed a wide range of service names. As the service name is sometimes used to name databases, the name was actually more restricted than any character, resulting in services that wouldn't start. Going forward, only alphanumeric and underscore characters are allowed. This only impacts service creation. Any services with invalid names should be migrated to a new service, with the data exported and imported as normal. Closes dokku/dokku-redis#99 Closes dokku/dokku-mysql#47 Closes dokku/dokku-mongo#86 Closes dokku/dokku-redis#81
This commit is contained in:
@@ -731,3 +731,15 @@ verify_service_name() {
|
||||
[[ ! -d "$PLUGIN_DATA_ROOT/$SERVICE" ]] && dokku_log_fail "$PLUGIN_SERVICE service $SERVICE does not exist"
|
||||
return 0
|
||||
}
|
||||
|
||||
is_valid_service_name() {
|
||||
declare desc="Validates a service name"
|
||||
declare SERVICE="$1"
|
||||
[[ -z "$SERVICE" ]] && dokku_log_fail "SERVICE must not be null"
|
||||
|
||||
if [[ "$SERVICE" =~ ^[A-Za-z0-9_]+$ ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ service_connect() {
|
||||
|
||||
service_create() {
|
||||
local SERVICE="$1"
|
||||
is_valid_service_name "$SERVICE" || dokku_log_fail "Please specify a valid name for the service. Valid characters are: [A-Za-z0-9_]+"
|
||||
[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service"
|
||||
[[ ! -d "$PLUGIN_DATA_ROOT/$SERVICE" ]] || dokku_log_fail "$PLUGIN_SERVICE service $SERVICE already exists"
|
||||
SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"; LINKS_FILE="$SERVICE_ROOT/LINKS"
|
||||
|
||||
@@ -10,3 +10,11 @@ load test_helper
|
||||
run dokku "$PLUGIN_COMMAND_PREFIX:create"
|
||||
assert_contains "${lines[*]}" "Please specify a name for the service"
|
||||
}
|
||||
|
||||
@test "($PLUGIN_COMMAND_PREFIX:create) error when there is an invalid name specified" {
|
||||
run dokku "$PLUGIN_COMMAND_PREFIX:create" d.erp
|
||||
assert_failure
|
||||
|
||||
run dokku "$PLUGIN_COMMAND_PREFIX:create" d-erp
|
||||
assert_failure
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user