You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bug Description
Vultr-CLI fails when executed by systemd, which runs by default at a system context. The system context does not define $XDG_CONFIG_HOME or $HOME. Vultr-CLI checks for these environment variables and fails if they are undefined before checking --config and $VULTR_API_KEY. Vultr-CLI's order of configuration evaluation causes Vultr-CLI to fail even when a configuration file is passed as an argument (test 1) and when the API key is exported to the executing environment (test 2). The issue does not occur when instructing systemd to execute at a user context (see the addition of User=root in Test 3's systemd service file).
Test Environment
Operating System: Debian 12 x86_64
Vultr-CLI binary vultr-cli_v3.4.0_linux_amd64 installed to /usr/local/sbin/vultr-cli with owner/group root:root and permissions 700
Vultr-CLI configuration file placed at /etc/vultr-cli.yaml with contents api-key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX with owner/group root:root and permissions 600(for test 1)
systemd service file /etc/systemd/system/vultr-cli-test-1.service:
Test 1 Execution $ systemctl start vultr-cli-test-1
Test 1 Results
$ systemctl status vultr-cli-test-1
× vultr-cli-test-1.service - Vultr CLI Test 1
Loaded: loaded (/etc/systemd/system/vultr-cli-test-1.service; disabled; preset: enabled)
Active: failed (Result: exit-code) since Mon 2024-11-18 18:55:14 UTC; 11s ago
Duration: 17ms
Process: 2632 ExecStart=bash -c vultr-cli account --config /etc/vultr-cli.yaml (code=exited, status=1/FAILURE)
Main PID: 2632 (code=exited, status=1/FAILURE)
CPU: 9ms
Nov 18 18:55:14 vultr systemd[1]: Started vultr-cli-test-1.service - Vultr CLI Test 1.
Nov 18 18:55:14 vultr vultr-cli-test-2[2632]: Unable to determine default user config directory : neither $XDG_CONFIG_HOME nor $HOME are defined
Nov 18 18:55:14 vultr systemd[1]: vultr-cli-test-1.service: Main process exited, code=exited, status=1/FAILURE
Nov 18 18:55:14 vultr systemd[1]: vultr-cli-test-1.service: Failed with result 'exit-code'.
Test 2 Execution $ systemctl start vultr-cli-test-2
Test 2 Results
$ systemctl status vultr-cli-test-2
× vultr-cli-test-2.service - Vultr CLI Test 2
Loaded: loaded (/etc/systemd/system/vultr-cli-test-2.service; disabled; preset: enabled)
Active: failed (Result: exit-code) since Mon 2024-11-18 18:52:52 UTC; 44s ago
Duration: 8ms
Process: 2620 ExecStart=bash -c export VULTR_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX; vultr-cli account (code=exited, status=1/FAILURE)
Main PID: 2620 (code=exited, status=1/FAILURE)
CPU: 6ms
Nov 18 18:52:52 vultr systemd[1]: Started vultr-cli-test-2.service - Vultr CLI Test 2.
Nov 18 18:52:52 vultr vultr-cli-test-1[2620]: Unable to determine default user config directory : neither $XDG_CONFIG_HOME nor $HOME are defined
Nov 18 18:52:52 vultr systemd[1]: vultr-cli-test-2.service: Main process exited, code=exited, status=1/FAILURE
Nov 18 18:52:52 vultr systemd[1]: vultr-cli-test-2.service: Failed with result 'exit-code'.
Test 3 Execution $ systemctl start vultr-cli-test-3
Test 3 Results
$ systemctl status vultr-cli-test-3
○ vultr-cli-test-3.service - Vultr CLI Test 3
Loaded: loaded (/etc/systemd/system/vultr-cli-test-3.service; disabled; preset: enabled)
Active: inactive (dead)
Nov 18 19:21:52 vultr systemd[1]: Started vultr-cli-test-3.service - Vultr CLI Test 3.
Nov 18 19:21:53 vultr vultr-cli-test-3[3020]: [REDACTED]
Nov 18 19:21:53 vultr vultr-cli-test-3[3020]: [REDACTED]
Nov 18 19:21:53 vultr systemd[1]: vultr-cli-test-3.service: Deactivated successfully.
Suggested Revision
Changing Vultr-CLI's order of configuration evaluation to something like the following would resolve the issue:
If the --config flag is set, use the defined path to set the API key.
If $VULTR_API_KEY is defined in the environment, use its value to set the API key.
alexgmathews
changed the title
[BUG] Incorrect configuration order evaluation causes CLI to fail when executed by systemd in system context
[BUG] CLI fails in system context because of missing local environment variables, despite passing an explicit configuration path
Nov 24, 2024
alexgmathews
changed the title
[BUG] CLI fails in system context because of missing local environment variables, despite passing an explicit configuration path
[BUG] CLI fails in system context because of missing local environment variables, despite passing explicit configuration
Nov 24, 2024
Bug Description
Vultr-CLI fails when executed by systemd, which runs by default at a system context. The system context does not define
$XDG_CONFIG_HOME
or$HOME
. Vultr-CLI checks for these environment variables and fails if they are undefined before checking--config
and$VULTR_API_KEY
. Vultr-CLI's order of configuration evaluation causes Vultr-CLI to fail even when a configuration file is passed as an argument (test 1) and when the API key is exported to the executing environment (test 2). The issue does not occur when instructing systemd to execute at a user context (see the addition ofUser=root
in Test 3's systemd service file).Test Environment
Operating System: Debian 12 x86_64
Vultr-CLI binary vultr-cli_v3.4.0_linux_amd64 installed to
/usr/local/sbin/vultr-cli
with owner/grouproot:root
and permissions700
Vultr-CLI configuration file placed at
/etc/vultr-cli.yaml
with contentsapi-key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
with owner/grouproot:root
and permissions600
(for test 1)systemd service file
/etc/systemd/system/vultr-cli-test-1.service
:/etc/systemd/system/vultr-cli-test-2.service
:/etc/systemd/system/vultr-cli-test-3.service
:Test 1 Execution
$ systemctl start vultr-cli-test-1
Test 1 Results
Test 2 Execution
$ systemctl start vultr-cli-test-2
Test 2 Results
Test 3 Execution
$ systemctl start vultr-cli-test-3
Test 3 Results
Suggested Revision
Changing Vultr-CLI's order of configuration evaluation to something like the following would resolve the issue:
--config
flag is set, use the defined path to set the API key.$VULTR_API_KEY
is defined in the environment, use its value to set the API key.$XDG_CONFIG_HOME
is defined in the environment. If it is, test if the file path per [Feature] - Use XDG_CONFIG_HOME to store config file #478 exists. If it does, use its value to set the API key.$HOME
is defined in the environment. If it is, test if the file$HOME/.vultr-cli.yaml
exists. If it does, use its value to set the API key.The text was updated successfully, but these errors were encountered: