mirror of
https://github.com/spantaleev/matrix-docker-ansible-deploy.git
synced 2026-09-02 14:03:16 +00:00
Test matrix-element-admin with Molecule
This commit is contained in:
@@ -137,6 +137,7 @@
|
||||
"roles/custom/matrix-bridge-mautrix-whatsapp/defaults/main.yml",
|
||||
"roles/custom/matrix-bridge-postmoogle/defaults/main.yml",
|
||||
"roles/custom/matrix-client-element/defaults/main.yml",
|
||||
"roles/custom/matrix-element-admin/defaults/main.yml",
|
||||
"roles/custom/matrix-ketesa/defaults/main.yml",
|
||||
"roles/custom/matrix-static-files/defaults/main.yml",
|
||||
"roles/custom/matrix-synapse/defaults/main.yml",
|
||||
@@ -152,6 +153,7 @@
|
||||
"description": "Automerge minor bumps of explicitly approved components with a weight-bearing Molecule scenario (via branch push - no PR). This list is intentionally narrower than the patch rule: the scenario must exercise enough real behavior to be a useful compatibility gate across a minor release. A failure surfaces as a PR instead. Keep every entry backed by a scenario and the patch rule - bin/check-molecule-automerge-list.py (minor rule) enforces that.",
|
||||
"matchFileNames": [
|
||||
"roles/custom/matrix-authentication-service/defaults/main.yml",
|
||||
"roles/custom/matrix-element-admin/defaults/main.yml",
|
||||
"roles/custom/matrix-static-files/defaults/main.yml",
|
||||
"roles/custom/matrix-synapse-auto-compressor/defaults/main.yml"
|
||||
],
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
# SPDX-FileCopyrightText: 2026 Slavi Pantaleev
|
||||
#
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
---
|
||||
- name: Include roles for matrix-element-admin Molecule tests
|
||||
hosts: all
|
||||
become: true
|
||||
vars_files:
|
||||
- "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/../../../molecule-shared/playbook-context.yml"
|
||||
gather_facts: true
|
||||
tasks:
|
||||
- name: Include roles for matrix-element-admin Molecule tests
|
||||
ansible.builtin.include_role:
|
||||
name: "{{ role_name }}"
|
||||
public: true
|
||||
loop:
|
||||
- com.devture.ansible.role.playbook_help
|
||||
- com.devture.ansible.role.systemd_docker_base
|
||||
- "custom/{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }}"
|
||||
loop_control:
|
||||
loop_var: role_name
|
||||
|
||||
# The component role installs the unit; the full playbook's systemd service manager
|
||||
# starts it. Keep the role-scoped scenario at the same boundary and start it directly.
|
||||
- name: Ensure matrix-element-admin is started
|
||||
hosts: all
|
||||
become: true
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Ensure systemd daemon is reloaded
|
||||
ansible.builtin.systemd_service:
|
||||
daemon_reload: true
|
||||
|
||||
- name: Ensure the matrix-element-admin systemd service is started
|
||||
ansible.builtin.systemd_service:
|
||||
name: matrix-element-admin.service
|
||||
state: started
|
||||
@@ -0,0 +1,74 @@
|
||||
# SPDX-FileCopyrightText: 2026 Slavi Pantaleev
|
||||
#
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
---
|
||||
dependency:
|
||||
name: galaxy
|
||||
options:
|
||||
requirements-file: requirements.yml
|
||||
force: true
|
||||
driver:
|
||||
name: docker
|
||||
platforms:
|
||||
- name: matrix-element-admin-${MOLECULE_DISTRO:-ubuntu2604}-default
|
||||
image: "geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2604}-ansible:latest"
|
||||
command: ${MOLECULE_DOCKER_COMMAND:-""}
|
||||
volumes:
|
||||
- /sys/fs/cgroup:/sys/fs/cgroup:rw
|
||||
cgroupns_mode: host
|
||||
privileged: true
|
||||
pre_build_image: true
|
||||
provisioner:
|
||||
name: ansible
|
||||
config_options:
|
||||
defaults:
|
||||
callback_result_format: yaml
|
||||
inventory:
|
||||
group_vars:
|
||||
all:
|
||||
# verify.yml is a separate play where the role's defaults are out of scope.
|
||||
# Use a deliberately non-default storage path, not merely the value the role
|
||||
# derives from matrix_base_data_path, so its rendered support-file locations
|
||||
# and the systemd unit's --env-file/--label-file contract are exercised.
|
||||
matrix_element_admin_base_path: /matrix/molecule-element-admin
|
||||
|
||||
matrix_element_admin_container_network: matrix-element-admin-molecule
|
||||
|
||||
# Element Admin currently hardcodes browser asset paths to `/`, so the role
|
||||
# correctly rejects a non-root public prefix. Exercise non-default public
|
||||
# routing through the hostname, priority and plain-HTTP entrypoint instead.
|
||||
matrix_element_admin_hostname: element-admin-console.molecule.local
|
||||
matrix_element_admin_path_prefix: /
|
||||
matrix_element_admin_container_labels_traefik_enabled: true
|
||||
matrix_element_admin_container_labels_traefik_priority: 619
|
||||
matrix_element_admin_container_labels_traefik_entrypoints: web
|
||||
matrix_element_admin_container_labels_traefik_tls: false
|
||||
matrix_element_admin_container_labels_additional_labels: |
|
||||
molecule.element-admin.coverage=enabled
|
||||
|
||||
# The image's entrypoint embeds its browser configuration into index.html
|
||||
# from SERVER_NAME.
|
||||
# This differs from the role and application's defaults, making the live HTTP
|
||||
# response evidence that the rendered env file reached the process.
|
||||
matrix_element_admin_environment_variable_server_name: matrix-backend.molecule.local
|
||||
matrix_element_admin_environment_variables_additional_variables: |
|
||||
MOLECULE_ELEMENT_ADMIN_MARKER=environment-reached
|
||||
env:
|
||||
# Workaround for https://github.com/ansible/molecule/issues/4391
|
||||
ANSIBLE_ROLES_PATH: ${MOLECULE_PROJECT_DIRECTORY}/../..:/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:${ANSIBLE_HOME:-~/.ansible}/roles
|
||||
scenario:
|
||||
test_sequence:
|
||||
- dependency
|
||||
- cleanup
|
||||
- destroy
|
||||
- syntax
|
||||
- create
|
||||
- prepare
|
||||
- converge
|
||||
- idempotence
|
||||
- verify
|
||||
- cleanup
|
||||
- destroy
|
||||
verifier:
|
||||
name: ansible
|
||||
@@ -0,0 +1,56 @@
|
||||
# SPDX-FileCopyrightText: 2026 Slavi Pantaleev
|
||||
#
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
---
|
||||
- name: Prepare matrix-element-admin Molecule tests
|
||||
hosts: all
|
||||
become: true
|
||||
vars_files:
|
||||
- "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/../../../molecule-shared/playbook-context.yml"
|
||||
gather_facts: true
|
||||
tasks:
|
||||
- name: Ensure apt cache is updated
|
||||
ansible.builtin.apt:
|
||||
update_cache: true
|
||||
cache_valid_time: 600
|
||||
when: ansible_facts['os_family'] == 'Debian'
|
||||
|
||||
- name: Ensure required packages are installed
|
||||
ansible.builtin.package:
|
||||
name:
|
||||
- python3-requests
|
||||
- fuse-overlayfs
|
||||
state: present
|
||||
|
||||
- name: Ensure Docker is installed
|
||||
ansible.builtin.include_role:
|
||||
name: ansible-role-docker
|
||||
vars:
|
||||
docker_daemon_options:
|
||||
storage-driver: fuse-overlayfs
|
||||
|
||||
# matrix-base creates this identity in a full deployment. The role's file tasks
|
||||
# resolve owner and group by name, so the role-scoped test provides it directly.
|
||||
- name: Ensure the matrix group exists
|
||||
ansible.builtin.group:
|
||||
name: "{{ matrix_group_name }}"
|
||||
gid: "{{ matrix_user_gid }}"
|
||||
state: present
|
||||
|
||||
- name: Ensure the matrix user exists
|
||||
ansible.builtin.user:
|
||||
name: "{{ matrix_user_name }}"
|
||||
uid: "{{ matrix_user_uid }}"
|
||||
group: "{{ matrix_group_name }}"
|
||||
create_home: false
|
||||
system: true
|
||||
state: present
|
||||
|
||||
- name: Ensure the base data path exists
|
||||
ansible.builtin.file:
|
||||
path: "{{ matrix_base_data_path }}"
|
||||
state: directory
|
||||
owner: "{{ matrix_user_name }}"
|
||||
group: "{{ matrix_group_name }}"
|
||||
mode: "0750"
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../molecule-shared/requirements.yml
|
||||
@@ -0,0 +1,307 @@
|
||||
# SPDX-FileCopyrightText: 2026 Slavi Pantaleev
|
||||
#
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
---
|
||||
# Element Admin is a static browser client. Its real application root and the live
|
||||
# configuration embedded from the role's env file are the weight-bearing checks; no
|
||||
# homeserver or third-party credentials are needed for the process to start.
|
||||
- name: Verify matrix-element-admin
|
||||
hosts: all
|
||||
become: true
|
||||
vars_files:
|
||||
- "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/../../../molecule-shared/vars.yml"
|
||||
- "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/../../../molecule-shared/playbook-context.yml"
|
||||
vars:
|
||||
matrix_element_admin_root_body: "{{ matrix_element_admin_root_http.stdout_lines[:-1] | join('\n') }}"
|
||||
matrix_element_admin_runtime: "{{ (matrix_element_admin_container_inspect.stdout | from_json) | first }}"
|
||||
gather_facts: false
|
||||
|
||||
tasks:
|
||||
# Loading the pin from the role keeps this scenario coupled to the shipped image
|
||||
# without duplicating a version which could silently drift.
|
||||
- name: Load the role's defaults under a separate name
|
||||
ansible.builtin.include_vars:
|
||||
file: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/defaults/main.yml"
|
||||
name: matrix_element_admin_role_defaults
|
||||
|
||||
- name: Wait for the matrix-element-admin service to become active
|
||||
ansible.builtin.systemd_service:
|
||||
name: matrix-element-admin.service
|
||||
register: matrix_element_admin_service
|
||||
until: matrix_element_admin_service.status.ActiveState == 'active'
|
||||
retries: 30
|
||||
delay: 5
|
||||
failed_when: false
|
||||
|
||||
# Restart=always means ActiveState alone can be green while the container crash-loops.
|
||||
- name: Assert the service is active and has not restarted
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- matrix_element_admin_service.status.ActiveState == 'active'
|
||||
- matrix_element_admin_service.status.NRestarts is defined
|
||||
- matrix_element_admin_service.status.NRestarts | int == 0
|
||||
fail_msg: >-
|
||||
matrix-element-admin.service is
|
||||
{{ matrix_element_admin_service.status.ActiveState | default('unknown') }} after
|
||||
{{ matrix_element_admin_service.status.NRestarts | default('?') }} restart(s)
|
||||
success_msg: "matrix-element-admin.service is active and has not restarted"
|
||||
|
||||
# Probe over the dedicated container network. Publishing a host port only for the
|
||||
# test would diverge from how Traefik reaches the service in real installations.
|
||||
- name: Wait for Element Admin to serve its application root
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- docker
|
||||
- run
|
||||
- --rm
|
||||
- --network={{ matrix_element_admin_container_network }}
|
||||
- "{{ molecule_shared_image_curl }}"
|
||||
- --silent
|
||||
- --show-error
|
||||
- --write-out
|
||||
- "\nHTTP_STATUS=%{http_code}"
|
||||
- http://matrix-element-admin:8080/
|
||||
register: matrix_element_admin_root_http
|
||||
changed_when: false
|
||||
until: "'HTTP_STATUS=200' in matrix_element_admin_root_http.stdout"
|
||||
retries: 24
|
||||
delay: 5
|
||||
failed_when: false
|
||||
|
||||
- name: Assert the application root is real Element Admin HTML
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- matrix_element_admin_root_http.rc == 0
|
||||
- matrix_element_admin_root_http.stdout_lines[-1] == 'HTTP_STATUS=200'
|
||||
- matrix_element_admin_root_body | trim | length > 100
|
||||
- "'<!doctype html' in matrix_element_admin_root_body | lower"
|
||||
- "'element admin' in matrix_element_admin_root_body | lower"
|
||||
fail_msg: >-
|
||||
Element Admin did not return its application HTML from the container network
|
||||
(rc={{ matrix_element_admin_root_http.rc }}, status={{ matrix_element_admin_root_http.stdout_lines[-1] | default('missing') }})
|
||||
success_msg: "Element Admin serves its real application root over HTTP"
|
||||
|
||||
# The image entrypoint base64-embeds JSON in index.html from SERVER_NAME. Decode
|
||||
# that exact live value instead of trusting that the environment merely exists.
|
||||
- name: Extract the live configuration and application asset path
|
||||
ansible.builtin.set_fact:
|
||||
matrix_element_admin_embedded_config_base64: >-
|
||||
{{ matrix_element_admin_root_body | regex_search('(?<=window.APP_CONFIG_BASE64 = ")[^"]+(?=";)') }}
|
||||
matrix_element_admin_application_asset_path: >-
|
||||
{{ matrix_element_admin_root_body | regex_search('(?<=src=")[/]assets[/][^"]+(?=")') }}
|
||||
|
||||
- name: Decode the live Element Admin configuration
|
||||
ansible.builtin.set_fact:
|
||||
matrix_element_admin_embedded_config: >-
|
||||
{{ matrix_element_admin_embedded_config_base64 | b64decode | from_json }}
|
||||
|
||||
- name: Assert the live configuration carries the configured homeserver name
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- matrix_element_admin_embedded_config is mapping
|
||||
- matrix_element_admin_embedded_config.keys() | list == ['serverName']
|
||||
- matrix_element_admin_embedded_config.serverName == matrix_element_admin_environment_variable_server_name
|
||||
fail_msg: >-
|
||||
Element Admin's live embedded configuration does not carry the SERVER_NAME value rendered by the role
|
||||
success_msg: "The live application configuration carries the configured homeserver name"
|
||||
|
||||
# Fetch a hashed application bundle referenced by the live HTML. This exercises a
|
||||
# real non-root HTTP path without claiming support for an invalid public subpath.
|
||||
- name: Fetch a live Element Admin application asset
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- docker
|
||||
- run
|
||||
- --rm
|
||||
- --network={{ matrix_element_admin_container_network }}
|
||||
- "{{ molecule_shared_image_curl }}"
|
||||
- --silent
|
||||
- --show-error
|
||||
- --output
|
||||
- /dev/null
|
||||
- --write-out
|
||||
- "HTTP_STATUS=%{http_code}\nCONTENT_TYPE=%{content_type}\nSIZE=%{size_download}"
|
||||
- "http://matrix-element-admin:8080{{ matrix_element_admin_application_asset_path }}"
|
||||
register: matrix_element_admin_asset_http
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
|
||||
- name: Assert the non-root application asset is served
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- matrix_element_admin_asset_http.rc == 0
|
||||
- "'HTTP_STATUS=200' in matrix_element_admin_asset_http.stdout_lines"
|
||||
- matrix_element_admin_asset_http.stdout | regex_search('(?m)^CONTENT_TYPE=application/javascript(?:;|$)') is not none
|
||||
- matrix_element_admin_asset_http.stdout | regex_search('SIZE=([1-9][0-9]{2,})') is not none
|
||||
fail_msg: "Element Admin did not serve the application bundle referenced by its live HTML"
|
||||
success_msg: "Element Admin serves a real non-root application asset"
|
||||
|
||||
- name: Read the environment file the role rendered
|
||||
ansible.builtin.slurp:
|
||||
src: "{{ matrix_element_admin_base_path }}/env"
|
||||
register: matrix_element_admin_env_file
|
||||
|
||||
- name: Initialize the parsed environment
|
||||
ansible.builtin.set_fact:
|
||||
matrix_element_admin_env_parsed: {}
|
||||
|
||||
- name: Parse the rendered environment
|
||||
ansible.builtin.set_fact:
|
||||
matrix_element_admin_env_parsed: >-
|
||||
{{ matrix_element_admin_env_parsed | combine({item.split('=', 1)[0]: item.split('=', 1)[1]}) }}
|
||||
loop: "{{ (matrix_element_admin_env_file.content | b64decode).splitlines() | reject('equalto', '') }}"
|
||||
when: "'=' in item"
|
||||
no_log: true
|
||||
|
||||
- name: Assert the rendered environment carries the scenario settings
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- matrix_element_admin_env_parsed.SERVER_NAME == matrix_element_admin_environment_variable_server_name
|
||||
- matrix_element_admin_env_parsed.MOLECULE_ELEMENT_ADMIN_MARKER == 'environment-reached'
|
||||
fail_msg: "The parsed environment does not carry the scenario's values"
|
||||
success_msg: "The parsed environment carries the scenario's values"
|
||||
|
||||
- name: Read the labels file the role rendered
|
||||
ansible.builtin.slurp:
|
||||
src: "{{ matrix_element_admin_base_path }}/labels"
|
||||
register: matrix_element_admin_labels_file
|
||||
|
||||
- name: Initialize the parsed labels
|
||||
ansible.builtin.set_fact:
|
||||
matrix_element_admin_labels_parsed: {}
|
||||
|
||||
- name: Parse the rendered labels
|
||||
ansible.builtin.set_fact:
|
||||
matrix_element_admin_labels_parsed: >-
|
||||
{{ matrix_element_admin_labels_parsed | combine({item.split('=', 1)[0]: item.split('=', 1)[1]}) }}
|
||||
loop: "{{ (matrix_element_admin_labels_file.content | b64decode).splitlines() | reject('equalto', '') }}"
|
||||
when: "'=' in item"
|
||||
no_log: true
|
||||
|
||||
- name: Assert the rendered labels carry the public routing contract
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- matrix_element_admin_labels_parsed['traefik.enable'] == 'true'
|
||||
- matrix_element_admin_labels_parsed['traefik.docker.network'] == matrix_element_admin_container_network
|
||||
- matrix_element_admin_labels_parsed['traefik.http.services.matrix-element-admin.loadbalancer.server.port'] == '8080'
|
||||
- matrix_element_admin_labels_parsed['traefik.http.routers.matrix-element-admin.rule'] == 'Host(`element-admin-console.molecule.local`)'
|
||||
- matrix_element_admin_labels_parsed['traefik.http.routers.matrix-element-admin.priority'] == '619'
|
||||
- matrix_element_admin_labels_parsed['traefik.http.routers.matrix-element-admin.entrypoints'] == 'web'
|
||||
- matrix_element_admin_labels_parsed['traefik.http.routers.matrix-element-admin.tls'] == 'false'
|
||||
- matrix_element_admin_labels_parsed['molecule.element-admin.coverage'] == 'enabled'
|
||||
fail_msg: "The rendered labels do not carry the scenario's routing values"
|
||||
success_msg: "The rendered labels carry the scenario's routing values"
|
||||
|
||||
- name: Inspect the running Element Admin container
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- docker
|
||||
- container
|
||||
- inspect
|
||||
- matrix-element-admin
|
||||
register: matrix_element_admin_container_inspect
|
||||
changed_when: false
|
||||
|
||||
- name: Assert the configured environment reached the running container
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- "('SERVER_NAME=' ~ matrix_element_admin_environment_variable_server_name) in matrix_element_admin_runtime.Config.Env"
|
||||
- "'MOLECULE_ELEMENT_ADMIN_MARKER=environment-reached' in matrix_element_admin_runtime.Config.Env"
|
||||
fail_msg: "The running container environment does not carry the scenario's settings"
|
||||
success_msg: "The configured environment reached the running container"
|
||||
|
||||
- name: Assert the rendered labels reached the running container
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- matrix_element_admin_runtime.Config.Labels['traefik.enable'] == 'true'
|
||||
- matrix_element_admin_runtime.Config.Labels['traefik.docker.network'] == matrix_element_admin_container_network
|
||||
- matrix_element_admin_runtime.Config.Labels['traefik.http.routers.matrix-element-admin.priority'] == '619'
|
||||
- matrix_element_admin_runtime.Config.Labels['molecule.element-admin.coverage'] == 'enabled'
|
||||
fail_msg: "The running container does not carry the labels the role rendered"
|
||||
success_msg: "The rendered labels reached the running container"
|
||||
|
||||
- name: Assert the running container uses the exact image and version the role pins
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- matrix_element_admin_runtime.Config.Image == matrix_element_admin_expected_image
|
||||
fail_msg: >-
|
||||
The running container uses {{ matrix_element_admin_runtime.Config.Image }},
|
||||
expected {{ matrix_element_admin_expected_image }}
|
||||
success_msg: "The running container uses the exact image and version defaults/main.yml pins"
|
||||
vars:
|
||||
matrix_element_admin_expected_image: >-
|
||||
{{ matrix_element_admin_role_defaults.matrix_element_admin_container_image_registry_prefix_upstream_default }}element-admin:{{ matrix_element_admin_role_defaults.matrix_element_admin_version }}
|
||||
|
||||
- name: Assert the running container uses the configured UID and GID
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- matrix_element_admin_runtime.Config.User == (matrix_user_uid | string) ~ ':' ~ (matrix_user_gid | string)
|
||||
fail_msg: >-
|
||||
The running container uses {{ matrix_element_admin_runtime.Config.User }},
|
||||
expected {{ matrix_user_uid }}:{{ matrix_user_gid }}
|
||||
success_msg: "The running container uses the configured UID and GID"
|
||||
|
||||
- name: Assert the running container command contract
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- matrix_element_admin_runtime.Config.Entrypoint == ['/docker-entrypoint.sh']
|
||||
- matrix_element_admin_runtime.Config.Cmd == ['nginx', '-g', 'daemon off;']
|
||||
fail_msg: >-
|
||||
The running container has unexpected entrypoint/command values:
|
||||
{{ matrix_element_admin_runtime.Config.Entrypoint }} {{ matrix_element_admin_runtime.Config.Cmd }}
|
||||
success_msg: "The role preserves the image's Element Admin entrypoint and command"
|
||||
|
||||
- name: Assert the running container security contract
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- matrix_element_admin_runtime.HostConfig.ReadonlyRootfs is sameas true
|
||||
- matrix_element_admin_runtime.HostConfig.Privileged is sameas false
|
||||
- matrix_element_admin_runtime.HostConfig.CapAdd | default([], true) | length == 0
|
||||
- matrix_element_admin_runtime.HostConfig.CapDrop == ['ALL']
|
||||
fail_msg: "The Element Admin container is missing its read-only root or dropped capabilities"
|
||||
success_msg: "The Element Admin container has a read-only root and all capabilities dropped"
|
||||
|
||||
- name: Assert the intended writable path is a constrained tmpfs mount
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- matrix_element_admin_runtime.Mounts | length == 0
|
||||
- matrix_element_admin_runtime.HostConfig.Binds | default([], true) | length == 0
|
||||
- matrix_element_admin_runtime.HostConfig.Tmpfs.keys() | list == ['/tmp']
|
||||
- matrix_element_admin_runtime.HostConfig.Tmpfs['/tmp'] == 'rw,noexec,nosuid,size=1024m'
|
||||
fail_msg: "The running container does not have the role's exact /tmp tmpfs contract"
|
||||
success_msg: "The running container has the exact constrained /tmp tmpfs mount"
|
||||
|
||||
- name: Assert the running container is attached only to its dedicated network
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- matrix_element_admin_runtime.NetworkSettings.Networks is mapping
|
||||
- matrix_element_admin_runtime.NetworkSettings.Networks | length == 1
|
||||
- matrix_element_admin_container_network in matrix_element_admin_runtime.NetworkSettings.Networks
|
||||
fail_msg: >-
|
||||
Element Admin has unexpected network attachments:
|
||||
{{ matrix_element_admin_runtime.NetworkSettings.Networks.keys() | list }}
|
||||
success_msg: "The running container is attached only to its dedicated network"
|
||||
|
||||
- name: Ask Docker for Element Admin's published ports
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- docker
|
||||
- container
|
||||
- port
|
||||
- matrix-element-admin
|
||||
register: matrix_element_admin_published_ports
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
|
||||
- name: Assert the role publishes no host ports
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- matrix_element_admin_runtime.Config.ExposedPorts.keys() | list == ['8080/tcp']
|
||||
- matrix_element_admin_runtime.HostConfig.PortBindings | default({}, true) | length == 0
|
||||
- matrix_element_admin_published_ports.rc == 0
|
||||
- matrix_element_admin_published_ports.stdout | trim | length == 0
|
||||
fail_msg: >-
|
||||
Element Admin unexpectedly publishes a host port:
|
||||
{{ matrix_element_admin_published_ports.stdout | default('unknown') }}
|
||||
success_msg: "The role leaves Element Admin's HTTP port unpublished"
|
||||
Reference in New Issue
Block a user