Commit Graph

341 Commits

Author SHA1 Message Date
Derek Collison
c14fda51e7 Direct access to JetStream resources would be affected if across a leafnode that was down.
This allows a solciting leafnode config to ask that any JetStream cluster assets that are a current leader have the leader stepdown.

Signed-off-by: Derek Collison <derek@nats.io>
2022-07-05 12:35:09 -07:00
Neil Alexander
e9abc5801e Add InProcessConn, DontListen 2022-06-28 17:02:47 +01:00
Derek Collison
9400733606 Allow for MQTT QoS-1 consumers to be auto cleanup after inactive threshold of time.
Signed-off-by: Derek Collison <derek@nats.io>
2022-06-14 17:37:45 -07:00
Ivan Kozlovic
da256ea15a Added consumer_memory_storage to make consumer memory based
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2022-05-18 15:53:23 -06:00
Ivan Kozlovic
1ddc5bd9f6 Added consumer_replicas (similar to stream_replicas)
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2022-05-18 15:53:23 -06:00
Ivan Kozlovic
5d3b1743e3 [ADDED] MQTT: Stream/Consumer replica count override
Ability to override the stream and consumers replica count, which is by default
determined based on the cluster size.

```
mqtt {
  port: 1883
  stream_replicas: 5
  consumer_replicas: 1
}
```

The above would allow *new* MQTT streams to be created with a replicas
factor of 5 (it will be an error if the cluster does not have that
many nodes, and error will occur at runtime when the first client
on a given account connects), and new consumers would be R=1.

The MQTT existing streams/consumers for an account are not modified.

The stream_replicas can also obviously be reduced to 1 for a cluster
of 3 nodes if one desire to have those streams as R=1.

A value of 0 or negative is considered letting the server pick
the value (from 1 to 3 depending on standalone/cluster size).

There is another property that allows the consumers to be created
with memory storage instead of file:
```
mqtt {
  ..
  consumer_memory_storage: true
}
```

Those new settings are global and apply to new streams/consumers
only.

Related to #3116

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>

