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:
Jose Diaz-Gonzalez
2019-03-09 00:17:30 -05:00
parent 876ff0c330
commit 35d5e9cab4
3 changed files with 21 additions and 0 deletions

View File

@@ -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
}