You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by "chewbranca (via GitHub)" <gi...@apache.org> on 2024/02/26 21:33:44 UTC

[I] Allow for proxy provided `nonce` in chttpd [couchdb]

chewbranca opened a new issue, #4993:
URL: https://github.com/apache/couchdb/issues/4993

   ## Summary
   
   As mentioned in https://github.com/apache/couchdb/pull/4990, when using a load balancer or proxy in front of CouchDB, the proxy will not receive the chosen `nonce` value from CouchDB until the response headers are sent, which, in the event of long running `_find` queries that return no data, can be a considerable amount of time longer than typical proxy timeouts.
   
   The result is that the Mango reports are logged with the `nonce` value but the proxy timed out the request before getting any response headers so it was never able to retrieve the `nonce` for logging and connecting the proxy logs with the mango report. This is exacerbated by `chttpd:maybe_log` typically being set to false when using a proxy alongside a CouchDB cluster.
   
   I was going to suggest modifying `chttpd:maybe_log` to be configurable based on error types, but @rnewson had a much simpler suggestion of allowing the proxy to provide the `nonce`, thereby establishing the connection from the get go.
   
   I suggest we stick with the existing naming and allow for a request header named `X-Couch-Request-ID`, following https://github.com/apache/couchdb/blob/main/src/chttpd/src/chttpd.erl#L1368.
   
   ## Desired Behaviour
   
   A frontend proxy load balancer to a CouchDB cluster may supply an `X-Couch-Request-ID` to utilize as the `nonce` value instead of randomly generating one here: https://github.com/apache/couchdb/blob/main/src/chttpd/src/chttpd.erl#L297-L317
   
   ## Possible Solution
   
   ```diff
   diff --git a/src/chttpd/src/chttpd.erl b/src/chttpd/src/chttpd.erl
   index ab8e1e9a3..6912115c1 100644
   --- a/src/chttpd/src/chttpd.erl
   +++ b/src/chttpd/src/chttpd.erl
   @@ -294,7 +294,12 @@ handle_request_int(MochiReq) ->
                Other -> Other
            end,
    
   -    Nonce = couch_util:to_hex(crypto:strong_rand_bytes(5)),
   +    Nonce = case MochiReq:get_header_value("x-couch-request-id") of
   +        undefined ->
   +            couch_util:to_hex(crypto:strong_rand_bytes(5));
   +        Nonce0 ->
   +            Nonce0
   +    end,
    
        HttpReq0 = #httpd{
            mochi_req = MochiReq,
   ```
   
   ## Additional context
   
   https://github.com/apache/couchdb/pull/4990
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Allow for proxy provided `nonce` in chttpd [couchdb]

Posted by "chewbranca (via GitHub)" <gi...@apache.org>.
chewbranca closed issue #4993: Allow for proxy provided `nonce` in chttpd
URL: https://github.com/apache/couchdb/issues/4993


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Allow for proxy provided `nonce` in chttpd [couchdb]

Posted by "chewbranca (via GitHub)" <gi...@apache.org>.
chewbranca commented on issue #4993:
URL: https://github.com/apache/couchdb/issues/4993#issuecomment-2981915462

   Closing this out as it was fixed by https://github.com/apache/couchdb/pull/5326


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Allow for proxy provided `nonce` in chttpd [couchdb]

Posted by "rnewson (via GitHub)" <gi...@apache.org>.
rnewson commented on issue #4993:
URL: https://github.com/apache/couchdb/issues/4993#issuecomment-1966188788

   agreed on those extra checks, nick.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Allow for proxy provided `nonce` in chttpd [couchdb]

Posted by "nickva (via GitHub)" <gi...@apache.org>.
nickva commented on issue #4993:
URL: https://github.com/apache/couchdb/issues/4993#issuecomment-1965509117

   +1 to check the length and maybe also ensure it as only alphanumeric characters, no escapes, slashes, semicolons, etc.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Allow for proxy provided `nonce` in chttpd [couchdb]

Posted by "rnewson (via GitHub)" <gi...@apache.org>.
rnewson commented on issue #4993:
URL: https://github.com/apache/couchdb/issues/4993#issuecomment-1966190075

   and a 400 bad request if those checks aren't met, rather than silently ignoring the header or stripping it of invalid chars, etc.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Allow for proxy provided `nonce` in chttpd [couchdb]

Posted by "rnewson (via GitHub)" <gi...@apache.org>.
rnewson commented on issue #4993:
URL: https://github.com/apache/couchdb/issues/4993#issuecomment-1965487142

   good idea, but let's protect ourselves from client input. rejecting an x-couch-request-id that's above a certain length, say.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org