forked from kiritbasu/datacollector
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SDC-10344: SDC Security Manager should not block access to the blobstore
This turned out to be quite a big issue actually - the BlobStore has been directly passed to stages that runs with different classloader - thus there were moments when the BlobStore wasn't properly running with it's own class loader which could lead to many random exceptions. This patch introduces a Runtime wrapper like we have for everything else that is crossing classloader boundaries. Change-Id: I8606cbd20d23297194394b1b7f524e57d87a6b24 Reviewed-on: https://review.streamsets.net/17427 Tested-by: StreamSets CI <[email protected]> Reviewed-by: Jeff Evans <[email protected]>
- Loading branch information
Showing
4 changed files
with
128 additions
and
11 deletions.
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
container/src/main/java/com/streamsets/datacollector/blobstore/BlobStoreRuntime.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* Copyright 2018 StreamSets Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.streamsets.datacollector.blobstore; | ||
|
||
import com.streamsets.datacollector.util.LambdaUtil; | ||
import com.streamsets.pipeline.api.BlobStore; | ||
import com.streamsets.pipeline.api.StageException; | ||
|
||
import java.util.Set; | ||
|
||
/** | ||
* This is a runtime wrapper for BlobStore that will properly switch class loaders. | ||
*/ | ||
public class BlobStoreRuntime implements BlobStore { | ||
|
||
private ClassLoader cl; | ||
private BlobStore delegate; | ||
|
||
public BlobStoreRuntime(ClassLoader cl, BlobStore delegate) { | ||
this.cl = cl; | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override | ||
public void store(String namespace, String id, long version, String content) throws StageException { | ||
LambdaUtil.privilegedWithClassLoader( | ||
cl, | ||
StageException.class, | ||
() -> { delegate.store(namespace, id, version, content); return null; } | ||
); | ||
} | ||
|
||
@Override | ||
public long latestVersion(String namespace, String id) throws StageException { | ||
return LambdaUtil.privilegedWithClassLoader( | ||
cl, | ||
StageException.class, | ||
() -> delegate.latestVersion(namespace, id) | ||
); | ||
} | ||
|
||
@Override | ||
public boolean exists(String namespace, String id) { | ||
return LambdaUtil.privilegedWithClassLoader( | ||
cl, | ||
() -> delegate.exists(namespace, id) | ||
); | ||
} | ||
|
||
@Override | ||
public boolean exists(String namespace, String id, long version) { | ||
return LambdaUtil.privilegedWithClassLoader( | ||
cl, | ||
() -> delegate.exists(namespace, id, version) | ||
); | ||
} | ||
|
||
@Override | ||
public Set<Long> allVersions(String namespace, String id) { | ||
return LambdaUtil.privilegedWithClassLoader( | ||
cl, | ||
() -> delegate.allVersions(namespace, id) | ||
); | ||
} | ||
|
||
@Override | ||
public String retrieve(String namespace, String id, long version) throws StageException { | ||
return LambdaUtil.privilegedWithClassLoader( | ||
cl, | ||
StageException.class, | ||
() -> delegate.retrieve(namespace, id, version) | ||
); | ||
} | ||
|
||
@Override | ||
public VersionedContent retrieveLatest(String namespace, String id) throws StageException { | ||
return LambdaUtil.privilegedWithClassLoader( | ||
cl, | ||
StageException.class, | ||
() -> delegate.retrieveLatest(namespace, id) | ||
); | ||
} | ||
|
||
@Override | ||
public void delete(String namespace, String id, long version) throws StageException { | ||
LambdaUtil.privilegedWithClassLoader( | ||
cl, | ||
StageException.class, | ||
() -> { delegate.delete(namespace, id, version); return null; } | ||
); | ||
} | ||
|
||
@Override | ||
public void deleteAllVersions(String namespace, String id) throws StageException { | ||
LambdaUtil.privilegedWithClassLoader( | ||
cl, | ||
StageException.class, | ||
() -> { delegate.deleteAllVersions(namespace, id); return null; } | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters