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

Unable to create private endpoints in CLI using bash terminal #13687

Closed
lchave opened this issue May 26, 2020 · 12 comments
Closed

Unable to create private endpoints in CLI using bash terminal #13687

lchave opened this issue May 26, 2020 · 12 comments

Comments

@lchave
Copy link

lchave commented May 26, 2020

This is autogenerated. Please review and update as needed.

Describe the bug

Command Name
az network private-endpoint create

Errors:

request failed: Error occurred in request., RetryError: HTTPSConnectionPool(host='management.azure.com', port=443): Max retries exceeded with url: /subscriptions/b526aa26-e5c4-4583-90a3-6d0a4663242a/resourceGroups/rg-eu2-network/providers/Microsoft.Network/privateEndpoints/pe-eu2-iris-dev-006?api-version=2020-03-01 (Caused by ResponseError('too many 500 error responses',))

To Reproduce:

Steps to reproduce the behavior. Note that argument values have been redacted, as they may contain sensitive information.

  • Put any pre-requisite steps here...
  • az network private-endpoint create --name {} --resource-group {} --vnet-name {} --subnet {} --location {} --private-connection-resource-id {} --group-id {} --connection-name {} --tags {}

Expected Behavior

Environment Summary

Windows-10-10.0.17763-SP0
Python 3.6.6
Installer: 

azure-cli 2.6.0

Extensions:
interactive 0.4.4

Additional Context

@ghost ghost added needs-triage This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels May 26, 2020
@yungezz yungezz added Network az network vnet/lb/nic/dns/etc... and removed question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels May 26, 2020
@ghost ghost removed the needs-triage This is a new issue that needs to be triaged to the appropriate team. label May 26, 2020
@yungezz yungezz added this to the S170 milestone May 26, 2020
@yungezz
Copy link
Member

yungezz commented May 26, 2020

hi @myronfanqiu, could you pls have a look?

@yonzhan
Copy link
Collaborator

yonzhan commented May 26, 2020

add to S170

@mmyyrroonn
Copy link
Contributor

@lchave Hi, Are you targeting at Private Link Service? --group-id is not needed for private link service. Or do you have any name containing ' or "? Could you run the command with --debug?

@lchave
Copy link
Author

lchave commented May 27, 2020

@myronfanqiu The group-id is just passing a variable defined in a previous step. When i run the --debug I see that the --private-connection-resource-id is sending the id with an \r at the end of it which is not added by us. The way we are getting the resource id is by running the az resource show and specifying the --query parameter to get the id. When I echo the variable defined to hold this ID it doesn't show the \r however, when calling the variable on the az network private-endpoint create it adds it. Any suggestions on this?

@mmyyrroonn
Copy link
Contributor

@lchave I see. Thanks for such useful information. @jiasli @zhoxing-ms Any idea?

@zhoxing-ms
Copy link
Contributor

Related issue: #13573

@zhoxing-ms
Copy link
Contributor

zhoxing-ms commented May 28, 2020

@lchave This problem seems to be related to Windows style newline characters, this can be caused by editing a file in Windows and trying to run it on a non-Windows system.
there is a similar problems here: link

Bash expects that end-of-line in a script is always and only a newline \n character, Unix-style, not a carriage return-newline combination \r\n like you normally see on Windows. Bash thinks the \r character is just an ordinary character at the end of the string.
So could you try to execute the command dos2unix for the scripts executed?

@jiasli
Copy link
Member

jiasli commented May 28, 2020

Hello @lchave,

  1. May I know the shell you are using, Mintty, Cygwin, MinGW? We haven't heard of this issue before with PowerShell on Windows or Bash on Linux. I doubt the output is not parsed correctly by the shell.
  2. Could you share a full code snippet so that we can repro?

@lchave
Copy link
Author

lchave commented May 28, 2020

@jiasli I've tried on WSL, Bash & Git Bash terminals from Visual Studio on Windows. As per the code, if you can share your MS email I can send the code to reproduce it.

@zhoxing-ms this looks accurate, however, this command runs on files and I'm just trying to pass this variable within my code to complete deployments.

@zhoxing-ms
Copy link
Contributor

@lchave Hi, please send them to jiasli@microsoft.com and Zhou.Xing@microsoft.com, thanks~

@mmyyrroonn mmyyrroonn removed their assignment May 29, 2020
@mmyyrroonn mmyyrroonn removed the Network az network vnet/lb/nic/dns/etc... label May 29, 2020
@yonzhan yonzhan modified the milestones: S170, S171 May 31, 2020
@yonzhan yonzhan removed this from the S171 milestone Jun 20, 2020
@yonzhan yonzhan added this to the S172 milestone Jun 20, 2020
@zhoxing-ms
Copy link
Contributor

zhoxing-ms commented Jun 28, 2020

I have reproduced this problem in the WSL environment and identified the root cause:
The newline character in WSL is LF and the newline character in windows is CRLF. Therefore, when a script written under Windows is used in WSL, only \n in the newline character \r\n of CRLF is recognized as the newline character of LF, while \r is recognized as plain text.

For example:

  1. Write a bash script in Windows, which is in CRLF format:
    The script content:
group_name=$(az group show -n zhoxing-test --query name)
echo $group_name
az group create -l westus --debug -n $group_name
  1. Execute the script in the WSL environment
root@DESKTOP-S8GCCTE:/mnt/c/Users/zhoxing.FAREAST/Desktop# file test.sh
test.sh: ASCII text, with CRLF line terminators

root@DESKTOP-S8GCCTE:/mnt/c/Users/zhoxing.FAREAST/Desktop# bash test.sh
"zhoxing-test"
Command arguments: ['group', 'create', '-l', 'westus', '--debug', '-n', '"zhoxing-test"\r\r']

At this point, the value of group_name is added with \r due to incompatibility between WSL and windows newline character.

  1. Convert the file format from CRLF to LF and then execute the script
root@DESKTOP-S8GCCTE:/mnt/c/Users/zhoxing.FAREAST/Desktop# dos2unix test.sh
dos2unix: converting file test.sh to Unix format...

root@DESKTOP-S8GCCTE:/mnt/c/Users/zhoxing.FAREAST/Desktop# file test.sh
test.sh: ASCII text

root@DESKTOP-S8GCCTE:/mnt/c/Users/zhoxing.FAREAST/Desktop# bash test.sh
"zhoxing-test"
Command arguments: ['group', 'create', '-l', 'westus', '--debug', '-n', '"zhoxing-test"']

Problem solving after the file format becomes LF.

@lchave The same is true even if the value of the variable is not written directly in the file but is returned from a query (as the example I provided). So when using CRLF files in Unix and Unix-like Systems (including WSL), you need to convert the file to LF (you can use the command dos2unix)

For more information, please refer to: click

@zhoxing-ms
Copy link
Contributor

Because there is no reply to this question for a long time, I will close it temporarily. If you have any questions, please feel free to let us know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants