Commit Graph

112 Commits

Author SHA1 Message Date
Matthias Hanel
9d1526cbb8 Adding user jwt payload and subscriber limits
Addresses part of #1552

Signed-off-by: Matthias Hanel <mh@synadia.com>
2020-08-24 18:16:25 -04:00
Ivan Kozlovic
92970316ee [FIXED] Possible panic for TLS connections that are aborted early
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-08-18 16:38:35 -06:00
Ivan Kozlovic
2c8bf520d1 [FIXED] Connection name in log statement for some IPv6 addresses
If an IPv6 address contains some "%" characters, this was causing
the connection name in log statement to mess up the Sprintf formatting.
The solution is to escape those "%" characters.

Resolves #1505

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-07-08 10:17:14 -06:00
Ivan Kozlovic
27540ee255 Fixed some flappers
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-07-03 11:30:48 -06:00
Ivan Kozlovic
342acb0fe7 Fixed async client tests
In some tests, async clients are used with a running server (which
was not original intent). This resulted in the client writeLoop
to be started twice.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-07-01 15:53:08 -06:00
Derek Collison
ddb4219f7a Allow support for a empty response message when no responders are present.
This will also set a response status of 503 with the new header support.

Signed-off-by: Derek Collison <derek@nats.io>
2020-06-15 10:10:21 -07:00
Derek Collison
5f130128ce Read INFO used bufio.Reader
Signed-off-by: Derek Collison <derek@nats.io>
2020-06-01 11:46:18 -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
Ivan Kozlovic
b0e43b6aa9 Fix flappers
- TestResponsePermissions: ensure subscription for service is
registered by server before sending requests.
- TestReloadDoesNotWipeAccountsWithOperatorMode: wait for subject
propagation.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-05-28 13:41:02 -06:00
Ivan Kozlovic
dc0f688cbf [FIXED] LameDuckMode sends INFO to clients
Also send an INFO to routes so that the remotes can remove the
LDM's server client URLs and notify their own clients of this
change.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-05-21 12:15:20 -06:00
Ivan Kozlovic
9715848a8e [ADDED] Websocket support
Websocket support can be enabled with a new websocket
configuration block:

```
websocket {
    # Specify a host and port to listen for websocket connections
    # listen: "host:port"

    # It can also be configured with individual parameters,
    # namely host and port.
    # host: "hostname"
    # port: 4443

    # This will optionally specify what host:port for websocket
    # connections to be advertised in the cluster
    # advertise: "host:port"

    # TLS configuration is required
    tls {
      cert_file: "/path/to/cert.pem"
      key_file: "/path/to/key.pem"
    }

    # If same_origin is true, then the Origin header of the
    # client request must match the request's Host.
    # same_origin: true

    # This list specifies the only accepted values for
    # the client's request Origin header. The scheme,
    # host and port must match. By convention, the
    # absence of port for an http:// scheme will be 80,
    # and for https:// will be 443.
    # allowed_origins [
    #    "http://www.example.com"
    #    "https://www.other-example.com"
    # ]

    # This enables support for compressed websocket frames
    # in the server. For compression to be used, both server
    # and client have to support it.
    # compression: true

    # This is the total time allowed for the server to
    # read the client request and write the response back
    # to the client. This include the time needed for the
    # TLS handshake.
    # handshake_timeout: "2s"
}
```

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-05-20 11:14:39 -06:00
Derek Collison
f5ceab339a Server support for headers between routes
Signed-off-by: Derek Collison <derek@nats.io>
2020-05-19 14:33:06 -07:00
Derek Collison
55c77d1e4e Added support for delivery of HMSG and support for older clients
Signed-off-by: Derek Collison <derek@nats.io>
2020-05-19 14:33:06 -07:00
Derek Collison
d61f1f5d92 Add in support for client header bool in CONNECT and tests
Signed-off-by: Derek Collison <derek@nats.io>
2020-05-19 14:33:06 -07:00
Derek Collison
d51566881e First pass at headers awareness for server
Signed-off-by: Derek Collison <derek@nats.io>
2020-05-19 14:33:06 -07:00
Derek Collison
a7f1bca534 Additional service latency upgrades.
We now share more information about the responder and the requestor. The requestor information by default is not shared, but can be when declaring the import.

Also fixed bug for error handling on old request style requests that would always result on a 408 response.

Signed-off-by: Derek Collison <derek@nats.io>
2020-05-19 14:26:46 -07:00
Ivan Kozlovic
46f880bc52 [FIXED] Early closed connection may linger in the server
If the connection is marked as closed while sending the INFO, the
connection would not be removed from the internal map, which would
cause it to be shown in the monitoring list of opened connections.

Resolves #1384

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-05-08 12:01:15 -06:00
Ivan Kozlovic
be00ea96cf [IMPROVED] Added close reason in the connection close log statement
This gives the close reason directly in the log without having to
get that information from the monitoring endpoint. Here is an
example of a route closed due to the remote side not replying to
PINGs:

```
[INF] 127.0.0.1:53839 - rid:2 - Router connection closed: Stale Connection
```

Without this change, the log statement would have been:
```
[INF] 127.0.0.1:53839 - rid:2 - Router connection closed
```

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-04-15 15:36:54 -06:00
Ivan Kozlovic
6f3418687b Capture original length of the first slice and updated test
Changed test to make the previous code in flushOutbound fail.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-03-03 19:12:42 -07:00
Ivan Kozlovic
fd8539f15f [FIXED] Incorrect buffer reuse in case of partial connection write
Added a test that demonstrates the issue and a proposed fix.

Also decrement c.out.pb if closing due to max pending limit.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-03-03 16:50:03 -07:00
Matthias Hanel
a8e6af30a3 On client connect, send first ping after ping interval.
On connect message resend reset timer with setFirstPingTimer, so RTT can
be obtained quicker.

Disable short first ping in default server options for client_test.
In log_test prevent immediate scheduling by setting ping interval.

Signed-off-by: Matthias Hanel <mh@synadia.com>
2020-03-02 20:10:15 -05:00
Ivan Kozlovic
20768b72c3 [FIXED] Display of connections address when using IPv6
When the server logs information related to a connection, it uses
the connection IP and remote port as a prefix. When it was an IPv6
address, the square brackets would be missing.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-01-22 09:12:39 -07:00
Ivan Kozlovic
971d2350ed Fixed client stalled duration computation and added back Gosched()
This related to PR #1233.

The computation of the time to stall a fast producer was bogus. Fixed
that and added a unit test for the function computing this stalled
duration.

Also, in PR #1233, I had removed Gosched() when a call to flushOutbound()
realizes that the flag is already set. It was forgetting that readLoop
in some cases will call flushOutbound() in place. So there is still
value in unlock/gosched/lock again in that function.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-01-10 11:21:38 -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
947798231b [UPDATED] TCP Write and SlowConsumer handling
- All writes will now be done by the writeLoop, unless when the
  writeLoop has not been started yet (likely in connection init).
- Slow consumers for non CLIENT connections will be reported but
  not failed. The idea is that routes, gateway, etc.. connections
  should stay connected as much as possible. However if a flush
  operation times out and no data at all has been written, the
  connection will be closed (regardless of type).
- Slow consumers due to max pending is only for CLIENT connections.
  This allows sending of SUBs through routes, etc.. to not have
  to be chunked.
- The backpressure to CLIENT connections is increased (up to 1sec)
  based on the sub's connection pending bytes level.
- Connection is flushed on close from the writeLoop as to not block
  the "fast path".

Some tests have been fixed and adapted since now closeConnection()
is not flushing/closing/removing connection in place.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2019-12-31 15:06:27 -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
a22da91647 [FIXED] Closing of Gateway or Route TLS connection may hang
This could happen if the remote server is running but not dequeueing
from the socket. TLS connection Close() may send/read and so we
need to protect with a deadline.

For non client/leaf connection, do not call flushOutbound().
Set the write deadline regardless of handshakeComplete flag, and
set it to a low value.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2019-12-04 17:27:00 -07:00
Ivan Kozlovic
9b7dab0548 Updates based on code review
- Add atomic in client to skip check in processInboundClientMsg()
  if value is 0. Avoids getting the lock in fast path if not needed.
- Have a timer per client instead of the global server list that
  was expiring: noticed a lot of contention there when running
  some perf/profiling tests. The timer is also not reset for
  every timestamp that is not yet expired since this too affects
  performance. Instead fires are regular interval and cleared
  when map is empty after a cycle.
- Move processing of gw map rely on its own function (in inbound msg).
  I have verified that this is inlined same way as when code was
  directly in processInboundClientMsg.
- Use string(subj[]) for prefix detection: I have verified that
  it is actually faster.
- Builds the RMSG with appends to local buffer in handleGatewayReply()
  instead of using fmt.Sprintf().

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2019-11-08 15:56:28 -07:00
Ivan Kozlovic
aa843945c9 Work on Gateways reply mapping
- New prefix that includes origin server for the request
- Mapping done if request is service import or requestor has
  recent subscription
- Subscription considered recent if less than 250ms
- Destination server strip GW prefix before giving to client
  and restore when getting a reply on that subject
- Mapping removed aftert 250ms
- Server rejects client publish on "$GNR." (the new prefix)
- Cluster and server hash are now 8 chars long and from base 62
  alphabets
- Mapped replies need to be sent to leafnode servers due to race
  (cluster B sends RS+ on GW inbound then RMSG on outbound, the
  RS+ may be processed later and cluster A may have given message
  to LN before RS+ on reply subject. So LN needs to accept the
  mapped reply but will strip to give to client and reassemble
  before sending it back)

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2019-11-06 16:06:49 -07:00
Ivan Kozlovic
17a7d0d866 [FIXED] Server should not send RTT PING before sending initial PONG
As soon as server has processed a client CONNECT, it was possible
that if Connz() or other was requested, the server will send a
PING to compute the RTT. This would cause clients that expect
the first PONG as part of synchronous CONNECT logic to fail.

Make sure that we delay the first RTT ping to after sending the
first PONG, or if client does not send PING as part of the CONNECT,
after 2 seconds have elapsed since the tcp connection was accepted.

Resolves #1174

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2019-10-30 19:50:19 -06:00
Jaime Piña
64664946e7 Add QueueSubscribe permissions.
```
users = [
  {
    user: "foo", permissions: {
      sub: {
        # Allow plain subscription foo, but only v1 groups or *.dev queue groups
        allow: ["foo", "foo v1", "foo v1.>", "foo *.dev"]

        # Prevent queue subscriptions on prod groups
        deny: ["> *.prod"]
     }
  }
]
```

Signed-off-by: Jaime Piña <jaime@synadia.com>
Signed-off-by: Waldemar Quevedo <wally@synadia.com>
2019-09-27 16:08:24 -07:00
Ivan Kozlovic
731941a18f Fixed ResponsePermissions
- Ensure that defaults are set when values are 0
- Fixed some tests
- Added some helpers in jwt tests to reduce copy/paste

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2019-09-19 14:42:38 -06:00
Ivan Kozlovic
effa30ce4a [FIXED] MaxPending > MaxInt32 causes client to be disconnected
Changed some of client.outbound fields to int64.
Moved fields around to minimize size of struct (checked with
unsafe.Sizeof())
Checked benchmark results before/after
Added test

Resolves #1118

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2019-09-11 14:29:02 -06:00
Derek Collison
7989118c3f First pass latency tracking for exported services
Signed-off-by: Derek Collison <derek@nats.io>
2019-08-30 10:52:48 -07:00
Derek Collison
8f5bc503e5 Add ability for cross account import services to return streams as well as singeltons.
Take into account tracking of response maps that are created and do proper cleanup.
Also fixes #1089 which was discovered while working on this.

Signed-off-by: Derek Collison <derek@nats.io>
2019-08-06 14:15:40 -07:00
Andy Xie
2f99b144aa add ut for tracemsg 2019-07-15 14:02:02 +08:00
Derek Collison
da938dcb1e Cleaned up debug and fixed test
Signed-off-by: Derek Collison <derek@nats.io>
2019-05-30 14:30:35 -07:00
Ivan Kozlovic
33505e4849 Print warning if code in readloop execute for more than threshold
Issue a warning in readLoop if execution of code after connection
Read() until end of for loop reaches a certain threshold.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2019-05-28 18:33:48 -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
af78552549 Move ints to proper sizes for all
Signed-off-by: Derek Collison <derek@nats.io>
2019-02-05 15:19:59 -08:00
Waldemar Quevedo
e4a4c98ad0 Fix logging public nkey on auth violation
Signed-off-by: Waldemar Quevedo <wally@synadia.com>
2019-02-01 17:20:04 -08:00
R.I.Pienaar
08eafd89f8 Expose the connection remote address to CustomClientAuthentication
This adds a RemoteAddress() method to the ClientAuthentication
interface which would facilitate CustomClientAuthentication
mechanisms considering the remote IP address of the client in
their decisions to allow clients or not

Resolves #832

Signed-off-by: R.I.Pienaar <rip@devco.net>
2018-12-06 09:04:56 +01:00
Derek Collison
0ee714ce28 Add JWT support for users, accounts and import activations.
Add in trusted keys options and binary stamp
User JWT and Account fetch with AccountResolver
Account and User expiration
Account Imports/Exports w/ updates
Import activation expiration

Signed-off-by: Derek Collison <derek@nats.io>
2018-11-21 10:36:32 -08:00
Ivan Kozlovic
0c11279946 Fixed data race with client trace flag
This was introduced with ec3115ad21

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2018-11-07 16:33:30 -07:00
Derek Collison
ea5a6d9589 Updates for comments, some golint fixes
Signed-off-by: Derek Collison <derek@nats.io>
2018-10-31 20:28:44 -07:00
Derek Collison
47963303f8 First pass at new cluster design
Signed-off-by: Derek Collison <derek@nats.io>
2018-10-24 21:29:29 -07:00
Derek Collison
f6cb706c68 First pass req/reply across accounts
Signed-off-by: Derek Collison <derek@nats.io>
2018-09-29 13:04:19 +02:00
Derek Collison
620e1d7364 Basic account mapping via import and export
Signed-off-by: Derek Collison <derek@nats.io>
2018-09-29 13:04:19 +02:00
Derek Collison
1cbfbfa071 Basic account support
Signed-off-by: Derek Collison <derek@nats.io>
2018-09-29 13:04:19 +02:00