-
Notifications
You must be signed in to change notification settings - Fork 32
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
Use new Docker images in kitchen (Chef) tests to get Systemd activated #439
Comments
Working branch: feature-439-docker-images-systemd. |
Hi all! The required tasks are almost completed. On the following, we briefly describe the changes we applied to reach our goals in this issue. Folders/Files Re-structuring We first, decided to re-structure the folders/files in the folder kitchen/wazuh-chef. So it looks like:
Parameterization Variables Our parameterization variables are environment variables that will be assigned in execution time. These are:
Parameterized For each testing suite there will be a dedicated folder under the folder We parameterized the platforms:
- name: <%= ENV['PLATFORM'] %>_<%= ENV['RELEASE'] %>_kitchen_chef
driver_config:
image: <%= ENV['IMAGE'] %>
platform: <%= ENV['PLATFORM'] %>
forward: 443
publish_all: true
run_command: /sbin/init
privileged: true
volume:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
provision_command:
- sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config
- python -mplatform | grep -qi debian && apt-get install -y apt-transport-https gnupg2 || yum install -y openssl Parameterized We also parameterized the paths in
Centralized platform:
.
.
driver_config:
provision_command:
- sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config
- python -mplatform | grep -qi debian && apt-get install -y apt-transport-https gnupg2 || yum install -y openssl As you can see, the following command autoruns the corresponding command based on the OS distribution:
Errors and Issues to solve 1. AmazonLinux Hostname is not loaded by Chef. args = "-m #{agent_auth['host']} -p #{agent_auth['port']} -A #{agent_auth['name']}"
if agent_auth['auto_negotiate']
args << ' -a ' + agent_auth['auto_negotiate']
end With the error:
Looks like the hostname is not loaded correctly. 2. Docker images created by kitchen are not deleted automatically We noted that we did not set the corresponding configuration to delete the Docker images created by Kitchen. And to do so we set the feature driver:
name: docker
use_sudo: false
remove_images: true
use_internal_docker_network: true However, this is not working, as the latest version of
And this problem was reported in test-kitchen/kitchen-docker#338 and supposedly fixed in test-kitchen/kitchen-docker#340. To test the corresponding fix, we cloned the master branch of https://github.com/test-kitchen/kitchen-docker and replaced the installed gem by it. But it produced an error when creating the containers and it's reported and fixed here test-kitchen/kitchen-docker#356. Testing with the corresponding fork branch https://github.com/paulcalabro/kitchen-docker/tree/fix-ip-address-issue resolves the commented issue and delete the docker images, but it produce an exception which orginally is generated due to the changes made in test-kitchen/kitchen-docker#340.
We will continue working to fix such errors. Kr, Rshad |
Hi all! Regarding the error we got when deleting the corresponding Docker images, I created an issue to comment on the error test-kitchen/kitchen-docker#360 and I fixed it in my fork branch. A PR with the fix is created also test-kitchen/kitchen-docker#361 We also adapted the related Dockerfile so it uses our fork branch of
Kr, Rshad |
Hi all! Regarding the issue, we are facing with
To be sure that the
After investigating this issue, I found that it's probably related to that the Ohai attributes are no directly loaded, but needs some time, and so we need to delay the variable evaluation, and here comes the function But using the function lazy would help in our case as we do not want to delay the execution if all the tasks in the recipe
ruby_block guarantees that all the tasks included in it will run in execute "#{dir}/bin/agent-auth #{args}" do
timeout 30
ignore_failure node['ossec']['ignore_failure']
only_if { agent_auth['register'] == 'yes' && agent_auth['host'] && !File.size?("#{dir}/etc/client.keys") }
end
We noticed that after creating the corresponding instance for the Kr, Rshad |
Hi all! We decided to maintain the support for Ubuntu 14.04 in our tests, and so we needed to adapt the tests of testinfra as we added some new tests which use original functions of dist = host.system_info.distribution.lower()
release = host.system_info.release
manager = host.service("wazuh-manager")
if( not( (dist == 'ubuntu') and (release.startswith("14")) ) ):
with host.sudo():
assert manager.is_running
assert manager.is_enabled In this case, we add a conditional statement to avoid the execution of such funtions if the OS distribution is Regarding the issue we faced with We detected a related WARNING message in the logs:
This message indicates that Chef created a new identity to the instance and it does not recognize attributes then. A similar issue, we found in chef/ohai#397, but in this case it's related to Gento. To solve such issue, we finally decided to manually set the hostname for the agent registration. kr, Rshad |
Hi all! We added some new changes to finish the required tasks in this issue. AmazonLinux2 Hostname Issue To solve the issue caused when running the tests in The original attribute name in default['ossec']['agent_auth']['name'] = node['hostname'] In this case we need to replace sed -i 's/node\['.*hostname.*'\]/amazon_agent/g' ../cookbooks/wazuh_agent/attributes/authd.rb This command will be included in the auxiliary script kitchen/wazuh-chef/common/run.sh if [[ $PLATFORM == *"amazon"* ]]; then
sed -i 's/node\['.*hostname.*'\]/"amazon_agent"/g' "$COOKBOOKS_PATH/wazuh_agent/attributes/authd.rb"
fi
We also adapted platforms:
- name: <%= ENV['PLATFORM'] %>_<%= ENV['RELEASE'] %>_kitchen_chef
driver_config:
image: <%= ENV['IMAGE'] %>
platform: <%= ENV['PLATFORM'] %>
publish_all: true
run_command: <%= ENV['RUN_COMMAND'] %>
privileged: true
volume:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
provision_command:
- sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config
- awk -F= '/^NAME/{print $2}' /etc/os-release | grep -qi 'debian\|ubuntu' && apt-get install -y apt-transport-https gnupg2 ca-certificates|| yum install -y openssl In the case of "/usr/sbin/sshd -D -o UseDNS=no -o UsePAM=no -o PasswordAuthentication=yes -o UsePrivilegeSeparation=no -o PidFile=/tmp/sshd.pid" Which is the default value as the official documentation mentions here. For the rest of OS images (Ubuntu {16.04, 18.04}, Centos7 and AmazonLinux2) it's
Kr, Rshad |
Hi all! We set For more info, please check https://github.com/wazuh/wazuh-jenkins/issues/1202#issuecomment-584090248. Kr, Rshad |
Hi all!
We need to change the Docker images we use in
Kitchen
tests so we getSystemd
which fits better with Kitchen tests when checking the status of the service, or if it's enabled or disabled, etc .. .Tasks
Identify the proper Docker images.
Adapt
kitchen.yml
to use ENVIRONMENT variables.Adapt
run.sh
Adapt the corresponding tests.
Verify the changes
CentOS 7.
Amazon Linux 2.
Kr,
Rshad
The text was updated successfully, but these errors were encountered: