supabase-database-functions

Secure Supabase PostgreSQL functions with search_path, security modes, and Vault secrets.

Updated Aug 29, 2023
One-click install
npx skills add https://github.com/SaschaLeh/dotfiles --skill supabase-database-functions
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: supabase-database-functions
Source: https://github.com/SaschaLeh/dotfiles/tree/main/dot_claude/skills/supabase-database-functions
Command: npx skills add https://github.com/SaschaLeh/dotfiles --skill supabase-database-functions

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Supabase users often struggle to implement secure, maintainable PostgreSQL functions that respect RLS, enforce proper permissions, and securely handle secrets. This Skill provides a structured approach to creating and managing database functions with explicit search_path, SECURITY INVOKER/DEFINER modes, Vault-based secret management, triggers, and RLS-aware patterns.

Core Features & Use Cases

  • Security modes: Choose between SECURITY INVOKER (default) and SECURITY DEFINER with explicit permission checks and safe fallback.
  • Vault-based secrets: Store and retrieve API keys or credentials without hardcoding them in functions.
  • Search_path discipline: Always set search_path = '' and reference objects with fully qualified names.
  • Triggers and RLS integration: Implement BEFORE/AFTER triggers and pattern-based RLS workflows for secure data access.

Quick Start

Create a sample SECURITY INVOKER function with search_path set to '' and retrieve a secret from Vault inside the function.

Frequently Asked Questions about supabase-database-functions

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I securely store API keys in Supabase PostgreSQL functions?

Store API keys in Supabase database functions by using Vault-based secret management to retrieve credentials without hardcoding. This ensures secure function definitions and consistent secret handling.

What is the difference between SECURITY INVOKER and SECURITY DEFINER in Supabase?

SECURITY INVOKER runs PostgreSQL functions with the caller's permissions, while SECURITY DEFINER executes with the creator's privileges. Use INVOKER by default and apply explicit permission checks for DEFINER with a safe fallback.

Why do I need to set search_path in PostgreSQL database functions?

You must set search_path = '' in PostgreSQL database functions to prevent schema spoofing attacks. Referencing objects with fully qualified names ensures consistent schema qualification and secure execution.

Can I use Supabase Vault with RLS-aware database triggers?

Yes, you can implement Supabase Vault with RLS-aware database triggers by applying BEFORE or AFTER triggers that securely retrieve secrets. This pattern enforces strict data access workflows within PostgreSQL.

How do I apply explicit grants for Supabase SECURITY DEFINER functions?

Apply explicit grants for Supabase SECURITY DEFINER functions by configuring strict permission checks and safe fallbacks. This ensures only authorized roles execute privileged operations without bypassing Row Level Security.

When should I not use SECURITY DEFINER for Supabase database functions?

Avoid using SECURITY DEFINER for Supabase database functions when standard RLS policies suffice for data access needs. Default to SECURITY INVOKER to maintain row-level security boundaries unless explicit privilege escalation is required.