Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

### Fixed

* Return every JWT-SVID without a hint from `fetchJwtSvids`. JWT-SVIDs with an empty hint were deduplicated as if they shared a hint, so only the first of them was returned. X.509-SVIDs already got this fix in #385
* Honor sub-second initialization timeouts in `DefaultX509Source`, `DefaultJwtSource` and `CachedJwtSource`. The `initTimeout` option and the `spiffe.newX509Source.timeout` and `spiffe.newJwtSource.timeout` system properties were truncated to whole seconds, so a timeout below one second failed `newSource` immediately
* Fail `newSource` with `X509SourceException` or `JwtSourceException`, and keep the thread's interrupt status, when the calling thread is interrupted while waiting for the initial update. Without a timeout, `newSource` used to return a source that had no SVID or bundles yet

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,14 +457,13 @@ private List<JwtSvid> processJwtSvidResponse(Workload.JWTSVIDResponse response,
ArrayList<JwtSvid> svids = new ArrayList<>(n);
HashSet<String> hints = new HashSet<>();
for (int i = 0; i < n; i++) {
final String hint = response.getSvids(i).getHint();
// In the event of more than one JWTSVID message with the same hint value set, then the first message in the
// list SHOULD be selected.
if (hints.contains(response.getSvids(i).getHint())) {
// list SHOULD be selected. JWT-SVIDs without a hint are all kept.
if (!hint.isEmpty() && !hints.add(hint)) {
continue;
}
JwtSvid svid = JwtSvid.parseInsecure(response.getSvids(i).getSvid(), audience, response.getSvids(i).getHint());
hints.add(svid.getHint());
svids.add(svid);
svids.add(JwtSvid.parseInsecure(response.getSvids(i).getSvid(), audience, hint));
}
return svids;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ void testFetchJwtSvids() {
List<JwtSvid> jwtSvids = workloadApiClient.fetchJwtSvids("aud1", "aud2", "aud3");
System.out.println(jwtSvids.toString());
assertNotNull(jwtSvids);
assertEquals(jwtSvids.size(), 2);
assertEquals(3, jwtSvids.size());
assertEquals(SpiffeId.parse("spiffe://example.org/workload-server"), jwtSvids.get(0).getSpiffeId());
assertTrue(jwtSvids.get(0).getAudience().contains("aud1"));
assertEquals(3, jwtSvids.get(0).getAudience().size());
Expand All @@ -409,6 +409,8 @@ void testFetchJwtSvids() {
assertTrue(jwtSvids.get(1).getAudience().contains("aud1"));
assertEquals(3, jwtSvids.get(1).getAudience().size());
assertEquals("", jwtSvids.get(1).getHint());
assertEquals(SpiffeId.parse("spiffe://example.org/other-workload-server"), jwtSvids.get(2).getSpiffeId());
assertEquals("", jwtSvids.get(2).getHint());
} catch (JwtSvidException e) {
fail(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public void fetchJWTSVID(Workload.JWTSVIDRequest request, StreamObserver<Workloa
String spiffeId = request.getSpiffeId();
String extraSpiffeId = "spiffe://example.org/extra-workload-server";
String skippedSpiffeId = "spiffe://example.org/this-should-be-filtered-out";
String otherSpiffeId = "spiffe://example.org/other-workload-server";
boolean firstOnly = true;
if (StringUtils.isBlank(spiffeId)) {
firstOnly = false;
Expand All @@ -139,10 +140,16 @@ public void fetchJWTSVID(Workload.JWTSVIDRequest request, StreamObserver<Workloa
extraClaims.put("aud", getAudienceList(request.getAudienceList()));
extraClaims.put("exp", expiration);

Map<String, Object> otherClaims = new HashMap<>();
otherClaims.put("sub", otherSpiffeId);
otherClaims.put("aud", getAudienceList(request.getAudienceList()));
otherClaims.put("exp", expiration);

KeyPair keyPair = TestUtils.generateECKeyPair(Curve.P_521);

String token = TestUtils.generateToken(claims, keyPair, "authority1");
String extraToken = TestUtils.generateToken(extraClaims, keyPair, "authority1");
String otherToken = TestUtils.generateToken(otherClaims, keyPair, "authority1");

Workload.JWTSVID jwtsvid = Workload.JWTSVID
.newBuilder()
Expand All @@ -157,6 +164,13 @@ public void fetchJWTSVID(Workload.JWTSVIDRequest request, StreamObserver<Workloa
.setSvid(extraToken)
.build();

// A second JWT-SVID without a hint. Empty hints are not deduplicated, so the client must keep it.
Workload.JWTSVID otherJwtsvid = Workload.JWTSVID
.newBuilder()
.setSpiffeId(otherSpiffeId)
.setSvid(otherToken)
.build();

// This JWT-SVID should be filtered out by the client because it has a non-unique hint and is not the first JWT-SVID in the response with this hint.
Workload.JWTSVID skippedJWTSVID = Workload.JWTSVID
.newBuilder()
Expand All @@ -170,6 +184,7 @@ public void fetchJWTSVID(Workload.JWTSVIDRequest request, StreamObserver<Workloa
builder.addSvids(skippedJWTSVID);
if (!firstOnly) {
builder.addSvids(extraJwtsvid);
builder.addSvids(otherJwtsvid);
}

Workload.JWTSVIDResponse response = builder.build();
Expand Down
Loading