Class SecretRegistry

java.lang.Object
com.xebialabs.xlrelease.osgi.api.tasks.SecretRegistry

public final class SecretRegistry extends Object
The plaintext secret values revealed during one execution, and the masking that uses them.

Host machinery, not part of the plugin-facing API. It lives in this package because both halves need it - Secret implementations register into it, and the host's output streams mask against it - and neither can see the other's package. A plugin has no reason to touch it.

Replaces walking a configuration's password descriptors up front to guess which values might be secret. That could only cover what the host thought to look at - a task's own properties and one hop of references - so a credential found deeper was never masked. The set is built the other way round instead: revealing a Secret adds the value it just decrypted, so anything an extension actually got hold of is masked, at whatever depth it came from.

Shared by reference, not snapshotted

Consumers must hold the registry itself rather than a copy of its contents. An extension typically reveals a secret and only then starts the work that produces output, and may reveal more while output is already streaming, so a snapshot taken when a stream was wired up would miss exactly the secrets that matter. The backing set is concurrent for the same reason: revealing happens on the worker thread while masking happens on whatever thread is pumping output.

Ambient during an execution

install(com.xebialabs.xlrelease.osgi.api.tasks.SecretRegistry) publishes a registry for the current thread so that revealing a secret anywhere beneath it - including inside record binding, which has no other way to reach the execution - is recorded. When nothing is installed, revealing still decrypts but registers nothing: that is the case for a connection test or a lookup, which have no task log to mask into.

Deliberately not inheritable. A thread an extension starts does not pick the registry up implicitly, so it cannot mask against another execution's secrets; code that needs to mask from another thread is given the registry object directly, which is what holding it by reference is for.

  • Constructor Details

    • SecretRegistry

      public SecretRegistry()
  • Method Details

    • register

      public void register(String plaintext)
      Records a revealed plaintext so every later write to the task log has it masked.
    • mask

      public String mask(String line)
      line with every revealed secret replaced by ********.

      Operates on a whole assembled line rather than a raw buffer fragment: a secret split across two writes matches neither half, so callers assemble lines first. Returns the input unchanged when nothing has been revealed, which is the common case.

    • isEmpty

      public boolean isEmpty()
      Whether anything has been revealed - lets a caller skip masking work entirely.
    • install

      public static SecretRegistry install(SecretRegistry registry)
      Installs registry for this thread, returning whatever was installed before so the caller can restore(com.xebialabs.xlrelease.osgi.api.tasks.SecretRegistry) it in a finally.
    • restore

      public static void restore(SecretRegistry previous)
      Puts back what install(com.xebialabs.xlrelease.osgi.api.tasks.SecretRegistry) returned, clearing the thread-local when that was null.