Skip to content

chore(streams): returns 403 when user has no read access#217742

Merged
kdelemme merged 10 commits intoelastic:mainfrom
kdelemme:streams/read-authorization-error
Apr 16, 2025
Merged

chore(streams): returns 403 when user has no read access#217742
kdelemme merged 10 commits intoelastic:mainfrom
kdelemme:streams/read-authorization-error

Conversation

@kdelemme
Copy link
Contributor

@kdelemme kdelemme commented Apr 9, 2025

Summary

Resolves https://github.com/elastic/streams-program/issues/247

This PR changes the error thrown when attempting to access a stream without the read privileges, from 404 to 403.
I had to use the functional tests feature flags setup to be able to use custom role on serverless: More details

@kdelemme kdelemme added v9.1.0 v8.19.0 backport:version Backport to applied version labels release_note:skip Skip the PR/issue when compiling release notes labels Apr 9, 2025
Comment on lines +101 to +112
export async function getCustomRoleApiClient<TServerRouteRepository extends ServerRouteRepository>(
st: ReturnType<typeof RoleScopedSupertestProvider>
): Promise<RepositorySupertestClient<TServerRouteRepository>> {
return await getApiClient(st, 'customRole');
}

export async function getAdminApiClient<TServerRouteRepository extends ServerRouteRepository>(
st: ReturnType<typeof RoleScopedSupertestProvider>
): Promise<RepositorySupertestClient<TServerRouteRepository>> {
return await getApiClient(st, 'admin');
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't want to change all the tests so I kept getAdminApiClient but one could argue we could have only one getApiClient(st, "role") instead... let me know if I should consolidate this or if it's fine like this

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm in favor of keeping the function split by role, it makes it much easier to audit later where we are using which role by a simple reference check

@kdelemme kdelemme marked this pull request as ready for review April 9, 2025 19:25
@kdelemme kdelemme requested a review from a team as a code owner April 9, 2025 19:25
@kdelemme kdelemme requested a review from a team April 9, 2025 19:25
@kdelemme kdelemme force-pushed the streams/read-authorization-error branch from 7159443 to 36eca18 Compare April 9, 2025 19:32
@kdelemme
Copy link
Contributor Author

kdelemme commented Apr 9, 2025

I thought I had a good idea
image


describe('read streams', () => {
it('fails when users has not read access', async () => {
await getStream(customRoleApiClient, STREAM_NAME, 403);
Copy link
Contributor

Choose a reason for hiding this comment

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

It's minor but perhaps we should actually test that is succeeds for the admin role?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it won't hurt adding it, but I have a problem with my setup since customRole does not seem to be available on serverless env

@kdelemme kdelemme requested review from a team as code owners April 10, 2025 13:57
@elastic-vault-github-plugin-prod elastic-vault-github-plugin-prod bot requested a review from a team as a code owner April 10, 2025 14:07
Copy link
Contributor

@dmlemeshko dmlemeshko left a comment

Choose a reason for hiding this comment

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

left a comment, should be an easy fix

export async function getCustomRoleApiClient<TServerRouteRepository extends ServerRouteRepository>(
st: ReturnType<typeof RoleScopedSupertestProvider>
): Promise<RepositorySupertestClient<TServerRouteRepository>> {
return await getApiClient(st, 'customRole');
Copy link
Contributor

Choose a reason for hiding this comment

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

In #217882 I'm changing the custom role naming and you will have to get the value via samlAuth.getCustomRole()

Could you make a change so that it won't be broken in the follow-up PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I should be able, let's see. I'll wait for your change to happen before updating

Copy link
Member

@jasonrhodes jasonrhodes left a comment

Choose a reason for hiding this comment

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

Approving on behalf of "Observability UI" without having looked at this much ... FWIW looks like this was triggered by the test_serverless/functional/.../streams/ directory, the index.ts and read_privilege.ts files. @miltonhultgren is in the "Observability UI" GH team so his review should have satisfied that CODEOWNERS requirement. Who knows.

@miltonhultgren
Copy link
Contributor

Could be those changes happened after my approval?

@kdelemme
Copy link
Contributor Author

blocked until #217882 is merged

@flash1293
Copy link
Contributor

@kdelemme seems like this is ready to go?

@kdelemme
Copy link
Contributor Author

@flash1293 saml customRoles api should have changed, let me see if I don't have to fix something

@kdelemme kdelemme changed the title chore(streams): returs 403 when user has no read access chore(streams): returns 403 when user has no read access Apr 15, 2025
@kdelemme
Copy link
Contributor Author

@flash1293 tests should be fixed now

@kdelemme kdelemme requested a review from dmlemeshko April 15, 2025 15:40
Copy link
Contributor

@dmlemeshko dmlemeshko left a comment

Choose a reason for hiding this comment

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

Code LGTM, thanks for adding CustomRoleScopedSupertestProvider

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

@kdelemme kdelemme merged commit e57a825 into elastic:main Apr 16, 2025
9 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

https://github.com/elastic/kibana/actions/runs/14501511251

@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
8.x Backport failed because of merge conflicts

Manual backport

To create the backport manually run:

node scripts/backport --pr 217742

Questions ?

Please refer to the Backport tool documentation

akowalska622 pushed a commit to akowalska622/kibana that referenced this pull request Apr 17, 2025
@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Apr 18, 2025
@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 217742 locally

2 similar comments
@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 217742 locally

@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 217742 locally

@kdelemme
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
8.19

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kdelemme added a commit to kdelemme/kibana that referenced this pull request Apr 23, 2025
)

(cherry picked from commit e57a825)

# Conflicts:
#	x-pack/test_serverless/functional/test_suites/observability/index.feature_flags.ts
@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

kdelemme added a commit that referenced this pull request Apr 24, 2025
) (#218954)

# Backport

This will backport the following commits from `main` to `8.19`:
- [chore(streams): returns 403 when user has no read access
(#217742)](#217742)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Kevin
Delemme","email":"kevin.delemme@elastic.co"},"sourceCommit":{"committedDate":"2025-04-16T20:03:18Z","message":"chore(streams):
returns 403 when user has no read access
(#217742)","sha":"e57a8259648e854891ba5c421abf0ed82c6bc9f0","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport
missing","backport:version","v9.1.0","v8.19.0"],"title":"chore(streams):
returns 403 when user has no read
access","number":217742,"url":"https://github.com/elastic/kibana/pull/217742","mergeCommit":{"message":"chore(streams):
returns 403 when user has no read access
(#217742)","sha":"e57a8259648e854891ba5c421abf0ed82c6bc9f0"}},"sourceBranch":"main","suggestedTargetBranches":["8.19"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/217742","number":217742,"mergeCommit":{"message":"chore(streams):
returns 403 when user has no read access
(#217742)","sha":"e57a8259648e854891ba5c421abf0ed82c6bc9f0"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
@kibanamachine kibanamachine removed the backport missing Added to PRs automatically when the are determined to be missing a backport. label Apr 24, 2025
akowalska622 pushed a commit to akowalska622/kibana that referenced this pull request May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:version Backport to applied version labels release_note:skip Skip the PR/issue when compiling release notes v8.19.0 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants