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

[git-bash] aws iam create-role --path /x/ error: The specified value for path is invalid. It must begin and end with / and contain only alphanumeric characters and/or / characters. #3829

Closed
rlyders opened this issue Jan 5, 2019 · 7 comments
Assignees
Labels
guidance Question that needs advice or information. third-party This issue is related to third-party libraries or applications.

Comments

@rlyders
Copy link

rlyders commented Jan 5, 2019

Running awscli in git-bash

Windows 10
$ aws --version
aws-cli/1.16.84 Python/3.7.2 Windows/10 botocore/1.12.74

$ git --version
git version 2.12.0.windows.1

I get an error when I RUN the following in git-bash on Windows:
aws iam create-role --role-name testRole --path "/service-role/" --assume-role-policy-document file://trust-relationship.json --profile=$profile

ERROR:
An error occurred (ValidationError) when calling the CreateRole operation: The specified value for path is invalid. It must begin and end with / and contain only alphanumeric characters and/or / characters.

This same error occurs whether I surround the Path parameter in quotes, single quotes, or leave it unquoted.

Debugging this error in Python (awscli/clidriver.py: main()) I find that the '--path' parameters equals 'C:/Program Files/Git/service-role/' as opposed to '/service-role/'. Apparently the path is erroneously being interpreted as a file system path and being prefixed with the file path to git.

My ugly fix to this problem is the following hack starting on existing line 490:

        call_parameters = self._build_call_parameters(
            parsed_args, self.arg_table)
        LOG.debug( '**NEW** __call__: BEFORE call_parameters=%s' % call_parameters )
        import re
        call_parameters['Path']=re.sub( r'[a-zA-Z]:.*\/Git', '', call_parameters['Path'])
        LOG.debug( '**NEW** __call__: AFTER call_parameters=%s' % call_parameters )

        event = 'calling-command.%s.%s' % (self._parent_name,
                                           self._name)

I gather this could be an error with git-bash... I've only had time to debug this up to this point. I appreciate any advice you have on this. Thanks.

Resulting debug output showing corrected Path value

2019-01-05 12:37:58,003 - MainThread - awscli.clidriver - DEBUG - **NEW** __call__: BEFORE call_parameters={'Path': 'C:/Program Files/Git/service-role/', 'RoleName': 'smsRequestLambdaRole', 'AssumeRolePolicyDocument': '{\n    "Version": "2012-10-17",\n    "Statement": [\n      {\n        "Effect": "Allow",\n        "Principal": {\n          "Service": "lambda.amazonaws.com"\n        },\n        "Action": "sts:AssumeRole"\n      }\n    ]\n}\n'}
2019-01-05 12:37:58,004 - MainThread - awscli.clidriver - DEBUG - **NEW** __call__: AFTER call_parameters={'Path': '/service-role/', 'RoleName': 'smsRequestLambdaRole', 'AssumeRolePolicyDocument': '{\n    "Version": "2012-10-17",\n    "Statement": [\n      {\n        "Effect": "Allow",\n        "Principal": {\n          "Service": "lambda.amazonaws.com"\n        },\n        "Action": "sts:AssumeRole"\n      }\n    ]\n}\n'}

trust-relationship.json:

{
    "Version": "2012-10-17",
    "Statement": [
      {
        "Effect": "Allow",
        "Principal": {
          "Service": "lambda.amazonaws.com"
        },
        "Action": "sts:AssumeRole"
      }
    ]
  }

Original error log...

2019-01-05 12:07:37,292 - MainThread - botocore.hooks - DEBUG - Event after-call.iam.CreateRole: calling handler <function json_decode_policies at 0x0000021ECA743AE8>
2019-01-05 12:07:37,293 - MainThread - awscli.clidriver - DEBUG - Exception caught in main()
Traceback (most recent call last):
  File "C:\users\richa\appdata\local\programs\python\python37\lib\site-packages\awscli\clidriver.py", line 209, in main
    return command_table[parsed_args.command](remaining, parsed_args)
  File "C:\users\richa\appdata\local\programs\python\python37\lib\site-packages\awscli\clidriver.py", line 350, in __call__
    return command_table[parsed_args.operation](remaining, parsed_globals)
  File "C:\users\richa\appdata\local\programs\python\python37\lib\site-packages\awscli\clidriver.py", line 527, in __call__
    call_parameters, parsed_globals)
  File "C:\users\richa\appdata\local\programs\python\python37\lib\site-packages\awscli\clidriver.py", line 649, in invoke
    client, operation_name, parameters, parsed_globals)
  File "C:\users\richa\appdata\local\programs\python\python37\lib\site-packages\awscli\clidriver.py", line 669, in _make_client_call
    **parameters)
  File "C:\users\richa\appdata\local\programs\python\python37\lib\site-packages\botocore\client.py", line 363, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "C:\users\richa\appdata\local\programs\python\python37\lib\site-packages\botocore\client.py", line 667, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (ValidationError) when calling the CreateRole operation: The specified value for path is invalid. It must begin and end with / and contain only alphanumeric characters and/or / characters.
2019-01-05 12:07:37,295 - MainThread - awscli.clidriver - DEBUG - Exiting with rc 255

An error occurred (ValidationError) when calling the CreateRole operation: The specified value for path is invalid. It must begin and end with / and contain only alphanumeric characters and/or / characters.`

@kyleknap
Copy link
Contributor

kyleknap commented Jan 9, 2019

@rlyders Thanks for the debug logs. That is really helpful. It looks like an issue with git-bash. Specifically, it is expanding /service-role/ to C:/Program Files/Git/service-role/. I'm not entirely sure why git-bash is expanding the value. Could you try quoting the --path value with single quotes instead of double quotes?

@kyleknap kyleknap added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Jan 9, 2019
@rlyders
Copy link
Author

rlyders commented Jan 9, 2019 via email

@no-response no-response bot removed the closing-soon This issue will automatically close in 4 days unless further comments are made. label Jan 9, 2019
@rlyders
Copy link
Author

rlyders commented Jan 9, 2019 via email

@kyleknap
Copy link
Contributor

@rlyders I was looking around online. Maybe following this comment fixes it for you? moby/moby#24029 (comment) It seems like this path expansion is a feature for the git bash shell you are using but you may be able to turn it off.

@kyleknap kyleknap added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Jan 11, 2019
@rlyders
Copy link
Author

rlyders commented Jan 11, 2019 via email

@no-response no-response bot removed the closing-soon This issue will automatically close in 4 days unless further comments are made. label Jan 11, 2019
@justnance justnance self-assigned this Jan 14, 2019
@justnance
Copy link

@rlyders - Thanks for the feedback and glad to here this is resolved.

@justnance justnance added guidance Question that needs advice or information. third-party This issue is related to third-party libraries or applications. labels Jan 14, 2019
@rlyders
Copy link
Author

rlyders commented Jan 18, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
guidance Question that needs advice or information. third-party This issue is related to third-party libraries or applications.
Projects
None yet
Development

No branches or pull requests

3 participants