fix(cloudflared): refuse unsafe hostnames, names, paths and tunnel ids
Ingress hostnames must be lowercase, with an optional leading *. and no whitespace: they land unquoted in config.yml. The service account names and directories must hold no newline or %, which the unit would read as directives, and the directories must be absolute. A set tunnel id must be a lowercase UUID, the shape the stale-credentials search relies on. Each refusal has a negative case in the scenario. Assisted-by: Claude Code:claude-opus-5-5
This commit is contained in:
1 parent
ee0fa0e89e
commit
fd1e9b67dd
3 files changed
+59
No files matched your search
@@ -20,6 +20,9 @@
|
|||||||
cloudflared_manage_dns: "{{ cloudflared_test_case.vars.cloudflared_manage_dns | default(false) }}"
|
cloudflared_manage_dns: "{{ cloudflared_test_case.vars.cloudflared_manage_dns | default(false) }}"
|
||||||
cloudflared_zone_name: "{{ cloudflared_test_case.vars.cloudflared_zone_name | default('') }}"
|
cloudflared_zone_name: "{{ cloudflared_test_case.vars.cloudflared_zone_name | default('') }}"
|
||||||
cloudflared_ingress: "{{ cloudflared_test_case.vars.cloudflared_ingress | default(cloudflared_test_ingress) }}"
|
cloudflared_ingress: "{{ cloudflared_test_case.vars.cloudflared_ingress | default(cloudflared_test_ingress) }}"
|
||||||
|
cloudflared_user: "{{ cloudflared_test_case.vars.cloudflared_user | default('cloudflared') }}"
|
||||||
|
cloudflared_install_dir: "{{ cloudflared_test_case.vars.cloudflared_install_dir | default('/usr/local/bin') }}"
|
||||||
|
cloudflared_config_dir: "{{ cloudflared_test_case.vars.cloudflared_config_dir | default('/etc/cloudflared') }}"
|
||||||
|
|
||||||
# Only reached when the include returned. The message must not contain the expected
|
# Only reached when the include returned. The message must not contain the expected
|
||||||
# text, so the rescue below cannot mistake it for the failure under test.
|
# text, so the rescue below cannot mistake it for the failure under test.
|
||||||
|
|||||||
@@ -139,6 +139,24 @@
|
|||||||
- name: ingress-without-service
|
- name: ingress-without-service
|
||||||
vars: {cloudflared_ingress: [{hostname: app.example.test}]}
|
vars: {cloudflared_ingress: [{hostname: app.example.test}]}
|
||||||
expect: each with hostname and service
|
expect: each with hostname and service
|
||||||
|
- name: hostname-uppercase
|
||||||
|
vars: {cloudflared_ingress: [{hostname: App.example.test, service: "http://127.0.0.1:8080"}]}
|
||||||
|
expect: must be lowercase letters
|
||||||
|
- name: hostname-whitespace
|
||||||
|
vars: {cloudflared_ingress: [{hostname: "app.example.test\n - service: x", service: "http://127.0.0.1:8080"}]}
|
||||||
|
expect: must be lowercase letters
|
||||||
|
- name: user-with-percent
|
||||||
|
vars: {cloudflared_user: "cloud%flared"}
|
||||||
|
expect: must not contain a newline or %
|
||||||
|
- name: config-dir-with-newline
|
||||||
|
vars: {cloudflared_config_dir: "/etc/cloudflared\nExecStartPre=/bin/false"}
|
||||||
|
expect: must not contain a newline or %
|
||||||
|
- name: install-dir-relative
|
||||||
|
vars: {cloudflared_install_dir: usr/local/bin}
|
||||||
|
expect: the two directories must be absolute paths
|
||||||
|
- name: tunnel-id-not-uuid
|
||||||
|
vars: {cloudflared_tunnel_id: not-a-uuid}
|
||||||
|
expect: must be a lowercase UUID
|
||||||
- name: tunnel-not-minted
|
- name: tunnel-not-minted
|
||||||
vars: {cloudflared_tunnel_id: ""}
|
vars: {cloudflared_tunnel_id: ""}
|
||||||
expect: run the mint entry point first
|
expect: run the mint entry point first
|
||||||
|
|||||||
@@ -35,6 +35,34 @@
|
|||||||
originRequest).
|
originRequest).
|
||||||
quiet: true
|
quiet: true
|
||||||
|
|
||||||
|
# A hostname lands unquoted in config.yml and is compared with DNS record names.
|
||||||
|
- name: Require plain lowercase ingress hostnames
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- cloudflared_ingress | map(attribute='hostname') | reject('string') | list | length == 0
|
||||||
|
- cloudflared_ingress | map(attribute='hostname') | reject('match', '^(\\*\\.)?[a-z0-9_.-]+\\Z') | list | length == 0
|
||||||
|
fail_msg: >-
|
||||||
|
Every cloudflared_ingress hostname must be lowercase letters, digits, dots, hyphens or underscores,
|
||||||
|
with an optional leading *. and no whitespace or newline.
|
||||||
|
quiet: true
|
||||||
|
|
||||||
|
# The values land in the systemd unit and in file paths: a newline or % would inject or expand
|
||||||
|
# unit directives.
|
||||||
|
- name: Require plain service account names and absolute directories
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- cloudflared_user is string
|
||||||
|
- cloudflared_group is string
|
||||||
|
- cloudflared_install_dir is string
|
||||||
|
- cloudflared_config_dir is string
|
||||||
|
- (cloudflared_user ~ cloudflared_group ~ cloudflared_install_dir ~ cloudflared_config_dir) is not search('[\\r\\n%]')
|
||||||
|
- cloudflared_install_dir is match('/')
|
||||||
|
- cloudflared_config_dir is match('/')
|
||||||
|
fail_msg: >-
|
||||||
|
cloudflared_user, cloudflared_group, cloudflared_install_dir and cloudflared_config_dir must not contain a
|
||||||
|
newline or %, and the two directories must be absolute paths.
|
||||||
|
quiet: true
|
||||||
|
|
||||||
# The role never creates the tunnel on its main entry point. Defined and empty (or null) counts
|
# The role never creates the tunnel on its main entry point. Defined and empty (or null) counts
|
||||||
# as missing, as in the mint entry point, so the two cannot disagree.
|
# as missing, as in the mint entry point, so the two cannot disagree.
|
||||||
- name: Require the minted tunnel secrets
|
- name: Require the minted tunnel secrets
|
||||||
@@ -50,6 +78,16 @@
|
|||||||
quiet: true
|
quiet: true
|
||||||
when: not (cloudflared_remove | bool)
|
when: not (cloudflared_remove | bool)
|
||||||
|
|
||||||
|
# The id names the credentials file, and stale credentials are found by the UUID shape.
|
||||||
|
- name: Require a UUID tunnel id
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- >-
|
||||||
|
cloudflared_tunnel_id | default('', true) | string | length == 0 or
|
||||||
|
cloudflared_tunnel_id | string is match('^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\\Z')
|
||||||
|
fail_msg: cloudflared_tunnel_id must be a lowercase UUID, as the mint entry point returns it.
|
||||||
|
quiet: true
|
||||||
|
|
||||||
# Every Cloudflare call below needs them: the tunnel check on every run, the tunnel deletion
|
# Every Cloudflare call below needs them: the tunnel check on every run, the tunnel deletion
|
||||||
# of a removal with cloudflared_remove_data.
|
# of a removal with cloudflared_remove_data.
|
||||||
- name: Require the Cloudflare API credentials
|
- name: Require the Cloudflare API credentials
|
||||||
|
|||||||
Reference in new issue
Block a user