Commit Graph

906 Commits

Author SHA1 Message Date
Todd Beets
46147cf0ea Add logfile_max_archives feature and test. 2023-09-15 16:21:51 -07:00
Waldemar Quevedo
0c68b891fe flakes: Fix TestAccountSubjectMapping
When it fails it hangs the build.

Signed-off-by: Waldemar Quevedo <wally@nats.io>
2023-09-05 21:17:22 -07:00
Waldemar Quevedo
d366027bbf Fix resetting TLS name from solicited remotes
In +Go 1.20, the x509.HostnameError changed to be wrapped in a
tls.CertificateVerificationError so sometimes the name would not
be reset causing tests to be extra flaky.

Signed-off-by: Waldemar Quevedo <wally@nats.io>
2023-08-28 10:09:55 -07:00
Waldemar Quevedo
bdb874a6a8 Update LastActivity on connect for routes
Signed-off-by: Waldemar Quevedo <wally@nats.io>
2023-08-22 07:10:30 -07:00
Waldemar Quevedo
05e2fa9373 test: fix TestAccountImportSubjectMapping hanging build
Added timeout to test to prevent running into go test timeout
in case messages did not arrive on time.

Signed-off-by: Waldemar Quevedo <wally@nats.io>
2023-08-09 19:49:24 -07:00
Waldemar Quevedo
9d43fb9606 test: fix TestClusterTLSMixedIPAndDNS test on +go1.20
Signed-off-by: Waldemar Quevedo <wally@nats.io>
2023-08-07 15:11:49 -07:00
Derek Collison
8079495903 Merge branch 'main' into dev
Signed-off-by: Derek Collison <derek@nats.io>
2023-08-04 10:15:35 -07:00
Todd Beets
ac43a8d4eb Enhance OCSP peer validation for GATEWAY and ROUTE connections. Nodes no longer required to have same CA issuer. OCSP response effectivity now checked using default clock skew and default validity period if not asserted by responder. 2023-08-02 16:09:21 -07:00
Todd Beets
1f0b70d5fc Fixed local issuer determination for OCSP Staple, issue #3773 2023-08-02 11:52:36 -07:00
Todd Beets
209fcd70eb OCSP Peer Feature 2023-08-02 11:25:48 -07:00
Todd Beets
971c61692a Fixed local issuer determination for OCSP Staple, issue #3773 (#4355)
Resolves problems of [issue
#3773](https://github.com/nats-io/nats-server/issues/3773).

With this fix, NATS Server will locally determine it's own certificate's
issuer from either the configured server certificate (bundle of leaf
cert plus optional intermediate CA certs) or from the configured server
CA trust store, as follows:

1. The operator may provide the server's certificate issuer in the
second position of the server's certificate configuration (typically
`cert_file` but may be `cert_store` on the Windows platform). If a
candidate issuer is found here it is PKI validated as the actual issuer
of the server's cert else a hard error.

2. If not found in [1], NATS Server will seek to create at least one
verified chain with its configured trust store (typically `ca_file` but
could by the system trust store if not configured). It will derive the
issuer from the first verified chain. If no verified chain can be formed
it is a hard error.
2023-08-01 16:13:25 -07:00
Todd Beets
e51a42963a OCSP Peer Verification (#4258)
New security feature [ADR-38: OCSP Peer
Verification](https://github.com/nats-io/nats-architecture-and-design/pull/226/files#diff-575a9545de9d498a48d2889972b0cb57dbadebde3b4328b65ab02bb43f557935)
providing fine-grain certificate status check via OCSP verification; for
inbound NATS, MQTT, WebSocket, and Leaf client connections (mTLS) as
well as outbound Leaf connections to another NATS System.
2023-08-01 09:17:27 -07:00
Derek Collison
c6c5358513 Merge branch 'main' into dev
Signed-off-by: Derek Collison <derek@nats.io>
2023-07-20 13:21:35 -07:00
Neil Twigg
b7d6b7e7a9 Add unit test to prove connection works
Signed-off-by: Neil Twigg <neil@nats.io>
2023-07-20 11:01:32 +01:00
Todd Beets
99dc11551b OCSP Peer Verification 2023-07-19 12:14:21 -07:00
Neil Twigg
1527000d1f Use crypto/rand.Read instead of math/rand.Read
As of Go 1.20, `math/rand.Read` is deprecated. In addition to that, it also
isn't recommended for use in combination with anything cryptographic.

I haven't replaced all `math/rand` with `crypto/rand` imports because there
are still some legitimate uses for the `math/rand` package in some places.

Signed-off-by: Neil Twigg <neil@nats.io>
2023-07-13 12:04:58 +01:00
Todd Beets
f854e95c11 Cert Store (aka wincert) 2023-06-22 12:25:54 -07:00
Derek Collison
60d006bbeb Merge branch 'main' into dev 2023-06-09 18:25:17 -07:00
Derek Collison
2765e534eb Fix test and update copyright
Signed-off-by: Derek Collison <derek@nats.io>
2023-06-09 15:09:15 -07:00
Ivan Kozlovic
67498af2dc [ADDED] LeafNode: Support for s2 compression
This is similar to PR #4115 but for LeafNodes.
Compression mode can be set on both side (the accept and in remotes).
```
leafnodes {
   port: 7422
   compression: s2_best
   remotes [
       {
         url: "nats://host2:74222"
         compression: s2_better
       }
   ]
}
```
Possible modes are similar than for routes (described in PR #4115),
except that when not defined we default to `s2_auto`.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2023-05-15 17:42:39 -06:00
Jean-Noël Moyne
e07ccf9cc1 [ADDED] Ability to drop partial wildcard tokens in some subject transforms (#4152)
- [X] Tests added
- [X] Branch rebased on top of current main (`git pull --rebase origin
main`)
- [X] Changes squashed to a single commit (described
[here](http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html))
 - [X] Build is green in Travis CI
- [X] You have certified that the contribution is your original work and
that you license the work to the project under the [Apache 2
license](https://github.com/nats-io/nats-server/blob/main/LICENSE)

### Changes proposed in this pull request:

There is currently a blanket requirement that subject transforms
destinations MUST use ALL of the partial wildcards defined in the source
of the transform. This is because the subject transformed defined for
imports must be 'reversible' and therefore the destination transform
must use all of the partial wildcard tokens defined in the source of the
transform.

This reversing of a transform is only used for transforms used by
imports, where in any case it doesn't make sense to use any transform
other than Wildcard.

This PR:
- relaxes this requirement to only apply when the transform is used by
an import, adding the ability to drop a wildcard token in transforms
other than as part of an import.
- Improves transform reverse to support both legacy style wildcards $X
and the new transform function {{Wildcard(X)}}- Improves reversible
transform checking to only allow the use of wildcards in the
destination.

---------

Signed-off-by: Jean-Noël Moyne <jnmoyne@gmail.com>
2023-05-14 14:02:19 -07:00
Derek Collison
0321eb6484 Merge branch 'main' into dev 2023-04-29 19:52:57 -07:00
Ivan Kozlovic
d6fe9d4c2d [ADDED] Support for route S2 compression
The new field `compression` in the `cluster{}` block allows to
specify which compression mode to use between servers.

It can be simply specified as a boolean or a string for the
simple modes, or as an object for the "s2_auto" mode where
a list of RTT thresholds can be specified.

By default, if no compression field is specified, the server
will use the s2_auto mode with default RTT thresholds of
10ms, 50ms and 100ms for the "uncompressed", "fast", "better"
and "best" modes.

```
cluster {
..
  # Possible values are "disabled", "off", "enabled", "on",
  # "accept", "s2_fast", "s2_better", "s2_best" or "s2_auto"
  compression: s2_fast
}
```

To specify a different list of thresholds for the s2_auto,
here is how it would look like:
```
cluster {
..
  compression: {
    mode: s2_auto
    # This means that for RTT up to 5ms (included), then
    # the compression level will be "uncompressed", then
    # from 5ms+ to 15ms, the mode will switch to "s2_fast",
    # then from 15ms+ to 50ms, the level will switch to
    # "s2_better", and anything above 50ms will result
    # in the "s2_best" compression mode.
    rtt_thresholds: [5ms, 15ms, 50ms]
  }
}
```

Note that the "accept" mode means that a server will accept
compression from a remote and switch to that same compression
mode, but will otherwise not initiate compression. That is,
if 2 servers are configured with "accept", then compression
will actually be "off". If one of the server had say s2_fast
then they would both use this mode.

If a server has compression mode set (other than "off") but
connects to an older server, there will be no compression between
those 2 routes.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2023-04-27 17:59:25 -06:00
Derek Collison
59e2107435 Fix test flapper
Signed-off-by: Derek Collison <derek@nats.io>
2023-04-27 07:19:56 -07:00
Ivan Kozlovic
105237cba8 [ADDED] Multiple routes and ability to have per-account routes
New configuration fields:
```
cluster {
   ...
   pool_size: 5
   accounts: ["A", "B"]
}
```

The configuration `pool_size` in the example above means that this
server will create 5 routes to a remote server, assuming that that
server has the same `pool_size` setting.

Accounts (which are not part of the `accounts[]` configuration)
are assigned a specific route in this pool, and this will be the
same route on all servers in the cluster.

Accounts that are defined in the `accounts` field will each have
a dedicated route connection. This will allow suppression of the
account name in some of the route protocols, reducing bytes transmitted
which may increase performance.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2023-04-03 09:32:25 -06:00
Derek Collison
80d0adede4 Merge branch 'main' into dev 2023-03-15 20:26:13 -07:00
Neil Twigg
f2bffec366 Refactor outbound queues, remove dynamic sizing, add buffer reuse
Also try to reduce flakiness of `TestClusterQueueSubs` and `TestCrossAccountServiceResponseTypes`
2023-03-15 09:37:40 +00:00
Waldemar Quevedo
da7a8b63bc Reword ocsp routes/gateways terminology to 'peers' instead
Add test for verify_and_map usage with ocsp

Signed-off-by: Waldemar Quevedo <wally@nats.io>
2023-03-14 17:01:42 -07:00
Waldemar Quevedo
f8914788f5 Fix leaf client connection failing in ocsp setup
Signed-off-by: Waldemar Quevedo <wally@nats.io>
2023-03-14 14:07:18 -07:00
Todd Beets
e1fd61778f certstore feature with windows credential manager 2023-01-25 21:22:20 -08:00
Neil Twigg
e4b6ba2f23 Refactor outbound queues, remove dynamic sizing, add buffer reuse
Also try to reduce flakiness of `TestClusterQueueSubs` and `TestCrossAccountServiceResponseTypes`
2023-01-09 09:35:22 +00:00
Derek Collison
ff79afef39 Merge branch 'main' into dev 2022-12-30 12:23:23 -08:00
Neil Twigg
14d0ba1c65 Fix some lint errors after move to golangci-lint 2022-12-30 20:00:08 +00:00
Derek Collison
3877ee2411 Merge branch 'main' into dev 2022-12-13 13:08:35 -08:00
Marco Primi
f8a030bc4a Use testing.TempDir() where possible
Refactor tests to use go built-in temporary directory utility for tests.

Also avoid binding to default port (which may be in use)
2022-12-12 13:18:44 -08:00
Derek Collison
baf9f42d9f Fix tests
Signed-off-by: Derek Collison <derek@nats.io>
2022-11-27 19:49:52 -08:00
Ivan Kozlovic
b3e0431959 [FIXED] allow_non_tls is lost after server reload
The server would reset its INFO's TLSRequired to the presence
of a TLS configuration without checking for the allow_non_tls
option.

Resolves #3581

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2022-10-27 09:49:44 -06:00
Ivan Kozlovic
b69ffe244e Fixed some tests
Code change:
- Do not start the processMirrorMsgs and processSourceMsgs go routine
if the server has been detected to be shutdown. This would otherwise
leave some go routine running at the end of some tests.
- Pass the fch and qch to the consumerFileStore's flushLoop otherwise
in some tests this routine could be left running.

Tests changes:
- Added missing defer NATS connection close
- Added missing defer server shutdown

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2022-09-08 11:28:23 -06:00
Phil Pennock
4ffc0336a2 TLS testdata: invoked regenerate_rdns_svid.sh 2022-09-07 16:33:37 -04:00
Phil Pennock
0ae8af7986 TLS testdata: automate more cert issuance 2022-09-07 16:33:28 -04:00
Marco Primi
f1883561ee Use testing.TB interface instead of *T
Using interface allows reusing helper function in benchmarks
2022-08-31 14:52:45 -07:00
Phil Pennock
06778cbd6e Regenerate test cert data 2022-08-27 16:23:22 -04:00
Phil Pennock
444e56b425 Set cert lifetime on CA cert too
This was an oversight when automating: we use the `req -x509` approach to
create the CA cert, which didn't pick up the defaults set for other stuff and
so defaulted to 30 days.

Abstract out CERT_DURATION and use for both the cert defaults and the CA's own
lifetime.
2022-08-27 16:21:24 -04:00
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
Ivan Kozlovic
3c9a7cc6e5 Move to Go 1.19, remote io/util, fix data race and a flapper
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2022-08-05 09:55:37 -06:00
Phil Pennock
e38419e09e testdata: regenerate X509 certs with new script 2022-07-28 02:52:56 -04:00
Phil Pennock
3f760760de test data: x509 cert reissuance script
We had some certs which used SHA1 still; this top-level script is a bit rough,
but works to recreate all the top-level certs, using a common CA.

RSA 2048 bits with SHA256.

I've put the IPv6 localhost IP into the certs too, wherever the IPv4 localhost
IP was present, as this might improve test-runner resilience in some
situations.  Seems like a good idea, can't think of a reason not to.
2022-07-28 02:52:36 -04:00
Matthias Hanel
d53d2d0484 [Added] account specific monitoring endpoint(s) (#3250)
Added http monitoring endpoint /accstatz
It responds with a list of statz for all accounts with local connections
the argument "unused=1" can be provided to get statz for all accounts
This endpoint is also exposed as nats request under:

This monitoring endpoint is exposed via the system account.
$SYS.REQ.ACCOUNT.*.STATZ
Each server will respond with connection statistics for the requested
account. The format of the data section is a list (size 1) identical to the event
$SYS.ACCOUNT.%s.SERVER.CONNS which is sent periodically as well as on
connect/disconnect. Unless requested by options, server without the account,
or server where the account has no local connections, will not respond.

A PING endpoint exists as well. The response format is identical to
$SYS.REQ.ACCOUNT.*.STATZ
(however the data section will contain more than one account, if they exist)
In addition to general filter options the request takes a list of accounts and
an argument to include accounts without local connections (disabled by default)
$SYS.REQ.ACCOUNT.PING.STATZ

Each account has a new system account import where the local subject
$SYS.REQ.ACCOUNT.PING.STATZ essentially responds as if
the importing account name was used for $SYS.REQ.ACCOUNT.*.STATZ

The only difference between requesting ACCOUNT.PING.STATZ from within
the system account and an account is that the later can only retrieve
statz for the account the client requests from.

Also exposed the monitoring /healthz via the system account under
$SYS.REQ.SERVER.*.HEALTHZ
$SYS.REQ.SERVER.PING.HEALTHZ
No dedicated options are available for these.
HEALTHZ also accept general filter options.

Signed-off-by: Matthias Hanel <mh@synadia.com>
2022-07-12 21:50:32 +02:00
Ivan Kozlovic
0e2ab5eeea Changes to tests that run on Travis
- Remove code coverage from Travis and add it to a GitHub Action
that will be run as a nightly.
- Use tag builds to exclude some tests, such as the "norace" or
JS tests. Since "go test" does not support "negative" regexs, there
is no other way.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2022-04-26 14:11:31 -06:00
Ivan Kozlovic
730d8921e4 [FIXED] LeafNode: propagation interest issue after a config reload
When a configuration reload is done, the account's leaf node connections
were not transfered to the new instance of the account, causing the
interest to not be propagated until a leafnode reconnect or a server
restart.

Resolves #3009

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2022-04-20 08:03:34 -06:00