Update warning

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2022-05-18 15:50:23 -06:00
xieyuschen
322115be31 [fixed] On config reload js got disabled, when previously set via command line arg
fixes #3003
2022-04-18 15:58:10 -04:00
Matthias Hanel
79b4374d01 [Fixed] limits enforcement issues (#3046)
* [Fixed] limits enforcement issues

stream create had checks that stream restore did not have.
Moved code into commonly used function checkStreamCfg.
Also introduced (cluster/non clustered) StreamLimitsCheck functions to
perform checks specific to clustered /non clustered data structures.

Checking for valid stream config and limits/reservations before
receiving all the data. Now fails the request right away.

Added a jetstream limit "max_request_batch" to limit fetch batch size

Shortened max name length from 256 to 255, more common file name limit

Added check for loop in cyclic source stream configurations

features related to limits

Signed-off-by: Matthias Hanel <mh@synadia.com>
2022-04-18 01:53:48 -04:00
Matthias Hanel
ec3f9258af [Adding] max_ha_assets to limit placement on server with more ha assets (#3032)
* [Adding] max_ha_assets to limit placement on server with more ha assets

server running more than max_ha_assets #raft nodes will not be used to
place new streams and fail if not enough free server can be found.
Durable Consumer creation on such server will fail as their peer size is
bound to the same set as their stream.

This also avoids updating placement where no new placement is needed.
This is the case when, on update, placement tags get removed. 

Signed-off-by: Matthias Hanel <mh@synadia.com>
2022-04-14 01:53:41 -04:00
Matthias Hanel
5662141932 Adding unique_tag to ensure matching tags are not used twice (#3011)
Allows to not place a stream in the same availability zone twice.

Signed-off-by: Matthias Hanel <mh@synadia.com>
2022-04-07 18:11:00 -04:00
Ivan Kozlovic
b5c9583ee2 Reject configuration with value below 2.8.0
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2022-04-07 12:49:34 -06:00
Ivan Kozlovic
7fa2676353 Fixed comment typos and some rewording
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2022-04-07 09:22:51 -06:00
Ivan Kozlovic
9e6f965913 [ADDED] LeafNode min_version new option
If set, a server configured to accept leafnode connections will
reject a remote server whose version is below that value. Note
that servers prior to v2.8.0 are not sending their version
in the CONNECT protocol, which means that anything below 2.8.0
would be rejected.

Configuration example:
```
leafnodes {
    port: 7422
    min_version: 2.8.0
}
```
The option is a string and can have the "v" prefix:
```
min_version: "v2.9.1"
```
Note that although suffix such as `-beta` would be accepted,
only the major, minor and update are used for the version comparison.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2022-04-06 18:40:33 -06:00
Matthias Hanel
d9da66d67e returns -1 for new unlimited/unset limits and tests/fixes info counts (#3002)
iterates on tiered limits

Signed-off-by: Matthias Hanel <mh@synadia.com>
2022-04-05 12:25:55 -04:00
Matthias Hanel
92f4dc986a added max_ack_pending setting to js account limits (#2982)
* added max_ack_penind setting to js account limits

because of the addition, defaults now have to be set later (depend on
these new limits now)

also re-organized the code to closer track how stream create looks

Signed-off-by: Matthias Hanel <mh@synadia.com>
2022-03-31 14:17:16 -04:00
Matthias Hanel
1445153130 Adding max stream bytes check (#2970)
* Adding max stream bytes check

Also start checking on  stream update

Signed-off-by: Matthias Hanel <mh@synadia.com>
2022-03-30 15:50:28 -04:00
Matthias Hanel
1aeaaf0ca3 Adding server limits (max ack pending/dedupe window) to js config (#2967)
* Adding server limits (max ack pending/dedupe window) to js config

Also shifting consumer config check to jsConsumerCreate as in clustered
mode this was enforced in the wrong place

Signed-off-by: Matthias Hanel <mh@synadia.com>
2022-03-29 13:19:36 -04:00
Matthias Hanel
0c5f3688a7 [ADDED] Tiered limits and fix limit issues on updates (#2945)
* Adding tiered limits and fix limit issues on updates

Signed-off-by: Matthias Hanel <mh@synadia.com>
2022-03-28 20:47:54 -04:00
Derek Collison
7e4a4c8fdd Merge pull request #2890 from nats-io/jnm/partition_mapping
[ADDED] deterministic subject tokens to partition mapping
2022-03-25 11:30:24 -07:00
Ivan Kozlovic
eef194c43b [CHANGED] Duplicates in authorization{} and accounts{} now detected
If accounts{} block is specified, authorization{} should not have
any user/password/token or users array defined.

The reason is that users parsed in accounts{} are associated with
their respective account but users parsed in authorization{} are
associated with the global account. If the same user name is
in both, and since internally the parsing of those 2 blocks is
completely random (even if layed out in the config in a specific
order), the outcome may be that a user is either associated with
an account or the default global account.

To minimize breaking changes, but still avoid this unexpected
outcome, the server will now detect if there are duplicate users
(or nkeys) inside authorization{} block itself, but also between
this block and accounts{}.
The check will also detect if accounts{} has any user/nkey, then
the authorization{} block should not have any user/password/token,
making this test similar to the check we had in authorization{}
block itself.

Resolves #2926

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2022-03-21 19:50:16 -06:00
Derek Collison
0bb84bf76b Make warning more detailed
Co-authored-by: Waldemar Quevedo <wally@synadia.com>
2022-03-17 14:59:14 -07:00
Derek Collison
e204a7961d When detecting exact duplicates for URLs for routes, gws or leafnodes, enter a warning and ignore.
If misconfigured could prevent the JetStream system from electing a leader.

Signed-off-by: Derek Collison <derek@nats.io>
2022-03-17 14:52:01 -07:00
jnmoyne
2138c96cdd Optimizations, cleanups and new mapping destination error 2022-03-04 14:10:18 -08:00
Derek Collison
ca1132a01d Allow stream placement by tags.
Signed-off-by: Derek Collison <derek@nats.io>
2022-02-15 17:07:32 -08:00
Derek Collison
a0a2e32185 Remove dynamic account behaviors.
We used these in tests and for experimenting with sandboxed environments like the demo network.

Signed-off-by: Derek Collison <derek@nats.io>
2022-02-04 13:32:18 -08:00
Derek Collison
ae43b24be4 Fixed #2810. Do not warn about password for internally generated no auth user when just system account assigned to non-default.
Signed-off-by: Derek Collison <derek@nats.io>
2022-01-21 10:09:10 -08:00
Ivan Kozlovic
c9c603b7a0 Merge pull request #2573 from julius-welink/implement-rate-limiting
[ADDED] TLS connection rate limiter
2022-01-13 10:35:19 -07:00
John Hooks
0b77d51905 Remove switch
Removes switch statement and uses map for finding correct multiple

Also uses ParseInt instead of Atoi for getting string integer.
2022-01-12 21:07:07 -05:00
John Hooks
4aa6c62bbc Fix non used error 2022-01-12 18:03:24 -05:00
John Hooks
d956d6d398 Review
Rename function
More easily read math
merged functions together
Changed from predefining error
Fix empty string issue
use same function for max mem store
2022-01-12 17:55:57 -05:00
John Hooks
12f8179fd8 Add parsing of string for sizes
Checks the suffix of the string to create the size of the int64
2022-01-11 22:13:20 -05:00
John Hooks
d10c306585 Check if value is string or int64 2022-01-11 21:06:26 -05:00
Julius Žaromskis
a47e5e045c [ADDED] TLS connection rate limiter 2022-01-11 16:57:19 +02:00
Derek Collison
52da55c8c6 Implement overflow placement for JetStream streams.
This allows stream placement to overflow to adjacent clusters.
We also do more balanced placement based on resources (store or mem). We can continue to expand this as well.
We also introduce an account requirement that stream configs contain a MaxBytes value.

We now track account limits and server limits more distinctly, and do not reserver server resources based on account limits themselves.

Signed-off-by: Derek Collison <derek@nats.io>
2022-01-06 19:33:08 -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
Matthias Hanel
3e8b66286d Js leaf deny (#2693)
Along a leaf node connection, unless the system account is shared AND the JetStream domain name is identical, the default JetStream traffic (without a domain set) will be denied.

As a consequence, all clients that wants to access a domain that is not the one in the server they are connected to, a domain name must be specified.
Affected from this change are setups where: a leaf node had no local JetStream OR the server the leaf node connected to had no local JetStream. 
One of the two accounts that are connected via a leaf node remote, must have no JetStream enabled.
The side that does not have JetStream enabled, will loose JetStream access and it's clients must set `nats.Domain` manually.

For workarounds on how to restore the old behavior, look at:
https://github.com/nats-io/nats-server/pull/2693#issuecomment-996212582

New config values added:
`default_js_domain` is a mapping from account to domain, settable when JetStream is not enabled in an account.
`extension_hint` are hints for non clustered server to start in clustered mode (and be usable to extend)
`js_domain` is a way to set the JetStream domain to use for mqtt.

Signed-off-by: Matthias Hanel <mh@synadia.com>
2021-12-16 16:53:20 -05:00
R.I.Pienaar
51ea92d7c7 support always presenting a nonce to clients
The nonce feature is useful to custom authentication plugins
but at present there is no way to enable a nonce to be presented
other than by setting nkey accounts etc.

This enables the nonce to always be presented in those situations.
Since its primarily useful to embedded scenarios there is no corresponding
configuration file behavior for this flag.

Signed-off-by: R.I.Pienaar <rip@devco.net>
2021-11-17 15:19:00 +01:00
Derek Collison
1552e6fd5b Fix for staticcheck shadow issue
Signed-off-by: Derek Collison <derek@nats.io>
2021-11-12 17:47:35 -08:00
Derek Collison
b96df068cb Add in max_sub_tokens support
Signed-off-by: Derek Collison <derek@nats.io>
2021-11-04 14:26:01 -07: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
David Simner
78991445f4 Fix #2630 2021-10-19 11:15:47 +02:00
Derek Collison
c9f615933a Honor JetStream server settings of 0.
Signed-off-by: Derek Collison <derek@nats.io>
2021-10-12 14:16:47 -07:00
Ivan Kozlovic
5c5cc88c1f [FIXED] Report config error if "token" defined for cluster{} and gateway{}
Authentication token has never been supported for cluster and
gateway (and leafnode). There is not even a Token option in
ClusterOpts or GatewayOpts.

However, the parsing of the configuration was not rejecting this
misconfiguration, making users believe that token was used for
authentication.

Documentation will also be fixed since it is reported there that
token is supported, which again, has never been the case.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-09-13 10:21:00 -06:00
Ivan Kozlovic
063432aa4b [FIXED] Account resolver TLS configuration
The RootCAs was not properly set, which could prevent the server
to create a TLS connection to the account resolver with an error
such as:
```
x509: certificate signed by unknown authority
```

Resolves #1207

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-09-02 09:13:54 -06:00
Matthias Hanel
0447f1c64f [added] operator option to ensure user are signed by certain accounts
option name: resolver_pinned_accounts
Contains a list of public account nkeys.
Connecting user of leaf nodes need to be signed by this.
The system account will always be able to connect.

Signed-off-by: Matthias Hanel <mh@synadia.com>
2021-08-23 13:45:11 -04:00
Ivan Kozlovic
4865dc7ae3 [CHANGED] Check that max_payload is not greater than max_pending
This is related to PR #2407. Since the 64MB pending size is actually
configurable, we should fail only if max_payload is greater than
the configured max_pending. This is done in validateOptions() which
covers both config file and direct options in embedded cases.
The check in opts.go is reverted to max int32 since at this point
we don't know if/what max_pending will be, so we simply check
that it is not more than a int32.

For the next minor release, we could have another change that
imposes a lower limit to max_payload (regardless if max_pending
is higher).

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-08-04 16:33:21 -06:00
jnmoyne
b5e3f8d394 Due to internal limits the actual maximum payload size is 64Mb. Beyond that the subscribing process is unable to receive the messages, so adjusting the maximum size the server allows you to set for max_payload. 2021-08-04 00:28:23 -07:00
Matthias Hanel
1d4243b565 [fixed] tls timeout now accepts units
Signed-off-by: Matthias Hanel <mh@synadia.com>
2021-07-19 11:42:28 -04:00
Derek Collison
bf6335dff9 Add in ability to have encrypted JetStream filestores.
This supports XChaChaPoly1305 for Seal and Open and ChaCha20 for our message blocks which use highway hashes and sequence numbers for authenticity.
We support snapshot and restore as well.

Signed-off-by: Derek Collison <derek@nats.io>
2021-06-21 19:28:10 -07:00
Waldemar Quevedo
60499e2749 ocsp: add more config options to customize ocsp stapling
Signed-off-by: Waldemar Quevedo <wally@synadia.com>
2021-06-10 10:48:51 -07:00