Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Linked Server Security


Linked Server Security

Author
Message
Brian Carlson
Brian Carlson
Old Hand
Old Hand (320 reputation)Old Hand (320 reputation)Old Hand (320 reputation)Old Hand (320 reputation)Old Hand (320 reputation)Old Hand (320 reputation)Old Hand (320 reputation)Old Hand (320 reputation)

Group: General Forum Members
Points: 320 Visits: 465
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.
Ray K
Ray K
SSCrazy
SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)

Group: General Forum Members
Points: 2606 Visits: 4564
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?

+--------------------------------------------------------------------------------------+
‌Check out my blog at https://pianorayk.wordpress.com/
Brian Carlson
Brian Carlson
Old Hand
Old Hand (320 reputation)Old Hand (320 reputation)Old Hand (320 reputation)Old Hand (320 reputation)Old Hand (320 reputation)Old Hand (320 reputation)Old Hand (320 reputation)Old Hand (320 reputation)

Group: General Forum Members
Points: 320 Visits: 465
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.
Lowell
Lowell
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14959 Visits: 38977
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

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Brian Carlson
Brian Carlson
Old Hand
Old Hand (320 reputation)Old Hand (320 reputation)Old Hand (320 reputation)Old Hand (320 reputation)Old Hand (320 reputation)Old Hand (320 reputation)Old Hand (320 reputation)Old Hand (320 reputation)

Group: General Forum Members
Points: 320 Visits: 465
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.
Lowell
Lowell
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14959 Visits: 38977
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

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Brian Carlson
Brian Carlson
Old Hand
Old Hand (320 reputation)Old Hand (320 reputation)Old Hand (320 reputation)Old Hand (320 reputation)Old Hand (320 reputation)Old Hand (320 reputation)Old Hand (320 reputation)Old Hand (320 reputation)

Group: General Forum Members
Points: 320 Visits: 465
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.
Lowell
Lowell
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14959 Visits: 38977
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

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Brian Carlson
Brian Carlson
Old Hand
Old Hand (320 reputation)Old Hand (320 reputation)Old Hand (320 reputation)Old Hand (320 reputation)Old Hand (320 reputation)Old Hand (320 reputation)Old Hand (320 reputation)Old Hand (320 reputation)

Group: General Forum Members
Points: 320 Visits: 465
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.
SQL ROb
SQL ROb
SSC Rookie
SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)

Group: General Forum Members
Points: 48 Visits: 457
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.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search