Labs Acces Control
Labs Acces Control
In this lab, first you will learn how to manage MySQL user accounts and roles using phpMyAdmin graphical
user interface (GUI) tool. Then you will learn how to control access to MySQL databases and their objects.
Finally you will learn how to secure your data adding extra layer of security using data encryption.
Objectives
After completing this lab, you will be able to use the phpMyAdmin to:
To complete this lab you will utilize the MySQL relational database service available as part of the IBM
Skills Network Labs (SN Labs) Cloud IDE. SN Labs is a virtual lab environment used in this course.
You will use a modified version of the database for the lab, so to follow the lab instructions successfully
please use the database provided with the lab, rather than the database from the original source.
The following ERD diagram shows the schema of the World database:
about:blank 1/15
23/11/2024 08:37 about:blank
The first row is the table name, the second is the primary key, and the remaining items are any additional
attributes.
User management is the process of controlling which users are allowed to connect to the MySQL server and
what permissions they have on each database. phpMyAdmin does not handle user management, rather it
passes the username and password on to MySQL, which then determines whether a user is permitted to
perform a particular action. Within phpMyAdmin, administrators have full control over creating users,
viewing and editing privileges for existing users, and removing users.
1. Go to Skills Network Toolbox by clicking the following icon from the side by side launched Cloud
IDE.
2. From the Databases drop-down menu, click MySQL to open the MySQL service session tab.
3. Click the *Create button and wait until MySQL service session gets launched.
about:blank 2/15
23/11/2024 08:37 about:blank
The MySQL server will take a few moments to start. Once it is ready, you will see the green “Active” label
near the top of the window.
about:blank 3/15
23/11/2024 08:37 about:blank
NOTE: Whenever you are required to enter your MySQL service session password from the MySQL service
session tab at any step of the lab, copy the password by clicking on the small copy button on the right of the
password block. Paste the password into the terminal using Ctrl + V (Mac: ⌘ + V), and press Enter on the
keyboard. For security reasons, you will not see the password as it is entered on the terminal.
3. Click phpMyAdmin button from the mysql service session tab. You will see the phpMyAdmin GUI
tool.
4. In the tree-view, click New to create a new empty database. Then enter world as the name of the
database and click Create.
about:blank 4/15
23/11/2024 08:37 about:blank
5. Go to the Import tab. Upload the following sql script file using the Choose File button (first download
the following sql script file to your local computer storage). Then click Go button at the bottom. You
will be notified when the import successfully gets finished. Click the Home icon.
world_mysql_script_full.sql
about:blank 5/15
23/11/2024 08:37 about:blank
6. Now you will create a user account with custom role “db_owner”. Usually a user with db_owner role
has all global privileges and access to all exisitng databases. Go to the User accounts tab and click
Add user account.
about:blank 6/15
23/11/2024 08:37 about:blank
7. Fill the Login Information as shown in following image (enter your own password). Under Global
privileges, click Check all. Scroll down and click Go.
about:blank 7/15
23/11/2024 08:37 about:blank
about:blank 8/15
23/11/2024 08:37 about:blank
about:blank 9/15
23/11/2024 08:37 about:blank
Making an exception to the user definition of db_owner role you created earlier, you will modify privileges of
this user so that this user won’t be able to update other columns except a specifc column of a specific table of
a specific database. You will restrict db_owner from updating all the other columns except the column
Population of the table city of the database world.
1. Go to Home > User accounts tab. Click Edit privileges option of db_owner user name.
about:blank 10/15
23/11/2024 08:37 about:blank
3. Under Database-specific privileges, select Check all and click Go at the bottom.
4. Switch to Table sub-tab. Select the table city from the drop-down menu and click Go.
about:blank 11/15
23/11/2024 08:37 about:blank
5. Under Table-specific privileges, configure all the SQL commands and their custom access to the
columns of the table city as shown below. Then click Go. Such table-specific privilege configuration
will restrict db_owner from updating all the other columns except the column Population of the table
city of the database world.
In this example exercise, you will learn how to secure your data adding extra layer of security using data
encryption. There may be certain parts of your database containing sensitive information which should not be
stored in plain text. This is where encryption comes in.
You will implement encryption and decryption of a column in the world database using the official AES
(Advanced Encryption Standard) algorithm. AES is a symmetric encryption where the same key is used to
encrypt and decrypt the data. The AES standard permits various key lengths. By default, key length of 128-
bits is used. Key lengths of 196 or 256 bits can be used. The key length is a trade off between performance
and security. Let’s get started.
1. Click the MySQL CLI button from the mysql service session tab.
2. First, you will need to hash your passphrase (consider your passphrase is My secret passphrase) with a
specific hash length (consider your hash length is 512) using a hash function (here you will use hash
function from SHA-2 family). It is good practice to hash the passphrase you use, since storing the
passphrase in plaintext is a significant security vulnerability. Use the following command in the
terminal to use the SHA2 algorithm to hash your passphrase and assign it to the variable key_str:
3. Now, let’s take a look at the world database. First, you will want to connect to the database by entering
the following command in the CLI:
USE world;
4. Next, let’s take a quick look at the countrylanguage table in our database with the following
command:
about:blank 13/15
23/11/2024 08:37 about:blank
For demonstration purposes, suppose that the last column in the table, labeled Percentage contains sensitive
data, such as a citizen’s passport number. Storing such sensitive data in plain text is an enormous security
concern, so let’s go ahead and encrypt that column.
5. To encrypt the Percentage column, we will first want to convert the data in the column into binary byte
strings of length 255 by entering the following command into the CLI:
6. Now to actually encrypt the Percentage column, we use the AES encryption standard and our hashed
passphrase to execute the following command:
7. Let’s go ahead and see if the column was successfully encrypted by taking another look at the
countrylanguage table. We again run the same command as in step 4:
As you can see, the data on the Percentage column is encrypted and completely illegible.
8. The supposedly sensitive data is now encrypted and secured from prying eyes. However, we should still
have a way to access the encrypted data when needed. To do this, we use the AES_DECRYPT command,
and since AES is symmetric, we use the same key for both encryption and decryption. In our case,
recall that the key was a passphrase which was hashed and stored in the variable key_str. Suppose we
need to access the sensitive data in that column. We can do so by entering the following command in
the CLI:
about:blank 14/15
23/11/2024 08:37 about:blank
Scenario: You will modify privileges of the user db_owner you created in example exercise A such
a way that this user won’t be able to insert, update and delete any column of a specific table
country of the world database.
Summary
In this lab, first learned how to manage MySQL user accounts and roles using phpMyAdmin graphical user
interface (GUI) tool. You also learned how to control access to MySQL databases and their objects. Finally,
you learned how to secure your data adding extra layer of security using data encryption.
Congratulations! You have completed this lab, and you are ready for the next topic.
Author(s)
Sandip Saha Joy
Other Contributor(s)
David Pasternak
about:blank 15/15