diff --git a/instruqt-tracks/enhance-rhel-with-selinux/01-join-red-hat-developer-portal/assignment.md b/instruqt-tracks/enhance-rhel-with-selinux/01-join-red-hat-developer-portal/assignment.md new file mode 100644 index 00000000..557d4b9a --- /dev/null +++ b/instruqt-tracks/enhance-rhel-with-selinux/01-join-red-hat-developer-portal/assignment.md @@ -0,0 +1,17 @@ +--- +slug: join-red-hat-developer-portal +id: 4hgm3l0ym300 +type: challenge +title: Join Red Hat Developer at no cost +teaser: Join Red Hat Developer at no cost +tabs: +- title: Red Hat Login + type: browser + hostname: rhd-login +difficulty: "" +--- +Before you proceed with the next challenge, please take a moment to register for Red Hat Developer. If you already have a Red Hat account, you can use the same login credentials. + +This will help us assess user satisfaction and enable us to provide more curated content. + +Click on the `Check` button at the bottom once you have registered or logged in. diff --git a/instruqt-tracks/enhance-rhel-with-selinux/01-join-red-hat-developer-portal/check-rhd-login b/instruqt-tracks/enhance-rhel-with-selinux/01-join-red-hat-developer-portal/check-rhd-login new file mode 100644 index 00000000..53051468 --- /dev/null +++ b/instruqt-tracks/enhance-rhel-with-selinux/01-join-red-hat-developer-portal/check-rhd-login @@ -0,0 +1,41 @@ +#!/bin/bash +set -euxo pipefail +echo 'logincheck' +if [ "${LOGGEDIN-0}" = "1" ]; then + echo 'loggedin' + exit 0 +fi + +rm -f /home/user/checkResult.json +rm -f /home/user/checkAssets.json +rm -f /home/user/checkError.txt + + +echo 'dropdown check' +echo '{"location":{"conditions":[{"url":"redhat.com","condition":"contains"}]},"innerText":[{"selector":"html \u003e body","value":"Please click on Check button in the bottom right of your screen to continue with the Lab."}]}' > /home/user/checkAssets.json +until [ -f /home/user/checkResult.json ]; do + sleep 1 +done +if grep "SUCCESS" /home/user/checkResult.json; then + echo 'account dropdown' + exit 0 +fi + + +rm -f /home/user/checkResult.json +rm -f /home/user/checkAssets.json +rm -f /home/user/checkError.txt + + +echo 'email check' +echo '{"location":{"conditions":[]},"innerText":[{"selector":"html \u003e body","value":"Email address verification"}]}' > /home/user/checkAssets.json +until [ -f /home/user/checkResult.json ]; do + sleep 1 +done +cat /home/user/checkResult.json +if grep "SUCCESS" /home/user/checkResult.json; then + echo 'email validation' + exit 0 +fi +fail-message "Please login and click 'Check' button." +exit 1 \ No newline at end of file diff --git a/instruqt-tracks/enhance-rhel-with-selinux/02-selinux-modes/assignment.md b/instruqt-tracks/enhance-rhel-with-selinux/02-selinux-modes/assignment.md new file mode 100644 index 00000000..3ea7578b --- /dev/null +++ b/instruqt-tracks/enhance-rhel-with-selinux/02-selinux-modes/assignment.md @@ -0,0 +1,76 @@ +--- +slug: selinux-modes +id: 0eodsxi9otyv +type: challenge +title: SELinux modes +notes: +- type: text + contents: '## Register RHEL host using ''subscription-manager'' and verify status + of SELinux.' +tabs: +- title: Terminal + type: terminal + hostname: rhel +- title: Console + type: browser + hostname: console +difficulty: "" +--- +## Add Red Hat Subscription to host +- To view the current subscription status of host. + ``` + subscription-manager status + ``` +- Register the host using following command. +``` +subscription-manager register +``` +> [!IMPORTANT] +> If the subscription-manager registration fails, please proceed to the **console** tab, log in, and complete the form. +> Thereafter, attempt to register the host with subscription-manager again. + +- Attach the subscription to the server using the command below. +``` +subscription-manager attach +``` +## Explore SELinux modes +SELinux operates in three distinct modes: Enforcing, Permissive, and Disabled. + +- **Enforcing**: In this mode, SELinux actively enforces the defined security policies. Any violation triggers an immediate response, such as blocking unauthorized access or generating an alert. +- **Permissive**: In permissive mode, SELinux logs violations while enforcing policies and without actively blocking them. This mode is useful for identifying policy gaps before transitioning to full enforcement. +- **Disabled**: SELinux is turned off in disabled mode, and DAC becomes the primary access control mechanism. While this might be necessary for specific legacy applications, it's not recommended for systems requiring strong security. + +To check the current SELinux status +``` +sestatus +``` + +You will receive similar results on your terminal as shown below. +``` +SELinux status: enabled +SELinuxfs mount: /sys/fs/selinux +SELinux root directory: /etc/selinux +Loaded policy name: targeted +Current mode: enforcing +Mode from config file: enforcing +``` + +To make permanent changes, you have to configure the file located at /etc/selinux/config. +``` +cat /etc/selinux/config +``` +By default, SELinux in RHEL is set to **enforcing** mode, and the type is set to **targeted**, as shown below +``` +# This file controls the state of SELinux on the system. +# SELINUX= can take one of these three values: +# enforcing - SELinux security policy is enforced. +# permissive - SELinux prints warnings instead of enforcing. +# disabled - No SELinux policy is loaded. +SELINUX=enforcing +# SELINUXTYPE= can take one of these two values: +# targeted - Targeted processes are protected, +# mls - Multi Level Security protection. +SELINUXTYPE=targeted +``` + +After successful registration and exploration of SELinux modes, click on the **check** button. \ No newline at end of file diff --git a/instruqt-tracks/enhance-rhel-with-selinux/02-selinux-modes/check-rhel b/instruqt-tracks/enhance-rhel-with-selinux/02-selinux-modes/check-rhel new file mode 100644 index 00000000..09503a2e --- /dev/null +++ b/instruqt-tracks/enhance-rhel-with-selinux/02-selinux-modes/check-rhel @@ -0,0 +1,12 @@ +#!/bin/bash + +output=$(subscription-manager status) + +search_string="Unknown" + +if echo "$output" | grep -q "$search_string"; then + FAIL "Host is not registered using subscription-manager. Please redo the steps for registration." + exit -1 +else + exit 0 +fi diff --git a/instruqt-tracks/enhance-rhel-with-selinux/03-deploy-sample-app/assignment.md b/instruqt-tracks/enhance-rhel-with-selinux/03-deploy-sample-app/assignment.md new file mode 100644 index 00000000..bd56fa14 --- /dev/null +++ b/instruqt-tracks/enhance-rhel-with-selinux/03-deploy-sample-app/assignment.md @@ -0,0 +1,76 @@ +--- +slug: deploy-sample-app +id: ehrptptf6ius +type: challenge +title: Deploy sample app +notes: +- type: text + contents: '## Deploy sample Red Hat Developers website with httpd server' +tabs: +- title: Terminal + type: terminal + hostname: rhel +- title: Sample App + type: service + hostname: rhel + path: / + port: 80 +difficulty: "" +--- +Install the httpd server on the RHEL system using the following command: +``` +dnf install httpd -y +``` +Enable the httpd server and verify the status to ensure it's running. +``` +systemctl start httpd && systemctl status httpd +``` + +Press **q** to exit from status check mode on terminal + +Create a new **index.html** file in the following directory for the static website, effectively setting it up as a sample application. + +``` + cd /var/www/html/ +``` +Run the following command to create a index.html file with required content. +``` +cat << 'EOF' > index.html + + + +     +     +    Red Hat Developers + + +    
+        

Welcome to Red Hat Developers portal

+         +            Red Hat Developers Logo +         +    
+    
+        

+            Red Hat Developers is a platform for developers to access resources, tools, and information about Red Hat technologies. +        

+        

+            Visit the Red Hat Developers website to learn more. +        

+    
+     + + +EOF +``` +Visit the `Sample App` tab beside of terminal tab to check the running app trhought httpd server. +> [!NOTE] +> If the Red Hat Developers website is not visible, Kidly refresh the page ↻ + +Check the labels of the file using the following command. +``` +ls -lZ +``` +After successful deloyment of web page, click on the **check** button. \ No newline at end of file diff --git a/instruqt-tracks/enhance-rhel-with-selinux/03-deploy-sample-app/check-rhel b/instruqt-tracks/enhance-rhel-with-selinux/03-deploy-sample-app/check-rhel new file mode 100644 index 00000000..103454ce --- /dev/null +++ b/instruqt-tracks/enhance-rhel-with-selinux/03-deploy-sample-app/check-rhel @@ -0,0 +1,26 @@ +#!/bin/bash + +output=$(http://localhost:80) + +search_string="Red Hat Developers" + +if echo "$output" | grep -q "$search_string"; then + FAIL "The website is running Red Hat Developers." + exit 1 +else + exit 0 +fi + + +# #!/bin/bash +# # check + +# output=$(http://localhost:80) + +# search_string="Red Hat Developers" + +# echo "Checking the solution of the challenge" +# if [ echo "$output" | grep -q "$search_string" ]; then +# echo "FAIL: Your challenge failed because of [The website is running Red Hat Developers clone.]" +# exit 1 +# fi diff --git a/instruqt-tracks/enhance-rhel-with-selinux/04-untitled-challenge-juhe0f/assignment.md b/instruqt-tracks/enhance-rhel-with-selinux/04-untitled-challenge-juhe0f/assignment.md new file mode 100644 index 00000000..12edb8c4 --- /dev/null +++ b/instruqt-tracks/enhance-rhel-with-selinux/04-untitled-challenge-juhe0f/assignment.md @@ -0,0 +1,97 @@ +--- +slug: untitled-challenge-juhe0f +id: wulql96otgxg +type: challenge +title: Test SElinux security +notes: +- type: text + contents: '## Test the SELinux labeling with deployed app' +tabs: +- title: Terminal + type: terminal + hostname: rhel +- title: Sample App + type: service + hostname: rhel + path: / + port: 80 +difficulty: "" +--- +In this challenge, we will replace index.html and demonstrate SELinux's ability to block unexpected changes from causing system malfunction. + +Create a new index.html file and overwrite the existing one with it. +``` +cat << 'EOF' > index.html + + + +     +     +    Red Hat Developers + + +    
+        

