-
Notifications
You must be signed in to change notification settings - Fork 15
Add translog encryption #39
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
Add translog encryption #39
Conversation
Signed-off-by: Rajat Gupta <[email protected]>
|
OSB: |
|
I will take a look at the PR but do you know why the throughout dropped and latency increased? |
|
is it solely coming from the Translog operation? can we isolate it by disabling and enabling it? |
Not sure but on my cluster in |
| private static ChannelFactory createCryptoChannelFactory(KeyIvResolver keyIvResolver, String translogUUID) throws IOException { | ||
| try { | ||
| CryptoChannelFactory channelFactory = new CryptoChannelFactory(keyIvResolver, translogUUID); | ||
| LogManager.getLogger(CryptoTranslog.class).debug("CryptoChannelFactory initialized for translog: {}", translogUUID); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can use logger defined above?
| public KeyIvResolver getKeyIvResolver() { | ||
| return keyIvResolver; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Who calls this method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, forgot to clean this.
| public FileChannel getDelegate() { | ||
| return delegate; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
who is calling this method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forgot to clean this.
| ChunkInfo chunkInfo = getChunkInfo(position); | ||
|
|
||
| // Read-modify-write chunk pattern | ||
| byte[] existingChunk = readAndDecryptChunk(chunkInfo.chunkIndex); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are decrypting entire file everytime and re-encrypting it along with new incoming diff. This may increase overall time. do we know rough idea, how frequently we write to this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not understand, we are encrypting and decrypting in 8kb chunks, not the whole file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ohh okay, we are decrypting only last chunk
Signed-off-by: Rajat Gupta <[email protected]>
udabhas
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
|
|
||
| // Create new engine config by copying all fields from existing config | ||
| // but replace the translog factory with our crypto version | ||
| EngineConfig cryptoConfig = new EngineConfig.Builder() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we just not override (the builder should allow) the cryptoTranslogFactory to an existing config rather than copying over all these configs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was the issue, EngineConfig.java doesn't have any copy constructor :/
src/main/java/org/opensearch/index/store/CryptoEngineFactory.java
Outdated
Show resolved
Hide resolved
| * | ||
| * @opensearch.internal | ||
| */ | ||
| public class CryptoFileChannelWrapper extends FileChannel { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds very very weird to extend the FileChannel. Did we do the same in actual Translog Impl?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the Translog impl, it was just returning FileChannel::open so it did not need to wrap the file channel
src/main/java/org/opensearch/index/translog/CryptoFileChannelWrapper.java
Outdated
Show resolved
Hide resolved
| * @throws IOException if there is an error setting up the channel | ||
| */ | ||
| public CryptoFileChannelWrapper( | ||
| FileChannel delegate, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see this is the weird part, we extend a FileChannel and then use it a constructor args.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are just using it as a wrapper, when we pass this FileChannel as the delegate field arg we are forwarding actual I/O operations to this delegate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We actually use a similar pattern here: https://github.com/opensearch-project/security/blob/main/src/main/java/org/opensearch/security/filter/DelegatingRestHandler.java#L28-L31
| return 0; | ||
| } | ||
|
|
||
| positionLock.writeLock().lock(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need a writeLock in read?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 280:
if (position == this.position.get()) {
this.position.addAndGet(dst.remaining());
}
this was modifying the position, but yes for stateful reads I should use writeLock and for positional reads readLock, will update this.
Signed-off-by: Rajat Gupta <[email protected]>
| buildscript { | ||
| ext { | ||
| opensearch_version = System.getProperty("opensearch.version", "3.1.0-SNAPSHOT") | ||
| opensearch_version = System.getProperty("opensearch.version", "3.2.0-SNAPSHOT") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you sync with the latest changes on the main branch? Not sure why this is showing here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, we were using 3.1.0 snapshot earlier, but for translog once the core changes are merged we will have to use 3.2.0 here.
src/main/java/org/opensearch/index/store/CryptoEngineFactory.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Rajat Gupta <[email protected]>
Signed-off-by: Rajat Gupta <[email protected]>
|
|
||
| // TranslogHeader constants replicated to avoid cross-classloader access | ||
| private static final String TRANSLOG_CODEC = "translog"; | ||
| private static final int VERSION_PRIMARY_TERM = 3; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how do we derive this value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, but it was hardcoded here in the TranslogHeader impl: https://github.com/opensearch-project/OpenSearch/blob/8f310f5e37c65f9c3116c05685a6713eb5e68886/server/src/main/java/org/opensearch/index/translog/TranslogHeader.java#L67
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use (i.e import) the constants as it is in the core? a change in there will also reflect at our side, otherwise we will corrupt the data.
Signed-off-by: Rajat Gupta <[email protected]>
| EngineConfig cryptoConfig = config | ||
| .toBuilder() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super!
| } | ||
|
|
||
| @Override | ||
| public MappedByteBuffer map(MapMode mode, long position, long size) throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
core supports Mmap?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We added it here just so that in future if map is used it clearly throws an exception.
|
On c5.12xLarge instance |
|
Perfect. we should consider this is our baseline. |
This reverts commit 352ac8a.
Description
Adds transaction log (translog) encryption using AES-GCM with 8KB chunks.
Related Issues
Resolves
Check List
--signoff.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.