prowler-api
This skill enforces architecture for the Prowler API by validating role-based access control and maintaining database tenant isolation.
Install
mkdir -p .claude/skills/prowler-api && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/7567" && unzip -o skill.zip -d .claude/skills/prowler-api && rm skill.zipInstalls to .claude/skills/prowler-api
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Prowler API patterns: RLS, RBAC, providers, Celery tasks. Trigger: When working in api/ on models/serializers/viewsets/filters/tasks involving tenant isolation (RLS), RBAC, or provider lifecycle.Key capabilities
- →Enforce tenant isolation via rls_transaction
- →Validate role access control with get_role
- →Execute database routing for 4-database architecture
- →Apply decorators for tenant and provider lifecycle
- →Manage through-models for M2M relationships
How it works
It wraps database access within an RLS transaction block and applies specific routing logic based on the 4-database schema.
Inputs & outputs
When to use prowler-api
- →Implement Row-Level Security
- →Validate RBAC role checks
- →Manage tenant-aware Celery tasks
About this skill
When to Use
Use this skill for Prowler-specific patterns:
- Row-Level Security (RLS) / tenant isolation
- RBAC permissions and role checks
- Provider lifecycle and validation
- Celery tasks with tenant context
- Multi-database architecture (primary, replica, admin)
- Server-Sent Events (SSE) endpoints
For generic DRF patterns (ViewSets, Serializers, Filters, JSON:API), use django-drf skill.
All paths below are relative to api/src/backend/ unless they start with api/.
Critical Rules
- ALWAYS use
rls_transaction(tenant_id)when querying tenant data outside a ViewSet (tasks, jobs, management commands) - ALWAYS take
tenant_idfrom the auth token (request.tenant_id), NEVER fromrequest.data - ALWAYS pass
tenant_idtoget_role(user, tenant_id); insideBaseRLSViewSetuse the cachedself.user_role - ALWAYS use explicit through models (inheriting
RowLevelSecurityProtectedModel) for M2M relationships - ALWAYS give Celery tasks a
name=; route withqueue=(omitted = defaultceleryqueue) - ALWAYS call tasks with keyword arguments (
tenant_id=...): the decorators readkwargs - NEVER access
Provider.objects(or any tenant model) in Celery without RLS context - NEVER combine plain
@set_tenantwith@handle_provider_deletion:@set_tenantpopstenant_id, which@handle_provider_deletionneeds. Use@set_tenant(keep_tenant=True) - NEVER use
MainRouter.admin_dbunless it is an auth or cross-tenant admin operation (it bypasses RLS)
rls_transaction(value, parameter=POSTGRES_TENANT_VAR, using=None, retry_on_replica=True)validates thatvalueis a UUID (UUID objects and strings both work) and raisesValidationErrorotherwise.
Architecture Overview
Databases (config/django/{devel,production,testing}.py)
| Alias | DB user | Purpose | RLS |
|---|---|---|---|
default | POSTGRES_USER (default = the prowler_user entry) | Standard API queries | Yes |
admin | POSTGRES_ADMIN_USER | Migrations, auth lookups, Django internal tables | No |
replica | POSTGRES_REPLICA_USER | Read-only queries | Yes |
admin_replica | POSTGRES_ADMIN_USER | Admin reads on replica | No |
neo4j | NEO4J_USER | Graph DB for Attack Paths (not routed by Django) | - |
from api.db_router import MainRouter, READ_REPLICA_ALIAS
User.objects.using(MainRouter.admin_db).get(id=user_id) # Auth lookups (bypasses RLS)
with rls_transaction(tenant_id, using=READ_REPLICA_ALIAS): # Read-heavy task code
Finding.objects.filter(scan_id=scan_id).count()
MainRouter.allow_migrate()only allowsadmin: runmanage.py migrate --database admin.READ_REPLICA_ALIASisNonewithout a replica;rls_transactionthen usesdefault.- Replica failures retry (
POSTGRES_REPLICA_MAX_ATTEMPTS, default 3) and then fall back to primary.
RLS Request Flow (api/base_views.py)
Request -> BaseRLSViewSet.dispatch() replica for SAFE_METHODS (if configured), transaction.atomic
-> BaseRLSViewSet.initial() tenant_id from request.auth (JWT or API key)
rls_transaction(tenant_id) -> set_config('api.tenant_id', ...)
-> queries are tenant-scoped; serializer context gets tenant_id
Other bases in the same file: BaseTenantViewset (tenant CRUD), BaseUserViewset (user endpoints), BaseViewSet (no RLS).
Implementation Checklist
| # | Pattern | Reference | Key Points |
|---|---|---|---|
| 1 | RLS Models | api/rls.py | Inherit RowLevelSecurityProtectedModel, add RowLevelSecurityConstraint |
| 2 | RLS Transactions | api/db_utils.py | rls_transaction(tenant_id) context manager |
| 3 | RBAC Permissions | api/rbac/permissions.py | Permissions enum, HasPermissions, get_role(), get_providers() |
| 4 | Provider Validation | api/models.py | validate_<provider>_uid() staticmethods on Provider |
| 5 | Celery Tasks | tasks/tasks.py, api/decorators.py, config/celery.py | @shared_task(base=RLSTask, name=...), @set_tenant, @handle_provider_deletion |
| 6 | Task business logic | tasks/jobs/*.py | Keep tasks.py thin; logic lives in jobs/ |
| 7 | RLS Serializers | api/v1/serializers.py | Inherit RLSSerializer to auto-inject tenant_id |
| 8 | Base ViewSets | api/base_views.py | BaseRLSViewSet for tenant-scoped resources |
| 9 | SSE endpoints | api/sse/ | Subclass BaseSSEViewSet, build channels with make_channel_name() |
| 10 | Changelog | api/changelog.d/ | Add a towncrier fragment, never edit CHANGELOG.md (see prowler-changelog) |
Full file paths: See references/file-locations.md
Decision Trees
Which Base Model?
Tenant-scoped data -> RowLevelSecurityProtectedModel
Global/shared data -> models.Model + BaseSecurityConstraint (rare)
Partitioned time-series -> PostgresPartitionedModel + RowLevelSecurityProtectedModel
Hide data of deleted providers -> objects = ActiveProviderManager(); all_objects = models.Manager()
Which Manager?
Normal queries -> Model.objects (ActiveProviderManager filters out deleted providers)
Include deleted records -> Model.all_objects
Celery task context -> Must be inside rls_transaction() first
Which Database?
Standard API queries -> default (automatic via ViewSet)
Read-only API requests -> replica (automatic for SAFE_METHODS in BaseRLSViewSet)
Heavy reads in tasks -> rls_transaction(tenant_id, using=READ_REPLICA_ALIAS)
Auth/admin operations -> MainRouter.admin_db
Cross-tenant lookups -> MainRouter.admin_db (use sparingly!)
Which Celery Decorators?
@set_tenant sets api.tenant_id on the default connection inside transaction.atomic.
| Task needs | Pattern (real example in tasks/tasks.py) |
|---|---|
RLS context, no tenant_id param | @set_tenant (check_provider_connection_task) |
RLS context + tenant_id param + deletion handling | @set_tenant(keep_tenant=True) then @handle_provider_deletion (generate_outputs_task) |
Job opens its own rls_transaction + deletion handling | @handle_provider_deletion only (perform_scan_task, perform_scan_summary_task) |
@shared_task(base=RLSTask, name="scan-report", queue="scan-reports")
@set_tenant(keep_tenant=True)
@handle_provider_deletion
def generate_outputs_task(scan_id: str, provider_id: str, tenant_id: str):
...
@handle_provider_deletion converts DB errors into ProviderDeletedException when the provider (looked up via provider_id or scan_id kwarg) was deleted mid-task.
RLS Model Pattern
from api.rls import RowLevelSecurityConstraint, RowLevelSecurityProtectedModel
class MyModel(RowLevelSecurityProtectedModel):
# tenant FK inherited from parent
id = models.UUIDField(primary_key=True, default=uuid4, editable=False)
name = models.CharField(max_length=255)
inserted_at = models.DateTimeField(auto_now_add=True, editable=False)
updated_at = models.DateTimeField(auto_now=True, editable=False)
class Meta(RowLevelSecurityProtectedModel.Meta):
db_table = "my_models"
constraints = [
RowLevelSecurityConstraint(
field="tenant_id",
name="rls_on_%(class)s",
statements=["SELECT", "INSERT", "UPDATE", "DELETE"],
),
]
class JSONAPIMeta:
resource_name = "my-models"
M2M Relationships (MUST use through models)
class Resource(RowLevelSecurityProtectedModel):
tags = models.ManyToManyField(ResourceTag, through="ResourceTagMapping")
class ResourceTagMapping(RowLevelSecurityProtectedModel):
resource = models.ForeignKey(Resource, on_delete=models.CASCADE)
tag = models.ForeignKey(ResourceTag, on_delete=models.CASCADE)
class Meta(RowLevelSecurityProtectedModel.Meta):
constraints = [
RowLevelSecurityConstraint(
field="tenant_id",
name="rls_on_%(class)s",
statements=["SELECT", "INSERT", "UPDATE", "DELETE"],
),
]
Async Task Response Pattern (202 Accepted)
Real code: ProviderViewSet.connection in api/v1/views.py.
@action(detail=True, methods=["post"], url_name="connection")
def connection(self, request, pk=None):
self.get_object() # visibility check before queuing
with transaction.atomic():
task = check_provider_connection_task.delay(
provider_id=pk, tenant_id=self.request.tenant_id
)
prowler_task = Task.objects.get(id=task.id) # created by RLSTask.apply_async
serializer = TaskSerializer(prowler_task)
return Response(
data=serializer.data,
status=status.HTTP_202_ACCEPTED,
headers={"Content-Location": reverse("task-detail", kwargs={"pk": prowler_task.id})},
)
Providers (16 in Provider.ProviderChoices)
| Provider | Value | UID Format |
|---|---|---|
| AWS | aws | 12 digits |
| Azure | azure | UUID v4 |
| GCP | gcp | 6-30 chars, lowercase, letter start (legacy domain:project allowed) |
| Kubernetes | kubernetes | 2-251 chars (context name or cluster ARN) |
| M365 | m365 | Valid domain |
| GitHub | github | 1-39 chars, alphanumeric + hyphens |
| MongoDB Atlas | mongodbatlas | 24-char hex |
| IaC | iac | Repository URL |
| Oracle Cloud | oraclecloud | Tenancy OCID (ocid1.…) |
| Alibaba Cloud | alibabacloud | 16 digits |
| Cloudflare | cloudflare | 32-char lowercase hex |
| OpenStack | openstack | Project ID or name |
| Image | image | Container image reference |
| Google Workspace | googleworkspace | C + alphanumerics |
| Vercel | vercel | team_ + 16-32 alphanumerics |
| Okta | okta | Okta-manag |
Content truncated.
When not to use it
- →Generic Django Rest Framework viewsets
- →Standard ORM queries not involving tenant context
Prerequisites
Limitations
- →Manual enforcement of rls_transaction required outside views
- →Strict decorator order requirement
How it compares
It enforces strict database-level security and multi-tenancy rules rather than relying on standard application-layer checks.
Compared to similar skills
prowler-api side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| prowler-api (this skill) | 1 | 5mo | Review | Advanced |
| security-header-generator | 5 | 1y | Caution | Intermediate |
| backend-security-coder | 24 | 7mo | No flags | Intermediate |
| detecting-sql-injection-vulnerabilities | 3 | 4mo | Review | Advanced |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by prowler-cloud
View all by prowler-cloud →You might also like
security-header-generator
Dexploarer
Generates security HTTP headers (CSP, HSTS, CORS, etc.) for web applications to prevent common attacks. Use when user asks to "add security headers", "setup CSP", "configure CORS", "secure headers", or "HSTS setup".
backend-security-coder
sickn33
Expert in secure backend coding practices specializing in input validation, authentication, and API security. Use PROACTIVELY for backend security implementations or security code reviews.
detecting-sql-injection-vulnerabilities
jeremylongshore
Detect and analyze SQL injection vulnerabilities in application code and database queries. Use when you need to scan code for SQL injection risks, review query construction, validate input sanitization, or implement secure query patterns. Trigger with phrases like "detect SQL injection", "scan for SQLi vulnerabilities", "review database queries", or "check SQL security".
dependency-auditor
moshesham
Dependency and license review for Python projects. Use when: auditing requirements.txt, checking for vulnerabilities, reviewing licenses, updating dependencies, managing version constraints.
django-pro
sickn33
Master Django 5.x with async views, DRF, Celery, and Django Channels. Build scalable web applications with proper architecture, testing, and deployment. Use PROACTIVELY for Django development, ORM optimization, or complex Django patterns.
senior-backend
davila7
Comprehensive backend development skill for building scalable backend systems using NodeJS, Express, Go, Python, Postgres, GraphQL, REST APIs. Includes API scaffolding, database optimization, security implementation, and performance tuning. Use when designing APIs, optimizing database queries, implementing business logic, handling authentication/authorization, or reviewing backend code.