-
Notifications
You must be signed in to change notification settings - Fork 697
UN-2407 [FEAT] Add global API deployment keys for grouped API deployments #1881
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
Merged
muhammad-ali-e
merged 15 commits into
main
from
UN-2407-unstract-api-need-to-generate-common-api-key-for-group-of-api-deployments
Aug 6, 2026
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
4ee988e
UN-2407 [FEAT] Add global API deployment keys for grouped API deploym…
Deepak-Kesavan 4f761fc
UN-2407 [FIX] Address PR review comments for global API deployment keys
Deepak-Kesavan dca5581
UN-2407 [FIX] Add admin permission message and hoist DeploymentScopeF…
Deepak-Kesavan a66cbb5
Merge remote-tracking branch 'origin/main' into UN-2407-sync
Deepak-Kesavan cb51b3c
UN-2407 [FIX] Address review comments: shared safe-text util + org-sc…
Deepak-Kesavan 4b759af
UN-2407 [FIX] Add migration for editable=False on organization field
Deepak-Kesavan 985d3db
UN-2407 [FIX] Deployment subset assignment + self-review fixes
Deepak-Kesavan 06b0770
UN-2407 [FIX] Address human review: least-privilege default, scope va…
Deepak-Kesavan 68fb2e9
UN-2407 [FIX] Address review: audit identity + per-reason logging + s…
Deepak-Kesavan c45d5a0
UN-2407 [FIX] Extract shared ApiKeyManager; de-duplicate platform + g…
Deepak-Kesavan e25728a
UN-2407 [FIX] Merge implicitly concatenated string (SonarCloud S5799)
Deepak-Kesavan fa93485
UN-2407 [FIX] Global-key auth tests, PATCH scope traps, import-time D…
Deepak-Kesavan b7bc6f3
Merge remote-tracking branch 'origin/main' into merge-main-into-un2407
Deepak-Kesavan 37b7eda
UN-2407 [FIX] Address PR review: select_related on key list, Sonar te…
Deepak-Kesavan c5341fe
Merge branch 'main' into UN-2407-unstract-api-need-to-generate-common…
muhammad-ali-e File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,30 @@ | ||
| from dataclasses import dataclass | ||
| from dataclasses import dataclass, field | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| from api_v2.models import APIDeployment | ||
|
|
||
| if TYPE_CHECKING: | ||
| from global_api_deployment_key.models import GlobalApiDeploymentKey | ||
|
|
||
| @dataclass | ||
|
|
||
| @dataclass(frozen=True) | ||
| class DeploymentExecutionDTO: | ||
| """DTO for deployment execution viewset.""" | ||
| """DTO for deployment execution viewset. | ||
|
|
||
| Frozen: built once per request in ``DeploymentHelper.validate_api_key`` and | ||
| only read downstream. | ||
| """ | ||
|
|
||
| api: APIDeployment | ||
| api_key: str | ||
| # repr=False: this is the live bearer credential. Without it the generated | ||
| # __repr__ writes the raw key into any ``logger.debug("...%s", dto)`` or | ||
| # exception repr that touches this object. | ||
| api_key: str = field(repr=False) | ||
| # The global API deployment key that authorized this execution, if any. | ||
| # Carrying the resolved key (not just a bool) preserves audit identity — | ||
| # "which named key authorized this?" — for downstream logging/incidents. | ||
| global_key: "GlobalApiDeploymentKey | None" = None | ||
|
|
||
| @property | ||
| def is_global_key(self) -> bool: | ||
| return self.global_key is not None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| from django.apps import AppConfig | ||
|
|
||
|
|
||
| class GlobalApiDeploymentKeyConfig(AppConfig): | ||
| default_auto_field = "django.db.models.BigAutoField" | ||
| name = "global_api_deployment_key" |
94 changes: 94 additions & 0 deletions
94
backend/global_api_deployment_key/migrations/0001_initial.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| # Generated by Django 4.2.1 on 2026-03-25 18:22 | ||
|
|
||
| import uuid | ||
|
|
||
| import django.db.models.deletion | ||
| from django.conf import settings | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| initial = True | ||
|
|
||
| dependencies = [ | ||
| migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
| ("account_v2", "0004_user_is_service_account"), | ||
| ("api_v2", "0003_add_organization_rate_limit"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name="GlobalApiDeploymentKey", | ||
| fields=[ | ||
| ("created_at", models.DateTimeField(auto_now_add=True)), | ||
| ("modified_at", models.DateTimeField(auto_now=True)), | ||
| ( | ||
| "id", | ||
| models.UUIDField( | ||
| default=uuid.uuid4, | ||
| editable=False, | ||
| primary_key=True, | ||
| serialize=False, | ||
| ), | ||
| ), | ||
| ("name", models.CharField(max_length=128)), | ||
| ("description", models.CharField(max_length=512)), | ||
| ("key", models.UUIDField(default=uuid.uuid4, unique=True)), | ||
| ("is_active", models.BooleanField(default=True)), | ||
| ( | ||
| "allow_all_deployments", | ||
| models.BooleanField( | ||
| db_comment="If True, this key can authenticate any API deployment in the org", | ||
| default=False, | ||
| ), | ||
| ), | ||
| ( | ||
| "api_deployments", | ||
| models.ManyToManyField( | ||
| blank=True, | ||
| related_name="global_api_deployment_keys", | ||
| to="api_v2.apideployment", | ||
| ), | ||
| ), | ||
| ( | ||
| "created_by", | ||
| models.ForeignKey( | ||
| null=True, | ||
| on_delete=django.db.models.deletion.SET_NULL, | ||
| related_name="global_api_deployment_keys_created", | ||
| to=settings.AUTH_USER_MODEL, | ||
| ), | ||
| ), | ||
| ( | ||
| "modified_by", | ||
| models.ForeignKey( | ||
| null=True, | ||
| on_delete=django.db.models.deletion.SET_NULL, | ||
| related_name="+", | ||
| to=settings.AUTH_USER_MODEL, | ||
| ), | ||
| ), | ||
| ( | ||
| "organization", | ||
| models.ForeignKey( | ||
| blank=True, | ||
| db_comment="Foreign key reference to the Organization model.", | ||
| editable=False, | ||
| null=True, | ||
| on_delete=django.db.models.deletion.CASCADE, | ||
| to="account_v2.organization", | ||
| ), | ||
| ), | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| ], | ||
| options={ | ||
| "db_table": "global_api_deployment_key", | ||
| }, | ||
| ), | ||
| migrations.AddConstraint( | ||
| model_name="globalapideploymentkey", | ||
| constraint=models.UniqueConstraint( | ||
| fields=("name", "organization"), | ||
| name="unique_global_api_deployment_key_name_per_org", | ||
| ), | ||
| ), | ||
| ] | ||
Empty file.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.