Security and User Authorization in SQL. Lu Chaojun, SJTU 2 Security Two aspects: –Users only see the data they’re supposed to; –Guard against malicious.

Slides:



Advertisements
Similar presentations
1 Datalog: Logic Instead of Algebra. 2 Datalog: Logic instead of Algebra Each relational-algebra operator can be mimicked by one or several Database Logic.
Advertisements

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Lecture 11: Datalog Tuesday, February 6, Outline Datalog syntax Examples Semantics: –Minimal model –Least fixpoint –They are equivalent Naive evaluation.
Chapter 23 Database Security and Authorization Copyright © 2004 Pearson Education, Inc.
1 Constraints, Triggers and Active Databases Chapter 9.
CSC 570 Notes for Chapter 10 Advanced Topics in Relational Databases.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Database Management System
Winter 2002Arthur Keller – CS 18015–1 Schedule Today: Feb. 28 (TH) u Datalog and SQL Recursion, ODL. u Read Sections , Project Part 6.
Winter 2002Arthur Keller – CS 18014–1 Schedule Today: Feb. 26 (T) u Datalog. u Read Sections Assignment 6 due. Feb. 28 (TH) u Datalog and SQL.
1 SQL Authorization Privileges Grant and Revoke Grant Diagrams.
CSE 636 Data Integration Datalog Rules / Programs / Negation Slides by Jeffrey D. Ullman.
1 Datalog Logical Rules Recursion SQL-99 Recursion.
1 SQL Authorization Privileges Grant and Revoke Grant Diagrams.
1 Query Languages: How to build or interrogate a relational database Structured Query Language (SQL)
System Administration Accounts privileges, users and roles
Security and Transaction Management Pertemuan 8 Matakuliah: T0413/Current Popular IT II Tahun: 2007.
Dec 15, 2003Murali Mani Transactions and Security B term 2004: lecture 17.
Cs3431 Transactions, Logging and Security. cs3431 Transactions: What and Why? A set of operations on a database must appear as one “unit”. Example: Consider.
Database Systems More SQL Database Design -- More SQL1.
Mid-term Class Review.
Logical Rules Recursion
Security and Integrity
Logical Query Languages Motivation: 1.Logical rules extend more naturally to recursive queries than does relational algebra. u Used in SQL recursion. 2.Logical.
Chapter 6: Integrity and Security Thomas Nikl 19 October, 2004 CS157B.
Database Systems Marcus Kaiser School of Computing Science Newcastle University.
CSE314 Database Systems More SQL: Complex Queries, Triggers, Views, and Schema Modification Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
Databases 1 8th lecture. Topics of the lecture Multivalued Dependencies Fourth Normal Form Datalog 2.
Recursive query plans for Data Integration Oliver Michael By Rajesh Kanisetti.
Lecture 7 Integrity & Veracity UFCE8K-15-M: Data Management.
Logical Query Languages Motivation: 1.Logical rules extend more naturally to recursive queries than does relational algebra. u Used in SQL recursion. 2.Logical.
Controlling User Access. Objectives After completing this lesson, you should be able to do the following: Create users Create roles to ease setup and.
Database Management COP4540, SCS, FIU Constraints and security in SQL (Ch. 8.6, Ch22.2)
Datalog Inspired by the impedance mismatch in relational databases. Main expressive advantage: recursive queries. More convenient for analysis: papers.
Unit III. Views A table that is derived from other tables Considered as a virtual table Does not store data.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Fall 2001Database Systems1 Triggers Assertions –Assertions describe rules that should hold for a given database. –An assertion is checked anytime a table.
SQL: Advanced topics Prof. Weining Zhang Cs.utsa.edu.
Module Coordinator Tan Szu Tak School of Information and Communication Technology, Politeknik Brunei Semester
Chapter 4: SQL Complex Queries Complex Queries Views Views Modification of the Database Modification of the Database Joined Relations Joined Relations.
View 1. Lu Chaojun, SJTU 2 View Three-level vision of DB users Virtual DB views DB Designer Logical DB relations DBA DBA Physical DB stored info.
Database Security. Multi-user database systems like Oracle include security to control how the database is accessed and used for example security Mechanisms:
Chapter 5 : Integrity And Security  Domain Constraints  Referential Integrity  Security  Triggers  Authorization  Authorization in SQL  Views 
Lu Chaojun, SJTU 1 Extended Relational Algebra. Bag Semantics A relation (in SQL, at least) is really a bag (or multiset). –It may contain the same tuple.
Chapter 13Introduction to Oracle9i: SQL1 Chapter 13 User Creation and Management.
Security and User Authorization in SQL CIS 4301 Lecture Notes Lecture /18/2006.
1 SQL Authorization (Chap. 8.7) Privileges Grant and Revoke Grant Diagrams.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 4: Intermediate.
SQL Triggers, Functions & Stored Procedures Programming Operations.
Database Security Database System Implementation CSE 507 Some slides adapted from Navathe et. Al.
Jennifer Widom Authorization. Jennifer Widom Authorization Database Authorization  Make sure users see only the data they’re supposed to see  Guard.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Controlling User Access
SQL Environment.
Privileges Grant and Revoke Grant Diagrams
Privileges Grant and Revoke Grant Diagrams
Privileges Grant and Revoke Grant Diagrams
SQL: Advanced Options, Updates and Views Lecturer: Dr Pavle Mogin
STRUCTURE OF PRESENTATION :
SQL Authorization Book: A First Course in Database Systems
Privileges Grant and Revoke Grant Diagrams
Authorization.
Session #, Speaker Name Database Privileges 11/29/2018.
אבטחת נתונים בסביבת SQL Data Security
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Privileges Grant and Revoke Grant Diagrams
Logic Based Query Languages
Chapter 8 Advanced SQL.
Datalog Inspired by the impedance mismatch in relational databases.
Presentation transcript:

Security and User Authorization in SQL

Lu Chaojun, SJTU 2 Security Two aspects: –Users only see the data they’re supposed to; –Guard against malicious users. How SQL control it? –Authorization ID –Privileges

Lu Chaojun, SJTU 3 Authorization ID An element of SQL environment A user or a group of users who may be granted some particular privileges on objects –User ID: personal security account on behalf of individuals, applications, system services Not defined in SQL standard regarding its creation –Role: a defined set of privileges CREATE ROLE Granted to users or other roles PUBLIC: a special built-in authorization ID

Lu Chaojun, SJTU 4 Authorization in A Session A session provides the authorization ID a context to execute SQL statements during the connection A session is associated with a user ID or a role name. On session initialization, session uid is determined by: –Explicit CONNECT TO … USER usr; –Implementation-defined manner

Lu Chaojun, SJTU 5 Authorization in A Session(cont.) In a session, embedded SQL, client module and SQL-invoked routines may specify authorization ID, so the current auth. ID is changing. –SESSION_USER: SQL session user ID –CURRENT_USER: the current user ID SET SESSION AUTHORIZATION… –CURRENT_ROLE: the current rolename SET ROLE…

Lu Chaojun, SJTU 6 Privileges Privileges are associated with authorization ID 9 types: SELECT, INSERT, DELETE, UPDATE: applied to a relation (base table or view) –SELECT, INSERT, UPDATE may be associated with a list of attributes. REFERENCES: the right to refer to relations in IC –May have attached list of attributes USAGE: the right to use some kinds of DB elements in ones’s own column definition TRIGGER: the right to define triggers on a relation EXECUTE: the right to execute PSM proc/func UNDER: the right to create subtypes of a UDT

Lu Chaojun, SJTU 7 selectinsertupdatedeletereftriggerusageexecunder Base table       View       Column      Domain  UDT   Character set  Collation  Trigger SQL-invoked routine  Method of UDT 

Lu Chaojun, SJTU 8 Obtaining Privileges Owner vs. granted user –SQL elements (e.g. schemas, modules) have an owner. –Owner has all privileges and may GRANT them to others

Lu Chaojun, SJTU 9 Ownership Establishment Three points –when creating a schema CREATE SCHEMA … AUTHORIZATION usr  usr is the owner of the schema;  If in a module def., then owner is module owner;  Otherwise, session uid. –when creating a module MODULE modname … AUTHORIZATION usr  usr is used as the current auth_id for the execution.  If no auth_id is defined, use session uid. –when initiating a session: explicit or implicit CONNECT TO svr AS conn AUTHORIZATION usr

Lu Chaojun, SJTU 10 Privilege-Checking Each schema, module, and session has an associated authorization ID. Let agent A operates on a DB element: A’s privileges derive from the current auth. ID that is either –auth. ID of the module that A is executing, if there is one; or –session auth. ID if not. We may execute the SQL operation only if the current auth. ID possesses all the privileges on the DB elements.

