Matrix Docker Ansible eploy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

510 lines
27 KiB

  1. # SPDX-FileCopyrightText: 2026 Slavi Pantaleev
  2. #
  3. # SPDX-License-Identifier: AGPL-3.0-or-later
  4. ---
  5. - name: Verify matrix-livekit-jwt-service
  6. hosts: all
  7. become: true
  8. vars_files:
  9. - "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/../../../molecule-shared/vars.yml"
  10. - "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/../../../molecule-shared/playbook-context.yml"
  11. vars:
  12. matrix_livekit_jwt_service_runtime: "{{ (matrix_livekit_jwt_service_container_inspect.stdout | from_json) | first }}"
  13. matrix_livekit_jwt_service_valid_request:
  14. room_id: "!call-room:molecule.local"
  15. slot_id: molecule-slot
  16. openid_token:
  17. access_token: known-openid-token
  18. token_type: Bearer
  19. matrix_server_name: "matrix-openid-fixture:8443"
  20. expires_in: 3600
  21. member:
  22. id: member-molecule-01
  23. claimed_user_id: "@alice:matrix-openid-fixture:8443"
  24. claimed_device_id: DEVICE_MOLECULE
  25. gather_facts: false
  26. tasks:
  27. - name: Load the role's defaults under a separate name
  28. ansible.builtin.include_vars:
  29. file: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/defaults/main.yml"
  30. name: matrix_livekit_jwt_service_role_defaults
  31. - name: Wait for the LiveKit JWT service to become active
  32. ansible.builtin.systemd_service:
  33. name: matrix-livekit-jwt-service.service
  34. register: matrix_livekit_jwt_service_service
  35. until: matrix_livekit_jwt_service_service.status.ActiveState == 'active'
  36. retries: 30
  37. delay: 5
  38. failed_when: false
  39. # Restart=always keeps a crash-looping service nominally active.
  40. - name: Assert the service is active and has not restarted
  41. ansible.builtin.assert:
  42. that:
  43. - matrix_livekit_jwt_service_service.status.ActiveState == 'active'
  44. - matrix_livekit_jwt_service_service.status.NRestarts is defined
  45. - matrix_livekit_jwt_service_service.status.NRestarts | int == 0
  46. fail_msg: >-
  47. matrix-livekit-jwt-service.service is
  48. {{ matrix_livekit_jwt_service_service.status.ActiveState | default('unknown') }} after
  49. {{ matrix_livekit_jwt_service_service.status.NRestarts | default('?') }} restart(s)
  50. success_msg: "matrix-livekit-jwt-service.service is active and has not restarted"
  51. - name: Wait for the live health endpoint on the configured non-default port
  52. ansible.builtin.command:
  53. argv:
  54. - docker
  55. - run
  56. - --rm
  57. - --network={{ matrix_livekit_jwt_service_container_network }}
  58. - "{{ molecule_shared_image_curl }}"
  59. - --silent
  60. - --show-error
  61. - --output
  62. - /dev/null
  63. - --write-out
  64. - "HTTP_STATUS=%{http_code}"
  65. - http://matrix-livekit-jwt-service:8097/healthz
  66. register: matrix_livekit_jwt_service_health
  67. changed_when: false
  68. until: matrix_livekit_jwt_service_health.stdout == 'HTTP_STATUS=200'
  69. retries: 24
  70. delay: 5
  71. failed_when: false
  72. - name: Assert the live service is healthy on the configured port
  73. ansible.builtin.assert:
  74. that:
  75. - matrix_livekit_jwt_service_health.rc == 0
  76. - matrix_livekit_jwt_service_health.stdout == 'HTTP_STATUS=200'
  77. fail_msg: "The LiveKit JWT service did not answer /healthz on port 8097"
  78. success_msg: "The LiveKit JWT service is healthy on its non-default port"
  79. - name: Exercise the get_token CORS preflight
  80. ansible.builtin.command:
  81. argv:
  82. - docker
  83. - run
  84. - --rm
  85. - --network={{ matrix_livekit_jwt_service_container_network }}
  86. - "{{ molecule_shared_image_curl }}"
  87. - --silent
  88. - --show-error
  89. - --include
  90. - --request
  91. - OPTIONS
  92. - --write-out
  93. - "\nHTTP_STATUS=%{http_code}"
  94. - http://matrix-livekit-jwt-service:8097/get_token
  95. register: matrix_livekit_jwt_service_cors
  96. changed_when: false
  97. failed_when: false
  98. - name: Assert get_token exposes its CORS contract
  99. ansible.builtin.assert:
  100. that:
  101. - matrix_livekit_jwt_service_cors.rc == 0
  102. - "'HTTP_STATUS=200' in matrix_livekit_jwt_service_cors.stdout_lines"
  103. - "'access-control-allow-origin: *' in matrix_livekit_jwt_service_cors.stdout | lower"
  104. - "'access-control-allow-methods: post' in matrix_livekit_jwt_service_cors.stdout | lower"
  105. - "'access-control-allow-headers: accept, content-type, content-length, accept-encoding, x-csrf-token' in matrix_livekit_jwt_service_cors.stdout | lower"
  106. fail_msg: "OPTIONS /get_token did not return the service's expected CORS headers"
  107. success_msg: "OPTIONS /get_token exposes the expected CORS contract"
  108. - name: Submit malformed JSON to get_token
  109. ansible.builtin.command:
  110. argv:
  111. - docker
  112. - run
  113. - --rm
  114. - --network={{ matrix_livekit_jwt_service_container_network }}
  115. - "{{ molecule_shared_image_curl }}"
  116. - --silent
  117. - --show-error
  118. - --header
  119. - "Content-Type: application/json"
  120. - --data-binary
  121. - "{not-json"
  122. - --write-out
  123. - "\nHTTP_STATUS=%{http_code}"
  124. - http://matrix-livekit-jwt-service:8097/get_token
  125. register: matrix_livekit_jwt_service_malformed
  126. changed_when: false
  127. failed_when: false
  128. - name: Assert malformed JSON is rejected structurally
  129. ansible.builtin.assert:
  130. that:
  131. - matrix_livekit_jwt_service_malformed.rc == 0
  132. - matrix_livekit_jwt_service_malformed.stdout_lines[-1] == 'HTTP_STATUS=400'
  133. - matrix_livekit_jwt_service_malformed_document.errcode == 'M_NOT_JSON'
  134. - matrix_livekit_jwt_service_malformed_document.error == 'Error reading request'
  135. fail_msg: "Malformed JSON did not produce the expected Matrix error response"
  136. success_msg: "Malformed JSON is rejected with M_NOT_JSON"
  137. vars:
  138. matrix_livekit_jwt_service_malformed_document: >-
  139. {{ matrix_livekit_jwt_service_malformed.stdout | regex_replace('(?s)\s*HTTP_STATUS=[0-9]+\s*$', '') | from_json }}
  140. - name: Ask get_token to validate an unknown OpenID token
  141. ansible.builtin.command:
  142. argv:
  143. - docker
  144. - run
  145. - --rm
  146. - --network={{ matrix_livekit_jwt_service_container_network }}
  147. - "{{ molecule_shared_image_curl }}"
  148. - --silent
  149. - --show-error
  150. - --header
  151. - "Content-Type: application/json"
  152. - --data-binary
  153. - "{{ matrix_livekit_jwt_service_unknown_token_request | to_json }}"
  154. - --write-out
  155. - "\nHTTP_STATUS=%{http_code}"
  156. - http://matrix-livekit-jwt-service:8097/get_token
  157. register: matrix_livekit_jwt_service_unknown_token
  158. changed_when: false
  159. failed_when: false
  160. vars:
  161. matrix_livekit_jwt_service_unknown_token_request: >-
  162. {{ matrix_livekit_jwt_service_valid_request | combine({'openid_token': matrix_livekit_jwt_service_valid_request.openid_token | combine({'access_token': 'unknown-openid-token'})}, recursive=True) }}
  163. - name: Assert an unknown OpenID token is unauthorized
  164. ansible.builtin.assert:
  165. that:
  166. - matrix_livekit_jwt_service_unknown_token.rc == 0
  167. - matrix_livekit_jwt_service_unknown_token.stdout_lines[-1] == 'HTTP_STATUS=401'
  168. - matrix_livekit_jwt_service_unknown_token_document.errcode == 'M_UNAUTHORIZED'
  169. - matrix_livekit_jwt_service_unknown_token_document.error == 'The request could not be authorised.'
  170. fail_msg: "An unknown OpenID token was not rejected as unauthorized"
  171. success_msg: "The live service rejects an unknown OpenID token"
  172. vars:
  173. matrix_livekit_jwt_service_unknown_token_document: >-
  174. {{ matrix_livekit_jwt_service_unknown_token.stdout | regex_replace('(?s)\s*HTTP_STATUS=[0-9]+\s*$', '') | from_json }}
  175. - name: Ask get_token to validate a mismatched claimed user
  176. ansible.builtin.command:
  177. argv:
  178. - docker
  179. - run
  180. - --rm
  181. - --network={{ matrix_livekit_jwt_service_container_network }}
  182. - "{{ molecule_shared_image_curl }}"
  183. - --silent
  184. - --show-error
  185. - --header
  186. - "Content-Type: application/json"
  187. - --data-binary
  188. - "{{ matrix_livekit_jwt_service_mismatched_user_request | to_json }}"
  189. - --write-out
  190. - "\nHTTP_STATUS=%{http_code}"
  191. - http://matrix-livekit-jwt-service:8097/get_token
  192. register: matrix_livekit_jwt_service_mismatched_user
  193. changed_when: false
  194. failed_when: false
  195. vars:
  196. matrix_livekit_jwt_service_mismatched_user_request: >-
  197. {{ matrix_livekit_jwt_service_valid_request | combine({'member': matrix_livekit_jwt_service_valid_request.member | combine({'claimed_user_id': '@mallory:matrix-openid-fixture:8443'})}, recursive=True) }}
  198. - name: Assert a valid token cannot impersonate another Matrix user
  199. ansible.builtin.assert:
  200. that:
  201. - matrix_livekit_jwt_service_mismatched_user.rc == 0
  202. - matrix_livekit_jwt_service_mismatched_user.stdout_lines[-1] == 'HTTP_STATUS=401'
  203. - matrix_livekit_jwt_service_mismatched_user_document.errcode == 'M_UNAUTHORIZED'
  204. fail_msg: "The OpenID subject and claimed Matrix user mismatch was not rejected"
  205. success_msg: "The live service rejects a claimed-user mismatch"
  206. vars:
  207. matrix_livekit_jwt_service_mismatched_user_document: >-
  208. {{ matrix_livekit_jwt_service_mismatched_user.stdout | regex_replace('(?s)\s*HTTP_STATUS=[0-9]+\s*$', '') | from_json }}
  209. # The request's server is not in FULL_ACCESS, so this validates OpenID and
  210. # signs a join token without trying to create a room on the absent SFU.
  211. - name: Request a real restricted-user LiveKit JWT
  212. ansible.builtin.command:
  213. argv:
  214. - docker
  215. - run
  216. - --rm
  217. - --network={{ matrix_livekit_jwt_service_container_network }}
  218. - "{{ molecule_shared_image_curl }}"
  219. - --silent
  220. - --show-error
  221. - --header
  222. - "Content-Type: application/json"
  223. - --data-binary
  224. - "{{ matrix_livekit_jwt_service_valid_request | to_json }}"
  225. - --write-out
  226. - "\nHTTP_STATUS=%{http_code}"
  227. - http://matrix-livekit-jwt-service:8097/get_token
  228. register: matrix_livekit_jwt_service_token_response
  229. changed_when: false
  230. failed_when: false
  231. - name: Parse the successful token response
  232. ansible.builtin.set_fact:
  233. matrix_livekit_jwt_service_token_document: >-
  234. {{ matrix_livekit_jwt_service_token_response.stdout | regex_replace('(?s)\s*HTTP_STATUS=[0-9]+\s*$', '') | from_json }}
  235. - name: Assert the live service returns a JWT for the configured SFU URL
  236. ansible.builtin.assert:
  237. that:
  238. - matrix_livekit_jwt_service_token_response.rc == 0
  239. - matrix_livekit_jwt_service_token_response.stdout_lines[-1] == 'HTTP_STATUS=200'
  240. - matrix_livekit_jwt_service_token_document.keys() | sort == ['jwt', 'url']
  241. - matrix_livekit_jwt_service_token_document.url == matrix_livekit_jwt_service_environment_variable_livekit_url
  242. - matrix_livekit_jwt_service_token_document.jwt.split('.') | length == 3
  243. fail_msg: "The restricted-user exchange did not return a JWT and configured SFU URL"
  244. success_msg: "The restricted-user exchange returns a real JWT for the configured SFU"
  245. - name: Decode and authenticate the returned LiveKit JWT
  246. ansible.builtin.command:
  247. argv:
  248. - python3
  249. - -c
  250. - >-
  251. import base64, hashlib, hmac, json, sys;
  252. parts = sys.argv[1].split('.');
  253. decode = lambda value: json.loads(base64.urlsafe_b64decode(value + '=' * (-len(value) % 4)));
  254. signature = base64.urlsafe_b64decode(parts[2] + '=' * (-len(parts[2]) % 4));
  255. expected = hmac.new(sys.argv[2].encode(), (parts[0] + '.' + parts[1]).encode(), hashlib.sha256).digest();
  256. print(json.dumps({'header': decode(parts[0]), 'claims': decode(parts[1]), 'signature_valid': hmac.compare_digest(signature, expected)}))
  257. - "{{ matrix_livekit_jwt_service_token_document.jwt }}"
  258. - "{{ matrix_livekit_jwt_service_environment_variable_livekit_secret }}"
  259. register: matrix_livekit_jwt_service_jwt_decode
  260. changed_when: false
  261. no_log: true
  262. - name: Assert the JWT signature, identity, room and restricted grant
  263. ansible.builtin.assert:
  264. that:
  265. - matrix_livekit_jwt_service_jwt.signature_valid is sameas true
  266. - matrix_livekit_jwt_service_jwt.header.alg == 'HS256'
  267. - matrix_livekit_jwt_service_jwt.claims.iss == matrix_livekit_jwt_service_environment_variable_livekit_key
  268. - matrix_livekit_jwt_service_jwt.claims.sub == 'BE7ZK/J/c3LsogjI1JLni7qtWV/DP6c+ev68BvHem0Y'
  269. - matrix_livekit_jwt_service_jwt.claims.video.room == 'diNaPECp1jHt2l0dLdiDxi+dgNzgucxPYMD0lCs1tEQ'
  270. - matrix_livekit_jwt_service_jwt.claims.video.roomJoin is sameas true
  271. - "'roomCreate' not in matrix_livekit_jwt_service_jwt.claims.video"
  272. - matrix_livekit_jwt_service_jwt.claims.video.canPublish is sameas true
  273. - matrix_livekit_jwt_service_jwt.claims.video.canSubscribe is sameas true
  274. - matrix_livekit_jwt_service_jwt.claims.video.canUpdateOwnMetadata is sameas true
  275. - matrix_livekit_jwt_service_jwt.claims.exp | int - matrix_livekit_jwt_service_jwt.claims.nbf | int == 3600
  276. fail_msg: "The returned JWT lost its authenticated MSC4195 identity, room or restricted join grant"
  277. success_msg: "The returned JWT has a valid signature and restricted MSC4195 grant"
  278. vars:
  279. matrix_livekit_jwt_service_jwt: "{{ matrix_livekit_jwt_service_jwt_decode.stdout | from_json }}"
  280. - name: Read the OpenID fixture's observed requests
  281. ansible.builtin.command:
  282. argv:
  283. - docker
  284. - run
  285. - --rm
  286. - --network={{ matrix_livekit_jwt_service_container_network }}
  287. - "{{ molecule_shared_image_curl }}"
  288. - --silent
  289. - --show-error
  290. - --insecure
  291. - https://matrix-livekit-jwt-openid-fixture:8443/_molecule/requests
  292. register: matrix_livekit_jwt_service_openid_requests_command
  293. changed_when: false
  294. - name: Assert the live service exercised both OpenID fixture outcomes
  295. ansible.builtin.assert:
  296. that:
  297. - matrix_livekit_jwt_service_openid_requests.requests | length >= 3
  298. - matrix_livekit_jwt_service_openid_requests.requests | map(attribute='path') | unique | list == ['/_matrix/federation/v1/openid/userinfo']
  299. - matrix_livekit_jwt_service_openid_requests.requests[-3:] | map(attribute='access_token') | list == ['unknown-openid-token', 'known-openid-token', 'known-openid-token']
  300. fail_msg: "The OpenID fixture did not observe the expected unknown and known token exchanges"
  301. success_msg: "The service exercised both HTTPS OpenID fixture outcomes"
  302. vars:
  303. matrix_livekit_jwt_service_openid_requests: "{{ matrix_livekit_jwt_service_openid_requests_command.stdout | from_json }}"
  304. - name: Read the environment file the role rendered
  305. ansible.builtin.slurp:
  306. src: "{{ matrix_livekit_jwt_service_base_path }}/env"
  307. register: matrix_livekit_jwt_service_env_file
  308. - name: Initialize the parsed environment
  309. ansible.builtin.set_fact:
  310. matrix_livekit_jwt_service_env_parsed: {}
  311. - name: Parse the rendered environment
  312. ansible.builtin.set_fact:
  313. matrix_livekit_jwt_service_env_parsed: >-
  314. {{ matrix_livekit_jwt_service_env_parsed | combine({item.split('=', 1)[0]: item.split('=', 1)[1]}) }}
  315. loop: "{{ (matrix_livekit_jwt_service_env_file.content | b64decode).splitlines() | reject('equalto', '') }}"
  316. when: "'=' in item"
  317. no_log: true
  318. - name: Assert the rendered environment carries every scenario setting
  319. ansible.builtin.assert:
  320. that:
  321. - matrix_livekit_jwt_service_env_parsed.LIVEKIT_JWT_BIND == ':8097'
  322. - matrix_livekit_jwt_service_env_parsed.LIVEKIT_KEY == 'molecule-livekit-api-key'
  323. - matrix_livekit_jwt_service_env_parsed.LIVEKIT_SECRET == 'molecule-livekit-signing-secret-32-bytes-long'
  324. - matrix_livekit_jwt_service_env_parsed.LIVEKIT_URL == 'wss://sfu.livekit.molecule.invalid:7881/rtc'
  325. - matrix_livekit_jwt_service_env_parsed.LIVEKIT_FULL_ACCESS_HOMESERVERS == 'full-access.molecule.local,second-full-access.molecule.local'
  326. - matrix_livekit_jwt_service_env_parsed.LIVEKIT_CS_API_URL_OVERRIDES == 'matrix-openid-fixture:8443=https://client-api.override.molecule.invalid'
  327. - matrix_livekit_jwt_service_env_parsed.LIVEKIT_INSECURE_SKIP_VERIFY_TLS == 'YES_I_KNOW_WHAT_I_AM_DOING'
  328. - matrix_livekit_jwt_service_env_parsed.LIVEKIT_LOG_LEVEL == 'debug'
  329. - matrix_livekit_jwt_service_env_parsed.MOLECULE_LIVEKIT_MARKER == 'environment-reached'
  330. fail_msg: "The parsed environment file does not carry the scenario's complete contract"
  331. success_msg: "The parsed environment file carries every scenario setting"
  332. no_log: true
  333. - name: Read the labels file the role rendered
  334. ansible.builtin.slurp:
  335. src: "{{ matrix_livekit_jwt_service_base_path }}/labels"
  336. register: matrix_livekit_jwt_service_labels_file
  337. - name: Initialize the parsed labels
  338. ansible.builtin.set_fact:
  339. matrix_livekit_jwt_service_labels_parsed: {}
  340. - name: Parse the rendered labels
  341. ansible.builtin.set_fact:
  342. matrix_livekit_jwt_service_labels_parsed: >-
  343. {{ matrix_livekit_jwt_service_labels_parsed | combine({item.split('=', 1)[0]: item.split('=', 1)[1]}) }}
  344. loop: "{{ (matrix_livekit_jwt_service_labels_file.content | b64decode).splitlines() | reject('equalto', '') }}"
  345. when: "'=' in item"
  346. no_log: true
  347. - name: Assert the rendered labels carry the public routing contract
  348. ansible.builtin.assert:
  349. that:
  350. - matrix_livekit_jwt_service_labels_parsed['traefik.enable'] == 'true'
  351. - matrix_livekit_jwt_service_labels_parsed['traefik.docker.network'] == matrix_livekit_jwt_service_container_network
  352. - matrix_livekit_jwt_service_labels_parsed['traefik.http.services.matrix-livekit-jwt-service.loadbalancer.server.port'] == '8097'
  353. - matrix_livekit_jwt_service_labels_parsed['traefik.http.routers.matrix-livekit-jwt-service.rule'] == 'Host(`jwt.livekit.molecule.local`) && PathPrefix(`/matrix-rtc/jwt`)'
  354. - matrix_livekit_jwt_service_labels_parsed['traefik.http.routers.matrix-livekit-jwt-service.priority'] == '847'
  355. - matrix_livekit_jwt_service_labels_parsed['traefik.http.routers.matrix-livekit-jwt-service.entrypoints'] == 'web'
  356. - matrix_livekit_jwt_service_labels_parsed['traefik.http.routers.matrix-livekit-jwt-service.tls'] == 'false'
  357. - matrix_livekit_jwt_service_labels_parsed['traefik.http.routers.matrix-livekit-jwt-service.middlewares'] == 'matrix-livekit-jwt-service-slashless-redirect,matrix-livekit-jwt-service-strip-prefix,matrix-livekit-jwt-service-add-headers'
  358. - matrix_livekit_jwt_service_labels_parsed['traefik.http.middlewares.matrix-livekit-jwt-service-add-headers.headers.customresponseheaders.X-Molecule-LiveKit'] == 'jwt-service'
  359. - matrix_livekit_jwt_service_labels_parsed['molecule.livekit-jwt.coverage'] == 'enabled'
  360. fail_msg: "The parsed labels do not carry the scenario's routing contract"
  361. success_msg: "The parsed labels carry the scenario's complete routing contract"
  362. - name: Inspect the running LiveKit JWT service container
  363. ansible.builtin.command:
  364. argv:
  365. - docker
  366. - container
  367. - inspect
  368. - matrix-livekit-jwt-service
  369. register: matrix_livekit_jwt_service_container_inspect
  370. changed_when: false
  371. - name: Assert the configured environment reached the running container
  372. ansible.builtin.assert:
  373. that:
  374. - "'LIVEKIT_JWT_BIND=:8097' in matrix_livekit_jwt_service_runtime.Config.Env"
  375. - "'LIVEKIT_FULL_ACCESS_HOMESERVERS=full-access.molecule.local,second-full-access.molecule.local' in matrix_livekit_jwt_service_runtime.Config.Env"
  376. - "'LIVEKIT_CS_API_URL_OVERRIDES=matrix-openid-fixture:8443=https://client-api.override.molecule.invalid' in matrix_livekit_jwt_service_runtime.Config.Env"
  377. - "'LIVEKIT_INSECURE_SKIP_VERIFY_TLS=YES_I_KNOW_WHAT_I_AM_DOING' in matrix_livekit_jwt_service_runtime.Config.Env"
  378. - "'MOLECULE_LIVEKIT_MARKER=environment-reached' in matrix_livekit_jwt_service_runtime.Config.Env"
  379. fail_msg: "The running container environment lost role-rendered settings"
  380. success_msg: "The role-rendered environment reached the running container"
  381. - name: Assert the configured labels reached the running container
  382. ansible.builtin.assert:
  383. that:
  384. - matrix_livekit_jwt_service_runtime.Config.Labels['traefik.enable'] == 'true'
  385. - matrix_livekit_jwt_service_runtime.Config.Labels['traefik.docker.network'] == matrix_livekit_jwt_service_container_network
  386. - matrix_livekit_jwt_service_runtime.Config.Labels['traefik.http.routers.matrix-livekit-jwt-service.priority'] == '847'
  387. - matrix_livekit_jwt_service_runtime.Config.Labels['molecule.livekit-jwt.coverage'] == 'enabled'
  388. - matrix_livekit_jwt_service_runtime.Config.Labels['molecule.livekit-jwt.extra-argument'] == 'reached'
  389. fail_msg: "The running container lost role-rendered or extra-argument labels"
  390. success_msg: "The configured labels reached the running container"
  391. - name: Assert the running container uses the exact image and version the role pins
  392. ansible.builtin.assert:
  393. that:
  394. - matrix_livekit_jwt_service_runtime.Config.Image == matrix_livekit_jwt_service_expected_image
  395. fail_msg: >-
  396. The running container uses {{ matrix_livekit_jwt_service_runtime.Config.Image }},
  397. expected {{ matrix_livekit_jwt_service_expected_image }}
  398. success_msg: "The running container uses the exact image and version defaults/main.yml pins"
  399. vars:
  400. matrix_livekit_jwt_service_expected_image: >-
  401. {{ matrix_livekit_jwt_service_role_defaults.matrix_livekit_jwt_service_container_image_registry_prefix_upstream_default }}element-hq/lk-jwt-service:{{ matrix_livekit_jwt_service_role_defaults.matrix_livekit_jwt_service_version }}
  402. - name: Assert the running container identity and image command
  403. ansible.builtin.assert:
  404. that:
  405. - matrix_livekit_jwt_service_runtime.Config.User == (matrix_user_uid | string) ~ ':' ~ (matrix_user_gid | string)
  406. - matrix_livekit_jwt_service_runtime.Config.Entrypoint | default([], true) | length == 0
  407. - matrix_livekit_jwt_service_runtime.Config.Cmd == ['/lk-jwt-service']
  408. - matrix_livekit_jwt_service_runtime.HostConfig.RestartPolicy.Name == 'no'
  409. - matrix_livekit_jwt_service_runtime.HostConfig.AutoRemove is sameas true
  410. - matrix_livekit_jwt_service_runtime.HostConfig.LogConfig.Type == 'none'
  411. fail_msg: "The running container has an unexpected identity, command or Docker lifecycle"
  412. success_msg: "The running container uses the configured identity, command and Docker lifecycle"
  413. - name: Assert the running container security and filesystem contract
  414. ansible.builtin.assert:
  415. that:
  416. - matrix_livekit_jwt_service_runtime.HostConfig.Privileged is sameas false
  417. - matrix_livekit_jwt_service_runtime.HostConfig.CapAdd | default([], true) | length == 0
  418. - matrix_livekit_jwt_service_runtime.HostConfig.CapDrop == ['ALL']
  419. - matrix_livekit_jwt_service_runtime.HostConfig.ReadonlyRootfs is sameas false
  420. - matrix_livekit_jwt_service_runtime.Mounts | length == 0
  421. - matrix_livekit_jwt_service_runtime.HostConfig.Binds | default([], true) | length == 0
  422. fail_msg: "The running container differs from the role's capability and mount contract"
  423. success_msg: "The running container has all capabilities dropped and no mounts"
  424. - name: Assert the broken upstream healthcheck is disabled
  425. ansible.builtin.assert:
  426. that:
  427. - matrix_livekit_jwt_service_runtime.Config.Healthcheck is mapping
  428. - matrix_livekit_jwt_service_runtime.Config.Healthcheck.Test == ['NONE']
  429. - matrix_livekit_jwt_service_runtime.State.Health.Status is not defined
  430. fail_msg: "The v0.6.0 image healthcheck was not disabled by the role"
  431. success_msg: "The broken v0.6.0 image healthcheck is disabled"
  432. - name: Assert the running container is attached only to its dedicated network
  433. ansible.builtin.assert:
  434. that:
  435. - matrix_livekit_jwt_service_runtime.HostConfig.NetworkMode == matrix_livekit_jwt_service_container_network
  436. - matrix_livekit_jwt_service_runtime.NetworkSettings.Networks is mapping
  437. - matrix_livekit_jwt_service_runtime.NetworkSettings.Networks | length == 1
  438. - matrix_livekit_jwt_service_container_network in matrix_livekit_jwt_service_runtime.NetworkSettings.Networks
  439. fail_msg: >-
  440. LiveKit JWT service has unexpected network attachments:
  441. {{ matrix_livekit_jwt_service_runtime.NetworkSettings.Networks.keys() | list }}
  442. success_msg: "The running container is attached only to its dedicated network"
  443. - name: Assert the observable extra runtime argument reached Docker
  444. ansible.builtin.assert:
  445. that:
  446. - matrix_livekit_jwt_service_runtime.Config.Hostname == 'livekit-jwt-molecule-runtime'
  447. fail_msg: "The configured hostname extra argument did not reach Docker"
  448. success_msg: "The approved container extra-argument setting reached Docker"
  449. - name: Ask Docker for the service's published ports
  450. ansible.builtin.command:
  451. argv:
  452. - docker
  453. - container
  454. - port
  455. - matrix-livekit-jwt-service
  456. register: matrix_livekit_jwt_service_published_ports
  457. changed_when: false
  458. failed_when: false
  459. - name: Assert the role publishes no host ports
  460. ansible.builtin.assert:
  461. that:
  462. - matrix_livekit_jwt_service_runtime.Config.ExposedPorts.keys() | list == ['8080/tcp']
  463. - matrix_livekit_jwt_service_runtime.HostConfig.PortBindings | default({}, true) | length == 0
  464. - matrix_livekit_jwt_service_published_ports.rc == 0
  465. - matrix_livekit_jwt_service_published_ports.stdout | trim | length == 0
  466. fail_msg: >-
  467. LiveKit JWT service unexpectedly publishes a host port:
  468. {{ matrix_livekit_jwt_service_published_ports.stdout | default('unknown') }}
  469. success_msg: "The role leaves the image's declared port unpublished"