-
Notifications
You must be signed in to change notification settings - Fork 6
Use EncryptedFilesSyncJob #400
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
Changes from all commits
3e2d8a1
dee6448
4e7d595
433bce0
17e9d56
4389717
651cb78
1019944
a60c81b
11da9d2
a14e301
cec55dc
e5e0095
d5cb5c2
b7a7bbc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,14 +14,14 @@ | |
|
|
||
| public class SaltEncryptionJob extends Job { | ||
| private final Collection<OperatorKey> globalOperators; | ||
| private final Collection<RotatingSaltProvider.SaltSnapshot> saltEntries; | ||
| private final RotatingSaltProvider saltProvider; | ||
| private final MultiScopeStoreWriter<Collection<RotatingSaltProvider.SaltSnapshot>> multiScopeStoreWriter; | ||
|
|
||
| public SaltEncryptionJob(Collection<OperatorKey> globalOperators, | ||
| Collection<RotatingSaltProvider.SaltSnapshot> saltEntries, | ||
| RotatingSaltProvider saltProvider, | ||
| MultiScopeStoreWriter<Collection<RotatingSaltProvider.SaltSnapshot>> multiScopeStoreWriter) { | ||
| this.globalOperators = globalOperators; | ||
| this.saltEntries = saltEntries; | ||
| this.saltProvider = saltProvider; | ||
| this.multiScopeStoreWriter = multiScopeStoreWriter; | ||
| } | ||
|
|
||
|
|
@@ -34,8 +34,8 @@ public String getId() { | |
| @Override | ||
| public void execute() throws Exception { | ||
| List<Integer> desiredPrivateState = PrivateSiteUtil.getPrivateSaltSites(globalOperators); | ||
| multiScopeStoreWriter.uploadPrivateWithEncryption(desiredPrivateState, saltEntries, null); | ||
| multiScopeStoreWriter.uploadPrivateWithEncryption(desiredPrivateState, saltProvider.getSnapshots(), saltProvider.getMetadata()); | ||
| List<Integer> desiredPublicState = PublicSiteUtil.getPublicSaltSites(globalOperators); | ||
| multiScopeStoreWriter.uploadPublicWithEncryption(desiredPublicState, saltEntries, null); | ||
| multiScopeStoreWriter.uploadPublicWithEncryption(desiredPublicState, saltProvider.getSnapshots(), saltProvider.getMetadata()); | ||
| } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. passing metadata in extraMeta argument to use this info while encrypting per site. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,8 +28,6 @@ public class EncryptedSaltStoreWriter extends SaltStoreWriter implements StoreWr | |
| private RotatingCloudEncryptionKeyProvider cloudEncryptionKeyProvider; | ||
| private Integer siteId; | ||
|
|
||
| private final List<RotatingSaltProvider.SaltSnapshot> previousSeenSnapshots = new ArrayList<>(); | ||
|
|
||
| private static final Logger LOGGER = LoggerFactory.getLogger(EncryptedSaltStoreWriter.class); | ||
| public EncryptedSaltStoreWriter(JsonObject config, RotatingSaltProvider provider, FileManager fileManager, | ||
| TaggableCloudStorage cloudStorage, VersionGenerator versionGenerator, StoreScope scope, | ||
|
|
@@ -51,12 +49,6 @@ protected void uploadSaltsSnapshot(RotatingSaltProvider.SaltSnapshot snapshot, S | |
| throw new IllegalStateException("Site ID is not set."); | ||
| } | ||
|
|
||
| if (!cloudStorage.list(location).isEmpty()) { | ||
| // update the tags on the file to ensure it is still marked as current | ||
| this.setStatusTagToCurrent(location); | ||
| return; | ||
| } | ||
|
|
||
| StringBuilder stringBuilder = new StringBuilder(); | ||
|
|
||
| for (SaltEntry entry: snapshot.getAllRotatingSalts()) { | ||
|
|
@@ -89,27 +81,12 @@ protected void uploadSaltsSnapshot(RotatingSaltProvider.SaltSnapshot snapshot, S | |
|
|
||
| this.upload(newSaltsFile.toString(), location); | ||
| } | ||
|
|
||
| @Override | ||
| protected void refreshProvider() { | ||
| // we do not need to refresh the provider on encrypted writers | ||
| } | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. re-organised the method to not have this noop |
||
| @Override | ||
| protected List<RotatingSaltProvider.SaltSnapshot> getSnapshots(RotatingSaltProvider.SaltSnapshot data){ | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dont need this as well, as getSnapshots is handled in |
||
| /* | ||
| Since metadata.json is overwritten during the process, we maintain a history of all snapshots seen so far. | ||
| On the final write, we append this history to metadata.json to ensure no snapshots are lost. | ||
| */ | ||
| this.previousSeenSnapshots.add(data); | ||
| return this.previousSeenSnapshots; | ||
| } | ||
|
|
||
| @Override | ||
| public void upload(Object data, JsonObject extraMeta) throws Exception { | ||
| for(RotatingSaltProvider.SaltSnapshot saltSnapshot: (Collection<RotatingSaltProvider.SaltSnapshot>) data) { | ||
| super.upload(saltSnapshot); | ||
| } | ||
| @SuppressWarnings("unchecked") | ||
| List<RotatingSaltProvider.SaltSnapshot> snapshots = new ArrayList<>((Collection<RotatingSaltProvider.SaltSnapshot>) data); | ||
| this.buildAndUploadMetadata(extraMeta, this.uploadSnapshotsAndGetMetadata(snapshots)); | ||
| } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gets all snapshots, calls buildAndUploadMetadata with extraMeta and snapshotmeta. buildAndUploadMetadata works same way for both unencrypted and encrypted |
||
|
|
||
| @Override | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,7 +43,7 @@ public SaltStoreWriter(JsonObject config, RotatingSaltProvider provider, FileMan | |
| this.versionGenerator = versionGenerator; | ||
| } | ||
|
|
||
| protected List<RotatingSaltProvider.SaltSnapshot> getSnapshots(RotatingSaltProvider.SaltSnapshot data){ | ||
| private List<RotatingSaltProvider.SaltSnapshot> getSnapshots(RotatingSaltProvider.SaltSnapshot data){ | ||
| if (provider.getSnapshots() == null) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed override |
||
| throw new IllegalStateException("Snapshots cannot be null"); | ||
| } | ||
|
|
@@ -75,10 +75,7 @@ protected List<RotatingSaltProvider.SaltSnapshot> getSnapshots(RotatingSaltProvi | |
| return filteredSnapshots; | ||
| } | ||
|
|
||
| public void upload(RotatingSaltProvider.SaltSnapshot data) throws Exception { | ||
| final Instant now = Instant.now(); | ||
| final long generated = now.getEpochSecond(); | ||
|
|
||
| protected JsonObject getMetadata() throws Exception { | ||
| JsonObject metadata = null; | ||
| try { | ||
| metadata = provider.getMetadata(); | ||
|
|
@@ -89,15 +86,20 @@ public void upload(RotatingSaltProvider.SaltSnapshot data) throws Exception { | |
| throw e; | ||
| } | ||
| } | ||
| // bump up metadata version | ||
| return metadata; | ||
| } | ||
|
|
||
| protected void buildAndUploadMetadata(JsonObject metadata, JsonArray snapshotsMetadata ) throws Exception{ | ||
| final Instant now = Instant.now(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. constructs metadata and upload based on init metadata. For unencrypted, it is provider.getMetadata(); |
||
| final long generated = now.getEpochSecond(); | ||
| metadata.put("version", versionGenerator.getVersion()); | ||
| metadata.put("generated", generated); | ||
|
|
||
| final JsonArray snapshotsMetadata = new JsonArray(); | ||
| metadata.put("salts", snapshotsMetadata); | ||
| fileManager.uploadMetadata(metadata, "salts", new CloudPath(provider.getMetadataPath())); | ||
| } | ||
|
|
||
| List<RotatingSaltProvider.SaltSnapshot> snapshots = this.getSnapshots(data); | ||
|
|
||
| protected JsonArray uploadSnapshotsAndGetMetadata(List<RotatingSaltProvider.SaltSnapshot> snapshots) throws Exception { | ||
| final JsonArray snapshotsMetadata = new JsonArray(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ,split it to a function, no change in implementation , except making it return snapshotsMetadata |
||
| for (RotatingSaltProvider.SaltSnapshot snapshot : snapshots) { | ||
| final String location = getSaltSnapshotLocation(snapshot); | ||
| final JsonObject snapshotMetadata = new JsonObject(); | ||
|
|
@@ -106,17 +108,19 @@ public void upload(RotatingSaltProvider.SaltSnapshot data) throws Exception { | |
| snapshotMetadata.put("location", location); | ||
| snapshotMetadata.put("size", snapshot.getAllRotatingSalts().length); | ||
| snapshotsMetadata.add(snapshotMetadata); | ||
|
|
||
| uploadSaltsSnapshot(snapshot, location); | ||
| } | ||
| return snapshotsMetadata; | ||
| } | ||
|
|
||
| fileManager.uploadMetadata(metadata, "salts", new CloudPath(provider.getMetadataPath())); | ||
|
|
||
| // refresh manually | ||
| public void upload(RotatingSaltProvider.SaltSnapshot data) throws Exception { | ||
| JsonObject metadata = this.getMetadata(); | ||
| List<RotatingSaltProvider.SaltSnapshot> snapshots = this.getSnapshots(data); | ||
| this.buildAndUploadMetadata(metadata, this.uploadSnapshotsAndGetMetadata(snapshots)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original SaltStoreWrite code only uploaded the latest snapshot, now it will re-upload all of them..
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. `
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. snapshots = this.getSnapshots(data) controls what snapshots are returned, and it only returns newestEffective. It isn't changed (if I understand it correctly) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah no sorry you're right |
||
| refreshProvider(); | ||
| } | ||
|
|
||
| protected void refreshProvider() throws Exception { | ||
| private void refreshProvider() throws Exception { | ||
| provider.loadContent(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed the noop override. It can be private |
||
| } | ||
|
|
||
|
|
||
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.
Changes to accept saltProvider and not just saltEntries.
We can then pass unencrypted saltEntries along with metadata to encryption process.