Commit Graph

2570 Commits

Author SHA1 Message Date
Ivan Kozlovic
1e08b67f08 [FIXED] User and claims activation revocation checks
This addresses [CVE-2020-26892](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-26892)

This is a port of #1632, #1635 and #1645

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-10-21 10:33:33 -06:00
Ivan Kozlovic
9ff8bcde2e [FIXED] Possible panic if server receives a maliciously crafted JWT
This addresses [CVE-2020-26521](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-26521)

This is mainly a port of #1624 with some other updates related
to tests.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-10-21 10:22:57 -06:00
Ivan Kozlovic
c0b574faf3 Merge pull request #1583 from nats-io/release_2_1_8
Release 2.1.8
v2.1.8
2020-09-03 16:59:17 -06:00
Ivan Kozlovic
eb5c052df6 Release 2.1.8
This is based on branch_2_1_x and includes the following fixes:

[FIXED] Allow response permissions to work across accounts
[FIXED] Race condition during implicit Gateway reconnection
[FIXED] Possible stall on shutdown with leafnode setup
[FIXED] Possible removal of interest on queue subs with leaf nodes
[FIXED] Unsubscribe may not be propagated through a leaf node
[FIXED] LeafNode solicit failure race could leave conn registered
[FIXED] Handling or real duplicate subscription
[FIXED] Log file size limit not honored after re-open signal
[FIXED] Connection name in log statement for some IPv6 addresses
[FIXED] Better support for distinguishedNameMatch in TLS Auth
[FIXED] Error when importing an account results in an error

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-09-03 15:39:47 -06:00
Matthias Hanel
b3390a60e4 [FIXED] Error when importing an account results in an error
When the account that could not be imported is updated, update the
original account as well.

Fixes #1582

Signed-off-by: Matthias Hanel <mh@synadia.com>
2020-09-03 14:31:11 -06:00
Waldemar Quevedo
7a88eee090 [FIXED] Better support for distinguishedNameMatch in TLS Auth
Signed-off-by: Waldemar Quevedo <wally@synadia.com>
2020-09-03 10:12:06 -06:00
Ivan Kozlovic
12ae32a477 [FIXED] Connection name in log statement for some IPv6 addresses
If an IPv6 address contains some "%" characters, this was causing
the connection name in log statement to mess up the Sprintf formatting.
The solution is to escape those "%" characters.

Resolves #1505

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-09-01 08:23:45 -06:00
Ivan Kozlovic
36d24550fe [FIXED] Log file size limit not honored after re-open signal
When the logfile_size_limit option is specified, the logfile will
be automatically rotated. However, if user still sends the re-open
signal (SIGUSR1), the log file will then no longer apply the
size limit.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-09-01 08:11:34 -06:00
Ivan Kozlovic
073789b860 Fix flappers
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-08-27 17:07:04 -06:00
Ivan Kozlovic
ff89a5f277 [FIXED] Handling or real duplicate subscription
That is, if the server receives "SUB foo 1" more than once from
the same client, we would register in the client map this subscription
only once, and add to the account's sublist only once, however we
would have updated shadow subscriptions and route/gateway maps for
each SUB protocol, which would result in inability to send unsubscribe
to routes when the client goes away or unsubscribes.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-08-27 15:10:22 -06:00
Ivan Kozlovic
2f877e7755 Fixed flapper
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-08-27 15:05:12 -06:00
Ivan Kozlovic
fa9de548b1 [FIXED] LeafNode solicit failure race could leave conn registered
This was found due to a recent test that was flapping. The test
was not checking the correct server for leafnode connection, but
that uncovered the following bug:

When a leafnode connection is solicited, the read/write loops are
started. Then, the connection lock is released and several
functions invoked to register the connection with an account and
add to the connection leafs map.
The problem is that the readloop (for instance) could get a read
error and close the connection *before* the above said code
executes, which would lead to a connection incorrectly registered.

