(Continuing from this thread)
Thanks to @shepmaster I got authentication working; as suggested in the other thread, "token" shouldn't be taken too literally. When accessing http resources cargo will first attempt to use an unauthenticated access. If it receives a 401 it will treat the "token" as a http Authorization
header value. The "token" value should be the same format as the http header value, using the Basic
scheme.
However, I'd like to understand how to use the platform-specific credential storage to store secrets, which cargo appears to support.
These can (allegedly) be enabled by adding cargo:macos-keychain
(on macos) as a credential provider. This can either be done globally, or to a specific registry. I did this:
[registries.my-reg]
index = "sparse+http://127.0.0.1:8000/"
credential-provider = ["cargo:macos-keychain"]
.. is this correct? It feels a little odd to have a list when the key is singular (the global setting is plural).
As far as I can tell, looking at the code, the idea is that the "password" is simply the "token value". I.e. it should contain the Basic <base64 blob>
. The code says that "account" isn't used and is empty. I don't know what the exact implications of this are. It looks up the password by the service set to let service_name = registry(reg.index_url);
. The registry()
function simply adds a cargo-registry:
in front of whatever is passed to reg.index_url
.
I tried to open up my keychain and simply add a new item. In the "Keychain Item Name" I filled in cargo-registry:sparse+http://127.0.0.1:8000/
. The "Account Name" needs to be set to something, so I set it to some random value. For the "Password" I set the token blob that worked when I put it in ~/.cargo/config.toml
.
Once this has been added, I get an entry which is broken in interesting ways. the "Name" is <unknown>
, "Kind" is "Internet password", "Account" is foo
and "Where" is ¯://
(yes..). (Anyone who wants to go hunt for a CVE due to unvalidated input in Apple's Keychain application .. you're welcome).
I think it's the :
and +
that throws the keychain app off, because if I just put in a plain ol' http://127.0.0.1
it doesn't explode.
Anyway -- all this is to ask the simple question: How does one format a Keychain item so that cargo can pick it up for a custom registry?