lithnet / access-manager

Access Manager provides web-based access to local admin (LAPS) passwords, BitLocker recovery keys, and just-in-time administrative access to Windows computers in a modern, secure, and user-friendly way.
Other
238 stars 20 forks source link

Unable to find database after upgrading from 1.0.7941.0 to 2.0.8904 #176

Closed davyyd closed 1 year ago

davyyd commented 1 year ago

Describe the bug After completing the installation of Lithnet Access Manager Service (version 2.0.8904) over an existing installation of version 1.0.794, the Lithnet Access Manager service does not start.

To Reproduce Install version 2.0.8904 over version 1.0.794 Select the option to use a local installation of SQL Lite Check the Windows Services control panel, and attempt to start "Lithnet Access Manager Service" Note that access-manager-service.log reports "The database could not be found"

Expected behavior Expected the service to start and stay running

Screenshots

Access Manager installation

Logs access-manager-service.log

ryannewington commented 1 year ago

@davyyd

Thank you for reporting this. We're able to reproduce the issue using the conditions you described. There looks to be a bug in the installer. We will investigate further and let you know the results.

Ryan

ryannewington commented 1 year ago

@davyyd Thanks for your patience while we sorted this out. A new version of the installer has been provided which addresses this issue for future installs.

However, to fix your current installation, please run the following PowerShell command, which will create the database and configure the appropriate permissions. After doing so, restart the Lithnet Access Manager service and it should start correctly now.

$cmd = "USE [master]

IF NOT EXISTS (SELECT 1  
     FROM master.sys.server_principals
     WHERE name = 'NT Service\lithnetams')
BEGIN
    PRINT 'AMS service account login does not exist'
    CREATE LOGIN [NT Service\lithnetams] FROM WINDOWS;
    PRINT 'Created login for AMS Service account'
END
GO

IF NOT EXISTS (SELECT 1 FROM master.dbo.sysdatabases WHERE name = 'AccessManager')
BEGIN
    PRINT 'Database does not exist and will be created'

    DECLARE @data_path nvarchar(256);
    SET @data_path = (SELECT SUBSTRING(physical_name, 1, CHARINDEX(N'master.mdf', LOWER(physical_name)) - 1)
                    FROM master.sys.master_files
                    WHERE database_id = 1 AND file_id = 1);

    EXECUTE ('
    CREATE DATABASE [AccessManager]
     CONTAINMENT = NONE
     ON  PRIMARY 
    ( NAME = N''AccessManager'', FILENAME = `"' + @data_path + 'AccessManager.mdf`", SIZE = 1048576KB , FILEGROWTH = 131072KB )
     LOG ON 
    ( NAME = N''AccessManager_log'', FILENAME = `"' + @data_path + 'AccessManager.ldf`", SIZE = 524288KB , FILEGROWTH = 65536KB )

    ')
    PRINT 'Created Database'
    ALTER DATABASE [AccessManager] SET RECOVERY SIMPLE 
    PRINT 'Set DB recovery mode'
END
GO

USE [AccessManager]

IF NOT EXISTS (SELECT 1
                FROM [sys].[database_principals]
                WHERE [name] = N'NT Service\lithnetams')
BEGIN
    PRINT 'Database user for AMS service does not exist'
    CREATE USER [NT Service\lithnetams] FOR LOGIN [NT Service\lithnetams] 
    PRINT 'Created database user for AMS service'
END
GO

ALTER ROLE [db_owner] ADD MEMBER [NT Service\lithnetams]
"

Invoke-SqlCmd -Server .\AMS -Query $cmd  -Verbose
stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs.