-
Notifications
You must be signed in to change notification settings - Fork 0
fix(security): keep credential-bearing PostgreSQL DSNs out of argv #180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c1a3abb
test(cli): reject credential-bearing DSNs from argv
seonghobae 80b4758
test(cli): reject malformed DSN without reflection
seonghobae 93cd180
fix(cli): reject credential-bearing DSN argv
seonghobae 8a0f822
docs(cli): define credential-free DSN argv boundary
seonghobae a1b779b
merge(main): compose protected security result into CLI DSN boundary
seonghobae 8560edb
test(security): cover all credential-bearing DSN parameters
seonghobae 035d45e
merge(main): integrate protected streaming head into CLI DSN hardening
seonghobae 16973ed
test(security): require loopback health listener default
seonghobae c59549f
fix(security): default readiness listener to loopback
seonghobae 584defa
chore: preserve cli source newline
seonghobae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| """Regression tests for PostgreSQL credential disclosure through CLI argv.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import pytest | ||
|
|
||
| from pg_llm_batch import cli | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "credential_dsn", | ||
| [ | ||
| "postgresql://app:secret-sentinel@db.example/batch", | ||
| "postgres://app:secret-sentinel@db.example/batch", | ||
| "host=db.example dbname=batch user=app password=secret-sentinel", | ||
| "host=db.example dbname=batch user=app passfile=/tmp/secret-sentinel.pgpass", | ||
| "host=db.example dbname=batch user=app sslkey=/tmp/secret-sentinel.key", | ||
| "host=db.example dbname=batch user=app sslpassword=secret-sentinel", | ||
| "host=db.example dbname=batch user=app oauth_client_secret=secret-sentinel", | ||
| ], | ||
| ) | ||
| def test_cli_rejects_credential_bearing_dsn_arguments_without_reflection( | ||
| credential_dsn: str, | ||
| capsys: pytest.CaptureFixture[str], | ||
| ) -> None: | ||
| """Credential-bearing DSNs fail in parsing without echoing sensitive argv.""" | ||
| parser = cli.build_parser() | ||
|
|
||
| with pytest.raises(SystemExit): | ||
| parser.parse_args(["health", "--dsn", credential_dsn]) | ||
|
|
||
| captured = capsys.readouterr() | ||
| assert "secret-sentinel" not in captured.err | ||
| assert "secret-sentinel" not in captured.out | ||
|
|
||
|
|
||
| def test_cli_rejects_malformed_dsn_without_reflection( | ||
| capsys: pytest.CaptureFixture[str], | ||
| ) -> None: | ||
| """Malformed conninfo fails with a fixed parser diagnostic.""" | ||
| parser = cli.build_parser() | ||
|
|
||
| with pytest.raises(SystemExit): | ||
| parser.parse_args( | ||
| ["health", "--dsn", "host=db.example password=secret-sentinel broken"] | ||
| ) | ||
|
|
||
| captured = capsys.readouterr() | ||
| assert "secret-sentinel" not in captured.err | ||
| assert "secret-sentinel" not in captured.out | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "selector", | ||
| [ | ||
| "postgresql://db.example/batch?sslmode=verify-full", | ||
| "host=db.example dbname=batch sslmode=verify-full", | ||
| "service=pg-llm-batch", | ||
| ], | ||
| ) | ||
| def test_cli_retains_credential_free_explicit_database_selectors(selector: str) -> None: | ||
| """Explicit database targeting remains usable when argv contains no secret.""" | ||
| args = cli.build_parser().parse_args(["health", "--dsn", selector]) | ||
|
|
||
| assert args.dsn == selector | ||
|
|
||
|
|
||
| def test_serve_healthz_cli_defaults_to_loopback() -> None: | ||
| """Direct CLI readiness serving must not bind every host interface by default.""" | ||
| args = cli.build_parser().parse_args( | ||
| ["serve-healthz", "--dsn", "postgresql://db.example/batch"] | ||
| ) | ||
|
|
||
| assert args.host == "127.0.0.1" | ||
|
|
||
|
|
||
| def test_serve_healthz_cli_allows_explicit_container_binding() -> None: | ||
| """Container callers may deliberately request an all-interface listener.""" | ||
| args = cli.build_parser().parse_args( | ||
| [ | ||
| "serve-healthz", | ||
| "--dsn", | ||
| "postgresql://db.example/batch", | ||
| "--host", | ||
| "0.0.0.0", | ||
| ] | ||
| ) | ||
|
|
||
| assert args.host == "0.0.0.0" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.