Skip to content

Update to sqlx 0.9#1992

Merged
kensimon merged 7 commits into
NVIDIA:mainfrom
kensimon:sqlx-0-9
Jun 2, 2026
Merged

Update to sqlx 0.9#1992
kensimon merged 7 commits into
NVIDIA:mainfrom
kensimon:sqlx-0-9

Conversation

@kensimon
Copy link
Copy Markdown
Contributor

@kensimon kensimon commented May 28, 2026

Description

Update the sqlx crate to 0.9.

Highlights:

  • sqlx no longer allows non-static Strings to be used in queries, due to the possibility of injection attacks. &'static str is ok, but any String we want to pass to a query needs to be adorned in sqlx::AssertSqlSafe(s) to assert that it is not vulnerable to injection. I tried to use &'static str wherever it was reasonable (there were plenty of cases of simple concatenation that could be moved to the concat!() macro), in other cases I switched to using a QueryBuilder (which returns a SqlString, which is marked as safe), and where it was less feasible I added AssertSqlSafe.

  • Change from passing the machine validation context as a String to passing it as a strongly-typed enum, so that we can be sure of its provenance, that it didn't come from user input.

  • sqlx now generates the PgHasArrayType impl when using #[derive(sqlx::Type)], so there are a couple of manual sqlx::Type impls we can now derive automatically.

  • Modify db::machine_validation and db::machine_validation_result's find_by methods to use ObjectColumnFilter instead of ObjectFilter, which gives us the query building for free. This was because I was hitting an issue using .push_bind() to pass a String to the query, since the actual columns are a UUID, and binding a string to the parameter fails. The old code was raw string-interpolating via format!("WHERE id = '{}'"), which avoids binding altogether but is a huge injection risk, so do it the "right" way via ObjectColumnFilter (which allows strongly-typed ID types, as well as not requring callers to pass the correct column name, which is also an injection risk.)

Type of Change

  • Add - New feature or capability
  • Change - Changes in existing functionality
  • Fix - Bug fixes
  • Remove - Removed features or deprecated functionality
  • Internal - Internal changes (refactoring, tests, docs, etc.)

Breaking Changes

  • This PR contains breaking changes

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • No testing required (docs, internal refactor, etc.)

Additional Notes

Highlights:

- sqlx no longer allows non-static `String`s to be used in queries, due
  to the possibility of injection attacks. `&'static str` is ok, but any
  String we want to pass to a query needs to be adorned in
  sqlx::AssertSqlSafe(s) to assert that it is not vulnerable to
  injection. I tried to use &'static str wherever it was reasonable
  (there were plenty of cases of simple concatenation that could be
  moved to the concat!() macro), in other cases I switched to using a
  QueryBuilder (which returns a SqlString, which is marked as safe), and
  where it was less feasible I added AssertSqlSafe.

- Change from passing the machine validation context as a String to
  passing it as a strongly-typed enum, so that we can be sure of its
  provenance, that it didn't come from user input.

- sqlx now generates the PgHasArrayType impl when using
  `#[derive(sqlx::Type)]`, so there are a couple of manual sqlx::Type
  impls we can now derive automatically.

- Modify db::machine_validation and db::machine_validation_result's
  find_by methods to use ObjectColumnFilter instead of ObjectFilter,
  which gives us the query building for free. This was because I was
  hitting an issue using .push_bind() to pass a String to the query,
  since the actual columns are a UUID, and binding a string to the
  parameter fails. The old code was raw string-interpolating via
  `format!("WHERE id = '{}'")`, which avoids binding altogether but is a
  huge injection risk, so do it the "right" way via ObjectColumnFilter
  (which allows strongly-typed ID types, as well as not requring callers
  to pass the correct column name, which is also an injection risk.)
@kensimon kensimon requested a review from a team as a code owner May 28, 2026 21:29
Copy link
Copy Markdown
Contributor

@poroh poroh left a comment

Choose a reason for hiding this comment

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

It would be better if this PR was split to simpler uniform parts.

Comment thread crates/api-db/src/redfish_actions.rs Outdated
The new sqlx version depends on a "whoami" crate to determine the
default username if none is provided, but with default_features = false,
which falls back on a stub backend that defaults to a username of
"anonymous", causing failed database authentication. Change the CI
database url to be explicit about the username (root) and database name
(also root) to make tests pass.
@kensimon kensimon requested a review from a team as a code owner May 29, 2026 15:42
@kensimon kensimon removed the request for review from a team June 2, 2026 16:52
@kensimon kensimon enabled auto-merge (squash) June 2, 2026 16:52
@kensimon kensimon merged commit 5e9faaa into NVIDIA:main Jun 2, 2026
52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants