Commit Graph

1595 Commits

Author SHA1 Message Date
Krzysztof Piotr Oledzki
8c8bd4593c [MAJOR] use the new auth framework for http stats
Support the new syntax (http-request allow/deny/auth) in
http stats.

Now it is possible to use the same syntax is the same like in
the frontend/backend http-request access control:
 acl src_nagios src 192.168.66.66
 acl stats_auth_ok http_auth(L1)

 stats http-request allow if src_nagios
 stats http-request allow if stats_auth_ok
 stats http-request auth realm LB

The old syntax is still supported, but now it is emulated
via private acls and an aditional userlist.
2010-01-31 19:14:09 +01:00
Krzysztof Piotr Oledzki
f9423ae43a [MINOR] acl: add http_auth and http_auth_group
Add two acls to match http auth data:
 acl <name> http_auth(userlist)
 acl <name> http_auth_hroup(userlist) group1 group2 (...)
2010-01-31 19:14:09 +01:00
Krzysztof Piotr Oledzki
59bb218b86 [MINOR] http-request: allow/deny/auth support for frontend/backend/listen
Use the generic auth framework to control access to frontends/backends/listens
2010-01-31 19:14:08 +01:00
Krzysztof Piotr Oledzki
d7528e5a60 [MINOR] add ACL_TEST_F_NULL_MATCH
Add ACL_TEST_F_NULL_MATCH so expr->kw->match can be called
even if expr->patterns is empty.
2010-01-31 19:14:07 +01:00
Krzysztof Piotr Oledzki
961050465e [MINOR] generic auth support with groups and encrypted passwords
Add generic authentication & authorization support.

Groups are implemented as bitmaps so the count is limited to
sizeof(int)*8 == 32.

Encrypted passwords are supported with libcrypt and crypt(3), so it is
possible to use any method supported by your system. For example modern
Linux/glibc instalations support MD5/SHA-256/SHA-512 and of course classic,
DES-based encryption.
2010-01-31 19:14:07 +01:00
Krzysztof Piotr Oledzki
fccbdc8421 [MINOR] Base64 decode
Implement Base64 decoding with a reverse table.

The function accepts and decodes classic base64 strings, which
can be composed from many streams as long each one is properly
padded, for example: SGVsbG8=IEhBUHJveHk=IQ==
2010-01-31 19:14:07 +01:00
Krzysztof Piotr Oledzki
4a3323b83d [CONTRIB] add base64rev-gen.c that was used to generate the base64rev table.
There is no offcial reverse table for base64, so a short
program is required to generate one.
2010-01-31 19:14:07 +01:00
Willy Tarreau
c097e32059 [DOC] add some missing ACLs about response header matching 2010-01-31 15:54:35 +01:00
Willy Tarreau
fdb563c06f [MEDIUM] http: add support for conditional response header rewriting
Just as for the req* rules, we can now condition rsp* rules with ACLs.
ACLs match on response, so volatile request information cannot be used.
A warning is emitted if a configuration contains such an anomaly.
2010-01-31 15:43:27 +01:00
Willy Tarreau
8abd4cd526 [MEDIUM] http: add support for conditional request header addition
Now the reqadd rules also support ACLs. All req* rules are converted
now.
2010-01-31 15:12:45 +01:00
Willy Tarreau
97ec969077 [DOC] add some build info about the AIX platform
(cherry picked from commit e41914c77e)
2010-01-29 10:30:19 +01:00
Willy Tarreau
5321c42722 [MEDIUM] http: add support for conditional request filter execution
All the req* rules except the reqadd rules can now be specified with
an if/unless condition. If a condition is specified and does not match,
the filter is ignored. This is particularly useful with reqidel, reqirep
and reqtarpit.
2010-01-28 20:35:13 +01:00
Willy Tarreau
6c123b15cb [MEDIUM] http: make the request filter loop check for optional conditions
From now on, if request filters have ACLs defined, these ACLs will be
evaluated to condition the filter. This will be used to conditionally
remove/rewrite headers based on ACLs.
2010-01-28 20:22:06 +01:00
Willy Tarreau
ade5ec430d [MEDIUM] config: factor out the parsing of 20 req*/rsp* keywords
A new function was added to take care of the common code between
all those keywords. This has saved 8 kB of object code and about
500 lines of source code. This has also permitted to spot and fix
minor bugs (allocated args that were never used).

