Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nats server run with ngs context fails on windows #732

Closed
kmpm opened this issue Mar 17, 2023 · 14 comments
Closed

nats server run with ngs context fails on windows #732

kmpm opened this issue Mar 17, 2023 · 14 comments

Comments

@kmpm
Copy link
Contributor

kmpm commented Mar 17, 2023

I'm running then natscli compiled from source 0d8f405 (because wanting to play with nats.micro) and are having issues following
the guide at https://docs.synadia.com/guides/ngs-dayone-guide#living-on-the-edge-ngs-leaf-nodes

One of the steps would have me to run the embedded server but it fails.

nats server run --context ngsleafnode --jetstream --extend
nats: error: Parse error on line 51: 'Invalid escape character 'U'. Only the following escape characters are allowed: \xXX, \t, \n, \r, \", \\.'

This looks a lot like issue #486 but my guess it is having a hard time finding the credentials or something because of lots of backslashes that are not escaped correctly.

nats context info ngsleafnode
NATS Configuration Context "ngsleafnode"

      Description: synadia (Synadia Communications Inc.)
      Server URLs: tls://connect.ngs.global
      Credentials: C:\Users\<redacted username>\.local\share\nats\nsc\keys\creds\synadia\<redacted account>\default.creds (OK)
             Path: C:\Users\<redacted username>\.config\nats\context\ngsleafnode.json
@ripienaar
Copy link
Collaborator

You should be able to swop the backslashes for forward slashes and it should work, i think

@kmpm
Copy link
Contributor Author

kmpm commented Mar 17, 2023

Yes it works if I edit the context.
So is the fault with nsc that created the context or natscli where it is used?
The context is technically correct since windows use backslash but where would you like the issue fixed?

@ripienaar
Copy link
Collaborator

Can you paste your context file please? C:\Users\<redacted username>\.config\nats\context\ngsleafnode.json

@kmpm
Copy link
Contributor Author

kmpm commented Mar 17, 2023

I have traced the issue to somewhere in the parse func in nats-server/conf/parse.go

The context looks like this...

# Friendly description for this context shown when listing contexts
description: synadia (Synadia Communications Inc.)

# A comma separated list of NATS Servers to connect to
url: tls://connect.ngs.global

# Connect using a specific username, requires password to be set
user: ""
password: ""

# Connect using a NATS Credentials stored in a file
creds: C:\Users\<redacted username>\.local\share\nats\nsc\keys\creds\synadia\<redacted account>\default.creds

# Connect using a NKey derived from a seedfile
nkey: ""

# Configures a token to pass in the connection
token: ""

# Sets a x509 certificate to use, both cert and key should be set
cert: ""
key: ""

# Sets an optional x509 trust chain to use
ca: ""

# Retrieves connection information from 'nsc'
#
# Example: nsc://Acme+Inc/HR/Automation
nsc: ""

# Use a custom inbox prefix
#
# Example : _INBOX.private.userid
inbox_prefix: ""

# Sets a color scheme to use for the nats command line tool
# this will influence table color choices allowing different
# contexts to be visually distinguished.
#
# Valid values are:
#
#   rounded
#   double
#   yellow
#   blue
#   cyan
#   green
#   magenta
#   red
#
# When not set "rounded" is used
color_scheme: ""

# Connects to a specific JetStream domain
jetstream_domain: ""

# Subject used as a prefix when accessing the JetStream API if imported from another account
jetstream_api_prefix: ""

# Subject prefix used to access JetStream events if imported from another account
jetstream_event_prefix: ""

# Use a Socks5 proxy like ssh to connect to the NATS server URLS
#
# Example: socks5://example.net:1090
socks_proxy: ""

@kmpm
Copy link
Contributor Author

kmpm commented Mar 17, 2023

In json

{
  "ca": "",
  "cert": "",
  "color_scheme": "",
  "creds": "C:\\Users\\<redacted user>\\.local\\share\\nats\\nsc\\keys\\creds\\synadia\\<redacted account>\\default.creds",
  "description": "synadia (Synadia Communications Inc.)",
  "inbox_prefix": "",
  "jetstream_api_prefix": "",
  "jetstream_domain": "",
  "jetstream_event_prefix": "",
  "key": "",
  "nkey": "",
  "nsc": "",
  "password": "",
  "socks_proxy": "",
  "token": "",
  "url": "tls://connect.ngs.global",
  "user": ""
}

@kmpm
Copy link
Contributor Author

kmpm commented Mar 17, 2023

The temporary server config created looks like


listen: 0.0.0.0:27260
server_name: nats_development
debug: false
trace: false
system_account: SYSTEM
logtime: false
jetstream {
    store_dir: C:\\Users\\<redacted user>\\.local\\share\\nats\\nats_development
	domain: NATS_DEVELOPMENT
}

accounts {
    USER: {
        jetstream: enabled
        users: [
            {
                user: "local",
                password: "<redacted hash>"
            }
        ]

        imports: [
            {service: {account: SERVICE, subject: "service.>"}, to: "imports.SERVICE.>"}
        ]
    }

    SERVICE: {
        jetstream: enabled
        users: [
            {
                user: "service",
                password: "<redacted hash>"
            }
        ]

        exports: [
            {service: service.>}
        ]
    }

    SYSTEM: {
        users: [{"user": "system", "password": "<redacted hash>"}],
    }
}

leafnodes {
    remotes = [
        {
            url: "tls://connect.ngs.global",
            credentials: "C:\Users\<redacted user>\.local\share\nats\nsc\keys\creds\synadia\<redacted account>\default.creds",
            account: "USER"
        }
    ]
}

@kmpm
Copy link
Contributor Author

kmpm commented Mar 17, 2023

Looks as the remote credentials path doesn't get correctly escaped before the config template is processed.

@ripienaar
Copy link
Collaborator

OK - I am a bit surprised the docs led a NGS user down the path of nats server run as its a very experimental feature.

But yes, seems if we escape these strings when writing the server config probably it will work

kmpm added a commit to kmpm/natscli that referenced this issue Mar 17, 2023
This adds a `fixpath` function that can be used in
the server template to escape windows paths.

* fixes nats-io#732
@kmpm
Copy link
Contributor Author

kmpm commented Mar 17, 2023

The output from your call to shellescape is the same as the input, so no effect.

@ripienaar
Copy link
Collaborator

The problem is we add yours then anyone who had already fixed this up will break...but anyway server run is not supported part of the cli (even hidden in --help) so will take your fix ontop of mine.

@ripienaar
Copy link
Collaborator

OK try main again, I should have just taken yours sorry about that.

@kmpm
Copy link
Contributor Author

kmpm commented Mar 17, 2023

Commit bcc57a2 now works, great, thanks..... but.
How about implementing the same method for StoreDir and remove the previous workaround ( about line 261-264 ).
Also add quotes to the StorDir in the template so that paths with spaces might work.
(see my PR for reference)

@ripienaar
Copy link
Collaborator

OK, I will have to get to this another day unfortunately - unless you want to update your PR or send a new one

@kmpm
Copy link
Contributor Author

kmpm commented Mar 17, 2023

I can make a new one. No worries

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants