-
Notifications
You must be signed in to change notification settings - Fork 817
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
Using aws-vault with WSL #683
Comments
@Majsvaffla in the above scenario, are you using WSL1 or WSL2? I can't get aws-vault.exe to execute within WSL without doing I'm limited to WSL1 due to company restricted windows version level. |
I’ve only used the wrapper in WSL2 but I think it should work in both versions. You should be able to execute aws-vault.exe just like cmd.exe. You need to put it in /usr/local/bin or some other place that’s on your $PATH in WSL. |
Working for me with WSL2, thanks for sharing! |
Thanks @Majsvaffla, feel free to submit this contrib script in a PR |
I'm glad to see that I'm not the only one who had issues with it 😄 Short version# All the commands are executed in a WSL2 terminal
# Download
AWS_VAULT_VERSION="v6.3.1" && \
wget -O aws-vault "https://github.com/99designs/aws-vault/releases/download/${AWS_VAULT_VERSION}/aws-vault-linux-amd64"
# Install
sudo mv aws-vault /usr/local/bin/ && \
sudo chmod +x /usr/local/bin/aws-vault
# Verify
aws-vault --version
# Output:
# v6.3.1
# Install the pass backend and update gnupg, which encrypts passwords
sudo apt-get update && sudo apt-get install -y pass gnupg
# Make sure your terminal windows is large enough
# Generate a key with gpg (gnupg)
gpg --gen-key
# Follow the prompts ...
# Create a storage key in pass from the previously generated public (pub) key
MY_PUBLIC_KEY="844E426A53A64C2A916CBD1F522014D5FDBF6E3D"
pass init "$MY_PUBLIC_KEY"
# All set, let's test
# Create an aws-vault profile
MY_PROFILE_NAME="staging-admin"
aws-vault add "$MY_PROFILE_NAME"
# Invoke some command with the AWS CLI using the previously created profile
aws-vault exec staging-admin -- aws s3 ls
# outputs a list of buckets if any Long VersionExpand/CollapseAll the commands are executed in WSL2. Download and "install" aws-vault # Download
AWS_VAULT_VERSION="v6.3.1" && \
wget -O aws-vault "https://github.com/99designs/aws-vault/releases/download/${AWS_VAULT_VERSION}/aws-vault-linux-amd64"
# Install
sudo mv aws-vault /usr/local/bin/ && \
sudo chmod +x /usr/local/bin/aws-vault
# Verify
aws-vault --version
# Output:
# v6.3.1 Install the pass backend for aws-vault. This is where we'll store the encrypted AWS credentials. We also need gnupg (gpg), which is the encryption tool that sudo apt-get update && sudo apt-get install -y pass gnupg Create a storage key with IMPORTANT: Make sure your terminal window is large enough; otherwise, you won't be prompted to set a passphrase, and the whole process will fail. gpg --gen-key
# Follow the prompts ... Valid output public and secret key created and signed.
pub rsa3072 2021-04-22 [SC] [expires: 2023-04-22]
844E426A53A64C2A916CBD1F522014D5FDBF6E3D
uid Meir Gabay <[email protected]>
sub rsa3072 2021-04-22 [E] [expires: 2023-04-22] Initialize a "key-store" for NOTE: A public key is used for encryption, "anyone" can have it; for decryption, you need a private/secret key—this why it's so important to keep the private key safe. pass init "844E426A53A64C2A916CBD1F522014D5FDBF6E3D"
# You should be prompted to insert the passphrase that was set during the `gpg --gen-key` process Valid output Password store initialized for 844E426A53A64C2A916CBD1F522014D5FDBF6E3D
gpg: checking the trustdb
gpg: marginals needed: 3 completes needed: 1 trust model: pgp
gpg: depth: 0 valid: 3 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 3u
gpg: next trustdb check due at 2023-04-22
staging-admin: reencrypting to 24552E67E0372C6C Luckily, the default "vaulting backend" for Linux is aws-vault add staging-admin
Enter Access Key ID: AKIAABCDEFGH12345678
Enter Secret Access Key:
Added credentials to profile "staging-admin" in vault Verify aws-vault exec staging-admin -- aws s3 ls
# buckets list ... |
Thank you @unfor19 . I needed a just a couple more things to get your solution working for me: export AWS_VAULT_BACKEND=pass which I've also added to my ~/.bashrc |
Superb! $ aws-vault --help
usage: aws-vault [<flags>] <command> [<args> ...]
A vault for securely storing and accessing AWS credentials in development environments.
Flags:
--help Show context-sensitive help (also try --help-long and --help-man).
--version Show application version.
--debug Show debugging output
--backend=pass Secret backend to use [pass file] ($AWS_VAULT_BACKEND) # <--- pass is default isn't it? |
My solution to the problem works nice. |
Thanks for this. Running WSL2 Ubuntu 20.04 LTS and this works. |
This is not using exec, but it accomplishes the same thing for me. From within your running bash or similar shell, run:
You can check this using |
Just sharing for others that may have this issue, will post a separate bug for it shortly. Issue 1237: Error when executing any AWS Vault Command on 7.2.0, in WSL Ubuntu on Windows 11 Not working with AWS Vault 7.2.0 I get the following error when trying to use any aws-vault command (example using the add command) ~$ aws-vault add "test" |
Me and my colleagues recently started using aws-vault and love it 😃 However, as my development environment is in WSL, I wasn't able to use the wincred backend for aws-vault at first. I'm opening this issue to find out whether there are others like me, wanting to use aws-vault from WSL, and to ask how are you using aws-vault with WSL? Would you also like to see some official support for using the wincred backend "natively" with aws-vault in WSL?
Here's what I did to get it to work:
I tried running the aws-vault.exe binary from WSL and that works for all of the sub commands that I've tried but one. It doesn't work for
aws-vault exec
since the command I wish to exec is not available from the executables point of view (in Windows).I want to share with you a Python script I wrote together with a colleague. To use it you would put in on your $PATH in WSL along with the aws-vault.exe Windows binary (instead of the real aws-vault Linux binary) and call it as it it were aws-vault. If called with the "exec" sub command it will use aws-vault.exe (with support for wincred backend) to get the environment with AWS credentials and then execute the original command in WSL using that environment. For all other sub commands it will simply forward the sub command and all other arguments to aws-vault.exe.
There are some limitations in how it accepts command line arguments. It works if all options (--backend, --prompt etc.) are put before "exec". It might and probably will crash otherwise.
The text was updated successfully, but these errors were encountered: