Skip to content

feat(slc29): inject Artifactory credentials into build tool proxy URLs - #5974

Open
rruslansaberov wants to merge 1 commit into
masterfrom
slc29-proxy-auth
Open

rruslansaberov wants to merge 1 commit into
masterfrom
slc29-proxy-auth

Conversation

@rruslansaberov

Copy link
Copy Markdown
Contributor

Test plan

  • ADO pipeline run with MS-hosted agent: verify each tool fetches via common.repositories.cloud.sap in logs
  • Self-hosted agent pipeline: verify no regression (env vars absent → original behaviour)

@rruslansaberov
rruslansaberov requested review from a team as code owners November 4, 2026 15:24

@fskhiri fskhiri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes — blockers below

Thanks for picking this up. The approach direction is right (reuse the System Trust Artifactory JWT already fetched for Docker pulls), but as currently structured the PR has three correctness bugs that will make SLC-29 flows fail on exactly the paths it's meant to enable, plus a credential-leak in debug logs. It also fans the same env-read logic across five files, when a single helper would collapse it. Please address the Tier-1 items before we re-review.

Tier 1 — Correctness (blocking)

1. Python: auth injected too late — venv bootstrap will 401

In cmd/pythonBuild.go, the PIP_INDEX_URL rewrite is placed after python.CreateVirtualEnvironment(...). That function runs pip install --upgrade setuptools (pkg/python/env.go:37), which hits PIP_INDEX_URL before credentials are injected. With the common.repositories.cloud.sap/.../simple/ default from resources#187, this fails with 401 on any MS-hosted agent.

Hint: either move the injection to the very top of runPythonBuild (before CreateVirtualEnvironment), or better — push it one layer down into pkg/python/env.go so the venv bootstrap itself is authenticated. Even better: write ~/.netrc once instead of mutating PIP_INDEX_URL; pip reads it natively and it keeps the token out of process env.

2. Gradle: only 1 of 3 init-script templates got credentials

Only mirrorInitScriptContentTemplate was patched. Both bomInitScriptContentTemplate (L93 — fetches cyclonedx-gradle-plugin:1.7.4 from ArtifactoryGradlePluginsURL at L98) and publishInitScriptContentTemplate (L33 — uses both plugin + mirror URLs at L39/L45) also resolve from the proxy and remain unauthenticated. gradle bom and gradle publish will fail on authenticated proxies.

Hint: don't fork getMirrorInitScriptContent off getInitScriptContent. Add ArtifactoryUsername + ArtifactoryPassword directly to gradleExecuteBuildOptions, keep a single getInitScriptContent, and add the {{- if .ArtifactoryUsername}} credentials { ... } {{- end}} block to every url "..." in all three templates. One code path, three templates fixed.

3. npm: auth is injected in publish.go, but npmExecuteScripts installs via pkg/npm/npm.go

The _authToken write is inside (*Execute).publish(). The install path — SetNpmRegistries in pkg/npm/npm.go:123, called from npm.go:220 and :338 — never writes credentials. The resources#187 deviation targets npmExecuteScripts.defaultNpmRegistry (install), so install stays unauthenticated.

Hint: move the _authToken write into SetNpmRegistries (or a shared helper called by both SetNpmRegistries and publish). The current placement only helps on publish, which isn't the SLC-29 use case.

4. Credential leaks in logs + process env

cmd/golangBuild.go:385: log.Entry().Debugf("GOPROXY set to: %s", proxy) now prints https://user:JWT@common.repositories.cloud.sap/.... Debug logs with the full Artifactory JWT embedded are a secret-exposure finding. Same shape for Python's PIP_INDEX_URL — once credentials are in the URL they end up in os.Environ(), subprocess env, /proc/<pid>/environ, and any child that happens to log env on error.

