Matrix Docker Ansible eploy
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

496 строки
27 KiB

  1. # SPDX-FileCopyrightText: 2026 Slavi Pantaleev
  2. #
  3. # SPDX-License-Identifier: AGPL-3.0-or-later
  4. ---
  5. # Proves the logged-out bridge starts, accepts the role-rendered configuration and
  6. # registration, migrates real Postgres and opens its appservice listener. Steam
  7. # credentials are deliberately outside the scenario boundary.
  8. - name: Verify matrix-bridge-steam
  9. hosts: all
  10. become: true
  11. vars_files:
  12. - "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/../../../molecule-shared/vars.yml"
  13. - "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/../../../molecule-shared/playbook-context.yml"
  14. vars:
  15. matrix_bridge_steam_config: "{{ matrix_bridge_steam_config_file.content | b64decode | from_yaml }}"
  16. matrix_bridge_steam_registration: "{{ matrix_bridge_steam_registration_file.content | b64decode | from_yaml }}"
  17. matrix_bridge_steam_labels_rendered: "{{ matrix_bridge_steam_labels_file.content | b64decode }}"
  18. matrix_bridge_steam_runtime: "{{ (matrix_bridge_steam_container_inspect.stdout | from_json) | first }}"
  19. gather_facts: false
  20. tasks:
  21. # A Renovate bump changes this source of truth and therefore the image expectation.
  22. - name: Load the role's defaults under a separate name
  23. ansible.builtin.include_vars:
  24. file: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/defaults/main.yml"
  25. name: matrix_bridge_steam_role_defaults
  26. - name: Wait for the Steam bridge service to become active
  27. ansible.builtin.systemd_service:
  28. name: matrix-steam-bridge.service
  29. register: matrix_bridge_steam_service
  30. until: matrix_bridge_steam_service.status.ActiveState == 'active'
  31. retries: 30
  32. delay: 5
  33. failed_when: false
  34. - name: Assert the service is active and has not restarted
  35. ansible.builtin.assert:
  36. that:
  37. - matrix_bridge_steam_service.status.ActiveState == 'active'
  38. - matrix_bridge_steam_service.status.NRestarts is defined
  39. - matrix_bridge_steam_service.status.NRestarts | int == 0
  40. fail_msg: >-
  41. matrix-steam-bridge.service is
  42. {{ matrix_bridge_steam_service.status.ActiveState | default('unknown') }} after
  43. {{ matrix_bridge_steam_service.status.NRestarts | default('?') }} restart(s)
  44. success_msg: "matrix-steam-bridge.service is active and has not restarted"
  45. - name: Wait for the bridge liveness endpoint
  46. ansible.builtin.command:
  47. argv:
  48. - docker
  49. - run
  50. - --rm
  51. - --network={{ matrix_bridge_steam_container_network }}
  52. - "{{ molecule_shared_image_curl }}"
  53. - --silent
  54. - --output
  55. - /dev/null
  56. - --write-out
  57. - "HTTP_STATUS=%{http_code}"
  58. - "http://matrix-steam-bridge:{{ matrix_bridge_steam_appservice_port }}/_matrix/mau/live"
  59. register: matrix_bridge_steam_live
  60. changed_when: false
  61. until: matrix_bridge_steam_live.rc == 0 and matrix_bridge_steam_live.stdout == 'HTTP_STATUS=200'
  62. retries: 24
  63. delay: 5
  64. failed_when: false
  65. - name: Wait for the bridge readiness endpoint
  66. ansible.builtin.command:
  67. argv:
  68. - docker
  69. - run
  70. - --rm
  71. - --network={{ matrix_bridge_steam_container_network }}
  72. - "{{ molecule_shared_image_curl }}"
  73. - --silent
  74. - --output
  75. - /dev/null
  76. - --write-out
  77. - "HTTP_STATUS=%{http_code}"
  78. - "http://matrix-steam-bridge:{{ matrix_bridge_steam_appservice_port }}/_matrix/mau/ready"
  79. register: matrix_bridge_steam_ready
  80. changed_when: false
  81. until: matrix_bridge_steam_ready.rc == 0 and matrix_bridge_steam_ready.stdout == 'HTTP_STATUS=200'
  82. retries: 24
  83. delay: 5
  84. failed_when: false
  85. - name: Assert the bridge is live and ready on the configured appservice port
  86. ansible.builtin.assert:
  87. that:
  88. - matrix_bridge_steam_live.rc == 0
  89. - matrix_bridge_steam_live.stdout == 'HTTP_STATUS=200'
  90. - matrix_bridge_steam_ready.rc == 0
  91. - matrix_bridge_steam_ready.stdout == 'HTTP_STATUS=200'
  92. fail_msg: >-
  93. Health probes returned live={{ matrix_bridge_steam_live.stdout | default('none') }} and
  94. ready={{ matrix_bridge_steam_ready.stdout | default('none') }}
  95. success_msg: "The bridge is live and ready on the configured appservice port"
  96. # This is the live homeserver-to-appservice half of the registration handshake.
  97. # It detects the old image-entrypoint mismatch, which generated unrelated tokens
  98. # under /app/data while the role's registration remained unused under /app/config.
  99. - name: Submit an empty appservice transaction with the configured token
  100. ansible.builtin.command:
  101. argv:
  102. - docker
  103. - run
  104. - --rm
  105. - --network={{ matrix_bridge_steam_container_network }}
  106. - "{{ molecule_shared_image_curl }}"
  107. - --silent
  108. - --show-error
  109. - --fail-with-body
  110. - --request
  111. - PUT
  112. - --header
  113. - "Content-Type: application/json"
  114. - --header
  115. - "Authorization: Bearer {{ matrix_bridge_steam_homeserver_token }}"
  116. - --data-binary
  117. - '{"events": [], "ephemeral": []}'
  118. - "http://matrix-steam-bridge:{{ matrix_bridge_steam_appservice_port }}/_matrix/app/v1/transactions/molecule-coverage"
  119. register: matrix_bridge_steam_transaction
  120. changed_when: false
  121. - name: Submit an appservice transaction with an invalid token
  122. ansible.builtin.command:
  123. argv:
  124. - docker
  125. - run
  126. - --rm
  127. - --network={{ matrix_bridge_steam_container_network }}
  128. - "{{ molecule_shared_image_curl }}"
  129. - --silent
  130. - --output
  131. - /dev/null
  132. - --write-out
  133. - "HTTP_STATUS=%{http_code}"
  134. - --request
  135. - PUT
  136. - --header
  137. - "Content-Type: application/json"
  138. - --header
  139. - "Authorization: Bearer definitely-wrong-molecule-token"
  140. - --data-binary
  141. - '{"events": [], "ephemeral": []}'
  142. - "http://matrix-steam-bridge:{{ matrix_bridge_steam_appservice_port }}/_matrix/app/v1/transactions/molecule-unauthorized"
  143. register: matrix_bridge_steam_transaction_unauthorized
  144. changed_when: false
  145. failed_when: false
  146. - name: Assert the live appservice accepts only the configured handshake token
  147. ansible.builtin.assert:
  148. that:
  149. - matrix_bridge_steam_transaction.rc == 0
  150. - matrix_bridge_steam_transaction.stdout | from_json == {}
  151. - matrix_bridge_steam_transaction_unauthorized.rc == 0
  152. - matrix_bridge_steam_transaction_unauthorized.stdout == 'HTTP_STATUS=401'
  153. fail_msg: "The live appservice did not enforce the role-rendered hs_token"
  154. success_msg: "The live appservice accepts the role-rendered hs_token and rejects another"
  155. - name: Query the authenticated Steam provisioning login flows
  156. ansible.builtin.command:
  157. argv:
  158. - docker
  159. - run
  160. - --rm
  161. - --network={{ matrix_bridge_steam_container_network }}
  162. - "{{ molecule_shared_image_curl }}"
  163. - --silent
  164. - --show-error
  165. - --fail-with-body
  166. - --header
  167. - "Authorization: Bearer {{ matrix_bridge_steam_provisioning_shared_secret }}"
  168. - "http://matrix-steam-bridge:{{ matrix_bridge_steam_appservice_port }}/_matrix/provision/v3/login/flows?user_id=%40alice%3Amolecule.local"
  169. register: matrix_bridge_steam_login_flows
  170. changed_when: false
  171. - name: Query the provisioning API with an invalid secret
  172. ansible.builtin.command:
  173. argv:
  174. - docker
  175. - run
  176. - --rm
  177. - --network={{ matrix_bridge_steam_container_network }}
  178. - "{{ molecule_shared_image_curl }}"
  179. - --silent
  180. - --output
  181. - /dev/null
  182. - --write-out
  183. - "HTTP_STATUS=%{http_code}"
  184. - --header
  185. - "Authorization: Bearer definitely-wrong-molecule-secret"
  186. - "http://matrix-steam-bridge:{{ matrix_bridge_steam_appservice_port }}/_matrix/provision/v3/login/flows?user_id=%40alice%3Amolecule.local"
  187. register: matrix_bridge_steam_login_flows_unauthorized
  188. changed_when: false
  189. failed_when: false
  190. - name: Assert the live provisioning API enforces auth and advertises Steam login
  191. ansible.builtin.assert:
  192. that:
  193. - matrix_bridge_steam_login_flows.rc == 0
  194. - (matrix_bridge_steam_login_flows.stdout | from_json).flows is sequence
  195. - (matrix_bridge_steam_login_flows.stdout | from_json).flows | length > 0
  196. - matrix_bridge_steam_login_flows_unauthorized.rc == 0
  197. - matrix_bridge_steam_login_flows_unauthorized.stdout == 'HTTP_STATUS=401'
  198. fail_msg: "The provisioning API did not enforce its secret or return Steam login flows"
  199. success_msg: "The provisioning API enforces its secret and returns Steam login flows"
  200. - name: Read the configuration the role rendered
  201. ansible.builtin.slurp:
  202. src: "{{ matrix_bridge_steam_config_path }}/config.yaml"
  203. register: matrix_bridge_steam_config_file
  204. - name: Assert the rendered configuration carries the appservice identity
  205. ansible.builtin.assert:
  206. that:
  207. - matrix_bridge_steam_config.homeserver.address == matrix_bridge_steam_homeserver_address
  208. - matrix_bridge_steam_config.homeserver.domain == matrix_bridge_steam_homeserver_domain
  209. - matrix_bridge_steam_config.homeserver.async_media
  210. - matrix_bridge_steam_config.appservice.id == 'steam'
  211. - matrix_bridge_steam_config.appservice.address == 'http://matrix-steam-bridge:8766'
  212. - matrix_bridge_steam_config.appservice.public_address == matrix_bridge_steam_appservice_public_address
  213. - matrix_bridge_steam_config.appservice.port == 8766
  214. - matrix_bridge_steam_config.appservice.bot.username == matrix_bridge_steam_appservice_bot_username
  215. - matrix_bridge_steam_config.appservice.bot.displayname == matrix_bridge_steam_appservice_bot_displayname
  216. - matrix_bridge_steam_config.appservice.bot.avatar == matrix_bridge_steam_appservice_bot_avatar
  217. - matrix_bridge_steam_config.appservice.as_token == matrix_bridge_steam_appservice_token
  218. - matrix_bridge_steam_config.appservice.hs_token == matrix_bridge_steam_homeserver_token
  219. fail_msg: "The rendered configuration does not carry the scenario's appservice identity"
  220. success_msg: "The rendered configuration carries the scenario's appservice identity"
  221. - name: Assert the rendered configuration carries non-default Steam behavior
  222. ansible.builtin.assert:
  223. that:
  224. - matrix_bridge_steam_config.network.displayname_template == matrix_bridge_steam_network_displayname_template
  225. - not matrix_bridge_steam_config.network.presence.enabled
  226. - matrix_bridge_steam_config.network.presence.inactivity_status == 'snooze'
  227. - matrix_bridge_steam_config.network.presence_topic.enabled
  228. - matrix_bridge_steam_config.network.presence_topic.rich_presence_enabled
  229. - matrix_bridge_steam_config.network.presence_topic.show_raw_tokens
  230. - matrix_bridge_steam_config.bridge.command_prefix == matrix_bridge_steam_command_prefix
  231. - matrix_bridge_steam_config.bridge.split_portals
  232. - matrix_bridge_steam_config.bridge.permissions['*'] == 'commands'
  233. - matrix_bridge_steam_config.bridge.permissions[matrix_bridge_steam_homeserver_domain] == 'admin'
  234. - matrix_bridge_steam_config.matrix.federate_rooms
  235. - matrix_bridge_steam_config.logging.min_level == matrix_bridge_steam_logging_level
  236. fail_msg: "The rendered configuration does not carry the scenario's Steam behavior"
  237. success_msg: "The rendered configuration carries the scenario's Steam behavior"
  238. - name: Assert the rendered configuration carries the cleanup policy
  239. ansible.builtin.assert:
  240. that:
  241. - matrix_bridge_steam_config.bridge.cleanup_on_logout.enabled
  242. - matrix_bridge_steam_config.bridge.cleanup_on_logout.manual.private == 'kick'
  243. - matrix_bridge_steam_config.bridge.cleanup_on_logout.manual.relayed == 'unbridge'
  244. - matrix_bridge_steam_config.bridge.cleanup_on_logout.manual.shared_no_users == 'delete'
  245. - matrix_bridge_steam_config.bridge.cleanup_on_logout.manual.shared_has_users == 'kick'
  246. - matrix_bridge_steam_config.bridge.cleanup_on_logout.bad_credentials.private == 'delete'
  247. - matrix_bridge_steam_config.bridge.cleanup_on_logout.bad_credentials.relayed == 'kick'
  248. - matrix_bridge_steam_config.bridge.cleanup_on_logout.bad_credentials.shared_no_users == 'unbridge'
  249. - matrix_bridge_steam_config.bridge.cleanup_on_logout.bad_credentials.shared_has_users == 'delete'
  250. fail_msg: "The rendered configuration does not carry the scenario's cleanup policy"
  251. success_msg: "The rendered configuration carries the scenario's cleanup policy"
  252. - name: Assert the rendered configuration carries integration and backfill settings
  253. ansible.builtin.assert:
  254. that:
  255. - matrix_bridge_steam_config.provisioning.shared_secret == matrix_bridge_steam_provisioning_shared_secret
  256. - matrix_bridge_steam_config.double_puppet.secrets['molecule.remote'] == 'molecule_steam_double_puppet_51d28a'
  257. - not matrix_bridge_steam_config.public_media.enabled
  258. - not matrix_bridge_steam_config.backfill.enabled
  259. - matrix_bridge_steam_config.backfill.max_initial_messages == 17
  260. - matrix_bridge_steam_config.backfill.max_catchup_messages == 29
  261. fail_msg: "The rendered configuration lost the scenario's integration or backfill settings"
  262. success_msg: "The rendered configuration carries the integration and backfill settings"
  263. - name: Assert the configuration points at the scenario's Postgres database
  264. ansible.builtin.assert:
  265. that:
  266. - matrix_bridge_steam_config.database.type == matrix_bridge_steam_database_engine
  267. - matrix_bridge_steam_database_username in matrix_bridge_steam_config.database.uri
  268. - matrix_bridge_steam_database_hostname in matrix_bridge_steam_config.database.uri
  269. - matrix_bridge_steam_database_name in matrix_bridge_steam_config.database.uri
  270. fail_msg: "The rendered database URI was not composed from the scenario's settings"
  271. success_msg: "The configuration points at the scenario's Postgres database"
  272. - name: Read the appservice registration the role rendered
  273. ansible.builtin.slurp:
  274. src: "{{ matrix_bridge_steam_config_path }}/registration.yaml"
  275. register: matrix_bridge_steam_registration_file
  276. - name: Assert the registration carries the configured handshake values
  277. ansible.builtin.assert:
  278. that:
  279. - matrix_bridge_steam_registration.id == 'steam'
  280. - matrix_bridge_steam_registration.as_token == matrix_bridge_steam_appservice_token
  281. - matrix_bridge_steam_registration.hs_token == matrix_bridge_steam_homeserver_token
  282. - matrix_bridge_steam_registration.sender_localpart == '_bot_' + matrix_bridge_steam_appservice_bot_username
  283. - matrix_bridge_steam_registration.url == 'http://matrix-steam-bridge:8766'
  284. fail_msg: "The registration does not carry the configured handshake values"
  285. success_msg: "The registration carries the configured handshake values"
  286. - name: Check for an entrypoint-generated registration in the writable data path
  287. ansible.builtin.stat:
  288. path: "{{ matrix_bridge_steam_data_path }}/registration.yaml"
  289. register: matrix_bridge_steam_generated_registration
  290. - name: Assert the image entrypoint did not generate a second registration
  291. ansible.builtin.assert:
  292. that:
  293. - not matrix_bridge_steam_generated_registration.stat.exists
  294. fail_msg: >-
  295. The image generated a second registration under the writable data path instead
  296. of consuming the role-rendered registration mounted under /app/config
  297. success_msg: "The image consumes the role-rendered registration without generating another"
  298. - name: Assert the registration namespaces cover only Steam ghosts and the bridge bot
  299. ansible.builtin.assert:
  300. that:
  301. - matrix_bridge_steam_ghost_regex | length > 0
  302. - matrix_bridge_steam_bot_regex | length > 0
  303. - matrix_bridge_steam_ghost_mxid is match(matrix_bridge_steam_ghost_regex)
  304. - matrix_bridge_steam_wrong_ghost_mxid is not match(matrix_bridge_steam_ghost_regex)
  305. - matrix_bridge_steam_bot_mxid is match(matrix_bridge_steam_bot_regex)
  306. fail_msg: "The registration namespaces do not cover only Steam ghosts and the bot"
  307. success_msg: "The registration namespaces cover only Steam ghosts and the bot"
  308. vars:
  309. matrix_bridge_steam_user_regexes: "{{ matrix_bridge_steam_registration.namespaces.users | map(attribute='regex') | list }}"
  310. matrix_bridge_steam_ghost_regex: "{{ matrix_bridge_steam_user_regexes | select('search', 'steam_') | first | default('') }}"
  311. matrix_bridge_steam_bot_regex: "{{ matrix_bridge_steam_user_regexes | reject('search', 'steam_') | first | default('') }}"
  312. matrix_bridge_steam_ghost_mxid: "@steam_76561198000000000:{{ matrix_bridge_steam_homeserver_domain }}"
  313. matrix_bridge_steam_wrong_ghost_mxid: "@discord_76561198000000000:{{ matrix_bridge_steam_homeserver_domain }}"
  314. matrix_bridge_steam_bot_mxid: "@{{ matrix_bridge_steam_appservice_bot_username }}:{{ matrix_bridge_steam_homeserver_domain }}"
  315. # Tables can appear only after DNS resolution, authentication and real migrations.
  316. - name: List the tables the bridge created in Postgres
  317. ansible.builtin.command:
  318. argv:
  319. - docker
  320. - exec
  321. - matrix-postgres-molecule
  322. - psql
  323. - --username={{ matrix_bridge_steam_database_username }}
  324. - --dbname={{ matrix_bridge_steam_database_name }}
  325. - --tuples-only
  326. - --no-align
  327. - "--command=SELECT tablename FROM pg_tables WHERE schemaname = 'public'"
  328. register: matrix_bridge_steam_tables
  329. changed_when: false
  330. - name: Assert the bridge migrated its schema into the configured database
  331. ansible.builtin.assert:
  332. that:
  333. - matrix_bridge_steam_tables.rc == 0
  334. - "'version' in matrix_bridge_steam_table_names"
  335. - "'portal' in matrix_bridge_steam_table_names"
  336. - "'message' in matrix_bridge_steam_table_names"
  337. - matrix_bridge_steam_table_names | length > 8
  338. fail_msg: >-
  339. The bridge did not migrate its schema into {{ matrix_bridge_steam_database_name }}
  340. (found {{ matrix_bridge_steam_table_names | length }} table(s): {{ matrix_bridge_steam_table_names | join(', ') }})
  341. success_msg: "The bridge migrated its schema into the configured database"
  342. vars:
  343. matrix_bridge_steam_table_names: "{{ matrix_bridge_steam_tables.stdout_lines | select | list }}"
  344. - name: Read the labels the role rendered
  345. ansible.builtin.slurp:
  346. src: "{{ matrix_bridge_steam_base_path }}/labels"
  347. register: matrix_bridge_steam_labels_file
  348. - name: Assert the labels route the exposed API to the configured appservice port
  349. ansible.builtin.assert:
  350. that:
  351. - "'traefik.enable=true' in matrix_bridge_steam_labels_rendered"
  352. - "'traefik.docker.network=' + matrix_bridge_steam_container_network in matrix_bridge_steam_labels_rendered"
  353. - "'traefik.http.services.matrix-steam-bridge.loadbalancer.server.port=8766' in matrix_bridge_steam_labels_rendered"
  354. - "'traefik.http.routers.matrix-steam-bridge-exposure.rule=Host(`steam-api.molecule.local`) && PathPrefix(`/bridges/steam-api`)' in matrix_bridge_steam_labels_rendered"
  355. - "'traefik.http.middlewares.matrix-steam-bridge-exposure-strip-prefix.stripprefix.prefixes=/bridges/steam-api' in matrix_bridge_steam_labels_rendered"
  356. - "'traefik.http.routers.matrix-steam-bridge-exposure.entrypoints=web' in matrix_bridge_steam_labels_rendered"
  357. - "'traefik.http.routers.matrix-steam-bridge-exposure.tls=false' in matrix_bridge_steam_labels_rendered"
  358. - "'matrix-steam-bridge-public-media' not in matrix_bridge_steam_labels_rendered"
  359. - "'molecule.steam.coverage=enabled' in matrix_bridge_steam_labels_rendered"
  360. fail_msg: "The rendered labels do not carry the scenario's exposure contract"
  361. success_msg: "The rendered labels carry the scenario's exposure contract"
  362. - name: Inspect the running Steam bridge container
  363. ansible.builtin.command:
  364. argv:
  365. - docker
  366. - container
  367. - inspect
  368. - matrix-steam-bridge
  369. register: matrix_bridge_steam_container_inspect
  370. changed_when: false
  371. - name: Assert the running container uses the exact image pinned by the role
  372. ansible.builtin.assert:
  373. that:
  374. - matrix_bridge_steam_runtime.Config.Image == matrix_bridge_steam_expected_image
  375. fail_msg: >-
  376. The running container uses {{ matrix_bridge_steam_runtime.Config.Image }}, expected
  377. {{ matrix_bridge_steam_expected_image }}
  378. success_msg: "The running container uses the exact image pinned by the role"
  379. vars:
  380. matrix_bridge_steam_expected_image: >-
  381. {{ matrix_bridge_steam_role_defaults.matrix_bridge_steam_container_image_registry_prefix_upstream_default }}jasonlaguidice/matrix-steam-bridge:{{ matrix_bridge_steam_role_defaults.matrix_bridge_steam_version }}
  382. - name: Assert the running container uses the playbook-supplied runtime
  383. ansible.builtin.assert:
  384. that:
  385. - matrix_bridge_steam_runtime.Config.User == (matrix_user_uid | string) ~ ':' ~ (matrix_user_gid | string)
  386. - matrix_bridge_steam_runtime.Config.Entrypoint == ['/app/entrypoint.sh']
  387. - matrix_bridge_steam_runtime.Config.Cmd == ['-r', '/app/config/registration.yaml', '--no-update']
  388. - matrix_bridge_steam_runtime.Config.WorkingDir == '/app'
  389. - "'CONFIG_FILE=/app/config/config.yaml' in matrix_bridge_steam_runtime.Config.Env"
  390. - "'REGISTRATION_FILE=/app/config/registration.yaml' in matrix_bridge_steam_runtime.Config.Env"
  391. - matrix_bridge_steam_runtime.HostConfig.RestartPolicy.Name == 'no'
  392. - matrix_bridge_steam_runtime.HostConfig.AutoRemove is sameas true
  393. - matrix_bridge_steam_runtime.HostConfig.LogConfig.Type == 'none'
  394. fail_msg: "The running container does not use the image entrypoint with the role's exact registration and lifecycle contract"
  395. success_msg: "The running container uses the image entrypoint with the role's exact registration and lifecycle contract"
  396. - name: Assert the running container has the intended privilege isolation
  397. ansible.builtin.assert:
  398. that:
  399. - matrix_bridge_steam_runtime.HostConfig.Privileged is sameas false
  400. - matrix_bridge_steam_runtime.HostConfig.CapAdd | default([], true) | length == 0
  401. - matrix_bridge_steam_runtime.HostConfig.CapDrop == ['ALL']
  402. fail_msg: "The running container does not have the intended privilege isolation"
  403. success_msg: "The running container drops all capabilities and is unprivileged"
  404. - name: Assert the running container carries the exact config and data mounts
  405. ansible.builtin.assert:
  406. that:
  407. - matrix_bridge_steam_config_mount | length > 0
  408. - matrix_bridge_steam_config_mount.Source == matrix_bridge_steam_config_path
  409. - not matrix_bridge_steam_config_mount.RW
  410. - matrix_bridge_steam_data_mount | length > 0
  411. - matrix_bridge_steam_data_mount.Source == matrix_bridge_steam_data_path
  412. - matrix_bridge_steam_data_mount.RW
  413. - matrix_bridge_steam_logs_mount | length > 0
  414. - matrix_bridge_steam_logs_mount.Type == 'volume'
  415. - matrix_bridge_steam_logs_mount.RW
  416. - matrix_bridge_steam_runtime.Mounts | length == 3
  417. fail_msg: "The running container does not carry the expected role and upstream image mounts"
  418. success_msg: "The running container carries read-only config, writable data, and the upstream logs volume"
  419. vars:
  420. matrix_bridge_steam_config_mount: >-
  421. {{ matrix_bridge_steam_runtime.Mounts
  422. | selectattr('Destination', 'equalto', '/app/config')
  423. | first | default({}) }}
  424. matrix_bridge_steam_data_mount: >-
  425. {{ matrix_bridge_steam_runtime.Mounts
  426. | selectattr('Destination', 'equalto', '/app/data')
  427. | first | default({}) }}
  428. matrix_bridge_steam_logs_mount: >-
  429. {{ matrix_bridge_steam_runtime.Mounts
  430. | selectattr('Destination', 'equalto', '/app/logs')
  431. | first | default({}) }}
  432. - name: Assert the rendered and extra labels reached the running container
  433. ansible.builtin.assert:
  434. that:
  435. - matrix_bridge_steam_runtime.Config.Labels['traefik.enable'] == 'true'
  436. - matrix_bridge_steam_runtime.Config.Labels['traefik.docker.network'] == matrix_bridge_steam_container_network
  437. - matrix_bridge_steam_runtime.Config.Labels['traefik.http.services.matrix-steam-bridge.loadbalancer.server.port'] == '8766'
  438. - matrix_bridge_steam_runtime.Config.Labels['molecule.steam.coverage'] == 'enabled'
  439. - matrix_bridge_steam_runtime.Config.Labels['molecule.steam.extra-argument'] == 'reached'
  440. fail_msg: "The running container does not carry the labels the role rendered and passed"
  441. success_msg: "The configured labels reached the running container"
  442. - name: Assert the running container has the exact network and port exposure
  443. ansible.builtin.assert:
  444. that:
  445. - matrix_bridge_steam_runtime.HostConfig.NetworkMode == matrix_bridge_steam_container_network
  446. - matrix_bridge_steam_container_network in matrix_bridge_steam_runtime.NetworkSettings.Networks
  447. - matrix_bridge_steam_runtime.NetworkSettings.Networks | length == 1
  448. - matrix_bridge_steam_runtime.HostConfig.PortBindings | default({}, true) | length == 0
  449. fail_msg: >-
  450. The container has unexpected networks or host ports:
  451. networks={{ matrix_bridge_steam_runtime.NetworkSettings.Networks.keys() | list }},
  452. ports={{ matrix_bridge_steam_runtime.HostConfig.PortBindings | default({}) }}
  453. success_msg: "The container uses only its dedicated network and publishes no host ports"
  454. - name: Assert the observable extra runtime argument reached Docker
  455. ansible.builtin.assert:
  456. that:
  457. - matrix_bridge_steam_runtime.Config.Hostname == 'steam-bridge-molecule-runtime'
  458. fail_msg: "The configured container hostname extra argument did not reach Docker"
  459. success_msg: "The configured container extra argument reached Docker"