Skip to content

Add TLS Validation #197

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

Closed
wants to merge 1 commit into from
Closed

Conversation

Sojamann
Copy link
Contributor

@Sojamann Sojamann commented May 2, 2025

This PR adds tls verification options and solves #185.


At the moment only insecure (no tls verification) is supported which I'd like to change since I cannot rely on the hosts CA Bundles which requests uses by default.

The tls options are also supported by the oras binary.

allow specification of:
- ca bundle for server verification
- client certificate/key for client verification

Signed-off-by: Robin Bergewski <robinbergewski@gmail.com>
@Sojamann Sojamann requested review from vsoch and SteveLasker as code owners May 2, 2025 09:09
def get_auth_backend(
name="token", session=None, insecure=False, tls_verify=True, **kwargs
):
def get_auth_backend(name="token", session=None, insecure=False, **kwargs):
backend = auth_backends.get(name)
if not backend:
raise ValueError(f"Authentication backend {backend} is not known.")
backend = backend(**kwargs)
backend.session = session or requests.Session()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This kinda is a problem if someone does not pass in the session... Is this something that needs to be taken into account or can we not just make session a required argument here. Having ONE session which is pre-configured to use for all requests has the advantage that we can pass less arguments around settings like

self.session.cookies.set_policy(DefaultCookiePolicy(allowed_domains=[]))

cannot be forgotten

Copy link
Contributor

Choose a reason for hiding this comment

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

The one session and passing it forward from the client was the idea - see how it is created and passed forward here:

self.session: requests.Session = requests.Session()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should the function get_auth_backend stay like this since it is correctly used for should session be made a required parameter?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry I don't understand - do you mean or should session be made required?

Copy link
Contributor Author

@Sojamann Sojamann May 2, 2025

Choose a reason for hiding this comment

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

Either we leave it like it is now since it works fine the way it is currently used or we change it to

def get_auth_backend(session: requests.Session, name="token", , insecure=False, **kwargs):

so that no that no mistakes be made where in the future somebody does not pass in the session and just does:

get_auth_backend(name="token", insecure=False)

@Sojamann
Copy link
Contributor Author

Sojamann commented May 2, 2025

The test is failing since I removed the explicit verify=False setting in each request, which leads to the issue described here.

The session has verify=False but when the verify parameter is not explicitly set in the request, it will default to checking the env variable REQUESTS_CA_BUNDLE which takes precedence over the session setting.

You might have known this, I just learned this today ... 😲

Since the user can now set the CA bundle explicitly, would it make sense to set trust_env = False on the session to prevent it from reading environment variables? This would make the code also less dependent on the underlying request library.

What are your thoughts? How should we proceed?

@vsoch
Copy link
Contributor

vsoch commented May 2, 2025

If the session is shared, for your implementation can you just create the client and set session.verify = /path/to/bundle instead?

@Sojamann
Copy link
Contributor Author

Sojamann commented May 2, 2025

@vsoch do you mean that this change should not be made and the user of the Registry should set the cert like this?

r = Registry(...)
r.session.verify = '/path/to/my/bundle'

@vsoch
Copy link
Contributor

vsoch commented May 2, 2025

@Sojamann yes I'm wondering if you'd like to try that and see if it works for your use case.

@Sojamann
Copy link
Contributor Author

Sojamann commented May 2, 2025

This would also work, but as a user of Oras, I would then be exposed to the internals of the library.

@vsoch
Copy link
Contributor

vsoch commented May 2, 2025

@Sojamann it's a developer library by default - I would argue that your use case is niche and should not refactor the entire structure of the library to support when it's as easy as tweaking the session on the class instance.

@Sojamann
Copy link
Contributor Author

Sojamann commented May 2, 2025

Hm I’m not fully on board with this, but I guess it is what it is. I’ll go ahead and close the PR then.

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