Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Linked Server Security Expand / Collapse
Author
Message
Posted Thursday, January 7, 2010 11:45 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Today @ 7:37 AM
Points: 271, Visits: 321
I do not really understand linked server security in sql server 2008. I have a SQL Server logon for the remote server. I do not want everyone to be able to access this though.

I can get the linked server to work by setting "Be made using this security context" under "For a login not defined in the list above, connections will" and providing the login and password.

What I would like to do is create the linked server with permissions only for a windows account with sysadmin priveledges. Then a stored procedure would access the data, owned by the same user, with the execute as owner permission set.

That is the theory. I have not been able to create the linked server. Would anyone be able to guide me to instructions on how to do this? I have checked BOL and it has not been helpful.

Thanks,
Brian.
Post #843774
Posted Thursday, January 7, 2010 11:57 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 3:42 PM
Points: 2,052, Visits: 3,545
The security issue is a good question. I wouldn't mind learning more about this myself.

As for how to link servers, I've had good luck with the sp_addlinkedserver SP. Did you come across this in BOL?
Post #843784
Posted Thursday, January 7, 2010 12:17 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Today @ 7:37 AM
Points: 271, Visits: 321
Yes, I have looked at sp_addlinkedserver. I'm not having trouble connecting the linked server though, just restricting it. If I open it up all the way it works but I can't get it to work for only one user.

Thanks.
Post #843803
Posted Thursday, January 7, 2010 2:02 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 2:14 PM
Points: 12,952, Visits: 32,476
there are a lot of options for linked server security; i've only used three ways, which i'll try to explain:



1: anyone accessing the linked server uses a specific logon from the other server. that's what you see in this screenshot; "for a login not listed above use ..."sa" or some specific user, who probably has way to much access, but is convenient as hell for a developer to get data from.

2. the line just above that, "Be made with the current logon's security context" which is pretty good security wise. if there are multiple servers in your organization, and i logged in as mydomain\lowell, the same credentials are used on the remote server...if i have access, great, if not, i can't get to anything i wasn't supposed to anyway.

3. the section at the top...you click "Add", and for example, if i login as "devuser", if i access the linked server, I might use the remote credentials for "webdev" , where a different logon "Accounting" might use a different remote user with access to more objects and elevated privileges.

the option "not be made" is so that if you are not on the list of impersonations at the top, there's no access. it sounds like this is what you wanted to do...add two users, "bob" and "sa"; noone else would have access except the sa user and bob.


Lowell

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #843870
Posted Friday, January 8, 2010 5:58 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Today @ 7:37 AM
Points: 271, Visits: 321
It is correct that I am trying to do #3. Unfortunately, I can't get it to work. I get the error: "Access to the remote server is denied because no login-mapping exists. (Microsoft SQL Server, Error: 7416)". I have read that it's mapping to a user rather than a login in the top screen. The problem is that they will not add windows logins to the remote server. I must map to a SQL Server login, which is how the first option works.

I'm beginning to think that the only way this will work is the first option. If that's the case, I will probably have to convert this to SSIS and have the procedure run the package. I'm pretty sure that will work but it's more moving parts than are necessary.

Thanks,
Brian.
Post #844222
Posted Friday, January 8, 2010 8:41 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 2:14 PM
Points: 12,952, Visits: 32,476
i see;
can't you go to the remote server, find the role that your user mydomainname\username is in, and then jsut add a SQL login to the same role?
then that logon would have the same permissions, and you can use the newly created sql logon for the linked server.


Lowell

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #844388
Posted Friday, January 8, 2010 10:19 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Today @ 7:37 AM
Points: 271, Visits: 321
The problem is that I don't have a mydomainname\username login on the remote sever. I must connect to that server with a SQL login. It's not the way I would do it but that part is out of my control. I was trying to map my domaim\user to a sql login but that doesn't work. It only maps to a user and tries to use your account to connect to the remote server, which fails in this case.
Post #844501
Posted Friday, January 8, 2010 10:36 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 2:14 PM
Points: 12,952, Visits: 32,476
I might be misreading your requirement, but what i guess that was what i was trying to say....
you have access to the remote server, right?

if you do, then you can create a role that has access to the specific database and tables your user needs. then create a logon and user that has that role.

then you can map your domain user on your regular server to use sql credentials via the linked server;


sample code, if you didn't use the GUI to do it on the remote server:
create database Whatever
GO
USE Whatever
--create the Role for my Dev guy
CREATE ROLE [WhateverDEVAdmins]
ALTER AUTHORIZATION ON SCHEMA::[db_ddladmin] TO [WhateverDEVAdmins]
ALTER AUTHORIZATION ON SCHEMA::[db_datareader] TO [WhateverDEVAdmins]
ALTER AUTHORIZATION ON SCHEMA::[db_datawriter] TO [WhateverDEVAdmins]
GRANT EXECUTE,ALTER TO [WhateverDEVAdmins]
--create role for my normal users
--now add specific users to nearly-Admins
IF NOT EXISTS (SELECT * FROM MASTER.dbo.syslogins WHERE name = N'myLinkedServerUser')
BEGIN
EXEC MASTER.dbo.sp_addlogin @loginame = N'myLinkedServerUser', @passwd = 'NotARealPassword', @defdb = N'WHATEVER', @deflanguage = N'us_english'
--add this user to permit read and write
END
USE [WHATEVER]
--make a user in the db for the matching login
CREATE USER [myLinkedServerUser] FOR LOGIN [myLinkedServerUser]
--add these logs to the role
EXEC sp_addrolemember N'WhateverDEVAdmins', N'myLinkedServerUser'




Lowell

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #844515
Posted Friday, January 8, 2010 11:30 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Today @ 7:37 AM
Points: 271, Visits: 321
Lowell, I ran the script you had verbatim. I still get the same error message using this sql server login. The issue is who the DOMAIN\USER is. If they have permissions on the server then it works fine. If they don't it doesn't.

What SQL Server may be doing behind the scenes is to login with the windows credentials and then do a setuser command. Since it can't do the first login it fails.

Thanks,
Brian.
Post #844566
Posted Tuesday, September 18, 2012 4:16 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Yesterday @ 12:26 AM
Points: 40, Visits: 345
Linked servers do not create logins\users, they map between them. What you are trying to do seems to be map a SQL Server login on the remote server to your windows login locally. This is fine but your Windows login must already have rights on the local server, and the SQL login must already be created and have rights on the remote server.
Post #1361051
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse