Skip to content

ateapi: stop logging the raw PostgreSQL connection string (which might contain db password) at startup - #1833

Merged
Jeff Luo (JeffLuoo) merged 2 commits into
agent-substrate:mainfrom
git286:ateapi-redact-dsn-log
Oct 1, 2026
Merged

Jeff Luo (JeffLuoo) merged 2 commits into
agent-substrate:mainfrom
git286:ateapi-redact-dsn-log

Conversation

@git286

@git286 Da Huang (git286) commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

logFlagValues writes every flag to the log when the server starts, and that included --postgres-connection-string verbatim. The bundled database and Cloud SQL IAM auth use passwordless strings, but an external database DSN can carry a password, and it was written to the log on every restart.

Log the parsed, non-secret parts instead: host, port, database, user, whether a password is set and whether TLS is on. pgconn.ParseConfig handles both the URI and the libpq key=value forms, so no string rewriting is needed and nothing is echoed. A string that does not parse is logged as ""; connectStore still reports the real error.

Fixes #1832

It's a good idea to open an issue first for discussion.

  • Tests pass
  • Appropriate changes to documentation are included in the PR

Comment thread cmd/ateapi/main.go Outdated
}
cfg, err := pgconn.ParseConfig(connString)
if err != nil {
return slog.String(key, "<unparseable>")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably want to be more specific?

""

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you mean including more information from the error, I kept the marker on purpose and did not include the error. pgx's ParseConfigError.Error() embeds the whole connection string, password masked by regex.

Renamed it to to make it a little more sepcific but still static.

@git286

Copy link
Copy Markdown
Collaborator Author

Bowei Du (@bowei) rebased on main (small conflict with #1839, only the connectStore comment) and renamed the marker as you suggested. Your approval got dismissed by the push, could you re-approve and merge if it looks good? Thanks.

logFlagValues writes every flag to the log when the server starts, and
that included --postgres-connection-string verbatim. The bundled database
and Cloud SQL IAM auth use passwordless strings, but an external database
DSN can carry a password, and it was written to the log on every restart.

Log the parsed, non-secret parts instead: host, port, database, user,
whether a password is set and whether TLS is on. pgconn.ParseConfig
handles both the URI and the libpq key=value forms, so no string
rewriting is needed and nothing is echoed. A string that does not parse
is logged as "<unparseable>"; connectStore still reports the real error.
@JeffLuoo
Jeff Luo (JeffLuoo) added this pull request to the merge queue Oct 1, 2026
Merged via the queue into agent-substrate:main with commit 38b9522 Oct 1, 2026
10 checks passed
Quentin Bisson (QuentinBisson) pushed a commit to giantswarm/substrate that referenced this pull request Oct 6, 2026
…t contain db password) at startup (agent-substrate#1833)

logFlagValues writes every flag to the log when the server starts, and
that included --postgres-connection-string verbatim. The bundled
database and Cloud SQL IAM auth use passwordless strings, but an
external database DSN can carry a password, and it was written to the
log on every restart.

Log the parsed, non-secret parts instead: host, port, database, user,
whether a password is set and whether TLS is on. pgconn.ParseConfig
handles both the URI and the libpq key=value forms, so no string
rewriting is needed and nothing is echoed. A string that does not parse
is logged as "<unparseable>"; connectStore still reports the real error.

Fixes agent-substrate#1832

> It's a good idea to open an issue first for discussion.

- [x] Tests pass
- [x] Appropriate changes to documentation are included in the PR

(cherry picked from commit 38b9522)
Quentin Bisson (QuentinBisson) added a commit to giantswarm/substrate that referenced this pull request Oct 6, 2026
Quentin Bisson (QuentinBisson) pushed a commit to giantswarm/substrate that referenced this pull request Oct 8, 2026
…t contain db password) at startup (agent-substrate#1833)

logFlagValues writes every flag to the log when the server starts, and
that included --postgres-connection-string verbatim. The bundled
database and Cloud SQL IAM auth use passwordless strings, but an
external database DSN can carry a password, and it was written to the
log on every restart.

Log the parsed, non-secret parts instead: host, port, database, user,
whether a password is set and whether TLS is on. pgconn.ParseConfig
handles both the URI and the libpq key=value forms, so no string
rewriting is needed and nothing is echoed. A string that does not parse
is logged as "<unparseable>"; connectStore still reports the real error.

Fixes agent-substrate#1832

> It's a good idea to open an issue first for discussion.

- [x] Tests pass
- [x] Appropriate changes to documentation are included in the PR

(cherry picked from commit 38b9522)
Quentin Bisson (QuentinBisson) added a commit to giantswarm/substrate that referenced this pull request Oct 8, 2026
Quentin Bisson (QuentinBisson) pushed a commit to giantswarm/substrate that referenced this pull request Oct 8, 2026
…t contain db password) at startup (agent-substrate#1833)

logFlagValues writes every flag to the log when the server starts, and
that included --postgres-connection-string verbatim. The bundled
database and Cloud SQL IAM auth use passwordless strings, but an
external database DSN can carry a password, and it was written to the
log on every restart.

Log the parsed, non-secret parts instead: host, port, database, user,
whether a password is set and whether TLS is on. pgconn.ParseConfig
handles both the URI and the libpq key=value forms, so no string
rewriting is needed and nothing is echoed. A string that does not parse
is logged as "<unparseable>"; connectStore still reports the real error.

Fixes agent-substrate#1832

> It's a good idea to open an issue first for discussion.

- [x] Tests pass
- [x] Appropriate changes to documentation are included in the PR

(cherry picked from commit 38b9522)
Quentin Bisson (QuentinBisson) added a commit to giantswarm/substrate that referenced this pull request Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/api-machinery area/observability area/security Security related issue/pr kind/bug Something isn't working / bugfixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ateapi startup log prints the raw postgres connection string, which can include the db password

3 participants