trek10inc / awsume

A utility for easily assuming AWS IAM roles from the command line.
https://awsu.me
MIT License
487 stars 90 forks source link

No output when running some commands #131

Open mancuss opened 3 years ago

mancuss commented 3 years ago

Hello,

Love the app, it really makes my life easier! I have a freshly installed Windows, AWSCLIV2, python 3.9.1 and AWSUME 4.5.0

I have copied .aws/credentials and .aws/config files from the old machine, so I know they work, or at least worked on awsume 4.4.1

credencials file:

[default]
aws_access_key_id = yyyz
aws_secret_access_key = yyy

[cli]
aws_access_key_id = xxxy
aws_secret_access_key = xxx

config file:

[default]
region = eu-west-1
output = json

[profile edi-prod]
region = eu-west-1
output = json
role_arn = arn:aws:iam::xxx
mfa_serial = arn:aws:iam::xxx
source_profile = cli

[profile walton]
region = eu-west-1
output = json
role_arn = arn:aws:iam::xxx
mfa_serial = arn:aws:iam::xxx
source_profile = cli

[profile shoot]
region = eu-west-1
output = json
role_arn = arn:aws:iam::xxx
mfa_serial = arn:aws:iam::xxx
source_profile = cli

[profile sandbox]
region = eu-west-1
output = json
role_arn = arn:aws:iam::xxx
mfa_serial = arn:aws:iam::xxx
source_profile = cli

When I run some commands I get no output, and it is kind of inconsistent, for example:

λ awsume -h

λ awsume -he
usage: awsume [-h] [-v] [-o output_profile] [--clean] [-r] [-s] [-u] [-a] [-k]
              [-l [more]] [--refresh-autocomplete] [--role-arn role_arn]
              [--principal-arn principal_arn] [--source-profile source_profile]
              [--external-id external_id] [--mfa-token mfa_token]
              [--region region] [--session-name session_name]
              [--role-duration role_duration]
              [--with-saml | --with-web-identity] [--json json]
              [--credentials-file credentials_file] [--config-file config_file]
              [--config [option ...]] [--list-plugins] [--info] [--debug]
              [profile_name]
awsume: error: argument -h/--help: ignored explicit argument 'e'

Getting similar issue with -l or --list-profiles

Example with debug:

C:\Users\lukasz\.aws
λ awsume -l
C:\Users\lukasz\.aws
λ awsume --list-profiles
C:\Users\lukasz\.aws
λ awsume --list-profiles --debug
[2021-02-15 15:39:57,465] main.py:main : [DEBUG] Debug logs are visible
[2021-02-15 15:39:57,465] main.py:main : [DEBUG] Executing awsume
[2021-02-15 15:39:57,465] app.py:__init__ : [DEBUG] Initalizing app
[2021-02-15 15:39:57,466] app.py:get_plugin_manager : [DEBUG] Creating plugin manager
[2021-02-15 15:39:57,466] app.py:get_plugin_manager : [DEBUG] Loading plugins
[2021-02-15 15:39:57,473] app.py:parse_args : [DEBUG] Gathering arguments
[2021-02-15 15:39:57,474] default_plugins.py:add_arguments : [INFO] Adding arguments
[2021-02-15 15:39:57,474] app.py:parse_args : [DEBUG] Parsing arguments
[2021-02-15 15:39:57,475] app.py:parse_args : [DEBUG] Handling arguments
[2021-02-15 15:39:57,475] default_plugins.py:post_add_arguments : [DEBUG] Post add arguments
[2021-02-15 15:39:57,475] default_plugins.py:post_add_arguments : [DEBUG] {"version": false, "output_profile": null, "clean": false, "profile_name": null, "force_refresh": false, "show_commands": false, "unset_variables": false, "auto_refresh": false, "kill": false, "list_profiles": "list", "refresh_autocomplete": false, "role_arn": null, "principal_arn": null, "source_profile": null, "external_id": null, "mfa_token": null, "region": null, "session_name": null, "role_duration": null, "with_saml": false, "with_web_identity": false, "json": null, "credentials_file": null, "config_file": null, "config": null, "list_plugins": false, "info": false, "debug": true}
[2021-02-15 15:39:57,475] default_plugins.py:post_add_arguments : [DEBUG] No profile name passed, target profile name will be "default"
[2021-02-15 15:39:57,475] app.py:get_profiles : [DEBUG] Gathering profiles
[2021-02-15 15:39:57,476] default_plugins.py:collect_aws_profiles : [INFO] Collecting AWS profiles
[2021-02-15 15:39:57,476] default_plugins.py:collect_aws_profiles : [DEBUG] Collected 6 profiles
[2021-02-15 15:39:57,477] default_plugins.py:post_collect_aws_profiles : [INFO] Post collect AWS profiles
[2021-02-15 15:39:57,477] default_plugins.py:post_collect_aws_profiles : [DEBUG] Listing profiles
[2021-02-15 15:39:57,477] profile.py:get_account_id : [INFO] Getting account ID from profile: {
  "aws_access_key_id": "SECRET",
  "aws_secret_access_key": "SECRET"
}
[2021-02-15 15:39:57,477] profile.py:get_account_id : [INFO] Getting account ID from profile: {
  "aws_access_key_id": "SECRET",
  "aws_secret_access_key": "SECRET",
  "region": "eu-west-1",
  "output": "json"
}
[2021-02-15 15:39:57,477] profile.py:get_account_id : [INFO] Getting account ID from profile: {
  "region": "eu-west-1",
  "output": "json",
  "role_arn": "xxx",
  "mfa_serial": "xxx",
  "source_profile": "cli"
}
[2021-02-15 15:39:57,478] profile.py:get_account_id : [INFO] Getting account ID from profile: {
  "region": "eu-west-1",
  "output": "json",
  "role_arn": "xxx",
  "mfa_serial": "xxx",
  "source_profile": "cli"
}
[2021-02-15 15:39:57,478] profile.py:get_account_id : [INFO] Getting account ID from profile: {
  "region": "eu-west-1",
  "output": "json",
  "role_arn": "xxx",
  "mfa_serial": "xxx",
  "source_profile": "cli"
}
[2021-02-15 15:39:57,478] profile.py:get_account_id : [INFO] Getting account ID from profile: {
  "region": "eu-west-1",
  "output": "json",
  "role_arn": "xxx",
  "mfa_serial": "xxx",
  "source_profile": "cli"
}
[2021-02-15 15:39:57,479] app.py:run : [DEBUG]
Traceback (most recent call last):
  File "C:\Users\lukasz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\awsume\awsumepy\app.py", line 262, in run
    profiles = self.get_profiles(args)
  File "C:\Users\lukasz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\awsume\awsumepy\app.py", line 107, in get_profiles
    self.plugin_manager.hook.post_collect_aws_profiles(
  File "C:\Users\lukasz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pluggy\hooks.py", line 286, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "C:\Users\lukasz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pluggy\manager.py", line 93, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "C:\Users\lukasz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pluggy\manager.py", line 84, in <lambda>
    self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
  File "C:\Users\lukasz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pluggy\callers.py", line 208, in _multicall
    return outcome.get_result()
  File "C:\Users\lukasz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pluggy\callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "C:\Users\lukasz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pluggy\callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "C:\Users\lukasz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\awsume\awsumepy\default_plugins.py", line 300, in post_collect_aws_profiles
    raise exceptions.EarlyExit()
awsume.awsumepy.lib.exceptions.EarlyExit: Early exit exception, nothing left to do
[2021-02-15 15:39:57,516] app.py:run : [DEBUG] EarlyExit exception raised, no more work to do

EDIT: it seems to be outputting awsume -l to a file temp.txt in the current directory

Any idea what I'm doing wrong/How to fix it? Thanks! Lukasz

mbarneyjr commented 3 years ago

We recently pushed 4.5.1 which did clean up a few shell script bugs, could you update and let me know if you hit these issues still?

The temp.txt is created so it can store the output of awsumepy so awsume.bat can store it in a variable and handle the output properly, from there it should be dumping the list to stdout later on in the script.

mbarneyjr commented 3 years ago

Also note, I've experienced issues where pip install --upgrade and pipx upgrade (depending on how you installed awsume) don't actually update the shell scripts, so if you're still experiencing issues, one thing I've done to ensure the shell scripts are updated is to uninstall and then reinstall awsume

mattelacchiato commented 2 years ago

I'm on the latest version (4.5.3) and have the same issue:

$ awsume MY_PROFILE
Session token will expire at 2021-11-16 22:58:50
[MY_PROFILE] Role credentials will expire 2021-11-16 12:38:21

$ awsume -l

$ awsume -h

But the commands for awsumepy do work...

mattelacchiato commented 2 years ago

This is the output for

$ awsume t-staging-developers -s --debug
[2021-11-16 14:17:52,548] main.py:main : [DEBUG] Debug logs are visible
[2021-11-16 14:17:52,548] main.py:main : [DEBUG] Executing awsume
[2021-11-16 14:17:52,548] app.py:__init__ : [DEBUG] Initalizing app
[2021-11-16 14:17:52,548] app.py:get_plugin_manager : [DEBUG] Creating plugin manager
[2021-11-16 14:17:52,549] app.py:get_plugin_manager : [DEBUG] Loading plugins
[2021-11-16 14:17:52,552] app.py:parse_args : [DEBUG] Gathering arguments
[2021-11-16 14:17:52,552] default_plugins.py:add_arguments : [INFO] Adding arguments
[2021-11-16 14:17:52,553] app.py:parse_args : [DEBUG] Parsing arguments
[2021-11-16 14:17:52,553] app.py:parse_args : [DEBUG] Handling arguments
[2021-11-16 14:17:52,553] default_plugins.py:post_add_arguments : [DEBUG] Post add arguments
[2021-11-16 14:17:52,553] default_plugins.py:post_add_arguments : [DEBUG] {"version": false, "output_profile": null, "clean": false, "profile_name": "t-staging-developers", "force_refresh": false, "show_commands": true, "unset_variables": false, "auto_refresh": false, "kill": false, "list_profiles": null, "refresh_autocomplete": false, "role_arn": null, "principal_arn": null, "source_profile": null, "external_id": null, "mfa_token": null, "region": null, "session_name": null, "role_duration": null, "with_saml": false, "with_web_identity": false, "json": null, "credentials_file": null, "config_file": null, "config": null, "list_plugins": false, "info": false, "debug": true}
[2021-11-16 14:17:52,553] app.py:get_profiles : [DEBUG] Gathering profiles
[2021-11-16 14:17:52,554] default_plugins.py:collect_aws_profiles : [INFO] Collecting AWS profiles
[2021-11-16 14:17:52,554] default_plugins.py:collect_aws_profiles : [DEBUG] Collected 4 profiles
[2021-11-16 14:17:52,554] default_plugins.py:post_collect_aws_profiles : [INFO] Post collect AWS profiles
[2021-11-16 14:17:52,554] app.py:get_credentials : [DEBUG] Getting credentials
[2021-11-16 14:17:52,554] app.py:get_credentials : [DEBUG] Pulling credentials from default awsume flow
[2021-11-16 14:17:52,554] profile.py:get_role_chain : [DEBUG] Getting role chain for [t-staging-developers]
[2021-11-16 14:17:52,554] profile.py:get_role_chain : [DEBUG] target profile: {"role_arn": "arn:aws:iam::123:role/Developers", "source_profile": "t-base", "mfa_serial": "arn:aws:iam::4567:mfa/matthias.brandt"}
[2021-11-16 14:17:52,554] profile.py:get_role_chain : [DEBUG] target profile: {"aws_access_key_id": "SECRET", "aws_secret_access_key": "SECRET", "region": "eu-central-1", "mfa_serial": "arn:aws:iam::4567:mfa/matthias.brandt"}
[2021-11-16 14:17:52,554] default_plugins.py:get_credentials : [DEBUG] Role chain: ['t-base', 't-staging-developers']
[2021-11-16 14:17:52,554] default_plugins.py:get_credentials_handler : [INFO] Getting credentials: t-base
[2021-11-16 14:17:52,555] profile.py:validate_profile : [DEBUG] Validating profile
[2021-11-16 14:17:52,555] default_plugins.py:get_session_token_credentials : [INFO] Getting session token credentials
[2021-11-16 14:17:52,555] cache.py:read_aws_cache : [DEBUG] Cache file path: /home/mb/.awsume/cache/aws-credentials-SECRET
[2021-11-16 14:17:52,555] cache.py:read_aws_cache : [DEBUG] Cache file found
[2021-11-16 14:17:52,556] cache.py:valid_cache_session : [DEBUG] Cache session is valid
[2021-11-16 14:17:52,556] aws.py:get_session_token : [DEBUG] Using cache session
Session token will expire at 2021-11-16 23:41:23
[2021-11-16 14:17:52,557] default_plugins.py:get_credentials_handler : [INFO] Getting credentials: t-staging-developers
[2021-11-16 14:17:52,557] profile.py:validate_profile : [DEBUG] Validating profile
[2021-11-16 14:17:52,557] default_plugins.py:get_credentials_handler : [DEBUG] assume_role call needed
[2021-11-16 14:17:52,557] default_plugins.py:get_assume_role_credentials : [INFO] Getting assume role credentials
[2021-11-16 14:17:52,557] aws.py:assume_role : [DEBUG] Assuming role: arn:aws:iam::789:role/Developers
[2021-11-16 14:17:52,557] aws.py:assume_role : [DEBUG] Session name: t-staging-developers
[2021-11-16 14:17:52,582] aws.py:assume_role : [DEBUG] Assuming role now
[2021-11-16 14:17:52,728] aws.py:assume_role : [DEBUG] Received role credentials
[2021-11-16 14:17:52,729] aws.py:assume_role : [DEBUG] Role credentials received
[t-staging-developers] Role credentials will expire 2021-11-16 15:17:52
[2021-11-16 14:17:52,734] app.py:export_data : [DEBUG] Exporting data

That's it. No further outputs...

mattelacchiato commented 2 years ago

Additionally the -s option does nothing: awsume -s t-staging-developers

When running the executable directly, I can see the output:

$ /home/mb/.local/bin/awsume -s t-staging-developers
Warning: the awsume shell script is not being sourced, please use awsume-configure to install the alias
Session token will expire at 2022-02-17 02:25:53
[t-staging-developers] Role credentials will expire 2022-02-16 15:27:06
export AWS_ACCESS_KEY_ID=xxx
export AWS_SECRET_ACCESS_KEY=xxx
export AWS_SESSION_TOKEN=xxx
export AWS_REGION=eu-central-1
export AWS_DEFAULT_REGION=eu-central-1
export AWSUME_PROFILE=t-staging-developers
export AWSUME_EXPIRATION=2022-02-16T15:27:06
/home/mb/.local/bin/awsume: line 183: return: can only `return' from a function or sourced script

Still on version 4.5.3

mattelacchiato commented 2 years ago

one thing I've done to ensure the shell scripts are updated is to uninstall and then reinstall awsume

Did that, but sadly it didn't help for me. Additionally, I've removed every file containing "awsume" in its name...

mtskillman commented 9 months ago

unable to replicate on PowerShell 7.3.6, with awsume 4.5.0 unable to replicate on PowerShell 7.3.6, with awsume 4.5.3

leaving this issue open as this warrants further investigation.