Class DelegationTokenSecretManager
java.lang.Object
org.apache.zookeeper.server.token.DelegationTokenSecretManager
Computes and validates delegation token credentials.
The token password is never stored: any ensemble member derives it as
HMAC-SHA256(masterKey, identifierBytes). The master key is either static —
shared by the whole ensemble via the file named by
zookeeper.tokenAuth.secretFile and referenced by tokens as key id
STATIC_KEY_ID — or, with zookeeper.tokenAuth.keyRotationEnabled,
generated by the leader, rolled every zookeeper.tokenAuth.keyRollIntervalMs
and replicated in the token store; tokens then reference the signing key by
its id in the identifier.
Validation here covers only the identifier lifetime (maxDate).
Revocation checks arrive with the token store.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longstatic final longstatic final longstatic final intLowest id ever assigned to a generated (rotated) key.static final intKey id reserved for the static master key from the secret file.static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final String -
Constructor Summary
ConstructorsConstructorDescriptionDelegationTokenSecretManager(byte[] masterKey) DelegationTokenSecretManager(byte[] masterKey, boolean keyRotationEnabled) -
Method Summary
Modifier and TypeMethodDescriptionbyte[]computePassword(byte[] identifierBytes) Derives the token password for the given serialized identifier using the static master key.static byte[]computePassword(byte[] keyBytes, byte[] identifierBytes) Derives the token password for the given serialized identifier using an explicit (rotated) key.static DelegationTokenSecretManagerCreates a manager from system properties, or returns null when token authentication is disabled.byte[]longlonglongbooleanstatic booleanReturns whether token authentication is enabled viazookeeper.tokenAuth.enabled.booleanlongnewKeyExpiry(long now) Expiry of a key created now: it must outlive the max date of every token it can sign, i.e.voidChecks that the token is still within its lifetime.
-
Field Details
-
TOKEN_AUTH_ENABLED
- See Also:
-
TOKEN_AUTH_SECRET_FILE
- See Also:
-
TOKEN_AUTH_RENEW_INTERVAL
- See Also:
-
TOKEN_AUTH_MAX_LIFETIME
- See Also:
-
TOKEN_AUTH_KEY_ROTATION_ENABLED
- See Also:
-
TOKEN_AUTH_KEY_ROLL_INTERVAL
- See Also:
-
DEFAULT_RENEW_INTERVAL_MS
public static final long DEFAULT_RENEW_INTERVAL_MS- See Also:
-
DEFAULT_MAX_LIFETIME_MS
public static final long DEFAULT_MAX_LIFETIME_MS- See Also:
-
DEFAULT_KEY_ROLL_INTERVAL_MS
public static final long DEFAULT_KEY_ROLL_INTERVAL_MS- See Also:
-
STATIC_KEY_ID
public static final int STATIC_KEY_IDKey id reserved for the static master key from the secret file.- See Also:
-
FIRST_GENERATED_KEY_ID
public static final int FIRST_GENERATED_KEY_IDLowest id ever assigned to a generated (rotated) key.- See Also:
-
-
Constructor Details
-
DelegationTokenSecretManager
public DelegationTokenSecretManager(byte[] masterKey) -
DelegationTokenSecretManager
public DelegationTokenSecretManager(byte[] masterKey, boolean keyRotationEnabled)
-
-
Method Details
-
getRenewIntervalMs
public long getRenewIntervalMs() -
getMaxLifetimeMs
public long getMaxLifetimeMs() -
isKeyRotationEnabled
public boolean isKeyRotationEnabled() -
getKeyRollIntervalMs
public long getKeyRollIntervalMs() -
hasStaticKey
public boolean hasStaticKey() -
generateKeyBytes
public byte[] generateKeyBytes() -
newKeyExpiry
public long newKeyExpiry(long now) Expiry of a key created now: it must outlive the max date of every token it can sign, i.e. tokens issued until the next roll. -
isEnabled
public static boolean isEnabled()Returns whether token authentication is enabled viazookeeper.tokenAuth.enabled. -
createIfEnabled
Creates a manager from system properties, or returns null when token authentication is disabled.- Throws:
IOException- if enabled but the secret file is missing or unusable, so a misconfigured server fails at startup instead of silently rejecting tokens
-
computePassword
public byte[] computePassword(byte[] identifierBytes) Derives the token password for the given serialized identifier using the static master key. -
computePassword
public static byte[] computePassword(byte[] keyBytes, byte[] identifierBytes) Derives the token password for the given serialized identifier using an explicit (rotated) key. -
validate
Checks that the token is still within its lifetime.- Throws:
SaslException- if the token has expired
-