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

/usr/bin/az wrapper does not account for environments where an alternate python is used (RHEL8) #28530

Closed
msftvito opened this issue Mar 8, 2024 · 7 comments
Assignees
Labels
Azure CLI Team The command of the issue is owned by Azure CLI team customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Milestone

Comments

@msftvito
Copy link

msftvito commented Mar 8, 2024

Describe the bug

The 'az' shell script wrapper that sets up the call to python created during the RPM build process (scripts/release/rpm/azure-cli.spec) uses the first python3.9 that it finds in PATH:

python_cmd=python3.9
if command -v python3.9 &>/dev/null; then python_cmd=python3.9; fi
AZ_INSTALLER=RPM PYTHONPATH="$bin_dir/../lib64/az/lib/python3.9/site-packages" $python_cmd -sm azure.cli "$@"

However, we often times run az within scripts in environments where we use our own non-system Python that may not be compatible with az that can cause azure-cli to fail. Since the dnf/yum install process properly pulls down the system python3.9 as a dependency, it makes sense that az should call that instead of relying on what's in the user's environment. I realize based on the various commits and history that this is a very finicky and multi-faceted issue since many OS/distributions are involved, but at least for us it makes sense to explicitly set the PATH or python to be used so that azure-cli can be used even in environments where a conflicting Python is required. As an example, dnf uses #!/usr/libexec/platform-python in RHEL like distros.

It is possible to work around this issue by wrapping around the az wrapper and setting the right values explicitly, but it makes more sense to have the actual az wrapper handle the logic correctly in the first place.

Related command

Steps to reproduce using a Rocky Linux 8 container:

docker run -it rockylinux:8 /bin/bash

#Install Azure-CLI
rpm --import https://packages.microsoft.com/keys/microsoft.asc
dnf install -y https://packages.microsoft.com/config/rhel/8/packages-microsoft-prod.rpm
#2.58.0-1.el8 at time of writing
dnf install -y azure-cli 

#Install alternative Python with incompatibilities
dnf install -y wget gcc make zlib-devel
wget 'https://www.python.org/ftp/python/3.9.18/Python-3.9.18.tgz'
tar -xf Python-*
cd Python-3.9.18
./configure --prefix=/tmp/python39 #No SSL support on purpose
make
make install

#Works as expected using system Python
az

#Fails because az wrapper runs alternative python with incompatibilities
export PATH=/tmp/python39/bin/:$PATH
az

Errors

N/A

Issue script & Debug output

N/A

Expected behavior

az / azure-cli to function even when the first python in PATH is set to an alternative Python install

Environment Summary

azure-cli 2.58.0-1.el8

Additional context

No response

@msftvito msftvito added the bug This issue requires a change to an existing behavior in the product in order to be resolved. label Mar 8, 2024
@yonzhan
Copy link
Collaborator

yonzhan commented Mar 8, 2024

Thank you for opening this issue, we will look into it.

@microsoft-github-policy-service microsoft-github-policy-service bot added the customer-reported Issues that are reported by GitHub users external to the Azure organization. label Mar 8, 2024
@yonzhan yonzhan added Azure CLI Team The command of the issue is owned by Azure CLI team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that and removed bug This issue requires a change to an existing behavior in the product in order to be resolved. labels Mar 9, 2024
@yonzhan yonzhan added this to the Backlog milestone Mar 9, 2024
@bebound
Copy link
Contributor

bebound commented Mar 11, 2024

az requires Python 3.9. If you've prioritized a newer Python 3.9 installation in your PATH over the system's default Python, then az should use new python3.9.
This follows standard practice in Linux environments.

@msftvito
Copy link
Author

msftvito commented Mar 11, 2024 via email

@bebound
Copy link
Contributor

bebound commented Mar 12, 2024

I stand by my point.

Regarding your issue, you can prioritize your own az which uses a hardcoded path.

@msftvito
Copy link
Author

msftvito commented Mar 12, 2024 via email

@bebound
Copy link
Contributor

bebound commented Mar 13, 2024

Yes

@msftvito
Copy link
Author

msftvito commented Mar 13, 2024 via email

@bebound bebound closed this as completed Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Azure CLI Team The command of the issue is owned by Azure CLI team customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
None yet
Development

No branches or pull requests

3 participants