Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS RDS Creating users for databases

I have an RDS instance spun up in AWS, running SQL Server 2012. I am able to login and create new databases fine (Through SSMS and sqlcmd.exe).

The issue I'm facing is that I cannot create users for each of my application databases due to not having sufficient privileges on "godmode" account setup through the RDS creation process.

I have > 5 applications with their databases on this RDS instance and want to set it up so that each application has its own login and is a user ONLY to its own database.

I can create a login, but I cannot assign that login as a user to a database. Is this something that cannot be done? I'm aware that RDS has restrictions, but this seems like something that should be possible. My use case cannot be all that unique!

I'm attempting to set up the users like so:

DECLARE @Username nvarchar(255) = 'test1';
DECLARE @Password nvarchar(255) = 'sUp3rS3crEt';

USE [Application1] 

IF NOT EXISTS 
    (SELECT name  
     FROM master.sys.server_principals
     WHERE name = @Username)
BEGIN
    EXEC sp_addlogin @Username, @Password
END

BEGIN
EXEC sp_adduser @Username, @Username, 'db_owner'
END

which fails on sp_adduser with

Msg 15247, Level 16, State 1, Procedure sp_adduser, Line 35 [Batch Start Line 0] 
User does not have permission to perform this action.

Attempting to manually create a user through SSMS also fails on permission issues.

Is this actual expected behavior of RDS with Sql Server 2012?

like image 324
John Geddes Avatar asked Aug 25 '16 04:08

John Geddes


People also ask

How many users can connect to RDS?

By default, RD session host servers allow unlimited number of Remote Desktop Services sessions, and Remote Desktop for Administration allows two Remote Desktop Services sessions.

Is it possible for a user to have multiple Databases on RDS?

You can have up to 40 Amazon RDS DB instances, with the following limitations: 10 for each SQL Server edition (Enterprise, Standard, Web, and Express) under the "license-included" model. 10 for Oracle under the "license-included" model. 40 for MySQL, MariaDB, or PostgreSQL.

How do I create another master user for my Amazon RDS DB instance that is running PostgreSQL?

1. Create a new user by running the CREATE ROLE command: postgres=> CREATE ROLE new_master WITH PASSWORD 'password' CREATEDB CREATEROLE LOGIN; Note: Replace new_master and password with your user name and password.


2 Answers

I didn´t use sp_addlogin to create the login for the user. I did it like this and it worked.

CREATE LOGIN userName WITH PASSWORD = 'y0urPa$$w0rd'

Then I can do

CREATE USER userName FOR LOGIN userName WITH DEFAULT_SCHEMA=dbo

It is important to notice that sp_addlogin will soon be removed in future versions of SQL Server.

This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature. Use CREATE LOGIN instead.

https://docs.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-addlogin-transact-sql?view=sql-server-2017

Hope this helps

like image 171
Philipp Otto Avatar answered Oct 12 '22 02:10

Philipp Otto


So far I've never tried doing it via SQL, but has done it via SSMS few times without issue. Please try the following (login as the user you specified at AWS RDS console earlier):

  1. Create the login. Keep the "server roles" as "public".
  2. Under user mapping tab, map the newly created login to the particular database that you desire. Select "db_owner" as the role. I normally just leave the default schema to dbo but that's up to you.
like image 34
Calvin Boey Avatar answered Oct 12 '22 03:10

Calvin Boey