[server][auth] Create auth package with extensible config for LDAP and OAuth

This commit is contained in:
Abhishek Shroff
2025-06-10 02:38:03 +05:30
parent aaa2986bd2
commit a4b7bd1bed
22 changed files with 284 additions and 260 deletions

View File

@@ -6,7 +6,9 @@ import (
"os"
"syscall"
"codeberg.org/shroff/phylum/server/internal/auth"
"codeberg.org/shroff/phylum/server/internal/core"
"codeberg.org/shroff/phylum/server/internal/db"
"github.com/spf13/cobra"
"golang.org/x/term"
)
@@ -53,7 +55,7 @@ func setupPasswdCommand() *cobra.Command {
}
}
err = core.UserManagerFromContext(context.Background()).UpdateUserPassword(u, password)
err = auth.UpdateUserPassword(db.Get(context.Background()), u, password)
if err != nil {
fmt.Println("could not add user: " + err.Error())
os.Exit(1)

View File

@@ -5,7 +5,9 @@ import (
"fmt"
"os"
"codeberg.org/shroff/phylum/server/internal/auth"
"codeberg.org/shroff/phylum/server/internal/core"
"codeberg.org/shroff/phylum/server/internal/db"
"codeberg.org/shroff/phylum/server/internal/mail"
"github.com/spf13/cobra"
)
@@ -22,7 +24,7 @@ func setupPwresetResetCommand() *cobra.Command {
if user, err := manager.UserByEmail(email); err != nil {
fmt.Println("unable to find user" + email + ": " + err.Error())
os.Exit(1)
} else if token, err := manager.CreateResetToken(user); err != nil {
} else if token, err := auth.CreateResetToken(db.Get(context.Background()), user); err != nil {
fmt.Println("unable to create reset token: " + err.Error())
os.Exit(1)
} else {

View File

@@ -8,12 +8,13 @@ import (
"path"
"strings"
"codeberg.org/shroff/phylum/server/internal/auth"
"codeberg.org/shroff/phylum/server/internal/auth/crypt"
"codeberg.org/shroff/phylum/server/internal/command/admin"
"codeberg.org/shroff/phylum/server/internal/command/fs"
"codeberg.org/shroff/phylum/server/internal/command/serve"
"codeberg.org/shroff/phylum/server/internal/command/user"
"codeberg.org/shroff/phylum/server/internal/core"
"codeberg.org/shroff/phylum/server/internal/crypt"
"codeberg.org/shroff/phylum/server/internal/db"
"codeberg.org/shroff/phylum/server/internal/mail"
"codeberg.org/shroff/phylum/server/internal/storage"
@@ -117,7 +118,9 @@ func SetupCommand() {
serve.Cfg = cfg.Server
mail.Cfg = cfg.Mail
core.Cfg = cfg.User
crypt.Cfg = cfg.Crypt
auth.Cfg = cfg.Auth
crypt.Cfg = cfg.Auth.Password.Crypt
if err := storage.Initialize(db.Get(context.Background())); err != nil {
logrus.Fatal("Failed to initialize storage: " + err.Error())
}

View File

@@ -13,22 +13,26 @@ storage:
user:
password:
length: 12
lower: 1
upper: 1
numeric: 1
symbols: 1
basedir: /home
permission: 0x10 # Invite users
crypt:
hash: argon2
argon2:
memory: 2048
iterations: 6
parallelism: 4
salt: 32
key: 32
auth:
password:
backend: crypt
crypt:
hash: argon2
argon2:
memory: 2048
iterations: 6
parallelism: 4
salt: 32
key: 32
requirements:
length: 12
lower: 1
upper: 1
numeric: 1
symbols: 1
server:
host:

View File

@@ -1,9 +1,9 @@
package command
import (
"codeberg.org/shroff/phylum/server/internal/auth"
"codeberg.org/shroff/phylum/server/internal/command/serve"
"codeberg.org/shroff/phylum/server/internal/core"
"codeberg.org/shroff/phylum/server/internal/crypt"
"codeberg.org/shroff/phylum/server/internal/db"
"codeberg.org/shroff/phylum/server/internal/mail"
"codeberg.org/shroff/phylum/server/internal/storage"
@@ -16,5 +16,5 @@ type Config struct {
Server serve.Config `koanf:"server"`
Mail mail.Config `koanf:"mail"`
User core.Config `koanf:"user"`
Crypt crypt.Config `koanf:"crypt"`
Auth auth.Config `koanf:"auth"`
}