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: Implement CRUD API for managing Harbor per-project Quota #3090

Open
wants to merge 41 commits into
base: topic/11-06-feat_implement_per-project_images_api_based_on_rbac
Choose a base branch
from

Conversation

jopemachine
Copy link
Member

@jopemachine jopemachine commented Nov 13, 2024

Resolves #1911.

Implement CRUD for controlling Harbor per-project Quota.

Important

Currently, the Project Quota API implemented in this PR is only available for the HarborV2 registry.

Details

  • In practice, the HarborV2 Quota API has no delete or create methods. But if you query a quota that does not exist, it returns -1. Using the update API at this point creates the quota. Updating it back to -1 resets it to an unlimited quota. Using this approach, I implemented all CRUD operations.

  • Quota mutations can only be executed by admin, superadmin, while quota queries are accessible to regular users if they have READ permissions.

Implementation Check list

  • REST API
  • Graphql API
  • Client SDK

Client code example

import asyncio
from ai.backend.client.session import AsyncSession

async def main():
    async with AsyncSession() as session:
        await session.Group.update_container_registry_quota("2de2b969-1d04-48a6-af16-0bc8adb3c831", 1200)

if __name__ == "__main__":
    asyncio.run(main())

GQL example

mutation {
  update_container_registry_quota(scope_id: "project:2de2b969-1d04-48a6-af16-0bc8adb3c831", quota: 100) {
    ok
    msg
  }
}

Reference


Checklist: (if applicable)

  • Milestone metadata specifying the target backport version
  • Mention to the original issue
  • API server-client counterparts (e.g., manager API -> client SDK)

📚 Documentation preview 📚: https://sorna--3090.org.readthedocs.build/en/3090/


📚 Documentation preview 📚: https://sorna-ko--3090.org.readthedocs.build/ko/3090/

Copy link
Member Author

jopemachine commented Nov 13, 2024

@jopemachine jopemachine added the type:feature Add new features label Nov 13, 2024
@jopemachine jopemachine added this to the 24.12 milestone Nov 13, 2024
@jopemachine jopemachine force-pushed the topic/11-06-feat_implement_per-project_images_api_based_on_rbac branch from 7b81657 to f0cc98f Compare November 13, 2024 06:34
@jopemachine jopemachine force-pushed the topic/11-13-feat_implement_management_api_for_controlling_harbor_per-project_quota branch from 47cacdd to a6068e1 Compare November 13, 2024 06:35
@jopemachine jopemachine force-pushed the topic/11-06-feat_implement_per-project_images_api_based_on_rbac branch from f0cc98f to f01260a Compare November 13, 2024 08:36
@jopemachine jopemachine force-pushed the topic/11-13-feat_implement_management_api_for_controlling_harbor_per-project_quota branch from f5a8af1 to 917dffd Compare November 13, 2024 08:36
@jopemachine
Copy link
Member Author

Remaining tasks: Adding REST API and SDK.

@jopemachine jopemachine force-pushed the topic/11-06-feat_implement_per-project_images_api_based_on_rbac branch from f01260a to 6fcfeae Compare November 14, 2024 06:01
@jopemachine jopemachine force-pushed the topic/11-13-feat_implement_management_api_for_controlling_harbor_per-project_quota branch from 1be79c6 to 6b91f24 Compare November 14, 2024 06:01
@jopemachine jopemachine force-pushed the topic/11-06-feat_implement_per-project_images_api_based_on_rbac branch from 6fcfeae to 548f6f8 Compare November 14, 2024 06:05
@jopemachine jopemachine force-pushed the topic/11-13-feat_implement_management_api_for_controlling_harbor_per-project_quota branch from 6b91f24 to 81dbd9e Compare November 14, 2024 06:05
@jopemachine jopemachine force-pushed the topic/11-06-feat_implement_per-project_images_api_based_on_rbac branch from 548f6f8 to bda8f44 Compare November 14, 2024 06:37
@jopemachine jopemachine force-pushed the topic/11-13-feat_implement_management_api_for_controlling_harbor_per-project_quota branch from 81dbd9e to 33c1b79 Compare November 14, 2024 06:38
@jopemachine jopemachine force-pushed the topic/11-06-feat_implement_per-project_images_api_based_on_rbac branch from bda8f44 to 30b5684 Compare November 18, 2024 01:16
@jopemachine jopemachine force-pushed the topic/11-13-feat_implement_management_api_for_controlling_harbor_per-project_quota branch from 33c1b79 to f036297 Compare November 18, 2024 01:16
@jopemachine jopemachine force-pushed the topic/11-06-feat_implement_per-project_images_api_based_on_rbac branch from 30b5684 to 56003a4 Compare November 18, 2024 01:28
@jopemachine jopemachine force-pushed the topic/11-13-feat_implement_management_api_for_controlling_harbor_per-project_quota branch from f036297 to 0d5ccf2 Compare November 18, 2024 01:28
@jopemachine jopemachine force-pushed the topic/11-06-feat_implement_per-project_images_api_based_on_rbac branch from 56003a4 to 643e723 Compare November 18, 2024 01:33
@jopemachine jopemachine force-pushed the topic/11-13-feat_implement_management_api_for_controlling_harbor_per-project_quota branch from 0d5ccf2 to 408bf1f Compare November 18, 2024 01:33
"""
)

scope_id = f"project:{group_id}"
Copy link
Member Author

@jopemachine jopemachine Nov 18, 2024

Choose a reason for hiding this comment

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

@fregataa If possible, instead of hardcoding the scope_id like this, I’d prefer to create a ProjectScope object and serialize it. However, since the ProjectScope type is currently located under the models directory, this violates the pants visibility rule.

What do you think about moving the types related to ScopeField under the common directory?

)

variables = {"id": base64(f"group_node:{group_id}")}
data = await api_session.get().Admin._query(query, variables)
Copy link
Member Author

@jopemachine jopemachine Nov 18, 2024

Choose a reason for hiding this comment

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

@fregataa Registry quota READ operation can be executed even if the user is not an admin.
However, it seems that GQL queries in the current SDK can only be executed through Admin.
What do you think about adding this query, _query functions to User as well?

@jopemachine jopemachine force-pushed the topic/11-13-feat_implement_management_api_for_controlling_harbor_per-project_quota branch from 6b415d5 to cae3fee Compare November 27, 2024 06:20
Comment on lines +115 to +118
cors.add(app.router.add_route("POST", "/registry-quota", create_registry_quota))
cors.add(app.router.add_route("GET", "/registry-quota", read_registry_quota))
cors.add(app.router.add_route("PATCH", "/registry-quota", update_registry_quota))
cors.add(app.router.add_route("DELETE", "/registry-quota", delete_registry_quota))

Choose a reason for hiding this comment

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

can we use PATCH, DELETE method? @fregataa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:docs Documentations comp:manager Related to Manager component size:L 100~500 LoC type:feature Add new features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create management API to take control of harbor projects dedicated to each user/project
2 participants