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

INITIAL_API_KEY_FILE not working as documented #2212

Closed
Maypul opened this issue Oct 9, 2024 · 5 comments · Fixed by #2220
Closed

INITIAL_API_KEY_FILE not working as documented #2212

Maypul opened this issue Oct 9, 2024 · 5 comments · Fixed by #2220
Labels
Milestone

Comments

@Maypul
Copy link

Maypul commented Oct 9, 2024

Shlink version

4.2.1

PHP version

4.2.1

How do you serve Shlink

Docker image

Database engine

PostgreSQL

Database version

16.3

Current behavior

When setting up INITIAL_API_KEY_FILE the initial API key is not being created. Using INITIAL_API_KEY works as intended.

As documented in https://shlink.io/documentation/environment-variables/#secret-env-vars
"Starting with Shlink 4.0.0, you can pass any environment variable with the _FILE suffix."

As a side request, if it would be implemented, could web client also use SHLINK_SERVER_API_KEY from the docker secret file?

Expected behavior

INITIAL_API_KEY_FILE loads value from the client and creates initial API key.

Minimum steps to reproduce

Create a docker container with the

shlink:
(...)
secrets:
- source: shlink_api_key
target: /run/secrets/shlink_api_key
environment:
(...)
INITIAL_API_KEY_FILE: /run/secrets/shlink_api_key

@acelaya
Copy link
Member

acelaya commented Oct 9, 2024

Did you set the file env var on the very first Shlink boot up?

The initial API key is special, and only set once if no other API keys exist yet.

If you started Shlink with the non-file env var and then switched to the file one, Shlink will ignore it.

@acelaya
Copy link
Member

acelaya commented Oct 9, 2024

Actually, scratch that. I see the problem.

This env var is different than the rest, in which it's not read by Shlink at runtime, but in the docker container entry point. See

if [ -n "${INITIAL_API_KEY}" ]; then

That is missing the logic to fall back to the _FILE suffixed env var for obvious reasons because that's implemented in PHP.

I'll need to investigate how to support it there.

@acelaya acelaya added this to the 4.2.2 milestone Oct 10, 2024
@acelaya acelaya moved this to Todo in Shlink Oct 10, 2024
@acelaya
Copy link
Member

acelaya commented Oct 13, 2024

In order to fix this I'm introducing a helper command to Shlink that will return the value for any supported env var, but making sure the fallback logic to _FILE is applied.

Then I will use that command in non-php scripts (like the docker entry point) to get the values of env vars, rather than reading env vars directly.

That should solve this problem for the INITIAL_API_KEY env var and other two env vars that are read in the entry point and are affected by this, even if nobody noticed yet.

@github-project-automation github-project-automation bot moved this from In review to Done in Shlink Oct 14, 2024
@acelaya
Copy link
Member

acelaya commented Oct 14, 2024

I have just released Shlink 4.2.2. You should be able to pass INITIAL_API_KEY_FILE in that version.

@Maypul
Copy link
Author

Maypul commented Oct 14, 2024

Seems to be working according the the log, thanks!

Initializing database if needed... Success!
Updating database... Success!
Generating proxies... Success!
Clearing entities cache... Success!
Downloading GeoLite2 db file... Success!
Creating first API key... Success!

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

Successfully merging a pull request may close this issue.

2 participants