Hint: redact the log at minimum (log.Entry().Debug("GOPROXY configured with Artifactory auth") — don't print the URL). Better: use ~/.netrc for both Go and pip and keep the token out of URL/env entirely. Go's module proxy supports netrc auth for private proxies.

Tier 2 — Structural (strongly recommended before merge)

5. Five copies of the same env-read-and-apply

Each file has its own inline os.Getenv("PIPER_ARTIFACTORY_USER") / TOKEN / empty-check, in five different shapes (URL embed, template vars, basic header, npmrc line). This is the textbook case for one central helper. Please introduce something like:

// pkg/credentials/artifactory.go (new)
package credentials

type ArtifactoryAuth struct{ User, Token string }

func ArtifactoryFromEnv() (ArtifactoryAuth, bool)
func (a ArtifactoryAuth) InjectIntoURL(raw string) (string, error)
func (a ArtifactoryAuth) BasicAuthHeader() http.Header
func (a ArtifactoryAuth) NpmrcLine(registry string) (key, value string)

Then each build tool is one call-site, not a bespoke twelve-line block. This also gives us a single place to apply log redaction (#4) and a single point of maintenance when SystemTrust rotation details change. os.Getenv in pkg/npm/publish.go and pkg/maven/settings.go is a cross-boundary smell — reusable packages shouldn't read process env directly.

6. Maven: please reuse what's already there

pkg/maven/settings.go already exposes CreateNewProjectSettingsXML(id, user, pass, utils) and UpdateProjectSettingsXML(...) — both write proper <server> blocks. pkg/http/http.go:388 already calls req.SetBasicAuth(user, token). The PR hand-rolls "Basic " + base64.StdEncoding.EncodeToString(...) and injects it only for the settings.xml download itself, which doesn't help the subsequent mvn dependency resolve (that reads the <server> block from the downloaded settings file).

Hint: either (a) serve the settings.xml from a public URL with a <server> block referencing credentials from env (clean, zero Go changes), or (b) if auth is really needed for the settings download too, call req.SetBasicAuth via pkg/http — don't hand-roll base64.

Also: strings.Contains(url, "common.repositories.cloud.sap") matches evil.common.repositories.cloud.sap.attacker.com. Use url.Parse + hostname equality, or — preferred — drop the host gate entirely. If the env vars are set, trust them for whatever URL the step is configured against.

7. Blast radius: downloadSettingsFromURL is reached from 7+ steps

mavenBuild, mavenExecute, mavenExecuteIntegration, mtaBuild, codeqlExecuteScan, detectExecuteScan, pkg/whitesource/configHelper. Side-effecting on os.Getenv inside a shared download util changes behavior for all of them silently. Pass the header in from the caller via the existing headers http.Header param, or scope the auth injection to the single step that needs it.

Tier 3 — Layer boundary

SLC-29 is SAP-specific and jenkins-library is archive-flagged for 2026-12-31 (critical fixes only; SAP-specific steps go in piper-library). The cleanest judo here keeps jenkins-library unchanged: since piper-azure-task already has the credentials and emits the proxy URLs via dockerOptions, it could pre-authenticate the URLs (or mount a pre-filled .piperNpmrc / settings.xml / .netrc) before the OSS step ever runs. If that's not feasible for this iteration, at least isolate the SAP-specific host/credential policy behind a provider interface in piper-library so the OSS side stays generic.

Tier 4 — Tests

Zero unit tests added for five new code paths. The current test plan ("verify URLs show up in logs") doesn't catch any of #1/#2/#3 above — those pass the log check and still fail at build time. Please add:

  • pythonBuild: venv bootstrap + build with and without creds
  • gradleExecuteBuild: all three init scripts, with and without creds
  • npm: install path (SetNpmRegistries) with and without creds, scoped package
  • maven: no behavior change when env vars unset; correct behavior when set
  • URL-parse-error path returns a loud error (not silently the raw URL)

Happy to pair on the pkg/credentials/artifactory.go extraction if useful. The size of the diff shouldn't grow much after the refactor — most of the new code moves into that single file and the five call sites shrink by ~half.

@fskhiri fskhiri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see comments.

@github-actions

Copy link
Copy Markdown
Contributor

Caution

🚫 THIS PULL REQUEST CHANGES STEPS THAT MOVED TO THE INNER SOURCE PIPER LIBRARY. CHANGES TO THESE STEPS ARE NO LONGER ACCEPTED IN THIS REPOSITORY.

SAP/jenkins-library will be archived on 2026-12-31. The steps below moved to the inner source Piper library, where their development continues. Please make this change there instead.

Until the archive date, pull requests are only accepted for steps that were not moved. Full list: moved.txt.

Moved step / path Changed files
golangBuild cmd/golangBuild.go
gradleExecuteBuild cmd/gradleExecuteBuild.go
pythonBuild cmd/pythonBuild.go

⚠️ Shared code: 2 file(s)

These files are not owned by a single step that stays here. They are also used by steps that moved to the inner source Piper library, so the change likely needs to be ported there too.

  • pkg/maven/settings.go
  • pkg/npm/publish.go

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants