Class DelegationTokenSecretManager

java.lang.Object
org.apache.zookeeper.server.token.DelegationTokenSecretManager

public class DelegationTokenSecretManager extends Object
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 Details

  • 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 via zookeeper.tokenAuth.enabled.
    • createIfEnabled

      public static DelegationTokenSecretManager createIfEnabled() throws IOException
      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

      public void validate(DelegationTokenIdentifier ident) throws SaslException
      Checks that the token is still within its lifetime.
      Throws:
      SaslException - if the token has expired