-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Enabling 2-way PKI authentication #2759
Comments
I also found myself wanting this feature. I am rolling progressive web app features onto a long lived project. I wanted to make sure that the issues I was seeing were not related to the browser ssl trust errors. I completely get the convention, heuristics, or interactivity over configuration methodology (and appreciate it very much). In the case of SSL, I am already configuring my local to do the I have code that accomplishes this. It basically is the third bullet point from @bitsandbytes original post: Make the webapps' certificate and key configurable. I am reading in I have all the code in I can do a PR (after a little code cleanup), but didn't know if the maintainers think this breaks the too much configuration rule. |
@craineum looks like your implementation was similar to my approach. The only issue is that https does need to be a boolean because create-react-app ultimately sends that to webpack-dev-server, which expects the type to be a boolean. Please correct me if I'm missing any additional changes you made. I have the pathnames to the certs in I initially tried leveraging as much of the proxy object configuration as I could in So, really it appears there needs to be a PR for webpack-dev-server to accept the requestCert method before create-react-app could support fetching the client cert (if it aligns with the philosophy). |
@dbk91 webpack-dev-server https can take an object as well. I also initially tried the proxy approach and ran into the same issues as you. |
@craineum Ah, I see now. My mistake. I must have been thinking of my original issue with create-react-app where the webpackDevServer config file only can send a boolean instead of either a boolean or an object. https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/config/webpackDevServer.config.js#L81 |
I have the same issue, I need to pass a certificate file in to webpackDevServer like so
|
Ok, this is nuts. I didn't even know this was possible with Node, but I found the hack when digging through the code in react-app-rewired. Monkey patch for the win...
if (process.env.NODE_ENV === 'development') {
const devServerConfigPath = 'react-scripts/config/webpackDevServer.config';
const devServerConfig = require(devServerConfigPath);
require.cache[require.resolve(devServerConfigPath)].exports = (
proxy,
allowedHost
) => {
const conf = devServerConfig(proxy, allowedHost);
conf.https = {
key: fs.readFileSync('./path/to/keyfile.key'),
cert: fs.readFileSync('./path/to/pemfile.pem')
};
return conf;
};
} |
@jamesmfriedman where exactly do I put this snippet of code? |
@tobias74 Sorry for the lack of context. A couple of options for you...
|
I got the react-app-rewired working, but when I got to add your conf and modify the key and cert names, it fails to start, I am assuming I have them in the wrong directory, can you clarify if these should be inside of the react-scripts/config folder? The override works without the :
|
@Makr91 root is just a variable for a path, you'll have to define the appropriate path to your file. I'll edit my previous comment to reflect this. |
Does anyone want to submit a PR to support this in some way without monkeypatching? |
@jamesmfriedman That's a great suggestion with React App Rewired. I am using a cert/key from a local CA (which I manually added to my keychain). I have localhost:3000 (react server) running via chrome successfully (green lock :) ). However, when I try to navigate to localhost:5000/auth/googleoauth/signup (starting the oauth flow), I get the following error:
My set up is pretty standard. I am using the same key / cert for the react server as my express / node server, but I assume that's ok because one is proxying the other. Do you have any ideas of how I can fix this? Did you see this in your travels? |
@AlexanderHolman146 How did you get the green lock with create-react-app? I'm still stuck there. |
@AlexanderHolman146 it took me forever to figure this out... Replace the stuff in caps with whatever makes sense for your setup. Make a file called ssl.conf. This file has to be in the directory you are running the bash command from (or you need to update the config path in the bash script)
openssl req \
-new \
-x509 \
-days 3650 \
-sha256 \
-nodes \
-extensions v3_req \
-out ./config/YOUR-OUT-FILE-NAME.local.pem \
-newkey rsa:2048 \
-keyout ./config/YOUR-OUT-FILE-NAME.local.key \
-config <( cat ./ssl.conf ) |
I have a similar use case that motivated me to go down this road. I'm developing a tab app for Microsoft Teams. Their tabs are essentially iframed web apps, but they don't allow http://localhost, even for development (you can upload a dev manifest that points to your local site but it just can't be localhost). So I've been modifying my hosts file to something like Except not quite, because the generated SSL cert is regenerated every time you restart the development server. But the bigger problem is that Teams is an electron app, so there is no way to dangerously bypass the invalid SSL warning that is accessible in chrome. This leaves me with the need to add the generated cert to my root CA store for my local machine. This works if I am hitting So I was able to get the monkey patching approach working as laid out by @jamesmfriedman (thanks for that as a short term solution). I also used his openssl script to generate my certs (I may never have figured that out). The key point seems to be that if your goal is to turn the browser lock icon green, it's not enough to just generate a normal ssl cert. You need it to be a CA with the correct DNS specifiers. I could be all wrong about this, but I couldn't get anything other than this to work. But I agree with @gaearon that this monkey patching isn't ideal, and I'd love to help out with a PR (or direction towards one) if I can. From my experience, I see a few things that would be steps in the right direction:
The last option is more flexible, but ultimately isn't what I really am after here. And honestly, it's a lot more work to specify your own cert than to have those other first two points just work. So I would shoot for those first two points as a first good goal that would increase usability and leave the open-ended configuration piece left for last. And finally, I'm not convinced all of this makes sense. There may be a better way or something I'm missing so please chime in on this aging thread if you want to steer my thinking in a different direction. Thanks! |
@gaearon is this still something you would be open to a PR for? The change would be contained to
with
And
|
@hansena Naive assumption here, but I'm inclined to believe that version 2 of Provided you can pass in the desired SSL options (which it looks like you can just interact with the normal http-proxy-middleware object), this would probably be the way to go as you would not have to rely on passing file paths in I'll try to see if I can get a working example this weekend to confirm that this is possible in the latest version. |
@dbk91 Did you get an example working? This would be really useful for my project. |
@dbk91 I'm also very interested in a working example |
Okay, so I finally got the chance to look into it. Unfortunately, as far as I can tell, my assumption was both naive and incorrect. I was assuming you could configure the server on the fly through the const fs = require('fs');
const path = require('path');
const proxy = require('http-proxy-middleware');
// Just reading certificates from outside src/
const key = fs.readFileSync(path.resolve(__dirname, '..', 'localhost-key.pem'));
const cert = fs.readFileSync(path.resolve(__dirname, '..', 'localhost.pem'));
module.exports = function(app) {
app.use(proxy('*', { target: 'localhost:4000', ssl: { key, cert } }));
}; However, this is for the proxy middleware, not the dev server configuration itself. I don't think any of the configuration parameters a user can pass in could override it. Here's the spot that tells the dev server to use self-signed certificates. I believe that's because passing a boolean creates self-signed certificates using webpack-dev-server. If there was a way to override that https variable with an object containing the paths to the key and cert rather than a boolean, you'd have a dev server using you certs of choice (I did confirm this using certs of my own). It may still be possible to have something override the config, but if there isn't, it's going to take a pull request to get this feature in. I'd say it's probably low-priority for the CRA team, and the way one implements it is important. But I'd say this is a useful feature. I think the lowest effort thing to do would be to allow the user to plop a directory with a specific name, and if there is a key and a cert in there, CRA will use it as the development certificates. This would probably live next to |
I need 2-way authentication to be configurable because my company requires all internal webapps to use it.
The proposal is three-fold. I want the following to be configurable:
Background on this:
Without the above I can't easily test my passport setup and can't easily test my custom authentication code until I build for production.
My open questions are:
The text was updated successfully, but these errors were encountered: