aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKN4CK3R <admin@oldschoolhack.me>2023-12-13 21:23:53 +0100
committerGitHub <noreply@github.com>2023-12-13 15:23:53 -0500
commit064f05204c0539d1f92895776dee7f626a628e3b (patch)
tree038af763dcd75ec90cbb821d5574ee9e237f5b0f
parent73047854c00589137d6afbd4329d5176290af0c4 (diff)
downloadgitea-064f05204c0539d1f92895776dee7f626a628e3b.tar.gz
gitea-064f05204c0539d1f92895776dee7f626a628e3b.zip
Add endpoint for not implemented Docker auth (#28457)
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.
-rw-r--r--routers/api/packages/api.go5
-rw-r--r--routers/api/packages/container/container.go11
2 files changed, 15 insertions, 1 deletions
diff --git a/routers/api/packages/api.go b/routers/api/packages/api.go
index 722ee3f87b..76116d0751 100644
--- a/routers/api/packages/api.go
+++ b/routers/api/packages/api.go
@@ -603,7 +603,10 @@ func ContainerRoutes() *web.Route {
})
r.Get("", container.ReqContainerAccess, container.DetermineSupport)
- r.Get("/token", container.Authenticate)
+ r.Group("/token", func() {
+ r.Get("", container.Authenticate)
+ r.Post("", container.AuthenticateNotImplemented)
+ })
r.Get("/_catalog", container.ReqContainerAccess, container.GetRepositoryList)
r.Group("/{username}", func() {
r.Group("/{image}", func() {
diff --git a/routers/api/packages/container/container.go b/routers/api/packages/container/container.go
index 62eec3064c..dce3809264 100644
--- a/routers/api/packages/container/container.go
+++ b/routers/api/packages/container/container.go
@@ -156,6 +156,17 @@ func Authenticate(ctx *context.Context) {
})
}
+// https://distribution.github.io/distribution/spec/auth/oauth/
+func AuthenticateNotImplemented(ctx *context.Context) {
+ // This optional endpoint can be used to authenticate a client.
+ // It must implement the specification described in:
+ // https://datatracker.ietf.org/doc/html/rfc6749
+ // https://distribution.github.io/distribution/spec/auth/oauth/
+ // Purpose of this stub is to respond with 404 Not Found instead of 405 Method Not Allowed.
+
+ ctx.Status(http.StatusNotFound)
+}
+
// https://docs.docker.com/registry/spec/api/#listing-repositories
func GetRepositoryList(ctx *context.Context) {
n := ctx.FormInt("n")