acoustic-librarian-29560
05/08/2025, 5:52 PMkeyring
on its own. However, there's a bit of a thorny bootstrapping problem.
My instinct, following the script I have that does this now, is to create a keyring
subsystem, which is a PythonToolBase
subsystem that can easily export a pex for keyring
+ any additional dependencies, like keyrings.google-artifactregistry-auth
.
However, I believe the keyring pex needs to be added to to the PATH
for pex_cli processes, which python_tool_base.py
has a dependency on. Furthermore, there's also the issue of needing to call create a pex CLI process to create the keyring pex in the first place. Packaging keyring as an external tool is also problematic because it typically requires other Python dependencies to work with services like Google artifact registry.
I also tried only importing the subsystem if TYPE_CHECKING
but this doesn't work with the rule decorator. I was curious if anyone had any ideas or opinions on how to work around this.curved-manchester-66006
05/08/2025, 8:24 PMkeyring
into the sandbox that just echos the resultsgorgeous-winter-99296
05/09/2025, 9:11 AMacoustic-librarian-29560
05/09/2025, 12:39 PMPants does the auth š with some new subsystem. Said subsystem can have whatever deps it needs like a normal pants subsystemSo my view is probably somewhat limited given I've only used this in practice with Google artifact registry, but for artifact registry, there's no need to set credentials, it just relies on your global
gcloud
cli config. Is it different for AWS?curved-manchester-66006
05/09/2025, 2:20 PMaws some-command
to refresh your credentials. AWS's docs suggest using that to spit out a new ~/.config/pip/pip.conf
every 8 hours but:
⢠That's kinda gross
⢠Pants studiously avoids using pip.conf
⢠Details are fuzzy, but obviously dont' want the token to end up in the lockfile.
An alternative approach is to regen .netrc every 8 hours. That is annoying and fiddly and I thought my less technical users would rebel, but doesn't require any bootstrapping shenanegans.acoustic-librarian-29560
05/09/2025, 3:46 PMacoustic-librarian-29560
05/09/2025, 3:49 PMcurved-manchester-66006
05/09/2025, 3:57 PMacoustic-librarian-29560
05/14/2025, 3:32 PMkeyring
binary be a script that calls said pex.acoustic-librarian-29560
05/14/2025, 3:33 PMkeyring
pex using a bash script that circumvents the existing rules and circular imports.curved-manchester-66006
05/14/2025, 3:43 PMI'm taking another stab at this, did you have any thoughts around how the injected keyringTrying to page the context back in, I think the idea was that in the sandbox there would be a file called
keyring
that was dynamically generated as something like:
#!/bin/sh
echo "THE_TOKEN_PANTS_JUST_CALCULATED"
(Or whatever format pip
expects to get when calling a keyring
binary)acoustic-librarian-29560
05/27/2025, 3:38 PMfast-nail-55400
05/27/2025, 3:55 PMPexKeyringConfigurationRequest
union which allowed any Pants plugin or backend to supply credentials to Pex invocations. This PR was not AWS-specific. It basically asked plugins for credentials and arranged for a keyring
script to essentially echo those credentials.
⦠Note: Not quite as simple as an echo
though. There was some code involved to try and make sure that varying credentials would not invalidate caching for a Process
(assuming all else was the same). This occurs because varying the shell script's content in the input root leads to invalidation given the cache key is computed on basically everything going into a Process
.
⦠Also, the PR does not deal how to handle remote_environment
and docker_environent
builds. Some design work would be needed here.
⢠https://github.com/pantsbuild/pants/pull/21853 adds AWS CodeArtifact support. It tracks the expiration of the CodeArtifact token and renews it before a run when necessary. It provides an implementation of the PexKeyringConfigurationRequest
union.
GCP support would just entail building on top of the first PR. I imagine it would be much simpler than the AWS PR since it could obtain the token locally.fast-nail-55400
05/27/2025, 3:59 PMacoustic-librarian-29560
05/28/2025, 2:39 PMpants-keyring-helper
that had the ability to store credentials in a cache-accessible location (i.e. named volumes for docker_environment
) and we would call that before calling the pex CLI. Then we'd link that on the PATH
as keyring
and it would be environment aware and know how to find the stored credentials for that environment.acoustic-librarian-29560
05/28/2025, 5:45 PMfrom dataclasses import dataclass
from pants.engine.unions import union
from pants.engine.rules import Get
@union
class GenerateCredentialsRequest:
"""Union base class to generate credentials."""
@dataclass(frozen=True)
class CredentialsResult:
key: str
contents: bytes
async def generate_credentials(request: GenerateCredentialsRequest) -> None:
credentials = await Get(CredentialsResult, GenerateCredentialsRequest, request)
# Call into some (probably Rust?) function to store the credentials outside of a sandbox
# store_credentials(credentials)
fast-nail-55400
05/28/2025, 5:47 PM.pants.d
directory and stashes the credentials there.fast-nail-55400
05/28/2025, 5:48 PMdocker_environment
issue, but it's an example.)acoustic-librarian-29560
05/28/2025, 5:57 PM~/.cache/pants/credstore
or something like that for docker_environment
, which we could have the containers mount. However, that probably wouldn't work for remote execution, which I'm assuming just uses local on the remote machine.fast-nail-55400
05/28/2025, 6:05 PMfast-nail-55400
05/28/2025, 6:06 PMacoustic-librarian-29560
05/28/2025, 6:22 PMfast-nail-55400
05/28/2025, 6:42 PMfast-nail-55400
05/28/2025, 6:43 PMfast-nail-55400
05/28/2025, 6:45 PMfast-nail-55400
05/28/2025, 6:46 PMfast-nail-55400
05/28/2025, 6:46 PMacoustic-librarian-29560
05/28/2025, 6:47 PMfast-nail-55400
05/28/2025, 6:47 PMfast-nail-55400
05/28/2025, 6:48 PMfast-nail-55400
05/28/2025, 6:48 PMfast-nail-55400
05/28/2025, 6:49 PMacoustic-librarian-29560
05/28/2025, 6:50 PMfast-nail-55400
05/28/2025, 6:50 PMfast-nail-55400
05/28/2025, 6:51 PMgorgeous-winter-99296
05/28/2025, 6:51 PMgorgeous-winter-99296
05/28/2025, 6:54 PMfast-nail-55400
05/28/2025, 6:55 PMskip_cache_lookup
member of ExecuteRequest
applies to whether the remote execution system short circuits the execution by returning an already cached ActionResult
. See the spec.
⢠The choice to use the cache is on the client (i.e., Pants) calling or not calling into the REAPI GetActionResult
API. If Pants asks for remote execution, then the remote execution system will store the ActionResult
in the Action Cache (subject to application of the skip_cache_lookup
bool). If Pants decides something is uncached, it just means Pants decided to not look in the remote cache, asking for remote execution will still result in the CAS having the inputs and the Action Cache will have the resulting ActionResult
.
⢠The secret will be stored in the Command
proto (for an environment variable) and uploaded to the CAS or in a file in the input root which itself put in the CAS. So it really depends on the server's GC algorithm as to when those would be purged.fast-nail-55400
05/28/2025, 6:58 PMResultsCachePolicy
with a "priority" value for how long to cache an ActionResult
but that is interpreted in a server-specific way.fast-nail-55400
05/28/2025, 6:59 PMfast-nail-55400
05/28/2025, 7:02 PMfast-nail-55400
05/28/2025, 7:03 PMacoustic-librarian-29560
05/30/2025, 12:21 PMdocker_environment
+ it feels very hacky doing filesystem ops this way https://github.com/pantsbuild/pants/pull/22370/files#diff-6486557a2dc478e17102593a7d055c9713ee262a3ab8ed6552399ec878206532R49-R64