Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1411)

Unified Diff: appengine/machine_provider/handlers_endpoints.py

Issue 2716783002: Enforce two-day limit on lease requests (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: appengine/machine_provider/handlers_endpoints.py
diff --git a/appengine/machine_provider/handlers_endpoints.py b/appengine/machine_provider/handlers_endpoints.py
index 316e9e90e90c6b47360a9bc4e4025e71683b4f78..6a128f3d5eb3792c4dfe6d25ffae16d31ce63eff 100644
--- a/appengine/machine_provider/handlers_endpoints.py
+++ b/appengine/machine_provider/handlers_endpoints.py
@@ -351,6 +351,11 @@ class MachineProviderEndpoints(remote.Service):
def _lease(self, request, user, request_hash):
"""Handles an incoming LeaseRequest."""
+ # Arbitrary limit. Increase if necessary.
+ MAX_LEASE_DURATION = 60 * 60 * 24 * 2
+ now = utils.time_time()
+ max_lease_expiration_ts = now + MAX_LEASE_DURATION
+
metrics.lease_requests_received.increment()
if request.duration:
if request.lease_expiration_ts:
@@ -363,12 +368,22 @@ class MachineProviderEndpoints(remote.Service):
client_request_id=request.request_id,
error=rpc_messages.LeaseRequestError.NONPOSITIVE_DEADLINE,
)
+ if request.duration > MAX_LEASE_DURATION:
+ return rpc_messages.LeaseResponse(
+ client_request_id=request.request_id,
+ error=rpc_messages.LeaseRequestError.LEASE_TOO_LONG,
+ )
elif request.lease_expiration_ts:
- if request.lease_expiration_ts <= utils.time_time():
+ if request.lease_expiration_ts <= now:
return rpc_messages.LeaseResponse(
client_request_id=request.request_id,
error=rpc_messages.LeaseRequestError.LEASE_EXPIRATION_TS_ERROR,
)
+ if request.lease_expiration_ts > max_lease_expiration_ts:
+ return rpc_messages.LeaseResponse(
+ client_request_id=request.request_id,
+ error=rpc_messages.LeaseRequestError.LEASE_TOO_LONG,
+ )
else:
return rpc_messages.LeaseResponse(
client_request_id=request.request_id,

Powered by Google App Engine
This is Rietveld 408576698