Matrix Docker Ansible eploy
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

400 wiersze
21 KiB

  1. # SPDX-FileCopyrightText: 2026 Slavi Pantaleev
  2. #
  3. # SPDX-License-Identifier: AGPL-3.0-or-later
  4. ---
  5. # Proves the logged-out bridge accepts the role-rendered configuration and registration,
  6. # migrates real Postgres, opens its appservice listener, and authenticates transactions.
  7. # A LINE login is deliberately outside this scenario's third-party boundary.
  8. - name: Verify beeper-line
  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. beeper_line_config: "{{ beeper_line_config_file.content | b64decode | from_yaml }}"
  16. beeper_line_registration: "{{ beeper_line_registration_file.content | b64decode | from_yaml }}"
  17. beeper_line_labels_rendered: "{{ beeper_line_labels_file.content | b64decode }}"
  18. beeper_line_expected_public_address: http://line-api.molecule.local/bridges/line-api
  19. gather_facts: false
  20. tasks:
  21. # A Renovate digest 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: beeper_line_role_defaults
  26. - name: Wait for the beeper-line service to become active
  27. ansible.builtin.systemd_service:
  28. name: matrix-beeper-line.service
  29. register: beeper_line_service
  30. until: beeper_line_service.status.ActiveState == 'active'
  31. retries: 30
  32. delay: 5
  33. failed_when: false
  34. # Restart=always makes ActiveState insufficient for detecting a crash loop.
  35. - name: Assert the service is active and has not been restarting
  36. ansible.builtin.assert:
  37. that:
  38. - beeper_line_service.status.ActiveState == 'active'
  39. - beeper_line_service.status.NRestarts is defined
  40. - beeper_line_service.status.NRestarts | int == 0
  41. fail_msg: >-
  42. matrix-beeper-line.service is {{ beeper_line_service.status.ActiveState | default('unknown') }}
  43. after {{ beeper_line_service.status.NRestarts | default('?') }} restart(s)
  44. success_msg: "matrix-beeper-line.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_beeper_line_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-beeper-line:29322/_matrix/mau/live
  59. register: beeper_line_live
  60. changed_when: false
  61. until: beeper_line_live.rc == 0 and beeper_line_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_beeper_line_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-beeper-line:29322/_matrix/mau/ready
  79. register: beeper_line_ready
  80. changed_when: false
  81. until: beeper_line_ready.rc == 0 and beeper_line_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. - beeper_line_live.rc == 0
  89. - beeper_line_live.stdout == 'HTTP_STATUS=200'
  90. - beeper_line_ready.rc == 0
  91. - beeper_line_ready.stdout == 'HTTP_STATUS=200'
  92. fail_msg: >-
  93. Health probes returned live={{ beeper_line_live.stdout | default('none') }} and
  94. ready={{ beeper_line_ready.stdout | default('none') }}
  95. success_msg: "The bridge is live and ready on its appservice port"
  96. # This is a real inbound appservice handshake using the role-rendered hs_token.
  97. - name: Submit an empty appservice transaction with the configured token
  98. ansible.builtin.command:
  99. argv:
  100. - docker
  101. - run
  102. - --rm
  103. - --network={{ matrix_bridge_beeper_line_container_network }}
  104. - "{{ molecule_shared_image_curl }}"
  105. - --silent
  106. - --show-error
  107. - --fail-with-body
  108. - --request
  109. - PUT
  110. - --header
  111. - "Content-Type: application/json"
  112. - --header
  113. - "Authorization: Bearer {{ matrix_bridge_beeper_line_homeserver_token }}"
  114. - --data-binary
  115. - '{"events": [], "ephemeral": []}'
  116. - http://matrix-beeper-line:29322/_matrix/app/v1/transactions/molecule-coverage
  117. register: beeper_line_transaction
  118. changed_when: false
  119. - name: Submit an appservice transaction with an invalid token
  120. ansible.builtin.command:
  121. argv:
  122. - docker
  123. - run
  124. - --rm
  125. - --network={{ matrix_bridge_beeper_line_container_network }}
  126. - "{{ molecule_shared_image_curl }}"
  127. - --silent
  128. - --output
  129. - /dev/null
  130. - --write-out
  131. - "HTTP_STATUS=%{http_code}"
  132. - --request
  133. - PUT
  134. - --header
  135. - "Content-Type: application/json"
  136. - --header
  137. - "Authorization: Bearer definitely-wrong-token"
  138. - --data-binary
  139. - '{"events": [], "ephemeral": []}'
  140. - http://matrix-beeper-line:29322/_matrix/app/v1/transactions/molecule-unauthorized
  141. register: beeper_line_transaction_unauthorized
  142. changed_when: false
  143. failed_when: false
  144. - name: Assert the live appservice accepts only the configured handshake token
  145. ansible.builtin.assert:
  146. that:
  147. - beeper_line_transaction.rc == 0
  148. - beeper_line_transaction.stdout | from_json == {}
  149. - beeper_line_transaction_unauthorized.rc == 0
  150. - beeper_line_transaction_unauthorized.stdout == 'HTTP_STATUS=401'
  151. fail_msg: "The appservice transaction endpoint did not enforce the rendered hs_token"
  152. success_msg: "The live appservice accepts the configured hs_token and rejects another"
  153. - name: Read the configuration the role rendered
  154. ansible.builtin.slurp:
  155. src: "{{ matrix_bridge_beeper_line_config_path }}/config.yaml"
  156. register: beeper_line_config_file
  157. - name: Assert the rendered configuration carries the appservice identity
  158. ansible.builtin.assert:
  159. that:
  160. - beeper_line_config.homeserver.address == matrix_bridge_beeper_line_homeserver_address
  161. - beeper_line_config.homeserver.domain == matrix_bridge_beeper_line_homeserver_domain
  162. - beeper_line_config.appservice.id == 'line'
  163. - beeper_line_config.appservice.address == 'http://matrix-beeper-line:29322'
  164. - beeper_line_config.appservice.public_address == beeper_line_expected_public_address
  165. - beeper_line_config.appservice.bot.username == matrix_bridge_beeper_line_appservice_bot_username
  166. - beeper_line_config.appservice.bot.displayname == matrix_bridge_beeper_line_appservice_bot_displayname
  167. - beeper_line_config.appservice.bot.avatar == matrix_bridge_beeper_line_appservice_bot_avatar
  168. - beeper_line_config.appservice.as_token == matrix_bridge_beeper_line_appservice_token
  169. - beeper_line_config.appservice.hs_token == matrix_bridge_beeper_line_homeserver_token
  170. - beeper_line_config.appservice.username_template == matrix_bridge_beeper_line_appservice_username_prefix + '{' + '{.}' + '}'
  171. fail_msg: "The rendered configuration does not carry the scenario's appservice identity"
  172. success_msg: "The rendered configuration carries the scenario's appservice identity"
  173. - name: Assert the rendered configuration carries non-default bridge behavior
  174. ansible.builtin.assert:
  175. that:
  176. - beeper_line_config.bridge.command_prefix == matrix_bridge_beeper_line_command_prefix
  177. - not beeper_line_config.bridge.personal_filtering_spaces
  178. - beeper_line_config.bridge.permissions['*'] == 'relay'
  179. - beeper_line_config.bridge.permissions[matrix_bridge_beeper_line_homeserver_domain] == 'admin'
  180. - not beeper_line_config.matrix.federate_rooms
  181. - beeper_line_config.provisioning.shared_secret == matrix_bridge_beeper_line_provisioning_shared_secret
  182. - beeper_line_config.logging.min_level == matrix_bridge_beeper_line_logging_level
  183. fail_msg: "The rendered configuration does not carry the scenario's bridge behavior"
  184. success_msg: "The rendered configuration carries the scenario's bridge behavior"
  185. - name: Assert the rendered configuration carries the non-default backfill policy
  186. ansible.builtin.assert:
  187. that:
  188. - beeper_line_config.backfill.enabled
  189. - beeper_line_config.backfill.max_initial_messages == 27
  190. - beeper_line_config.backfill.max_catchup_messages == 43
  191. - beeper_line_config.backfill.unread_hours_threshold == 168
  192. fail_msg: "The rendered configuration does not carry the scenario's backfill policy"
  193. success_msg: "The rendered configuration carries the scenario's backfill policy"
  194. - name: Assert the configuration points at the scenario's Postgres database
  195. ansible.builtin.assert:
  196. that:
  197. - beeper_line_config.database.type == 'postgres'
  198. - matrix_bridge_beeper_line_database_username in beeper_line_config.database.uri
  199. - matrix_bridge_beeper_line_database_hostname in beeper_line_config.database.uri
  200. - matrix_bridge_beeper_line_database_name in beeper_line_config.database.uri
  201. fail_msg: >-
  202. database.uri is {{ beeper_line_config.database.uri | default('unset') }}, which was not
  203. composed from the scenario's connection settings
  204. success_msg: "The configuration points at the scenario's Postgres database"
  205. - name: Read the appservice registration the role rendered
  206. ansible.builtin.slurp:
  207. src: "{{ matrix_bridge_beeper_line_config_path }}/registration.yaml"
  208. register: beeper_line_registration_file
  209. - name: Assert the registration carries the configured handshake values
  210. ansible.builtin.assert:
  211. that:
  212. - beeper_line_registration.id == 'line'
  213. - beeper_line_registration.as_token == matrix_bridge_beeper_line_appservice_token
  214. - beeper_line_registration.hs_token == matrix_bridge_beeper_line_homeserver_token
  215. - beeper_line_registration.sender_localpart == '_bot_' + matrix_bridge_beeper_line_appservice_bot_username
  216. - beeper_line_registration.url == 'http://matrix-beeper-line:29322'
  217. fail_msg: "The registration does not carry the configured handshake values"
  218. success_msg: "The registration carries the configured handshake values"
  219. - name: Assert the registration namespaces use the shared LINE ghost prefix and cover the bridge bot
  220. ansible.builtin.assert:
  221. that:
  222. - beeper_line_registration.namespaces.users | length == 2
  223. - beeper_line_ghost_regex == beeper_line_expected_ghost_regex
  224. - beeper_line_bot_regex == beeper_line_expected_bot_regex
  225. - beeper_line_ghost_mxid is match(beeper_line_ghost_regex)
  226. - beeper_line_wrong_ghost_mxid is not match(beeper_line_ghost_regex)
  227. - beeper_line_bot_mxid is match(beeper_line_bot_regex)
  228. fail_msg: "The registration namespaces do not use the shared LINE ghost prefix or cover the bot"
  229. success_msg: "The registration namespaces use the shared LINE ghost prefix and cover the bot"
  230. vars:
  231. beeper_line_ghost_regex: "{{ beeper_line_registration.namespaces.users[0].regex }}"
  232. beeper_line_bot_regex: "{{ beeper_line_registration.namespaces.users[1].regex }}"
  233. beeper_line_expected_ghost_regex: '^@{{ matrix_bridge_beeper_line_appservice_username_prefix | regex_escape }}.+:{{ matrix_bridge_beeper_line_homeserver_domain | regex_escape }}$'
  234. beeper_line_expected_bot_regex: '^@{{ matrix_bridge_beeper_line_appservice_bot_username | regex_escape }}:{{ matrix_bridge_beeper_line_homeserver_domain | regex_escape }}$'
  235. beeper_line_ghost_mxid: "@{{ matrix_bridge_beeper_line_appservice_username_prefix }}moleculefixture:{{ matrix_bridge_beeper_line_homeserver_domain }}"
  236. beeper_line_wrong_ghost_mxid: "@twitter_moleculefixture:{{ matrix_bridge_beeper_line_homeserver_domain }}"
  237. beeper_line_bot_mxid: "@{{ matrix_bridge_beeper_line_appservice_bot_username }}:{{ matrix_bridge_beeper_line_homeserver_domain }}"
  238. # Tables can appear only after hostname resolution, authentication, and real migrations.
  239. - name: List the tables the bridge created in Postgres
  240. ansible.builtin.command:
  241. argv:
  242. - docker
  243. - exec
  244. - matrix-postgres-molecule
  245. - psql
  246. - --username={{ matrix_bridge_beeper_line_database_username }}
  247. - --dbname={{ matrix_bridge_beeper_line_database_name }}
  248. - --tuples-only
  249. - --no-align
  250. - "--command=SELECT tablename FROM pg_tables WHERE schemaname = 'public'"
  251. register: beeper_line_tables
  252. changed_when: false
  253. - name: Assert the bridge migrated its schema into the configured database
  254. ansible.builtin.assert:
  255. that:
  256. - beeper_line_tables.rc == 0
  257. - "'version' in beeper_line_table_names"
  258. - "'portal' in beeper_line_table_names"
  259. - "'user_login' in beeper_line_table_names"
  260. - "'message' in beeper_line_table_names"
  261. - beeper_line_table_names | length > 10
  262. fail_msg: >-
  263. The bridge did not migrate its schema into {{ matrix_bridge_beeper_line_database_name }}
  264. (found {{ beeper_line_table_names | length }} table(s))
  265. success_msg: "The bridge migrated its schema into the configured database"
  266. vars:
  267. beeper_line_table_names: "{{ beeper_line_tables.stdout_lines | select | list }}"
  268. - name: Read the labels the role rendered
  269. ansible.builtin.slurp:
  270. src: "{{ matrix_bridge_beeper_line_base_path }}/labels"
  271. register: beeper_line_labels_file
  272. - name: Assert the labels route the public endpoint to the appservice port
  273. ansible.builtin.assert:
  274. that:
  275. - "'traefik.enable=true' in beeper_line_labels_rendered"
  276. - "'traefik.docker.network=' + matrix_bridge_beeper_line_container_network in beeper_line_labels_rendered"
  277. - "'traefik.http.services.matrix-beeper-line-exposure.loadbalancer.server.port=29322' in beeper_line_labels_rendered"
  278. - "'traefik.http.routers.matrix-beeper-line-exposure.rule=Host(`line-api.molecule.local`) && PathPrefix(`/bridges/line-api`)' in beeper_line_labels_rendered"
  279. - "'traefik.http.middlewares.matrix-beeper-line-exposure-strip-prefix.stripprefix.prefixes=/bridges/line-api' in beeper_line_labels_rendered"
  280. - "'traefik.http.routers.matrix-beeper-line-exposure.priority=1722' in beeper_line_labels_rendered"
  281. - "'traefik.http.routers.matrix-beeper-line-exposure.entrypoints=web' in beeper_line_labels_rendered"
  282. - "'traefik.http.routers.matrix-beeper-line-exposure.tls=false' in beeper_line_labels_rendered"
  283. - "'molecule.beeper-line.coverage=enabled' in beeper_line_labels_rendered"
  284. fail_msg: "The rendered labels do not carry the scenario's exposure configuration"
  285. success_msg: "The rendered labels carry the scenario's exposure configuration"
  286. - name: Inspect the running bridge container
  287. ansible.builtin.command:
  288. argv:
  289. - docker
  290. - container
  291. - inspect
  292. - matrix-beeper-line
  293. register: beeper_line_container_inspect
  294. changed_when: false
  295. - name: Parse the running bridge container inspection
  296. ansible.builtin.set_fact:
  297. beeper_line_container: "{{ (beeper_line_container_inspect.stdout | from_json) | first }}"
  298. - name: Assert the running container uses the exact image pinned by the role
  299. ansible.builtin.assert:
  300. that:
  301. - beeper_line_container.Config.Image == beeper_line_expected_image
  302. fail_msg: >-
  303. The running container uses {{ beeper_line_container.Config.Image }}, expected
  304. {{ beeper_line_expected_image }}
  305. success_msg: "The running container uses the exact image pinned by the role"
  306. vars:
  307. beeper_line_expected_image: >-
  308. {{ beeper_line_role_defaults.matrix_bridge_beeper_line_container_image_registry_prefix_upstream_default }}crispyduck/beeper-line:{{ beeper_line_role_defaults.matrix_bridge_beeper_line_version }}
  309. - name: Assert the running container uses the playbook-supplied runtime
  310. ansible.builtin.assert:
  311. that:
  312. - beeper_line_container.Config.User == (matrix_user_uid | string) + ':' + (matrix_user_gid | string)
  313. - beeper_line_container.Config.WorkingDir == '/data'
  314. - beeper_line_container.Config.Cmd == ['/usr/bin/matrix-line', '-c', '/config/config.yaml', '-r', '/config/registration.yaml', '--no-update']
  315. - beeper_line_container.Config.Env is contains('MOLECULE_BEEPER_LINE_COVERAGE=enabled')
  316. - beeper_line_container.HostConfig.RestartPolicy.Name == 'no'
  317. - beeper_line_container.HostConfig.AutoRemove
  318. - beeper_line_container.HostConfig.LogConfig.Type == 'none'
  319. fail_msg: "The running container does not use the role's exact identity and command"
  320. success_msg: "The running container uses the role's exact identity, command, and extra argument"
  321. - name: Assert the running container has the intended privilege isolation
  322. ansible.builtin.assert:
  323. that:
  324. - "'ALL' in beeper_line_container.HostConfig.CapDrop"
  325. - not beeper_line_container.HostConfig.Privileged
  326. fail_msg: "The running container does not have the intended privilege isolation"
  327. success_msg: "The running container drops all capabilities and is unprivileged"
  328. - name: Assert the running container carries the role's exact bind mounts
  329. ansible.builtin.assert:
  330. that:
  331. - beeper_line_config_mount | length > 0
  332. - beeper_line_config_mount.Source == matrix_bridge_beeper_line_config_path
  333. - not beeper_line_config_mount.RW
  334. - beeper_line_data_mount | length > 0
  335. - beeper_line_data_mount.Source == matrix_bridge_beeper_line_data_path
  336. - beeper_line_data_mount.RW
  337. - beeper_line_container.Mounts | length == 2
  338. fail_msg: "The running container does not carry the role's exact config and data mounts"
  339. success_msg: "The running container carries read-only config and writable data mounts"
  340. vars:
  341. beeper_line_config_mount: >-
  342. {{ beeper_line_container.Mounts
  343. | selectattr('Destination', 'equalto', '/config')
  344. | first | default({}) }}
  345. beeper_line_data_mount: >-
  346. {{ beeper_line_container.Mounts
  347. | selectattr('Destination', 'equalto', '/data')
  348. | first | default({}) }}
  349. - name: Assert the rendered labels are attached to the running container
  350. ansible.builtin.assert:
  351. that:
  352. - beeper_line_container.Config.Labels['traefik.enable'] == 'true'
  353. - beeper_line_container.Config.Labels['traefik.docker.network'] == matrix_bridge_beeper_line_container_network
  354. - beeper_line_container.Config.Labels['traefik.http.services.matrix-beeper-line-exposure.loadbalancer.server.port'] == '29322'
  355. - beeper_line_container.Config.Labels['molecule.beeper-line.coverage'] == 'enabled'
  356. fail_msg: "The running container does not carry the labels the role rendered"
  357. success_msg: "The running container carries the labels the role rendered"
  358. - name: Assert the running container has the exact network and port exposure
  359. ansible.builtin.assert:
  360. that:
  361. - beeper_line_container.HostConfig.NetworkMode == matrix_bridge_beeper_line_container_network
  362. - matrix_bridge_beeper_line_container_network in beeper_line_container.NetworkSettings.Networks
  363. - beeper_line_container.NetworkSettings.Networks | length == 1
  364. - beeper_line_container.HostConfig.PortBindings | default({}, true) | length == 0
  365. fail_msg: >-
  366. The container has unexpected networks or host ports:
  367. networks={{ beeper_line_container.NetworkSettings.Networks.keys() | list }},
  368. ports={{ beeper_line_container.HostConfig.PortBindings | default({}) }}
  369. success_msg: "The container uses only its dedicated network and publishes no host ports"