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

Cloud Code and SSL #1695

Closed
cheesykyle opened this issue May 3, 2016 · 22 comments
Closed

Cloud Code and SSL #1695

cheesykyle opened this issue May 3, 2016 · 22 comments

Comments

@cheesykyle
Copy link

I'm unable to run Cloud Code functions now that I've secured Parse with SSL. I wasn't having any issues before this change and everything else (aside from LiveQuery) is working perfectly.

Calling a Cloud Code function simply times out after an extended delay of about 30sec-1min and returns an error in the browser telling me the network connection was lost.

I'm running an Express app with https. The server itself is reachable as all other data passes through aside from cloud functions.

Any solutions?

@drew-gross
Copy link
Contributor

Have you tried setting your serverURL to be an HTTPS url?

@cheesykyle
Copy link
Author

I have and it turns out most other functions are working as expected. It seems that this particular function is where the timeout issue is occurring. This was working well before recent updates:

Parse.Cloud.define('isAdmin', function(request, response){
    var adminRoleQuery = new Parse.Query(Parse.Role);
        adminRoleQuery.equalTo('name', 'Admin');
        adminRoleQuery.equalTo('users', request.user);

    return adminRoleQuery.first({ useMasterKey: true }).then(function(adminRole) {
        if (!adminRole) {
            throw new Error('Not an admin');
        } else {
            throw new response.success(true);
        }
    });
});

@drew-gross
Copy link
Contributor

What problem are you seeing? Incorrect results? Crash? Can you post some server logs?

@cheesykyle
Copy link
Author

That's the problem: I'm not receiving any errors at all. The browser simply times out after trying to call that particular function and claims that it failed to load the resource. Some other functions are working as expected, though.

@drew-gross
Copy link
Contributor

How about server logs? Or MongoDB logs? Right now I don't have enough information to debug this.

@cheesykyle
Copy link
Author

This is the relevant line in the log. So it appears that the function is being called, but it never returns any sort of response.

verbose: POST /parse/functions/isAdmin { host: '***',
  'content-type': 'text/plain',
  origin: 'https://*****.com',
  'accept-encoding': 'gzip, deflate',
  'content-length': '258',
  connection: 'keep-alive',
  accept: '*/*',
  'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/601.5.17 (KHTML, like Gecko) Version/9.1 Safari/601.5.17',
  referer: 'https://****.com/****',
  'cache-control': 'max-age=0',
  'accept-language': 'en-us' } {}

@drew-gross
Copy link
Contributor

Is this for users that are admins, or users that aren't? I see you aren't doing anything with the response in the catch block or in the "Not an admin" branch.

@cheesykyle
Copy link
Author

I'm trying to determine if the current user is an Admin.

It seems the issue is with the query itself. This doesn't log anything to the console, even if I remove the query constraints:

Parse.Cloud.define('isAdmin', function(request, response){
    var adminRoleQuery = new Parse.Query(Parse.Role);
        adminRoleQuery.equalTo('name', 'Admin');
        adminRoleQuery.equalTo('users', request.user);

    adminRoleQuery.first({ useMasterKey: true }).then(function(adminRole) {
        console.log('isAdmin fired succesfully');   
    });
});

@cheesykyle
Copy link
Author

Once I add the error handler to the function, I get this:

ParseError {
  code: 100,
  message: 'XMLHttpRequest failed: "Unable to connect to the Parse API"' }

My serverURL is set correctly as https://localhost:****/parse .
This is leading me back to thinking this is somehow related to SSL.

@drew-gross
Copy link
Contributor

That seems to indicate some type of network error, yes. I don't I'll be able to help you, though, without knowing your exact setup, how you are doing SSL termination, and etc.

@ericmbarnard
Copy link

If you have the following still in your code:

        if (!adminRole) {
            throw new Error('Not an admin');
        } else {
            throw new response.success(true);
        }

I'm thinking you don't want to throw new response.success(true). Probably something more like:

        if (!adminRole) {
            throw new Error('Not an admin');
        } else {
            response.success(true);
        }

@cheesykyle
Copy link
Author

It works fine when I run the server without https alongside the https and set the serverURL to http://

Are there any reasons that I would be able access everything fine over https, but CloudCode functions can't connect to the Parse API?

@thamer898
Copy link

Hello @cheesykyle

i have the same problem my app only connect to my server with http protocol ?

Regards

@lukesiedle
Copy link

lukesiedle commented Jun 11, 2016

If you're using a self signed certificate and/or working in a local environment and using https, you may find cloud code functions aren't working, see this thread: #411

This is due to using a self-signed certificate. Place this in your development environment index.js file

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"

@apavamontri
Copy link

I had the same problem. This is my set up.

  • in AWS
  • public and private network (parse server is in private network)
  • Elastic Beanstalk setup
  • SSL Cert from GoDaddy
  • ELB terminates the SSL
  • Node.js, Express, CloudCode

This is how i fixed it.

  • Add process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; line in index.js
  • Set the SERVER_URL environment variable in Elastic Beanstalk to http://localhost:80/parse
  • restart the server

It appears that the connection (HTTPS) from the client (web, mobile) to the parse server is working fine. My test call to normal Parse API works. But the CloudCode that connect to parse server with HTTPS is the problem. Once i changed to http://localhost:80/parse things just work.

Hope this help.

@thamer898
Copy link

Hello
Can you please me to install the ssl certificate to my parse server since I purchased the ssl certificate and I need to encrypt client connection ?
Regards 

Sent from Yahoo Mail on Android

On Wed, 29 Jun, 2016 at 6:35 pm, Anusidh Pavamontrinotifications@github.com wrote:
I had the same problem. This is my set up.

  • in AWS
  • public and private network (parse server is in private network)
  • Elastic Beanstalk setup
  • SSL Cert from GoDaddy
  • ELB terminates the SSL
  • Node.js, Express, CloudCode

This is how i fixed it.

  • Add process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; line in index.js
  • Set the SERVER_URL environment variable in Elastic Beanstalk to http://localhost:80/parse
  • restart the server

It appears that the connection (HTTPS) from the client (web, mobile) to the parse server is working fine. My test call to normal Parse API works. But the CloudCode that connect to parse server with HTTPS is the problem. Once i changed to http://localhost:80/parse things just work.

Hope this help.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

@thamer898
Copy link

Hello @apavamontri

I purchased a certificate , can you please mention the required steps to install ssl certificate with parse ?

Regards

@apavamontri
Copy link

@thamer898 I didn't install SSL certificate on Parse server. I installed it on the AWS Elastic Load Balancer and Load Balancer terminates the SSL and connects to Parse server normally with HTTP port 80. To install SSL certificate you should follow the normal steps for Apache, Nginx server. But if you are using Express.js or Node.js You can follow this answer in the StackOverlow: http://stackoverflow.com/a/11805909

@thamer898
Copy link

thamer898 commented Jul 3, 2016

Hello @apavamontri

i have already a public url with ssl certificate but i can't access the parse server via android app with https ? the android app client only work's with http ? kindly advice .

Note : i used node.js & express

Regards

@thamer898
Copy link

Hello @apavamontri

Thank you very much no i can create a ssl connection between the client app and my parse server , i added this line to my index.js process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; after that i changed the url to be https in Parse.initialize and it work's , but is it encrypted now or not ?

Rgards

@flovilmart
Copy link
Contributor

Closing due to lack of activity, please update to latest parse-server version and reopen if the issue persist.

Don't forget to include your current:

  • node version
  • npm version
  • parse-server version
  • any relevant logs (VERBOSE=1 will enable verbose logging)

@sureshkoduri
Copy link

I am facing the same issue. Can anyone help me?

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

No branches or pull requests

8 participants