Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To run ScrapydWeb in HTTPS mode #18

Closed
ohenrik opened this issue Jan 11, 2019 · 9 comments
Closed

To run ScrapydWeb in HTTPS mode #18

ohenrik opened this issue Jan 11, 2019 · 9 comments
Labels
feature request Request for new features

Comments

@ohenrik
Copy link

ohenrik commented Jan 11, 2019

How do i enable https? I have a certificate file from let's encrypt and would like to start the server using https.

Is this possible at this time? It should be possible since using basic auth without HTTPS is dangerous.

@ohenrik ohenrik added the bug Something isn't working label Jan 11, 2019
@ohenrik
Copy link
Author

ohenrik commented Jan 11, 2019

Maybe adding config paths for the certificate files and optionally adding them here:
https://github.com/my8100/scrapydweb/blob/master/scrapydweb/run.py#L92

Would be enough?

You might also need to require pyopenssl (pip install pyopenssl)

app.run with ssl_context:

app.run(ssl_context=('cert.pem', 'key.pem'))

@my8100
Copy link
Owner

my8100 commented Jan 11, 2019

This works for me, and no need to install pyopenssl. Could you try and tell me your result?

context = ('/path/to/the/cert.pem', '/path/to/the/cert.key')
app.run(host=app.config['SCRAPYDWEB_BIND'], port=app.config['SCRAPYDWEB_PORT'], ssl_context=context)

@ohenrik
Copy link
Author

ohenrik commented Jan 11, 2019

It seems to work :)

@my8100
Copy link
Owner

my8100 commented Jan 11, 2019

What's the file type of your certificate? (Mine is '.pem')

@my8100 my8100 changed the title HTTPS (SSL) To run ScrapydWeb in HTTPS mode Jan 12, 2019
@my8100 my8100 added enhancement and removed bug Something isn't working labels Jan 12, 2019
@my8100
Copy link
Owner

my8100 commented Jan 21, 2019

Fixed in v1.1.0: Now you can set up ENABLE_HTTPS, CERTIFICATE_FILEPATH, and PRIVATEKEY_FILEPATH to enable HTTPS mode.

@my8100 my8100 closed this as completed Jan 21, 2019
@my8100 my8100 added feature request Request for new features and removed enhancement labels Mar 23, 2019
@my8100 my8100 removed their assignment May 16, 2019
@jwjhdev
Copy link

jwjhdev commented Jun 22, 2021

Just wanted to point out to anyone having issues with SSL that scrapydweb uses assert os.path.isfile() to check the certificate and key files which only returns true if the path exists and is a file and you have (at least) read permissions.

Popular certificate aggregators like LetsEncrypt chmod the certificate as root only read/write.

That means you will need to run scrapydweb as root in order for the certificate to parse.

@my8100
Copy link
Owner

my8100 commented Jun 22, 2021

The below assert line could be commented out.

check_assert('ENABLE_HTTPS', False, bool)
if config.get('ENABLE_HTTPS', False):
logger.info("HTTPS mode enabled: ENABLE_HTTPS = %s", config['ENABLE_HTTPS'])
for k in ['CERTIFICATE_FILEPATH', 'PRIVATEKEY_FILEPATH']:
check_assert(k, '', str, non_empty=True)
assert os.path.isfile(config[k]), "%s not found: %s" % (k, config[k])
logger.info("Running in HTTPS mode: %s, %s", config['CERTIFICATE_FILEPATH'], config['PRIVATEKEY_FILEPATH'])

@jwjhdev
Copy link

jwjhdev commented Jun 22, 2021

Thanks @my8100 👍

I can't think of a clean way to fix this issue other than acknowledging the file exists manually and commenting out that line as you say, would you agree?

  • It should rightly fail without permission to read the cert/key, the assert os.path.isfile() is the correct method.
  • Non-root users shouldn't change the permission of the cert/key as it is set to root as a layer of security
  • Installing scrapyd, logparser and scrapydweb shouldn't be installed as root as a layer of security
  • Running scrapydweb as a root user should also be avoided as a layer of security

Kind of leaves you in no man's land.

Thanks for a great tool by the way @my8100 and hello from Australia!

@my8100
Copy link
Owner

my8100 commented Jun 22, 2021

@jwjhdev
As the below comment said, HTTPS mode was not fully tested.
Thank you so much for the feedback.

############################## ScrapydWeb #####################################
# The default is False, set it to True and add both CERTIFICATE_FILEPATH and PRIVATEKEY_FILEPATH
# to run ScrapydWeb in HTTPS mode.
# Note that this feature is not fully tested, please leave your comment here if ScrapydWeb
# raises any excepion at startup: https://github.com/my8100/scrapydweb/issues/18
ENABLE_HTTPS = False
# e.g. '/home/username/cert.pem'
CERTIFICATE_FILEPATH = ''
# e.g. '/home/username/cert.key'
PRIVATEKEY_FILEPATH = ''

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request for new features
Projects
None yet
Development

No branches or pull requests

3 participants