The code could be factored even more but that would make it a bit
more complex which is not interesting at this stage.

Various tests have been performed, and the warnings and errors are
still correctly reported and everything seems to work as expected.
2010-01-28 19:42:59 +01:00
Willy Tarreau
3ec18a0eee [CLEANUP] config: specify correct const char types to warnif_* functions
Also factor out a few declarations of acl_cond everywhere.
2010-01-28 19:01:34 +01:00
Willy Tarreau
f4f04125d4 [MINOR] prepare req_*/rsp_* to receive a condition
It will be very handy to be able to pass conditions to req_* and rsp_*.
For now, we just add the pointer to the condition in the affected
structs.
2010-01-28 18:10:50 +01:00
Willy Tarreau
f1e98b8628 [CLEANUP] config: use warnif_cond_requires_resp() to check for bad ACLs
Factor out some repetitive copy-pasted code to check for request ACLs
validity.
2010-01-28 17:59:39 +01:00
Willy Tarreau
ef6494cb8c [CLEANUP] config: use build_acl_cond() instead of parse_acl_cond()
This allows to clean up the code a little bit by moving some of the
ACL internals out of the config parser.
2010-01-28 17:12:36 +01:00
Willy Tarreau
2bbba415d7 [MINOR] acl: add build_acl_cond() to make it easier to add ACLs in config
This function automatically builds a rule, considering the if/unless
statements, and automatically updates the proxy's acl_requires, the
condition's file and line.
2010-01-28 16:48:33 +01:00
Willy Tarreau
c3e8b25c79 [MINOR] http: disable keep-alive when process is going down
Krzysztof Oledzki suggested to disable keep-alive when a process
is going down due to a reload, in order to avoid ever-lasting
sessions. This is a simple and very efficient solution as it
ensures that at most one more request will be handled on a
keep-alive connection after the process has received a SIGUSR1
signal.
2010-01-28 15:01:20 +01:00
Willy Tarreau
910ba4bb8b [BUG] halog: fix segfault in case of empty log in PCT mode
(cherry picked from commit fe362fe476)
2010-01-28 10:07:26 +01:00
Willy Tarreau
db40a1c8bd [BUILD] halog: make without arch-specific optimizations 2010-01-28 10:07:07 +01:00
Willy Tarreau
ef78104947 [MINOR] checks: add the server's status in the checks
Now a server can check the contents of the header X-Haproxy-Server-State
to know how haproxy sees it. The same values as those reported in the stats
are provided :
  - up/down status + check counts
  - throttle
  - weight vs backend weight
  - active sessions vs backend sessions
  - queue length
  - haproxy node name
2010-01-27 20:16:12 +01:00
Willy Tarreau
e9d8788fdd [MINOR] checks: make the HTTP check code add the CRLF itself
Currently we cannot easily add headers nor anything to HTTP checks
because the requests are pre-formatted with the last CRLF. Make the
check code add the CRLF itself so that we can later add useful info.
2010-01-27 20:16:12 +01:00
Willy Tarreau
1edb144b8d [BUG] restore accidentely removed line in last patch !
The test condition for the acl expression validity got dropped, and
only the error remained. Error reported by Krzysztof Oledzki.
2010-01-27 20:13:38 +01:00
Willy Tarreau
ac778f5ade [CLEANUP] acl, patterns: make use of my_strndup() instead of malloc+memcpy
This is simpler and more readable.
2010-01-26 19:02:46 +01:00
Willy Tarreau
0c55931696 [MINOR] config: off-by-one in "stick-table" after list of converters 2010-01-26 18:36:26 +01:00
Willy Tarreau
d31d6eb89a [MINOR] pattern: add the "ipmask()" converting function
This converter can be applied on top of an IPv4-type pattern. It
applies a netmask which is suited for IP address storage and matching.
This can be used to make all hosts within a certain mask to share the
same table entries and as such use the same server.

