Skip to content

Commit b746def

Browse files
committed
avoid using the shell, accept a list of arguments instead
1 parent 73cbf47 commit b746def

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

text/0000-cargo-token-from-process.md

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,28 @@ keyring.
2828
[guide-level-explanation]: #guide-level-explanation
2929

3030
Suppose a user has their authentication token stored in a password manager, and
31-
the password manager provides a command, `creds cargo`, to decrypt and print
32-
that token in a secure way. Instead of also storing the token in plaintext, the
33-
user can add this snippet to their own `.cargo/credentials` to authenticate
34-
with crates.io:
31+
the password manager provides a command, `/usr/bin/cargo-creds`, to decrypt and
32+
print that token in a secure way. Instead of also storing the token in
33+
plaintext, the user can add this snippet to their own `.cargo/credentials` to
34+
authenticate with crates.io:
3535

3636
```toml
3737
[registry]
38-
token-from-process = "creds cargo"
38+
token-from-process = "/usr/bin/cargo-creds"
3939
```
4040

4141
When authentication is required Cargo will execute the command and use its
42-
output as the token, which will never be stored by Cargo on disk. The command
43-
will be executed inside the system's shell environment, to allow the usage of
44-
CLI utilities:
42+
output as the token, which will never be stored by Cargo on disk. If the
43+
command requires arguments, for example `password-manager creds crates-io`, you
44+
can add them in a list:
4545

4646
```toml
4747
[registry]
48-
token-from-process = "creds cargo | awk '{print($2)}'"
48+
token-from-process = ["password-manager", "creds", "crates-io"]
4949
```
5050

51-
It will be possible to use `token-from-process` on both crates.io and alternative
52-
registries.
51+
It will be possible to use `token-from-process` on both crates.io and
52+
alternative registries.
5353

5454
# Reference-level explanation
5555
[reference-level-explanation]: #reference-level-explanation
@@ -58,14 +58,16 @@ A new key, `token-from-process`, will be added to the `[registry]` and
5858
`[registries.NAME]` sections of the `.cargo/credentials` configuration file.
5959
When a `token` key is also present, the latter will take precedence over
6060
`token-from-process` to maintain backward compatibility, and a warning will be
61-
issued to let the user know about that.
61+
issued to let the user know about that. The `token-from-process` key accepts
62+
either a string containing the binary to call or a list containing the binary
63+
name and the arguments to provide to it.
6264

6365
When a `cargo` subcommand needs the authentication token, Cargo will execute
64-
the string contained in the configuration key with the system shell (`cmd.exe`
65-
on Windows and `sh` on other platforms). The process will inherit Cargo's
66-
standard input and error, and the standard output will be captured by Cargo to
67-
read the token (with trimmed newlines). If the command returns an exit code
68-
other than `0` Cargo will treat that as a failure.
66+
the binary contained in the configuration key with the defined arguments (if
67+
provided by the user). The process will inherit Cargo's standard input and
68+
error, and the standard output will be captured by Cargo to read the token
69+
(with trimmed newlines). If the command returns an exit code other than `0`
70+
Cargo will treat that as a failure.
6971

7072
The following environment variables will be provided to the executed command:
7173

@@ -75,8 +77,7 @@ The following environment variables will be provided to the executed command:
7577
# Drawbacks
7678
[drawbacks]: #drawbacks
7779

78-
This RFC requires cargo to execute a command with the system shell, which could
79-
make it more difficult to port Cargo to a new operative system without a shell.
80+
No known drawbacks yet.
8081

8182
# Rationale and alternatives
8283
[rationale-and-alternatives]: #rationale-and-alternatives
@@ -104,8 +105,8 @@ secret storage we expect a lot of users to use.
104105
Multiple command line tools implement this system or a similar one to retrieve
105106
authentication tokens or other secrets:
106107

107-
* [awscli][awscli] includes the `credentials_process` setting with the same
108-
behavior as the one proposed in this RFC.
108+
* [awscli][awscli] includes the `credentials_process` setting with nearly the
109+
same behavior as the one proposed in this RFC.
109110
* [Docker CLI][docker] offers "credential stores", programs the Docker CLI
110111
calls with specific arguments expecting JSON output. Implementations are
111112
provided for common storage systems, and the protocol is documented for users

0 commit comments

Comments
 (0)