Skip to content

Proposal: reusing context basic auth result in git http implementation #4952

@beeonthego

Description

@beeonthego

Current basic auth flow - is it a password? is it a password again? is it a token?

In the current implementation, when cloning/committing private repo over http/https using basic auth header, for each request, Gitea tries the following workflow

  1. treating basic auth token as password and attempting to sign in user when creating context in middleware (modules/context/context.go).

  2. treating basic auth token as password and attempting to sign in user AGAIN in routers/repo/http.go

  3. validating it as token and verifying access to repo.

Each sign in operation involves hashing provided token and comparing it with the record retrieved from db. These are two wasted cycles in each request to perform git operations on private repo over http/https.

The proposed basic auth workflow - is it a token? is it a password?

If basic auth header is present, in context middleware, we will first attempt to validate the header as application token, then treat it as password. we can set a flag in ctx.Data to indicate whether it is plain text password. The decision can be made in routers whether to accept/reject auth by plain text password using the current logic.

If a valid token is provided (for example when Drone clones a private repo using token from a netrc file), then there will only be one validation cycle needed.

The reason behind is that there are potentially more git operations over http than login requests from users.

In order to keep existing integration with Drone, we will look for token both in username and password, using the same logic as it is done now.

Are there any concerns to this approach?

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/enhancementAn improvement of existing functionalitytype/proposalThe new feature has not been accepted yet but needs to be discussed first.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions