27
IT203 Unit 9: Database Security II Is It Secure? Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall Chapter8.1

IT203 Unit 9: Database Security II Is It Secure? Copyright © 2012 Pearson Education, Inc. Publishing as Prentice HallChapter8.1

Embed Size (px)

Citation preview

Page 1: IT203 Unit 9: Database Security II Is It Secure? Copyright © 2012 Pearson Education, Inc. Publishing as Prentice HallChapter8.1

IT203 Unit 9: Database Security IIIT203 Unit 9: Database Security II

Is It Secure?

Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall Chapter8.1

Page 2: IT203 Unit 9: Database Security II Is It Secure? Copyright © 2012 Pearson Education, Inc. Publishing as Prentice HallChapter8.1

Analyzing Security Needs

• One way to analyze the security needs of a database is to look at the security requirements of each type of database user.

• You can analyze those needs in terms of specific permissions on tables and objects.

Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall Chapter8.2

Page 3: IT203 Unit 9: Database Security II Is It Secure? Copyright © 2012 Pearson Education, Inc. Publishing as Prentice HallChapter8.1

Analysis Example

Table name SELECT INSERT UPDATE DELETE ConstraintsStudent Tutor X A public subset of

tutor infoCourse X StudentCourse Ethnicity Session X X* X* *Only for own

sessionsRequest X RequestNote X

Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall Chapter8.3

Page 4: IT203 Unit 9: Database Security II Is It Secure? Copyright © 2012 Pearson Education, Inc. Publishing as Prentice HallChapter8.1

Threat Analysis

• Threat analysis involves identifying all the ways a database can be harmed and then finding strategies to mitigate those threats.

• Databases can also be damaged by accidental actions.

• Analyzing threats is a complex and ongoing task.

Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall Chapter8.4

Page 5: IT203 Unit 9: Database Security II Is It Secure? Copyright © 2012 Pearson Education, Inc. Publishing as Prentice HallChapter8.1

Threat Analysis Example

Role StudentThreat DescriptionSELECT See private information of other studentsINSERT False or inaccurate information in Student table UPDATE False or inaccurate information in the Session

table, removing other students from scheduled sessions

DELETE --

Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall Chapter8.5

Page 6: IT203 Unit 9: Database Security II Is It Secure? Copyright © 2012 Pearson Education, Inc. Publishing as Prentice HallChapter8.1

Disaster Recovery

• Disaster recovery means planning for the worst.

• Disasters can be manmade, such as an attack by a hacker, or a major mistake by an administrator.

• Disasters can also be natural. Fires, floods, and earthquakes can destroy data.

Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall Chapter8.6

Page 7: IT203 Unit 9: Database Security II Is It Secure? Copyright © 2012 Pearson Education, Inc. Publishing as Prentice HallChapter8.1

Disaster Recovery Plan

• A disaster recovery plan is a plan for how to recover data and its availability after various possible disasters.

• A disaster recovery plan consists of policies and procedures for disaster prevention and recovery.

Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall Chapter8.7

Page 8: IT203 Unit 9: Database Security II Is It Secure? Copyright © 2012 Pearson Education, Inc. Publishing as Prentice HallChapter8.1

Policies

• Policies are rules for how to do things.• For instance, a business could have a

rule that all databases are backed up twice a day.

• Another policy could be that all backups are kept off site in some secure place.

Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall Chapter8.8

Page 9: IT203 Unit 9: Database Security II Is It Secure? Copyright © 2012 Pearson Education, Inc. Publishing as Prentice HallChapter8.1

Procedures

• Procedures are step-by-step instructions for how to do things.

• In a disaster plan, procedures are the step-by-step instructions for implementing a policy.

Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall Chapter8.9

Page 10: IT203 Unit 9: Database Security II Is It Secure? Copyright © 2012 Pearson Education, Inc. Publishing as Prentice HallChapter8.1

Backup Procedure Example• Maintain four portable hard drives.• Each morning, retrieve the two drives with the oldest backup

date.• Perform a full database backup to one of the drives at 11:00 AM.• Backup the log files to the hard drive.• Record the current date and time of the backup on the hard disk.• Send an employee to deposit the hard drive in a safety deposit

box at Westlake Security Co.• At closing, around 5:00 PM, do a full backup to the second hard

disk.• Back up the log files to the hard disk.• Record the date and time on the hard disk.• Send an employee to deposit the hard drive in a safety deposit

box at Westlake Security Co. (Westlake is open until 7 PM.)• If Westlake is closed the employee is to take the disk home and

deposit it when he or she drives in to work the next work day. Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall Chapter8.10

Page 11: IT203 Unit 9: Database Security II Is It Secure? Copyright © 2012 Pearson Education, Inc. Publishing as Prentice HallChapter8.1

Finding Solutions

• Implementing effective security measures can be very complex.

• You can use a mixture of schema roles and permissions.

• One approach is to build a layer of views and stored procedures to manage all user access.

Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall Chapter8.11

Page 12: IT203 Unit 9: Database Security II Is It Secure? Copyright © 2012 Pearson Education, Inc. Publishing as Prentice HallChapter8.1

Views

• Views are essentially stored queries.• Ideally, each view corresponds to a

particular “view” that a user has of the data.

• Views can be used to hide the underlying structure of the database.

• Views are accessed just like tables.

Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall Chapter8.12

Page 13: IT203 Unit 9: Database Security II Is It Secure? Copyright © 2012 Pearson Education, Inc. Publishing as Prentice HallChapter8.1

Syntax for a View

CREATE VIEW <ViewName>AS<Select query>

Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall Chapter8.13

Page 14: IT203 Unit 9: Database Security II Is It Secure? Copyright © 2012 Pearson Education, Inc. Publishing as Prentice HallChapter8.1

