beads/cmd
Sam 7e4da9ab20
Add credentials file support for Dolt server passwords (#2854)
* feat: add credentials file support for Dolt server passwords

Add INI-style credentials file (~/.config/beads/credentials) as a
fallback for Dolt server passwords, keyed by [host:port] section.
This lets users working with multiple servers avoid juggling env vars
per project.

Lookup order: BEADS_DOLT_PASSWORD env var > credentials file > empty.
Path overridable via BEADS_CREDENTIALS_FILE env var.
Warns on overly permissive file permissions (unix only, mirrors ssh).

* docs: document credentials file in DOLT.md

Add credentials file section to the Dolt backend docs covering file
format, default location, permission warnings, and password resolution
order. Update the config reference and env var table to reference the
new feature.

* fix: use resolved runtime port for credentials file lookup

The credential file lookup in GetDoltServerPassword() used the port
from metadata.json, but the actual connection port comes from
doltserver.DefaultConfig() which has its own priority chain (port file >
config.yaml > metadata.json). When these diverge — e.g., IAP tunnel on
3308 vs local Dolt on 3307 — the credentials file lookup used the wrong
[host:port] section.

Add GetDoltServerPasswordForPort() that accepts an explicit port, and
use it in main.go where the resolved runtime port is already known.
Existing GetDoltServerPassword() delegates to the new method for
backward compatibility.

* fix: use mysql.Config.FormatDSN for proper password escaping

Passwords with special characters (& < > / % etc.) were inserted raw
into the DSN string, breaking go-sql-driver/mysql parsing. Passwords
like "zId&z,L9P4X,%k4n4rylGV<Ibos9<)/p" would cause "Access denied"
errors even though the password was correct.

Switch from manual fmt.Sprintf DSN construction to mysql.Config's
FormatDSN(), which handles escaping correctly. This also consolidates
timeout and TLS configuration into the typed Config struct instead of
string concatenation.

* test: add DSN special character password roundtrip tests

Covers passwords with &, <, >, /, ?, %, @, :, and () — all of which
broke the old fmt.Sprintf DSN construction. Verifies that FormatDSN
produces a parseable DSN and the password survives the roundtrip.
2026-04-02 20:35:56 -07:00
..
bd Add credentials file support for Dolt server passwords (#2854) 2026-04-02 20:35:56 -07:00