Skip to content

Commit a7b923c

Browse files
authored
HADOOP-17379. AbstractS3ATokenIdentifier to set issue date == now. (#2466)
Unless you explicitly set it, the issue date of a delegation token identifier is 0, which confuses spark renewal (SPARK-33440). This patch makes sure that all S3A DT identifiers have the current time as issue date, fixing the problem as far as S3A tokens are concerned. Contributed by Jungtaek Lim.
1 parent b57f04c commit a7b923c

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/auth/delegation/AbstractS3ATokenIdentifier.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.io.DataOutput;
2525
import java.io.IOException;
2626
import java.net.URI;
27+
import java.time.Clock;
2728
import java.util.Objects;
2829
import java.util.UUID;
2930

@@ -140,6 +141,7 @@ protected AbstractS3ATokenIdentifier(
140141
final URI uri) {
141142
super(kind, owner, renewer, realUser);
142143
this.uri = requireNonNull(uri);
144+
initializeIssueDate();
143145
}
144146

145147
/**
@@ -164,6 +166,13 @@ protected AbstractS3ATokenIdentifier(
164166
*/
165167
protected AbstractS3ATokenIdentifier(final Text kind) {
166168
super(kind);
169+
initializeIssueDate();
170+
}
171+
172+
private void initializeIssueDate() {
173+
Clock clock = Clock.systemDefaultZone();
174+
long now = clock.millis();
175+
setIssueDate(now);
167176
}
168177

169178
public String getBucket() {

hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/auth/delegation/TestS3ADelegationTokenSupport.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import static org.junit.Assert.assertEquals;
3939
import static org.junit.Assert.assertNotNull;
4040
import static org.junit.Assert.assertNull;
41+
import static org.junit.Assert.assertTrue;
4142

4243
/**
4344
* Unit tests related to S3A DT support.
@@ -58,6 +59,14 @@ public void testSessionTokenKind() throws Throwable {
5859
assertEquals(SESSION_TOKEN_KIND, identifier.getKind());
5960
}
6061

62+
@Test
63+
public void testSessionTokenIssueDate() throws Throwable {
64+
AbstractS3ATokenIdentifier identifier
65+
= new SessionTokenIdentifier();
66+
assertEquals(SESSION_TOKEN_KIND, identifier.getKind());
67+
assertTrue("issue date is not set", identifier.getIssueDate() > 0L);
68+
}
69+
6170
@Test
6271
public void testSessionTokenDecode() throws Throwable {
6372
Text alice = new Text("alice");
@@ -90,6 +99,8 @@ public void testSessionTokenDecode() throws Throwable {
9099
UserGroupInformation.AuthenticationMethod.TOKEN,
91100
decodedUser.getAuthenticationMethod());
92101
assertEquals("origin", decoded.getOrigin());
102+
assertEquals("issue date", identifier.getIssueDate(),
103+
decoded.getIssueDate());
93104
}
94105

95106
@Test

0 commit comments

Comments
 (0)