Skip to content

Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.

feat(backend:auth:ldap): move adminGroup to options, add autoCreateUser and autoCreatePermissions

johaven96d52c95585e
diff --git a/backend/src/authentication/providers/ldap/auth-ldap.config.ts b/backend/src/authentication/providers/ldap/auth-ldap.config.ts
index 9ec70da0..237a446f 100644
--- a/backend/src/authentication/providers/ldap/auth-ldap.config.ts
+++ b/backend/src/authentication/providers/ldap/auth-ldap.config.ts
@@ -18,6 +18,7 @@ import {
IsString,
ValidateNested
} from 'class-validator'
+import { USER_PERMISSION } from '../../../applications/users/constants/user'
import { LDAP_COMMON_ATTR, LDAP_LOGIN_ATTR } from './auth-ldap.constants'
export class AuthMethodLDAPAttributesConfig {
@@ -32,6 +33,25 @@ export class AuthMethodLDAPAttributesConfig {
email: string = LDAP_COMMON_ATTR.MAIL
}
+export class AuthMethodLDAPOptionsConfig {
+ @IsOptional()
+ @IsString()
+ adminGroup?: string
+
+ @IsOptional()
+ @IsBoolean()
+ autoCreateUser? = true
+
+ @IsOptional()
+ @IsArray()
+ @IsEnum(USER_PERMISSION, { each: true })
+ autoCreatePermissions?: USER_PERMISSION[] = []
+
+ @IsOptional()
+ @IsBoolean()
+ enablePasswordAuthFallback? = true
+}
+
export class AuthMethodLDAPConfig {
@Transform(({ value }) => (Array.isArray(value) ? value.filter((v: string) => Boolean(v)) : value))
@ArrayNotEmpty()
@@ -54,10 +74,6 @@ export class AuthMethodLDAPConfig {
@Type(() => AuthMethodLDAPAttributesConfig)
attributes: AuthMethodLDAPAttributesConfig = new AuthMethodLDAPAttributesConfig()
- @IsOptional()
- @IsString()
- adminGroup?: string
-
@IsOptional()
@IsString()
upnSuffix?: string
@@ -66,7 +82,10 @@ export class AuthMethodLDAPConfig {
@IsString()
netbiosName?: string
- @IsOptional()
- @IsBoolean()
- enablePasswordAuthFallback? = true
+ @IsDefined()
+ @IsNotEmptyObject()
+ @IsObject()
+ @ValidateNested()
+ @Type(() => AuthMethodLDAPOptionsConfig)
+ options: AuthMethodLDAPOptionsConfig = new AuthMethodLDAPOptionsConfig()
}
diff --git a/backend/src/authentication/providers/ldap/auth-provider-ldap.service.ts b/backend/src/authentication/providers/ldap/auth-provider-ldap.service.ts
index c2715996..58ceaa38 100644
--- a/backend/src/authentication/providers/ldap/auth-provider-ldap.service.ts
+++ b/backend/src/authentication/providers/ldap/auth-provider-ldap.service.ts
@@ -61,7 +61,7 @@ export class AuthProviderLDAP implements AuthProvider {
// Allow local password authentication for:
// - admin users (break-glass access)
// - regular users when password authentication fallback is enabled
- if (user && Boolean(ldapErrorMessage) && (user.isAdmin || this.ldapConfig.enablePasswordAuthFallback)) {
+ if (user && Boolean(ldapErrorMessage) && (user.isAdmin || this.ldapConfig.options.enablePasswordAuthFallback)) {
const localUser = await this.usersManager.logUser(user, password, ip)
if (localUser) return localUser
}
@@ -80,6 +80,11 @@ export class AuthProviderLDAP implements AuthProvider {
return null
}
+ if (!user && !this.ldapConfig.options.autoCreateUser) {
+ this.logger.warn(`${this.validateUser.name} - User not found and autoCreateUser is disabled`)
+ throw new HttpException('User not found', HttpStatus.UNAUTHORIZED)
+ }
+
const identity = this.createIdentity(entry, password)
user = await this.updateOrCreateUser(identity, user)
this.usersManager.updateAccesses(user, ip, true).catch((e: Error) => this.logger.error(`${this.validateUser.name} : ${e}`))
@@ -92,7 +97,7 @@ export class AuthProviderLDAP implements AuthProvider {
// Generic LDAP: build DN from login attribute + baseDN
const bindUserDN = this.isAD ? ldapLogin : `${this.ldapConfig.attributes.login}=${ldapLogin},${this.ldapConfig.baseDN}`
let client: Client
- let error: any
+ let error: InvalidCredentialsError | any
for (const s of this.ldapConfig.servers) {
client = new Client({ ...this.clientOptions, url: s })
try {
@@ -101,12 +106,12 @@ export class AuthProviderLDAP implements AuthProvider {
} catch (e) {
if (e.errors?.length) {
for (const err of e.errors) {
- this.logger.warn(`${this.checkAuth.name} - ${ldapLogin} : ${err}`)
+ this.logger.warn(`${this.checkAuth.name} - ${bindUserDN} : ${err}`)
error = err
}
} else {
error = e
- this.logger.warn(`${this.checkAuth.name} - ${ldapLogin} : ${e}`)
+ this.logger.warn(`${this.checkAuth.name} - ${bindUserDN} : ${e}`)
}
if (error instanceof InvalidCredentialsError) {
return false
@@ -155,6 +160,7 @@ export class AuthProviderLDAP implements AuthProvider {
private async updateOrCreateUser(identity: CreateUserDto, user: UserModel): Promise<UserModel> {
if (user === null) {
// Create
+ identity.permissions = this.ldapConfig.options.autoCreatePermissions.join(',')
const createdUser = await this.adminUsersManager.createUserOrGuest(identity, identity.role)
const freshUser = await this.usersManager.fromUserId(createdUser.id)
if (!freshUser) {
@@ -187,7 +193,7 @@ export class AuthProviderLDAP implements AuthProvider {
if (Object.keys(identityHasChanged).length > 0) {
try {
if (identityHasChanged?.role != null) {
- if (user.role === USER_ROLE.ADMINISTRATOR && !this.ldapConfig.adminGroup) {
+ if (user.role === USER_ROLE.ADMINISTRATOR && !this.ldapConfig.options.adminGroup) {
// Prevent removing the admin role when adminGroup was removed or not defined
delete identityHasChanged.role
}
@@ -233,9 +239,9 @@ export class AuthProviderLDAP implements AuthProvider {
private createIdentity(entry: LdapUserEntry, password: string): CreateUserDto {
const isAdmin =
- typeof this.ldapConfig.adminGroup === 'string' &&
- this.ldapConfig.adminGroup &&
- entry[LDAP_COMMON_ATTR.MEMBER_OF]?.includes(this.ldapConfig.adminGroup)
+ typeof this.ldapConfig.options.adminGroup === 'string' &&
+ this.ldapConfig.options.adminGroup &&
+ entry[LDAP_COMMON_ATTR.MEMBER_OF]?.includes(this.ldapConfig.options.adminGroup)
return {
login: this.dbLogin(entry[this.ldapConfig.attributes.login]),
email: entry[this.ldapConfig.attributes.email] as string,
diff --git a/backend/src/authentication/providers/oidc/auth-provider-oidc.service.ts b/backend/src/authentication/providers/oidc/auth-provider-oidc.service.ts
index d0e75a4f..4c116580 100644
--- a/backend/src/authentication/providers/oidc/auth-provider-oidc.service.ts
+++ b/backend/src/authentication/providers/oidc/auth-provider-oidc.service.ts
@@ -51,6 +51,26 @@ export class AuthProviderOIDC implements AuthProvider {
private readonly adminUsersManager: AdminUsersManager
) {}
+ async validateUser(login: string, password: string, ip?: string, scope?: AUTH_SCOPE): Promise<UserModel> {
+ // Find user from login or email
+ const user: UserModel = await this.usersManager.findUser(login, false)
+
+ if (!user) {
+ return null
+ }
+
+ if (user.isGuest || user.isAdmin || scope || this.oidcConfig.options.enablePasswordAuth) {
+ // Allow local password authentication for:
+ // - guest users
+ // - admin users (break-glass access)
+ // - application scopes (app passwords)
+ // - regular users when password authentication is enabled
+ return this.usersManager.logUser(user, password, ip, scope)
+ }
+
+ return null
+ }
+
async getConfig(): Promise<Configuration> {
if (!this.config) {
this.config = await this.initializeOIDCClient()
@@ -167,26 +187,6 @@ export class AuthProviderOIDC implements AuthProvider {
}
}
- async validateUser(login: string, password: string, ip?: string, scope?: AUTH_SCOPE): Promise<UserModel> {
- // Find user from login or email
- const user: UserModel = await this.usersManager.findUser(login, false)
-
- if (!user) {
- return null
- }
-
- if (user.isGuest || user.isAdmin || scope || this.oidcConfig.options.enablePasswordAuth) {
- // Allow local password authentication for:
- // - guest users
- // - admin users (break-glass access)
- // - application scopes (app passwords)
- // - regular users when password authentication is enabled
- return this.usersManager.logUser(user, password, ip, scope)
- }
-
- return null
- }
-
getRedirectCallbackUrl(accessExpiration: number, refreshExpiration: number) {
if (!this.frontendBaseUrl) {
const url = new URL(this.oidcConfig.redirectUri)
@@ -257,7 +257,8 @@ export class AuthProviderOIDC implements AuthProvider {
let user: UserModel = await this.usersManager.findUser(email || login, false)
if (!user && !this.oidcConfig.options.autoCreateUser) {
- throw new HttpException('User not found and autoCreateUser is disabled', HttpStatus.UNAUTHORIZED)
+ this.logger.warn(`${this.validateUser.name} - User not found and autoCreateUser is disabled`)
+ throw new HttpException('User not found', HttpStatus.UNAUTHORIZED)
}
// Determine if user should be admin based on groups/roles
diff --git a/backend/src/configuration/config.environment.ts b/backend/src/configuration/config.environment.ts
index 4c9a535e..e7398c5b 100755
--- a/backend/src/configuration/config.environment.ts
+++ b/backend/src/configuration/config.environment.ts
@@ -47,5 +47,14 @@ function loadConfiguration(): GlobalConfig {
config.applications.files.usersPath = join(config.applications.files.dataPath, 'users')
config.applications.files.spacesPath = join(config.applications.files.dataPath, 'spaces')
config.applications.files.tmpPath = join(config.applications.files.dataPath, 'tmp')
+ // DEPRECATIONS
+ // ldap.adminGroup → ldap.options.adminGroup
+ if (typeof config.auth.ldap['adminGroup'] === 'string' && config.auth.ldap['adminGroup'].length > 0) {
+ config.auth.ldap.options.adminGroup = config.auth.ldap['adminGroup']
+ console.warn(
+ '[DEPRECATED][CONFIGURATION] auth.ldap.adminGroup is deprecated and will be removed in a future version. ' +
+ 'Please use auth.ldap.options.adminGroup instead.'
+ )
+ }
return transformAndValidate(GlobalConfig, config, { exposeDefaultValues: true }, { skipMissingProperties: false })
}
diff --git a/environment/environment.dist.min.yaml b/environment/environment.dist.min.yaml
index d106553f..e12332b4 100644
--- a/environment/environment.dist.min.yaml
+++ b/environment/environment.dist.min.yaml
@@ -1,5 +1,5 @@
mysql:
- url: mysql://user:MySQLRootPassword@localhost:3306/database
+ url: mysql://user:MySQLPassword@localhost:3306/database
auth:
encryptionKey: changeEncryptionKeyWithStrongKey
token:
diff --git a/environment/environment.dist.yaml b/environment/environment.dist.yaml
index c489690a..f5e97a52 100755
--- a/environment/environment.dist.yaml
+++ b/environment/environment.dist.yaml
@@ -26,7 +26,7 @@ logger:
filePath:
mysql:
# required
- url: mysql://user:MySQLRootPassword@localhost:3306/database
+ url: mysql://user:MySQLPassword@localhost:3306/database
# default: `false`
logQueries: false
cache:
@@ -84,16 +84,6 @@ auth:
# Optional but strongly recommended
# Warning: do not change or remove the encryption key after MFA activation, or the codes will become invalid
encryptionKey: changeEncryptionKeyWithStrongKey
- # Multifactor authentication
- mfa:
- # TOTP configuration
- totp:
- # Enable TOTP authentication
- # default: true
- enabled: true
- # Name displayed in the authentication app (FreeOTP, Proton Authenticator, Aegis Authenticator etc.)
- # default: Sync-in
- issuer: Sync-in
# cookie sameSite setting: `lax` | `strict`
# default: `strict`
cookieSameSite: strict
@@ -112,13 +102,33 @@ auth:
# token expiration = cookie maxAge
# default: `4h`
expiration: 4h
+ # Multifactor authentication
+ mfa:
+ # TOTP configuration
+ totp:
+ # Enable TOTP authentication
+ # default: true
+ enabled: true
+ # Name displayed in the authentication app (FreeOTP, Proton Authenticator, Aegis Authenticator etc.)
+ # default: Sync-in
+ issuer: Sync-in
+ # LDAP authentication
ldap:
# e.g: [ldap://localhost:389, ldaps://localhost:636] (array required)
+ # required
servers: []
# baseDN: distinguished name (e.g., ou=people,dc=ldap,dc=sync-in,dc=com)
- baseDN:
+ # required
+ baseDN: ou=people,dc=ldap,dc=sync-in,dc=com
# filter, e.g: (acl=admin)
+ # optional
filter:
+ # upnSuffix: AD domain suffix used with `userPrincipalName` to build UPN-style logins (e.g., user@`sync-in.com`)
+ # optional
+ upnSuffix:
+ # netbiosName: NetBIOS domain name used with `sAMAccountName` to build legacy logins (e.g., `SYNC_IN`\user)
+ # optional
+ netbiosName:
attributes:
# Login attribute used to construct the user's DN for binding.
# The value of this attribute is used as the naming attribute (first RDN) when forming the Distinguished Name (DN) during authentication
@@ -129,17 +139,32 @@ auth:
# email: `mail` or `email`
# default: `mail`
email: mail
- # adminGroup: The CN of a group containing Sync-in administrators (e.g., administrators)
- adminGroup:
- # upnSuffix: AD domain suffix used with `userPrincipalName` to build UPN-style logins (e.g., user@`sync-in.com`)
- upnSuffix:
- # netbiosName: NetBIOS domain name used with `sAMAccountName` to build legacy logins (e.g., `SYNC_IN`\user)
- netbiosName:
- # enablePasswordAuthFallback: Enable local password authentication as a fallback when the LDAP authentication service is unavailable.
- # This fallback applies only to existing users and is NOT triggered when credentials are invalid.
- # Users must have signed in at least once.
- # default: true
- enablePasswordAuthFallback: true
+ options:
+ # autoCreateUser: Automatically create a local user on first successful LDAP authentication.
+ # The local account is created from LDAP attributes:
+ # - login: from the configured LDAP login attribute (e.g. uid, cn, sAMAccountName, userPrincipalName)
+ # - email: from the configured email attribute (required)
+ # - firstName / lastName: from givenName+sn, or displayName, or cn (fallback)
+ # When disabled, only existing users can authenticate via LDAP.
+ # default: true
+ autoCreateUser: true
+ # autoCreatePermissions: Permissions assigned to users automatically created via LDAP.
+ # Applied only at user creation time when autoCreateUser is enabled.
+ # Has no effect on existing users.
+ # A complete list of permissions is available in the documentation: https://sync-in.com/docs/admin-guide/permissions
+ # e.g.: [personal_space, spaces_access] (array required)
+ # default: []
+ autoCreatePermissions: []
+ # adminGroup: Name of the LDAP group (CN) that grants Sync-in administrator privileges.
+ # If set, users whose LDAP `memberOf` contains this group name are assigned the administrator role.
+ # If not set, existing administrator users keep their role and it cannot be removed via LDAP.
+ # optional
+ adminGroup:
+ # enablePasswordAuthFallback: Allow local password authentication when LDAP authentication fails.
+ # When enabled, users can authenticate with their local password if the LDAP service is unavailable.
+ # Always allowed for administrator users (break-glass access).
+ # default: true
+ enablePasswordAuthFallback: true
oidc:
# issuerUrl: The URL of the OIDC provider's discovery endpoint
# Examples:
@@ -152,10 +177,10 @@ auth:
issuerUrl:
# clientId: OAuth 2.0 Client ID obtained from your OIDC provider
# required
- clientId: sync-in
+ clientId:
# clientSecret: OAuth 2.0 Client Secret obtained from your OIDC provider
# required
- clientSecret: changeClientSecret
+ clientSecret: changeOIDCClientSecret
# redirectUri: The callback URL where users are redirected after authentication
# This URL must be registered in your OIDC provider's allowed redirect URIs
# Example (API callback): https://sync-in.domain.com/api/auth/oidc/callback
@@ -174,15 +199,6 @@ auth:
# e.g.: [personal_space, spaces_access] (array required)
# default: []
autoCreatePermissions: []
- # autoRedirect: Automatically redirect users to the OIDC login flow.
- # When enabled, the login page is skipped and users are sent directly to the OIDC provider.
- # default: false
- autoRedirect: false
- # enablePasswordAuth: Enable local password-based authentication (login or email/password).
- # When enabled, users can sign in with their Sync-in password in addition to OIDC authentication.
- # Users must have signed in at least once and have a local password set.
- # default: true
- enablePasswordAuth: true
# adminRoleOrGroup: Name of the role or group that grants Sync-in administrator access
# Users with this value will be granted administrator privileges.
# The value is matched against `roles` or `groups` claims provided by the IdP.
@@ -190,6 +206,15 @@ auth:
# and require proper IdP mappers to be included in the ID token or UserInfo response.
# optional
adminRoleOrGroup:
+ # enablePasswordAuth: Enable local password-based authentication (login or email/password).
+ # When enabled, users can sign in with their Sync-in password in addition to OIDC authentication.
+ # Users must have signed in at least once and have a local password set.
+ # default: true
+ enablePasswordAuth: true
+ # autoRedirect: Automatically redirect users to the OIDC login flow.
+ # When enabled, the login page is skipped and users are sent directly to the OIDC provider.
+ # default: false
+ autoRedirect: false
# buttonText: Label displayed on the OIDC login button.
# default: Continue with OpenID Connect
buttonText: Continue with OpenID Connect