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

storage: fix auth compatibility for registry backend #1425

Merged
merged 1 commit into from
Sep 27, 2023

Conversation

lihuahua123
Copy link
Contributor

@lihuahua123 lihuahua123 commented Sep 14, 2023

Relevant Issue (if applicable)

Details

fix auth compatibility for registry backend:
Due to the different implementations of various image registries, auth requests may use the GET or POST methods.
In the previous way, it just use 'GET' method, and in the pr, we fix it advanced, it can use and cache the GET or POST methods.

Types of changes

What types of changes does your PullRequest introduce? Put an x in all the boxes that apply:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation Update (if none of the other choices apply)

Checklist

Go over all the following points, and put an x in all the boxes that apply.

  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

@lihuahua123 lihuahua123 requested a review from a team as a code owner September 14, 2023 13:11
@lihuahua123 lihuahua123 requested review from liubogithub, imeoer and changweige and removed request for a team September 14, 2023 13:11
@imeoer
Copy link
Collaborator

imeoer commented Sep 15, 2023

Hi @lihuahua123 please add the detailed commit message, and the commit title better be like storage: fix auth compatibility for registry backend.

@codecov
Copy link

codecov bot commented Sep 15, 2023

Codecov Report

Merging #1425 (9276471) into master (d2fcfcd) will decrease coverage by 0.07%.
Report is 7 commits behind head on master.
The diff coverage is 8.57%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1425      +/-   ##
==========================================
- Coverage   46.46%   46.40%   -0.07%     
==========================================
  Files         123      123              
  Lines       38643    38745     +102     
  Branches    38643    38745     +102     
==========================================
+ Hits        17954    17978      +24     
- Misses      19716    19794      +78     
  Partials      973      973              
Files Coverage Δ
storage/src/backend/registry.rs 32.94% <8.57%> (-1.27%) ⬇️

... and 12 files with indirect coverage changes

@lihuahua123 lihuahua123 changed the title fix the auth method storage: fix auth compatibility for registry backend Sep 15, 2023
@@ -188,6 +189,10 @@ struct RegistryState {
// Use RwLock here to avoid using mut backend trait object.
// Example: RwLock<"Bearer <token>">
// RwLock<"Basic base64(<username:password>)">

// Cache the method of getting auth, get | post
cached_get_auth_method: HashCache,
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about:

// Cache for the HTTP method when getting auth, possible values: "get", "post".
// Due to the different implementations of various image registries, auth requests
// may use the GET or POST methods, we need to cache the method after the
// fallback, so it can be reused next time and reduce an unnecessary request.
cached_auth_using_http_get: HashCache,

And can we make it as HashCache<bool> ?

struct HashCache(RwLock<HashMap<String, T>>);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the context ,HashCache is implemented as
struct HashCache(RwLock<HashMap<String, String>>);
if we make it as' HashCache ', it need implement another logic

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have resolve it with changing the implemention of struct HashCache(RwLock<HashMap<String, String>>); to struct HashCache<T>(RwLock<HashMap<String, T>>);.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is reused as follows.

    // Cache for the HTTP method when getting auth, possible values: "get", "post".
    // Due to the different implementations of various image registries, auth requests
    // may use the GET or POST methods, we need to cache the method after the
    // fallback, so it can be reused next time and reduce an unnecessary request.
    cached_auth_using_http_get: HashCache<bool>,
    // Cache 30X redirect url
    // Example: RwLock<HashMap<"<blob_id>", "<redirected_url>">>
    cached_redirect: HashCache<String>,

storage/src/backend/registry.rs Show resolved Hide resolved
storage/src/backend/registry.rs Show resolved Hide resolved
@@ -189,10 +193,14 @@ struct RegistryState {
// Example: RwLock<"Bearer <token>">
// RwLock<"Basic base64(<username:password>)">
cached_auth: Cache,
// Cache for the HTTP method when getting auth, possible values: "get", "post".
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should also update the comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok!

Signed-off-by: lihuahua123 <771725652@qq.com>
Copy link
Collaborator

@imeoer imeoer left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@imeoer imeoer merged commit d7b1851 into dragonflyoss:master Sep 27, 2023
23 of 24 checks passed
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.

None yet

2 participants