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

No Support for Docker Secrets #42

Open
Nhimself opened this issue Nov 5, 2024 · 0 comments
Open

No Support for Docker Secrets #42

Nhimself opened this issue Nov 5, 2024 · 0 comments

Comments

@Nhimself
Copy link

Nhimself commented Nov 5, 2024

No Support for Docker Secrets

There is an issue when using Docker Compose with an Arma Reforger server, specifically when attempting to use Docker secrets for environment variables. When the GAME_PASSWORD environment variable is set to reference a Docker secret, the directory path to the secret is passed as a string, causing the password to be set as the directory path instead of the actual password stored in the secret file.

To Reproduce

Steps to reproduce the behavior:

  1. Set the GAME_PASSWORD variable to: /run/secrets/game_password
  2. Launch the game server
  3. The admin password is set as the string: /run/secrets/game_password (instead of reading the password content from the secret file)

Expected Behavior

The value in the Docker secret file should be read correctly, and the password inside that file should be set as the game server's game password, rather than using the path to the file itself.

Code to Handle Secrets

I’ve created a helper function to check whether the value is an environment variable or a secret file, and read the secret if applicable. Here’s the code I’m using to fetch the secret:

        if env_defined("GAME_PASSWORD"):
            config["game"]["password"] = get_secret_or_env_value("GAME_PASSWORD")

Function that fetches the value of an environment variable. If the value starts with '/run/secrets/', it reads the content of the file at that location (Docker secret). Otherwise, it returns the variable value directly.

def get_secret_or_env_value(env_var_name):
    value = None
    if env_defined(env_var_name):
        value = os.environ[env_var_name]
        if value.startswith('/run/secrets/'):
            try:
                with open(value, 'r') as secret_file:
                    secret_value = secret_file.read().strip()
                    print(f"{env_var_name}: '{secret_value}'")
                    value = secret_value
            except FileNotFoundError:
                print(f"Secret file '{value}' not found for {env_var_name}.")
            except Exception as e:
                print(f"Error reading secret file for {env_var_name}: '{e}'")
    return value

Additional Context

I’ve created a fork to restructure some of the steamcmd code into functions and moved things around to suit my needs, so I won’t be able to submit a pull request directly. However, feel free to check out my repo for the changes:
Nhimself Reforger Repo

Let me know if you need more details or clarification!

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

No branches or pull requests

1 participant