Native .netrc support for authenticated package and module resolution #1767
Replies: 2 comments 6 replies
|
Hi there! Personally, I'm skeptical that this is something that Pkl should do implicitly by default, but I'm open to discuss this in more depth. I'd encourage you to join us in our biweekly community call and/or the pkl.community Discord (not maintained by us) if you'd like to discuss this in a more synchronous venue. All that said, you can achieve this pretty simply now with the support for generalized HTTP headers that was recently released with Pkl 0.32. You can place this in your Pkl settings file ( amends "pkl:settings"
http {
// Attempt to read netrc file from env-specified path, falling back to ~/.netrc
// Windows support left as an exercise to the reader (hint: import "pkl:platform")
local netrc = read?(read?("env:NETRC") ?? "\(read("env:HOME"))/.netrc")
headers {
when (netrc != null) {
for (entry in parseNetrc(netrc)) {
[entry.globPattern] {
["Authorization"] = entry.authorizationHeader
}
}
}
}
}
// Implementation left as an exercise for the reader
const local function parseNetrc(input: Resource): List<NetrcEntry> = TODO()
local class NetrcEntry {
machine: String
login: String
password: String
fixed globPattern: String = "https://\(machine)/**"
fixed authorizationHeader: String = "Basic \("\(login):\(password)".base64)"
}(this ^ is freehanded, so it may need tweaking!) This configuration appears to address every concern you've enumerated, with the exception of checking for hardened |
|
Hi @HT154 , While the above provides a way to support adding auth headers, I'm thinking from an ergonomics angle that
I believe we have until 7/22/2026@9am PT to continue here, and decide if we want to add this to the agenda of that meeting. Thanks! |
Uh oh!
There was an error while loading. Please reload this page.
Hi everyone,
Following up on the challenges discussed in #431 regarding authenticated resource loading, I want to pitch a native, zero-configuration solution for enterprise environments that enforce authentication on internal artifact registries (e.g., private Artifactory, Nexus) or private Git hosting platforms.
The Problem
In many corporate settings, anonymous access to configuration schemas is strictly prohibited. Currently, teams are forced to either run local authenticating sidecar proxies (like
pkl-proxy) or implement complexSPICE-0009external readers just to supply Basic Auth credentials.As noted by
@holzenspin #431, we cannot interpolate credentials into static string literal imports (e.g.,import "https://\(Token)@..."), and hardcoding credentials in source files is a non-starter. We need a way for Pkl to read ambient host credentials without altering the static nature of the import graph.Proposed Approach: Ambient
.netrcResolutionI am proposing that Pkl's core networking layer (
pkl-core) adds native support for evaluating industry-standard.netrc(and Windows_netrc) files during package/module resolution.When Pkl makes an outbound HTTPS request (
HttpResourceReaderorPackageResolver), it would:.netrcfile.Authorization: Basic <base64>header.How It Addresses Previous Concerns:
NETRCenvironment variable first, falling back to standard home directory locations (~/.netrcor%USERPROFILE%\_netrc). This ensures perfect compatibility with standard CI/CD workflow steps—such as theextractions/netrcGitHub Action—allowing pipelines to seamlessly pass authenticated contexts to Pkl without custom shell bootstrapping.https://schemas, never plainhttp://. We could also matchcurl's behavior and reject or warn if file permissions are laxer than0600on POSIX systems.I am highly interested in contributing this on my personal time and would love to hear thoughts from the maintainers and community on this direction. If there is alignment on the approach, I have a formal SPICE design document ready to submit to
apple/pkl-evolutionto iron out the implementation details.What do you think?
All reactions