Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@zfralish
Copy link

https://anaconda.atlassian.net/browse/CLI-14

Some issues are bubbling up in the base conda client from the auth plugin http client not handling ssl contexts correctly.

I have ripped some of the ssl handling logic from the base client to attempt to remedy the issue.

FYI, I don't have much idea what im doing, be critical.

@zfralish
Copy link
Author

Not clear on how versions are managed here, also don't see a changelog.

Comment on lines 119 to 121
try:
from conda.base.context import context
from conda.gateways.connection.adapters.http import HTTPAdapter
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this will be graceful or not, but was my best guess on how to handle environments where conda was not available.

Comment on lines 124 to 126
self.config.ssl_verify_policy = context.ssl_verify
self.config.proxy_servers = context.proxy_servers
self.config.ssl_verify = context.ssl_verify
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wanted to fall back on the config as the source of truth, that way we can handle any complicated logic with precedence if needed, or if we would like to overwrite.


# We need an http adapter

http_adapter = HTTPAdapter(ssl_context=ssl_context)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is weird, and had to be imported from deep in the conda base module, so no idea how well this will play.

Comment on lines +153 to +156
if context.client_ssl_cert_key:
self.cert = (context.client_ssl_cert, context.client_ssl_cert_key)
elif context.client_ssl_cert:
self.cert = context.client_ssl_cert
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is needed or not, but it was handled like this in the base conda, so figured why not?

@zfralish
Copy link
Author

I have no clue how to write tests to cover this, will need some help there.

api_key = get_api_key(access_token, config.ssl_verify)

api_key = get_api_key(
access_token, config.ssl_verify if isinstance(config.ssl_verify, bool) else True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to support trustore in the anaconda.com (and on-prem) routes?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was meant to bring the config inline with the base conda config which differed in type.

auths was bool

whereas base conda config was Union[bool, str] so I thought matching the base config type wise made sense.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type casting is just to control for that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I mean should the get_api_key be adjusted to support the string values rather than just true/false? Or is getting an api key working correctly for these users?

from conda.base.context import context
from conda.gateways.connection.adapters.http import HTTPAdapter

# We need to decide which takes precedence, for now im assuming conda base config.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to read your code carefully, but the general precedence followed by unified cli is as follows (from low to high)

  1. Coded default in source code
  2. Config files (config.toml, condarc, etc)
  3. Env variables
  4. Direct kward override in init (like using this class in an ipython shell or jupyter notebook)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this ascending or descending?

Because if 4. is lowest priority it is never really an "override" correct? or am missing somethin?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is ascending priority. 4 (init kwargs) is the absolute override of everything.

https://github.com/anaconda/anaconda-cli-base?tab=readme-ov-file#config-file

@AlbertDeFusco
Copy link
Contributor

Versions are managed through the Releases tab on github.

A Changelog would be nice we could pobably convert that info to a changelog 🤔 to get it started

@AlbertDeFusco
Copy link
Contributor

Let me see if I understand

  • conda has a sophisticated ssl config support true/false/'truststore'(/path-to-certs?) and proxies
  • the same request challenges extend to anaconda.com (and on-prem) for customers using the above capabilities for conda
  • we want to extend anaconda-auth to support more than true/false ssl configuration
  • in the abence of specific overrides in ~/.anaconda/config.toml, ANACONDA_AUTH_ env vars, or init kwargs we read the conda configs and apply matching configuration to anaconda-auth BaseClient

Is any of the above correct?

@zfralish
Copy link
Author

Let me see if I understand

  • conda has a sophisticated ssl config support true/false/'truststore'(/path-to-certs?) and proxies
  • the same request challenges extend to anaconda.com (and on-prem) for customers using the above capabilities for conda
  • we want to extend anaconda-auth to support more than true/false ssl configuration
  • in the abence of specific overrides in ~/.anaconda/config.toml, ANACONDA_AUTH_ env vars, or init kwargs we read the conda configs and apply matching configuration to anaconda-auth BaseClient

Is any of the above correct?

There are some certificate issues bubbling up in the conda env-logger in some enterprise envs where this plugin is in use.

@mattkram speculated that it was because the plugin here used a different client for requests that lacked ssl config, so the idea is to port the ssl config from the base conda client into this plugin.

My current understanding of precedence after the latest push is as follows.

  1. Any direct passed args to init will override anything else
  2. Env vars will be respected and set in the AuthConfig object
  3. If at the point of evaluation, ssl settings are None we will attempt to import settings from the base conda env if available, I believe this will respect condarc settings but I am not sure.

@zfralish zfralish marked this pull request as ready for review October 23, 2025 17:40
elif context.client_ssl_cert:
self.cert = context.client_ssl_cert

except Exception:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we catch something ImportError here?

ssl_verify: Optional[bool] = None,
extra_headers: Optional[Union[str, dict]] = None,
hash_hostname: Optional[bool] = None,
proxy_servers: Optional[MutableMapping[str, str]] = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should ssl_verify in this init support str?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants