Skip to content

Instantly share code, notes, and snippets.

@SCdF
Created January 10, 2019 09:48
Show Gist options
  • Save SCdF/fb5f1dd4ebca24a986ce77b3e1a2fa59 to your computer and use it in GitHub Desktop.
Save SCdF/fb5f1dd4ebca24a986ce77b3e1a2fa59 to your computer and use it in GitHub Desktop.
CouchDB MacOS bug

1: no config is present

$ curl -X GET "http://admin:pass@localhost:5984/_node/$COUCH_NODE_NAME/_config/httpd/" | jq .
{
  "port": "5986",
  "max_http_request_size": "4294967296",
  "bind_address": "127.0.0.1",
  "allow_jsonp": "false",
  "enable_cors": "false",
  "socket_options": "[{sndbuf, 262144}]",
  "authentication_handlers": "{couch_httpd_auth, cookie_authentication_handler}, {couch_httpd_auth, default_authentication_handler}",
  "secure_rewrites": "true",
  "enable_xframe_options": "false"
}

In this state, loading http://admin:pass@localhost:5984/_utils will not let you use basic auth.

2: Add config

$ curl -X PUT "http://admin:pass@localhost:5984/_node/$COUCH_NODE_NAME/_config/httpd/WWW-Authenticate"   -d
 '"Basic realm=\"administrator\""' -H "Content-Type: application/json"
$ curl -X GET "http://admin:pass@localhost:5984/_node/$COUCH_NODE_NAME/_config/httpd/" | jq .
{
  "port": "5986",
  "max_http_request_size": "4294967296",
  "bind_address": "127.0.0.1",
  "allow_jsonp": "false",
  "enable_cors": "false",
  "socket_options": "[{sndbuf, 262144}]",
  "WWW-Authenticate": "Basic realm=\"administrator\"",
  "authentication_handlers": "{couch_httpd_auth, cookie_authentication_handler}, {couch_httpd_auth, default_authentication_handler}",
  "secure_rewrites": "true",
  "enable_xframe_options": "false"
}

In this state, loading http://admin:pass@localhost:5984/_utils will let you use basic auth, as expected.

3: restart couchdb

Done by selecting "Quit Apache CouchDB" from the system tray dropdown.

Once it's booted again, we can check config:

$ curl -X GET "http://admin:pass@localhost:5984/_node/$COUCH_NODE_NAME/_config/httpd/" | jq .
{
  "port": "5986",
  "max_http_request_size": "4294967296",
  "www-authenticate": "Basic realm=\"administrator\"",
  "bind_address": "127.0.0.1",
  "allow_jsonp": "false",
  "enable_cors": "false",
  "socket_options": "[{sndbuf, 262144}]",
  "authentication_handlers": "{couch_httpd_auth, cookie_authentication_handler}, {couch_httpd_auth, default_authentication_handler}",
  "secure_rewrites": "true",
  "enable_xframe_options": "false"
}

Note that WWW-Authenticate got saved (or possibly loaded) as www-authenticate. Note also that this option doesn't work: we cannot use basic auth to log in.

For us to use basic auth we have to once again push the setting, with the correct case:

$ curl -X PUT "http://admin:pass@localhost:5984/_node/$COUCH_NODE_NAME/_config/httpd/WWW-Authenticate"   -d
 '"Basic realm=\"administrator\""' -H "Content-Type: application/json"
$ curl -X GET "http://admin:pass@localhost:5984/_node/$COUCH_NODE_NAME/_config/httpd/" | jq .
{
  "port": "5986",
  "max_http_request_size": "4294967296",
  "www-authenticate": "Basic realm=\"administrator\"",
  "bind_address": "127.0.0.1",
  "allow_jsonp": "false",
  "enable_cors": "false",
  "socket_options": "[{sndbuf, 262144}]",
  "WWW-Authenticate": "Basic realm=\"administrator\"",
  "authentication_handlers": "{couch_httpd_auth, cookie_authentication_handler}, {couch_httpd_auth, default_authentication_handler}",
  "secure_rewrites": "true",
  "enable_xframe_options": "false"
}

Note we now have both :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment