Skip to content

Commit 77edb37

Browse files
committed
server: control honouring internal IDs by old APIs
Fixes #9684 Signed-off-by: Abhishek Kumar <[email protected]>
1 parent bfc4f60 commit 77edb37

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

server/src/main/java/com/cloud/api/ApiServer.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,19 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
348348
, ConfigKey.Scope.Global, null, null, null, null, null, ConfigKey.Kind.Select,
349349
EnumSet.allOf(ApiSessionKeyCheckOption.class).stream().map(Enum::toString).collect(Collectors.joining(", ")));
350350

351+
public static final ConfigKey<Boolean> ApiDisallowInternalIds = new ConfigKey<>(
352+
ConfigKey.CATEGORY_ADVANCED,
353+
Boolean.class,
354+
"api.disallow.internal.ids",
355+
"false",
356+
"When enabled, APIs will not honour requests containing internal database IDs. "
357+
+ "Only UUIDs will be accepted as entity identifiers. "
358+
+ "By default, internal IDs are still accepted for backward compatibility with pre-3.x APIs.",
359+
true,
360+
ConfigKey.Scope.Global
361+
);
362+
363+
351364
@Override
352365
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
353366
messageBus.subscribe(AsyncJob.Topics.JOB_EVENT_PUBLISH, MessageDispatcher.getDispatcher(this));
@@ -1685,7 +1698,8 @@ public ConfigKey<?>[] getConfigKeys() {
16851698
useForwardHeader,
16861699
listOfForwardHeaders,
16871700
ApiSessionKeyCookieSameSiteSetting,
1688-
ApiSessionKeyCheckLocations
1701+
ApiSessionKeyCheckLocations,
1702+
ApiDisallowInternalIds
16891703
};
16901704
}
16911705
}

server/src/main/java/com/cloud/api/dispatch/ParamProcessWorker.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import org.apache.logging.log4j.Logger;
5252
import org.apache.logging.log4j.LogManager;
5353

54+
import com.cloud.api.ApiServer;
5455
import com.cloud.exception.InvalidParameterValueException;
5556
import com.cloud.user.Account;
5657
import com.cloud.user.AccountManager;
@@ -510,7 +511,7 @@ private Long translateUuidToInternalId(final String uuid, final Parameter annota
510511
}
511512
Long internalId = null;
512513
// If annotation's empty, the cmd existed before 3.x try conversion to long
513-
final boolean isPre3x = annotation.since().isEmpty();
514+
final boolean isPre3x = annotation.since().isEmpty() && !ApiServer.ApiDisallowInternalIds.value();
514515
// Match against Java's UUID regex to check if input is uuid string
515516
final boolean isUuid = UuidUtils.isUuid(uuid);
516517
// Enforce that it's uuid for newly added apis from version 3.x

0 commit comments

Comments
 (0)