Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] java.io.FilePermission error while querying remote restored index with scripted field. #14268

Closed
Dileep-Dora opened this issue Jun 13, 2024 · 2 comments · Fixed by #14411
Assignees
Labels
bug Something isn't working Search:Searchable Snapshots

Comments

@Dileep-Dora
Copy link

Describe the bug

We're trying out searchable snapshots. we've taken snapshot and restored as remote searchable index on search nodes.
also we've a scripted field defined.

When querying getting the below exception.

java.base/java.security.AccessController.checkPermission(AccessController.java:1068)
java.base/java.lang.SecurityManager.checkPermission(SecurityManager.java:416)
java.base/java.lang.SecurityManager.checkDelete(SecurityManager.java:875)
java.base/sun.nio.fs.UnixPath.checkDelete(UnixPath.java:794)
java.base/sun.nio.fs.UnixFileSystemProvider.implDelete(UnixFileSystemProvider.java:226)
java.base/sun.nio.fs.AbstractFileSystemProvider.deleteIfExists(AbstractFileSystemProvider.java:110)
java.base/java.nio.file.Files.deleteIfExists(Files.java:1191)
org.opensearch.index.store.remote.filecache.FileCacheFactory.lambda$createDefaultBuilder$0(FileCacheFactory.java:58)
org.opensearch.ExceptionsHelper.catchAsRuntimeException(ExceptionsHelper.java:352)
org.opensearch.index.store.remote.filecache.FileCacheFactory.lambda$createDefaultBuilder$1(FileCacheFactory.java:58)
org.opensearch.index.store.remote.utils.cache.LRUCache.evict(LRUCache.java:363)
org.opensearch.index.store.remote.utils.cache.LRUCache.replaceNode(LRUCache.java:330)
org.opensearch.index.store.remote.utils.cache.LRUCache.compute(LRUCache.java:168)
org.opensearch.index.store.remote.utils.cache.SegmentedCache.compute(SegmentedCache.java:96)
org.opensearch.index.store.remote.filecache.FileCache.compute(FileCache.java:91)
org.opensearch.index.store.remote.utils.TransferManager.fetchBlob(TransferManager.java:59)
org.opensearch.index.store.remote.file.OnDemandBlockSnapshotIndexInput.fetchBlock(OnDemandBlockSnapshotIndexInput.java:148)
org.opensearch.index.store.remote.file.OnDemandBlockIndexInput.demandBlock(OnDemandBlockIndexInput.java:340)
org.opensearch.index.store.remote.file.OnDemandBlockIndexInput.seekInternal(OnDemandBlockIndexInput.java:311)
org.opensearch.index.store.remote.file.OnDemandBlockIndexInput.readInt(OnDemandBlockIndexInput.java:251)
org.opensearch.index.store.remote.file.OnDemandBlockSnapshotIndexInput.readInt(OnDemandBlockSnapshotIndexInput.java:28)
org.apache.lucene.codecs.lucene90.IndexedDISI.advanceBlock(IndexedDISI.java:474)
org.apache.lucene.codecs.lucene90.IndexedDISI.advanceExact(IndexedDISI.java:459)
org.apache.lucene.codecs.lucene90.Lucene90DocValuesProducer$21.advanceExact(Lucene90DocValuesProducer.java:904)
org.apache.lucene.index.SingletonSortedSetDocValues.advanceExact(SingletonSortedSetDocValues.java:85)
org.opensearch.index.fielddata.FieldData$12.advanceExact(FieldData.java:434)
org.opensearch.index.fielddata.ScriptDocValues$BinaryScriptDocValues.setNextDocId(ScriptDocValues.java:508)
org.opensearch.index.fielddata.ScriptDocValues$Strings.setNextDocId(ScriptDocValues.java:547)
org.opensearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:103)
org.opensearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:56)
if (doc.containsKey('tp') && !doc['tp'].empty ) {
  def 
                                  ^---- HERE



access denied ("java.io.FilePermission" "/data/opensearch/data/nodes/0/cache/tIZdR9UlQZqkFyOsaAIycw/0/RemoteLocalStore/_259_Lucene90_0.dvd.15" "delete")

but the required file permissions are there 0755

Related component

Search:Searchable Snapshots

To Reproduce

  1. Index some data
  2. Take snapshot
  3. restore snapshot as remote
  4. query with a scripted field defined

Expected behavior

It should not throw any exception and should work like regular search i.e scripted field on a normal index vs remote index(restored from snapshot as remote).

Additional Details

Opensearch
version: 2.13

@andrross
Copy link
Member

We ran into a similar problem before where if a script trigged a remote download, then we must elevate privileges for the security manager:

return AccessController.doPrivileged((PrivilegedAction<FileCachedIndexInput>) () -> {

This appears to be the case where even before attempting a remote download we do an eviction from the cache, which results in deleting a local file. That part of the code does not elevate privileges:

final CachedIndexInput cacheEntry = fileCache.compute(key, (path, cachedIndexInput) -> {

I suspect the fix here is to move the AccessController.doPrivileged call higher up in the call stack to cover this case.

@finnegancarroll
Copy link
Contributor

Thanks for the insight @andrross, i'll test this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Search:Searchable Snapshots
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants