puresec / serverless-puresec-cli

Serverless plugin for least privileges.
Other
247 stars 11 forks source link

Installation fails when virtualenv is active #12

Closed killthrush closed 7 years ago

killthrush commented 7 years ago

Hi, ran into a minor issue today with installation - from within an active virtualenvwrapper session, the plugin installer fails with the following error:

> serverless-puresec-cli@1.2.0 install /Users/bpeterson/cloudzero-reactor-aws/node_modules/serverless-puresec-cli
> npip install

No python_modules directory; installing pip locally if needed.
Error: Python site module exited with code 1.

    at ChildProcess.child.on.code (/Users/bpeterson/cloudzero-reactor-aws/node_modules/nopy/src/api.js:66:18)
    at emitTwo (events.js:125:13)
    at ChildProcess.emit (events.js:213:7)
    at maybeClose (internal/child_process.js:887:16)
    at Socket.stream.socket.on (internal/child_process.js:340:11)
    at emitOne (events.js:115:13)
    at Socket.emit (events.js:210:7)
    at Pipe._handle.close [as _onclose] (net.js:546:12)

It didn't seem to matter which version of Node was active (7 or 8), and yarn and NPM fail with the same error. Not really sure whether this is an issue with nopy or the plugin installer - nopy installs fine by itself.

I was able to work around this issue by deactivating my python virtualenv.

Any thoughts on this?

avish9 commented 7 years ago

Hi @killthrush , thanks for posting the issue. We'll check it and let you know as soon as we find the problem.

Thanks, Avi

alastairpatrick commented 7 years ago

I found the discussion "Behavior of --user in virtualenv" helpful. It seems there is at least one way to make virtualenv support user site directories: use the --system-site-packages switch when creating the environment. I don't understand the rationale for virtualenv not supporting this by default. Hopefully there's a way to support user site directories without getting the system site packages as well, though I didn't find one.

I believe I reproduced the issue and --system-site-packages fixed it.

Fails: $ virtualenv myenv $ source myenv/bin/activate $ npm install dependency_using_nopy

Works: $ virtualenv myenv --system-site-packages $ source myenv/bin/activate $ npm install dependency_using_nopy

odedniv commented 7 years ago

Out of curiosity, what drove you to run the npm install inside a virtualenv?

killthrush commented 7 years ago

@odedniv I'm using serverless for lambdas written in python 3.6, so I'm always in a virtualenv when in the terminal.

odedniv commented 7 years ago

Unfortunately currently there is no solution due to virtualenv's strictness (being unable to execute a specific python run with user site). My recommendation for you right now is to run npm install and serverless puresec gen-roles out of virtualenv (it shouldn't interfere with your usage as far as I can tell), or create the virtualenv the way @alastairpatrick mentioned above.

Let us know if that solution helps

killthrush commented 7 years ago

Yeah, that workaround is fine for me - I don't need to run it all that often. Thanks!