Skip to content

Commit b0c82e2

Browse files
authored
Update ansible/tasks/setup-pgbackrest.yml
1 parent c74f6b2 commit b0c82e2

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

ansible/tasks/setup-pgbackrest.yml

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,37 @@
8585
ansible.builtin.copy:
8686
content: |
8787
#!/bin/bash
88-
_raw_args="$@"
89-
_sanitized_args=$(echo $_raw_args | sed -e 's/--cmd=[^ ]*//g; s/--repo-host-cmd=[^ ]*//g; s/--config=[^ ]*//g' )
90-
exec sudo -u pgbackrest /var/lib/pgbackrest/.nix-profile/bin/pgbackrest "$_sanitized_args"
88+
# Sanitize dangerous arguments
89+
sanitized_args=()
90+
while [[ $# -gt 0 ]]; do
91+
case "$1" in
92+
--cmd=*|--cmd)
93+
# Skip --cmd and its value
94+
[[ "$1" == "--cmd" ]] && shift
95+
shift || true
96+
;;
97+
--ssh-cmd=*|--ssh-cmd)
98+
# Skip --ssh-cmd and its value
99+
[[ "$1" == "--ssh-cmd" ]] && shift
100+
shift || true
101+
;;
102+
--repo-host-cmd=*|--repo-host-cmd)
103+
# Skip --repo-host-cmd and its value
104+
[[ "$1" == "--repo-host-cmd" ]] && shift
105+
shift || true
106+
;;
107+
--config=*|--config)
108+
# Skip --config and its value
109+
[[ "$1" == "--config" ]] && shift
110+
shift || true
111+
;;
112+
*)
113+
sanitized_args+=("$1")
114+
shift
115+
;;
116+
esac
117+
done
118+
exec sudo -u pgbackrest /var/lib/pgbackrest/.nix-profile/bin/pgbackrest "${sanitized_args[@]}"
91119
dest: '/usr/bin/pgbackrest'
92120
group: 'root'
93121
mode: '0755'

0 commit comments

Comments
 (0)