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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment variable interpreted as a string #309

Open
luthes opened this issue Apr 5, 2022 · 3 comments
Open

Environment variable interpreted as a string #309

luthes opened this issue Apr 5, 2022 · 3 comments

Comments

@luthes
Copy link

luthes commented Apr 5, 2022

馃悰 Bug Report

I'm using AWS ECS, which gets it's IAM credentials the same way an EC2 instnace would. Setting the FOUNDRY_AWS_CONFIG environment variable to "true" causes it to be read as a string, and it subsequently gets added to the path: The configured awsConfig path /data/Config/true does not exist or is not accessible.. This should not happen, as ECS gets it's IAM credentials the same way that EC2 does.

To Reproduce

Steps to reproduce the behavior:

Set environment variable as "true", get error.

Expected behavior

I expected it to not use any file, or environment variables and use the attached IAM policy instead. I'm not sure if the entrypoint, or later javascript is expected that to be a bool without quotes, but perhaps there should be a check in there to see if the string evaluates to true or false.

Any helpful log output

Please run this command:

docker inspect --format='{{range $k, $v := .Config.Labels}}
    {{- printf "%s = \"%s\"\n" $k $v -}} {{end}}' \
    felddy/foundryvtt:latest

Paste the results here:

Hopefully this is legibly formatted

# ECS Log Output
[info] Application Options:
    {
    "port": 30000,
    "upnp": false,
    "fullscreen": false,
    "hostname": "my.foundryurl.com",
    "localHostname": null,
    "routePrefix": null,
    "sslCert": null,
    "sslKey": null,
    "awsConfig": null,
    "dataPath": "/data",
    "passwordSalt": null,
    "proxySSL": false,
    }
[info] Foundry Virtual Tabletop - Version 9
[info] Loading data from user directory - /data
[error] The configured awsConfig path /data/Config/true does not exist or is not accessible.

Run the container with CONTAINER_VERBOSE set to true,and paste any useful
log output here:

@felddy felddy added the bug label Apr 5, 2022
@felddy felddy self-assigned this Apr 5, 2022
@felddy
Copy link
Owner

felddy commented Apr 5, 2022

Hmmm. That does sound broken. Thanks for the bug report.

It's weird that your application options is logged as: "awsConfig": null, although you can clearly see the error below.

I haven't had a chance to play with the container with ECS, EKS, or Fargate yet so this might take me a bit of time.

I'm just going to paste some context below... I'm not going to be able to dig into it tonight, but I'll try to take a look tomorrow.

awsConfig: process.env.FOUNDRY_AWS_CONFIG || null,

From: https://github.com/felddy/foundryvtt-docker#optional

Name Purpose Default
FOUNDRY_AWS_CONFIG An absolute or relative path that points to the awsConfig.json or true for AWS environment variable credentials evaluation usage. null

@luthes
Copy link
Author

luthes commented Apr 5, 2022

No worries. I'll play around with a bit, and see if I can't figure it out and get a PR going. Thanks for the reply!

@luthes
Copy link
Author

luthes commented Apr 5, 2022

I'm guessing this is a type coercion issue, and I've never done anything in JavaScript but this seems to fix it:

function checkAwsConfig(
  AWS_CONFIG: string | any
) : boolean | string {
  if (!AWS_CONFIG) {
    return AWS_CONFIG;
  } else if (AWS_CONFIG.toLowerCase() === 'true') {
    return true;
  } else if (AWS_CONFIG.toLowerCase() === 'false') {
    return false;
  } else {
    return AWS_CONFIG;
  }
}

if (process.env.FOUNDRY_DEMO_CONFIG) {
  parsedDemoConfig = JSON.parse(process.env.FOUNDRY_DEMO_CONFIG);
}

let options: object = {
  awsConfig: checkAwsConfig(process.env.FOUNDRY_AWS_CONFIG) || null,

Guessing you'll want something cleaner in a PR, so I won't open one.

@felddy felddy changed the title Environment variable interpreted as a strong Environment variable interpreted as a string Apr 26, 2022
@github-actions github-actions bot removed the bug label Jun 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants