Git Product home page Git Product logo

nats-account-server's Introduction

NATS

nats-account-server

License ReportCard Build Coverage Version

Usage Recommendation ⚠️

If you are creating a new NATS deployment we highly recommend using the internal NATS Resolver for a much simpler and easy to manage account resolution system.

This account server is functional and still serves as a good reference to build upon for custom account resolution.

The NATS Account Server

A simple HTTP server to host account JWTs for nats-server 2.0 account authentication.

NATS 2.0 introduced the concept of accounts to provide secure multi-tenancy through separate subject spaces. These accounts are configured with JWTs that encapsulate the account settings. User JWTs are used to authenticate. The nats-server can be configured to use local account information or to rely on an external, HTTP-based source for account JWTs. The server in this repository is intended as a simple to use solution for hosting account JWTs.

This server is also intended as an example for developers that want to implement their own version of the server for resolving JWTs.

The nats-account-server does not have or need access to any private keys. Public keys are used to identify the operator and accounts.

HTTP API

The server's primary responsibility is to host account JWTs over HTTP. The NATS server, or other clients, can access an accounts JWT using the URL:

GET /jwt/v1/accounts/<pubkey>

this endpoint will:

  • Contains cache control headers
  • Uses the JTI as the ETag
  • Has content type application/jwt
  • Is unvalidated, and the JWT may have expired
  • Returns 304 if the request contains the appropriate If-None-Match header
  • Returns 404 if the JWT is not found
  • Return 200 and the encoded JWT if it is found

Several optional and mutually exclusive query parameters are supported:

  • text - set to "true" to change the content type to text/plain
  • decode - set to "true" to display the decoded JSON for the JWT header and body
  • check - set to "true" to tell the server to return 404 if the JWT is expired
  • notify - set to "true" to tell the server to send a notification to the nats-server indicating that this account changed.

For example, curl http://localhost:8080/jwt/v1/accounts/<pubkey>?check=true will return a 404 error if the JWT is expired.

The NATS server will hit this endpoint without a public key on startup to test that the server is available, so the server responds to GET /jwt/v1/accounts/ and GET /jwt/v1/accounts with a status 200.

When run with a mutable JWT store, the server will also allow JWTs to be uploaded.

POST /jwt/v1/accounts/<pubkey>

The JWT must be signed by the operator specified in the server's configuration.

A status 400 is returned if there is a problem with the JWT or the server is in read-only mode. In rare cases a status 500 may be returned if there was an issue saving the JWT.

Activation Tokens

The account server also supports storing activation tokens. These tokens are used when one account needs to give permission to another account to access a private export. Tokens can be configured as full tokens, or URLs. By hosting them in the account server you can avoid the copy/paste process of embedding tokens. They can also be updated more easily on expiration.

GET /jwt/v1/activations/<hash>

Retrieve an activation token by its hash.

The hash is calculated by creating a string with jwtIssuer.jwtSubject.[subject] and constructing the SHA-256 hash and base32 encoding that. Where [subject] is the exported subject, minus any wildcards, so foo.* becomes foo. The one special case is that if the export starts with "*" or is ">" the [subject] will be set to "_".

Three optional query parameters are supported:

  • text - can be set to "true" to change the content type to text/plain
  • decode - can be set to "true" to display the JSON for the JWT header and body
  • notify - can be set to "true" to trigger a notification event if NATS is configured

The response contains cache control headers, and uses the JTI as the ETag.

A 304 is returned if the request contains the appropriate If-None-Match header.

POST /jwt/v1/activations

Post a new activation token a JWT.

The body of the POST should be a valid activation token, with an account subject and issuer.

Activation tokens are stored by their hash, so two tokens with the same hash will overwrite each other, however this should only happen if the accounts and subjects match which requires either the same export or a matching one.

A status 400 is returned if there is a problem with the JWT or saving it. In rare cases a status 500 may be returned if there was an issue saving the JWT. Otherwise a status 200 is returned.

Help

A help page, for the API, is available at:

GET /jwt/v1/help

JWT Stores

This repository provides three JWT store implementations, and can be extended to provide others.

  • Directory Store - The directory store saves and loads JWTs into an optionally sharded structure under a root folder. The last two characters in the accounts public key are used to create a sub-folder, and the accounts public key is used as the file name, with ".jwt" appended. The directory store can be run in read-only mode. The server will watch for changes in read-only mode and send NATS notifications on changes, if configured to do so. In writable mode the server will only notify the nats-server of a change if the POST command is used to update a JWT.

  • NSC Store - The NSC store uses an operator folder, as created by the nsc tool as a JWT source. The store is read-only, but will automatically host new JWTs added by nsc. The server will watch for changes in the account JWT files and send NATS notifications on changes, if configured to do so.

  • Memory Store - By default the account server uses an in-memory store. This store is provided for testing and shouldn't be used in production.

The server understands one special JWT that doesn't have to be in the store. This JWT, called the system account, can be set up in the config file. The server will always try to return a JWT from the store, and if that fails, and the request was for the system JWT will try to return it directly.

NATS Notifications

The nats-server listens for notifications about changes to account JWTs on a system account. The account-server sends these notifications when a POST request is received, or when the notify query parameter is used with a GET request. Security for the NATS connection is configured via a credentials file in the configuration or on the command line.

The account server can be started with or without a NATS configuration, and will try to connect on a regular timer if it is configured to talk to NATS but can't find a server. This reconnect strategy allows us to avoid the chicken and egg problem where the NATS server requires its account resolver to be running but the account server can't find a valid nats-server to connect to.

Running the server

The server will compile to an executable named nats-account-server. You can run this executable without flags to get a memory based account server with no notifications. For more interesting operation there are a hand full of flags and a configuration file.

NSC Mode

To run the server on an NSC folder, use the -nsc flag to point to a specific operator folder in your NSC directory. For example:

% nats-account-server -nsc ~/.nsc/nats/signing_test

will run the account server, in read-only mode, on the operator folder named signing_test. Any account in signing test will be available via HTTP to the nats-server or another client. To enable notifications you can add the -nats parameter, and optionally the -creds flag to set a credential file.

% nats-account-server -nsc ~/.nsc/nats/signing_test -nats nats://localhost:4222

If the -nats flag is set, you can force a notification using a GET request like:

% curl http://localhost:58385/jwt/v1/accounts/ABVSBM3U45DGYEUECKXQS7BENHWG7KFQUDRTEHAJASORPVWBZ4HOIKCH\?notify\=true

The nsc-based account server will not accept POST requests.

Directory Mode

To run against a folder, use the -dir flag with an optional -ro flag. The -ro flag tells the server not to accept POST requests, and instead to watch the file system for changes. If the server accepts POST requests, it does not watch the file system for changes.

% nats-account-server -dir ~/myjwts

Directory Mode and Git

If you want to store your JWTs in a revision controlled folder, you can do something like:

% git clone <url to myjwts> myjwts
% nats-account-server -dir myjwts -ro -nats nats://192.169.0.1:4222

The account server will watch for file changes and send notifications to the nats-server when a change occurs. Only account JWTs are watched, activation JWT changes are ignored.

Note, creation of a file won't send the notification, only an actual write to the file. So if you edit a JWT and do a git pull, the notification will be sent.

Running with a Configuration File

To run with a configuration file, use the -c flag:

% nats-account-server -c <config file>

Any settings in the configuration file are applied first, then other flags are used. This allows you to override some settings on the command line.

Finally, you can use the -D, -V or -DV flags to turn on debug or verbose logging. The -DV option will turn on all logging, depending on the config file settings.

Replica Mode

For larger clusters you may deploy nats-servers in distributed locations geographically. This can lead to delay times when the server requests a JWT from the account server. To help alleviate this delay, or to allow load balancing and fault tolerance, the account server can run in replica mode. In this mode the server retrieves all JWTs from its primary. The replica will listen for NATS notifications and update appropriately. The replica will also look update on a regular time table in case a NATS message is missed.

Both account and activation tokens are replicated.

A replication timeout can be used to tune HTTP/network delays between the replica and the primary server.

Currently, replica mode only works if the primary nats-account-server is running in Directory Mode.

Replicas will try to download an initial set of JWTs from the master on startup. You can configure the maximum number to get with MaxReplicationPack, the default is 10,000, use 0 to disable this feature. JWTs are downloaded in no particular order, so if you have 100 and set max to 50 you will get a random set of 50. Also, if a directory store is used, the JWTs will only be saved if they were issued after the one the replica currently knows about.

