Skip to content

Commit 1d5d7d0

Browse files
pzampinosteveloughran
authored andcommitted
HADOOP-16658. S3A connector does not support including the token renewer in the token identifier.
Contributed by Phil Zampino. Change-Id: Iea9d5028dcf58bda4da985604f5cd3ac283619bd
1 parent a901405 commit 1d5d7d0

14 files changed

+119
-32
lines changed

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
import org.apache.hadoop.fs.s3a.s3guard.BulkOperationState;
111111
import org.apache.hadoop.fs.s3a.select.InternalSelectConstants;
112112
import org.apache.hadoop.io.IOUtils;
113+
import org.apache.hadoop.io.Text;
113114
import org.apache.hadoop.security.token.TokenIdentifier;
114115
import org.apache.hadoop.util.DurationInfo;
115116
import org.apache.hadoop.util.LambdaUtils;
@@ -3186,7 +3187,8 @@ public Token<AbstractS3ATokenIdentifier> getDelegationToken(String renewer)
31863187
entryPoint(Statistic.INVOCATION_GET_DELEGATION_TOKEN);
31873188
LOG.debug("Delegation token requested");
31883189
if (delegationTokens.isPresent()) {
3189-
return delegationTokens.get().getBoundOrNewDT(encryptionSecrets);
3190+
return delegationTokens.get().getBoundOrNewDT(encryptionSecrets,
3191+
(renewer != null ? new Text(renewer) : new Text()));
31903192
} else {
31913193
// Delegation token support is not set up
31923194
LOG.debug("Token support is not enabled");

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,17 @@ public S3ADelegationTokens.TokenIssuingPolicy getTokenIssuingPolicy() {
129129
* filesystem has been deployed unbonded.
130130
* @param policy minimum policy to use, if known.
131131
* @param encryptionSecrets encryption secrets for the token.
132+
* @param renewer the principal permitted to renew the token.
132133
* @return the token or null if the back end does not want to issue one.
133134
* @throws IOException if one cannot be created
134135
*/
135136
public Token<AbstractS3ATokenIdentifier> createDelegationToken(
136137
final Optional<RoleModel.Policy> policy,
137-
final EncryptionSecrets encryptionSecrets) throws IOException {
138+
final EncryptionSecrets encryptionSecrets,
139+
final Text renewer) throws IOException {
138140
requireServiceStarted();
139141
final AbstractS3ATokenIdentifier tokenIdentifier =
140-
createTokenIdentifier(policy, encryptionSecrets);
142+
createTokenIdentifier(policy, encryptionSecrets, renewer);
141143
if (tokenIdentifier != null) {
142144
Token<AbstractS3ATokenIdentifier> token =
143145
new Token<>(tokenIdentifier, secretManager);
@@ -157,17 +159,19 @@ public Token<AbstractS3ATokenIdentifier> createDelegationToken(
157159
* This will only be called if a new DT is needed, that is: the
158160
* filesystem has been deployed unbonded.
159161
*
160-
* If {@link #createDelegationToken(Optional, EncryptionSecrets)}
162+
* If {@link #createDelegationToken(Optional, EncryptionSecrets, Text)}
161163
* is overridden, this method can be replaced with a stub.
162164
*
163165
* @param policy minimum policy to use, if known.
164166
* @param encryptionSecrets encryption secrets for the token.
167+
* @param renewer the principal permitted to renew the token.
165168
* @return the token data to include in the token identifier.
166169
* @throws IOException failure creating the token data.
167170
*/
168171
public abstract AbstractS3ATokenIdentifier createTokenIdentifier(
169172
Optional<RoleModel.Policy> policy,
170-
EncryptionSecrets encryptionSecrets) throws IOException;
173+
EncryptionSecrets encryptionSecrets,
174+
Text renewer) throws IOException;
171175

172176
/**
173177
* Verify that a token identifier is of a specific class.

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,23 @@ public abstract class AbstractS3ATokenIdentifier
103103
* Constructor.
104104
* @param kind token kind.
105105
* @param uri filesystem URI.
106-
* @param owner token owner
106+
* @param owner token owner.
107+
* @param renewer token renewer.
107108
* @param origin origin text for diagnostics.
108109
* @param encryptionSecrets encryption secrets to set.
109110
*/
110111
protected AbstractS3ATokenIdentifier(
111112
final Text kind,
112113
final URI uri,
113114
final Text owner,
115+
final Text renewer,
114116
final String origin,
115117
final EncryptionSecrets encryptionSecrets) {
116-
this(kind, owner, new Text(), new Text(), uri);
118+
this(kind,
119+
owner,
120+
(renewer != null ? renewer : new Text()),
121+
new Text(),
122+
uri);
117123
this.origin = requireNonNull(origin);
118124
this.encryptionSecrets = requireNonNull(encryptionSecrets);
119125
}
@@ -237,6 +243,7 @@ public String toString() {
237243
sb.append(getKind());
238244
sb.append("; uri=").append(uri);
239245
sb.append("; timestamp=").append(created);
246+
sb.append("; renewer=").append(getRenewer());
240247
sb.append("; encryption=").append(encryptionSecrets.toString());
241248
sb.append("; ").append(uuid);
242249
sb.append("; ").append(origin);

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.apache.hadoop.fs.s3a.auth.MarshalledCredentials;
3131
import org.apache.hadoop.fs.s3a.auth.RoleModel;
3232
import org.apache.hadoop.fs.s3native.S3xLoginHelper;
33+
import org.apache.hadoop.io.Text;
3334

3435
import static org.apache.hadoop.fs.s3a.auth.delegation.DelegationConstants.FULL_TOKEN_KIND;
3536

@@ -61,7 +62,7 @@ public class FullCredentialsTokenBinding extends
6162
private String credentialOrigin;
6263

6364
/**
64-
* Constructor, uses name of {@link #name} and token kind of
65+
* Constructor, uses name of {@link #NAME} and token kind of
6566
* {@link DelegationConstants#FULL_TOKEN_KIND}.
6667
*
6768
*/
@@ -138,11 +139,13 @@ public AWSCredentialProviderList deployUnbonded() throws IOException {
138139
@Override
139140
public AbstractS3ATokenIdentifier createTokenIdentifier(
140141
final Optional<RoleModel.Policy> policy,
141-
final EncryptionSecrets encryptionSecrets) throws IOException {
142+
final EncryptionSecrets encryptionSecrets,
143+
final Text renewer) throws IOException {
142144
requireServiceStarted();
143145

144146
return new FullCredentialsTokenIdentifier(getCanonicalUri(),
145147
getOwnerText(),
148+
renewer,
146149
awsCredentials,
147150
encryptionSecrets,
148151
credentialOrigin);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@ public FullCredentialsTokenIdentifier() {
3737

3838
public FullCredentialsTokenIdentifier(final URI uri,
3939
final Text owner,
40+
final Text renewer,
4041
final MarshalledCredentials marshalledCredentials,
4142
final EncryptionSecrets encryptionSecrets,
4243
String origin) {
4344
super(DelegationConstants.FULL_TOKEN_KIND,
4445
owner,
46+
renewer,
4547
uri,
4648
marshalledCredentials,
4749
encryptionSecrets,

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.apache.hadoop.fs.s3a.auth.MarshalledCredentials;
3737
import org.apache.hadoop.fs.s3a.auth.RoleModel;
3838
import org.apache.hadoop.fs.s3a.auth.STSClientFactory;
39+
import org.apache.hadoop.io.Text;
3940

4041
import static org.apache.hadoop.fs.s3a.auth.MarshalledCredentialBinding.fromSTSCredentials;
4142
import static org.apache.hadoop.fs.s3a.auth.delegation.DelegationConstants.DELEGATION_TOKEN_CREDENTIALS_PROVIDER;
@@ -75,7 +76,7 @@ public class RoleTokenBinding extends SessionTokenBinding {
7576

7677
/**
7778
* Constructor.
78-
* Name is {@link #name}; token kind is
79+
* Name is {@link #NAME}; token kind is
7980
* {@link DelegationConstants#ROLE_TOKEN_KIND}.
8081
*/
8182
public RoleTokenBinding() {
@@ -129,7 +130,8 @@ COMPONENT, getFileSystem().getUri(),
129130
@Retries.RetryTranslated
130131
public RoleTokenIdentifier createTokenIdentifier(
131132
final Optional<RoleModel.Policy> policy,
132-
final EncryptionSecrets encryptionSecrets) throws IOException {
133+
final EncryptionSecrets encryptionSecrets,
134+
final Text renewer) throws IOException {
133135
requireServiceStarted();
134136
Preconditions.checkState(!roleArn.isEmpty(), E_NO_ARN);
135137
String policyJson = policy.isPresent() ?
@@ -152,6 +154,7 @@ public RoleTokenIdentifier createTokenIdentifier(
152154
return new RoleTokenIdentifier(
153155
getCanonicalUri(),
154156
getOwnerText(),
157+
renewer,
155158
fromSTSCredentials(credentials),
156159
encryptionSecrets,
157160
AbstractS3ATokenIdentifier.createDefaultOriginMessage()

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ public RoleTokenIdentifier() {
3535

3636
public RoleTokenIdentifier(final URI uri,
3737
final Text owner,
38+
final Text renewer,
3839
final MarshalledCredentials marshalledCredentials,
3940
final EncryptionSecrets encryptionSecrets,
4041
final String origin) {
4142
super(DelegationConstants.ROLE_TOKEN_KIND,
4243
owner,
44+
renewer,
4345
uri,
4446
marshalledCredentials,
4547
encryptionSecrets,

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ public Optional<Token<AbstractS3ATokenIdentifier>> getBoundDT() {
352352

353353
/**
354354
* Predicate: will this binding issue a DT if requested
355-
* in a call to {@link #getBoundOrNewDT(EncryptionSecrets)}?
355+
* in a call to {@link #getBoundOrNewDT(EncryptionSecrets, Text)}?
356356
* That is: should the filesystem declare that it is issuing
357357
* delegation tokens?
358358
* @return a declaration of what will happen when asked for a token.
@@ -368,10 +368,12 @@ public TokenIssuingPolicy getTokenIssuingPolicy() {
368368
* @return a delegation token.
369369
* @throws IOException if one cannot be created
370370
* @param encryptionSecrets encryption secrets for any new token.
371+
* @param renewer the token renewer.
371372
*/
372373
@SuppressWarnings("OptionalGetWithoutIsPresent")
373374
public Token<AbstractS3ATokenIdentifier> getBoundOrNewDT(
374-
final EncryptionSecrets encryptionSecrets)
375+
final EncryptionSecrets encryptionSecrets,
376+
final Text renewer)
375377
throws IOException {
376378
LOG.debug("Delegation token requested");
377379
if (isBoundToDT()) {
@@ -382,13 +384,13 @@ public Token<AbstractS3ATokenIdentifier> getBoundOrNewDT(
382384
// not bound to a token, so create a new one.
383385
// issued DTs are not cached so that long-lived filesystems can
384386
// reliably issue session/role tokens.
385-
return createDelegationToken(encryptionSecrets);
387+
return createDelegationToken(encryptionSecrets, renewer);
386388
}
387389
}
388390

389391
/**
390392
* How many delegation tokens have been issued?
391-
* @return the number times {@link #createDelegationToken(EncryptionSecrets)}
393+
* @return the number times {@link #createDelegationToken(EncryptionSecrets, Text)}
392394
* returned a token.
393395
*/
394396
public int getCreationCount() {
@@ -400,12 +402,14 @@ public int getCreationCount() {
400402
* This will only be called if a new DT is needed, that is: the
401403
* filesystem has been deployed unbonded.
402404
* @param encryptionSecrets encryption secrets for the token.
405+
* @param renewer the token renewer
403406
* @return the token
404407
* @throws IOException if one cannot be created
405408
*/
406409
@VisibleForTesting
407410
public Token<AbstractS3ATokenIdentifier> createDelegationToken(
408-
final EncryptionSecrets encryptionSecrets) throws IOException {
411+
final EncryptionSecrets encryptionSecrets,
412+
final Text renewer) throws IOException {
409413
requireServiceStarted();
410414
checkArgument(encryptionSecrets != null,
411415
"Null encryption secrets");
@@ -420,7 +424,7 @@ public Token<AbstractS3ATokenIdentifier> createDelegationToken(
420424
try(DurationInfo ignored = new DurationInfo(LOG, DURATION_LOG_AT_INFO,
421425
"Creating New Delegation Token", tokenBinding.getKind())) {
422426
Token<AbstractS3ATokenIdentifier> token
423-
= tokenBinding.createDelegationToken(rolePolicy, encryptionSecrets);
427+
= tokenBinding.createDelegationToken(rolePolicy, encryptionSecrets, renewer);
424428
if (token != null) {
425429
token.setService(service);
426430
noteTokenCreated(token);

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,8 @@ public long getDuration() {
353353
@Retries.RetryTranslated
354354
public SessionTokenIdentifier createTokenIdentifier(
355355
final Optional<RoleModel.Policy> policy,
356-
final EncryptionSecrets encryptionSecrets) throws IOException {
356+
final EncryptionSecrets encryptionSecrets,
357+
final Text renewer) throws IOException {
357358
requireServiceStarted();
358359

359360
final MarshalledCredentials marshalledCredentials;
@@ -384,11 +385,12 @@ public SessionTokenIdentifier createTokenIdentifier(
384385
}
385386
}
386387
return new SessionTokenIdentifier(getKind(),
387-
getOwnerText(),
388-
getCanonicalUri(),
389-
marshalledCredentials,
390-
encryptionSecrets,
391-
origin);
388+
getOwnerText(),
389+
renewer,
390+
getCanonicalUri(),
391+
marshalledCredentials,
392+
encryptionSecrets,
393+
origin);
392394
}
393395

394396
@Override

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ protected SessionTokenIdentifier(final Text kind) {
7373
/**
7474
* Constructor.
7575
* @param kind token kind.
76-
* @param owner token owner
76+
* @param owner token owner.
77+
* @param renewer token renewer.
7778
* @param uri filesystem URI.
7879
* @param marshalledCredentials credentials to marshall
7980
* @param encryptionSecrets encryption secrets
@@ -82,11 +83,12 @@ protected SessionTokenIdentifier(final Text kind) {
8283
public SessionTokenIdentifier(
8384
final Text kind,
8485
final Text owner,
86+
final Text renewer,
8587
final URI uri,
8688
final MarshalledCredentials marshalledCredentials,
8789
final EncryptionSecrets encryptionSecrets,
8890
final String origin) {
89-
super(kind, uri, owner, origin, encryptionSecrets);
91+
super(kind, uri, owner, renewer, origin, encryptionSecrets);
9092
this.marshalledCredentials = marshalledCredentials;
9193
}
9294

0 commit comments

Comments
 (0)