Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(jans-cedarling): add configurable token-to-entity mapping via CEDARLING_TOKEN_ENTITY_MAPPER #10591

Open
rmarinn opened this issue Jan 10, 2025 · 0 comments
Assignees
Labels
comp-jans-cedarling Touching folder /jans-cedarling enhancement kind-feature Issue or PR is a new feature request

Comments

@rmarinn
Copy link
Contributor

rmarinn commented Jan 10, 2025

Is your feature request related to a problem? Please describe.

When creating policies, users might need access to token entities. For instance, a token entity could be referenced in the attributes of a principal entity. Here's an example of how this might look in a schema:

namespace Jans {
    entity Access_token = {
        jti: String,
    };
    entity Custom_token = {
        jti: String,
    };
    entity Workload = {
        client_id: String,
        access_token: Access_token,
        custom_token: Custom_token,
    };
}

To streamline this process, we aim to automate the creation of these token entities and ensure they are properly referenced within principal entities. However, this requires a mechanism to link token entities to their corresponding principals during entity creation.

Furthermore, we want this solution to support any custom tokens that the user might want.

Describe the solution you'd like

Supporting custom tokens

Currently, input tokens are passed into Cedarling using a map:

input = { 
           "tokens": {
               "access_token": "...", 
               "id_token": "...", 
               "userinfo_token": "...", 
               "custom_token": "..." 
            },
           "resource": {"id": "12345", "type": "Ticket", "creator": "[email protected]", "organization": "gluu"},
           "action": "View",
           "context": {
                       "ip_address": "54.9.21.201",
                       "network_type": "VPN",
                       "user_agent": "Chrome 125.0.6422.77 (Official Build) (arm64)",
                       "time": "1719266610.98636",
                      }
         }

decision_result = authz(input)

We know that the access_token, id_token, and userinfo_token are token entities because of the CEDARLING_MAPPING_ID_TOKEN, CEDARLING_MAPPING_ACCESS_TOKEN, CEDARLING_MAPPING_USERINFO_TOKEN bootstrap entities.

To support custom tokens, we can replace the aforementioned bootstrap properties with a single bootstrap property called CEDARLING_TOKEN_ENTITY_MAPPER which is a map of token identifier -> fully qualified token entity name. for example:

CEDARLING_TOKEN_ENTITY_MAPPER = {
    "access_token": "Jans::Access_token", 
    "id_token": "Jans::Id_token", 
    "userinfo_token": "Jans::Userinfo_token", 
    "custom_token", "SomeCompany::Custom_token"
]

Automatically adding token entities to the principal entity's attributes

To automatically add token entities to the principal entity's attributes, we can employ the following approach:

  1. Create Token Entities: Begin by creating the required token entities.
  2. Store Entity References: Save the unique IDs of the created token entities for later use.
  3. Create Principal Entities: When creating a principal entity, check if its schema requires references to token entities.
    • If required token entities already exist, use their IDs to establish the reference.
    • If a required token entity is missing, fail the creation of the principal entity and log the issue.

In this approach utilize the already existing Cedar schema together with the CEDARLING_TOKEN_ENTITY_MAPPER bootstrap property to:

  1. Know which entities in the schema are token entities
  2. Know which principal entities require token entities
  3. Automatically insert token entities into the principal entity attributes if it's specified in the schema

Describe alternatives you've considered

N/A

Additional context

This feature would make token handling in Cedarling more customizable and applicable to a broader range of scenarios, including systems with non-standard or custom token usage.

@rmarinn rmarinn assigned moabu and unassigned moabu Jan 10, 2025
@mo-auto mo-auto added comp-jans-cedarling Touching folder /jans-cedarling kind-feature Issue or PR is a new feature request labels Jan 10, 2025
@rmarinn rmarinn self-assigned this Jan 12, 2025
@rmarinn rmarinn marked this as a duplicate of #10592 Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp-jans-cedarling Touching folder /jans-cedarling enhancement kind-feature Issue or PR is a new feature request
Projects
None yet
Development

No branches or pull requests

3 participants