π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[server] Treat firstUser as admin if admins config is empty
Neeraj Gupta829b4ab43669
diff --git a/server/configurations/local.yaml b/server/configurations/local.yamlindex 707b9155aa..bca362b838 100644--- a/server/configurations/local.yaml+++ b/server/configurations/local.yaml@@ -323,6 +323,7 @@ internal:# local-domain-suffix: "@example.org"# local-domain-value: 123456# List of user IDs that can use the admin API endpoints.+ # If this is not set, as a fallback, the first user is considered an admin.admins: []# Replication configdiff --git a/server/pkg/middleware/auth.go b/server/pkg/middleware/auth.goindex 5adeaf0567..81a9f85f97 100644--- a/server/pkg/middleware/auth.go+++ b/server/pkg/middleware/auth.go@@ -91,6 +91,14 @@ func (m *AuthMiddleware) AdminAuthMiddleware() gin.HandlerFunc {return}}+ // if no admins are set, then check if the user is first user in the system+ if len(admins) == 0 {+ id, err := m.UserAuthRepo.GetMinUserID()+ if err != nil && id == userID {+ c.Next()+ return+ }+ }c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "insufficient permissions"})}}diff --git a/server/pkg/repo/userauth.go b/server/pkg/repo/userauth.goindex c182e9e870..ed17061431 100644--- a/server/pkg/repo/userauth.go+++ b/server/pkg/repo/userauth.go@@ -172,3 +172,14 @@ func (repo *UserAuthRepository) GetActiveSessions(userID int64, app ente.App) ([}return sessions, nil}++// GetMinUserID returns the first user that was created in the system+func (repo *UserAuthRepository) GetMinUserID() (int64, error) {+ row := repo.DB.QueryRow(`select min(user_id) from users where encrypted_email is not null;`)+ var id int64+ err := row.Scan(&id)+ if err != nil {+ return -1, stacktrace.Propagate(err, "")+ }+ return id, nil+}