Skip to content

"nsc generate creds" adds empty line before ------END NATS USER JWT------ #732

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

Closed
TrinterSoftware opened this issue Apr 11, 2025 · 19 comments
Labels
defect Suspected defect such as a bug or regression

Comments

@TrinterSoftware
Copy link

What version were you using?

2.10.2

What environment was the server running in?

Linux x86_64 native (no docker)

Is this defect reproducible?

nsc generate creds -n

Given the capability you are leveraging, describe your expectation?

generate no empty line before ------END NATS USER JWT------

Given the expectation, what is the defect you are observing?

"nsc generate creds" adds empty line (line break) before ------END NATS USER JWT------
A connection with this JWT is not possible, the server logs an auth error.

@TrinterSoftware TrinterSoftware added the defect Suspected defect such as a bug or regression label Apr 11, 2025
@aricart
Copy link
Member

aricart commented Apr 14, 2025

@TrinterSoftware what application fails to connect. The formatting for the creds is done by the JWT library, which standardizes on the format.

@TrinterSoftware
Copy link
Author

I observed it on two occations:

  1. With nats tool I couldn't connect using a context with a .creds file containing that empty line
  2. Connection with the GO client failed using that .creds file

@aricart
Copy link
Member

aricart commented Apr 15, 2025

I did a quick test:

> nsc generate creds -n U | bat -A -
───────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ STDIN
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ -----BEGIN·NATS·USER·JWT-----␊
   2   │ eyJ0eXAiOiJKV1QiLCJhbGciOiJlZDI1NTE5LW5rZXkifQ.eyJqdGkiOiJPUDQ1TFJNNFZOQk8zWVNJTUxYRTRKTVY2R0dLT1M0SVE3WEJJNDRGSFpMTDZIRDJRSFNBIiwiaWF0IjoxNzQ
       │ 0NzI2MzE1LCJpc3MiOiJBQ1gzTVZMSE5aNFNKWlFGUjcyRTJSUTdCVUlEVFFBQUZPVUFaTERRN1RLNDRSUzU1T1NWU1dVNSIsIm5hbWUiOiJ1Iiwic3ViIjoiVUJYWU5NQk1ZQTVaNFZYV
       │ jRMNzVCQjNLQkY3WUtBTVM1VjJaV0MyUVJMNVVYRUtESU5GSjI3TlIiLCJuYXRzIjp7InB1YiI6e30sInN1YiI6e30sInN1YnMiOi0xLCJkYXRhIjotMSwicGF5bG9hZCI6LTEsInR5cGU
       │ iOiJ1c2VyIiwidmVyc2lvbiI6Mn19.5jkqBNH7QrJc08RbZ7HPBl2teGSMaPEeGeDp2zbG6WaLMwPS8YWO6BKBTbET7uaLg24sLMfSVBh4SfZa18XODQ␊
   3   │ ------END·NATS·USER·JWT------␊
   4   │ ␊
   5   │ *************************·IMPORTANT·*************************␊
   6   │ NKEY·Seed·printed·below·can·be·used·to·sign·and·prove·identity.␊
   7   │ NKEYs·are·sensitive·and·should·be·treated·as·secrets.␊
   8   │ ␊
   9   │ -----BEGIN·USER·NKEY·SEED-----␊
  10   │ SUALIOPYEJREEYXDPPTJKT3AOK37S5PDEF35PACJRNL3VB6PLYWCOBTFJA␊
  11   │ ------END·USER·NKEY·SEED------␊
  12   │ ␊
  13   │ *************************************************************␊
  14   │ ␊
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

are your files being stored in some sort of shared volume? or something that would muck with line endings - editor?

@TrinterSoftware
Copy link
Author

The creds files are stored on the local drive. I used xfce4-terminal:

Image

@aricart
Copy link
Member

aricart commented Apr 15, 2025

Looks to me like the xfce4 terminal is doing stuff. Can you try a different terminal or output the creds to a file - nsc generate creds -n service -o /tmp/service.creds

@TrinterSoftware
Copy link
Author

With xterm the same, generated file also contains that empty line (I opened the file with mousepad and also printed it with cat).

@TrinterSoftware
Copy link
Author

TrinterSoftware commented Apr 15, 2025

A look with a hex editor shows two times 0x0A:
Image

@aricart
Copy link
Member

aricart commented Apr 15, 2025

Is this a particular user creating this situation?

....
00000230: 6834 5366 5a61 3138 584f 4451 0a2d 2d2d  h4SfZa18XODQ.---
00000240: 2d2d 2d45 4e44 204e 4154 5320 5553 4552  ---END NATS USER
00000250: 204a 5754 2d2d 2d2d 2d2d 0a0a 2a2a 2a2a   JWT------..****
00000260: 2a2a 2a2a 2a2a 2a2a 2a2a 2a2a 2a2a 2a2a  ****************
...

@TrinterSoftware
Copy link
Author

TrinterSoftware commented Apr 15, 2025

Yes, it depends on the users. Some have an empty line others not.
All tested users are from one account.

The strange thing is: I have two users, one correct, one with empty line. Both have the same (unlimited) permissions.

@TrinterSoftware
Copy link
Author

I've created three new users, all credentials are correct. Maybe it's a problem of an older version.

@aricart
Copy link
Member

aricart commented Apr 15, 2025

Can you take a look at the user JWT on disk for that user? is it possible that somehow a rogue newline was added?

@aricart
Copy link
Member

aricart commented Apr 15, 2025

I think the JWT for that user was copied from windows or viewed on an editor etc.

@TrinterSoftware
Copy link
Author

The creds file for the "service" user on disk und .local/share/nats/nsc/keys/creds/... has no empty line any more, I removed it by hand. When I create new creds for this user, the line shows up again.

I now know how to workaround this. From my perspective you can close this. I opened that ticket only to let you know.

@TrinterSoftware
Copy link
Author

The creds file for the "service" user on disk und .local/share/nats/nsc/keys/creds/... has no empty line any more, I removed it by hand. When I create new creds for this user, the line shows up again.

I now know how to workaround this. From my perspective you can close this. I opened that ticket only to let you know.

I didn't read you correctly, you wrote JWT and I thought .creds.
The problematic JWT has an 0x0A at the end, the correct ones dont't have it.

@aricart
Copy link
Member

aricart commented Apr 15, 2025

is that JWT super old?

@aricart
Copy link
Member

aricart commented Apr 15, 2025

cred generation doesn't regenerate the JWT, it simply copies them into the other document.

@TrinterSoftware
Copy link
Author

Thank you for bringing me clarity. It really looks like the JWT file was opened in an text editor.

@TrinterSoftware
Copy link
Author

is that JWT super old?

from may 2023

@aricart
Copy link
Member

aricart commented Apr 15, 2025

hummm . so possibly some old version of the software was not doing the right thing.

@aricart aricart closed this as completed Apr 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect Suspected defect such as a bug or regression
Projects
None yet
Development

No branches or pull requests

2 participants