Lu Chaojun, SJTU 11 Principle 1 Privileges are always available if the data is owned by U and U is the current authorization ID. –Module owner is U; or when module has no owner, –Session owner is U. D-owner CAI M/S-owner U = U U data Module/Session

Lu Chaojun, SJTU 12 Principle 2 Privileges are available if the current auth. ID U has been granted those privileges by the owner of the data, or if the privileges have been granted to PUBLIC. data D-owner CAI M/S-owner O U U GRANT Module/Session

Lu Chaojun, SJTU 13 Principle 3 Executing a module owned by the owner of the data, or by someone who has been granted privileges on the data, makes the needed privileges available. One needs the EXECUTE privilege on the module itself. D-owner CAI M-owner S-owner O V O/U V data module GRANT session EXECUTE

Lu Chaojun, SJTU 14 Principle 4 Executing a publicly available module during a session whose auth. ID is that of a user with the needed privileges. D-owner CAI M-owner S-owner O O/U O/U data module GRANT session

Lu Chaojun, SJTU 15 Granting Privileges Syntax GRANT privileges ON DB-element TO users [WITH GRANT OPTION] –The granter must possess the privileges granted or more general privileges (with the grant option) –privileges: SELECT, INSERT, DELETE,... INSERT(A), UPDATE(A), … ALL PRIVILEGES –DB-element: usu. a relation. Other DB-element: e.g. ASSERTION myAssertion, TYPE myType, etc.

Lu Chaojun, SJTU 16 WITH GRANT OPTION Users having been granted WITH GRANT OPTION may grant equal or lesser privileges to other users. User AUser BUser C with grant option

Lu Chaojun, SJTU 17 Grant Diagram To keep track of both privileges and their origins Node: user/privilege –* = WITH GRANT OPTION –** = derived from ownership Arc: grants. If U1/Q grants P to U2, then U1 Q ** U2 P * Q is P or more general than P

Lu Chaojun, SJTU 18 Revoking Privileges Syntax REVOKE privileges ON DB-element FROM users [CASCADE | RESTRICT] –CASCADE: also revoke any privileges that were granted only because of the revoked privileges. Any node that is not accessible from some ownership node is also deleted. –RESTRICT: Revoke statement cannot be executed if it would result in the cascading revoking of any other privilege.

Lu Chaojun, SJTU 19 Revoking GRANT OPTION Syntax REVOKE GRANT OPTION FOR privilege ON relation FROM users [CASCADE | RESTRICT] –Only revoke the grant option, not the privilege itself.

Lu Chaojun, SJTU 20 Roles Syntax CREATE ROLE rolename [ WITH ADMIN { CURRENT_USER | CURRENT_ROLE}] DROP ROLE rolename

Recursion in SQL

Lu Chaojun, SJTU 22 Problem Why do we need recursion? Parent(person, parent) –Direct Ancestor(person,ancestor) –Indirect: transitive closure It saves space if we only store Parent and compute Ancestor when we need it.

Lu Chaojun, SJTU 23 Computation Find “parent of parent”  first,third (  R(first,second) (Parent)  R(second,third) (Parents)) Find “parent of parent of parent” –Join three copies of Parent Find i th grandparent by (i-1) joins: R i Find all ancestors up to i th :  i k=1 R k How to do infinite union? –Limit i not known

Lu Chaojun, SJTU 24 Recursive Rules in Datalog Dependency If P( ) ...Q( )..., we say IDB P depends on Q Dependency graph Nodes: IDB predicates Arc: P  Q if P depends on Q Recursive iff cycles –An IDB predicate appears in both the head and the body of rules

Lu Chaojun, SJTU 25 Example Example: define IDB Ancestors by ancestor(x,y)  parent(x,y) ancestor(x,y)  parent(x,z) AND ancestor(z,y)

Lu Chaojun, SJTU 26 Evaluation of Recursive Rules The following works when there is no negation: 1.Start by assuming all IDB relations are empty. 2.Repeatedly evaluate the rules using the EDB and the previous IDB, to get a new IDB. 3.End when no change to IDB.

Lu Chaojun, SJTU 27 Evaluation Algorithm Start: IDB = 0 Apply rules to IDB, EDB Change to IDB? no yes done

