Skip to content
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

Containers: test privileged mode #17793

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/main_containers.pm
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ sub load_image_tests_docker {
}
}

sub load_container_engine_privileged_mode {
my ($run_args) = @_;
loadtest('containers/privileged_mode', run_args => $run_args, name => $run_args->{runtime} . "_privileged_mode");
}

sub load_host_tests_podman {
my ($run_args) = @_;
# podman package is only available as of 15-SP1
Expand All @@ -93,6 +98,7 @@ sub load_host_tests_podman {
# In Public Cloud we don't have internal resources
load_image_test($run_args) unless is_public_cloud || is_alp;
load_3rd_party_image_test($run_args);
load_container_engine_privileged_mode($run_args);
loadtest 'containers/podman_bci_systemd';
loadtest 'containers/podman_pods';
# Default for ALP is Netavark
Expand All @@ -116,6 +122,7 @@ sub load_host_tests_docker {
# In Public Cloud we don't have internal resources
load_image_test($run_args) unless is_public_cloud || is_alp;
load_3rd_party_image_test($run_args);
load_container_engine_privileged_mode($run_args);
# Firewall is not installed in Public Cloud, JeOS OpenStack and MicroOS but it is in SLE Micro
loadtest 'containers/docker_firewall' unless (is_public_cloud || is_openstack || is_microos);
unless (is_sle("<=15") && is_aarch64) {
Expand Down
54 changes: 54 additions & 0 deletions tests/containers/privileged_mode.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# SUSE's openQA tests
#
# Copyright 2023 SUSE LLC
# SPDX-License-Identifier: FSFAP

# Package: podman
# Summary: Test container runtime privileged mode
# Maintainer: qa-c@suse.de

use Mojo::Base 'containers::basetest';
use testapi;
use serial_terminal 'select_serial_terminal';
use utils qw(validate_script_output_retry);
use containers::utils qw(reset_container_network_if_needed);

sub run {
my ($self, $args) = @_;
select_serial_terminal;

my $runtime = $args->{runtime};
my $engine = $self->containers_factory($runtime);
$self->{runtime} = $engine;
reset_container_network_if_needed($runtime);

my $image = "registry.suse.com/bci/bci-base:latest";

record_info('Test', 'Launch a container with privileged mode');
# /dev is only accessible in privileged mode
assert_script_run("$runtime run --rm --privileged $image ls /dev/bus");

# Mounting tmpfs only works in privileged mode because the read-only protection in the default mode
assert_script_run("$runtime run --rm --privileged $image mount -t tmpfs none /mnt");

# Capabilities are only available in privileged mode
my $capbnd = script_output("cat /proc/1/status | grep CapBnd");
validate_script_output("$runtime run --rm --privileged $image cat /proc/1/status | grep CapBnd", sub { m/$capbnd/ });
}

sub cleanup {
my ($self) = @_;
$self->{runtime}->cleanup_system_host();
}

sub post_run_hook {
my ($self) = @_;
$self->cleanup();
}

sub post_fail_hook {
my ($self) = @_;
$self->cleanup();
}

1;