Docsity

Database Security-Introduction to Database System-Lecture 18 Slides-Computer Science, Slides of Introduction to Database Management Systems

Toggle sidebar
bg1
1
Security and Integrit y G52DBS – Database System s
www.cs.nott.ac.uk/~smx/DBS
Database Security
• Database security is
about controlling
access to
informat ion
• Some information
should be available
freely
• Other information
should only be
available to certain
people or groups
• Many aspects to
consider for security
• Legal issues
• Physical security
• OS/Network security
• Security policies and
protocols
• Encryption and
passwords
•DBMS security
Security and Integrit y G52DBS – Database System s
www.cs.nott.ac.uk/~smx/DBS
DBMS Security Support
•DBMS can provide
some security
• Each user has an
account, username
and password
• These are used to
identify a user and
control their access to
information
•DBMS verifies
password and checks
a user’s permissions
when they try to
• Retrieve data
•Modify data
• Modify the database
structure
Security and Integrit y G52DBS – Database System s
www.cs.nott.ac.uk/~smx/DBS
Permissions and Privilege
• SQL uses privileges
to control access to
tables and other
database objects
• SELECT privilege
• INSERT privilege
• UPDATE privilege
• DELETE privilege
• The owner (creator)
of a database has all
privileges on all
objects in the
database, and can
grant these to others
• The owner (creator)
of an object has all
privileges on that
object and can pass
them on to others
Security and Integrit y G52DBS – Database System s
www.cs.nott.ac.uk/~smx/DBS
Privileges in SQL
GRANT <privileges>
ON <object>
TO <users>
[WITH GRANT OPTION]
•<privileges> is a list of
SELECT <columns>,
INSERT <columns>,
DELETE, and
UPDATE <columns>, or
simply ALL
•<users> is a list of user
names or PUBLIC
•<object> is the name of
a table or view (later)
•WITH GRANT OPTION
means that the users can
pass their privileges on
to others
Security and Integrit y G52DBS – Database System s
www.cs.nott.ac.uk/~smx/DBS
Privileges Examples
GRANT ALL ON Employee
TO Manager
WITH GRANT OPTION
The user ā€˜Manager’ can do
anything to the Employee
table, and can allow other
users to do the same (by
using GRANT statements)
GRANT SELECT,
UPDATE(Salary) ON
Employee TO Finance
The user ā€˜Finance’ can view
the entire Employee table,
and can change Salary
values, but cannot change
other values or pass on
their privilege
Security and Integrit y G52DBS – Database System s
www.cs.nott.ac.uk/~smx/DBS
Removing Privileges
• If you want to
remove a privilege
you have granted
you use
REVOKE <privileges>
ON <object>
FROM <users>
• If a user has the
same privilege from
other users then
they keep it
• All privileges
dependent on the
revoked one are also
revoked
pf3
pf4
pf5

Partial preview of the text

Download Database Security-Introduction to Database System-Lecture 18 Slides-Computer Science and more Slides Introduction to Database Management Systems in PDF only on Docsity!

Security and Integrity G52DBS – Database Systems www.cs.nott.ac.uk/~smx/DBS

Database Security

  • Database security is

about controlling

access to

information

  • Some information should be available freely
  • Other information should only be available to certain people or groups - Many aspects to

consider for security

  • Legal issues
  • Physical security
  • OS/Network security
  • Security policies and protocols
  • Encryption and passwords
  • DBMS security

Security and Integrity G52DBS – Database Systems www.cs.nott.ac.uk/~smx/DBS

DBMS Security Support

  • DBMS can provide

some security

  • Each user has an account, username and password
  • These are used to identify a user and control their access to information - DBMS verifies

password and checks

a user’s permissions

when they try to

  • Retrieve data
  • Modify data
  • Modify the database structure

Security and Integrity G52DBS – Database Systems www.cs.nott.ac.uk/~smx/DBS

Permissions and Privilege

  • SQL uses privileges

to control access to

tables and other

database objects

  • SELECT privilege
  • INSERT privilege
  • UPDATE privilege
  • DELETE privilege
    • The owner (creator) of a database has all privileges on all objects in the database, and can grant these to others
    • The owner (creator) of an object has all privileges on that object and can pass them on to others

Security and Integrity G52DBS – Database Systems www.cs.nott.ac.uk/~smx/DBS

Privileges in SQL

GRANT ON TO [WITH GRANT OPTION]

  • is a list of SELECT , INSERT , DELETE, and UPDATE , or simply ALL - is a list of user names or PUBLIC - is the name of a table or view (later)

    • WITH GRANT OPTION

    means that the users can pass their privileges on to others

    Security and Integrity G52DBS – Database Systems www.cs.nott.ac.uk/~smx/DBS

    Privileges Examples

    GRANT ALL ON Employee TO Manager WITH GRANT OPTION

    The user ā€˜Manager’ can do anything to the Employee table, and can allow other users to do the same (by using GRANT statements)

    GRANT SELECT,

    UPDATE(Salary) ON Employee TO Finance

    The user ā€˜Finance’ can view the entire Employee table, and can change Salary values, but cannot change other values or pass on their privilege

    Security and Integrity G52DBS – Database Systems www.cs.nott.ac.uk/~smx/DBS

    Removing Privileges

    • If you want to

    remove a privilege

    you have granted

    you use

    REVOKE ON FROM

    • If a user has the

    same privilege from

    other users then

    they keep it

    • All privileges

    dependent on the

    revoked one are also

    revoked

    Security and Integrity G52DBS – Database Systems www.cs.nott.ac.uk/~smx/DBS

    Removing Privileges

    • Example
      • ā€˜Admin’ grants ALL privileges to ā€˜Manager’, and SELECT to ā€˜Finance’ with grant option
      • ā€˜Manager’ grants ALL to Personnel
      • ā€˜Finance’ grants SELECT to Personnel

    Admin

    Finance Manager

    Personnel

    SELECT

    SELECT

    ALL

    ALL

    Security and Integrity G52DBS – Database Systems www.cs.nott.ac.uk/~smx/DBS

    SELECT ALL

    SELECT

    Removing Privileges

    Admin

    Finance Manager

    Personnel

    ALL

    • Manager’ revokes ALL

    from ā€˜Personnel’

    • ā€˜Personnel’ still has SELECT privileges from ā€˜Finance’
    • ā€˜Admin’ revokes

    SELECT from ā€˜Finance’

    • Personnel loses SELECT also

    Security and Integrity G52DBS – Database Systems www.cs.nott.ac.uk/~smx/DBS

    Views

    • Privileges work at

    the level of tables

    • You can restrict access by column
    • You cannot restrict access by row
    • Views, along with

    privileges, allow for

    customised access

    • Views provide

    ā€˜derived’ tables

    • A view is the result of a SELECT statement which is treated like a table
    • You can SELECT from (and sometimes UPDATE etc) views just like tables

    Security and Integrity G52DBS – Database Systems www.cs.nott.ac.uk/~smx/DBS

    Creating Views

    CREATE VIEW

    AS is a

    query that returns

    the rows and

    columns of the view

    • Example
      • We want each user to be able to view the names and phone numbers (only) of those employees in their own department

    Security and Integrity G52DBS – Database Systems www.cs.nott.ac.uk/~smx/DBS

    View Example

    • Example
      • We want each user to be able to view the names and phone numbers (only) of those employees in their own department
      • In Oracle, you can refer to the current user as USER

    Employee ID Name Phone Department Salary E158 Mark x6387 Accounts £15, E159 Mary x6387 Marketing £15, E160 Jane x6387 Marketing £15,

    Security and Integrity G52DBS – Database Systems www.cs.nott.ac.uk/~smx/DBS

    View Example

    CREATE VIEW OwnDept AS

    SELECT Name, Phone FROM Employee

    WHERE Department =

    (SELECT Department FROM Employee

    WHERE name = USER)

    GRANT SELECT ON OwnDept TO PUBLIC

    Security and Integrity G52DBS – Database Systems www.cs.nott.ac.uk/~smx/DBS

    Using Views and Privileges

    Create a view

    CREATE VIEW forJohn AS SELECT Name, Department FROM Employee

    Set the privileges

    GRANT SELECT,

    UPDATE (Department)

    ON forJohn

    TO John

    REVOKE ALL ON

    forJohn FROM John

    Security and Integrity G52DBS – Database Systems www.cs.nott.ac.uk/~smx/DBS

    Database Integrity

    • Security vs Integrity
      • Database security makes sure that the user is authorised to access information
      • Database integrity makes sure that (authorised) users use that information correctly - Integrity constraints - Domain constraints apply to data types - Attribute constraints apply to columns - Relation constraints apply to rows in a single table - Database constraints apply between tables

    Security and Integrity G52DBS – Database Systems www.cs.nott.ac.uk/~smx/DBS

    Domains and Attributes

    • Domains constraints are

    data types

    • SQL: CREATE DOMAIN

    (not in Oracle)

    CREATE DOMAIN Colour CHAR(15) CONSTRAINT checkCol CHECK (VALUE IN (ā€˜RED’,ā€˜Blue’…))

    • Attributes are

    constrained by their

    domains

    CREATE TABLE

    Rainbow ( Rorder Int, Rcolour Colour)

    Security and Integrity G52DBS – Database Systems www.cs.nott.ac.uk/~smx/DBS

    Assertions

    • Provide a way to

    give relation and

    database constraints

    • Give a boolean condition that must always be true
    • No action is permitted that would make the condition false
    • Again, not supported in Oracle

    CREATE ASSERTION

    CHECK (

    • The condition can refer to one or several tables
    • Often use EXISTS or NOT EXISTS

    Security and Integrity G52DBS – Database Systems www.cs.nott.ac.uk/~smx/DBS

    Relation Constraints

    • To create a relation

    constraint

    • We simply make an assertion that checks the constraint
    • Example: in an Employee table, no employee’s bonus should be more than 15% of their salary

    CREATE ASSERTION

    checkSalaryBonus

    CHECK (

    NOT EXISTS (

    SELECT *

    FROM EMPLOYEE

    WHERE (Bonus >

    0.15*Salary)

    Security and Integrity G52DBS – Database Systems www.cs.nott.ac.uk/~smx/DBS

    Database Constraints

    • Database constraints are similar but

    refer to several tables

    • Example: Given tables student and

    enrolment, make sure no CS student takes

    more than 12 modules

    ID Code

    Enrolment ID Name Department

    Student

    Security and Integrity G52DBS – Database Systems www.cs.nott.ac.uk/~smx/DBS

    Database Constraints

    CREATE ASSERTION CSEnrolment CHECK

    (NOT EXISTS (

    SELECT * FROM Student AS S

    WHERE S.Department = ā€˜CS’ AND

    ((SELECT COUNT(*) FROM

    Enrolment AS E

    WHERE S.ID = E.ID) > 12)))

    Security and Integrity G52DBS – Database Systems www.cs.nott.ac.uk/~smx/DBS

    Constraints in Oracle

    • Oracle does not

    support domains or

    assertions

    • It does, however,

    support row-level

    constraints using

    CHECK constraints

    • These are declared

    like other constraints

    CONSTRAINT

    CHECK

    ()

    • This is less general

    than an assertion

    since the condition

    refers to a single row

    of a single table

    Security and Integrity G52DBS – Database Systems www.cs.nott.ac.uk/~smx/DBS

    CHECK Example

    • To add a check on the Employee table

    to make sure no employee’s bonus is

    more than 15% of their salary

    ALTER TABLE Employee

    ADD CONSTRAINT checkSalaryBonus

    CHECK (Bonus < 0.15*Salary)