Configuration

The configuration file uses the same YAML/JSON-like format as the nats-server. Configuration is organized into a root section with several sub-sections. The root section can contain the following entries:

  • logging - configuration for server logging
  • nats - configuration for the NATS connection
  • http - configuration for the HTTP Server
  • store - the store configuration parameters
  • operatorjwtpath - the path to an operator JWT, required for stores that accept POST request, all JWTs sent in a POST must be signed by one of the operator's keys
  • systemaccountjwtpath - the path to an account JWT that should be returned as the system account, works outside the normal store if necessary, however, the system account can be in the store, in which case this setting is optional
  • primary - the URL for the primary server, sets the server to run in replica mode, the format of the url is protocol://host:port
  • replicationtimeout - the time in milliseconds that the replica allows when talking to the primary, defaults to 5,000, or five seconds
  • maxreplicationpack - the number of JWTs to try to sync with the primary on startup, defaults to 10,000

The default configuration is:

{
    logging: {
        colors: true,
        time:   true,
        debug:  false,
        trace:  false,
    },
    http: {
        readtimeout:  5000,
        writetimeout: 5000,
    },
    nats: {
        connecttimeout: 5000,
        reconnectwait:  1000,
        maxreconnects:  0,
    },
    replicationtimeout: 5000,
}

Logging

Logging is configured in a manner similar to the nats-server:

logging: {
  time: true,
  debug: false,
  trace: false,
  colors: true,
  pid: false,
}

These properties are configured for:

  • time - include the time in logging statements
  • debug - include debug logging
  • trace - include verbose, or trace, logging
  • colors - colorize the logging statements
  • pid - include the process id in logging statements

Debug and trace can also be set on the command line with -D, -V and -DV to match the nats-server.

TLS

The NATS and HTTP configurations take an optional TLS setting. The TLS configuration takes three possible settings:

  • root - file path to a CA root certificate store, used for NATS connections
  • cert - file path to a server certificate, used for HTTPS monitoring and optionally for client side certificates with NATS
  • key - key for the certificate store specified in cert

NATS Configuration

The account server can connect to NATS to send notifications to the nats-servers associated with it. This connection requires a single section in the main configuration:

nats: {
  Servers: ["localhost:4222"],
  ConnectTimeout: 5000,
  MaxReconnects: 5,
  ReconnectWait: 5000,
}

NATS can be configured with the following properties:

  • servers - an array of server URLS
  • connecttimeout - the time, in milliseconds, to wait before failing to connect to the NATS server
  • reconnectwait - the time, in milliseconds, to wait between reconnect attempts
  • maxreconnects - the maximum number of reconnects to try before exiting the bridge with an error.
  • tls - (optional) TLS configuration. If the NATS server uses unverified TLS with a valid certificate, this setting isn't required.
  • UserCredentials - (optional) the path to a credentials file for connecting to the system account.

The account server uses the reconnect wait in two ways. First, it is used for normal NATS reconnections. Second, it is used with a timer if the account server can't connect to the NATS server upon startup. This failure at startup is expected since the nats-server configured with a URL resolver requires an account-server but the account server doesn't "require" NATS to host JWTs.

HTTP Configuration

HTTP is configured in the main section under http:

http: {
  host: "localhost",
  port: 9090,
  readtimeout: 5000,
  writetimeout: 5000,
}

The HTTP section contains the following properties:

  • host - a host on the local machine
  • port - the port to run on
  • readtimeout - the time, in milliseconds, to wait for reads to complete
  • writetimeout - the time, in milliseconds, to wait for writes to complete
  • tls - (optional) TLS configuration, only the cert and key properties are used.

If no host and port are provided the server will bind to all network interfaces and an ephemeral port.

Store Configuration

The store is configured in a single section called store:

store: {
    nsc: ~/.nsc/nats/signing_test
}

This section can contain the following properties:

  • nsc - the path to an NSC operator folder, this setting takes precedent over the others
  • dir - the path to a folder to use for storing JWTS
  • readonly - turns on/off mutability for the directory or memory stores
  • shard - if "true" the directory store will shard the files into sub-directories based on the last 2 characters of the public keys.

A memory store is created if nsc and dir are not set.

Building the Server

This project uses go modules and provides a make file. You should be able to simply:

