Skip to content

Return 404 when unauthorised to access resources#1494

Merged
tobias-urdin merged 1 commit into
gnocchixyz:masterfrom
Callum027:404-on-wrong-project
May 8, 2026
Merged

Return 404 when unauthorised to access resources#1494
tobias-urdin merged 1 commit into
gnocchixyz:masterfrom
Callum027:404-on-wrong-project

Conversation

@Callum027

@Callum027 Callum027 commented Mar 21, 2026

Copy link
Copy Markdown
Contributor

When a user is not authorised to access a specific resource (e.g. did not create the resource, or not part of the project that owns the resource, or the project that created the resource), they should not be able to enumerate the resource in any way.

To prevent such users from inferring the existence of resources they should not have access to, change the policy enforcement for get resource such that it returns 404 Not Found instead of 403 Forbidden in these cases.

@Callum027 Callum027 force-pushed the 404-on-wrong-project branch 3 times, most recently from dc91177 to 018fe3b Compare March 22, 2026 00:08
@Callum027 Callum027 changed the title Return 404 when projects do not match Return 404 when unauthorised to access resources Mar 22, 2026
@Callum027 Callum027 force-pushed the 404-on-wrong-project branch 7 times, most recently from b40356f to 77b7fbf Compare March 22, 2026 22:38
Comment thread gnocchi/rest/auth_helper.py
tobias-urdin
tobias-urdin previously approved these changes Apr 10, 2026

@tobias-urdin tobias-urdin 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.

LGTM, let me know if it's good to merge

@Callum027 Callum027 force-pushed the 404-on-wrong-project branch from 77b7fbf to 34d0960 Compare May 7, 2026 21:29
@mergify mergify Bot dismissed tobias-urdin’s stale review May 7, 2026 21:29

Pull request has been modified.

When a user is not authorised to access a specific resource (e.g. did not create the resource, or not part of the project that owns the resource, or the project that created the resource), they should not be able to enumerate the resource in any way.

To prevent such users from inferring the existence of resources they should not have access to, change the policy enforcement for `get resource` such that it returns `404 Not Found` instead of `403 Forbidden` in these cases.
@Callum027 Callum027 force-pushed the 404-on-wrong-project branch from 34d0960 to 6f2cf1a Compare May 7, 2026 21:36
@Callum027

Callum027 commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

Project the resource is located in:

# openstack project show 03837612201c42dfa746b56ef65af145
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | None                             |
| domain_id   | default                          |
| enabled     | True                             |
| id          | 03837612201c42dfa746b56ef65af145 |
| is_domain   | False                            |
| name        | projectowner1.example.com        |
| parent_id   | default                          |
| tags        | []                               |
+-------------+----------------------------------+

Resource accessed by an admin:

# openstack metric resource show --type network 9c8406c3-8287-4e52-9bf9-da2c4068314d
+-----------------------+-------------------------------------------------------------------+
| Field                 | Value                                                             |
+-----------------------+-------------------------------------------------------------------+
| created_by_project_id | 7f9c10a210954feea4a6c8fdde433c96                                  |
| created_by_user_id    | 1333c5829ffc4d80aea02a7fdbaee5cd                                  |
| creator               | 1333c5829ffc4d80aea02a7fdbaee5cd:7f9c10a210954feea4a6c8fdde433c96 |
| ended_at              | None                                                              |
| id                    | 9c8406c3-8287-4e52-9bf9-da2c4068314d                              |
| metrics               | network: 3b2c0e67-c122-45ec-bddd-07d22afd89c5                     |
| name                  | test-network                                                      |
| original_resource_id  | 9c8406c3-8287-4e52-9bf9-da2c4068314d                              |
| project_id            | 03837612201c42dfa746b56ef65af145                                  |
| revision_end          | None                                                              |
| revision_start        | 2026-05-07T21:50:55.983238+00:00                                  |
| started_at            | 2026-05-07T21:50:55.983229+00:00                                  |
| type                  | network                                                           |
| user_id               | None                                                              |
+-----------------------+-------------------------------------------------------------------+

Accessed by a normal user inside the project:

# OS_PROJECT_NAME=projectowner1.example.com OS_USERNAME=projectowner1@example.com openstack metric resource show --type network 9c8406c3-8287-4e52-9bf9-da2c4068314d
+-----------------------+-------------------------------------------------------------------+
| Field                 | Value                                                             |
+-----------------------+-------------------------------------------------------------------+
| created_by_project_id | 7f9c10a210954feea4a6c8fdde433c96                                  |
| created_by_user_id    | 1333c5829ffc4d80aea02a7fdbaee5cd                                  |
| creator               | 1333c5829ffc4d80aea02a7fdbaee5cd:7f9c10a210954feea4a6c8fdde433c96 |
| ended_at              | None                                                              |
| id                    | 9c8406c3-8287-4e52-9bf9-da2c4068314d                              |
| metrics               | network: 3b2c0e67-c122-45ec-bddd-07d22afd89c5                     |
| name                  | test-network                                                      |
| original_resource_id  | 9c8406c3-8287-4e52-9bf9-da2c4068314d                              |
| project_id            | 03837612201c42dfa746b56ef65af145                                  |
| revision_end          | None                                                              |
| revision_start        | 2026-05-07T21:50:55.983238+00:00                                  |
| started_at            | 2026-05-07T21:50:55.983229+00:00                                  |
| type                  | network                                                           |
| user_id               | None                                                              |
+-----------------------+-------------------------------------------------------------------+

