mirror of
https://github.com/kopia/kopia.git
synced 2026-03-16 21:28:15 -04:00
* nit: replaced harcoded string constants with named constants * acl: added management of ACL entries * auth: implemented DefaultAuthorizer which uses ACLs if any entries are found in the system and falls back to LegacyAuthorizer if not * cli: switch to DefaultAuthorizer when starting server * cli: added ACL management * server: refactored authenticator + added refresh Authenticator is now an interface which also supports Refresh. * authz: refactored authorizer to be an interface + added Refresh() * server: refresh authentication and authorizer * e2e tests for ACLs * server: handling of SIGHUP to refresh authn/authz caches * server: reorganized flags to specify auth options: - removed '--allow-repository-users' - it's always on - one of --without-password, --server-password or --random-password can be specified to specify password for the UI user - htpasswd-file - can be specified to provide password for UI or remote users * cli: moved 'kopia user' to 'kopia server user' * server: allow all UI actions if no authenticator is set * acl: removed priority until we have a better understood use case for it * acl: added validation of allowed labels when adding ACL entries * site: added docs for ACLs
42 lines
922 B
Go
42 lines
922 B
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/kopia/kopia/internal/auth"
|
|
)
|
|
|
|
func requireUIUser(s *Server, r *http.Request) bool {
|
|
if s.authenticator == nil {
|
|
return true
|
|
}
|
|
|
|
user, _, _ := r.BasicAuth()
|
|
|
|
return user == s.options.UIUser
|
|
}
|
|
|
|
func anyAuthenticatedUser(s *Server, r *http.Request) bool {
|
|
return true
|
|
}
|
|
|
|
func handlerWillCheckAuthorization(s *Server, r *http.Request) bool {
|
|
return true
|
|
}
|
|
|
|
func requireContentAccess(level auth.AccessLevel) isAuthorizedFunc {
|
|
return func(s *Server, r *http.Request) bool {
|
|
return s.httpAuthorizationInfo(r).ContentAccessLevel() >= level
|
|
}
|
|
}
|
|
|
|
func hasManifestAccess(s *Server, r *http.Request, labels map[string]string, level auth.AccessLevel) bool {
|
|
return s.httpAuthorizationInfo(r).ManifestAccessLevel(labels) >= level
|
|
}
|
|
|
|
var (
|
|
_ isAuthorizedFunc = requireUIUser
|
|
_ isAuthorizedFunc = anyAuthenticatedUser
|
|
_ isAuthorizedFunc = handlerWillCheckAuthorization
|
|
)
|