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

Fixes #12959: Add direct token auth to the auth_modes for the Vault plugin #66

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions vault/share/plugins/vault/20_cfe_basics/vault_lib.cf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# "server_addr": "YOUR_VAULT_SERVER",
# "auth":
# {
# "mode": "userpass",
# "userpass":
# {
# "user": "USER",
Expand All @@ -30,7 +31,7 @@
# }
# }
#
# The auth field can contain one field for each auth mode, with the latter as key name.
# The auth field can contain one field for each auth mode, with the latter as key name. It needs a "mode" field to determine which one to use.

bundle agent vault_fetch_config()
{
Expand All @@ -39,31 +40,37 @@ bundle agent vault_fetch_config()
"vault.config" data => readjson("${config_path}");
}

bundle agent vault_get_token(auth_mode)
bundle agent vault_get_token()
{
vars:
"class_prefix" string => canonify("vault_get_token${auth_mode}");

pass1::
"vault.server_addr" string => "${vault.config[server_addr]}";

"vault.auth_mode" string => "${vault.config[auth][mode]}";

pass2.mode_token.vault_reachable::
"vault.auth_token" string => "${vault.config[auth][token]}";

pass2.mode_userpass.vault_reachable::
"vault_apicall_output" string => execresult("/usr/bin/curl -s --request POST --data '{\"password\": \"${vault.config[auth][userpass][password]}\"}' ${vault.server_addr}/v1/auth/userpass/login/${vault.config[auth][userpass][user]}", "noshell");

"data_output" data => "${vault_apicall_output}";

pass2.vault_reachable::
"vault.auth_token" string => "${data_output[auth][client_token]}",
ifvarclass => isvariable("data_output[auth][client_token]");


"vault.auth_token" string => "${vault.config[auth][token]}",
ifvarclass => "direct_token_correct";

classes:
pass1::
pass2::
# We need this to determinate whether an auth error is due to bad credentials or the Vault server being unreachable
"vault_reachable" expression => returnszero("/usr/bin/curl -s ${vault.server_addr}", "noshell");

# What auth mode are we using
"mode_userpass" expression => strcmp("${auth_mode}", "userpass");

"mode_userpass" expression => strcmp("${vault.auth_mode}", "userpass");
"mode_token" expression => strcmp("${vault.auth_mode}", "token");

any::
"pass3" expression => "pass2";
"pass2" expression => "pass1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ bundle agent variable_from_vault(variable_prefix, variable_name, path)

methods:
pass1::
"Auth" usebundle => vault_get_token("userpass"),
"Auth" usebundle => vault_get_token(),
ifvarclass => not(isvariable("vault.auth_token"));

pass3.variable_defined::
Expand Down