Commit Graph

1471 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
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
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
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
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
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
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
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
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
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
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
c54f41acd6 Fixed flapper test
Make sure that the subscription on "service" is registered on
server A.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-04-14 13:27:17 -06:00
Derek Collison
aff10aa16b Fix for #1344
Signed-off-by: Derek Collison <derek@nats.io>
2020-04-14 09:26:35 -07:00
Derek Collison
dc55356096 Have events look at whether or not a leaf is a hub, regardless of solicit
Signed-off-by: Derek Collison <derek@nats.io>
2020-04-13 15:25:21 -07:00
Derek Collison
6fa7f1ce82 Have hub role sent to accepting side and adapt to be a spoke
Signed-off-by: Derek Collison <derek@nats.io>
2020-04-13 15:18:42 -07:00
Ivan Kozlovic
439dca67c8 Test for interest propagation with GWs and Hub leafnodes
Setup:

  B <- GW -> C
 /            \
v              v
A              D

Leafnodes are created from B to A and C to D. The remotes on B and
C have the option "Hub: true".

The replier connects to D and listens to "service". The requestor
connects to "A" and sends the request on "service". The reply does
not make it back to A.
If the requestor on A, instead of calling Request(), first creates
a subscription on an inbox, wait a little bit (few 100s ms), then
publishes the request on "service" with that inbox for the reply
subject, the reply makes it back to A.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-04-13 12:47:18 -06:00
Derek Collison
2b1fe8f261 Merge pull request #1337 from nats-io/service-account-leaf-test
[FIXED] Service across accounts and leaf nodes
2020-04-10 17:38:07 -07:00
Derek Collison
ef85a1b836 Fix for #1336
Signed-off-by: Derek Collison <derek@nats.io>
2020-04-10 17:30:03 -07:00
Ivan Kozlovic
7218da1cbc Merge pull request #1338 from nats-io/reduce_loop_errors
LeafNode: delay connect even when loop detected by accepting side
2020-04-10 18:04:11 -06:00
Ivan Kozlovic
b200368e52 LeafNode: delay connect even when loop detected by accepting side
If the loop is detected by a server accepting the leafnode connection,
an error is sent back and connection is closed.
This change ensures that the server checks an -ERR for "Loop detected"
and then set the connect delay, so that it does not try to reconnect
right away.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-04-10 16:44:16 -06:00
Derek Collison
090abc939d Fix for stream imports and leafnodes, #1332
Signed-off-by: Derek Collison <derek@nats.io>
2020-04-10 10:36:20 -07:00
Derek Collison
84841a35bb Merge pull request #1334 from nats-io/leafnode_bug
Fix for bug when requestor and leafnode on same server.
2020-04-10 08:51:31 -07:00
Derek Collison
e843a27bba When a responder was on a leaf node and the requestor was connected to the same server as the leafnode we did not propagate the service reply wildcard properly. This fixes that.
Signed-off-by: Derek Collison <derek@nats.io>
2020-04-10 08:35:09 -07:00
Ivan Kozlovic
34eb5bda31 [ADDED] Deny import/export options for LeafNode remote configuration
This will allow a leafnode remote connection to prevent unwanted
messages to be received, or prevent local messages to be sent
to the remote server.

Configuration will be something like:
```
leafnodes {
  remotes: [
    {
      url: "nats://localhost:6222"
      deny_imports: ["foo.*", "bar"]
      deny_exports: ["baz.*", "bat"]
    }
  ]
}
```

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-04-09 18:55:44 -06:00
Derek Collison
d70426d3f6 Do prefix test to avoid read lock if possible
Signed-off-by: Derek Collison <derek@nats.io>
2020-04-09 08:48:04 -07:00
Derek Collison
699502de8f Detection for loops with leafnodes.
We need to send the unique LDS subject to all leafnodes to properly detect setups like triangles.
This will have the server who completes the loop be the one that detects the error soley based on
its own loop detection subject.

Otehr changes are just to fix tests that were not waiting for the new LDS sub.

Signed-off-by: Derek Collison <derek@nats.io>
2020-04-08 20:00:40 -07:00