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

Export not working #32

Open
kinderlars opened this issue Apr 29, 2021 · 11 comments
Open

Export not working #32

kinderlars opened this issue Apr 29, 2021 · 11 comments

Comments

@kinderlars
Copy link

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

@sam701
Copy link
Owner

sam701 commented Apr 29, 2021

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.

@kinderlars
Copy link
Author

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

@sam701
Copy link
Owner

sam701 commented Apr 30, 2021

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?

@kinderlars
Copy link
Author

kinderlars commented Apr 30, 2021

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

assume_role zsh: command not found: assume_role

@sam701
Copy link
Owner

sam701 commented Apr 30, 2021

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.

@kinderlars
Copy link
Author

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
Copy link
Author

kinderlars commented Apr 30, 2021

@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

@sam701
Copy link
Owner

sam701 commented Apr 30, 2021

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

@kinderlars
Copy link
Author

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 kinderlars reopened this May 4, 2021
@kinderlars
Copy link
Author

kinderlars commented May 4, 2021

@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.

@sam701
Copy link
Owner

sam701 commented May 4, 2021

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?

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

2 participants