Access denied for a normal user outside the project (before):

# OS_PROJECT_NAME=projectowner2.example.com OS_USERNAME=projectowner2@example.com openstack metric resource show --type network 9c8406c3-8287-4e52-9bf9-da2c4068314d
Forbidden (HTTP 403)

Access denied for a normal user outside the project (after):

# OS_PROJECT_NAME=projectowner2.example.com OS_USERNAME=projectowner2@example.com openstack metric resource show --type network 9c8406c3-8287-4e52-9bf9-da2c4068314d
Resource 9c8406c3-8287-4e52-9bf9-da2c4068314d does not exist (HTTP 404)

Debug logs:

2026-05-07 21:57:29,470 [9] DEBUG    gnocchi.rest.auth_helper: Checking if user 5ba7975468a84cb69d613cd085b4765a:dfa7fa5103324c96906b21d6de310779 is allowed to access any resource in any project under policy rule [get resource].
2026-05-07 21:57:29,472 [9] DEBUG    gnocchi.rest.api: Aborting request. Code [403]. Details []
2026-05-07 21:57:29,473 [9] DEBUG    gnocchi.rest.auth_helper: User 5ba7975468a84cb69d613cd085b4765a:dfa7fa5103324c96906b21d6de310779 is NOT allowed to access any resource in any project under policy rule [get resource].
2026-05-07 21:57:29,474 [9] DEBUG    gnocchi.rest.auth_helper: Checking if user 5ba7975468a84cb69d613cd085b4765a:dfa7fa5103324c96906b21d6de310779 is allowed to access resources within their project under policy rule [get resource].
2026-05-07 21:57:29,476 [9] DEBUG    gnocchi.rest.auth_helper: User 5ba7975468a84cb69d613cd085b4765a:dfa7fa5103324c96906b21d6de310779 is allowed to access resources within their project under policy rule [get resource].
2026-05-07 21:57:29,477 [9] DEBUG    gnocchi.rest.auth_helper: User 5ba7975468a84cb69d613cd085b4765a:dfa7fa5103324c96906b21d6de310779 is NOT authenticated under the project the resource belongs to.
2026-05-07 21:57:29,478 [9] DEBUG    gnocchi.rest.auth_helper: Checking if user 5ba7975468a84cb69d613cd085b4765a:dfa7fa5103324c96906b21d6de310779 is allowed to access resources if they are part of the project that created the resource under policy rule [get resource].
2026-05-07 21:57:29,480 [9] DEBUG    gnocchi.rest.api: Aborting request. Code [403]. Details []
2026-05-07 21:57:29,480 [9] DEBUG    gnocchi.rest.auth_helper: User 5ba7975468a84cb69d613cd085b4765a:dfa7fa5103324c96906b21d6de310779 is NOT allowed to access resources if they are part of the project that created the resource under policy rule [get resource].
2026-05-07 21:57:29,481 [9] DEBUG    gnocchi.rest.auth_helper: Checking if user 5ba7975468a84cb69d613cd085b4765a:dfa7fa5103324c96906b21d6de310779 is allowed to access resources they created under policy rule [get resource].
2026-05-07 21:57:29,483 [9] DEBUG    gnocchi.rest.api: Aborting request. Code [403]. Details []
2026-05-07 21:57:29,484 [9] DEBUG    gnocchi.rest.auth_helper: User 5ba7975468a84cb69d613cd085b4765a:dfa7fa5103324c96906b21d6de310779 is NOT allowed to access resources they created under policy rule [get resource].
2026-05-07 21:57:29,484 [9] DEBUG    gnocchi.rest.auth_helper: User 5ba7975468a84cb69d613cd085b4765a:dfa7fa5103324c96906b21d6de310779 allowed access to the endpoint, but denied access to the resource under policy rule [get resource]. Forbidding access to resource 9c8406c3-8287-4e52-9bf9-da2c4068314d.
2026-05-07 21:57:29,485 [9] DEBUG    gnocchi.rest.api: Aborting request. Code [404]. Details [Resource 9c8406c3-8287-4e52-9bf9-da2c4068314d does not exist]

Note that the policy in our deployment does not allow anyone except admins and users part of the project to access resources. Creators are not allowed.

@Callum027

Copy link
Copy Markdown
Contributor Author

@tobias-urdin Sorry for the delay, I'm satisfied this is ready to go.

@Callum027 Callum027 requested a review from tobias-urdin May 7, 2026 22:09
@tobias-urdin tobias-urdin merged commit 4eb297b into gnocchixyz:master May 8, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants