Skip to content

Commit 5791fe9

Browse files
committed
Don't fail reading policy_urls as non-superuser
Have to access the value directly for internal purposes, as GetConfigOption will honor the GUC_SUPERUSER_ONLY on it. Add tests as non-superuser to the Travis and AppVeyor configs. Not having any was an oversight. In passing, try adding PG 13 and Java 15 to the Travis and AppVeyor builds. I have not otherwise checked whether those are available yet in those services. This should be a way to find out.
1 parent c445975 commit 5791fe9

File tree

3 files changed

+95
-7
lines changed

3 files changed

+95
-7
lines changed

.travis.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ arch:
66
- ppc64le
77
dist: bionic
88
env:
9+
- POSTGRESQL_VERSION: 13
10+
JAVA_VERSION: 15
11+
JVM_IMPL: hotspot
12+
MVN_VERSION: 3.5.2
913
- POSTGRESQL_VERSION: 12
1014
JAVA_VERSION: 14
1115
JVM_IMPL: hotspot
@@ -153,6 +157,7 @@ script: |
153157
154158
import static java.nio.file.Paths.get
155159
import java.sql.Connection
160+
import java.sql.ResultSet
156161
import org.postgresql.pljava.packaging.Node
157162
import static org.postgresql.pljava.packaging.Node.q
158163
import static org.postgresql.pljava.packaging.Node.stateMachine
@@ -267,6 +272,41 @@ script: |
267272
(o,p,q) -> null == o
268273
);
269274
}
275+
276+
/*
277+
* Get another new connection and make sure the extension can be loaded
278+
* in a non-superuser session.
279+
*/
280+
try ( Connection c = n1.connect() )
281+
{
282+
succeeding &= stateMachine(
283+
"become non-superuser",
284+
null,
285+
286+
q(c,
287+
"CREATE ROLE alice;" +
288+
"GRANT USAGE ON SCHEMA sqlj TO alice;" +
289+
"SET SESSION AUTHORIZATION alice")
290+
.flatMap(Node::semiFlattenDiagnostics)
291+
.peek(Node::peek),
292+
293+
(o,p,q) -> isDiagnostic(o, Set.of("error")) ? 1 : -2,
294+
(o,p,q) -> null == o
295+
);
296+
297+
succeeding &= stateMachine(
298+
"load as non-superuser",
299+
null,
300+
301+
q(c, "SELECT null::pg_catalog.void FROM sqlj.get_classpath('public')")
302+
.flatMap(Node::semiFlattenDiagnostics)
303+
.peek(Node::peek),
304+
305+
(o,p,q) -> isDiagnostic(o, Set.of("error")) ? 1 : -2,
306+
(o,p,q) -> isVoidResultSet(o, 1, 1) ? 3 : false,
307+
(o,p,q) -> null == o
308+
);
309+
}
270310
} catch ( Throwable t )
271311
{
272312
succeeding = false;

appveyor.yml

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,23 @@ environment:
1010
JDK: 10
1111
PG: 12
1212
- SYS: MINGW
13-
JDK: 14
14-
PG: 12
15-
- SYS: MINGW
16-
JDK: 13
13+
JDK: 11
1714
PG: 12
1815
- SYS: MINGW
1916
JDK: 12
2017
PG: 12
2118
- SYS: MINGW
22-
JDK: 11
19+
JDK: 13
2320
PG: 12
21+
- SYS: MINGW
22+
JDK: 14
23+
PG: 13
24+
- SYS: MINGW
25+
JDK: 15
26+
PG: 13
27+
- SYS: MSVC
28+
JDK: 15
29+
PG: 13
2430
- SYS: MSVC
2531
JDK: 14
2632
PG: 12
@@ -84,6 +90,7 @@ test_script:
8490
8591
import static java.nio.file.Paths.get
8692
import java.sql.Connection
93+
import java.sql.ResultSet
8794
import org.postgresql.pljava.packaging.Node
8895
import static org.postgresql.pljava.packaging.Node.q
8996
import static org.postgresql.pljava.packaging.Node.stateMachine
@@ -205,6 +212,42 @@ test_script:
205212
(o,p,q) -> null == o
206213
);
207214
}
215+
216+
/*
217+
* Get another new connection and make sure the extension can be loaded
218+
* in a non-superuser session.
219+
*/
220+
try ( Connection c = n1.connect() )
221+
{
222+
succeeding &= stateMachine(
223+
"become non-superuser",
224+
null,
225+
226+
q(c,
227+
"CREATE ROLE alice;" +
228+
"GRANT USAGE ON SCHEMA sqlj TO alice;" +
229+
"SET SESSION AUTHORIZATION alice")
230+
.flatMap(Node::semiFlattenDiagnostics)
231+
.peek(Node::peek),
232+
233+
(o,p,q) -> isDiagnostic(o, Set.of("error")) ? 1 : -2,
234+
(o,p,q) -> null == o
235+
);
236+
237+
succeeding &= stateMachine(
238+
"load as non-superuser",
239+
null,
240+
241+
q(c,
242+
"SELECT null::pg_catalog.void FROM sqlj.get_classpath('public')")
243+
.flatMap(Node::semiFlattenDiagnostics)
244+
.peek(Node::peek),
245+
246+
(o,p,q) -> isDiagnostic(o, Set.of("error")) ? 1 : -2,
247+
(o,p,q) -> isVoidResultSet(o, 1, 1) ? 3 : false,
248+
(o,p,q) -> null == o
249+
);
250+
}
208251
} catch ( Throwable t )
209252
{
210253
succeeding = false;

pljava-so/src/main/c/Backend.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ static bool seenVisualVMName;
208208
static bool seenModuleMain;
209209
static char const visualVMprefix[] = "-Dvisualvm.display.name=";
210210
static char const moduleMainPrefix[] = "-Djdk.module.main=";
211+
static char const policyUrlsGUC[] = "pljava.policy_urls";
211212

212213
/*
213214
* In a background worker, _PG_init may be called very early, before much of
@@ -1648,7 +1649,7 @@ static void registerGUCOptions(void)
16481649
NULL); /* show hook */
16491650

16501651
STRING_GUC(
1651-
"pljava.policy_urls",
1652+
policyUrlsGUC,
16521653
"URLs to Java security policy file(s) for PL/Java's use",
16531654
"Quote each URL and separate with commas. Any URL may begin (inside "
16541655
"the quotes) with n= where n is the index of the Java "
@@ -1923,7 +1924,11 @@ JNICALL Java_org_postgresql_pljava_internal_Backend__1getConfigOption(JNIEnv* en
19231924
{
19241925
PG_TRY();
19251926
{
1926-
const char *value = PG_GETCONFIGOPTION(key);
1927+
const char *value;
1928+
if ( 0 == strcmp(policyUrlsGUC, key) )
1929+
value = policy_urls;
1930+
else
1931+
value = PG_GETCONFIGOPTION(key);
19271932
pfree(key);
19281933
if(value != 0)
19291934
result = String_createJavaStringFromNTS(value);

0 commit comments

Comments
 (0)