From 2a7b9f4a1d4b8b6109d8514b90b8eb63f427c428 Mon Sep 17 00:00:00 2001 From: hiddingtrojans <107155157+hiddingtrojans@users.noreply.github.com> Date: Fri, 21 Aug 2026 19:08:29 +0200 Subject: [PATCH 1/2] Add credential_hosts source param to scope HTTP(S) credentials Refs #482. When set, username/password are written to .netrc as machine-scoped entries for the listed hosts instead of the default entry, which matches every host and so sends the credentials to any host a submodule URL points at. Omitting the param keeps the previous behavior. Uses the same machine-scoping mechanism submodule_credentials already uses. Signed-off-by: hiddingtrojans <107155157+hiddingtrojans@users.noreply.github.com> --- README.md | 4 ++++ assets/common.sh | 9 ++++++++- assets/source_schema.json | 1 + test/check.sh | 26 ++++++++++++++++++++++++++ test/helpers.sh | 11 +++++++++++ 5 files changed, 50 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4a990388..a6a273f6 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,10 @@ private_key: | password (Optional) Password for HTTP(S) auth when pulling/pushing. + + credential_hosts (Optional) + List of hostnames the HTTP(S) username/password may be sent to. When set, the credentials are written to .netrc scoped to these hosts instead of the default entry, which matches every host. Hosts are specified with no protocol, e.g. github.com. Submodules on hosts not listed here will not receive these credentials; use submodule_credentials for those. When omitted, credentials match all hosts (previous behavior). + skip_ssl_verification (Optional) Skips git ssl verification by exporting GIT_SSL_NO_VERIFY=true. diff --git a/assets/common.sh b/assets/common.sh index 6a2faccb..21f5dbca 100644 --- a/assets/common.sh +++ b/assets/common.sh @@ -282,7 +282,14 @@ configure_credentials() { configure_submodule_credentials "$1" if [ "$username" != "" -a "$password" != "" ]; then - echo "default login $username password $password" >> "${HOME}/.netrc" + local credential_hosts=$(jq -r '.source.credential_hosts // [] | .[]' <<< "$1") + if [ "$credential_hosts" != "" ]; then + for host in $credential_hosts; do + echo "machine $host login $username password $password" >> "${HOME}/.netrc" + done + else + echo "default login $username password $password" >> "${HOME}/.netrc" + fi fi } diff --git a/assets/source_schema.json b/assets/source_schema.json index b9fa8775..36964c81 100644 --- a/assets/source_schema.json +++ b/assets/source_schema.json @@ -8,6 +8,7 @@ "forward_agent": "", "username": "", "password": "", + "credential_hosts": "", "paths": "", "sparse_paths": "", "ignore_paths": "", diff --git a/test/check.sh b/test/check.sh index 04df6677..64fcd7a3 100755 --- a/test/check.sh +++ b/test/check.sh @@ -168,6 +168,31 @@ EOF [ ! -f "$HOME/.netrc" ] } +it_scopes_credentials_to_credential_hosts() { + local repo=$(init_repo) + local ref=$(make_commit "$repo") + local expected_netrc + expected_netrc=$(cat < Date: Fri, 21 Aug 2026 20:08:42 +0200 Subject: [PATCH 2/2] credential_hosts: tolerate string form, not just arrays A bare string (credential_hosts: "host1") previously failed the jq iteration, and because 'local' masks the exit code the function fell through to writing the default netrc entry - silently unscoping the credentials the user meant to restrict. Accept a string (single or space-separated, matching the ignore_paths convention) as well as a list. Signed-off-by: hiddingtrojans <107155157+hiddingtrojans@users.noreply.github.com> --- assets/common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/common.sh b/assets/common.sh index 21f5dbca..38f9a060 100644 --- a/assets/common.sh +++ b/assets/common.sh @@ -282,7 +282,7 @@ configure_credentials() { configure_submodule_credentials "$1" if [ "$username" != "" -a "$password" != "" ]; then - local credential_hosts=$(jq -r '.source.credential_hosts // [] | .[]' <<< "$1") + local credential_hosts=$(jq -r '(.source.credential_hosts // []) | if type == "array" then .[] else . end' <<< "$1") if [ "$credential_hosts" != "" ]; then for host in $credential_hosts; do echo "machine $host login $username password $password" >> "${HOME}/.netrc"