This could be fixed either by delaying the start of read/write loops
after the registration is done, or like in this PR, check the
connection close status after registration, and if closed, manually
undoing the registration with account/leafs map.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-08-27 15:04:40 -06:00
Ivan Kozlovic
7e22004c3a [FIXED] Unsubscribe may not be propagated through a leaf node
There is a race between the time the processing of a subscription
and the init/send of subscriptions when accepting a leaf node
connection that may cause internally a subscription's subject
to be counted many times, which would then prevent the send of
an LS- when the subscription's interest goes away.

Imagine this sequence of events, each side represents a "thread"
of execution:
```
client readLoop                         leaf node readLoop
----------------------------------------------------------
recv SUB foo 1
sub added to account's sublist

                                         recv CONNECT
                                     auth, added to acc.

updateSmap
smap["foo"]++ -> 1
no LS+ because !allSubsSent

                                         init smap
                                    finds sub in acc sl
                                    smap["foo"]++ -> 2
                                        sends LS+ foo
                                    allSubsSent == true

recv UNSUB 1
updateSmap
smap["foo"]-- -> 1
no LS- because count != 0
----------------------------------------------------------
```
Equivalent result but with slightly diffent execution:
```
client readLoop                         leaf node readLoop
----------------------------------------------------------
recv SUB foo 1
sub added to account's sublist

                                         recv CONNECT
                                     auth, added to acc.

                                         init smap
                                    finds sub in acc sl
                                    smap["foo"]++ -> 1
                                        sends LS+ foo
                                    allSubsSent == true

updateSmap
smap["foo"]++ -> 2
no LS+ because count != 1

recv UNSUB 1
updateSmap
smap["foo"]-- -> 1
no LS- because count != 0
----------------------------------------------------------
```

The approach for the fix is delay the creation of the smap
until we actually initialize the map and send the subs on processing
of the CONNECT.
In the meantime, as soon as the LN connection is registered
and available in updateSmap, we check that smap is nil or
not. If nil, we do nothing.

In "init smap" we keep track of the subscriptions that have been
added to smap. This map will be short lived, just enough to
protect against races above.

In updateSmap, when smap is not nil, we need to checki, if we
are adding, that the subscription has not already been handled.
The tempory subscription map will be ultimately emptied/set to
nil with the use of a timer (if not emptied in place when
processing smap updates).

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-08-27 14:48:42 -06:00
Ivan Kozlovic
fe31ab3796 [FIXED] Possible removal of interest on queue subs with leaf nodes
Server was incorrectly processing a queue subscription removal
as both a plain sub and queue sub, which may have resulted in
drop of interest even when some queue subs remained.

Resolves #1421

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-08-27 14:39:19 -06:00
Ivan Kozlovic
87c00e3e8f [FIXED] Possible stall on shutdown with leafnode setup
If a leafnode connection is accepted but the server is shutdown
before the connection is fully registered, the shutdown would
stall because read and write loop go routine would not be
stopped.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-08-27 14:38:22 -06:00
Ivan Kozlovic
df676b7c63 [FIXED] Race condition during implicit Gateway reconnection
Say server in cluster A accepts a connection from a server in
cluster B.
The gateway is implicit, in that A does not have a configured
remote gateway to B.
Then the server in B is shutdown, which A detects and initiate
a single reconnect attempt (since it is implicit and if the
reconnect retries is not set).
While this happens, a new server in B is restarted and connects
to A. If that happens before the initial reconnect attempt
failed, A will register that new inbound and do not attempt to
solicit because it has already a remote entry for gateway B.
At this point when the reconnect to old server B fails, then
the remote GW entry is removed, and A will not create an outbound
connection to the new B server.

