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

Use own ad server #226

Merged
merged 18 commits into from Jul 12, 2016
Merged

Use own ad server #226

merged 18 commits into from Jul 12, 2016

Conversation

deargle
Copy link
Collaborator

@deargle deargle commented Apr 22, 2016

Okay here goes. This is functionality for toggling the use of the psiturk ad server. Look in the new comments in psiturk/default_configs/local_config_defaults.txt for an overview of the changes. See this gist for an example config. Here's a summary of the process:

  1. You can say whether you want to use psiturk's ad server. Default is true.
  2. If you don't, then just say so and also set an ad_location url in the config for the location of your psiturk ad route. This url should point to a proxy server running in front psiturk/gunicorn. I used nginx. See the gist referenced above for a config that works for psiturk (and for flask/gunicorn/nginx in general). Your proxy server will need to handle SSL. You will need to get your own certs right now if you want to do this.
  3. You can optionally also have gunicorn work with SSL. If you want to to do this, set paths to both keyfile and certfile in the [Server Parameters] section. Assuming your process has permissions necessary to read the keyfile, they'll be loaded into gunicorn (see the same gist as before for an example of launching psiturk with sudo while still using the proper virtualenv binaries). If you do this, make sure that you switch the url of your proxy_pass in nginx to use the https:// protocol.

Some other changes:

  1. I also copied the slightly-updated styles.css from psiturk.org to the static/css files so that formatting on the "thanks-mturksubmit.html" file matches what happens if using the psiturk ad server. Sorry for the spacing creating lots of line changes, blame vim auto-formatting.
  2. I'm bringing back closepopup.html from the dead. Also bringing back the old thanks.html and calling it thanks-mturksubmit.html so that it has the nice submit button thing. Leaving the 2.0 thanks.html alone.

Even if this isn't merged, it demonstrates how to go about the process.

Also see #121

@deargle
Copy link
Collaborator Author

deargle commented Apr 22, 2016

@gureckis @pfeyz

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.09%) to 13.6% when pulling 6b11fc0 on deargle:use-own-ad-server into 418f098 on NYUCCL:master.

@jhamrick
Copy link
Member

Woohoo this is awesome! I'll do a code review too to help out with this as I think this is pretty important. Maybe I will do a PR after this to include integration with something like Let's Encrypt :-)

/* these are all the same for now, but easy to modify individually */
#container-ad, #container-error, #container-exp, #container-consent, #container-instructions, #container-questionnaire {
position: absolute;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines were removed on purpose, so adding them back in will introduce a regression -- see #159

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jhamrick Ah okay mb. Hmm I'll try to figure out a different way to make it match the 'push the complete button' page used when using the psiturk ad server.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I get it now. the style.css on psiturk.org, which I incorporated into this commit, is outdated. I'll just revert all changes to this file.

@deargle
Copy link
Collaborator Author

deargle commented Apr 22, 2016

@jhamrick Code review would be great! The problem with Let's Encrypt is that they won't issue certs for IP addresses -- so domain name registration would still be required.

On Fri, Apr 22, 2016 at 4:08 PM Jessica B. Hamrick notifications@github.com
wrote:

Woohoo this is awesome! I'll do a code review too to help out with this as
I think this is pretty important. Maybe I will do a PR after this to
include integration with something like Let's Encrypt :-)


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#226 (comment)

)
else:
# then AMT isn't involved. Show them a thanks message and tell them to go away
return render_template( 'thanks.html' )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this still need to have the template variables like is_sandbox, hitid, assignmentid, and workerid? Unless I'm missing something here? And I'm a bit confused about the comment -- isn't this used if we're relying on the psiTurk ad server, which does still involve AMT?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jhamrick I admit that I'm a bit confused about the purpose of thanks.html. It was put back in 2.1.2 by @gureckis. It doesn't use is_sandbox, hitid, assignmentid, or workerid anymore (it used to, before psiturk 2.0. It used to have the "click here to submit your hit" button). I couldn't figure out a way how workers would ever get to this page if they were using AMT. If they try to revisit the ad page, AMT just says "no more hits available to you in this group" and doesn't show the ad... at least that's how it went for me. Todd said this in the commit: "local thanks page needed when reloading the local ad and a worker has already completed the task."