% git clone https://github.com/nats-io/nats-account-server.git
% cd nats-account-server
% make

Note: Since changes to this project are not too frequent, it is possible that when you download the source and build the server, the tooling used to check code (staticcheck) finds issues that were not present the last time a commit was pushed. If that is the case, open an issue or if you are able, submit a PR with a fix. Thank you!

Use make test to run the tests, and make install to install.

The server does depend on the nats-server repo as well as nsc, and as a result contains a number of dependencies. However, the final executable is fairly small, ~10mb.

Docker

You can build the docker image using:

% docker build . -t "nats-io/nats-account-server:0.5"

Then run it with:

% docker run -v ~/.nsc/nats/<op name>:/<op name> -p 9090:9090 "nats-io/nats-account-server:0.5" -nsc /<op name> -nats docker.for.mac.host.internal:4222 -hp 0.0.0.0:9090

Note the use of docker.for.mac.host.internal for the mac host, and update that properly. Also, we use the operator name for the folder name to allow the server to find the operator JWT.

External Resources

License

Unless otherwise noted, the nats-account-server source files are distributed under the Apache Version 2.0 license found in the LICENSE file.

nats-account-server's People

Contributors

aricart avatar caleblloyd avatar colinsullivan1 avatar dthuering avatar gcolliso avatar jarema avatar kozlovic avatar matthiashanel avatar nsurfer avatar sasbury avatar tamalsaha avatar variadico avatar wallyqs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nats-account-server's Issues

version 0.8.2 throws error when running in replica mode

trying out the replica mode for the nats-account-server and there seems to be an issue with 0.8.2 version
When starting the replica nats-account-server (0.8.2), it gives the following error

./go/bin/nats-account-server -c natsAccRepl.conf -DV -primary http://localhost:9090
2019/11/06 17:54:57.955890 [INF] loading configuration from "/Users/m0s00tx/natsAccRepl.conf"
2019/11/06 17:54:57.956159 [INF] starting NATS Account server, version 0.8.2
2019/11/06 17:54:57.956179 [INF] server time is Wed Nov 6 17:54:57 CST 2019
2019/11/06 17:54:57.956188 [INF] starting in replicated mode, with primary at http://localhost:9090
2019/11/06 17:54:57.956197 [INF] running in replicated mode without NATS notifications can result in delayed updates
2019/11/06 17:54:57.956201 [INF] loading operator from /Users/m0s00tx/nn/.nsc/nats/O/O.jwt
2019/11/06 17:54:57.957054 [INF] creating a store at /tmp/jwts
2019/11/06 17:54:57.957084 [INF] NATS is not configured, server will not fire notifications on update
2019/11/06 17:54:57.957091 [INF] grabbing initial JWT pack from primary http://localhost:9090
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x1406d73]

goroutine 1 [running]:
github.com/nats-io/nats-account-server/server/core.(*AccountServer).initializeFromPrimary(0xc0000b2ea0, 0x0, 0x0)
/Users/m0s00tx/go/src/github.com/nats-io/nats-account-server/server/core/server.go:449 +0x283
github.com/nats-io/nats-account-server/server/core.(*AccountServer).Start(0xc0000b2ea0, 0x0, 0x0)
/Users/m0s00tx/go/src/github.com/nats-io/nats-account-server/server/core/server.go:233 +0x72f
main.main()
/Users/m0s00tx/go/src/github.com/nats-io/nats-account-server/main.go:134 +0x855

Downgraded nats-account-server to 0.8.0, and everything runs as it should
Let me know if more details are required

Server should exit 1 if specified config file does not exists

Currently it starts and creates an in-memory store:

ls /tmp/bar.conf
ls: /tmp/bar.conf: No such file or directory

nats-account-server -c /tmp/bar.conf
2019/08/09 14:44:36.843171 [INF] loading configuration from "/tmp/bar.conf"
2019/08/09 14:44:36.843331 [INF] starting NATS Account server, version 0.8.0
2019/08/09 14:44:36.843354 [INF] server time is Fri Aug  9 14:44:36 PDT 2019
2019/08/09 14:44:36.843373 [INF] creating an in-memory store

Exposition of port 9090 should be done before trying to communicate with Nats Cluster. To avoid the "Chicken and egg" issue

