Commit Graph

6189 Commits

Author SHA1 Message Date
Ivan Kozlovic
f6c4e5fcee [CHANGED] Gateway: Switch all accounts to interest-only mode
We are phasing out the optimistic-only mode. Servers accepting
inbound gateway connections will switch the accounts to interest-only
mode.

The servers with outbound gateway connection will check interest
and ignore the "optimistic" mode if it is known that the corresponding
inbound is going to switch the account to interest-only. This is
done using a boolean in the gateway INFO protocol.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2022-08-19 16:41:44 -06:00
Matthias Hanel
6bf50dbb77 induce delay prior to scale down (#3381)
This is to avoid a narrow race between adding server and them catching
up where they also register as current.

Also wait for all peers to be caught up.

This also avoids clearing catchup marker once catchup stalled.
A stalled catchup would remove the marker causing the peer to
register as current.

Signed-off-by: Matthias Hanel <mh@synadia.com>
2022-08-18 13:47:40 -07:00
Jean-Noël Moyne
2a709aaf61 - Changes to make adding new mapping functions easier (#3305)
* - Changes to make adding new mapping functions easier
- Adds new subject mapping functions:
{{SplitFromLeft(wildcard index, position)}}
{{SplitFromRight(wildcard index, position)}}
{{SliceFromLeft(wildcard index, slice size)}}
{{SliceFromRight(wildcard index, slice size)}}
{{Split(wildcard index, deliminator)}}

Examples:
	shouldMatch("*", "{{splitfromleft(1,3)}}", "12345", "123.45")
	shouldMatch("*", "{{SplitFromRight(1,3)}}", "12345", "12.345")
	shouldMatch("*", "{{SliceFromLeft(1,3)}}", "1234567890", "123.456.789.0")
	shouldMatch("*", "{{SliceFromRight(1,3)}}", "1234567890", "1.234.567.890")
	shouldMatch("*", "{{split(1,-)}}", "-abc-def--ghi-", "abc.def.ghi")
	shouldMatch("*.*", "{{split(2,-)}}.{{splitfromleft(1,2)}}", "foo.-abc-def--ghij-", "abc.def.ghij.fo.o")

- Subject mapping functions can now be all lower case or Pascal case (or a combination): e.g. splitfromleft, SplitFromLeft, splitFromleft, etc...
2022-08-18 09:52:28 -07:00
Ivan Kozlovic
aa02c12711 Merge pull request #3379 from mprimi/chaos-test-kv
Chaos tests for KeyValue
2022-08-18 10:22:09 -06:00
Ivan Kozlovic
76fec26af2 Bump version to RC.6
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2022-08-18 09:02:51 -06:00
Derek Collison
1228a32bc5 Merge pull request #3380 from nats-io/direct-get-delay
Don't immediately listen on the direct get subjects.
2022-08-17 17:26:52 -07:00
Matthias Hanel
904b7aeefc fixed consumer source update receiving upstream msgs (#3364)
if an origin stream contains:
1M msgs with subject foo and 1M msgs with subject bar

IF the source consumer changes their filter from foo to bar
Then it would have received messages for subject bar.
This happens because this tail was filtered and their
respective seqno was not communicated to the consumer.

This is somewhat unexpected. It is also coincidental.
Had the last message in the stream had subject foo then
this wouldn't happen.

Therefore, when completely changing the subject say,
from foo to bar, we only receive messages received
after the time the change was made.

However, if the old and new subject overlap in any way,
we go by sequence number. Meaning in these cases the
outlined behavior remains in order to not induce artificial
message loss for the part of the subject space that is
covered by old and new filter.

Signed-off-by: Matthias Hanel <mh@synadia.com>

Signed-off-by: Matthias Hanel <mh@synadia.com>
2022-08-17 17:16:03 -07:00
Derek Collison
ce2d5fa173 Don't immediately listen on the direct get subjects.
Signed-off-by: Derek Collison <derek@nats.io>
2022-08-17 16:39:34 -07:00
Marco Primi
d5277bf8ad Chaos tests for KeyValue 2022-08-17 16:25:14 -07:00
Derek Collison
c61465b344 Bump to 2.9.0-RC.5
Signed-off-by: Derek Collison <derek@nats.io>
2022-08-17 15:17:58 -07:00
Matthias Hanel
9892a132e7 Improve StreamMoveInProgressError (#3376)
by adding progress indicators

Signed-off-by: Matthias Hanel <mh@synadia.com>
2022-08-17 15:12:32 -07:00
Derek Collison
8612ca66c8 Merge pull request #3377 from nats-io/no-fss
When filestore is used for raft layer do not attempt to track subjects
2022-08-17 15:10:56 -07:00
Derek Collison
3739e50070 Merge pull request #3378 from nats-io/meta-cleanup-fix
We can't purge directories here since not 100% sure all state is in snapshot.
2022-08-17 15:10:42 -07:00
Derek Collison
9c9de656c6 We can't purge directories here since not 100% sure all state is in snapshot.
Signed-off-by: Derek Collison <derek@nats.io>
2022-08-17 14:57:19 -07:00
Derek Collison
35135948a0 Make sure llts update under lock, fss can be force expired so remove.
Signed-off-by: Derek Collison <derek@nats.io>
2022-08-17 14:54:35 -07:00
Derek Collison
d48ccf4c5a When filestore is used for raft layer do not attempt to track subject metadata.
Signed-off-by: Derek Collison <derek@nats.io>
2022-08-17 13:46:13 -07:00
Ivan Kozlovic
81a8016938 Merge pull request #3374 from nats-io/gw_possible_panic
[FIXED] Gateway: possible panic if monitor endpoint inspected too soon
2022-08-17 13:55:06 -06:00
Ivan Kozlovic
5d3ee8ebf4 [FIXED] Gateway: possible panic if monitor endpoint inspected too soon
The monitoring http server is started early and the gateway setup
(when configured) may not be fully ready when the `/gatewayz`
endpoint is inspected and could cause a panic.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2022-08-17 13:30:58 -06:00
Matthias Hanel
c67d6aad79 fix jwt template ordering issue and error message (#3373)
ordering of templates got messed up by a map (now removed)
Also improved error message when template generation fails

Signed-off-by: Matthias Hanel <mh@synadia.com>
2022-08-16 19:00:41 -07:00
Ivan Kozlovic
4b4de20c25 Merge pull request #3365 from nats-io/fix_3361
[FIXED] JetStream: issue with max deliver and server/cluster restart
2022-08-16 19:13:49 -06:00
Ivan Kozlovic
02ecda535c Stop the raft node to not cause test to flap.
Test TestNoRaceJetStreamClusterCorruptWAL() would start to flap
because of the snapshot on cluster shutdown. Disable the snapshot
on exit for this test by stopping the raft node before shutdown.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2022-08-16 18:44:32 -06:00
Ivan Kozlovic
7de4497815 Install consumer snapshot on clean exit and few other fixes
- didRemove in applyMetaEntries() could be reset when processing
multiple entries
- change "no race" test names to include JetStream
- separate raft nodes leader stepdown and stop in server
shutdown process
- in InstallSnapshot, call wal.Compact() with lastIndex+1

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2022-08-16 17:05:49 -06:00
Ivan Kozlovic
f0b098af92 [FIXED] JetStream: issue with max deliver and server/cluster restart
This is a regression introduced in v2.8.3. If a message reaches
the max redeliver count, it stops being delivered to the consumer.
However, after a server or cluster restart, those messages would
be redelivered again.

Resolves #3361

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2022-08-16 17:05:47 -06:00
Ivan Kozlovic
56a807798b Merge pull request #3372 from nats-io/kozlovic-patch-1
Update dependencies.md [ci skip]
2022-08-16 16:52:40 -06:00
Ivan Kozlovic
8ccce93b92 Update dependencies.md
According to go-licenses, github.com/klauspost/compress/s2 is BSD, not Apache License 2.0
2022-08-16 16:48:00 -06:00
Derek Collison
443f04d262 Bump to 2.9.0-RC.4
Signed-off-by: Derek Collison <derek@nats.io>
2022-08-16 13:21:46 -07:00
Derek Collison
09a3da1412 Merge pull request #3371 from nats-io/aes
[ADDED] Support for AES-GCM as a cipher along with ChaChaPoly.
2022-08-16 13:21:03 -07:00
Derek Collison
9508276b98 Make kek function based on review feedback
Signed-off-by: Derek Collison <derek@nats.io>
2022-08-16 12:49:03 -07:00
Ivan Kozlovic
f91f2f80b5 Merge pull request #3370 from nats-io/update_deps_md
Updated dependency file [ci skip]
2022-08-16 11:36:38 -06:00
Ivan Kozlovic
8352114b4a Merge pull request #3334 from mprimi/chaos-test-2
Chaos tests for Consumers
2022-08-16 11:15:31 -06:00
Marco Primi
02a34117e4 Add chaos tests for Ordered, Async, Pull, Durable consumers
Tests consists of a single client trying to consume a fixed number of messages in a stream.
While the cluster is being bounced by a chaos monkey.
2022-08-16 09:52:48 -07:00
Marco Primi
c6af1ecc9c Fix typo in comment 2022-08-16 09:07:05 -07:00
Derek Collison
ef91d67708 Support auto-conversion
Signed-off-by: Derek Collison <derek@nats.io>
2022-08-16 08:41:39 -07:00
Ivan Kozlovic
84a152b743 Updated dependency file [ci skip]
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2022-08-16 09:26:45 -06:00
Derek Collison
827b34a77a Add support for AES cipher encryption for filestore.
Signed-off-by: Derek Collison <derek@nats.io>
2022-08-15 14:21:37 -07:00
Matthias Hanel
b7ee177497 Adding templates to scoped signing key user permis (#3367)
For security reasons we have introduced scoped signing keys to jwt.
They carry user permissions.
Wich is why jwt issued by those keys are not allowed to carry their own permission.
Instead they are copied from the signing key.
If the scoped signing key gets compromised, an attacker can only issue jwt with the permissions of the key.
With a plain signing key, an attacker can create arbitrary user with permissions.
Because user jwt creation is greatly simplified we added a single utility function to go/java/.net which issues user for such keys.
This is function is documented in ADR-14:

```
/**
 * signingKey, is a mandatory account nkey pair to sign the generated jwt.
 * accountId, is a mandatory public account nkey. Will return error when not set or not account nkey.
 * publicUserKey, is a mandatory public user nkey. Will return error when not set or not user nkey.
 * name, optional human readable name. When absent, default to publicUserKey.
 * expiration, optional but recommended duration, when the generated jwt needs to expire. If not set, JWT will not expire.
 * tags, optional list of tags to be included in the JWT.
 *
 * Returns:
 * error, when issues arose.
 * string, resulting jwt.
 **/
IssueUserJWT(signingKey nkey, accountId string, publicUserKey string, name string, expiration time.Duration, tags []string) (error, string)
```

Currently the only downside of this is that the permissions are static and can't be tailored to the user.

This PR changes that by allowing the user pub/sub permissions to be parameterized with templates.

templates are for entire tokens only and include:
{{name()}} -> username
{{subject()}} -> user subject (nkey)
{{account-name()}} -> users account name
{{account-subject()}} -> user accoutn subject (nkey)

{{tag(arbitrary-prefix)}}
provided the tag "arbitrary-prefix:value" will result in "value"
provided the tags ["arbitrary-prefix:1", "arbitrary-prefix:2"] will result in two subjects "1" & "2"

If the resulting subject is not valid.
Say a tag is not present or name is not set.
This will result in an error for deny subjects
and result in no subject for allow subject.

Signed-off-by: Matthias Hanel <mh@synadia.com>

Signed-off-by: Matthias Hanel <mh@synadia.com>
2022-08-15 12:49:35 -07:00
Ivan Kozlovic
9e748ed2e7 Bump to RC.3
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2022-08-12 11:15:38 -06:00
Ivan Kozlovic
396aa5527c Merge pull request #3366 from nats-io/fs-subject-state
[FIXED] Make sure when SubjectState is called we have loaded fss state.
2022-08-12 11:15:06 -06:00
Derek Collison
d7534dff5f Make sure when SubjectState is called we have loaded fss state.
Signed-off-by: Derek Collison <derek@nats.io>
2022-08-12 07:14:39 -05:00
Ivan Kozlovic
d8d25d9b0b Merge pull request #3363 from nats-io/fix_3362
[FIXED] JetStream: subject overlap error should be returned
2022-08-11 16:41:53 -06:00
Ivan Kozlovic
00345cac64 [FIXED] JetStream: subject overlap error should be returned
In standalone mode, when attempting to create a stream which has
subjects that overlap with an existing stream, the generic
stream create error "10049" was returned instead of the more
accurate "10065" error code corresponding to subject overlap,
as it was the case in clustered mode.

Resolves #3362

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2022-08-11 13:32:29 -06:00
Matthias Hanel
76219f8e5b fix unit test (#3359)
Signed-off-by: Matthias Hanel <mh@synadia.com>
2022-08-11 01:46:30 +02:00
Ivan Kozlovic
4ceee46bb6 Merge pull request #3358 from nats-io/js_fix_direct_get_msg_timestamp_formatting
Fixed message timestamp formatting for direct message get feature
2022-08-10 16:25:26 -06:00
Ivan Kozlovic
68e74e1d1c Update nats.go mod to be able to run tests
Will then update nats.go to remove temp code and then have
another server PR to point to nats.go latest.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2022-08-10 13:26:06 -06:00
Ivan Kozlovic
1f428310b0 Fixed message timestamp formatting for direct message get feature
In normal message get, the returned format is RFC3339Nano, which
is what is being used when using JSON marshaling. However, for
the direct get we had to pass a string to construct the header
and we were using time.Time.String() which was using a different
layout. So use time.Time.MarshalJSON() to be consistent with
the non-direct get message.

Libraries that already parsed the non RFC3339Nano time format
can be updated since none should have been released yet (since
the feature in the server is not released yet)

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2022-08-10 12:53:08 -06:00
Matthias Hanel
f1d42646fe bump version to 2.9.0-RC.2 (#3357)
Signed-off-by: Matthias Hanel <mh@synadia.com>
2022-08-10 19:17:06 +02:00
Matthias Hanel
c26e915c5b adding source/mirror unit tests (#3352)
* adding source/mirror unit tests

Signed-off-by: Matthias Hanel <mh@synadia.com>
2022-08-10 19:01:45 +02:00
Matthias Hanel
c6e37cf7af Fix race between stream stop and monitorStream (#3350)
* Fix race between stream stop and monitorStream

monitorCluster stops the stream, when doing so, monitorStream
needs to be stopped to avoid miscounting of store size.
In a test stop and reset of store size happened first and then
was followed by storing more messages via monitorStream

Signed-off-by: Matthias Hanel <mh@synadia.com>
2022-08-10 19:01:21 +02:00
Matthias Hanel
7015e46dd9 fix move cancel issue where tags and peers diverge (#3354)
This can happen if the move was initiated by the user.
A subsequent cancel resets the initial peer list.
The original peer list was picked on the old set of tags.
A cancel would then keep the new list of tags but reset
to the old peers. Thus tags and peers diverge.

The problem is that at the time of cancel, the old
placement tags can't be found anymore.

This fix causes cancel to remove the placement tags, if
the old peers do not satisfy the new placement tags.

Signed-off-by: Matthias Hanel <mh@synadia.com>
2022-08-10 18:48:18 +02:00
Matthias Hanel
2cf2868406 fixed consumer restart on source filter update (#3355)
* fixed consumer restart on source filter update

When a stream source filter subject was updated, the internal consumer
was not re created

If the upstream stream contains a tail of previously filtered messages,
these will now be delivered

Signed-off-by: Matthias Hanel <mh@synadia.com>
2022-08-10 18:47:19 +02:00