Skip to content

Commit beed772

Browse files
CA-422448: Write proxy credentials to repo file instead of command line (#6836)
DNF5 logs command-line arguments to /var/log/dnf5.log, exposing proxy_password when passed via `dnf config-manager setopt`. Write proxy credentials directly to the .repo file (mode 0o400) and remove them after sync completes to avoid password exposure in logs. Tested: 4530865 CloudRepoUpdate With the fix, threre's no password. ``` # grep password /var/log/dnf5* [root@genus-34-01d ~]# ``` 4530867 CloudRepoUpdate Without the fix, there're passwords in the logs. ``` # grep password /var/log/dnf5* /var/log/dnf5.log:2026-01-14T09:44:42+0000 [33030] INFO --- DNF5 launched with arguments: "/usr/bin/dnf config-manager setopt remote-49e2ea36-154c-9fd4-51bb-4b319d25d05a.proxy=http://10.62.50.94:3128 remote-49e2ea36-154c-9fd4-51bb-4b319d25d05a.proxy_username=debian remote-49e2ea36-154c-9fd4-51bb-4b319d25d05a.proxy_password=JwNm8I2rAxlB" --- /var/log/dnf5.log.1:2026-01-14T09:44:42+0000 [33023] INFO --- DNF5 launched with arguments: "/usr/bin/dnf config-manager setopt remote-9b300a0d-765a-3426-5ad2-0384bc427c28.proxy=http://10.62.50.94:3128 remote-9b300a0d-765a-3426-5ad2-0384bc427c28.proxy_username=debian remote-9b300a0d-765a-3426-5ad2-0384bc427c28.proxy_password=JwNm8I2rAxlB" --- ```
2 parents df259c4 + 6b4237f commit beed772

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

ocaml/tests/test_repository_helpers.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,8 @@ module WriteYumConfig = Generic.MakeStateless (struct
346346
let gpgkey_path' = Option.value ~default:"" name in
347347
try
348348
(* The path of file which will be written by write_yum_config *)
349-
write_yum_config ~source_url ~binary_url ~repo_gpgcheck:true
350-
~gpgkey_path:gpgkey_path' ~repo_name ;
349+
write_yum_config ~proxy_config:[] ~source_url ~binary_url
350+
~repo_gpgcheck:true ~gpgkey_path:gpgkey_path' ~repo_name ;
351351
let in_ch = open_in repo_file_path in
352352
let content = read_from_in_channel "" in_ch in
353353
close_in in_ch ; finally () ; Ok content

ocaml/xapi/repository.ml

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,12 @@ let sync ~__context ~self ~token ~token_id ~username ~password =
224224
| s ->
225225
s
226226
in
227-
let write_initial_yum_config ~binary_url =
228-
write_yum_config ~source_url ~binary_url ~repo_gpgcheck:true ~gpgkey_path
229-
~repo_name
227+
let proxy_config =
228+
match use_proxy with true -> get_proxy_params ~__context | false -> []
229+
in
230+
let write_initial_yum_config ~proxy_config ~binary_url =
231+
write_yum_config ~proxy_config ~source_url ~binary_url ~repo_gpgcheck:true
232+
~gpgkey_path ~repo_name
230233
in
231234
Xapi_stdext_pervasives.Pervasiveext.finally
232235
(fun () ->
@@ -255,7 +258,7 @@ let sync ~__context ~self ~token ~token_id ~username ~password =
255258

256259
with_sync_client_auth client_auth @@ fun client_auth ->
257260
with_sync_server_auth server_auth @@ fun binary_url' ->
258-
write_initial_yum_config
261+
write_initial_yum_config ~proxy_config
259262
~binary_url:(Option.value binary_url' ~default:binary_url) ;
260263
clean_yum_cache repo_name ;
261264
(* Remove imported YUM repository GPG key *)
@@ -272,15 +275,10 @@ let sync ~__context ~self ~token ~token_id ~username ~password =
272275
| None ->
273276
[]
274277
in
275-
let proxy_params =
276-
match use_proxy with
277-
| true ->
278-
get_proxy_params ~__context
279-
| false ->
280-
[]
281-
in
282-
auth_params @ proxy_params |> fun x ->
283-
config_repo x ; make_cache () ; sync_repo ()
278+
(* Proxy config is now written directly to repo file, so only pass
279+
* auth_params to config_repo to avoid exposing credentials in
280+
* command-line arguments which get logged by DNF5 *)
281+
config_repo auth_params ; make_cache () ; sync_repo ()
284282
)
285283
(fun () ->
286284
(* Rewrite repo conf file as initial content to remove credential
@@ -294,7 +292,8 @@ let sync ~__context ~self ~token ~token_id ~username ~password =
294292
*)
295293
match Pkgs.manager with
296294
| Yum ->
297-
write_initial_yum_config ~binary_url
295+
(* Write clean config without proxy credentials *)
296+
write_initial_yum_config ~proxy_config:[] ~binary_url
298297
| Dnf ->
299298
Unixext.unlink_safe !Xapi_globs.dnf_repo_config_file
300299
) ;

ocaml/xapi/repository_helpers.ml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ let remove_repo_conf_file repo_name =
310310
in
311311
Unixext.unlink_safe path
312312

313-
let write_yum_config ~source_url ~binary_url ~repo_gpgcheck ~gpgkey_path
314-
~repo_name =
313+
let write_yum_config ~proxy_config ~source_url ~binary_url ~repo_gpgcheck
314+
~gpgkey_path ~repo_name =
315315
let file_path =
316316
Filename.concat !Xapi_globs.yum_repos_config_dir (repo_name ^ ".repo")
317317
in
@@ -344,6 +344,7 @@ let write_yum_config ~source_url ~binary_url ~repo_gpgcheck ~gpgkey_path
344344
; opt_gpgcheck
345345
; opt_gpgkey
346346
]
347+
@ proxy_config
347348
in
348349
let content_of_source =
349350
match source_url with
@@ -445,8 +446,8 @@ let with_local_repositories ~__context f =
445446
s
446447
in
447448
remove_repo_conf_file repo_name ;
448-
write_yum_config ~source_url:None ~binary_url ~repo_gpgcheck:false
449-
~gpgkey_path ~repo_name ;
449+
write_yum_config ~proxy_config:[] ~source_url:None ~binary_url
450+
~repo_gpgcheck:false ~gpgkey_path ~repo_name ;
450451
clean_yum_cache repo_name ;
451452
let Pkg_mgr.{cmd; params} =
452453
[

0 commit comments

Comments
 (0)