We fix that by checking if there is a registered inbound when
we get to the point of removing the remote on a failed implicit
reconnect. If there is one, we try the reconnection.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-08-27 14:36:54 -06:00
Ivan Kozlovic
6e3401eb81 [FIXED] Allow response permissions to work across accounts
This is a port of https://github.com/nats-io/nats-server/pull/1487

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-08-27 14:33:53 -06:00
Ivan Kozlovic
bf0930ee76 Merge pull request #1394 from nats-io/release_2_1_7
Release v2.1.7
v2.1.7
2020-05-14 11:33:56 -06:00
Ivan Kozlovic
b329215af3 Release v2.1.7
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-05-13 19:40:49 -06:00
Ivan Kozlovic
54e014070f Merge pull request #1392 from guilherme-santos/master
[ADDED] base path for monitoring endpoints
2020-05-13 16:28:57 -06:00
Guilherme Santos
25858cba0b Implement basePath for monitoring endpoints 2020-05-13 23:29:11 +02:00
Ivan Kozlovic
0c3acfbaad Merge pull request #1393 from nats-io/internal_client_reload
Move reset of internal client to after the account sublist was moved.
2020-05-13 14:43:30 -06:00
Matthias Hanel
d486f6ab9b Move reset of internal client to after the account sublist was moved.
This does not avoid the race condition, but makes it less likely to
trigger in unit tests.

Signed-off-by: Matthias Hanel <mh@synadia.com>
2020-05-13 15:52:29 -04:00
Ivan Kozlovic
09a58cbada Merge pull request #1387 from nats-io/reload
[FIXED] Unnecessary account reloads
2020-05-12 16:09:39 -06:00
Ivan Kozlovic
9a6c840039 Merge pull request #1391 from nats-io/default_perms
[FIXED] default_permissions apply to nkey users as well
2020-05-12 16:08:12 -06:00
Matthias Hanel
04b81abdde [FIXED] default_permissions apply to nkey users as well
Fixes 1390

Signed-off-by: Matthias Hanel <mh@synadia.com>
2020-05-12 17:13:25 -04:00
Matthias Hanel
11c0669ae2 [FIXES] Unnecessary account reloads and pointer to old accounts
Fixes #1372 by updating s.sys.account pointer.

This issue also showed that accounts are unnecessarily reloaded.
This happened because account imports were not copied and thus,
deepEqual detected a difference were none was.
This was addressed by making the copy less shallow.

Furthermore did deepEqual detects a difference when it compared
slices that were appended to while processing a map.
This was fixed by sorting before comparison.

Noticed that Account.clients stored an unnecessary pointer.
Removed duplicated code in systemAccount.

Signed-off-by: Matthias Hanel <mh@synadia.com>
2020-05-11 21:51:41 -04:00
Waldemar Quevedo
db5c8aec8a Merge pull request #1386 from wallyqs/tls-auth-rdns
Add support to match domainComponent (DC) in RDNSequence with TLS Auth
2020-05-11 17:54:54 -07:00
Waldemar Quevedo
9a2d095885 Add support to match domainComponent (DC) in RDNSequence with TLS Auth
Currently when using TLS based authentication, any domain components
that could be present in the cert will be omitted since Go's
ToRDNSequence is not including them:

202c43b2ad/src/crypto/x509/pkix/pkix.go (L226-L245)

This commit adds support to include the domain components in case
present, also roughly following the order suggested at:
https://tools.ietf.org/html/rfc2253

Signed-off-by: Waldemar Quevedo <wally@synadia.com>
2020-05-11 17:41:11 -07:00
Ivan Kozlovic
80b4857cd7 Merge pull request #1385 from nats-io/fix_close_conn
[FIXED] Early closed connection may linger in the server
2020-05-08 12:01:57 -06:00
Ivan Kozlovic
46f880bc52 [FIXED] Early closed connection may linger in the server
If the connection is marked as closed while sending the INFO, the
connection would not be removed from the internal map, which would
cause it to be shown in the monitoring list of opened connections.

Resolves #1384

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-05-08 12:01:15 -06:00
Ivan Kozlovic
81fabde729 Merge pull request #1362 from nats-io/monitoring_as_systemevents
[ADDED] Making monitoring endpoints available via system services.
2020-05-07 11:37:50 -06:00
Ivan Kozlovic
1ab26dfa0f Merge pull request #1381 from nats-io/validateOnReload
[FIXED] on reload, check error conditions checked in validateOptions
2020-05-06 15:50:03 -06:00
Matthias Hanel
0eae40070b [FIXED] on reload, check error conditions checked in validateOptions
Fixes #1378 by calling validateOptions on reload
Add missing comment to validateOptions

