Commit Graph

225 Commits

Author SHA1 Message Date
Matthias Hanel
fa12d096cd Fix jwt based user/activation token revocation and revocation granularity
user and activation token did not honor the jwt value for all * on
connect.

activation token where not re evaluated when the export revoked a key.
In part this is a consistency measure so servers that already have an
account and servers that don't behave the same way.

in jwt activation token revocations are stored per export.
The server stored them per account, thus effectively merging
revocations. Now they are stored per export inside the server too.

fixes nats-io/nsc/issues/442

Signed-off-by: Matthias Hanel <mh@synadia.com>
2022-01-25 13:48:12 -05:00
Ivan Kozlovic
f6acc9d28b [FIXED] Possible deadlock
This is due to a re-entrant RLock(). It works sometimes, but if there
is a go routine requesting the write lock, then the second RLock()
will not be granted which will lead to a deadlock.
In summary: one should never make re-entrant RLock calls.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2022-01-20 13:53:52 -07:00
Derek Collison
7dc99c3840 Merge from main
Signed-off-by: Derek Collison <derek@nats.io>
2022-01-13 10:01:33 -08:00
Matthias Hanel
78bbcd791f [Adding] support for JS MaxBytesRequired
Signed-off-by: Matthias Hanel <mh@synadia.com>
2022-01-12 22:57:34 -05:00
Derek Collison
43eff407b8 Add in explicit subscription for import responses when bound to a leafnode.
When we want to track service import response interest across a leafnode we need to send sub and unsub for all response _R_ subjects versus using a wildcard.

Signed-off-by: Derek Collison <derek@nats.io>
2022-01-12 18:24:03 -08:00
Derek Collison
b43cb5b352 Added in ability to have account limits configured in server config.
Signed-off-by: Derek Collison <derek@nats.io>
2021-12-21 18:31:07 -08:00
Derek Collison
65d098f526 Fix for latency tracking bug.
The bug occures when latency tracking is on, a requestor and responder are not connected to the same server, and the responder sends two responses for a single request.

Signed-off-by: Derek Collison <derek@nats.io>
2021-11-12 17:37:15 -08:00
Phil Pennock
fc6df0fbbc Redact URLs before logging or returning in error (#2643)
* Redact URLs before logging or returning in error

This does not affect strings which failed to parse, and in such a scenario
there's a mix of "which evil" to accept; we can't sanely find what should be
redacted in those cases, so we leave them alone for debugging.

The JWT library returns some errors for Operator URLs, but it rejects URLs
which contain userinfo, so there can't be passwords in those and they're safe.

Fixes #2597

* Test the URL redaction auxiliary functions

* End-to-end tests for secrets in debug/trace

Create internal/testhelper and move DummyLogger there, so it can be used from
the test/ sub-dir too.

Let DummyLogger optionally accumulate all log messages, not just retain the
last-seen message.

Confirm no passwords logged by TestLeafNodeBasicAuthFailover.

Change TestNoPasswordsFromConnectTrace to check all trace messages, not just the
most recent.

Validate existing trace redaction in TestRouteToSelf.

* Test for password in solicited route reconnect debug
2021-10-27 12:44:59 -04:00
Derek Collison
15fb253c7c Revert back to old subject, don't suppress updates on non client/leaf
Signed-off-by: Derek Collison <derek@nats.io>
2021-09-23 16:07:35 -07:00
Derek Collison
3740a707f6 Do not count non client or leafnode connections for account limit reporting.
Signed-off-by: Derek Collison <derek@nats.io>
2021-09-23 15:43:07 -07:00
Ivan Kozlovic
4076abfd57 Use a better seed for a rand generator
This was causing some test to flap.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-08-26 15:16:22 -06:00
Derek Collison
02c702f7af Added test for system account update as well
Signed-off-by: Derek Collison <derek@nats.io>
2021-08-17 11:09:13 -07:00
Derek Collison
84ff537e66 Make sure jwt claim update does not wipe system imports
Signed-off-by: Derek Collison <derek@nats.io>
2021-08-17 10:03:30 -07:00
Derek Collison
10167b1bcf Added in ability for normal accounts to access scoped connz info.
Added in client kind and sub type for clients.
Added in ability to filter connections based on matching subject interest.

Signed-off-by: Derek Collison <derek@nats.io>
2021-08-13 10:19:12 -07:00
Derek Collison
f13fa767c2 Remove the swapping of accounts during processing of service imports.
When processing service imports we would swap out the accounts during processing.
With the addition of internal subscriptions and internal clients publishing in JetStream we had an issue with the wrong account being used.
This was specific to delyaed pull subscribers trying to unsubscribe due to max of 1 while other JetStream API calls were running concurrently.
2021-07-26 07:57:10 -07:00
Derek Collison
26e63a14a6 Merge pull request #2324 from nats-io/large-r1
Improvements to large numbers of JetStream R1 consumers per stream.
2021-06-29 08:35:17 -07:00
Derek Collison
3c16f776dc Protect account prand, use faster Uint64 variant
Signed-off-by: Derek Collison <derek@nats.io>
2021-06-29 06:13:41 -07:00
Derek Collison
99fed910f0 Improvements to large numbers of JetStream R1 consumers per stream.
1. We were holding open FDs longer than we should for consumers causing issues with open FD limits. We now do not hold them open and cap updates a bit better.

2. When doing a stream delete, consumer delete was repeating alot of work that was not necessary, causing longer delays. This has been optimized a bit, still more improvements to be made.

3. We cover all JS under a single export, but that was also trapping GetNext for pull based consumers, and since this was a no-op (is handled at user account level) we were creating alot of garbage service import responses and reverse map entries that had to be garbage collected. We have a fix in to avoind this but still looking for a better one.

4. Still had some lingering references to all exports vs single JS export.

Signed-off-by: Derek Collison <derek@nats.io>
2021-06-29 05:45:55 -07:00
Ivan Kozlovic
1d3cddfa7c [CHANGED] Reduce print for an account subs limit to every 2 sec
We could make it for all limits by having a map of error types
instead of applying just to max subs.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-06-22 11:00:41 -06:00
Matthias Hanel
9f6ba90d3e [fixing] leafnode missing retry and service export interest propagation (#2288)
* [fixing] leafnode missing retry and service export interest propagation

A missing account on initial connect attempt caused the leaf node
connection to never be established.

An account service import subscription was not propagated along leaf
node connections.

Signed-off-by: Matthias Hanel <mh@synadia.com>
2021-06-17 19:10:05 -04:00
Matthias Hanel
83389db226 [fixed] hanging leaf node connection when account can't be found (#2267)
* [fixed] hanging leaf node connection when account can't be found

as a result of the issue, the leaf node connection never got created,
even after the account can be found.

Also tracing account id and name (when available)

Signed-off-by: Matthias Hanel <mh@synadia.com>
2021-06-10 11:55:16 -04:00
Matthias Hanel
748b7c32f4 [fixed] deletion of js mappings on account jwt update
fixed by moving setting of the mappings into a common function that is
also called when the jwt is updated

Signed-off-by: Matthias Hanel <mh@synadia.com>
2021-05-24 16:44:14 -04:00
Derek Collison
0bd92e85da Add in formal support for multiple JetStream domains across leafnodes.
This CL adds in support for multiple JetStream domains using mapped subjects.
Mapping subjects aligns well with the JetStream context APIPrefix in clients.

Signed-off-by: Derek Collison <derek@nats.io>
2021-05-06 18:45:27 -06:00
Ivan Kozlovic
2881e4a1f0 [FIXED] MQTT fixes and improvements
Some issues that have been fixed would manifest by timeouts on
connect, unexpected memory usage on high publish message rate.

Some details:
- Replies were not always GW routed properly because we were looking
at the wrong connection's rsubs
- GW routed replies would not be found because they were tracked
in the subscription's client object, which may not be the same used
to send the reply
- Increased the mqtt timeout to wait for JS replies since in some
tests it was sometimes taking more than the original 2 seconds
- Incoming gateway messages destined for an MQTT internal subscription
may have been rejected as a no interest if the account had service imports
- Don't use time.After(), instead create explicit timer so it can
be stopped when not timing out.
- Unnecessary copy of a slice since we were converting to a string anyway.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-05-04 20:48:14 -06:00
Ivan Kozlovic
56d0d9ec87 Do not propagate service import interest across GW and ROUTES
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-04-15 11:34:36 -06:00
Matthias Hanel
edee54b005 [Adding] (fetch) timeout to nats resolver (#2057)
* [Adding] (fetch) timeout to nats resolver

Signed-off-by: Matthias Hanel <mh@synadia.com>
2021-04-02 12:27:02 -04:00
Matthias Hanel
6ffe9adf97 [added] disconnect of all clients and disable account on remove
Error sent to the client: Account Authentication Expired

Signed-off-by: Matthias Hanel <mh@synadia.com>
2021-03-30 02:24:02 -04:00
Matthias Hanel
c3479d339e [added] ability to remove account jwt using an operator signing key
Signed-off-by: Matthias Hanel <mh@synadia.com>
2021-03-29 23:58:28 -04:00
Matthias Hanel
eb1a91d5b6 [fixed] private import issue by pulling in up to date jwt library
Also prevent nats based account resolver from storing invalid jwt
Updated compress and highwayhash

Signed-off-by: Matthias Hanel <mh@synadia.com>
2021-03-14 19:37:14 -04:00
Matthias Hanel
2187c0d2ae [Fixed] missing export jsAllApi on system account update
Signed-off-by: Matthias Hanel <mh@synadia.com>
2021-03-03 16:01:22 -05:00
Derek Collison
00a49ce329 Test for existing service import
Signed-off-by: Derek Collison <derek@nats.io>
2021-03-02 20:38:16 -08:00
Derek Collison
43b9017b74 Merge pull request #1953 from nats-io/api
JetStream API Changes
2021-03-02 19:46:00 -07:00
Matthias Hanel
25ef6b0f0d Merge pull request #1952 from nats-io/goland-lint
Fixed linter issues
2021-03-02 21:43:04 -05:00
Matthias Hanel
c50ee2a1c6 [Changed] all times exposed will be computed in UTC (#1943)
This also applies to times that end up in that json.
Where applicable moved time.Now() to where it is used.
Moved calls to .UTC() to where time is created it that time is converted
later anyway.

Signed-off-by: Matthias Hanel <mh@synadia.com>
2021-03-02 21:37:42 -05:00
Derek Collison
4f7fbefc7c In clustered JetStream we need to move API calls out of routes/gateways/leafnodes path.
This moves from explicit imports and subscriptions to one wildcard subscription and a single wildcard export.

Signed-off-by: Derek Collison <derek@nats.io>
2021-03-02 17:54:41 -08:00
Matthias Hanel
4f2db7d187 Fixed linter issues
Signed-off-by: Matthias Hanel <mh@synadia.com>
2021-03-02 20:21:44 -05:00
Derek Collison
d803189eca Changes needed to properly support multi-layer service imports for system services like JS.
Signed-off-by: Derek Collison <derek@nats.io>
2021-02-12 17:01:32 -08:00
Ivan Kozlovic
264148ead2 Merge pull request #1899 from nats-io/si_subj_remap
Remap subject only for service imports
2021-02-08 15:54:36 -07:00
Matthias Hanel
0cae6ab4e7 [added] support for jwt based account mappings (#1897)
support for jwt based account mappings

Signed-off-by: Matthias Hanel <mh@synadia.com>
2021-02-08 17:25:14 -05:00
Ivan Kozlovic
8af8cf4e67 Remap subject only for service imports
Also optimized a test that was taking too long to run.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-02-08 14:41:33 -07:00
Derek Collison
5fca2be35f Merge pull request #1875 from nats-io/jsc-remove
Removing peers from streams and consumers and stepdown functionality
2021-02-02 09:28:03 -07:00
Derek Collison
e5c1d65fff Added in JS disable per server on reload. Also removing peerw from a stream and leader stepdown for streams and consumers.
Various bug fixes, stability improvments.

Signed-off-by: Derek Collison <derek@nats.io>
2021-02-01 19:39:08 -08:00
Matthias Hanel
3799b90011 [Adding] support for account_token_position (#1874)
This change does 4 things:
Refactor to only have one function to validate imports.
Have this function support the jwt field account_token_position.
For completeness make this value configurable as well.
unit tests.

Signed-off-by: Matthias Hanel <mh@synadia.com>
2021-02-01 19:51:36 -05:00
Matthias Hanel
ffc20e950b [removed] activation token download (#1867)
Signed-off-by: Matthias Hanel <mh@synadia.com>
2021-02-01 12:30:47 -05:00
Derek Collison
8bd290c77a Fix for #1864.
When trying to make sure we properly created all subs for service imports we would check the internal client to see if we should process.
With JS enabled on the server we would place system imports that would break that check and orphan other service imports.

Signed-off-by: Derek Collison <derek@nats.io>
2021-01-29 17:51:14 -08:00
Matthias Hanel
dea9effa8d [added] support for StrictSigningKeyUsage and updated jwt library (#1845)
This will cause the server to not trust accounts/user signed by an
identity key

The boot strapping system account will assume the account is issued by
the operator.
If this is not desirable, the system account can be provided right away
as resolver_preload.

[fixes] crash when the system account uses signing keys and an update changes that key set.

Signed-off-by: Matthias Hanel <mh@synadia.com>
2021-01-26 17:49:58 -05:00
Matthias Hanel
d35cd2996d [added] jwt/issuerkey/nametag/tags to monitoring and event endpoints (#1830)
Also added a trace on jwt authentication

Signed-off-by: Matthias Hanel <mh@synadia.com>
2021-01-21 21:16:34 -05:00
Ivan Kozlovic
42dcdd2eb2 Simplify sendSubsToRoute()
Since we were creating subs on the fly, sub.im would always be nil.
We were passing a client because it was needed in sendRouteSubOrUnSubProtos().

This PR simply fills the buffer with each account's subscriptions.
There is also no need to have subs sent from different go routine
based on some threshold. Routes are no longer subject to max pending.

Some code has been made into a function so that they can be shared
by sendSubsToRoute() and sendRouteSubOrUnSubProtos(). The function
is simply adding to given buffer the RS+/- protocol.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-01-19 14:01:43 -07:00
Derek Collison
a18a6803c1 Added support for stream and consumer lists.
This utilizes a scatter and gather approach.

Signed-off-by: Derek Collison <derek@nats.io>
2021-01-16 12:42:45 -08:00
Derek Collison
754e31a3bc Routes send subscriptions by utilizing random clients from an account.
There was a bug where the client chosen under the $SYS account could have a different account.

Signed-off-by: Derek Collison <derek@nats.io>
2021-01-15 17:02:38 -08:00