-
Notifications
You must be signed in to change notification settings - Fork 39
feat: add API key namespace restriction, MODULE_FULL type and g… #106
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
Open
markdjones82
wants to merge
10
commits into
MatthewJohn:main
Choose a base branch
from
markdjones82:feat/api-key-git-provider-ui
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
fbeaf54
feat(auth): add API key namespace restriction, MODULE_FULL type and g…
markdjones82 259af59
Revert CHANGELOG.md to origin/main
markdjones82 7cb10c8
feat(db): add namespace column to api_key
markdjones82 d3d5faa
refactor(auth): move API key type to auth subclasses, check DB
markdjones82 e252b3c
Remove provider sources UI. This is not part of this effort
markdjones82 8e07a2e
Rename provider source to git provider sources for clarity.
markdjones82 0e05f4a
Change module_full naming to upload_and_publish
markdjones82 a189aee
Fix/Update Traefik docker provider routing in local dev
markdjones82 0e30e5c
Fix edit/delete buttons for git providers.
markdjones82 5379aba
Add tests
markdjones82 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
38 changes: 38 additions & 0 deletions
38
terrareg/alembic/versions/5aa1e8d0d9fb_add_api_key_table.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,38 @@ | ||
| """add_api_key_table | ||
|
|
||
| Revision ID: 5aa1e8d0d9fb | ||
| Revises: c72f7c6ef6a7 | ||
| Create Date: 2026-05-12 00:00:00.000000 | ||
|
|
||
| """ | ||
| from alembic import op | ||
| import sqlalchemy as sa | ||
|
|
||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = '5aa1e8d0d9fb' | ||
| down_revision = 'c72f7c6ef6a7' | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade(): | ||
| op.create_table( | ||
| 'api_key', | ||
| sa.Column('id', sa.Integer(), nullable=False, autoincrement=True), | ||
| sa.Column('name', sa.String(length=128), nullable=False), | ||
| sa.Column('key_type', sa.String(length=32), nullable=False), | ||
| sa.Column('key_prefix', sa.String(length=16), nullable=False), | ||
| sa.Column('key_hash', sa.String(length=128), nullable=False), | ||
| sa.Column('key_salt', sa.String(length=64), nullable=False), | ||
| sa.Column('created_at', sa.DateTime(), nullable=False), | ||
| sa.Column('created_by', sa.String(length=128), nullable=True), | ||
| sa.Column('last_used_at', sa.DateTime(), nullable=True), | ||
| sa.Column('expires_at', sa.DateTime(), nullable=True), | ||
| sa.Column('is_active', sa.Boolean(), nullable=False, server_default=sa.true()), | ||
| sa.PrimaryKeyConstraint('id') | ||
| ) | ||
|
|
||
|
|
||
| def downgrade(): | ||
| op.drop_table('api_key') |
24 changes: 24 additions & 0 deletions
24
terrareg/alembic/versions/a1b2c3d4e5f6_add_namespace_to_api_key.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,24 @@ | ||
| """add_namespace_to_api_key | ||
|
|
||
| Revision ID: a1b2c3d4e5f6 | ||
| Revises: 5aa1e8d0d9fb | ||
| Create Date: 2026-05-12 00:00:00.000000 | ||
|
|
||
| """ | ||
| from alembic import op | ||
| import sqlalchemy as sa | ||
|
|
||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = 'a1b2c3d4e5f6' | ||
| down_revision = '5aa1e8d0d9fb' | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade(): | ||
| op.add_column('api_key', sa.Column('namespace', sa.String(length=128), nullable=True)) | ||
|
markdjones82 marked this conversation as resolved.
Outdated
|
||
|
|
||
|
|
||
| def downgrade(): | ||
| op.drop_column('api_key', 'namespace') | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
|
|
||
| import terrareg.models | ||
| from .base_api_key_auth_method import BaseApiKeyAuthMethod | ||
|
|
||
|
|
||
| class ModuleFullApiKeyAuthMethod(BaseApiKeyAuthMethod): | ||
|
markdjones82 marked this conversation as resolved.
Outdated
|
||
| """Auth method for module-full API key (upload + publish)""" | ||
|
|
||
| @classmethod | ||
| def check_auth_state(cls): | ||
| """Check if module-full API key is provided""" | ||
| return cls._check_api_key([], key_type=terrareg.models.ApiKeyType.MODULE_FULL) | ||
|
|
||
| @classmethod | ||
| def is_enabled(cls): | ||
| return terrareg.models.ApiKey.has_active_keys(terrareg.models.ApiKeyType.MODULE_FULL) | ||
|
|
||
| def can_upload_module_version(self, namespace): | ||
| """Whether user can upload/index module version within a namespace.""" | ||
| key = self.matched_api_key | ||
| if key is not None and key.namespace is not None: | ||
| return key.namespace == namespace | ||
| return True | ||
|
|
||
| def can_publish_module_version(self, namespace): | ||
| """Whether user can publish module version within a namespace.""" | ||
| key = self.matched_api_key | ||
| if key is not None and key.namespace is not None: | ||
| return key.namespace == namespace | ||
| return True | ||
|
|
||
| def check_namespace_access(self, permission_type, namespace): | ||
| """Check access level to a given namespace.""" | ||
| return False | ||
|
|
||
| def get_username(self): | ||
| """Get username of current user""" | ||
| return 'Module Full API Key' | ||
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
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.