Signed-off-by: Matthias Hanel <mh@synadia.com>
2020-05-06 17:38:28 -04:00
Ivan Kozlovic
7e60769f9e Merge pull request #1377 from nats-io/subsz
[FIXED] subsz monitoring endpoint did not account for accounts.
2020-05-06 14:06:12 -06:00
Matthias Hanel
136feb9bc6 [FIXEd] subsz monitoring endpoint did not account for accounts.
Fixes  #1371 and #1357 by adding up stats and collecting subscriptions
from all accounts.

Signed-off-by: Matthias Hanel <mh@synadia.com>
2020-05-06 15:48:51 -04:00
Ivan Kozlovic
b1f1e878c6 Merge pull request #1363 from nats-io/default_user
[ADDED] Configuration to allow non authorized user to bind to a given account
2020-05-06 10:02:13 -06:00
Matthias Hanel
14c716052d Making monitoring endpoints available via system services.
Available via $SYS.REQ.SERVER.%s.%s and $SYS.REQ.SERVER.PING.%s
Last token is the endpoint name.

Signed-off-by: Matthias Hanel <mh@synadia.com>
2020-05-04 13:31:50 -04:00
Matthias Hanel
b074c941ae Add a no_auth_user
This configuration allows to refer to a configured user to be used when
the connection provides no credentials.

Signed-off-by: Matthias Hanel <mh@synadia.com>
2020-05-02 15:59:06 -04:00
Derek Collison
487e7bdff7 Merge pull request #1364 from nats-io/tyler_split_issue_templates
Use split GitHub issue templates
2020-04-30 05:27:53 -07:00
Tyler Neely
27882a93cd Add header with the issue type to the top of the issue templates 2020-04-30 02:45:15 +02:00
Tyler Neely
5f9e36b324 Use GitHub issue templates to present reporters with a more streamlined reporting experience 2020-04-30 02:37:56 +02:00
Ivan Kozlovic
a8be338bc1 Merge pull request #1352 from nats-io/update_gws_urls
[FIXED] Update remote gateway URLs when node goes away in cluster
2020-04-20 14:10:18 -06:00
Ivan Kozlovic
fef94759ab [FIXED] Update remote gateway URLs when node goes away in cluster
If a node in the cluster goes away, an async INFO is sent to
inbound gateway connections so they get a chance to update their
list of remote gateway URLs. Same happens when a node is added
to the cluster.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-04-20 13:48:47 -06:00
Ivan Kozlovic
5e9bff33f3 Merge pull request #1348 from nats-io/add_close_reason_in_log_statement
[IMPROVED] Added close reason in the connection close log statement
2020-04-15 18:32:57 -06:00
Ivan Kozlovic
2ec00d86ed Replaced %v with %s so String() is not needed
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-04-15 17:52:44 -06:00
Ivan Kozlovic
be00ea96cf [IMPROVED] Added close reason in the connection close log statement
This gives the close reason directly in the log without having to
get that information from the monitoring endpoint. Here is an
example of a route closed due to the remote side not replying to
PINGs:

```
[INF] 127.0.0.1:53839 - rid:2 - Router connection closed: Stale Connection
```

Without this change, the log statement would have been:
```
[INF] 127.0.0.1:53839 - rid:2 - Router connection closed
```

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-04-15 15:36:54 -06:00
Ivan Kozlovic
f7db844c79 Merge pull request #1347 from nats-io/fix_leafnode_test_flappers
Fix some leafnode test flappers
2020-04-15 15:36:17 -06:00
Ivan Kozlovic
1cf21fc4ee Fix some leafnode test flappers
Make use of some existing helpers and add checkFor in some places
since accounting updates may not be instantaneous.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-04-15 15:15:26 -06:00
Ivan Kozlovic
9fe4146d9d Merge pull request #1346 from nats-io/fix_flapper
Fixed flapper test
2020-04-14 16:23:00 -06:00