The mask can be passed in dotted form (eg: 255.255.255.0) or in CIDR
form (eg: 24).
2010-01-26 18:05:48 +01:00
Willy Tarreau
9e92d327f7 [MINOR] pattern: add support for argument parsers for converters
Some converters will need one or several arguments. It's not possible
to write a simple generic parser for that, so let's add the ability
for each converter to support its own argument parser, and call it
to get the arguments when it's specified. If unspecified, the arguments
are passed unmodified as string+len.
2010-01-26 18:01:35 +01:00
Willy Tarreau
2937c0dd20 [MINOR] standard: str2mask: string to netmask converter
This function converts a dotted or CIDR value to a netmask.
2010-01-26 17:36:17 +01:00
Willy Tarreau
1a51b6342e [MINOR] pattern: make the converter more flexible by supporting void* and int args
The pattern type converters currently support a string arg and a length.
Sometimes we'll prefer to pass them a list or a structure. So let's convert
the string and length into a generic void* and int that each converter may
use as it likes.
2010-01-26 17:17:56 +01:00
Willy Tarreau
a724d49b6e [BUG] patterns: copy-paste typo in type conversion arguments 2010-01-26 16:48:20 +01:00
Willy Tarreau
7aabd11cec [STATS] make it possible to change a CLI connection timeout
Sometimes it helps to be able to change an interactive CLI connection
timeout. Now we just have to enter "set timeout cli <value>" to do that.
2010-01-26 11:11:42 +01:00
Willy Tarreau
2eba6aaa1b [RELEASE] Released version 1.4-dev8
Released version 1.4-dev8 with the following main changes :
    - [CLEANUP] Keep in sync "defaults" support between documentation and code
    - [MEDIUM] http: add support for Proxy-Connection header
    - [CRITICAL] buffers: buffer_insert_line2 must not change the ->w entry
    - [MINOR] http: remove a copy-paste typo in transaction cleaning
    - [BUG] http: trim any excess buffer data when recycling a connection
2010-01-25 23:28:05 +01:00
Cyril Bonté
99ed327d62 [CLEANUP] Keep in sync "defaults" support between documentation and code
Hi Willy,

I've made a quick pass on the "defaults" column in the Proxy keywords matrix (chapter 4.1. in the documentation).
This patch resyncs the code and the documentation. I let you decide if some keywords that still work in the "defaults" section should be forbidden.

- default_backend : in the matrix, "defaults" was not supported but the keyword details say it is.
Tests also shows it works, then I've updated the matrix.

- capture cookie : in the keyword details, we can read `It is not possible to specify a capture in a "defaults" section.'.
Ok, even if the tests worked, I've added an alert in the configuration parser (as it is for capture request/response header).

- description : not supported in "defaults", I added an alert in the parser.
I've also noticed that this keyword doesn't appear in the documentation.
There's one "description" entry, but for the "global" section, which is for a different use (the patch doesn't update the documentation).

- grace : even if this is maybe useless, it works in "defaults". Documentation is updated.
- redirect : alert is added in the parser.
- rsprep : alert added in the parser.

--
Cyril Bonté
2010-01-25 23:20:35 +01:00
Willy Tarreau
739cfbab6a [BUG] http: trim any excess buffer data when recycling a connection
We must trim any excess data from the response buffer when recycling
a keep-alive connection, because we may have blocked an invalid response
from a server that we don't want to accidentely forward once we disable
the analysers, nor do we want those data to come along with next response.
A typical example of such data would be from a buggy server responding to
a HEAD with some data, or sending more than the advertised content-length.
2010-01-25 23:11:14 +01:00
Willy Tarreau
d08f82ebe2 [MINOR] http: remove a copy-paste typo in transaction cleaning
For deciding to set the BF_EXPECT_MORE, we reused the same code as in
http_wait_for_request(), but here we must ignore buf->lr which is not
yet set and useless. This might only have caused random sub-optimal
behaviours.
2010-01-25 22:46:30 +01:00
Willy Tarreau
c5bbe53f6f [CRITICAL] buffers: buffer_insert_line2 must not change the ->w entry
Krzysztof Oledzki reported that 1.4-dev7 would regularly crash
on an apparently very common workload. The cores he provided
showed some inter-buffer data corruption, exactly similar to
what was fixed by the following recent commit :

bbfa7938bd [BUG] buffer_replace2 must never change the ->w entry

In fact, it was buffer_insert_line2() which was still modifying the
->w pointer, causing issues with pipelined responses in keep-alive
mode if some headers were to be added.

The bug requires a remote client, a near server, large server buffers
and small client buffers to be reproduced, with response header
insertion. Still, it's surprizing that it did not trigger earlier.

Now after 100k pipelined requests it did not trigger anymore.
2010-01-25 20:46:42 +01:00
Willy Tarreau
88d349d25d [MEDIUM] http: add support for Proxy-Connection header
Despite what is explicitly stated in HTTP specifications,
browsers still use the undocumented Proxy-Connection header
instead of the Connection header when they connect through
a proxy. As such, proxies generally implement support for
this stupid header name, breaking the standards and making
it harder to support keep-alive between clients and proxies.

Thus, we add a new "option http-use-proxy-header" to tell
haproxy that if it sees requests which look like proxy
requests, it should use the Proxy-Connection header instead
of the Connection header.
2010-01-25 12:48:26 +01:00
Willy Tarreau
6939b5522d [RELEASE] Released version 1.4-dev7
Released version 1.4-dev7 with the following main changes :
    - [BUG] appsession: possible memory leak in case of out of memory condition
    - [MINOR] config: don't accept 'appsession' in defaults section
    - [MINOR] Add function to parse a size in configuration
    - [MEDIUM] Add stick table (persistence) management functions and types
    - [MEDIUM] Add pattern fetch management types and functions
    - [MEDIUM] Add src dst and dport pattern fetches.
    - [MEDIUM] Add stick table configuration and init.
    - [MEDIUM] Add stick and store rules analysers.
    - [MINOR] add option "mysql-check" to use MySQL health checks
    - [BUG] health checks: fix requeued message
    - [OPTIM] remove SSP_O_VIA and SSP_O_STATUS
    - [BUG] checks: fix newline termination
    - [MINOR] acl: add fe_id/so_id to match frontend's and socket's id
    - [BUG] appsession's sessid must be reset at end of transaction
    - [BUILD] appsession did not build anymore under gcc-2.95
    - [BUG] server redirection used an uninitialized string.
    - [MEDIUM] http: fix handling of message pointers
    - [MINOR] http: fix double slash prefix with server redirect
    - [MINOR] http redirect: add the ability to append a '/' to the URL
    - [BUG] stream_interface: fix retnclose and remove cond_close
    - [MINOR] http redirect: don't explicitly state keep-alive on 1.1
    - [MINOR] http: move appsession 'sessid' from session to http_txn
    - [OPTIM] reorder http_txn to optimize cache lines placement
    - [MINOR] http: differentiate waiting for new request and waiting for a complete requst
    - [MINOR] http: add a separate "http-keep-alive" timeout
    - [MINOR] config: remove undocumented and buggy 'timeout appsession'
    - [DOC] fix various too large lines
    - [DOC] remove several trailing spaces
    - [DOC] add the doc about stickiness
    - [BUILD] remove a warning in standard.h on AIX
    - [BUG] checks: chars are unsigned on AIX, check was always true
    - [CLEANUP] stream_sock: MSG_NOSIGNAL is only for send(), not recv()
    - [BUG] check: we must not check for error before reading a response
    - [BUG] buffers: remove remains of wrong obsolete length check
    - [OPTIM] stream_sock: don't shutdown(write) when the socket is in error
    - [BUG] http: don't count req errors on client resets or t/o during keep-alive
    - [MEDIUM] http: don't switch to tunnel mode upon close
    - [DOC] add documentation about connection header processing
    - [MINOR] http: add http_remove_header2() to remove a header value.
    - [MINOR] tools: add a "word_match()" function to match words and ignore spaces
    - [MAJOR] http: rework request Connection header handling
    - [MAJOR] http: rework response Connection header handling
    - [MINOR] add the ability to force kernel socket buffer size.
    - [BUG] http_server_error() must not purge a previous pending response
    - [OPTIM] http: don't delay response if next request is incomplete
    - [MINOR] add the "force-persist" statement to force persistence on down servers
    - [MINOR] http: logs must report persistent connections to down servers
    - [BUG] buffer_replace2 must never change the ->w entry
2010-01-25 01:54:37 +01:00
Willy Tarreau
bbfa7938bd [BUG] buffer_replace2 must never change the ->w entry
This function is used to move data which is located between ->w and ->r,
so it must not touch ->w, otherwise it will displace pending data which
is before the one we're actually overwriting. The issue arises with
some pipelined responses which cause some part of the previous one to
be chopped off when removing the connection: close header, thus
corrupting last response and shifting next one. Those are detected
in the logs because the next response will be a 502 with flags PH.
2010-01-25 01:53:38 +01:00
Willy Tarreau
2a6d88dafe [MINOR] http: logs must report persistent connections to down servers
When using "option persist" or "force-persist", we want to know from the
logs if the cookie referenced a valid server or a down server. Till here
the flag reported a valid server even if the server was down, which is
misleading. Now we correctly report that the requested server was down.
We can typically see "--DI" when using "option persist" with redispatch,
ad "SCDN" when using force-persist on a down server.
2010-01-24 13:10:43 +01:00
Willy Tarreau
4de9149f87 [MINOR] add the "force-persist" statement to force persistence on down servers
This is used to force access to down servers for some requests. This
is useful when validating that a change on a server correctly works
before enabling the server again.
2010-01-22 19:10:05 +01:00
Willy Tarreau
ff7b5883c0 [OPTIM] http: don't delay response if next request is incomplete
We use to delay the response if there is a new request in the buffer.
However, if the pending request is incomplete, we should not delay the
pending responses.
2010-01-22 14:43:47 +01:00
Willy Tarreau
d5fd51c75b [BUG] http_server_error() must not purge a previous pending response
This can cause parts of responses to be truncated in case of
pipelined requests if the second request generates an error
before the first request is completely flushed.
2010-01-22 14:20:17 +01:00
Willy Tarreau
e803de2c6b [MINOR] add the ability to force kernel socket buffer size.
Sometimes we need to be able to change the default kernel socket
buffer size (recv and send). Four new global settings have been
added for this :
   - tune.rcvbuf.client
   - tune.rcvbuf.server
   - tune.sndbuf.client
   - tune.sndbuf.server

Those can be used to reduce kernel memory footprint with large numbers
of concurrent connections, and to reduce risks of write timeouts with
very slow clients due to excessive kernel buffering.
2010-01-22 11:49:41 +01:00
Willy Tarreau
6046652253 [MAJOR] http: rework response Connection header handling
This one is the next step of previous patch. It correctly computes
the response mode and the Connection flag transformations depending
on the request mode and version, and the response version and headers.

We're now also able to add "Connection: keep-alive", and to convert
server's close during a keep-alive connection to a server-close
connection.
2010-01-22 11:49:41 +01:00
Willy Tarreau
bbf0b37f6c [MAJOR] http: rework request Connection header handling
We need to improve Connection header handling in the request for it
to support the upcoming keep-alive mode. Now we have two flags which
keep in the session the information about the presence of a
Connection: close and a Connection: keep-alive headers in the initial
request, as well as two others which keep the current state of those
headers so that we don't have to parse them again. Knowing the initial
value is essential to know when the client asked for keep-alive while
we're forcing a close (eg in server-close mode). Also the Connection
request parser is now able to automatically remove single header values
at the same time they are parsed. This provides greater flexibility and
reliability.

All combinations of listen/front/back in all modes and with both
1.0 and 1.1 have been tested.
2010-01-22 11:49:35 +01:00
Willy Tarreau
348238b3a9 [MINOR] tools: add a "word_match()" function to match words and ignore spaces
Some header values might be delimited with spaces, so it's not enough to
compare "close" or "keep-alive" with strncasecmp(). Use word_match() for
that.
2010-01-18 19:51:39 +01:00
Willy Tarreau
68085d8cfb [MINOR] http: add http_remove_header2() to remove a header value.
Calling this function after http_find_header2() automatically deletes
the current value of the header, and removes the header itself if the
value is the only one. The context is automatically adjusted for a
next call to http_find_header2() to return the next header. No other
change nor test should be made on the transient context though.
2010-01-18 19:51:33 +01:00