Skip to content

Commit 74ab798

Browse files
GiteaBotKN4CK3R
andauthored
Add endpoint for not implemented Docker auth (#28457) (#28462)
Backport #28457 by @KN4CK3R Recently Docker started to use the optional `POST /v2/token` endpoint which should respond with a `404 Not Found` status code instead of the current `405 Method Not Allowed`. > Note: Not all token servers implement oauth2. If the request to the endpoint returns 404 using the HTTP POST method, refer to Token Documentation for using the HTTP GET method supported by all token servers. Co-authored-by: KN4CK3R <[email protected]>
1 parent 97a0bf1 commit 74ab798

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

routers/api/packages/api.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,10 @@ func ContainerRoutes() *web.Route {
603603
})
604604

605605
r.Get("", container.ReqContainerAccess, container.DetermineSupport)
606-
r.Get("/token", container.Authenticate)
606+
r.Group("/token", func() {
607+
r.Get("", container.Authenticate)
608+
r.Post("", container.AuthenticateNotImplemented)
609+
})
607610
r.Get("/_catalog", container.ReqContainerAccess, container.GetRepositoryList)
608611
r.Group("/{username}", func() {
609612
r.Group("/{image}", func() {

routers/api/packages/container/container.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,17 @@ func Authenticate(ctx *context.Context) {
156156
})
157157
}
158158

159+
// https://distribution.github.io/distribution/spec/auth/oauth/
160+
func AuthenticateNotImplemented(ctx *context.Context) {
161+
// This optional endpoint can be used to authenticate a client.
162+
// It must implement the specification described in:
163+
// https://datatracker.ietf.org/doc/html/rfc6749
164+
// https://distribution.github.io/distribution/spec/auth/oauth/
165+
// Purpose of this stub is to respond with 404 Not Found instead of 405 Method Not Allowed.
166+
167+
ctx.Status(http.StatusNotFound)
168+
}
169+
159170
// https://docs.docker.com/registry/spec/api/#listing-repositories
160171
func GetRepositoryList(ctx *context.Context) {
161172
n := ctx.FormInt("n")

0 commit comments

Comments
 (0)