Lu Chaojun, SJTU 28 Example Sib(x,y)  Par(x,p) AND Par(y,p) AND x <> y Cousin(x,y)  Sib(x,y) Cousin(x,y)  Par(x,xp) AND Par(y,yp) AND Cousin(xp,yp) Let EDB Par( ) = Sib Cousin a   b c bc,ef  d e f bc,ef de,df

Lu Chaojun, SJTU 29 Recursion in SQL Since SQL:1999 WITH statement: –Define and use temporary relations, recursive or not. –Syntax WITH R AS definition_of_R query involving R –R is only available within WITH statement –We may define multiple temporary relations in one WITH statement.

Lu Chaojun, SJTU 30 Defining Recursive Relations WITH [RECURSIVE] R 1 AS query 1, [RECURSIVE] R n AS query n query involving R 1,...,R n and other relations –R 1,...,R n may be recursive or mutually recursive

Lu Chaojun, SJTU 31 Meaning 1. Compute R 1,...,R n 2. Evaluate query involving R 1,...,R n and other relations 3. Destroy R 1,...,R n

Lu Chaojun, SJTU 32 Example WITH RECURSIVE Ancestor(x,y) AS (SELECT person AS x, parent AS y FROM Parent) UNION (SELECT a.x, p.parent AS y FROM Ancestor a, Parent p WHERE a.y = p.person) SELECT y FROM Ancestor WHERE x = ‘James Bond’;

Lu Chaojun, SJTU 33 Example WITH Sib(x,y) AS SELECT p1.child, p2.child FROM Par p1, Par p2 WHERE p1.parent = p2.parent AND p1.child <> p2.child, RECURSIVE Cousin(x,y) AS Sib UNION (SELECT p1.child, p2.child FROM Par p1, Par p2, Cousin WHERE p1.parent = Cousin.x AND p2.parent = Cousin.y) SELECT y FROM Cousin WHERE x = ‘Sally’;

Lu Chaojun, SJTU 34 Legal SQL Recursion It is possible to define SQL recursions that do not have a meaning. The SQL standard restricts recursion so there is a meaning. Restrictions –Linear recursion P(x)  … P(x) … Only one subgoal is mutually recursive with head. –Monotonicity

Lu Chaojun, SJTU 35 Monotonicity If relation P is a function of relation Q (and perhaps other things), we say P is monotone in Q if adding tuples to Q cannot cause any tuple of P to be deleted. Examples: P = Q ∪ R P = σ a =10 (Q ) To be a legal SQL recursion, the definition of a recursive relation R may only involve the use of a mutually recursive relation S (S can be R itself) if that use is monotone in S.

Lu Chaojun, SJTU 36 Example: Meaningless Recursion EDB: R(x) = {(1)}. IDB: P(x)  R(x) AND NOT P(x). –Is (1) in P(x)? If so, the recursive rule says it is not. If not, the recursive rule says it is. IDB: P(x)  R(x) AND NOT Q(x) Q(x)  R(x) AND NOT P(x) –Is P(0) true? Two solutions: P={(0)} and Q={} P={} and Q={(0)}

Lu Chaojun, SJTU 37 Example For the Sib/Cousin example, there are three nodes: Sib, Cousin and SQ (the second term of the union in the rule for Cousin). –No nonmonotonicity, hence legal. Sib Cousin SQ

Lu Chaojun, SJTU 38 A Nonmonotonic Example Change the UNION to EXCEPT in the rule for Cousin. RECURSIVE Cousin(x,y) AS Sib EXCEPT (SELECT p1.child, p2.child FROM Par p1, Par p2, Cousin WHERE p1.parent = Cousin.x AND p2.parent = Cousin.y) Now, adding to the result of the subquery can delete Cousin facts; i.e. Cousin is nonmonotone in SQ.

Lu Chaojun, SJTU 39 Another Source Aggregation can also leads to nonmonotonicity. Example SELECT AVG(grade) FROM SC WHERE sno = ‘S1’; –Adding to SC a tuple that gives a new course of S1 will usually change the result, i.e. the old tuple is lost.

Lu Chaojun, SJTU 40 Nonmonotonicity Example WITH RECURSIVE P(x) AS (SELECT * FROM R) UNION (SELECT * FROM Q), RECURSIVE Q(x) AS SELECT SUM(x) FROM P SELECT * FROM P;