-
Notifications
You must be signed in to change notification settings - Fork 376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
agent persist firewall scenario #2983
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,6 +140,7 @@ def create_environment_list(self) -> List[Dict[str, Any]]: | |
runbook_images = self._get_runbook_images(loader) | ||
|
||
skip_test_suites: List[str] = [] | ||
skip_test_suites_images: List[str] = [] | ||
for test_suite_info in loader.test_suites: | ||
if self.runbook.cloud in test_suite_info.skip_on_clouds: | ||
skip_test_suites.append(test_suite_info.name) | ||
|
@@ -149,7 +150,14 @@ def create_environment_list(self) -> List[Dict[str, Any]]: | |
else: | ||
images_info: List[VmImageInfo] = self._get_test_suite_images(test_suite_info, loader) | ||
|
||
skip_images_info: List[VmImageInfo] = self._get_test_suite_skip_images(test_suite_info, loader) | ||
if len(skip_images_info) > 0: | ||
skip_test_suite_image = f"{test_suite_info.name}: {','.join([i.urn for i in skip_images_info])}" | ||
skip_test_suites_images.append(skip_test_suite_image) | ||
|
||
for image in images_info: | ||
if image in skip_images_info: | ||
continue | ||
# 'image.urn' can actually be the URL to a VHD if the runbook provided it in the 'image' parameter | ||
if self._is_vhd(image.urn): | ||
marketplace_image = "" | ||
|
@@ -238,6 +246,9 @@ def create_environment_list(self) -> List[Dict[str, Any]]: | |
if len(skip_test_suites) > 0: | ||
self._log.info("Skipping test suites %s", skip_test_suites) | ||
|
||
if len(skip_test_suites_images) > 0: | ||
self._log.info("Skipping test suits run on images \n %s", '\n'.join([f"\t{skip}" for skip in skip_test_suites_images])) | ||
|
||
return environments | ||
|
||
def create_existing_vm_environment(self) -> Dict[str, Any]: | ||
|
@@ -440,6 +451,20 @@ def _get_test_suite_images(suite: TestSuiteInfo, loader: AgentTestLoader) -> Lis | |
unique[i.urn] = i | ||
return [v for k, v in unique.items()] | ||
|
||
@staticmethod | ||
def _get_test_suite_skip_images(suite: TestSuiteInfo, loader: AgentTestLoader) -> List[VmImageInfo]: | ||
""" | ||
Returns images that need to skip by the suite. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "to be skipped" |
||
|
||
A test suite may be reference multiple image sets and sets can intersect; this method eliminates any duplicates. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "may reference" |
||
""" | ||
skip_unique: Dict[str, VmImageInfo] = {} | ||
for image in suite.skip_on_images: | ||
image_list = loader.images[image] | ||
for i in image_list: | ||
skip_unique[i.urn] = i | ||
return [v for k, v in skip_unique.items()] | ||
|
||
def _get_location(self, suite_info: TestSuiteInfo, image: VmImageInfo) -> str: | ||
""" | ||
Returns the location on which the test VM for the given test suite and image should be created. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# | ||
# Iptable rules that agent add not persisted on reboot. So we use firewalld service if distro supports it otherwise agent creates custom service and only runs on boot before network up. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice description, thanks |
||
# so that attacker will not have room to contact the wireserver | ||
# This test verifies that either of the service is active. Ensure those rules are added on boot and working as expected. | ||
# | ||
name: "AgentPersistFirewall" | ||
tests: | ||
- "agent_persist_firewall/agent_persist_firewall.py" | ||
images: | ||
- "endorsed" | ||
- "endorsed-arm64" | ||
owns_vm: true # This vm cannot be shared with other tests because it modifies the firewall rules and agent status. | ||
# agent persist firewall service not running on flatcar distro since agent can't install custom service due to read only filesystem. | ||
# so skipping the test run on flatcar distro. | ||
# (2023-11-14T19:04:13.738695Z ERROR ExtHandler ExtHandler Unable to setup the persistent firewall rules: [Errno 30] Read-only file system: '/lib/systemd/system/waagent-network-setup.service) | ||
skip_on_images: | ||
- "flatcar" | ||
- "flatcar_arm64" | ||
- "debian_9" # TODO: Reboot is slow on debian_9. Need to investigate further. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Microsoft Azure Linux Agent | ||
# | ||
# Copyright 2018 Microsoft Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
from tests_e2e.tests.lib.agent_test import AgentVmTest | ||
from tests_e2e.tests.lib.agent_test_context import AgentVmTestContext | ||
from tests_e2e.tests.lib.logging import log | ||
from tests_e2e.tests.lib.ssh_client import SshClient | ||
|
||
|
||
class AgentPersistFirewallTest(AgentVmTest): | ||
""" | ||
This test verifies agent setup persist firewall rules using custom network setup service or firewalld service. Ensure those rules are added on boot and working as expected. | ||
""" | ||
|
||
def __init__(self, context: AgentVmTestContext): | ||
super().__init__(context) | ||
self._ssh_client: SshClient = self._context.create_ssh_client() | ||
|
||
def run(self): | ||
self._test_setup() | ||
# Test case 1: After test agent install, verify firewalld or network.setup is running | ||
self._verify_persist_firewall_service_running() | ||
# Test case 2: Perform reboot and ensure firewall rules added on boot and working as expected | ||
self._context.vm.restart(wait_for_boot=True, ssh_client=self._ssh_client) | ||
self._verify_persist_firewall_service_running() | ||
self._verify_firewall_rules_on_boot("first_boot") | ||
# Test case 3: Disable the agent(so that agent won't get started after reboot) | ||
# perform reboot and ensure firewall rules added on boot even after agent is disabled | ||
self._disable_agent() | ||
self._context.vm.restart(wait_for_boot=True, ssh_client=self._ssh_client) | ||
self._verify_persist_firewall_service_running() | ||
self._verify_firewall_rules_on_boot("second_boot") | ||
# Test case 4: perform firewalld rules deletion and ensure deleted rules added back to rule set after agent start | ||
self._verify_firewall_rules_readded() | ||
|
||
def _test_setup(self): | ||
log.info("Doing test setup") | ||
self._run_remote_test(self._ssh_client, f"agent_persist_firewall-test_setup {self._context.username}", | ||
use_sudo=True) | ||
log.info("Successfully completed test setup\n") | ||
|
||
def _verify_persist_firewall_service_running(self): | ||
log.info("Verifying persist firewall service is running") | ||
self._run_remote_test(self._ssh_client, "agent_persist_firewall-verify_persist_firewall_service_running.py", | ||
use_sudo=True) | ||
log.info("Successfully verified persist firewall service is running\n") | ||
|
||
def _verify_firewall_rules_on_boot(self, boot_name): | ||
log.info("Verifying firewall rules on {0}".format(boot_name)) | ||
self._run_remote_test(self._ssh_client, f"agent_persist_firewall-verify_firewall_rules_on_boot.py --user {self._context.username} --boot_name {boot_name}", | ||
use_sudo=True) | ||
log.info("Successfully verified firewall rules on {0}".format(boot_name)) | ||
|
||
def _disable_agent(self): | ||
log.info("Disabling agent") | ||
self._run_remote_test(self._ssh_client, "agent-service disable", use_sudo=True) | ||
log.info("Successfully disabled agent\n") | ||
|
||
def _verify_firewall_rules_readded(self): | ||
log.info("Verifying firewall rules readded") | ||
self._run_remote_test(self._ssh_client, "agent_persist_firewall-verify_firewalld_rules_readded.py", | ||
use_sudo=True) | ||
log.info("Successfully verified firewall rules readded\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"or image sets"