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

[RHCLOUD-35997] Add admin endpoint to delete/list workspace/tenantmapping #1287

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

astrozzc
Copy link
Contributor

@astrozzc astrozzc commented Nov 5, 2024

Link(s) to Jira

Description of Intent of Change(s)

The what, why and how.

Local Testing

How can the feature be exercised?
How can the bug be exploited and fix confirmed?
Is any special local setup required?

Checklist

  • if API spec changes are required, is the spec updated?
  • are there any pre/post merge actions required? if so, document here.
  • are theses changes covered by unit tests?
  • if warranted, are documentation changes accounted for?
  • does this require migration changes?
    • if yes, are they backwards compatible?
  • is there known, direct impact to dependent teams/components?
    • if yes, how will this be handled?

Secure Coding Practices Checklist Link

Secure Coding Practices Checklist

  • Input Validation
  • Output Encoding
  • Authentication and Password Management
  • Session Management
  • Access Control
  • Cryptographic Practices
  • Error Handling and Logging
  • Data Protection
  • Communication Security
  • System Configuration
  • Database Security
  • File Management
  • Memory Management
  • General Coding Practices

@@ -55,6 +56,10 @@

logger = logging.getLogger(__name__)
TENANTS = TenantCache()
RESOURCE_MODEL_MAPPING = {
"workspace": Workspace,
"mapping": TenantMapping,
Copy link
Contributor

Choose a reason for hiding this comment

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

Will we want to manage BindingMapping as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

if resource == "workspace":
# Have to delete the ones without references (default workspaces)
logger.info("Deleting default workspaces.")
resource_objs.exclude(parent=None).delete()
Copy link
Contributor

Choose a reason for hiding this comment

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

This would be all default + standard, correct? Not just default? Some of these would still fail if they have FK refs?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess in our case for now, we're just using this for default and root though, right? So we should be able to get away with just deleting defaults first and then root, I guess is what you're saying? Platex may start testing with full hierarchy though, which would mean we'd need to do some recursive deletion.

rbac/internal/views.py Outdated Show resolved Hide resolved
if org_id:
tenant = get_object_or_404(Tenant, org_id=org_id)
if resource == "binding":
resource_objs = resource_objs.filter(role__tenant=tenant)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will miss bindings for system roles because those are in the public tenant. Is this intentional?

I think we probably want removing the binding to be based off of the tenant of the resource, however we don't have a foreign key here, and we might not always know the owning Tenant of the bound resource. For now, we actually do, though, since the resource is always a Workspace. Maybe we could just start there? That is, find all workspaces for a tenant, and then delete all the binding mappings for those workspaces (using resource type namespace, resource type name, and resource id fields to filter).

In the long run, we probably won't be able to support removing bindings by org, unless we make it clear it's limited to only certain narrow filter options (like custom roles, or workspace bindings).

It also may be safer for us to just blow away everything, but it probably doesn't hurt to have something org specific in case it is needed. It just has to be used very carefully of course.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had the wrong impression the bindings for system roles have to be kept. I am ignoring the org_id for bindingmapping for now

rbac/api/utils.py Outdated Show resolved Hide resolved
@astrozzc
Copy link
Contributor Author

astrozzc commented Nov 8, 2024

/retest

@astrozzc astrozzc force-pushed the list/clean branch 4 times, most recently from 7c5e747 to a41d699 Compare November 8, 2024 21:45
Comment on lines 35 to 39
if resource != "binding" and org_id:
tenant = get_object_or_404(Tenant, org_id=org_id)
queryset = queryset.filter(tenant=tenant)
Copy link
Collaborator

@alechenninger alechenninger Nov 9, 2024

Choose a reason for hiding this comment

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

Maybe abort or raise an error if its the binding and org_id is passed? Just so we have to be intentional if we want to delete everything, and someone doesn't think they're only deleting bindings for one org and end up accidentally deleting everything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

@astrozzc astrozzc force-pushed the list/clean branch 2 times, most recently from deada1c to ac96c19 Compare November 11, 2024 20:53
@lpichler
Copy link
Contributor

@astrozzc Does this need update to open api spec ?


def migration_resource_deletion(resource, org_id):
"""Delete migration related resources."""
resource_objs = get_resources(resource, org_id)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does resource needs to be checked if exists in RESOURCE_MODEL_MAPPING ? Maybe this check should in get_resources function ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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


DELETE /_private/api/utils/migration_resources/?resource=xxx&org_id=xxx
GET /_private/api/utils/migration_resources/?resource=xxx&org_id=xxx&limit=1000
optinos of resource: workspace, mapping(tenantmapping), binding(bindingmapping)
Copy link
Contributor

Choose a reason for hiding this comment

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

typo optinos

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, forgot to update this, good catch!

@astrozzc
Copy link
Contributor Author

@astrozzc Does this need update to open api spec ?

Oh, good point! Let me update that

@astrozzc
Copy link
Contributor Author

/retest

1 similar comment
@astrozzc
Copy link
Contributor Author

/retest

Copy link
Collaborator

@alechenninger alechenninger left a comment

Choose a reason for hiding this comment

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

LGTM

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.

4 participants