Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "pglite/pgtap"]
path = pglite/pgtap
url = https://github.com/theory/pgtap.git
[submodule "pglite/pg_uuidv7"]
path = pglite/pg_uuidv7
url = https://github.com/fboulnois/pg_uuidv7/
4 changes: 3 additions & 1 deletion pglite/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ include $(top_builddir)/src/Makefile.global
SUBDIRS = \
pg_ivm \
vector \
pgtap
pgtap \
pg_uuidv7 \
pg_session_jwt

prefix ?= /install/pglite
EXTENSIONS_BUILD_ROOT := /tmp/extensions/build
Expand Down
28 changes: 28 additions & 0 deletions pglite/pg_session_jwt/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Minimal PGXS-style shim for PGlite builds.
#
# Upstream pg_session_jwt is pgrx-based and doesn't ship a Makefile compatible
# with PGlite's backend build (which expects to `make install` each extension
# directory). This shim installs a fallback-mode-only SQL implementation that
# uses PostgREST-compatible `request.jwt.claims`.

EXTENSION = pg_session_jwt
EXTVERSION = 0.4.0

prefix ?= /install/pglite

EXTENSION_DIR = $(DESTDIR)$(prefix)/share/postgresql/extension

.PHONY: all install

all:
@echo "$(EXTENSION): nothing to build (SQL-only shim)"

install:
mkdir -p $(EXTENSION_DIR)
printf "%s\n" \
"comment = 'pg_session_jwt (PGlite shim): JWT session helpers using request.jwt.claims'" \
"default_version = '$(EXTVERSION)'" \
"relocatable = false" \
"trusted = true" \
> $(EXTENSION_DIR)/$(EXTENSION).control
cp -f pglite/$(EXTENSION)--$(EXTVERSION).sql $(EXTENSION_DIR)/
76 changes: 76 additions & 0 deletions pglite/pg_session_jwt/pglite/pg_session_jwt--0.4.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
CREATE SCHEMA IF NOT EXISTS auth;

CREATE OR REPLACE FUNCTION auth."session"() RETURNS jsonb
STABLE PARALLEL SAFE
LANGUAGE plpgsql
AS $$
DECLARE
claims_text text;
BEGIN
claims_text := current_setting('request.jwt.claims', true);

IF claims_text IS NULL OR claims_text = '' THEN
RETURN NULL;
END IF;

BEGIN
RETURN claims_text::jsonb;
EXCEPTION
WHEN others THEN
RETURN NULL;
END;
END;
$$;

CREATE OR REPLACE FUNCTION auth."jwt"() RETURNS jsonb
STABLE PARALLEL SAFE
LANGUAGE sql
AS $$
SELECT auth."session"();
$$;

CREATE OR REPLACE FUNCTION auth."user_id"() RETURNS text
STABLE PARALLEL SAFE
LANGUAGE sql
AS $$
SELECT auth."session"() ->> 'sub';
$$;

CREATE OR REPLACE FUNCTION auth."uid"() RETURNS uuid
STABLE PARALLEL SAFE
LANGUAGE plpgsql
AS $$
DECLARE
sub text;
BEGIN
sub := auth."user_id"();
IF sub IS NULL OR sub = '' THEN
RETURN NULL;
END IF;

BEGIN
RETURN sub::uuid;
EXCEPTION
WHEN others THEN
RETURN NULL;
END;
END;
$$;

CREATE OR REPLACE FUNCTION auth."init"() RETURNS void
LANGUAGE plpgsql
AS $$
BEGIN
RAISE EXCEPTION
'pg_session_jwt JWK validation is not supported in this PGlite shim; set request.jwt.claims instead';
END;
$$;

CREATE OR REPLACE FUNCTION auth."jwt_session_init"(jwt text) RETURNS void
LANGUAGE plpgsql
AS $$
BEGIN
RAISE EXCEPTION
'pg_session_jwt JWK validation is not supported in this PGlite shim; set request.jwt.claims instead';
END;
$$;
1 change: 1 addition & 0 deletions pglite/pg_uuidv7
Submodule pg_uuidv7 added at c707aa
4 changes: 2 additions & 2 deletions src/backend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ pglite: pglite-exported-functions
$(CC) $(CFLAGS) $(LDFLAGS) -DPG_PREFIX=/tmp/pglite -I$(top_builddir)/src/include -I$(top_builddir)/src/ -I$(top_builddir)/src/interfaces/libpq -o pglite.o -c $(top_builddir)/$(PGLITE_MAIN) -Wno-incompatible-pointer-types-discards-qualifiers
$(CC) \
$(PGLITE_CFLAGS) \
-fPIC -m32 -D_FILE_OFFSET_BITS=64 -mno-bulk-memory -mnontrapping-fptoint -mno-reference-types -mno-sign-ext -mno-extended-const -mno-atomics -mno-tail-call -mno-multivalue -mno-relaxed-simd -mno-simd128 -mno-multimemory -mno-exception-handling -Wno-unused-command-line-argument -Wno-unreachable-code-fallthrough -Wno-unused-function -Wno-invalid-noreturn -Wno-declaration-after-statement -Wno-invalid-noreturn \
-DPYDK=1 -DPG_PREFIX=/tmp/pglite -o pglite.html \
-fPIC -m32 -mno-bulk-memory -mnontrapping-fptoint -mno-reference-types -mno-sign-ext -mno-extended-const -mno-atomics -mno-tail-call -mno-multivalue -mno-relaxed-simd -mno-simd128 -mno-multimemory -mno-exception-handling -Wno-unused-command-line-argument -Wno-unreachable-code-fallthrough -Wno-unused-function -Wno-invalid-noreturn -Wno-declaration-after-statement -Wno-invalid-noreturn \
-DPG_PREFIX=/tmp/pglite -o pglite.html \
$(PGPRELOAD) \
-ferror-limit=1 \
-sEXPORTED_FUNCTIONS=@$(emscripten_imports_dir)/exported_functions.txt \
Expand Down
3 changes: 0 additions & 3 deletions src/include/port/pg_pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@

#ifndef PG_PTHREAD_H
#define PG_PTHREAD_H
#if defined(__wasi__)
#define PYDK
#endif /* __wasi__ */
#include <pthread.h>

#ifndef HAVE_PTHREAD_BARRIER_WAIT
Expand Down