The only time I could see it being reached is if it were in debug (non-AMT) mode and a worker re-visited the /ad page. I guess though that /ad wouldn't be involved in debug mode.

My confusion aside, it should all still work fine though, just removing the "then AMT isn't involved" part.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, ok, so those variables were accidentally left in even though they weren't being used. Got it. Looks good then!

@jhamrick
Copy link
Member

Ahh, good point. Bummer. Well, it might still be worthwhile to do if you are running psiTurk behind a domain name (which I usually am).

@jhamrick
Copy link
Member

Oh one additional comment is that since you are adding in new config options, it would be good to add those to the relevant documentation files too:

@deargle
Copy link
Collaborator Author

deargle commented Apr 22, 2016

@jhamrick right, good idea. My original thought was to not document this until it had been tested a bit -- like the "experimental tunnel server" was never documented. But since things are going into the default config file users will wonder about them. I'll document it.

Also a github noob question -- do I have to do username mentions each time for you to know that I responded since you're not the thread author? Or would you get notification regardless? .

Thanks a ton for the code review.

@jhamrick
Copy link
Member

Ah, I see. I would probably err on the side of documenting it and maybe just adding a note to say it's an experimental feature rather than not documenting it at all.

do I have to do username mentions each time for you to know that I responded since you're not the thread author? Or would you get notification regardless?

Once someone comments on a thread they get notifications by default, so it's not necessary to @-mention people. If they haven't commented yet, though, then @-mentioning them will notify them (unless they are already automatically subscribed to all issues on the repo, in which case they'll get notified regardless). The one thing that doesn't get notified is if you push a new commit to a PR that addresses someone's comments -- in that case you want to leave a comment saying you've made the changes.

No problem for the code review! Glad to help on the occasional chance that I have a few spare moments 😛

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 13.508% when pulling d2ca974 on deargle:use-own-ad-server into 418f098 on NYUCCL:master.

@deargle
Copy link
Collaborator Author

deargle commented Apr 23, 2016

@jhamrick code commits done, working on docs now. I'm going to pull all the commentary out of the default config file. After looking at it again, it may be overwhelming to non-technical newcomers. I'll move the commentary into the docs.

[shell parameter] SSL- and ad-server-related experimental features. Sorry
in advance for typos.

Also I'm removing most of the inline documentation from the default local
config.txt file. It seemed like it might have been overwhelming to
newcomers. I moved it into the docs instead.
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 13.508% when pulling 08ce6c8 on deargle:use-own-ad-server into 418f098 on NYUCCL:master.

@deargle
Copy link
Collaborator Author

deargle commented Apr 23, 2016

Okay documentation pushed up now too. Phew 😴 😌 <== my first github emoji

@jhamrick
Copy link
Member

👍 looks great to me! Though note, I haven't actually tested it, just looked through the code.

GitHub emojis are the best! 🎉

…abled, a proxy server must be used in front of it in order to serve static content.
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 13.508% when pulling 8a3c441 on deargle:use-own-ad-server into 418f098 on NYUCCL:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 13.508% when pulling f640529 on deargle:use-own-ad-server into 418f098 on NYUCCL:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 13.569% when pulling 2b2d565 on deargle:use-own-ad-server into 418f098 on NYUCCL:master.

@deargle
Copy link
Collaborator Author

deargle commented May 12, 2016

Todo:

  • [ ] fix the do_debug function to return a different ad url base if own ad location is being used (see here)

Scratch this, it's not clear to me that the functionality of do_debug should be any different even if using a non-psiturk-server ad_location. Users can always instead browse to their ad_location on their own and get a random debug url with the functionality @jhamrick recently implemented.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 13.516% when pulling d1d5074 on deargle:use-own-ad-server into 418f098 on NYUCCL:master.

…mpting to load when using own ad server but debugging
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 13.505% when pulling 4b2f638 on deargle:use-own-ad-server into 418f098 on NYUCCL:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.08%) to 13.609% when pulling 0288d84 on deargle:use-own-ad-server into 418f098 on NYUCCL:master.

@deargle deargle merged commit 178a21d into NYUCCL:master Jul 12, 2016
@hyiltiz
Copy link

hyiltiz commented Jan 10, 2019

I am having issues setting up my own ad_server. I followed this gist to set up the psiturk gunicorn server behind an nginx, with SSL enabled through certbot serving at port 443. I am getting the following SSH error from mTurk once I fill in my AWS and mTurk API keys (both of which work if used directly from within psiturk in sandbox mode, not behind nginx).
The error message:

ssl.SSLError: [SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl.c:727)

Some key configurations:

# config.txt
[Server Parameters]
host = 0.0.0.0
port = 22362
# certfile = /etc/letsencrypt/live/exp.myserver.com/fullchain.pem
# keyfile = /etc/letsencrypt/live/exp.myserver.com/privkey.pem

[Shell Parameters]
launch_in_sandbox_mode = true
use_psiturk_ad_server = false
ad_location = https://www.myserver.com:443/ad


# cat /etc/nginx/sites-available/psiturk-host-own-ad.conf
# use this if you're hosting your own ad (i.e., you're not using the psiturk ad server). Requires that you have your own ssl cert.

server {
        listen 80;
        server_name www.myserver.com www.myserver.com;
        rewrite ^/(.*) https://www.myserver.com/$1 permanent;
}

server {
        listen 443;
        root /mnt/home/hyiltiz/src/myexp;

        ssl on;
        ssl_certificate /etc/letsencrypt/live/exp.myserver.com/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/exp.myserver.com/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

        server_name exp.myserver.com;
        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        location / {
                # checks for static files; if not found, proxy to app
                try_files $uri @proxy_to_app;
        }

        location @proxy_to_app {
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                proxy_redirect off;

                proxy_pass http://localhost:22362;
                # proxy_pass https://localhost:22362;
        }
}

psiturk can create hit in sandbox mode without using the nginx reverse proxy, or nginx can serve the experiment correctly at http://exp.myserver.com (which redirects to) https://exp.myserver.com when no AWS and mTurk keys were provided in ~/.psiturkconfig file. That is, the keys were wroking and the SSL were working, but mTurk doesn't like the ad_server that I set up here.

I also tried running gunicorn with SSL by 1. uncommenting the above two lines for SSL keys in config.txt, 2. use proxy_pass https://localhost:22362; in nginx configuration instead, 3. restart nginx and start psiturk. That threw the same errors as well.

@deargle
Copy link
Collaborator Author

deargle commented Jan 10, 2019 via email

@hyiltiz
Copy link

hyiltiz commented Jan 10, 2019

Removed ssl on; and changed to listen 442 ssl; as suggested with ssl_protocols TLSv1.2; but I am getting the same error regardless of whether a) I use proxy_pass https://... and specify the SSL keys in config.txt for psiturk, or b) I use proxy_pass http://... but comment out the SSL keys in config.txt.

I see no reason to do proxy_pass https://... so I'd prefer running psiturk with plain HTTP protocol at port 22362 then reverse proxy the SSL port 443 to it. This set up works with the above snippets if I do not fill in the AWS and mTurk API keys/credentials; any other computer can simply visit https://www.myserver.com to see "Begin by viewing the ad" page, and then to proceed with the experiment as expected.

Somehow getting mTurk to accept our nginx server is not working. Is there a working documentation for how to set up psiturk for it?

@deargle
Copy link
Collaborator Author

deargle commented Jan 10, 2019

Is there a working documentation for how to set up psiturk for it?

You and I are updating the documentation right now ;-) I wrote all that functionality, and the gist.

I see no reason to do proxy_pass https://... so I'd prefer running psiturk with plain HTTP protocol at port 22362 then reverse proxy the SSL port 443 to it.

Agreed. One user needed ssl all the way, even between the rev proxy and gunicorn, so I added that for him. But it's not necessary for mturk.

Removed ssl on; and changed to listen 442 ssl;

I hope you meant listen 443 ssl; ?

Consider letting heroku host your stuff. They give you rev proxy and ssl out of the box. I wrote a doc page for that somewhere on readthedocs.

I am guessing that the error has something to do with mturk expecting the nginx server to support a different cipher suite -- probably tls 1.3. Try adding that. like this

@hyiltiz
Copy link

hyiltiz commented Jan 10, 2019

Yup, it was 443. Was a typo. Same error with TLSv1.3 added to the enabled protocols as well. I did see the documentation on deplying at heroku but I generally prefer setting up my own servers, so...
Is there any way to get the actual debug errors other than:

psiturk
Traceback (most recent call last):
  File "/usr/local/bin/psiturk", line 11, in <module>
    load_entry_point('PsiTurk==2.2.3', 'console_scripts', 'psiturk')()
  File "/usr/local/lib/python2.7/dist-packages/PsiTurk-2.2.3-py2.7.egg/psiturk/command_line.py", line 15, in process
    launch_shell()
  File "/usr/local/lib/python2.7/dist-packages/PsiTurk-2.2.3-py2.7.egg/psiturk/command_line.py", line 115, in launch_shell
    ps.run(cabinmode=args.cabinmode)
  File "/usr/local/lib/python2.7/dist-packages/PsiTurk-2.2.3-py2.7.egg/psiturk/psiturk_shell.py", line 1218, in run
    quiet=quiet)
  File "/usr/local/lib/python2.7/dist-packages/PsiTurk-2.2.3-py2.7.egg/psiturk/psiturk_shell.py", line 747, in __init__
    self.update_hit_tally()
  File "/usr/local/lib/python2.7/dist-packages/PsiTurk-2.2.3-py2.7.egg/psiturk/psiturk_shell.py", line 852, in update_hit_tally
    num_hits = self.amt_services_wrapper.tally_hits()
  File "/usr/local/lib/python2.7/dist-packages/PsiTurk-2.2.3-py2.7.egg/psiturk/amt_services_wrapper.py", line 282, in tally_hits
    hits = self.get_active_hits(all_studies=False)
  File "/usr/local/lib/python2.7/dist-packages/PsiTurk-2.2.3-py2.7.egg/psiturk/amt_services_wrapper.py", line 305, in get_active_hits
    hits = self._get_hits(all_studies)
  File "/usr/local/lib/python2.7/dist-packages/PsiTurk-2.2.3-py2.7.egg/psiturk/amt_services_wrapper.py", line 294, in _get_hits
    amt_hits = self.amt_services.get_all_hits()
  File "/usr/local/lib/python2.7/dist-packages/PsiTurk-2.2.3-py2.7.egg/psiturk/amt_services_wrapper.py", line 67, in amt_services
    self.config.getboolean('Shell Parameters', 'launch_in_sandbox_mode'))
  File "/usr/local/lib/python2.7/dist-packages/PsiTurk-2.2.3-py2.7.egg/psiturk/amt_services.py", line 312, in __init__
    self.valid_login = self.verify_aws_login()
  File "/usr/local/lib/python2.7/dist-packages/PsiTurk-2.2.3-py2.7.egg/psiturk/amt_services.py", line 482, in verify_aws_login
    self.mtc.get_account_balance()
  File "/usr/local/lib/python2.7/dist-packages/boto-2.15.0-py2.7.egg/boto/mturk/connection.py", line 72, in get_account_balance
    ('OnHoldBalance', Price)])
  File "/usr/local/lib/python2.7/dist-packages/boto-2.15.0-py2.7.egg/boto/mturk/connection.py", line 820, in _process_request
    response = self.make_request(None, params, verb='POST')
  File "/usr/local/lib/python2.7/dist-packages/boto-2.15.0-py2.7.egg/boto/connection.py", line 1049, in make_request
    return self._mexe(http_request)
  File "/usr/local/lib/python2.7/dist-packages/boto-2.15.0-py2.7.egg/boto/connection.py", line 965, in _mexe
    raise e
ssl.SSLError: [SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl.c:727)

The error trace above wasn't quite helpful, so here is an strace output for running psiturk.
https://termbin.com/frus

Just noticed that even commenting out ad_location and setting use_psiturk_ad_server = false produces the same error. How is that possible? My AWS API keys were working before, so do I need to update them?

I am getting the same error with my experiment or using the psiturk example experiment.

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

Successfully merging this pull request may close these issues.

None yet

5 participants