Skip to content

Commit 3882c03

Browse files
authored
OPA: Fail fast when OPA bearer token file is unreadable (#3062)
1 parent 9680d2a commit 3882c03

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

extensions/auth/opa/impl/src/main/java/org/apache/polaris/extension/auth/opa/token/FileBearerTokenProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ public FileBearerTokenProvider(
100100
this.clock = clock;
101101
this.asyncExec = asyncExec;
102102

103+
checkState(Files.isReadable(tokenFilePath), "OPA token file does not exist or is not readable");
104+
103105
this.nextRefresh = Instant.MIN;
104106
this.lastRefresh = Instant.MIN;
105107
// start refreshing the token (immediately)
106108
scheduleRefreshAttempt(Duration.ZERO);
107109

108-
checkState(Files.isReadable(tokenFilePath), "OPA token file does not exist or is not readable");
109-
110110
logger.debug(
111111
"Created file token provider for path: {} with refresh interval: {}, JWT expiration refresh: {}, JWT buffer: {}, next refresh: {}",
112112
tokenFilePath,

extensions/auth/opa/impl/src/test/java/org/apache/polaris/extension/auth/opa/token/FileBearerTokenProviderTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ public void testNonExistentFileThrows() {
199199
.close())
200200
.isInstanceOf(IllegalStateException.class)
201201
.hasMessageContaining("OPA token file does not exist or is not readable");
202+
203+
// No refresh tasks should be scheduled when construction fails fast.
204+
assertThat(asyncExec.tasks()).isEmpty();
202205
}
203206

204207
@Test

0 commit comments

Comments
 (0)