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 etcd http basic auth support #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ You can configure the builtin server using environment variables:

* AUTH_USER: Username for http basic auth (skip to disable auth)
* AUTH_PASS: Password for http basic auth
* ETCD_AUTH_USER: Username for etcd http basic auth (skip to disable auth)
* ETCD_AUTH_PASS: Password for etcd http basic auth
* ETCD_HOST: IP of the etcd host the internal proxy should use [172.17.42.1]
* ETCD_PORT: Port of the etcd daemon [4001]
* SERVER_PORT: Port of builtin server

If you use a secured etcd:
* ETCDCTL_CA_FILE
* ETCDCTL_KEY_FILE
* ETCDCTL_CERT_FILE
* ETCDCTL_CERT_FILE
10 changes: 9 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ var serverPort = process.env.SERVER_PORT || 8000;
var publicDir = 'frontend';
var authUser = process.env.AUTH_USER;
var authPass = process.env.AUTH_PASS;

var etcdAuthUser = process.env.ETCD_AUTH_USER;
var etcdAuthPass = process.env.ETCD_AUTH_PASS;


var mimeTypes = {
Expand Down Expand Up @@ -93,6 +94,13 @@ function proxy(client_req, client_res) {
opts.cert = fs.readFileSync(cert_file);
}

// etcd http basic auth
if(etcdAuthUser && etcdAuthPass) {
opts.headers = {
"Authorization" : "Basic " + new Buffer(etcdAuthUser + ':' + etcdAuthPass).toString('base64')
}
}

client_req.pipe(requester(opts, function(res) {
// if etcd returns that the requested page has been moved
// to a different location, indicates that the node we are
Expand Down