microsoft / microsoft/DacFx

Drop Certificate Login

Open
#303 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
C#
Stars
460
Forks
29
Avg merge
4d 9h
Merged PRs (30d)
7

Description

- SqlPackage or DacFx Version: 16.1.8089.0
- .NET Framework (Windows-only) or .NET Core: .NET Framework Version: 4.8.1 or later
- Environment (local platform and source/target platforms): Windows 11 | Visual Studio 2022 | SQL Server 2019

**Steps to Reproduce:**

There seems to be a bug in SSDT regarding the order of creating and removing logins based on a certificate.
SSDT tries to delete the certificate and create it again, although the certificate already exists in the database. Also, the certificate cannot be deleted because there is a logon based on the certificate.

PRINT N'Dropping Certificate [cerClrStrictSecurity]...';
GO

DROP CERTIFICATE [cerClrStrictSecurity];
GO

PRINT N'Creating Certificate [cerClrStrictSecurity]...';
GO

CREATE CERTIFICATE [cerClrStrictSecurity]
AUTHORIZATION [dbo]
FROM FILE = N'C:\clr\Personal\project_master\Security\Environments\Development\Certificates\ClrStrictSecurity.cer'
WITH PRIVATE KEY (FILE = N'C:\clr\Personal\project_master\Security\Environments\Development\Certificates\ClrStrictSecurity.pvk', DECRYPTION BY PASSWORD = N'*********');
GO

PRINT N'Creating Login [ClrStrictSecurity]...';
GO

CREATE LOGIN [ClrStrictSecurity]
FROM CERTIFICATE [cerClrStrictSecurity];
GO

PRINT N'Update complete.';
GO


Dropping Certificate [cerClrStrictSecurity]...
Msg 15559, Level 16, State 1, Line 47
Cannot drop certificate 'cerClrStrictSecurity' because there is a login mapped to it.
Creating Certificate [cerClrStrictSecurity]...
Msg 15232, Level 16, State 1, Line 55
A certificate with name 'cerClrStrictSecurity' already exists or this certificate already has been added to the database.
Creating Login [ClrStrictSecurity]...
Msg 33140, Level 16, State 1, Line 66
The login 'ClrStrictSecurity' could not be created because a login is already associated with certificate 'cerClrStrictSecurity'.
Update complete.

Completion time: 2023-07-15T12:25:32.9674231+02:00

**Did this occur in prior versions? If not - which version(s) did it work in?**

(DacFx/SqlPackage/SSMS/Azure Data Studio)

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the reported deployment with SqlPackage or DacFx 16.1.8089.0 on SQL Server 2019, using the certificate and login sequence shown in the issue. Trace how the deployment orders certificate and certificate-backed login changes; done means the deployment completes without attempting an invalid certificate drop or producing the reported errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, sql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.