mirror of
https://github.com/project-zot/zot.git
synced 2026-06-16 20:38:08 +08:00
auth: support a read-only mode
This is useful if we want to roll out experimental versions of zot pointing to some storage shared with another zot instance. Also, when under storage full conditions, will be useful to turn on this flag to prevent further writes.
This commit is contained in:
@@ -91,6 +91,12 @@ func basicAuthHandler(c *Controller) mux.MiddlewareFunc {
|
||||
authFail(w, realm, 5)
|
||||
return
|
||||
}
|
||||
|
||||
if (r.Method != http.MethodGet && r.Method != http.MethodHead) && c.Config.HTTP.ReadOnly {
|
||||
// Reject modification requests in read-only mode
|
||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
// Process request
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
@@ -175,6 +181,12 @@ func basicAuthHandler(c *Controller) mux.MiddlewareFunc {
|
||||
return
|
||||
}
|
||||
|
||||
if (r.Method != http.MethodGet && r.Method != http.MethodHead) && c.Config.HTTP.ReadOnly {
|
||||
// Reject modification requests in read-only mode
|
||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
basicAuth := r.Header.Get("Authorization")
|
||||
if basicAuth == "" {
|
||||
authFail(w, realm, delay)
|
||||
|
||||
Reference in New Issue
Block a user