Commit Graph

73 Commits

Author SHA1 Message Date
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
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
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
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
Phil Pennock
0ae8af7986 TLS testdata: automate more cert issuance 2022-09-07 16:33:28 -04: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
Julius Žaromskis
a47e5e045c [ADDED] TLS connection rate limiter 2022-01-11 16:57:19 +02:00
Ivan Kozlovic
8e5dff3e30 [FIXED] TLS map: panic for existing user but conn type not allowed
For TLS configuration with `verify_and_map` set to true, if a
connection connects and has a certificate with ID that matches
a user, but that user's `allowed_connection_types` is specified
and does not have the connection type in its list, then the
server will panic.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-12-15 10:09:18 -07:00
Ivan Kozlovic
a025ce7472 Set defaultServerOptions port to -1 for random
Updated some tests based on this change but also missing defer
connection close or server shutdown.

Fixed how the OCSP run go routine would shutdown, which would
never complete because grWG was not decremented by this go routine
prior to invoking s.Shutdown()

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-09-02 14:22:56 -06:00
Matthias Hanel
b1dee292e6 [changed] pinned certs to check the server connected to as well (#2247)
* [changed] pinned certs to check the server connected to as well

on reload clients with removed pinned certs will be disconnected.
The check happens only on tls handshake now.

Signed-off-by: Matthias Hanel <mh@synadia.com>
2021-05-24 17:28:32 -04:00
Matthias Hanel
6f6f22e9a7 [added] pinned_cert option to tls block hex(sha256(spki)) (#2233)
* [added] pinned_cert option to tls block hex(sha256(spki))

When read form config, the values are automatically lower cased.
The check when seeing the values programmatically requires 
lower case to avoid having to alter the map at this point.

Signed-off-by: Matthias Hanel <mh@synadia.com>
2021-05-20 17:00:09 -04:00
Ivan Kozlovic
6e1205b660 Cleanup some tests + GetTLSConnectionState() race fix
Missing defers

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-04-15 11:37:43 -06:00
Jaime Piña
d929ee1348 Check errors when removing test directories and files
Currently in tests, we have calls to os.Remove and os.RemoveAll where we
don't check the returned error. This hides useful error messages when
tests fail to run, such as "too many open files".

This change checks for more filesystem related errors and calls t.Fatal
if there is an error.
2021-04-07 11:09:47 -07:00
Jaime Piña
e44275b963 Consolidate temporary test files and directories
Currently, temporary test files and directories are written in lots of
different paths within the OS's temp dir. This makes it hard to know
which files are from nats-server and which are unrelated. This in turn
makes it hard to clean up nats-server test files.
2021-04-06 10:42:55 -07:00
Ivan Kozlovic
6c4229300a Fixed service import cycle detection that broke with JS clustering
Also added some no-op error handler for some tests to silence the
error report in the log.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-01-14 11:27:36 -07:00
Waldemar Quevedo
a766b52c47 Allow matching DNs regardless of order
Signed-off-by: Waldemar Quevedo <wally@synadia.com>
2020-11-23 12:16:49 -08:00
Waldemar Quevedo
886ecf7f89 Add support for subjects with multi value RDN
Signed-off-by: Waldemar Quevedo <wally@synadia.com>
2020-11-20 22:13:52 -08:00
Waldemar Quevedo
4029650740 Add test for multiple CNs
Signed-off-by: Waldemar Quevedo <wally@synadia.com>
2020-11-20 22:08:03 -08:00
Matthias Hanel
8fd1b66f66 Renaming to verify_cert_and_check_known_urls
Signed-off-by: Matthias Hanel <mh@synadia.com>
2020-11-20 16:56:44 -05:00
Matthias Hanel
eda80ff7b5 changing the option name verify_and_implicit_allow to verify_and_accept_known_urls
This follows the suggestion by phil. I added the and to be similar to verify_and_map.
I fixed a minor issue where the implicit verify could be overwriting an
explicitly configured one.

Signed-off-by: Matthias Hanel <mh@synadia.com>
2020-11-20 14:27:24 -05:00
Matthias Hanel
06e4e93185 Speeding up unit test fail case
Signed-off-by: Matthias Hanel <mh@synadia.com>
2020-11-20 13:57:34 -05:00
Matthias Hanel
f24aec4af7 Incorporating comments and fixed an issue where code was not invoked
had to change failing tests to use insecure as to not fail due to the
outgoing connection being not trusted.

Signed-off-by: Matthias Hanel <mh@synadia.com>
2020-11-20 13:57:34 -05:00
Matthias Hanel
74642e024e [Added] verify_and_implicit_allow to tie subject alt name to url in cfg
Only works for gateways and routes. When true the subject alt DNS name
must match one url in the corresponding configuration

Signed-off-by: Matthias Hanel <mh@synadia.com>
2020-11-20 13:57:34 -05:00
Waldemar Quevedo
26f4971827 Fix all certs for Go 1.15 SAN and CN changes
Signed-off-by: Waldemar Quevedo <wally@synadia.com>
2020-09-09 04:43:23 -07:00
Waldemar Quevedo
57f2c74d62 Better support for distinguishedNameMatch in TLS Auth
Signed-off-by: Waldemar Quevedo <wally@synadia.com>
2020-09-03 00:52:50 -07:00
Derek Collison
dd61535e5a Cluster names are now required.
Added cluster names as required for prep work for clustered JetStream. System can dynamically pick a cluster name and settle on one even in large clusters.

Signed-off-by: Derek Collison <derek@nats.io>
2020-06-12 15:48:38 -07:00
Derek Collison
4dee03b587 Allow mixed TLS and non-TLS on same port
Signed-off-by: Derek Collison <derek@nats.io>
2020-06-05 18:04:11 -07:00
Derek Collison
2bd7553c71 System Account on by default.
Most of the changes are to turn it off for tests that were watching subscriptions and such.

Signed-off-by: Derek Collison <derek@nats.io>
2020-05-29 17:56:45 -07:00
Waldemar Quevedo
625dd18974 Add support for SPIFFE x.509 SVIDs for auth
This can be enabled by using `verify_and_map`.

```
tls {
 cert_file: "server.pem"
 key_file: "server.key"
 ca_file: "ca.pem"
 timeout: 5
 verify_and_map: true
}

authorization {
  users = [
    {
      user = "spiffe://localhost/my-nats-service/user-a"
    },
    {
      user = "spiffe://localhost/my-nats-service/user-b",
      permissions = { subscribe = { deny = ">" }}
    },
  ]
}
```

Signed-off-by: Waldemar Quevedo <wally@synadia.com>
2020-05-27 13:10:42 -07: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
b42856afa2 Set expectConnect flag for CLIENT only if auth required
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-01-07 10:48:11 -07:00
Ivan Kozlovic
c73be88ac0 Updated based on comments
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-01-06 16:57:48 -07:00
Ivan Kozlovic
1b2754475b Refactor async client tests
Updated all tests that use "async" clients.
- start the writeLoop (this is in preparation for changes in the
  server that will not do send-in-place for some protocols, such
  as PING, etc..)
- Added missing defers in several tests
- fixed an issue in client.go where test was wrong possibly causing
  a panic.
- Had to skip a test for now since it would fail without server code
  change.

The next step will be ensure that all protocols are sent through
the writeLoop and that the data is properly flushed on close (important
for -ERR for instance).

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2019-12-12 11:58:24 -07:00
Ivan Kozlovic
3e1728d623 [FIXED] Some accounts locking issues
- Risk of deadlock when checking if issuer claim are trusted. There
  was a RLock() in one thread, then a request for Lock() in another
  that was waiting for RLock() to return, but the first thread was
  then doing RLock() which was not acquired because this was blocked
  by the Lock() request (see e2160cc571)

- Use proper account/locking mode when checking if stream/service
  exports/signer have changed.

- Account registration race (regression from https://github.com/nats-io/nats-server/pull/890)

- Move test from #890 to "no race" test since only then could it detect
  the double registration.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2019-11-16 16:59:38 -07:00
Ivan Kozlovic
e230e7fde9 Attempt at fixing flapper again
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2019-08-15 09:06:56 -06:00
Ivan Kozlovic
07e3db6b8e Prepare for v2.0.4 with goreleaser
Also fixed some flappers

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2019-08-15 09:06:56 -06:00
Ivan Kozlovic
ed1901c792 Update go.mod to satisfy v2 requirements
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2019-06-03 19:45:47 -06:00
Derek Collison
d7140a0fd1 Update for client rename
Signed-off-by: Derek Collison <derek@nats.io>
2019-05-10 15:11:30 -07:00
Derek Collison
acfe372d63 Changes for rename from gnatsd -> nats-server
Signed-off-by: Derek Collison <derek@nats.io>
2019-05-06 15:04:24 -07:00
Waldemar Quevedo
c3ee84a543 Support using SANs present in TLS cert for auth.
Also try multiple email and SANs found in cert until one valid
otherwise, default to the subject in the cert.

```
authorization {
  users [
    { user = "app.nats.dev", permissions = {
	publish {
	  allow = ["sandbox.>"]
	}
	subscribe {
	  allow = ["sandbox.>"]
	}
      }
    }
  ]
}
```

Signed-off-by: Waldemar Quevedo <wally@synadia.com>
2019-04-20 00:59:45 +09:00
Ivan Kozlovic
18399a3808 Gateways: Rework Account Sub/Unsub
We now send A- if an account does not exists, or if there is no
interest on a given subject and no existing subscription.
An A+ is sent if an A- was previously sent and a subscription
for this account is registered.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2019-02-26 18:34:30 -07:00
Waldemar Quevedo
4846b5ad6c Support for TLS certs based auth for gateways
When enabling verify and map as part of its TLS config
a the subject from TLS cert can now be used to confirm
the identity of a gateway.

```
gateway {
  tls {
    cert_file = "./configs/certs/tlsauth/server.pem"
    key_file = "./configs/certs/tlsauth/server-key.pem"
    ca_file = "./configs/certs/tlsauth/ca.pem"
    verify_and_map = true
    timeout = 2
  }

  authorization {
    user = "CN=localhost,OU=NATS.io Operators"
  }
}
```

Signed-off-by: Waldemar Quevedo <wally@synadia.com>
2019-02-18 21:48:06 -08:00
Waldemar Quevedo
01057467cf Support TLS based auth for routes
Similar as with clients, this makes it possible to
use the subject from a TLS certificate to validate
the permissions from a cluster member.

Currently only a single configured user is supported:

```
cluster {
  tls {
    cert_file = "./configs/certs/tlsauth/server.pem"
    key_file = "./configs/certs/tlsauth/server-key.pem"
    ca_file = "./configs/certs/tlsauth/ca.pem"
    verify_and_map = true
    timeout = 2
  }

  permissions {
    publish {
  	allow = ["public.>"]
    }
    subscribe {
  	allow = ["public.>"]
    }
  }

  authorization {
    user = "CN=localhost,OU=NATS.io Operators"
  }
}
```

Signed-off-by: Waldemar Quevedo <wally@synadia.com>
2019-02-18 17:12:09 -08:00
Waldemar Quevedo
7645d95c18 Support using TLS cert subject to auth user
Signed-off-by: Waldemar Quevedo <wally@synadia.com>
2019-02-06 12:36:03 -08:00
Ivan Kozlovic
b075c00103 [FIXED] Memory usage for failed TLS connections
Moving some of the connection initialization post TLS handshake
to avoid temporary memory growth when getting repeated failed
connections to any of the client, route and gateway ports.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2019-01-09 15:50:23 -07:00
Derek Collison
7978d8e667 Support for mapping user from TLS client certificate
Signed-off-by: Derek Collison <derek@nats.io>
2018-12-20 07:51:43 -08:00
Waldemar Quevedo
3cfc2fec29 Only consider as slow consumers clients that did CONNECT
Under some scenarios a client may hit the slow consumer
write deadline during the connecting stage, meaning that
it is possible to consider unhealthy clients could not
finish the TLS handshake as slow consumers.

With this change, we only consider as slow consumers
clients that did connect to the cluster without issues.

Signed-off-by: Waldemar Quevedo <wally@synadia.com>
2018-12-18 23:17:57 -08:00
Ivan Kozlovic
7c220ba700 Support for service export with wildcards
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2018-12-13 21:22:01 -07:00
Ivan Kozlovic
5f493862e6 [FIXED] Misleading Slow Consumer error message during TLS Handshake
When a TLS timeout occurs, it was possible that code trying to
send data would get a timeout error and report it as a Slow Consumer
with the write deadline exceeded error.
Checking that if the connection is TLS and handshake not complete,
it is likely a TLS timeout error instead.

Resolves #835

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2018-12-04 20:23:12 -07:00