Skip to content

Commit 891896f

Browse files
rabbahdgrove-oss
authored andcommitted
Do not allow re-init of the action exec.
Disables re-initialization of the executable unless explicitly permitted via an environment variable PROXY_ALLOW_REINIT == "1", which is generally useful for local testing and development.
1 parent 470cd35 commit 891896f

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

core/actionProxy/actionproxy.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,16 +203,26 @@ def initCodeFromZip(self, message):
203203

204204
proxy = flask.Flask(__name__)
205205
proxy.debug = False
206+
# disable re-initialization of the executable unless explicitly allowed via an environment
207+
# variable PROXY_ALLOW_REINIT == "1" (this is generally useful for local testing and development)
208+
proxy.rejectReinit = 'PROXY_ALLOW_REINIT' not in os.environ or os.environ['PROXY_ALLOW_REINIT'] != "1"
209+
proxy.initialized = False
206210
runner = None
207211

208-
209212
def setRunner(r):
210213
global runner
211214
runner = r
212215

213216

214217
@proxy.route('/init', methods=['POST'])
215218
def init():
219+
if proxy.rejectReinit is True and proxy.initialized is True:
220+
msg = 'Cannot initialize the action more than once.'
221+
sys.stderr.write(msg + '\n')
222+
response = flask.jsonify({'error': msg})
223+
response.status_code = 403
224+
return complete(response)
225+
216226
message = flask.request.get_json(force=True, silent=True)
217227
if message and not isinstance(message, dict):
218228
flask.abort(404)
@@ -228,6 +238,7 @@ def init():
228238
status = False
229239

230240
if status is True:
241+
proxy.initialized = True
231242
return ('OK', 200)
232243
else:
233244
response = flask.jsonify({'error': 'The action failed to generate or locate a binary. See logs for details.'})

tests/src/test/scala/runtime/actionContainers/ActionProxyContainerTests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,4 +245,5 @@ class ActionProxyContainerTests extends BasicActionRunnerTests with WskActorSyst
245245
testUnicode(stdUnicodeSamples)
246246
testEnv(stdEnvSamples)
247247
testLargeInput(stdLargeInputSamples)
248+
testInitCannotBeCalledMoreThanOnce(codeNotReturningJson) // any code sample will do
248249
}

0 commit comments

Comments
 (0)