Skip to content

feat: read the stem of the stacklet:rls_access claim after a stem: prefix (ENG-9104) - #118

Merged
albertodonato merged 1 commit into
stacklet/integrationfrom
ack/feat/rls-access-stem-claim
Nov 16, 2026
Merged

albertodonato merged 1 commit into
stacklet/integrationfrom
ack/feat/rls-access-stem-claim

Conversation

@albertodonato

@albertodonato albertodonato commented Nov 16, 2026 •

Copy link
Copy Markdown

What type of PR is this?

  • Feature

Description

The platform is changing the stacklet:rls_access claim so that a scoped user's stem comes after a fixed stem: prefix, and a stem alone is no longer valid. This follows ENG-9107, and keeps a stem from ever being taken for one of the two reserved values whatever shape it has.

stacklet:rls_access Result
absent (token minted before the claim) fall back to stacklet:db_role
unrestricted db_role = None: queries run as the data source user, unfiltered
no_visibility 401
stem: then a match for [a-z0-9_]{1,20}_[0-9a-f]{6} db_role = "sso_" + stem
anything else, a stem without the prefix included 401

Only the shape accepted for a stem changes: the reserved values, the fallback to stacklet:db_role and the role names it produces are as before. This has to be deployed before the platform starts sending the prefixed value, as until then a token carrying stem:... is refused.

How is this tested?

  • Unit tests

test_jwt_sets_db_role_from_claims and test_jwt_denied_claims use the prefixed form and refuse a bare stem, a stem with nothing or a malformed value after the prefix, and a prefix in another case. I ran the claim function on those cases on its own; the suite itself needs the Docker test stack, which I didn't run.

Related Tickets & Documents

…efix (ENG-9104)

## What type of PR is this?

- [x] Feature

## Description

The platform is changing the `stacklet:rls_access` claim so that a scoped user's stem comes after a fixed `stem:` prefix, and a stem alone is no longer valid. This follows [ENG-9107](https://stacklet.atlassian.net/browse/ENG-9107), and keeps a stem from ever being taken for one of the two reserved values whatever shape it has.

| `stacklet:rls_access` | Result |
|---|---|
| absent (token minted before the claim) | fall back to `stacklet:db_role` |
| `unrestricted` | `db_role = None`: queries run as the data source user, unfiltered |
| `no_visibility` | 401 |
| `stem:` then a match for `[a-z0-9_]{1,20}_[0-9a-f]{6}` | `db_role = "sso_" + stem` |
| anything else, a stem without the prefix included | 401 |

Only the shape accepted for a stem changes: the reserved values, the fallback to `stacklet:db_role` and the role names it produces are as before. This has to be deployed before the platform starts sending the prefixed value, as until then a token carrying `stem:...` is refused.

## How is this tested?

- [x] Unit tests

`test_jwt_sets_db_role_from_claims` and `test_jwt_denied_claims` use the prefixed form and refuse a bare stem, a stem with nothing or a malformed value after the prefix, and a prefix in another case. I ran the claim function on those cases on its own; the suite itself needs the Docker test stack, which I didn't run.

## Related Tickets & Documents

- [ENG-9104](https://stacklet.atlassian.net/browse/ENG-9104)
- Epic: [ENG-9107](https://stacklet.atlassian.net/browse/ENG-9107)
@albertodonato
albertodonato marked this pull request as ready for review November 16, 2026 11:33

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.
Architecture diagram
sequenceDiagram
    participant Client as API Client
    participant Auth as Auth Service
    participant JWT as JWT Validator
    participant RLS as RLS Claim Parser
    participant DB as Database

    Client->>Auth: Request with JWT token
    Auth->>JWT: Validate and decode token
    JWT->>JWT: Extract claims payload
    JWT-->>Auth: Claims (stacklet:rls_access, stacklet:db_role)

    Auth->>RLS: _db_role_from_claims(payload)
    
    alt stacklet:rls_access absent
        RLS-->>Auth: Fall back to stacklet:db_role
    else stacklet:rls_access = "unrestricted"
        RLS-->>Auth: Return None (unfiltered access)
    else stacklet:rls_access = "no_visibility"
        RLS-->>Auth: Raise Unauthorized (401)
    else stacklet:rls_access starts with "stem:"
        RLS->>RLS: Extract stem after prefix
        alt Stem matches [a-z0-9_]{1,20}_[0-9a-f]{6}
            RLS-->>Auth: Return "sso_" + stem
        else Stem malformed
            RLS-->>Auth: Raise Unauthorized (401)
        end
    else Invalid claim format
        RLS-->>Auth: Raise Unauthorized (401)
    end

    Auth-->>Client: Response (authorized or 401)
Loading

This PR changes authentication, authorization, or input validation. Ultrareviews find 2.4x more serious bugs than standard reviews. Comment @cubic-dev-ai ultrareview to run one.

Re-trigger cubic

@fwereade fwereade left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Lgtm, thanks

@albertodonato
albertodonato merged commit 9f43d97 into stacklet/integration Nov 16, 2026
4 checks passed
@albertodonato
albertodonato deleted the ack/feat/rls-access-stem-claim branch November 16, 2026 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants