Sto cercando di trovare una combinazione di autorizzazioni che consentirà a un partner di vedere db schema ma non espone oggetti incluso il codice. Quindi,

  1. VISUALIZZA e SELEZIONA su TABELLE (chiavi incluse)
  2. Impedisci / NEGA su visualizzazioni, processi archiviati, funzioni.

Ho pensato di passare attraverso e negare i singoli oggetti, ma questo non proteggerà quelli appena creati.

Aggiunta considerazione: ho bisogno di farlo per lavorare in SQL Azure.

Risposta

È possibile creare un ruolo e quindi concedere / revocare le autorizzazioni. Qualsiasi utente che sia una parte del ruolo erediterà le autorizzazioni.

Di seguito è riportato un esempio per iniziare:

 -- Create the database role CREATE ROLE TableSelector AUTHORIZATION [dbo] GO ---- Grant access rights to a specific schema in the databas GRANT SELECT ON SCHEMA::dbo TO TableSelector GO -- Add an existing user to the new role created EXEC sp_addrolemember "TableSelector", "MyDBUser" GO -- Revoke access rights on a schema from a role DENY ALTER -- you can customize here ... ON SCHEMA::dbo TO TableSelector 

Risposta

Penso che forse hai solo bisogno di un elenco di oggetti consentiti. Questo può essere fatto in uno script come di seguito o nella definizione Ro le come descritto da Kin. Di seguito è riportato un esempio di concessione di diritti a un utente utilizzando una variabile di tabella che definisce lelenco di oggetti consentiti.

DECLARE @AllowedObjects AS TABLE( name SYSNAME ) INSERT INTO @AllowedObjects SELECT N"dbo.Table1" UNION SELECT N"dbo.Table2" DECLARE @name SYSNAME DECLARE names CURSOR FOR SELECT name FROM @AllowedObjects OPEN names FETCH NEXT FROM names INTO @name WHILE(@@FETCH_STATUS <> -1) BEGIN IF (@@FETCH_STATUS <> -2) BEGIN EXEC ("GRANT SELECT ON OBJECT::" + @name + " TO userName") END FETCH NEXT FROM names INTO @name END CLOSE names DEALLOCATE names 

Risposta

Alla fine ho usato i ruoli di datareader e datawriter per dare accesso ai dati. Quindi concesso VIEW DEFINITION con la procedura seguente. Sarà necessario ricordarsi di mantenerlo …

Grazie a tutti.

Create PROCEDURE GrantViewDefinitionOnTables (@login VARCHAR(30)) AS begin /* Included Object Types are: P - Stored Procedure V - View FN - SQL scalar-function TR - Trigger IF - SQL inlined table-valued function TF - SQL table-valued function U - Table (user-defined) */ SET NOCOUNT ON CREATE TABLE #runSQL (runSQL VARCHAR(2000) NOT NULL) --Declare @execSQL varchar(2000), @login varchar(30), @space char (1), @TO char (2) DECLARE @execSQL VARCHAR(2000), @space CHAR (1), @TO CHAR (2) SET @to = "TO" SET @execSQL = "Grant View Definition ON " SET @login = REPLACE(REPLACE (@login, "[", ""), "]", "") SET @login = "[" + @login + "]" SET @space = " " INSERT INTO #runSQL SELECT @execSQL + schema_name(schema_id) + "." + [name] + @space + @TO + @space + @login FROM sys.all_objects s -- Want the view permission to sp, view, trigger then add type code mention in above. eg: where type IN("P","V","FN",TR","IF","TF","U") WHERE type IN ("U") AND is_ms_shipped = 0 ORDER BY s.type, s.name SET @execSQL = "" Execute_SQL: SET ROWCOUNT 1 SELECT @execSQL = runSQL FROM #runSQL PRINT @execSQL --Comment out if you don"t want to see the output EXEC (@execSQL) DELETE FROM #runSQL WHERE runSQL = @execSQL IF EXISTS (SELECT * FROM #runSQL) GOTO Execute_SQL SET ROWCOUNT 0 DROP TABLE #runSQL end ------------------------ EXEC GrantViewDefinitionOnTables "MyDatabase" 

Commenti

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *