Skip to content

Conversation

@iain-macdonald
Copy link
Contributor

The authorization code in remotes/docker/authorizer.go currently ignores OAuth token expiration times that are provided by the issuer, instead relying on the caller to inform it of authentication failures to learn of token invalidations. This is slightly inefficient because round-trip requests to the server can be made using tokens that the client knows are expired, and requires the client to reauthorize more often that is strictly necessary. This PR tracks the token-issuer-provided expiration time along with the token itself and preemptively refreshes expired tokens when authorization requests are received for expired tokens.

I believe this the bearer auth case of #6377, though I noticed it in a slightly different context: we encountered errors streaming container images using the soci-snapshotter when these auth tokens expired and weren't refreshed correctly.

Signed-off-by: Iain Macdonald xiainx@gmail.com

@k8s-ci-robot
Copy link

Hi @iain-macdonald. Thanks for your PR.

I'm waiting for a containerd member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@cardyok
Copy link
Contributor

cardyok commented Jun 27, 2023

might related to #8388
since currently expires_in is not an required field for registry, it might be better if we do not rely on this field.

@iain-macdonald
Copy link
Contributor Author

might related to #8388 since currently expires_in is not an required field for registry, it might be better if we do not rely on this field.

That makes sense. I'll admit I'm not an expert with golang, but my understanding is if it isn't set, the default value assigned to ExpiresInSeconds will be 0 which will trigger the if-condition on line 341 and fallback to the existing logic. Is that correct, or am I misunderstanding something?

@cardyok
Copy link
Contributor

cardyok commented Jun 28, 2023

might related to #8388 since currently expires_in is not an required field for registry, it might be better if we do not rely on this field.

That makes sense. I'll admit I'm not an expert with golang, but my understanding is if it isn't set, the default value assigned to ExpiresInSeconds will be 0 which will trigger the if-condition on line 341 and fallback to the existing logic. Is that correct, or am I misunderstanding something?

yea you right it will fallback. But token expiration problem still exists if expires_in is not include in registry response

@iain-macdonald
Copy link
Contributor Author

might related to #8388 since currently expires_in is not an required field for registry, it might be better if we do not rely on this field.

That makes sense. I'll admit I'm not an expert with golang, but my understanding is if it isn't set, the default value assigned to ExpiresInSeconds will be 0 which will trigger the if-condition on line 341 and fallback to the existing logic. Is that correct, or am I misunderstanding something?

yea you right it will fallback. But token expiration problem still exists if expires_in is not include in registry response

Yes, and this PR preserves the existing behavior in the case, so it's strictly an improvement for the cases where expires_in is provided.

@iain-macdonald
Copy link
Contributor Author

Hey, it's been a few weeks without any feedback from the containerd team. Are there any next steps for me to take here? I've tried to follow the instructions in https://github.com/containerd/project/blob/main/CONTRIBUTING.md, but please let me know if I've missed a step or something.

@iain-macdonald
Copy link
Contributor Author

Hey, checking in one more time. Let me know if there are any additional steps I need to take to get this PR reviewed. Thanks!

@dmcgowan
Copy link
Member

This change looks good to accept. I have a few questions though.

we encountered errors streaming container images using the soci-snapshotter when these auth tokens expired and weren't refreshed correctly.

What were the errors? I'm wondering if @cardyok 's PR fixes the general issue without relying on the registry.

Which registries today are setting this? (As this is only a recommended field https://datatracker.ietf.org/doc/html/rfc6749#section-4.2.2)

@dmcgowan dmcgowan self-assigned this Jul 27, 2023
@iain-macdonald
Copy link
Contributor Author

The errors are 401 (unauthorized) errors, and the Docker Hub registry sets this field.

@cardyok 's PR also fixes the issue we observed, Docker Hub sets the error field in its response as well, though it requires an additional roundtrip to/from the container registry to learn when access tokens have expired so it's slightly slower. That said, it's much simpler.

@cpuguy83
Copy link
Member

Is there any concern with this? It looks like a good change that can save a round trip with the registry.
I guess if we are suddnely using a field that may have a junk value in it that could cause problems.

@iain-macdonald
Copy link
Contributor Author

Hey all, apologies for losing track of this for a little bit. I just rebased it, so it should be ready for review again. Thanks!

Signed-off-by: Iain Macdonald <xiainx@gmail.com>
@iain-macdonald
Copy link
Contributor Author

Thanks for the review, Derek. Can you suggest another reviewer so I can get this change approved and merged, or recommend different steps forward if not that?

@estesp estesp added this pull request to the merge queue Jan 29, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 29, 2024
@estesp estesp added this pull request to the merge queue Jan 29, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 29, 2024
@estesp estesp added this pull request to the merge queue Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants