Skip to content

Commit 5ff8afe

Browse files
committed
Treat permission denied as 403
Signed-off-by: Piotr Jastrzebski <[email protected]>
1 parent 3d01e74 commit 5ff8afe

9 files changed

+14
-11
lines changed

libsql-server/src/auth/authenticated.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ impl Authenticated {
6767
perm: Permission,
6868
) -> crate::Result<()> {
6969
match self {
70-
Authenticated::Anonymous => Err(crate::Error::NotAuthorized(
70+
Authenticated::Anonymous => Err(crate::Error::Forbidden(
7171
"anonymous access not allowed".to_string(),
7272
)),
7373
Authenticated::Authorized(a) => {
7474
if !a.has_right(Scope::Namespace(namespace.clone()), perm) {
75-
Err(crate::Error::NotAuthorized(format!(
75+
Err(crate::Error::Forbidden(format!(
7676
"Current session doesn't not have {perm:?} permission to namespace {namespace}")))
7777
} else {
7878
Ok(())
@@ -84,7 +84,7 @@ impl Authenticated {
8484
{
8585
Ok(())
8686
} else {
87-
Err(crate::Error::NotAuthorized(format!(
87+
Err(crate::Error::Forbidden(format!(
8888
"Current session doesn't not have {perm:?} permission to namespace {namespace}")))
8989
}
9090
}
@@ -95,7 +95,7 @@ impl Authenticated {
9595
match self {
9696
Authenticated::Authorized(a) if a.ddl_permitted(namespace) => Ok(()),
9797
Authenticated::FullAccess => Ok(()),
98-
_ => Err(crate::Error::NotAuthorized(format!(
98+
_ => Err(crate::Error::Forbidden(format!(
9999
"DDL statements not permitted on namespace {namespace}"
100100
))),
101101
}

libsql-server/src/connection/program.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ pub async fn check_program_auth(
371371
StmtKind::Attach(ref ns) => {
372372
ctx.auth.has_right(ns, Permission::AttachRead)?;
373373
if !ctx.meta_store.handle(ns.clone()).await.get().allow_attach {
374-
return Err(Error::NotAuthorized(format!(
374+
return Err(Error::Forbidden(format!(
375375
"Namespace `{ns}` doesn't allow attach"
376376
)));
377377
}

libsql-server/src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ pub enum Error {
3737
InvalidBatchStep(usize),
3838
#[error("Not authorized to execute query: {0}")]
3939
NotAuthorized(String),
40+
#[error("Authorization forbidden: {0}")]
41+
Forbidden(String),
4042
#[error("The replicator exited, instance cannot make any progress.")]
4143
ReplicatorExited,
4244
#[error("Timed out while opening database connection")]
@@ -176,6 +178,7 @@ impl IntoResponse for &Error {
176178
Internal(_) => self.format_err(StatusCode::INTERNAL_SERVER_ERROR),
177179
InvalidBatchStep(_) => self.format_err(StatusCode::INTERNAL_SERVER_ERROR),
178180
NotAuthorized(_) => self.format_err(StatusCode::UNAUTHORIZED),
181+
Forbidden(_) => self.format_err(StatusCode::FORBIDDEN),
179182
ReplicatorExited => self.format_err(StatusCode::SERVICE_UNAVAILABLE),
180183
DbCreateTimeout => self.format_err(StatusCode::TOO_MANY_REQUESTS),
181184
BuilderError(_) => self.format_err(StatusCode::INTERNAL_SERVER_ERROR),

libsql-server/tests/namespaces/snapshots/tests__namespaces__shared_schema__check_migration_perms.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ expression: "conn.execute(\"create table test (x)\", ()).await.unwrap_err()"
44
---
55
Hrana(
66
Api(
7-
"{\"error\":\"Not authorized to execute query: Current session doesn't not have Write permission to namespace schema\"}",
7+
"{\"error\":\"Authorization forbidden: Current session doesn't not have Write permission to namespace schema\"}",
88
),
99
)

libsql-server/tests/namespaces/snapshots/tests__namespaces__shared_schema__disable_ddl.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ expression: "conn.execute(\"create table test (x)\", ()).await.unwrap_err()"
44
---
55
Hrana(
66
Api(
7-
"{\"error\":\"Not authorized to execute query: DDL statements not permitted on namespace ns1\"}",
7+
"{\"error\":\"Authorization forbidden: DDL statements not permitted on namespace ns1\"}",
88
),
99
)

libsql-server/tests/standalone/snapshots/tests__standalone__attach__attach_auth-2.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ expression: "txn.execute(\"ATTACH DATABASE bar as bar\", ()).await.unwrap_err()"
44
---
55
Hrana(
66
Api(
7-
"{\"error\":\"Not authorized to execute query: Current session doesn't not have AttachRead permission to namespace bar\"}",
7+
"{\"error\":\"Authorization forbidden: Current session doesn't not have AttachRead permission to namespace bar\"}",
88
),
99
)

libsql-server/tests/standalone/snapshots/tests__standalone__attach__attach_auth-3.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ expression: "bar_conn.execute(\"ATTACH foo as foo\", ()).await.unwrap_err()"
44
---
55
Hrana(
66
Api(
7-
"{\"error\":\"Not authorized to execute query: Namespace `foo` doesn't allow attach\"}",
7+
"{\"error\":\"Authorization forbidden: Namespace `foo` doesn't allow attach\"}",
88
),
99
)

libsql-server/tests/standalone/snapshots/tests__standalone__attach__attach_auth.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ expression: "bar_conn.execute(\"ATTACH foo as foo\", ()).await.unwrap_err()"
44
---
55
Hrana(
66
Api(
7-
"{\"error\":\"Not authorized to execute query: Current session doesn't not have AttachRead permission to namespace foo\"}",
7+
"{\"error\":\"Authorization forbidden: Current session doesn't not have AttachRead permission to namespace foo\"}",
88
),
99
)

libsql-server/tests/standalone/snapshots/tests__standalone__attach__attach_no_auth.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ expression: "bar_conn.execute(\"ATTACH foo as foo\", ()).await.unwrap_err()"
44
---
55
Hrana(
66
Api(
7-
"{\"error\":\"Not authorized to execute query: Namespace `foo` doesn't allow attach\"}",
7+
"{\"error\":\"Authorization forbidden: Namespace `foo` doesn't allow attach\"}",
88
),
99
)

0 commit comments

Comments
 (0)