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.
 
 
 

388 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 starts, accepts the role-rendered configuration and
  6. # registration, migrates real Postgres, and opens its appservice listener. A Bluesky
  7. # login is deliberately outside this scenario's third-party boundary.
  8. - name: Verify mautrix-bluesky
  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. mautrix_bluesky_config: "{{ mautrix_bluesky_config_file.content | b64decode | from_yaml }}"
  16. mautrix_bluesky_registration: "{{ mautrix_bluesky_registration_file.content | b64decode | from_yaml }}"
  17. mautrix_bluesky_labels_rendered: "{{ mautrix_bluesky_labels_file.content | b64decode }}"
  18. mautrix_bluesky_expected_public_address: http://bluesky-api.molecule.local/bridges/bluesky-api
  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: mautrix_bluesky_role_defaults
  26. - name: Wait for the mautrix-bluesky service to become active
  27. ansible.builtin.systemd_service:
  28. name: matrix-mautrix-bluesky.service
  29. register: mautrix_bluesky_service
  30. until: mautrix_bluesky_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. - mautrix_bluesky_service.status.ActiveState == 'active'
  39. - mautrix_bluesky_service.status.NRestarts is defined
  40. - mautrix_bluesky_service.status.NRestarts | int == 0
  41. fail_msg: >-
  42. matrix-mautrix-bluesky.service is
  43. {{ mautrix_bluesky_service.status.ActiveState | default('unknown') }} after
  44. {{ mautrix_bluesky_service.status.NRestarts | default('?') }} restart(s)
  45. success_msg: "matrix-mautrix-bluesky.service is active and has not restarted"
  46. - name: Wait for the bridge liveness endpoint
  47. ansible.builtin.command:
  48. argv:
  49. - docker
  50. - run
  51. - --rm
  52. - --network={{ matrix_bridge_mautrix_bluesky_container_network }}
  53. - "{{ molecule_shared_image_curl }}"
  54. - --silent
  55. - --output
  56. - /dev/null
  57. - --write-out
  58. - "HTTP_STATUS=%{http_code}"
  59. - http://matrix-mautrix-bluesky:29340/_matrix/mau/live
  60. register: mautrix_bluesky_live
  61. changed_when: false
  62. until: mautrix_bluesky_live.rc == 0 and mautrix_bluesky_live.stdout == 'HTTP_STATUS=200'
  63. retries: 24
  64. delay: 5
  65. failed_when: false
  66. - name: Wait for the bridge readiness endpoint
  67. ansible.builtin.command:
  68. argv:
  69. - docker
  70. - run
  71. - --rm
  72. - --network={{ matrix_bridge_mautrix_bluesky_container_network }}
  73. - "{{ molecule_shared_image_curl }}"
  74. - --silent
  75. - --output
  76. - /dev/null
  77. - --write-out
  78. - "HTTP_STATUS=%{http_code}"
  79. - http://matrix-mautrix-bluesky:29340/_matrix/mau/ready
  80. register: mautrix_bluesky_ready
  81. changed_when: false
  82. until: mautrix_bluesky_ready.rc == 0 and mautrix_bluesky_ready.stdout == 'HTTP_STATUS=200'
  83. retries: 24
  84. delay: 5
  85. failed_when: false
  86. - name: Assert the bridge is live and ready on the configured appservice port
  87. ansible.builtin.assert:
  88. that:
  89. - mautrix_bluesky_live.rc == 0
  90. - mautrix_bluesky_live.stdout == 'HTTP_STATUS=200'
  91. - mautrix_bluesky_ready.rc == 0
  92. - mautrix_bluesky_ready.stdout == 'HTTP_STATUS=200'
  93. fail_msg: >-
  94. Health probes returned live={{ mautrix_bluesky_live.stdout | default('none') }}
  95. (rc={{ mautrix_bluesky_live.rc | default('?') }}) and
  96. ready={{ mautrix_bluesky_ready.stdout | default('none') }}
  97. (rc={{ mautrix_bluesky_ready.rc | default('?') }})
  98. success_msg: "The bridge is live and ready on the configured appservice port"
  99. # This authenticated endpoint exercises the provisioning middleware and the network
  100. # connector's login-flow API without starting a Bluesky login or carrying credentials.
  101. - name: Query the authenticated provisioning login flows
  102. ansible.builtin.command:
  103. argv:
  104. - docker
  105. - run
  106. - --rm
  107. - --network={{ matrix_bridge_mautrix_bluesky_container_network }}
  108. - "{{ molecule_shared_image_curl }}"
  109. - --silent
  110. - --show-error
  111. - --fail-with-body
  112. - --header
  113. - "Authorization: Bearer {{ matrix_bridge_mautrix_bluesky_provisioning_shared_secret }}"
  114. - "http://matrix-mautrix-bluesky:29340/_matrix/provision/v3/login/flows?user_id=%40alice%3Amolecule.local"
  115. register: mautrix_bluesky_login_flows
  116. changed_when: false
  117. - name: Query the provisioning API with an invalid secret
  118. ansible.builtin.command:
  119. argv:
  120. - docker
  121. - run
  122. - --rm
  123. - --network={{ matrix_bridge_mautrix_bluesky_container_network }}
  124. - "{{ molecule_shared_image_curl }}"
  125. - --silent
  126. - --output
  127. - /dev/null
  128. - --write-out
  129. - "HTTP_STATUS=%{http_code}"
  130. - --header
  131. - "Authorization: Bearer definitely-wrong-molecule-secret"
  132. - "http://matrix-mautrix-bluesky:29340/_matrix/provision/v3/login/flows?user_id=%40alice%3Amolecule.local"
  133. register: mautrix_bluesky_login_flows_unauthorized
  134. changed_when: false
  135. failed_when: false
  136. - name: Assert the live provisioning API enforces auth and advertises login flows
  137. ansible.builtin.assert:
  138. that:
  139. - mautrix_bluesky_login_flows.rc == 0
  140. - (mautrix_bluesky_login_flows.stdout | from_json).flows is sequence
  141. - (mautrix_bluesky_login_flows.stdout | from_json).flows | length > 0
  142. - (mautrix_bluesky_login_flows.stdout | from_json).flows | map(attribute='id') | list == ['password']
  143. - mautrix_bluesky_login_flows_unauthorized.rc == 0
  144. - mautrix_bluesky_login_flows_unauthorized.stdout == 'HTTP_STATUS=401'
  145. fail_msg: "The provisioning API did not enforce its secret or return Bluesky login flows"
  146. success_msg: "The provisioning API enforces its secret and returns Bluesky login flows"
  147. - name: Read the configuration the role rendered
  148. ansible.builtin.slurp:
  149. src: "{{ matrix_bridge_mautrix_bluesky_config_path }}/config.yaml"
  150. register: mautrix_bluesky_config_file
  151. - name: Assert the rendered configuration carries the appservice identity
  152. ansible.builtin.assert:
  153. that:
  154. - mautrix_bluesky_config.homeserver.address == matrix_bridge_mautrix_bluesky_homeserver_address
  155. - mautrix_bluesky_config.homeserver.domain == matrix_bridge_mautrix_bluesky_homeserver_domain
  156. - mautrix_bluesky_config.appservice.id == 'bluesky'
  157. - mautrix_bluesky_config.appservice.address == 'http://matrix-mautrix-bluesky:29340'
  158. - mautrix_bluesky_config.appservice.public_address == mautrix_bluesky_expected_public_address
  159. - mautrix_bluesky_config.appservice.bot.username == matrix_bridge_mautrix_bluesky_appservice_bot_username
  160. - mautrix_bluesky_config.appservice.bot.displayname == matrix_bridge_mautrix_bluesky_appservice_bot_displayname
  161. - mautrix_bluesky_config.appservice.bot.avatar == matrix_bridge_mautrix_bluesky_appservice_bot_avatar
  162. - mautrix_bluesky_config.appservice.as_token == matrix_bridge_mautrix_bluesky_appservice_token
  163. - mautrix_bluesky_config.appservice.hs_token == matrix_bridge_mautrix_bluesky_homeserver_token
  164. fail_msg: "The rendered configuration does not carry the scenario's appservice identity"
  165. success_msg: "The rendered configuration carries the scenario's appservice identity"
  166. - name: Assert the rendered configuration carries non-default bridge behavior
  167. ansible.builtin.assert:
  168. that:
  169. - mautrix_bluesky_config.network.displayname_template == matrix_bridge_mautrix_bluesky_network_displayname_template
  170. - mautrix_bluesky_config.bridge.command_prefix == matrix_bridge_mautrix_bluesky_bridge_command_prefix
  171. - mautrix_bluesky_config.bridge.permissions['*'] == 'relay'
  172. - mautrix_bluesky_config.bridge.permissions[matrix_bridge_mautrix_bluesky_homeserver_domain] == 'admin'
  173. - not mautrix_bluesky_config.matrix.federate_rooms
  174. - mautrix_bluesky_config.provisioning.shared_secret == matrix_bridge_mautrix_bluesky_provisioning_shared_secret
  175. - mautrix_bluesky_config.logging.min_level == matrix_bridge_mautrix_bluesky_logging_level
  176. fail_msg: "The rendered configuration does not carry the scenario's bridge behavior"
  177. success_msg: "The rendered configuration carries the scenario's bridge behavior"
  178. - name: Assert the rendered configuration carries the non-default backfill policy
  179. ansible.builtin.assert:
  180. that:
  181. - not mautrix_bluesky_config.backfill.enabled
  182. - mautrix_bluesky_config.backfill.max_initial_messages == 23
  183. - mautrix_bluesky_config.backfill.max_catchup_messages == 37
  184. fail_msg: "The rendered configuration does not carry the scenario's backfill policy"
  185. success_msg: "The rendered configuration carries the scenario's backfill policy"
  186. - name: Assert the configuration points at the scenario's Postgres database
  187. ansible.builtin.assert:
  188. that:
  189. - mautrix_bluesky_config.database.type == 'postgres'
  190. - matrix_bridge_mautrix_bluesky_database_username in mautrix_bluesky_config.database.uri
  191. - matrix_bridge_mautrix_bluesky_database_hostname in mautrix_bluesky_config.database.uri
  192. - matrix_bridge_mautrix_bluesky_database_name in mautrix_bluesky_config.database.uri
  193. fail_msg: >-
  194. database.uri is {{ mautrix_bluesky_config.database.uri | default('unset') }}, which
  195. was not composed from the scenario's connection settings
  196. success_msg: "The configuration points at the scenario's Postgres database"
  197. - name: Read the appservice registration the role rendered
  198. ansible.builtin.slurp:
  199. src: "{{ matrix_bridge_mautrix_bluesky_config_path }}/registration.yaml"
  200. register: mautrix_bluesky_registration_file
  201. - name: Assert the registration carries the configured handshake values
  202. ansible.builtin.assert:
  203. that:
  204. - mautrix_bluesky_registration.id == 'bluesky'
  205. - mautrix_bluesky_registration.as_token == matrix_bridge_mautrix_bluesky_appservice_token
  206. - mautrix_bluesky_registration.hs_token == matrix_bridge_mautrix_bluesky_homeserver_token
  207. - mautrix_bluesky_registration.sender_localpart == '_bot_' + matrix_bridge_mautrix_bluesky_appservice_bot_username
  208. - mautrix_bluesky_registration.url == 'http://matrix-mautrix-bluesky:29340'
  209. fail_msg: "The registration does not carry the configured handshake values"
  210. success_msg: "The registration carries the configured handshake values"
  211. - name: Assert the registration namespaces cover only Bluesky ghosts and the bridge bot
  212. ansible.builtin.assert:
  213. that:
  214. - mautrix_bluesky_ghost_regex | length > 0
  215. - mautrix_bluesky_bot_regex | length > 0
  216. - mautrix_bluesky_ghost_mxid is match(mautrix_bluesky_ghost_regex)
  217. - mautrix_bluesky_wrong_ghost_mxid is not match(mautrix_bluesky_ghost_regex)
  218. - mautrix_bluesky_bot_mxid is match(mautrix_bluesky_bot_regex)
  219. fail_msg: "The registration namespaces do not cover only Bluesky ghosts and the bot"
  220. success_msg: "The registration namespaces cover only Bluesky ghosts and the bot"
  221. vars:
  222. mautrix_bluesky_user_regexes: "{{ mautrix_bluesky_registration.namespaces.users | map(attribute='regex') | list }}"
  223. mautrix_bluesky_ghost_regex: "{{ mautrix_bluesky_user_regexes | select('search', 'bluesky_') | first | default('') }}"
  224. mautrix_bluesky_bot_regex: "{{ mautrix_bluesky_user_regexes | reject('search', 'bluesky_') | first | default('') }}"
  225. mautrix_bluesky_ghost_mxid: "@bluesky_did_plc_moleculefixture:{{ matrix_bridge_mautrix_bluesky_homeserver_domain }}"
  226. mautrix_bluesky_wrong_ghost_mxid: "@twitter_did_plc_moleculefixture:{{ matrix_bridge_mautrix_bluesky_homeserver_domain }}"
  227. mautrix_bluesky_bot_mxid: "@{{ matrix_bridge_mautrix_bluesky_appservice_bot_username }}:{{ matrix_bridge_mautrix_bluesky_homeserver_domain }}"
  228. # Tables can appear only after hostname resolution, authentication, and real migrations.
  229. - name: List the tables the bridge created in Postgres
  230. ansible.builtin.command:
  231. argv:
  232. - docker
  233. - exec
  234. - matrix-postgres-molecule
  235. - psql
  236. - --username={{ matrix_bridge_mautrix_bluesky_database_username }}
  237. - --dbname={{ matrix_bridge_mautrix_bluesky_database_name }}
  238. - --tuples-only
  239. - --no-align
  240. - "--command=SELECT tablename FROM pg_tables WHERE schemaname = 'public'"
  241. register: mautrix_bluesky_tables
  242. changed_when: false
  243. - name: Assert the bridge migrated its schema into the configured database
  244. ansible.builtin.assert:
  245. that:
  246. - mautrix_bluesky_tables.rc == 0
  247. - "'version' in mautrix_bluesky_table_names"
  248. - "'portal' in mautrix_bluesky_table_names"
  249. - "'user_login' in mautrix_bluesky_table_names"
  250. - "'message' in mautrix_bluesky_table_names"
  251. - mautrix_bluesky_table_names | length > 10
  252. fail_msg: >-
  253. The bridge did not migrate its schema into {{ matrix_bridge_mautrix_bluesky_database_name }}
  254. (found {{ mautrix_bluesky_table_names | length }} table(s))
  255. success_msg: "The bridge migrated its schema into the configured database"
  256. vars:
  257. mautrix_bluesky_table_names: "{{ mautrix_bluesky_tables.stdout_lines | select | list }}"
  258. - name: Read the labels the role rendered
  259. ansible.builtin.slurp:
  260. src: "{{ matrix_bridge_mautrix_bluesky_base_path }}/labels"
  261. register: mautrix_bluesky_labels_file
  262. - name: Assert the labels route the public endpoint to the appservice port
  263. ansible.builtin.assert:
  264. that:
  265. - "'traefik.enable=true' in mautrix_bluesky_labels_rendered"
  266. - "'traefik.docker.network=' + matrix_bridge_mautrix_bluesky_container_network in mautrix_bluesky_labels_rendered"
  267. - "'traefik.http.services.matrix-mautrix-bluesky-exposure.loadbalancer.server.port=29340' in mautrix_bluesky_labels_rendered"
  268. - "'traefik.http.routers.matrix-mautrix-bluesky-exposure.rule=Host(`bluesky-api.molecule.local`) && PathPrefix(`/bridges/bluesky-api`)' in mautrix_bluesky_labels_rendered"
  269. - "'traefik.http.middlewares.matrix-mautrix-bluesky-exposure-strip-prefix.stripprefix.prefixes=/bridges/bluesky-api' in mautrix_bluesky_labels_rendered"
  270. - "'traefik.http.routers.matrix-mautrix-bluesky-exposure.entrypoints=web' in mautrix_bluesky_labels_rendered"
  271. - "'traefik.http.routers.matrix-mautrix-bluesky-exposure.tls=false' in mautrix_bluesky_labels_rendered"
  272. - "'molecule.bluesky.coverage=enabled' in mautrix_bluesky_labels_rendered"
  273. fail_msg: "The rendered labels do not carry the scenario's exposure configuration"
  274. success_msg: "The rendered labels carry the scenario's exposure configuration"
  275. - name: Inspect the running bridge container
  276. ansible.builtin.command:
  277. argv:
  278. - docker
  279. - container
  280. - inspect
  281. - matrix-mautrix-bluesky
  282. register: mautrix_bluesky_container_inspect
  283. changed_when: false
  284. - name: Parse the running bridge container inspection
  285. ansible.builtin.set_fact:
  286. mautrix_bluesky_container: "{{ (mautrix_bluesky_container_inspect.stdout | from_json) | first }}"
  287. - name: Assert the running container uses the exact image pinned by the role
  288. ansible.builtin.assert:
  289. that:
  290. - mautrix_bluesky_container.Config.Image == mautrix_bluesky_expected_image
  291. fail_msg: >-
  292. The running container uses {{ mautrix_bluesky_container.Config.Image }}, expected
  293. {{ mautrix_bluesky_expected_image }}
  294. success_msg: "The running container uses the exact image pinned by the role"
  295. vars:
  296. mautrix_bluesky_expected_image: >-
  297. {{ mautrix_bluesky_role_defaults.matrix_bridge_mautrix_bluesky_container_image_registry_prefix_upstream_default }}mautrix/bluesky:{{ mautrix_bluesky_role_defaults.matrix_bridge_mautrix_bluesky_version }}
  298. - name: Assert the running container uses the playbook-supplied runtime
  299. ansible.builtin.assert:
  300. that:
  301. - mautrix_bluesky_container.Config.User == (matrix_user_uid | string) + ':' + (matrix_user_gid | string)
  302. - mautrix_bluesky_container.Config.WorkingDir == '/data'
  303. - mautrix_bluesky_container.Config.Cmd == ['/usr/bin/mautrix-bluesky', '-c', '/config/config.yaml', '-r', '/config/registration.yaml', '--no-update']
  304. - mautrix_bluesky_container.HostConfig.RestartPolicy.Name == 'no'
  305. - mautrix_bluesky_container.HostConfig.AutoRemove
  306. - mautrix_bluesky_container.HostConfig.LogConfig.Type == 'none'
  307. fail_msg: "The running container does not use the role's exact identity and command"
  308. success_msg: "The running container uses the role's exact identity and command"
  309. - name: Assert the running container has the intended privilege isolation
  310. ansible.builtin.assert:
  311. that:
  312. - "'ALL' in mautrix_bluesky_container.HostConfig.CapDrop"
  313. - not mautrix_bluesky_container.HostConfig.Privileged
  314. fail_msg: "The running container does not have the intended privilege isolation"
  315. success_msg: "The running container drops all capabilities and is unprivileged"
  316. - name: Assert the running container carries the role's exact bind mounts
  317. ansible.builtin.assert:
  318. that:
  319. - mautrix_bluesky_config_mount | length > 0
  320. - mautrix_bluesky_config_mount.Source == matrix_bridge_mautrix_bluesky_config_path
  321. - not mautrix_bluesky_config_mount.RW
  322. - mautrix_bluesky_data_mount | length > 0
  323. - mautrix_bluesky_data_mount.Source == matrix_bridge_mautrix_bluesky_data_path
  324. - mautrix_bluesky_data_mount.RW
  325. - mautrix_bluesky_container.Mounts | length == 2
  326. fail_msg: "The running container does not carry the role's exact config and data mounts"
  327. success_msg: "The running container carries read-only config and writable data mounts"
  328. vars:
  329. mautrix_bluesky_config_mount: >-
  330. {{ mautrix_bluesky_container.Mounts
  331. | selectattr('Destination', 'equalto', '/config')
  332. | first | default({}) }}
  333. mautrix_bluesky_data_mount: >-
  334. {{ mautrix_bluesky_container.Mounts
  335. | selectattr('Destination', 'equalto', '/data')
  336. | first | default({}) }}
  337. - name: Assert the rendered labels are attached to the running container
  338. ansible.builtin.assert:
  339. that:
  340. - mautrix_bluesky_container.Config.Labels['traefik.enable'] == 'true'
  341. - mautrix_bluesky_container.Config.Labels['traefik.docker.network'] == matrix_bridge_mautrix_bluesky_container_network
  342. - mautrix_bluesky_container.Config.Labels['traefik.http.services.matrix-mautrix-bluesky-exposure.loadbalancer.server.port'] == '29340'
  343. - mautrix_bluesky_container.Config.Labels['molecule.bluesky.coverage'] == 'enabled'
  344. fail_msg: "The running container does not carry the labels the role rendered"
  345. success_msg: "The running container carries the labels the role rendered"
  346. - name: Assert the running container has the exact network and port exposure
  347. ansible.builtin.assert:
  348. that:
  349. - mautrix_bluesky_container.HostConfig.NetworkMode == matrix_bridge_mautrix_bluesky_container_network
  350. - matrix_bridge_mautrix_bluesky_container_network in mautrix_bluesky_container.NetworkSettings.Networks
  351. - mautrix_bluesky_container.NetworkSettings.Networks | length == 1
  352. - mautrix_bluesky_container.HostConfig.PortBindings | default({}, true) | length == 0
  353. fail_msg: >-
  354. The container has unexpected networks or host ports:
  355. networks={{ mautrix_bluesky_container.NetworkSettings.Networks.keys() | list }},
  356. ports={{ mautrix_bluesky_container.HostConfig.PortBindings | default({}) }}
  357. success_msg: "The container uses only its dedicated network and publishes no host ports"