Skip to content

Commit 4eac3e1

Browse files
authored
Merge pull request #562 from IABTechLab/gdm-UID2-5448-cleanup
Cleaned up refresh from and salt age threshold flags
2 parents 53eb4ed + c181f3e commit 4eac3e1

33 files changed

+121
-198
lines changed

conf/default-config.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
{
2-
"enable_keysets": false,
3-
"enable_salt_rotation_refresh_from": false
4-
}
2+
"enable_keysets": false
3+
}

conf/local-config.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"keys_acl_metadata_path": "keys_acl/metadata.json",
1313
"salts_metadata_path": "salts/metadata.json",
1414
"salt_snapshot_location_prefix": "salts/salts.txt.",
15-
"enable_salt_rotation_refresh_from": false,
1615
"operators_metadata_path": "operators/metadata.json",
1716
"enclaves_metadata_path": "enclaves/metadata.json",
1817
"partners_metadata_path": "partners/metadata.json",
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package com.uid2.admin;
22

3-
public class AdminConst {
4-
public static String enableKeysetConfigProp = "enable_keysets";
3+
public final class AdminConst {
4+
private AdminConst() {
5+
}
6+
7+
public static final String enableKeysetConfigProp = "enable_keysets";
58
public static final String ROLE_OKTA_GROUP_MAP_MAINTAINER = "role_okta_group_map_maintainer";
69
public static final String ROLE_OKTA_GROUP_MAP_PRIVILEGED = "role_okta_group_map_privileged";
710
public static final String ROLE_OKTA_GROUP_MAP_SUPER_USER = "role_okta_group_map_super_user";
8-
public static final String ENABLE_SALT_ROTATION_REFRESH_FROM = "enable_salt_rotation_refresh_from";
9-
public static final String ENABLE_SALT_ROTATION_CUSTOM_AGE_THRESHOLDS = "enable_salt_rotation_custom_age_thresholds";
1011
}

src/main/java/com/uid2/admin/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public void run() {
233233
WriteLock writeLock = new WriteLock();
234234
KeyHasher keyHasher = new KeyHasher();
235235
IKeypairGenerator keypairGenerator = new SecureKeypairGenerator();
236-
SaltRotation saltRotation = new SaltRotation(config, keyGenerator);
236+
SaltRotation saltRotation = new SaltRotation(keyGenerator);
237237
EncryptionKeyService encryptionKeyService = new EncryptionKeyService(
238238
config, auth, writeLock, encryptionKeyStoreWriter, keysetKeyStoreWriter, keyProvider, keysetKeysProvider, adminKeysetProvider, adminKeysetStoreWriter, keyGenerator, clock);
239239
KeysetManager keysetManager = new KeysetManager(

src/main/java/com/uid2/admin/salt/SaltRotation.java

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
package com.uid2.admin.salt;
22

3-
import com.uid2.admin.AdminConst;
43
import com.uid2.shared.model.SaltEntry;
54
import com.uid2.shared.secret.IKeyGenerator;
65

7-
import com.uid2.shared.store.salt.ISaltProvider;
86
import com.uid2.shared.store.salt.ISaltProvider.ISaltSnapshot;
97
import com.uid2.shared.store.salt.RotatingSaltProvider.SaltSnapshot;
10-
import io.vertx.core.json.JsonObject;
118
import lombok.Getter;
129
import org.slf4j.Logger;
1310
import org.slf4j.LoggerFactory;
@@ -22,18 +19,10 @@ public class SaltRotation {
2219
private static final double MAX_SALT_PERCENTAGE = 0.8;
2320

2421
private final IKeyGenerator keyGenerator;
25-
private final boolean isRefreshFromEnabled;
26-
private final boolean isCustomAgeThresholdEnabled;
2722
private static final Logger LOGGER = LoggerFactory.getLogger(SaltRotation.class);
2823

29-
public SaltRotation(JsonObject config, IKeyGenerator keyGenerator) {
24+
public SaltRotation(IKeyGenerator keyGenerator) {
3025
this.keyGenerator = keyGenerator;
31-
this.isRefreshFromEnabled = config.getBoolean(AdminConst.ENABLE_SALT_ROTATION_REFRESH_FROM, false);
32-
this.isCustomAgeThresholdEnabled = config.getBoolean(AdminConst.ENABLE_SALT_ROTATION_CUSTOM_AGE_THRESHOLDS, false);
33-
}
34-
35-
public boolean isCustomAgeThresholdEnabled() {
36-
return this.isCustomAgeThresholdEnabled;
3726
}
3827

3928
public Result rotateSalts(
@@ -97,7 +86,6 @@ public Result rotateSaltsZero(
9786
return Result.fromSnapshot(nextSnapshot);
9887
}
9988

100-
10189
private static int getNumSaltsToRotate(SaltEntry[] preRotationSalts, double fraction) {
10290
return (int) Math.ceil(preRotationSalts.length * fraction);
10391
}
@@ -107,11 +95,7 @@ private Set<SaltEntry> findRefreshableSalts(SaltEntry[] preRotationSalts, Target
10795
}
10896

10997
private boolean isRefreshable(TargetDate targetDate, SaltEntry salt) {
110-
if (this.isRefreshFromEnabled) {
111-
return Instant.ofEpochMilli(salt.refreshFrom()).truncatedTo(ChronoUnit.DAYS).equals(targetDate.asInstant());
112-
}
113-
114-
return true;
98+
return Instant.ofEpochMilli(salt.refreshFrom()).truncatedTo(ChronoUnit.DAYS).equals(targetDate.asInstant());
11599
}
116100

117101
private SaltEntry[] rotateSalts(SaltEntry[] oldSalts, List<SaltEntry> saltsToRotate, TargetDate targetDate) throws Exception {
@@ -163,7 +147,7 @@ private List<SaltEntry> pickSaltsToRotate(
163147
TargetDate targetDate,
164148
Duration[] minAges,
165149
int numSaltsToRotate) {
166-
var maxSaltsPerAge = this.isRefreshFromEnabled ? (int) (numSaltsToRotate * MAX_SALT_PERCENTAGE) : numSaltsToRotate;
150+
var maxSaltsPerAge = (int) (numSaltsToRotate * MAX_SALT_PERCENTAGE);
167151

168152
var thresholds = Arrays.stream(minAges)
169153
.map(minAge -> targetDate.asInstant().minusSeconds(minAge.getSeconds()))

src/main/java/com/uid2/admin/vertx/service/SaltService.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,7 @@ private void handleSaltRotate(RoutingContext rc) {
132132
final Optional<Double> fraction = RequestUtil.getDouble(rc, "fraction");
133133
if (fraction.isEmpty()) return;
134134

135-
final Duration[] ageThresholds;
136-
if (saltRotation.isCustomAgeThresholdEnabled()) {
137-
ageThresholds = RequestUtil.getDurations(rc, "min_ages_in_seconds");
138-
if (ageThresholds == null) return;
139-
} else {
140-
ageThresholds = SALT_ROTATION_AGE_THRESHOLDS;
141-
}
142-
LOGGER.info("Salt rotation age thresholds in seconds: {}", Arrays.stream(ageThresholds).map(Duration::toSeconds).collect(Collectors.toList()));
135+
LOGGER.info("Salt rotation age thresholds in seconds: {}", Arrays.stream(SALT_ROTATION_AGE_THRESHOLDS).map(Duration::toSeconds).collect(Collectors.toList()));
143136

144137
final TargetDate targetDate =
145138
RequestUtil.getDate(rc, "target_date", DateTimeFormatter.ISO_LOCAL_DATE)
@@ -155,7 +148,7 @@ private void handleSaltRotate(RoutingContext rc) {
155148
final List<RotatingSaltProvider.SaltSnapshot> snapshots = saltProvider.getSnapshots();
156149
final RotatingSaltProvider.SaltSnapshot lastSnapshot = snapshots.getLast();
157150

158-
final SaltRotation.Result result = saltRotation.rotateSalts(lastSnapshot, ageThresholds, fraction.get(), targetDate);
151+
final SaltRotation.Result result = saltRotation.rotateSalts(lastSnapshot, SALT_ROTATION_AGE_THRESHOLDS, fraction.get(), targetDate);
159152
if (!result.hasSnapshot()) {
160153
ResponseUtil.error(rc, 200, result.getReason());
161154
return;
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"version" : 1744264807066,
3-
"generated" : 1744264807,
2+
"version" : 1,
3+
"generated" : 1754901630,
44
"first_level" : "fOGY/aRE44peL23i+cE9MkJrzmEeNZZziNZBfq7qqk8=",
55
"id_prefix" : "b",
66
"id_secret" : "HF6Qz42HBbVHINxhh191dB09BCuTWyBkNtrNicO4ZCw=",
@@ -10,10 +10,10 @@
1010
"location" : "salts/encrypted/123_public/salts.txt.1670796729291",
1111
"size" : 2
1212
}, {
13-
"effective" : 1766125493000,
13+
"effective" : 1745907348982,
1414
"expires" : 1766720293000,
15-
"location" : "salts/encrypted/123_public/salts.txt.1766125493000",
16-
"size" : 4
15+
"location" : "salts/encrypted/123_public/salts.txt.1745907348982",
16+
"size" : 2
1717
} ],
1818
"key_id" : 3
1919
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"key_id" : 3,
33
"encryption_version" : "1.0",
4-
"encrypted_payload" : "9vKzSl5qhansVyce77wGN1PPaqauuiB18AMnDk1qlCU0idX2yPbrVOnulSqzDk3riG03T43qbx80bhGyxYe0oEbUeNmRV/9xmwMjmmkVzBZlCUPomhVxkmHMrOR2nKUWit0s02lm4lxFvkTdjw5yyZA/gPFmNpfP04URb/l6vw+d0Le1TIrE9esYi6GycqTPf8armDW8rEzEJhhN4uSgZvPG"
4+
"encrypted_payload" : "T+Gb8K0+APNgzfQ70bIv6d46r3xMIg2ZoLzKkBIJJ1jYN3s0F/5K6rru7gcdoYGWU8+Oe3i8VCUBAxk7i5NvExsKPObSZZFVxNhkYV9w3PMvTilWTXhSZTSu7fPPr2vb2TPP8MNYb8EqwrygwclHCKTT5GM9tChA5xxjMWa5P9S6tlaIdWrIrlov3zzxEm1XTCvnhQi6sWl3EfmI8pakFjI0jY1O7YtJ2ZELa16I780VeW4d4s1IgMIvVR3oGRtBD3KI0ikmjSJ12S36dp4cZhe/uHRt0UanN4rEjgnNWtujBLK2qoLf0bbZgin3GonG4Q+Y3mzTM8I="
55
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"key_id" : 3,
3+
"encryption_version" : "1.0",
4+
"encrypted_payload" : "baVbB6zql5BepnPma05MDRHC+o1FP2Fs02wydarYH6/KkPcVwZY3EgSAzGqpgT0xli3+tz4VBB00jjz2uVtRMCNJlvMH4GSPUfdi6qjWgX1fHMXeU+Z5Rxcyg6elsX81pMFD0/87pQBllo6+5rOSfDfan881QqhM2cVJY7gVG/z9plDp33CEhWQ0/dWaoGiyBWMyqmGwkkhipeVAT/lH3gr5W7sMnuG3Z9PQw6sWv5PJLdFiCiN4EjWYIv3qpJ689sbYKGaGi3HNaq3bHsO9nFInDc+80vK+MWpMHb/wRIQgfUGJytfSNuDdczDEijQyTJNElpypQ74="
5+
}

src/main/resources/localstack/s3/core/salts/encrypted/123_public/salts.txt.1766125493000

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)