Welcome to Red Hat Developers portal clone

+         +            Red Hat Developers Logo +         +    
+    
+        

+            Red Hat Developers is a platform for developers to access resources, tools, and information about Red Hat technologies. +        

+        

+            Visit the Red Hat Developers website to learn more. +        

+    
+     + + +EOF +``` + +Replace the existing index.html file with a duplicate index.html file using the following **mv** command. +``` +mv index.html /var/www/html/ +``` +Now visit the Sample App console tab again to check the app. This time web page is not visible and a **Forbidden ERROR** is shown. +> [!NOTE] +> Kindly refresh the page ↻. To see the changes. + +![image.png](..\assets\image.png) + +The issue is caused by the labels attached to the files. The label assigned to the previous index.html differs from the one assigned to the current index.html file. + +``` +cd /var/www/html/ +``` +Check the labels of this file. You may notice that the labels of this file are different compared to the last index.html. +``` +ls -lZ +``` + +To fix this issue we need to check with journalctl command as shown below. +``` +journalctl -b 0 +``` +This command will show us the root cause and necessary remediation or solution to fix this issue. + +Our issue is related to the index.html, so search it using following command in interactive mode of terminal. +``` +/index.html +``` +![](https://lh7-us.googleusercontent.com/lmB7PiVivfZkuZ6aH2RjweAbBvDhP7LmQJkAhZgKozJiXlz0ZcBtbArrolq31Y-_V4o4trSN-_xfvRNgHasx1ZlH8qpPUFa9h0xJ0VdQAoiLlcVB7VjLl98nP86byC_RHIcnYq1oFTGo_qD9mWxEcA) +Press **q** to exit from interactive mode in the terminal. + +To fix the labels use following comand. (The same command is recommended in the snapshot above.) + +``` +/sbin/restorecon -v /var/www/html/index.html +``` +After fixing the labels with the above command, please visit the `Sample App` tab and refresh it. You will be directed to the Red Hat Developer webpage. + +This lab is a good exercise to showcase how SELinux works with labeling, especially in Enforcing mode. + +We are done with activities of SELInux on RHEL machine, so click on the **check** button. \ No newline at end of file diff --git a/instruqt-tracks/enhance-rhel-with-selinux/04-untitled-challenge-juhe0f/check-rhel b/instruqt-tracks/enhance-rhel-with-selinux/04-untitled-challenge-juhe0f/check-rhel new file mode 100644 index 00000000..97d71d5a --- /dev/null +++ b/instruqt-tracks/enhance-rhel-with-selinux/04-untitled-challenge-juhe0f/check-rhel @@ -0,0 +1,26 @@ +# #!/bin/bash + +# output=$(http://localhost:80) + +# search_string="Red Hat Developers clone" + +# if echo "$output" | grep -q "$search_string"; then +# FAIL "The website is running Red Hat Developers clone." +# exit -1 +# else +# exit 0 +# fi + + +#!/bin/bash +# check + +output=$(http://localhost:80) + +search_string="Red Hat Developers clone" + +echo "Checking the solution of the challenge" +if [ echo "$output" | grep -q "$search_string" ]; then + echo "FAIL: Your challenge failed because of [The website is running Red Hat Developers clone.]" + exit 1 +fi \ No newline at end of file diff --git a/instruqt-tracks/enhance-rhel-with-selinux/04-untitled-challenge-juhe0f/setup-rhel b/instruqt-tracks/enhance-rhel-with-selinux/04-untitled-challenge-juhe0f/setup-rhel new file mode 100644 index 00000000..70c50091 --- /dev/null +++ b/instruqt-tracks/enhance-rhel-with-selinux/04-untitled-challenge-juhe0f/setup-rhel @@ -0,0 +1,4 @@ +#!/bin/bash +mv /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.d/welcome.conf_backup +# rm -f /etc/httpd/conf.d/welcome.conf +systemctl restart httpd diff --git a/instruqt-tracks/enhance-rhel-with-selinux/assets/image.png b/instruqt-tracks/enhance-rhel-with-selinux/assets/image.png new file mode 100644 index 00000000..817b1c9f Binary files /dev/null and b/instruqt-tracks/enhance-rhel-with-selinux/assets/image.png differ diff --git a/instruqt-tracks/enhance-rhel-with-selinux/assets/rhel.webp b/instruqt-tracks/enhance-rhel-with-selinux/assets/rhel.webp new file mode 100644 index 00000000..321b4b29 Binary files /dev/null and b/instruqt-tracks/enhance-rhel-with-selinux/assets/rhel.webp differ diff --git a/instruqt-tracks/enhance-rhel-with-selinux/config.yml b/instruqt-tracks/enhance-rhel-with-selinux/config.yml new file mode 100644 index 00000000..7652d756 --- /dev/null +++ b/instruqt-tracks/enhance-rhel-with-selinux/config.yml @@ -0,0 +1,15 @@ +version: "3" +virtualbrowsers: +- name: console + url: https://developers.redhat.com/content-gateway/link/3881693 +- name: rhd-login + url: https://developers.redhat.com/node/284339?auHash=5k9QV-yD0z-jAU7XkJyq1TUxhVyyZVLiuZz7tsfTz_s&offerid=3882356 +virtualmachines: +- name: rhel + image: projects/tmm-instruqt-11-26-2021/global/images/rhel-9-1-11-18-2022-4 + shell: /bin/bash + machine_type: n1-standard-1 + allow_external_ingress: + - https + - http + - high-ports diff --git a/instruqt-tracks/enhance-rhel-with-selinux/track.yml b/instruqt-tracks/enhance-rhel-with-selinux/track.yml new file mode 100644 index 00000000..6bc235a5 --- /dev/null +++ b/instruqt-tracks/enhance-rhel-with-selinux/track.yml @@ -0,0 +1,21 @@ +slug: enhance-rhel-with-selinux +id: rjdycaafkria +title: Enhance RHEL with SELinux +description: "" +icon: .\assets\rhel.webp +tags: +- rhel +- selinux +owner: openshift +developers: +- narathod@redhat.com +- nityadav@redhat.com +show_timer: true +timelimit: 1800 +lab_config: + overlay: false + width: 33 + position: right + feedback_recap_enabled: true + loadingMessages: true +checksum: "6612310405079298019"