Skip to content

Commit ab73250

Browse files
committed
fix(rust): avoid full table scans
just a handful of places, a full review is needed
1 parent 91c9ddb commit ab73250

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

implementations/rust/ockam/ockam_abac/src/policy/storage/resource_policy_repository_sql.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl ResourcePoliciesRepository for ResourcePolicySqlxDatabase {
7777
let query = query_as(
7878
r#"SELECT resource_name, action, expression
7979
FROM resource_policy
80-
WHERE node_name = $1 and resource_name = $2 and action = $3"#,
80+
WHERE tenant_id = $1 and node_name = $1 and resource_name = $2 and action = $3"#,
8181
)
8282
.bind(&self.node_name)
8383
.bind(resource_name)
@@ -93,7 +93,7 @@ impl ResourcePoliciesRepository for ResourcePolicySqlxDatabase {
9393
let query = query_as(
9494
r#"SELECT resource_name, action, expression
9595
FROM resource_policy
96-
WHERE node_name = $1"#,
96+
WHERE tenant_id = $1 and node_name = $1"#,
9797
)
9898
.bind(&self.node_name);
9999
let row: Vec<PolicyRow> = query.fetch_all(&*self.database.pool).await.into_core()?;
@@ -109,7 +109,7 @@ impl ResourcePoliciesRepository for ResourcePolicySqlxDatabase {
109109
let query = query_as(
110110
r#"SELECT resource_name, action, expression
111111
FROM resource_policy
112-
WHERE node_name = $1 and resource_name = $2"#,
112+
WHERE tenant_id = $1 and node_name = $1 and resource_name = $2"#,
113113
)
114114
.bind(&self.node_name)
115115
.bind(resource_name);

implementations/rust/ockam/ockam_abac/src/policy/storage/resource_repository_sql.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl ResourcesRepository for ResourcesSqlxDatabase {
7070
let query = query_as(
7171
r#"SELECT resource_name, resource_type
7272
FROM resource
73-
WHERE node_name = $1 and resource_name = $2"#,
73+
WHERE tenant_id = $1 and node_name = $1 and resource_name = $2"#,
7474
)
7575
.bind(&self.node_name)
7676
.bind(resource_name);

implementations/rust/ockam/ockam_abac/src/policy/storage/resource_type_policy_repository_sql.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl ResourceTypePoliciesRepository for ResourceTypePolicySqlxDatabase {
8282
let query = query_as(
8383
r#"SELECT resource_type, action, expression
8484
FROM resource_type_policy
85-
WHERE node_name = $1 and resource_type = $2 and action = $3"#,
85+
WHERE tenant_id = $1 and node_name = $1 and resource_type = $2 and action = $3"#,
8686
)
8787
.bind(&self.node_name)
8888
.bind(resource_type)
@@ -97,7 +97,7 @@ impl ResourceTypePoliciesRepository for ResourceTypePolicySqlxDatabase {
9797
async fn get_policies(&self) -> Result<Vec<ResourceTypePolicy>> {
9898
let query = query_as(
9999
r#"SELECT resource_type, action, expression
100-
FROM resource_type_policy where node_name = $1"#,
100+
FROM resource_type_policy where tenant_id = $1 and node_name = $1"#,
101101
)
102102
.bind(&self.node_name);
103103
let row: Vec<PolicyRow> = query.fetch_all(&*self.database.pool).await.into_core()?;
@@ -112,7 +112,7 @@ impl ResourceTypePoliciesRepository for ResourceTypePolicySqlxDatabase {
112112
) -> Result<Vec<ResourceTypePolicy>> {
113113
let query = query_as(
114114
r#"SELECT resource_type, action, expression
115-
FROM resource_type_policy where node_name = $1 and resource_type = $2"#,
115+
FROM resource_type_policy where tenant_id = $1 and node_name = $1 and resource_type = $2"#,
116116
)
117117
.bind(&self.node_name)
118118
.bind(resource_type);

implementations/rust/ockam/ockam_identity/src/identities/storage/identity_attributes_repository_sql.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl IdentityAttributesRepository for IdentityAttributesSqlxDatabase {
6060
attested_by: &Identifier,
6161
) -> Result<Option<AttributesEntry>> {
6262
let query = query_as(
63-
"SELECT identifier, attributes, added, expires, attested_by FROM identity_attributes WHERE identifier = $1 AND attested_by = $2 AND node_name = $3"
63+
"SELECT identifier, attributes, added, expires, attested_by FROM identity_attributes WHERE identifier = $1 AND attested_by = $2 AND node_name = $3 and tenant_id = $3"
6464
)
6565
.bind(identity)
6666
.bind(attested_by)

0 commit comments

Comments
 (0)