View ExampleCREATE VIEW vw_SessionsASSELECT TutorLastName AS [Tutor],StudentKey AS [Student],SessionDateKey AS [Date],SessionTimeKey AS [Time],CourseKey AS [Course]FROM Tutor tINNER JOIN [Session] sON t.TutorKey=s.TutorKeyWHERE SessionDateKey >=GetDate()

Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall Chapter8.14

Page 15: IT203 Unit 9: Database Security II Is It Secure? Copyright © 2012 Pearson Education, Inc. Publishing as Prentice HallChapter8.1

Stored Procedures

• Stored procedures consist of one or more SQL commands.

• They can take parameters from the user.• They allow all the commands to be

executed as a unit.• They allow error checking and validation

to help ensure a safe transaction.

Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall Chapter8.15

Page 16: IT203 Unit 9: Database Security II Is It Secure? Copyright © 2012 Pearson Education, Inc. Publishing as Prentice HallChapter8.1

Stored Procedure Syntax

CREATE PROC <Procedure Name><Parameter list>AS<SQL statements>

Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall Chapter8.16

Page 17: IT203 Unit 9: Database Security II Is It Secure? Copyright © 2012 Pearson Education, Inc. Publishing as Prentice HallChapter8.1

Stored Procedure ExampleCREATE PROCEDURE usp_StudentLogIn@studentKey nchar(10)ASIF EXISTS(SELECT *FROM studentWHERE studentKey=@studentKey)BEGINSELECT studentLastNameFROM StudentWHERE Studentkey=@studentKeyEND

Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall Chapter8.17

Page 18: IT203 Unit 9: Database Security II Is It Secure? Copyright © 2012 Pearson Education, Inc. Publishing as Prentice HallChapter8.1

A Few Stored Procedure Notes

• The following slides discuss a few of the features of stored procedures, specifically:– Parameters– Variables– If/else and blocks– Transactions and try/catch blocks

Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall Chapter8.18

Page 19: IT203 Unit 9: Database Security II Is It Secure? Copyright © 2012 Pearson Education, Inc. Publishing as Prentice HallChapter8.1

Parameters

• A parameter is a value passed to the stored procedure from the user.

• Parameters are listed after the CREATE statement and before the AS.

• All parameters start with the @ symbol and must be given a data type:

@studentKey nchar(10)

Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall Chapter8.19

Page 20: IT203 Unit 9: Database Security II Is It Secure? Copyright © 2012 Pearson Education, Inc. Publishing as Prentice HallChapter8.1

Variables

• Variables are declared after the AS keyword and must be assigned values internally.

• Variables are declared with the DECLARE keyword.

• Variables can be assigned values with the SET or SELECT keywords.

Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall Chapter8.20

Page 21: IT203 Unit 9: Database Security II Is It Secure? Copyright © 2012 Pearson Education, Inc. Publishing as Prentice HallChapter8.1

Variable Examples

DECLARE @CourseKey NCHAR(10)SELECT @CourseKey=CourseKeyFROM [Session]WHERE SessionDateKey=@SessionDateKeyAND SessionTimeKey=@SessionTimeKey

DECLARE @CurrentDate DateSET @CurrentDate=GetDate()

Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall Chapter8.21

Page 22: IT203 Unit 9: Database Security II Is It Secure? Copyright © 2012 Pearson Education, Inc. Publishing as Prentice HallChapter8.1

IF, ELSE, BEGIN, END

• It is possible to select among possibilities by using the IF and ELSE keywords.

• IF sets up the condition and what to do if the condition is true.

• ELSE describes what to do if the condition is false.

• BEGIN is used to mark the start of an IF or ELSE block.

• END is used to mark the end of the block.

Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall Chapter8.22

Page 23: IT203 Unit 9: Database Security II Is It Secure? Copyright © 2012 Pearson Education, Inc. Publishing as Prentice HallChapter8.1

If ExampleIF EXISTS(SELECT *FROM studentWHERE studentKey=@studentKey)BEGINSELECT studentLastNameFROM StudentWHERE Studentkey=@studentKeyEND

Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall Chapter8.23

Page 24: IT203 Unit 9: Database Security II Is It Secure? Copyright © 2012 Pearson Education, Inc. Publishing as Prentice HallChapter8.1

TRY CATCH TRANS

• TRY CATCH blocks can be used with transactions to catch any errors.

• The TRY tests the code for errors.• If there are no errors, the statements are

committed to the database.• If there are errors, the execution will go to

the CATCH block and roll back the transaction.

Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall Chapter8.24

Page 25: IT203 Unit 9: Database Security II Is It Secure? Copyright © 2012 Pearson Education, Inc. Publishing as Prentice HallChapter8.1

TRY CATCH ExampleBEGIN TRAN

BEGIN TRYUPDATE [Session]SET StudentKey=@StudentKeyWHERE

SessionDateKey=@SessionDateKeyAND SessionTimeKey=@SessionTimeKeyCOMMIT TRAN

END TRYBEGIN CATCH

ROLLBACK TRANEND CATCH

Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall Chapter8.25

Page 26: IT203 Unit 9: Database Security II Is It Secure? Copyright © 2012 Pearson Education, Inc. Publishing as Prentice HallChapter8.1

Documentation

• It is crucial to document the security setup.• Authentication types and policies should be

spelled out.• All roles and schema should be described.• All stored procedures and views should be

described.• Disaster plans and all policies and procedures

should be documented and readily available.

Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall Chapter8.26

Page 27: IT203 Unit 9: Database Security II Is It Secure? Copyright © 2012 Pearson Education, Inc. Publishing as Prentice HallChapter8.1

All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic,

mechanical, photocopying, recording, or otherwise, without the prior written permission of the publisher. Printed in the United States of America.

Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall