Class S3ADelegationTokens
java.lang.Object
org.apache.hadoop.service.AbstractService
org.apache.hadoop.fs.s3a.auth.delegation.AbstractDTService
org.apache.hadoop.fs.s3a.auth.delegation.S3ADelegationTokens
- All Implemented Interfaces:
Closeable,AutoCloseable,org.apache.hadoop.service.Service
Support for creating a DT from a filesystem.
Isolated from S3A for control and testability.
The S3A Delegation Tokens are special in that the tokens are not directly
used to authenticate with the AWS services.
Instead they can session/role credentials requested off AWS on demand.
The design is extensible in that different back-end bindings can be used
to switch to different session creation mechanisms, or indeed, to any
other authentication mechanism supported by an S3 service, provided it
ultimately accepts some form of AWS credentials for authentication through
the AWS SDK. That is, if someone wants to wire this up to Kerberos, or
OAuth2, this design should support them.
URIs processed must be the canonical URIs for the service.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumHow will tokens be issued on request?Nested classes/interfaces inherited from interface org.apache.hadoop.service.Service
org.apache.hadoop.service.Service.STATE -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final EnumSet<AWSPolicyProvider.AccessLevel>The access policies we want for operations.static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidbindToDelegationToken(org.apache.hadoop.security.token.Token<AbstractS3ATokenIdentifier> token) Bind to a delegation token retrieved for this filesystem.voidbindToFileSystem(URI uri, StoreContext context, DelegationOperations delegationOperations) Bind to the filesystem.org.apache.hadoop.security.token.Token<AbstractS3ATokenIdentifier>createDelegationToken(EncryptionSecrets encryptionSecrets, org.apache.hadoop.io.Text renewer) Create a delegation token for the user.extractIdentifier(org.apache.hadoop.security.token.Token<? extends AbstractS3ATokenIdentifier> token) From a token, get the session token identifier.org.apache.hadoop.security.token.DelegationTokenIssuer[]Get a null/possibly empty list of extra delegation token issuers.Optional<org.apache.hadoop.security.token.Token<AbstractS3ATokenIdentifier>>Get any bound DT.org.apache.hadoop.security.token.Token<AbstractS3ATokenIdentifier>getBoundOrNewDT(EncryptionSecrets encryptionSecrets, org.apache.hadoop.io.Text renewer) Get any bound DT or create a new one.The canonical name of the service.intHow many delegation tokens have been issued?Get the AWS credential provider.Get any decoded identifier from the bound DT; empty if not bound.Get the encryption secrets of the DT.org.apache.hadoop.io.TextGet the service identifier of the owning FS.Predicate: will this binding issue a DT if requested in a call togetBoundOrNewDT(EncryptionSecrets, Text)?org.apache.hadoop.io.TextGet the kind of the issued tokens.Return a string for use in building up the User-Agent field, so get into the S3 access logs.static booleanhasDelegationTokenBinding(org.apache.hadoop.conf.Configuration conf) Predicate: does this configuration enable delegation tokens?booleanPredicate: is there a bound DT?static org.apache.hadoop.security.token.Token<AbstractS3ATokenIdentifier>lookupS3ADelegationToken(org.apache.hadoop.security.Credentials credentials, URI uri) Look for any S3A token for the given FS service.static org.apache.hadoop.security.token.Token<AbstractS3ATokenIdentifier>lookupToken(org.apache.hadoop.security.Credentials credentials, org.apache.hadoop.io.Text service) Look up any token from the service; cast it to one of ours.static org.apache.hadoop.security.token.Token<AbstractS3ATokenIdentifier>lookupToken(org.apache.hadoop.security.Credentials credentials, org.apache.hadoop.io.Text service, org.apache.hadoop.io.Text kind) Look up a token from the credentials, verify it is of the correct kind.org.apache.hadoop.security.token.Token<AbstractS3ATokenIdentifier>Find a token for the FS user and canonical filesystem URI.protected voidserviceInit(org.apache.hadoop.conf.Configuration conf) Init the service.protected voidService startup includes binding to any delegation token, and deploying unbounded if there is none.protected voidStop the token binding.toString()Methods inherited from class org.apache.hadoop.fs.s3a.auth.delegation.AbstractDTService
getCanonicalUri, getOwner, getPolicyProvider, getStoreContext, requireServiceStarted, requireServiceStateMethods inherited from class org.apache.hadoop.service.AbstractService
close, getBlockers, getConfig, getFailureCause, getFailureState, getLifecycleHistory, getName, getServiceState, getStartTime, init, isInState, noteFailure, putBlocker, registerGlobalListener, registerServiceListener, removeBlocker, setConfig, start, stop, unregisterGlobalListener, unregisterServiceListener, waitForServiceToStop
-
Field Details
-
E_DELEGATION_TOKENS_DISABLED
- See Also:
-
ACCESS_POLICY
The access policies we want for operations. There's no attempt to ask for "admin" permissions here.
-
-
Constructor Details
-
S3ADelegationTokens
Instantiate.- Throws:
IOException- if login fails.
-
-
Method Details
-
bindToFileSystem
public void bindToFileSystem(URI uri, StoreContext context, DelegationOperations delegationOperations) throws IOException Description copied from class:AbstractDTServiceBind to the filesystem. Subclasses can use this to perform their own binding operations - but they must always call their superclass implementation. This Must be called before callinginit(). Important: This binding will happen during FileSystem.initialize(); the FS is not live for actual use and will not yet have interacted with AWS services.- Overrides:
bindToFileSystemin classAbstractDTService- Parameters:
uri- the canonical URI of the FS.context- store contextdelegationOperations- delegation operations- Throws:
IOException- failure.
-
serviceInit
Init the service. This identifies the token binding class to use and creates, initializes and starts it. Will raise an exception if delegation tokens are not enabled.- Overrides:
serviceInitin classAbstractDTService- Parameters:
conf- configuration- Throws:
Exception- any failure to start up
-
serviceStart
Service startup includes binding to any delegation token, and deploying unbounded if there is none. It is after this that token operations can be used.- Overrides:
serviceStartin classorg.apache.hadoop.service.AbstractService- Throws:
Exception- any failure
-
serviceStop
Stop the token binding.- Overrides:
serviceStopin classorg.apache.hadoop.service.AbstractService- Throws:
Exception- on any failure
-
bindToDelegationToken
@VisibleForTesting public void bindToDelegationToken(org.apache.hadoop.security.token.Token<AbstractS3ATokenIdentifier> token) throws IOException Bind to a delegation token retrieved for this filesystem. Extract the secrets from the token and set internal fields to the values.boundDTis set totoken.decodedIdentifieris set to the extracted identifier.bindingInfois set to the info returned by the token binding.
- Parameters:
token- token to decode and bind to.- Throws:
IOException- selection/extraction/validation failure.
-
isBoundToDT
public boolean isBoundToDT()Predicate: is there a bound DT?- Returns:
- true if there's a value in
boundDT.
-
getBoundDT
Get any bound DT.- Returns:
- a delegation token if this instance was bound to it.
-
getTokenIssuingPolicy
Predicate: will this binding issue a DT if requested in a call togetBoundOrNewDT(EncryptionSecrets, Text)? That is: should the filesystem declare that it is issuing delegation tokens?- Returns:
- a declaration of what will happen when asked for a token.
-
getBoundOrNewDT
public org.apache.hadoop.security.token.Token<AbstractS3ATokenIdentifier> getBoundOrNewDT(EncryptionSecrets encryptionSecrets, org.apache.hadoop.io.Text renewer) throws IOException Get any bound DT or create a new one.- Parameters:
encryptionSecrets- encryption secrets for any new token.renewer- the token renewer.- Returns:
- a delegation token.
- Throws:
IOException- if one cannot be created
-
getCreationCount
public int getCreationCount()How many delegation tokens have been issued?- Returns:
- the number times
createDelegationToken(EncryptionSecrets, Text)returned a token.
-
createDelegationToken
@VisibleForTesting public org.apache.hadoop.security.token.Token<AbstractS3ATokenIdentifier> createDelegationToken(EncryptionSecrets encryptionSecrets, org.apache.hadoop.io.Text renewer) throws IOException Create a delegation token for the user. This will only be called if a new DT is needed, that is: the filesystem has been deployed unbonded.- Parameters:
encryptionSecrets- encryption secrets for the token.renewer- the token renewer- Returns:
- the token
- Throws:
IOException- if one cannot be created
-
getAdditionalTokenIssuers
public org.apache.hadoop.security.token.DelegationTokenIssuer[] getAdditionalTokenIssuers() throws IOExceptionGet a null/possibly empty list of extra delegation token issuers. These will be asked for tokens whenDelegationTokenIssuer.getAdditionalTokenIssuers()recursively collects all DTs a filesystem can offer.- Returns:
- a null or empty array. Default implementation: null
- Throws:
IOException- failure
-
getCredentialProviders
Get the AWS credential provider.- Returns:
- the DT credential provider
- Throws:
IOException- failure to parse the DTIllegalStateException- if this instance is not bound to a DT
-
getEncryptionSecrets
Get the encryption secrets of the DT. non-empty iff service is started and was bound to a DT.- Returns:
- any encryption settings propagated with the DT.
-
getDecodedIdentifier
Get any decoded identifier from the bound DT; empty if not bound.- Returns:
- the decoded identifier.
-
getService
public org.apache.hadoop.io.Text getService()Get the service identifier of the owning FS.- Returns:
- a service identifier to use when registering tokens
-
getCanonicalServiceName
The canonical name of the service. This can be used as the canonical service name for the FS.- Returns:
- the canonicalized FS URI.
-
selectTokenFromFSOwner
@VisibleForTesting public org.apache.hadoop.security.token.Token<AbstractS3ATokenIdentifier> selectTokenFromFSOwner() throws IOExceptionFind a token for the FS user and canonical filesystem URI.- Returns:
- the token, or null if one cannot be found.
- Throws:
IOException- on a failure to unmarshall the token.
-
toString
- Overrides:
toStringin classorg.apache.hadoop.service.AbstractService
-
getTokenKind
public org.apache.hadoop.io.Text getTokenKind()Get the kind of the issued tokens.- Returns:
- token kind.
-
extractIdentifier
public AbstractS3ATokenIdentifier extractIdentifier(org.apache.hadoop.security.token.Token<? extends AbstractS3ATokenIdentifier> token) throws IOException From a token, get the session token identifier.- Parameters:
token- token to process- Returns:
- the session token identifier
- Throws:
IOException- failure to validate/read data encoded in identifier.IllegalArgumentException- if the token isn't an S3A session token
-
getUserAgentField
Return a string for use in building up the User-Agent field, so get into the S3 access logs. Useful for diagnostics. Delegates to {AbstractDelegationTokenBinding.getUserAgentField()} for the current binding.- Returns:
- a string for the S3 logs or "" for "nothing to add"
-
lookupToken
@VisibleForTesting public static org.apache.hadoop.security.token.Token<AbstractS3ATokenIdentifier> lookupToken(org.apache.hadoop.security.Credentials credentials, org.apache.hadoop.io.Text service, org.apache.hadoop.io.Text kind) throws DelegationTokenIOException Look up a token from the credentials, verify it is of the correct kind.- Parameters:
credentials- credentials to look up.service- service namekind- token kind to look for- Returns:
- the token or null if no suitable token was found
- Throws:
DelegationTokenIOException- wrong token kind found
-
lookupToken
public static org.apache.hadoop.security.token.Token<AbstractS3ATokenIdentifier> lookupToken(org.apache.hadoop.security.Credentials credentials, org.apache.hadoop.io.Text service) Look up any token from the service; cast it to one of ours.- Parameters:
credentials- credentialsservice- service to look up- Returns:
- any token found or null if none was
- Throws:
ClassCastException- if the token is of a wrong type.
-
lookupS3ADelegationToken
public static org.apache.hadoop.security.token.Token<AbstractS3ATokenIdentifier> lookupS3ADelegationToken(org.apache.hadoop.security.Credentials credentials, URI uri) Look for any S3A token for the given FS service.- Parameters:
credentials- credentials to scan.uri- the URI of the FS to look for- Returns:
- the token or null if none was found
-
hasDelegationTokenBinding
public static boolean hasDelegationTokenBinding(org.apache.hadoop.conf.Configuration conf) Predicate: does this configuration enable delegation tokens? That is: is there any text in the optionDelegationConstants.DELEGATION_TOKEN_BINDING?- Parameters:
conf- configuration to examine- Returns:
- true iff the trimmed configuration option is not empty.
-