Skip to content

Commit 5379195

Browse files
committed
disable keyring per default and only install via an extra
1 parent 3b7ef12 commit 5379195

File tree

11 files changed

+133
-66
lines changed

11 files changed

+133
-66
lines changed

docs/_index.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ Any non-ancient version of `pipx` will do.
5858
```bash
5959
pipx install poetry
6060
```
61+
62+
If you want to use a keyring for storing credentials, you can install Poetry with its `keyring` extra:
63+
64+
```bash
65+
pipx install poetry[keyring]
66+
```
67+
68+
See [Repositories - Configuring credentials]({{< relref "repositories#configuring-credentials" >}})
69+
for more information.
6170
{{< /step >}}
6271
{{< step >}}
6372
**Install Poetry (advanced)**

docs/configuration.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ across all your projects if incorrectly set.
234234

235235
**Environment Variable**: `POETRY_INSTALLER_ONLY_BINARY`
236236

237-
*Introduced in 1.9.0*
237+
*Introduced in 2.0.0*
238238

239239
When set, this configuration allows users to enforce the use of binary distribution format for all, none or
240240
specific packages.
@@ -502,10 +502,13 @@ for more information.
502502

503503
**Type**: `boolean`
504504

505-
**Default**: `true`
505+
**Default**: `false`
506506

507507
**Environment Variable**: `POETRY_KEYRING_ENABLED`
508508

509+
*Changed default to `false` in 2.0.0*
510+
509511
Enable the system keyring for storing credentials.
512+
(Requires Poetry to be installed with the `keyring` extra.)
510513
See [Repositories - Configuring credentials]({{< relref "repositories#configuring-credentials" >}})
511514
for more information.

docs/repositories.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -472,16 +472,20 @@ poetry config http-basic.pypi <username> <password>
472472
You can also specify the username and password when using the `publish` command
473473
with the `--username` and `--password` options.
474474

475-
If a system keyring is available and supported, the password is stored to and retrieved from the keyring. In the above example, the credential will be stored using the name `poetry-repository-pypi`. If access to keyring fails or is unsupported, this will fall back to writing the password to the `auth.toml` file along with the username.
476-
477-
Keyring support is enabled using the [keyring library](https://pypi.org/project/keyring/). For more information on supported backends refer to the [library documentation](https://keyring.readthedocs.io/en/latest/?badge=latest).
478-
479-
If you do not want to use the keyring, you can tell Poetry to disable it and store the credentials in plaintext config files:
475+
If a system keyring is available and supported, the password is stored to and retrieved from the keyring.
476+
Otherwise, credentials are stored in plaintext config files.
477+
In order to use keyring, you have to install Poetry with its `keyring` extra (`poetry[keyring]`)
478+
and enable keyring support:
480479

481480
```bash
482-
poetry config keyring.enabled false
481+
poetry config keyring.enabled true
483482
```
484483

484+
In the above example, the credential will be stored using the name `poetry-repository-pypi`.
485+
If access to keyring is disabled, fails or is unsupported, this will fall back to writing the password to the `auth.toml` file along with the username.
486+
487+
Keyring support is enabled using the [keyring library](https://pypi.org/project/keyring/). For more information on supported backends refer to the [library documentation](https://keyring.readthedocs.io/en/latest/?badge=latest).
488+
485489
{{% note %}}
486490

487491
Poetry will fall back to Pip style use of keyring so that backends like

poetry.lock

Lines changed: 53 additions & 46 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ dulwich = "^0.22.1"
3939
fastjsonschema = "^2.18.0"
4040
importlib-metadata = { version = ">=4.4", python = "<3.10" }
4141
installer = "^0.7.0"
42-
keyring = "^25.1.0"
42+
keyring = { version = "^25.1.0", optional = true }
4343
# packaging uses calver, so version is unclamped
4444
packaging = ">=24.0"
4545
pkginfo = "^1.10"
@@ -55,6 +55,9 @@ trove-classifiers = ">=2022.5.19"
5555
virtualenv = "^20.26.6"
5656
xattr = { version = "^1.0.0", markers = "sys_platform == 'darwin'" }
5757

58+
[tool.poetry.extras]
59+
keyring = [ "keyring" ]
60+
5861
[tool.poetry.group.dev.dependencies]
5962
pre-commit = ">=2.10"
6063
# add setuptools for PyCharm
@@ -66,6 +69,7 @@ setuptools = { version = ">=60", python = "<3.10" }
6669
coverage = ">=7.2.0"
6770
deepdiff = ">=6.3"
6871
httpretty = ">=1.1"
72+
keyring = "*" # version is constrained via extra
6973
jaraco-classes = ">=3.3.1"
7074
pytest = ">=8.0"
7175
pytest-cov = ">=4.0"
@@ -132,8 +136,19 @@ unfixable = [
132136
"ERA", # do not autoremove commented out code
133137
]
134138

139+
[tool.ruff.lint.per-file-ignores]
140+
# keyring is an extra and must only be imported in password_manager.py
141+
# and even there not globally
142+
# see flake8-tidy-imports.banned-api and .banned-module-level-imports settings
143+
"password_manager.py" = ["TID251"]
144+
"tests/*" = ["TID251", "TID253"]
145+
135146
[tool.ruff.lint.flake8-tidy-imports]
136147
ban-relative-imports = "all"
148+
banned-module-level-imports = ["keyring"] # because it is an extra
149+
150+
[tool.ruff.lint.flake8-tidy-imports.banned-api]
151+
"keyring".msg = "keyring imports are only allowed in password_manager.py"
137152

138153
[tool.ruff.lint.isort]
139154
force-single-line = true

src/poetry/config/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class Config:
133133
},
134134
"system-git-client": False,
135135
"keyring": {
136-
"enabled": True,
136+
"enabled": False,
137137
},
138138
}
139139

src/poetry/utils/password_manager.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,12 @@ def keyring(self) -> PoetryKeyring:
154154

155155
@staticmethod
156156
def warn_plaintext_credentials_stored() -> None:
157-
logger.warning("Using a plaintext file to store credentials")
157+
logger.warning(
158+
"Using a plaintext file to store credentials.\n"
159+
"Install Poetry with its `keyring` extra (`poetry[keyring]`)"
160+
"and enable it (`poetry config keyring.enabled true`)"
161+
" to store credentials securely."
162+
)
158163

159164
def set_pypi_token(self, repo_name: str, token: str) -> None:
160165
if not self.use_keyring:

tests/config/test_config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ def test_config_expands_tilde_for_virtualenvs_path(
111111
def test_disabled_keyring_is_unavailable(
112112
config: Config, with_simple_keyring: None, dummy_keyring: DummyBackend
113113
) -> None:
114+
manager = PasswordManager(config)
115+
assert not manager.use_keyring
116+
117+
config.config["keyring"]["enabled"] = True
114118
manager = PasswordManager(config)
115119
assert manager.use_keyring
116120

0 commit comments

Comments
 (0)