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

Handle auto-creation of API user along Super User #2322

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Amphaal
Copy link

@Amphaal Amphaal commented Feb 23, 2025

Would fix #2314

@knadh
Copy link
Owner

knadh commented Feb 26, 2025

Thanks for the PR @Amphaal. API secrets are randomly generated, so it doesn't seem right to pass a manually constructed random looking secret into the DB from the CLI. Doesn't seem semantically right.

I do agree that it'd be good to have a way to generate a fully capable API user programmatically.

Would be good to know how other apps approach this. Have you seen examples?

@Amphaal
Copy link
Author

Amphaal commented Feb 27, 2025

No problem @knadh !

I agree with you, this is kind of an hack to allow "admin" permissions - like we would have pre v4 - which allows me to setup listmonk using automation.

What I am used to regarding token usage are:

  • Pre-generated "admin" API token somewhere on the container triggered by ENV parameterization, that we need to extract via volume binding on a specific path
  • Short-lived generation of tokens via a POST request (for example on /login/generateToken) that we would trigger using the classic Authorization auth method of existing admin user-password pair

Regarding current implementation, the first solution seems to fit. Let me know your thoughts about this !

@knadh
Copy link
Owner

knadh commented Mar 4, 2025

Thanks @Amphaal. API tokens are auto-generated strings, so passing a manually constructed string seems off. It then allows for string patterns (including proper words) to be passed as tokens, which technically is fine, but semantically, incorrect.

I think a more semantic, but slightly clunky approach is to auto-generate a token (when LISTMONK_ADMIN_API_USER is set) and print it to stdout, which can then be captured and extracted. This is a standard practice as well (eg: openssl CLI).

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 this pull request may close these issues.

Create API user through script/command line
2 participants