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

Add support for using SSL client certificates when making target HTTP requests. #9

Closed
kevinswiber opened this issue Sep 6, 2016 · 17 comments
Assignees

Comments

@kevinswiber
Copy link
Contributor

This should be a fairly straightforward change. We'll have to add configuration options for key and cert files per host. Then we can update the HTTP agent to use these based on the hostname for the backend request.

@kevinswiber
Copy link
Contributor Author

An early Pull Request is ready for testing here: #11.

@kevinswiber
Copy link
Contributor Author

These changes have been pushed to [email protected]. @srinandan has been testing it out and will report issues here.

To install: npm install -g [email protected].

@zcmack
Copy link

zcmack commented Sep 21, 2016

installed this and am working with it now. attempting to hit a node service running on another machine on the network, getting the following error response. {"message":"write EPROTO","code":"EPROTO","errno":"EPROTO","syscall":"write"}.

I can send you my configuration file if you'd like but I'm wondering if this has to do with using a self signed certificate or not?

@srinandan
Copy link
Contributor

I think it might be something else. Self-signed certs should work. You should set the environment variable NODE_TLS_REJECT_UNAUTHORIZED to 0 if you're using self-signed certs.

Please do send us the configuration file.

@kevinswiber
Copy link
Contributor Author

@zcmack It definitely seems TLS related. I just had a thrilling read through this very long thread: nodejs/node#3692

@asnowfix
Copy link

Usually I get this (misleading) error from EMG when it unsuccessfully tries to directly reach an SSL site while it should use a proxy...

@zcmack
Copy link

zcmack commented Sep 21, 2016

so i created a different express service on my local machine and secured via https. loaded in my certs and am now receiving {"message":"self signed certificate","code":"DEPTH_ZERO_SELF_SIGNED_CERT"}

i included rejectUnauthorized: "false" in my conf file, but I'm still having issues.

@srinandan
Copy link
Contributor

Please set environment variable NODE_TLS_REJECT_UNAUTHORIZED to 0

@zcmack
Copy link

zcmack commented Sep 21, 2016

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; is the first line in my
node service.

On Wed, Sep 21, 2016 at 4:52 PM, Srinandan Sridhar <[email protected]

wrote:

Please set environment variable NODE_TLS_REJECT_UNAUTHORIZED to 0


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#9 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AGFBdi7p46ejUHktcmGnwOa5Nx_4bxSUks5qsacpgaJpZM4J1_BE
.

@srinandan
Copy link
Contributor

Try setting it as an environment variable (outside of node.js).

@zcmack
Copy link

zcmack commented Sep 22, 2016

tried it as an environmental var with no luck. i added rejectUnauthorized=false to my config file and my service and specified the ca in both places as well. My error message changed to

{"message":"self signed certificate in certificate chain","code":"SELF_SIGNED_CERT_IN_CHAIN"}

Any other ideas?

@zcmack
Copy link

zcmack commented Sep 23, 2016

ok so i was able to get this working by setting the environment variable on the EMG rather than the server, my bad. I am curious how we can configure this to use bi-directional SSL. How can I configure a truststore on the EMG?

@kevinswiber
Copy link
Contributor Author

@zcmack You can point to a file for the CA.

targets:
  - host: 'example.com'
    ssl:
      client:
        key: '/location/of/key'
        cert: '/location/of/cert'
        ca: '/location/of/ca'

@kevinswiber
Copy link
Contributor Author

@zcmack It might be worth keeping an eye on this Node PR, as well: "crypto: use system CAs instead of bundled ones" (nodejs/node#8334). It hasn't been merged yet.

@gealogojoemarg
Copy link

@zcmack You can point to a file for the CA.

targets:
  - host: 'example.com'
    ssl:
      client:
        key: '/location/of/key'
        cert: '/location/of/cert'
        ca: '/location/of/ca'

@kevinswiber

When i tried to configure 1 way ssl, i encountered this error.

{"message":"self signed certificate","code":"DEPTH_ZERO_SELF_SIGNED_CERT"}

below is my configuration

edgemicro:
port: 8000
max_connections: 1000
config_change_poll_interval: 600
logging:
level: info
dir: /var/tmp
stats_log_interval: 60
rotate_interval: 24
plugins:
sequence:

  • oauth
    targets:
  • host: 'dev.test.com'
    ssl:
    client:
    ca: '/home/vagrant/dev.test.com.jks'
    passphrase: ncsiph2019
    rejectUnauthorized: false

Hope you have an idea on this error.

@dawncold
Copy link

dawncold commented May 1, 2019

@gealogojoemarg You should make sure your targets config on top level instead of under edgemicro, like this:

edge_config:
  ...some configs...
targets:
  - ssl:
      client:
        ca: '/path/to/your/self/signed/certificate.pem'
edgemicro:
  request_timeout: 7
  port: 8888 #or 8080  #NOTE: never use one of these ports for your backends!!!
  max_connections: 1000
  max_connections_hard: 5000
  config_change_poll_interval: 600  #seconds
... others configs...

If you write it under edgemicro, you will get an empty targets after this line: https://github.com/apigee/microgateway-core/blob/master/lib/config.js#L15

and maybe the documents should be updated, it confused me several hours: https://docs.apigee.com/api-platform/microgateway/2.5.x/operation-and-configuration-reference-edge-microgateway#usingclientssltlsoptions

@relloller
Copy link
Contributor

relloller commented May 1, 2019

@dawncold Thanks for the post. I spent some time on the same issue but didn't get a chance to request the doc update. I have just filed the ticket.

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

7 participants