Skip to content

fix(write): prevent writes to soft-deleted databases - #26722

Merged
philjb merged 3 commits into
mainfrom
pjb/26721/reject-writes-deleted-db
Aug 27, 2025
Merged

fix(write): prevent writes to soft-deleted databases#26722
philjb merged 3 commits into
mainfrom
pjb/26721/reject-writes-deleted-db

Conversation

@philjb

@philjb philjb commented Aug 22, 2025

Copy link
Copy Markdown
Contributor

Soft-deleted databases have been accepting write operations during their deletion grace period. Users typically have no reason to write data to a database scheduled for deletion.

This change adds validation in WriteValidator::initialize() to check if a database is marked as deleted and rejects write attempts with a DatabaseDeleted error. Querying deleted databases remains allowed for data recovery purposes.

@philjb
philjb requested a review from hiltontj August 22, 2025 21:30
Soft-deleted databases have been accepting write operations during
their deletion grace period. Users typically have no reason to write
data to a database scheduled for deletion.

This change adds validation in WriteValidator::initialize() to check if
a database is marked as deleted and rejects write attempts with a
DatabaseDeleted error. Querying deleted databases remains allowed for
data recovery purposes.

* fixes #26721
@philjb
philjb force-pushed the pjb/26721/reject-writes-deleted-db branch from 3fa1e81 to 834ed5f Compare August 22, 2025 21:30
@philjb philjb added the v3 label Aug 22, 2025

@hiltontj hiltontj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

:shipit:

@philjb

philjb commented Aug 25, 2025

Copy link
Copy Markdown
Contributor Author

example of error

> ./target/debug/influxdb3 write --database foo1-20250825T184205  "m1 f=1"
Write command failed: server responded with error [500 Internal Server Error]: write buffer error: cannot write to soft-deleted database 'foo1-20250825T184205' - it is marked for deletion

it should ideally be a 400 series error.

Other client errors also return a 500: for example, db name is too long

Write command failed: server responded with error [500 Internal Server Error]: error validating namespace name: namespace name < really long db name > length must be between 1 and 64 characters

And another with 400

Write command failed: server responded with error [400 Bad Request]: {"error":"db name "___-----" did not start with a number or letter","data":null}

This commit makes the error for attempting to write to a soft deleted db
a bad request instead of the default error mapping which is a server
error.
@philjb
philjb requested a review from hiltontj August 25, 2025 19:10
@philjb

philjb commented Aug 25, 2025

Copy link
Copy Markdown
Contributor Author

I added a commit which makes it a 400 BAD REQUEST error in the mapping now.

Write command failed: server responded with error [400 Bad Request]: {"error":"db name did not start with a number or letter"}

I also suppressed the data: null printing from the ErrorMessage struct. This does impact other errors in how they are displayed but i think for the better.

struct ErrorMessage<T: Serialize> {
error: String,
#[serde(skip_serializing_if = "Option::is_none")]
data: Option<T>,
}

#[derive(Debug, Serialize)]
struct ErrorMessage<T: Serialize> {
error: String,
#[serde(skip_serializing_if = "Option::is_none")]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This impacts how all ErrorMessage's are serialized to json for all errors that map through it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I tend to agree with this change, but it looks like this caused a test failure or two that will need to be fixed for CI to go ✅

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes! I saw the failure yesterday too but didn't get to it until today.

I believe i fixed it; CI will tell me.

let serialized = serde_json::to_string(&err).unwrap();
let body = bytes_to_response_body(serialized);
ResponseBuilder::new()
.status(StatusCode::BAD_REQUEST)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

400 bad request is better than 500 internal server error imo. I also debated 403: forbidden but i think 400 is better.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Agreed. AFAICT we've reserved 403 strictly for permissions related errors.

@philjb

philjb commented Aug 26, 2025

Copy link
Copy Markdown
Contributor Author

on merge hold for next release.

@philjb
philjb merged commit b85f938 into main Aug 27, 2025
12 checks passed
@philjb
philjb deleted the pjb/26721/reject-writes-deleted-db branch August 27, 2025 18:59
@hiltontj

Copy link
Copy Markdown
Contributor

Opened https://github.com/influxdata/influxdb_pro/issues/1222

hiltontj pushed a commit that referenced this pull request Aug 28, 2025
* fix(write): prevent writes to soft-deleted databases

Soft-deleted databases have been accepting write operations during
their deletion grace period. Users typically have no reason to write
data to a database scheduled for deletion.

This change adds validation in WriteValidator::initialize() to check if
a database is marked as deleted and rejects write attempts with a
DatabaseDeleted error. Querying deleted databases remains allowed for
data recovery purposes.

* fixes #26721

* chore: cannot write to soft deleted db is a 400 error

This commit makes the error for attempting to write to a soft deleted db
a bad request instead of the default error mapping which is a server
error.

* chore: fix test expectations because of the json output change
hiltontj added a commit that referenced this pull request Aug 28, 2025
* fix(write): prevent writes to soft-deleted databases (#26722)

* fix(write): prevent writes to soft-deleted databases

Soft-deleted databases have been accepting write operations during
their deletion grace period. Users typically have no reason to write
data to a database scheduled for deletion.

This change adds validation in WriteValidator::initialize() to check if
a database is marked as deleted and rejects write attempts with a
DatabaseDeleted error. Querying deleted databases remains allowed for
data recovery purposes.

* fixes #26721

* chore: cannot write to soft deleted db is a 400 error

This commit makes the error for attempting to write to a soft deleted db
a bad request instead of the default error mapping which is a server
error.

* chore: fix test expectations because of the json output change

* chore: Port changes from Enterprise (#26755)

* fix: Ensure catalog UUID is preserved during migration

---------

Co-authored-by: Phil Bracikowski <13472206+philjb@users.noreply.github.com>
Co-authored-by: Stuart Carnie <stuart.carnie@gmail.com>
mgattozzi pushed a commit that referenced this pull request Sep 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[v3][core] Users should not be able to write to a deleted database.

2 participants