feat(config,client): provide a per-registry envvar scheme to set autentication#237
feat(config,client): provide a per-registry envvar scheme to set autentication#237mkatychev wants to merge 1 commit into
Conversation
|
@vados-cosmonic @ryan-surname-p I know this is a bit "hacky" so I've included this PR as a draft/proposal functionality. Ideally I'd like to see this land in 0.16 (with further tests & discussion of course) because there is a real gap in configuration currently where CI has to explicitly override config files with bearer tokens because there is no means for doing so from the environment I usually end up having to overwrite/create files and merge them with existing configs that have password as a placeholder: # wkg-config set-password --registry my-registry --password $env.OCI_BEARER_TOKEN config.toml
export def set-password [--registry: string --password: string path: path] {
# override the config.toml path
open $path
| merge deep -s overwrite {registry: {$registry: {oci: { auth: { password: $"($password)"}}}}}
| save --force $path
}
def main [] { }This change should not have regressions as we do not have an existing flow for bearer tokens |
This seems reasonable for mitigating the issue in the near term. I'm partial to the overlay approach which it looks like you have in the plans already anyway baed on the todo. |
vados-cosmonic
left a comment
There was a problem hiding this comment.
Looks good to me -- happy to have this to make things slightly easier for actual use.
| .chars() | ||
| .map(|c| if c.is_ascii_alphanumeric() { c } else { '_' }) | ||
| .collect(); | ||
| format!("WKG_REGISTRIES_{}_TOKEN", sanitized.to_ascii_uppercase()) |
There was a problem hiding this comment.
| format!("WKG_REGISTRIES_{}_TOKEN", sanitized.to_ascii_uppercase()) | |
| format!("WKG_REGISTRY_{}_AUTH_BEARER_TOKEN", sanitized.to_ascii_uppercase()) |
| if let Ok(token) = std::env::var(registry_token_env_var(&self.oci_registry)) | ||
| && !token.is_empty() | ||
| { | ||
| return Ok(RegistryAuth::Bearer(token)); |
There was a problem hiding this comment.
What do you think about leaving a log message (tracing::debug?) here to make it clear we took this shortcut/the ENV was honored?
This fills a gap where the only current ways of overriding configs through envvars are only through the
wkg ocisubcommands withWKG_OCI_USERNAMEandWKG_OCI_PASSWORD:wasm-pkg-tools/crates/wkg/src/oci.rs
Lines 14 to 32 in 6ca7180
Many OCI registries do not expect a username/password scheme and instead want to be given a bearer token.
This attempts to fill the gap by exposing
WKG_REGISTRIES_<name>_TOKENas a means of providing credentials for a given registry.This attempts to account for scenarios where multiple registries are authenticated with at once.