Hello guys !
I'm sharing my experience with the Nats account server, hope we can find a solution.

The documentation says we should spawn the Account Server before the Nats cluster.

When we do so, the Account Server tries to talk with the not yet available Nats Cluster, and retries until it's ready
(that make sense to me so far).

However, until the communication is ready, the Account Server doesn't seem to expose it's port 9090, that's where it breaks for me.
The Account Server is stalled there, trying to talk to nats, without exposing it's port.

On the other end, the Nats Cluster tries to boot, but cannot boot because it can't reach the Account Server.

Account Server error message:

2020/01/31 15:49:48.373407 [ERR] failed to connect to NATS, nats: no servers available for connection
2020/01/31 15:49:48.373422 [ERR] will try to connect again in 5000 milliseconds

Cluster error message:
nats-server: /etc/nats-config/nats.conf:29:1: could not fetch <"http://nats-account-server.default.svc.cluster.local:9090/jwt/v1/accounts/">: Get http://nats-account-server.default.svc.cluster.local:9090/jwt/v1/accounts/: dial tcp 172.20.237.239:9090: connect: connection refused

In the documentation here, it seems to be explained as the "Chicken and egg" issue lol.
https://github.com/nats-io/nats-account-server#run

Documentation says : "The account server can be started with or without a NATS configuration, and will try to connect on a regular timer if it is configured to talk to NATS but can't find a server. This reconnect strategy allows us to avoid the chicken and egg problem where the NATS server requires its account resolver to be running but the account server can't find a valid nats-server to connect to."

If the Account Server would expose it's 9090 port first, and then tries to communicate with the Cluster, that issue would probably not happen ?

R.I Piennar found this "sequential order" that seems to be reflecting my issue :

if err := server.connectToNATS(); err != nil {
return err
}
if server.primary != "" {
err := server.initializeFromPrimary()
if err != nil {
return err
}
}
if err := server.startHTTP(); err != nil {

Currently, seems the only way to work around this would be :

  1. Start account server without config (so it will exposed 9090)
  2. Start nats cluster
  3. Shutdown account server, edit config to add nats cluster endpoint and start again.

Doesn't really make sense right ?
What you guys think, should we invert the order ? Will it break something ?

Thanks !
--jm

stopping the nats-server where the account-server is performing notifications, stops the JWT store

nsc create operator -n X
nsc create account -n A
nsc create account -n SYS
nsc create user -n sys

Create a nats-account-server config nas.conf:

systemaccountjwtpath: "/users/synadia/.nsc/nats/X/accounts/SYS/SYS.jwt"
http {
	port: 9090
},
store {
	dir: "/tmp/as_store",
	readonly: false,
	shard: true
}
nats {
  servers: [nats://localhost:4222]
  usercredentials: "/Users/synadia/.nkeys/X/accounts/SYS/users/sys.creds"
}

Create a nats-server config server.conf:

operator: /users/synadia/.nsc/nats/X/X.jwt
resolver: URL(http://localhost:9090/jwt/v1/accounts/)
system_account: AAUR7CJU5WTR2RROXOJJFTJFJQPZ6B4VF2NOX6OQ6SQMPIKLQYQ7T37U

Start the various processes

> nats-account-server -c nas.conf
> nats-server -c server.conf

Use nsc to seed the account server

nsc push -A

<ctrl+z> the nats-server

The nats-account-server disconnects:

2019/05/31 16:37:28.631941 [WRN] nats disconnected
2019/05/31 16:37:28.632019 [ERR] nats connection closed, shutting down bridge
2019/05/31 16:37:28.632029 [INF] stopping account server
2019/05/31 16:37:28.632032 [INF] disconnected from NATS
2019/05/31 16:37:28.632035 [INF] stopping http server
2019/05/31 16:37:28.632090 [INF] http server stopped
2019/05/31 16:37:28.632100 [INF] http stopped
2019/05/31 16:37:28.632105 [INF] closed JWT store

staticcheck error S1017

version: NATS account server v1.0.0
golang: 1.16.6
staticcheck: v0.2.0

Following the recommended steps to build nats-account-server, i used the cmds

git clone --depth 1 --branch v1.0.0 https://github.com/nats-io/nats-account-server.git
cd nats-account-server
make

Make bails out of the staticcheck ./... part, crying out loud:

server/core/server.go:370:2: should replace this if statement with an unconditional strings.TrimSuffix (S1017)

This translates to line 376 in master:

	if strings.HasSuffix(primary, "/") {
		primary = primary[:len(primary)-1]
	}

What version of staticcheck are you using in your environment, that does not choke on the mentioned line?

Thank you for your feedback!

Default port with configuration file

If you use a configuration file, the default port of 9090 is not used.

To reproduce, just run with an empty config file.

$ touch oo.conf
$ nats-account-server -c oo.conf
2019/05/13 14:18:42.583273 [INF] loading configuration from "/Users/colinsullivan/go/src/github.com/nats-io/nats-account-server/oo.conf"
2019/05/13 14:18:42.583546 [INF] starting NATS Account server, version 0.0-dev
2019/05/13 14:18:42.583572 [INF] server time is Mon May 13 14:18:42 MDT 2019
2019/05/13 14:18:42.583583 [INF] creating an in-memory store
2019/05/13 14:18:42.583612 [INF] NATS is not configured, server will not fire notifications on update
2019/05/13 14:18:42.583961 [INF] http listening on port 61787
2019/05/13 14:18:42.583975 [INF] nats-account-server is running
2019/05/13 14:18:42.583980 [INF] configure the nats-server with:
2019/05/13 14:18:42.583992 [INF]   resolver: URL(http://127.0.0.1:61787/jwt/v1/accounts/)

v1.0.0 release broken

The v1.0.0 release has some issues, some are fixed in master, e.g.

  • wrong golang version in Dockerfile FROM golang:1.12.4 AS builder, should be >= 1.16, fixed in master
  • staticcheck fails (PR approved, but not merged)

This means the 1.0.0 release was never fully tested and since Mar 18 nobody has tried to fire up make in CI.

Could you please add some info to the repo release page to tell users to avoid the v1.0.0 release and use master?
And could you please merge #80 soon?

I am not sure if this 1.0.0 release is as embarrassing as i feel it is or if i am just angry to have wasted my time on this.

panic: runtime error when revocation is done for a user

Hi all,

I am using the nats-account-server version 0.8.4. If the server is running while doing a revocation using nsc tool, the nats-account-server stops and throws an error:

2020/11/22 18:44:02.555349 [INF] loading configuration from "/home/ubuntu/natsaccountserver.conf"
2020/11/22 18:44:02.556384 [INF] starting NATS Account server, version 0.8.4
2020/11/22 18:44:02.558303 [INF] server time is Sun Nov 22 18:44:02 CET 2020
2020/11/22 18:44:02.559107 [INF] loading operator from /home/ubuntu/.nsc/nats/something/something.jwt
2020/11/22 18:44:02.564659 [INF] loading system account from /home/ubuntu/.nsc/nats/something/accounts/SYS/SYS.jwt
2020/11/22 18:44:02.568421 [INF] creating a read-only store for the NSC folder at /home/ubuntu/.nsc/nats/something
2020/11/22 18:44:02.569964 [INF] connecting to NATS for notifications
2020/11/22 18:44:02.604849 [INF] connected to NATS for account and activation notifications
2020/11/22 18:44:02.608459 [INF] http listening on port 9090
2020/11/22 18:44:02.609303 [INF] nats-account-server is running
2020/11/22 18:44:02.610130 [INF] configure the nats-server with:
2020/11/22 18:44:02.611052 [INF]   resolver: URL(http://localhost:9090/jwt/v1/accounts/)
2020/11/22 18:45:09.961708 [ERR] The NSC store encountered an error, shutting down ...
2020/11/22 18:45:09.961765 [INF] stopping account server
2020/11/22 18:45:09.962008 [INF] disconnected from NATS
2020/11/22 18:45:09.962037 [INF] stopping http server
2020/11/22 18:45:09.962183 [INF] http server stopped
2020/11/22 18:45:09.962219 [ERR] error closing listener: close tcp 127.0.0.1:9090: use of closed network connection
2020/11/22 18:45:09.962246 [INF] http stopped
2020/11/22 18:45:09.976430 [INF] closed JWT store
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x60 pc=0x7a69ef]

goroutine 10 [running]:
github.com/nats-io/nats-account-server/server/store.(*NSCJWTStore).startWatching.func1(0xc0000ecab0, 0xc0000582a0)
	/Users/waldemarquevedo/repos/nats-dev/src/github.com/nats-io/nats-account-server/server/store/nscstore.go:125 +0x32f
created by github.com/nats-io/nats-account-server/server/store.(*NSCJWTStore).startWatching
	/Users/waldemarquevedo/repos/nats-dev/src/github.com/nats-io/nats-account-server/server/store/nscstore.go:103 +0x2b0

The nsc command I use to do the revocation is: nsc revocations add_user --name simple

Algorithm Problem Activations

Hi guys,

JWT Custom folder use.
/jwt/v1/activations POST Use algorithm HS256.
Error ; [ERR] bad activation JWT in request - unexpected "HS256" algorithm
change type; ed25519
after this problem;
bad activation JWT in request - claim failed signature verification.

Have you ever faced this problem?
I am trying to create tokens via JWT with PHP.

decoding functionality keeps HTML escapes

so when viewing decoded entries we get:

        "exports": [
            {
                "name": "abc",
                "subject": "a.b.c.\u003e",
                "type": "stream"
            }

go fix:

 buf := &bytes.Buffer{}
    encoder := json.NewEncoder(buf)
    encoder.SetEscapeHTML(false)
    err := encoder.Encode(conf)```

Primary and replica

Hello maintainers,
I would appreciate clarification on the primary/replica setup. From what I gather, there should be a single primary only. Any number of replicas that would download the token store from the primary on start.
Say I enable writable token store on both primary and replicas. The primary is at primary example com, and many replicas are behind a loadbalancer at replica.example.com. The loadbalancer uses simple random routing. What happens if i try to upload a token to replica.example.com? Would the primary now contain the uploaded token? In other words, is the primary's sole purpose a source for new replicas to sync up to?

some flags not working or missing

NATS Account server, version 0.8.6

"-nsc" is missing: flag provided but not defined: -nsc

"-c" doesn't appear to read the config file.

hostport on config file doesn't work

The host port in the config doesn't work (port will always autogenerate)
Also there's a stutter in the configuration:

http: {
 http: {
     port: x
     host: y
 }
}

Tried embedding the HostPort struct to see if the config parser would be happy - I noticed that it parses the map correctly however the apply doesn't work likely because of other logic trying to manage the embedded struct.

Run nats-account-server as Windows Service

nats-account-server can currently not be run as a Windows Service. Starting a nats-account-server as Windows Service currently gives the following error:
Windows could not start the MyNAS service on Local Computer.
Error 1053: The service did not respond to the start or control request in a timely fashion.

We believe this to be because "ServiceMain" is not implemented in this project.
There are workarounds for this like nssm but it would be prefered this is not needed. nats-server can currently already run as a windows service and it would be nice if nats-account-server could as well.

nsc push results in 404

When using the latest nsc against the latest nats-account-server release, nsc push -A returns that it failed to push to the remote server due to a 404 page error.

The `-nats` parameter is not honored when a config file is specified.

I tried this:

nats-account-server -nats "nats://foo:1234" -c config.conf

With a config file that specified localhost:4222. It connected to the local NATS server running at 4222. The command line parameter is ignored. This makes the account server impossible to run from within a docker image.

Support for direct access of the nsc folder has been removed

I was following the steps mentioned in the readme. I built the Docker image (after figuring out the missing steps of needing to cd into the folder) and ran docker run -v ~/.nsc/nats/<op name>:/<op name> -p 9090:9090 "nats-io/nats-account-server:0.5" -nsc /<op name> -nats docker.for.mac.host.internal:4222 -hp 0.0.0.0:9090 after taking quite a while to figure out that op is meant to be "operator". I'm then shown this error:
[ERR] Support for direct access of the nsc folder has been removed.

Guys, you've created a good software. But using it and figuring out the concepts is a nightmare. Please do a "hallway testing" of your documentation and tutorials to see how difficult it it is for someone to understand it. Also, there is a lot about the commands and the way components interact with each other that can be massively simplified.

For now, how does one get past this error and yet retain the ability to push JWT's to this server? My NSC is installed on my PC, with an operator and users configured. NATS is active as a Docker container with port 4222 exposed. Am only facing this issue with NAS.

Are filesystem notifications required?

One question raised by the #48 is the extra complexity involving the need for https://github.com/fsnotify/fsnotify, and whether nsc and read-only functionality is needed.

The server provides two kinds of stores, nsc and dir where it watches for modifications and performs a reload (need verification for the dir case). Filesystem initiated reloads are developer use-cases.

If nas is relying on filesystem notifications for internal reloads, that functionality arguably should be dropped, as any CDN caching, should be performed by a proper CDN. This means that the nas server should respond correctly to http HEAD requests, and allow the CDN to operate as it normally does. Invalidation of the CDN and nas integration is a separate topic.

The nsc option allows easier developer experience, save that it requires the user to specify the directory for the operator JWT. While technically this is useful, it would be more seamless from the user's perspective to have nsc start the nats-account-server and supplying all the required information. More importantly, it would be more useful for nsc to supply a skeleton configuration for the nats-account-server and then push the account configurations to it. This more closely models the actual usage of the product.

feature request - support db store for accounts

when deploying the nats-account-server on kubernetes, we should make sure we don't lose accounts though we have three replicas and PVC setup.

it's not easy to setup a backup-restore strategy on pvc with low RPO and RTO, i wonder would it be possible to add a new db store like postgresql, as a result, it would be much easier for recovery.

Is `nats-io/jwt/v2` not supported with `nats-account-server` ?

I created an operator using nats-io/jwt/v2 library. Then I used that as operatorjwtpath in config file.
But when I started nats-account-server, it's showing unexpected "ed25519-nkey" algorithm for operator jwt.

$ cat nats-account-server.conf
operatorjwtpath: "/home/masud/go/src/github.com/masudur-rahman/demo-cloudevents/nats/confs/KO.jwt"
http {
    port: 9090
}
store {
    dir: "/tmp/as_store",
    readonly: false,
    shard: true
}
$ nats-account-server -c nats-account-server.conf
2020/09/14 16:34:16.412009 [INF] loading configuration from "/home/masud/nats-account-server.conf"
2020/09/14 16:34:16.412332 [INF] starting NATS Account server, version 0.8.4
2020/09/14 16:34:16.412378 [INF] server time is Mon Sep 14 16:34:16 +06 2020
2020/09/14 16:34:16.412409 [INF] loading operator from /home/masud/go/src/github.com/masudur-rahman/demo-cloudevents/nats/confs/KO.jwt
2020/09/14 16:34:16.412612 [ERR] unexpected "ed25519-nkey" algorithm
2020/09/14 16:34:16.412632 [INF] stopping account server
2020/09/14 16:34:16.412644 [INF] http stopped

No Logs for when the account server connects to nats (only on reconnect)

When the Account Server is connecting to Nats there is no clear log statement that says it connected to Nats. However, when I delete / recreate the Nats Server it shows that it disconnects and reconnects.

2019/11/14 03:45:07.947756 [�[32mINF�[0m] connecting to NATS for notifications
2019/11/14 03:45:07.992676 [�[31mERR�[0m] failed to connect to NATS, nats: no servers available for connection
2019/11/14 03:45:07.992694 [�[31mERR�[0m] will try to connect again in 5000 milliseconds
2019/11/14 03:45:12.992832 [�[32mINF�[0m] connecting to NATS for notifications
2019/11/14 03:47:44.128313 [�[0;93mWRN�[0m] nats disconnected
2019/11/14 03:48:14.622499 [�[0;93mWRN�[0m] nats reconnected

Hostport on config file still does not work

The host and port setting in config file is still ignored. The standard host and port will be used.
When using the commandline parameter -hp everything works as expected.

Add `operator` config as in the NATS Server

Make these consistent. Current NATS Account Server:

operatorjwtpath: "./nsc/accounts/nats/KO/KO.jwt"
systemaccountjwtpath: "./nsc/accounts/nats/KO/accounts/SYS/SYS.jwt"

In NATS Server:

operator: eyJ0eXAiOiJqd3QiLCJhbGciOiJlZDI1NTE5In0.eyJqdGkiOiJI...
resolver: URL(http://external-nats-account-server:9090/jwt/v1/accounts/)
system_account: ABWYO322B3VDCKEFRVXWSIXXK6NZLY63XBAIZ34Q5HDU3VTDVVVPWCEV

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.