11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 29 • SECURING MYSQLwww.it-ebooks.infoThe <strong>MySQL</strong> Access Privilege SystemProtecting your data from unwarranted review, modification, or deletion—accidental or otherwise—should always be a primary concern. Yet balancing a secure database with an acceptable level of userconvenience and flexibility is often a difficult affair. The delicacy of this balance becomes obvious whenyou consider the wide array of access scenarios that might exist in any given environment. For example,what if a user requires modification privileges but not insertion privileges? How do you authenticate auser who might need to access the database from a number of different IP addresses? What if you wantto provide a user with read access to certain table columns and restrict access to the rest? Thankfully, the<strong>MySQL</strong> developers have taken these sorts of scenarios into account, integrating fully featuredauthentication and authorization capabilities into the server. This is commonly referred to as <strong>MySQL</strong>’sprivilege system, and it relies upon a special database named mysql which is present on all <strong>MySQL</strong>servers. In this section, I’ll explain how the privilege system works, referring to the roles the varioustables within this database play in implementing this powerful security feature. Following this overview,I’ll delve deeper into these tables, formally introducing their roles, contents, and structure.How the Privilege System Works<strong>MySQL</strong>’s privilege system is based on two general concepts:• Authentication: Is the user even allowed to connect to the server?• Authorization: Does the authenticated user possess adequate privileges to executethe desired query?Because authorization cannot take place without successful authentication, you can think of thisprocess as taking place in two stages.The Two Stages of Access ControlThe general privilege control process takes place in two distinct stages: connection authentication andrequest verification. Together, these stages are carried out in five distinct steps:1. <strong>MySQL</strong> uses the contents of the user table to determine whether the incomingconnection should be accepted or rejected. This is done by matching thespecified host and the user to a row contained within the user table. <strong>MySQL</strong>also determines whether the user requires a secure connection to connect, andwhether the number of maximum allowable connections per hour for thataccount has been exceeded. The execution of Step 1 completes theauthentication stage of the privilege control process.2. Step 2 initiates the authorization stage of the privilege control process. If theconnection is accepted, <strong>MySQL</strong> verifies whether the maximum allowablenumber of queries or updates per hour for that account has been exceeded.Next, the corresponding privileges as granted within the user table areexamined. If any of these privileges are enabled (set to y), then the user has theability to act in the capacity granted by that privilege for any database residingon that server. A properly configured <strong>MySQL</strong> server will likely have all of theseprivileges disabled, which causes Step 3 to occur.560

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!