awstools icon indicating copy to clipboard operation
awstools copied to clipboard

Export not working

Open kinderlars opened this issue 4 years ago • 11 comments

Hi,

I have installed awstools a few days ago and I think it is a really nice solution. The problem is, the created keys are not exported to my shell. Using zsh and not sure why this is happening.

Hope you can help.

Cheers, Lars

kinderlars avatar Apr 29 '21 19:04 kinderlars

Hi @kinderlars , yes, zsh is tricky. The idea is that awstools assume prints a shell script that must be sourced into your current shell session. It is difficult to debug remotely. To reproduce I'd need:

  • In what file did you define aws_assume() function?
  • What zsh version do you use?
  • Do you use any additional plugins with zsh?

P.S. You might consider to use awscredx if you are mostly interested in the role assumption. That project has focus on role assumptions.

sam701 avatar Apr 29 '21 19:04 sam701

Hi @sam701,

thanks for the quick response. I am using zsh 5.8 (x86_64-apple-darwin19.6.0)

I defined the assume_role() function in .bash_profiles and added source /Users/lars/.bash_profile to my .zshenv file

Cheers, Lars

kinderlars avatar Apr 30 '21 08:04 kinderlars

You do not actually need a separate .bash_profile, you can define assume_role directly in .zshenv. Next please check if it's not a typo: you wrote .bash_profiles (plural) but source ../.bash_profile (singular).

What's happening when you type assume_role abc abc in your shell?

sam701 avatar Apr 30 '21 08:04 sam701

Was a typo, sorry about that. Added the aws_assume() to .zshenv now

assume_role zsh: command not found: assume_role

kinderlars avatar Apr 30 '21 08:04 kinderlars

It means .zshenv is not loaded by your shell. I suppose if you explicitly call source ~/.zshenv it will work. You should make sure you define aws_assume in a file that is sourced by your shell. Otherwise the shell is not aware of the function.

sam701 avatar Apr 30 '21 08:04 sam701

Thanks a lot for the help. :) Sadly even when sourcing, the function still does not get detected. Any other idea why this could happen?

kinderlars avatar Apr 30 '21 08:04 kinderlars

@sam701 , got the function assume_role to work. Somehow it was not able to detect my config.toml so.

aws_assume ACCOUNT ROLE 2021/04/30 11:05:45 ERROR open /Users/lars/.config/awstools/awstools.toml: no such file or directory

Had to rename the file from config.toml to awstools.toml

A new problem, now I am not able to run awstools assume anymoe :D awstools assume ACCOUNT ROLE 2021/04/30 11:13:49 ERROR open /Users/lars/.config/awstools/config.toml: no such file or directory

kinderlars avatar Apr 30 '21 09:04 kinderlars

Could you paste your assume_role shell function? And also the output of awstools assume none none?

sam701 avatar Apr 30 '21 11:04 sam701

Hi @sam701,

I removed the assume_role from my zshenv and now only using the helper script function.

function aws_assume() { config_file="${config_dir}/awstools.toml" creds_file=$(mktemp) awstools --config ${config_file} assume --export ${creds_file} $@; source ${creds_file}; rm ${creds_file} }

In addition awstools now works as intended as well. awstools assume none none 2021/05/04 15:31:58 No such account: none

Not sure what is different, but the issue can be closed, as it was on my end.

Thanks again for supporting me. :)

kinderlars avatar May 04 '21 13:05 kinderlars

@sam701 : Sorry about it, forgot that the export with awstools assume was the original problem. That is still not working, therefore I re-opened the ticket.

kinderlars avatar May 04 '21 13:05 kinderlars

Hmm, I couldn't reproduce this issue. Here is what I did:

cp ~/.config/awstools/config.toml /tmp/tt.toml
cat > /tmp/tt.sh <<EOF
function aws_assume() {
  config_file="/tmp/tt.toml"
  creds_file=\$(mktemp)
  awstools --config \${config_file} assume --export \${creds_file} \$@; source \${creds_file};
  cat \${creds_file}
  rm \${creds_file}
}
EOF
zsh --version
export SHELL=$(which zsh)
source /tmp/tt.sh
aws_assume my_account my_role

Can you try the same, obfuscate and paste the output?

sam701 avatar May 04 '21 15:05 sam701