Class SecretsTool

java.lang.Object
com.iizix.server.secrets.SecretsTool

public final class SecretsTool extends Object
The command-line tool of the secrets store of a machine (SECRETS-STORE-DESIGN.md section 10, build order SK-4, decision P-16 (a)): what an operator of a production server and a build script use to fill, read and check the store that SecretsStore keeps. It runs the same store class as the server, through SecretsLifecycle.openServerStore(Path, PropFactory, long, boolean), so the file it writes is the file the server reads.

The store file is --store <file> when given, else the system property "iizi.secrets.file", else <user.home>/.iizi-secrets/iizi-secrets.xml (SecretsStore.defaultFile()).

Commands.

  • set <key> [--kind string|password|pkcs12] [--dbconf <directory>] - stores a value read from standard input, never from the command line: piped, with one trailing line ending removed for a text kind, or typed twice without echo when standard input is a terminal. The prompt says what the key is for (describeKey(String, String)): for a dbconf.<name>/password key the database role and the URL of the dbconf.properties in the directory --dbconf names, which must name the key as its passwordSecret (MDV-D-30: the MLS rehearsal's operator was asked for a "Value of dbconf.mls/password" and could not tell which password that was). A new key needs --kind; an existing one keeps its kind unless --kind names another. Written at once, owner-only and atomically, by the store.
  • get <key> [--tty] - writes the value to standard output, exactly its UTF-8 bytes (the bytes of a PKCS#12), the only command that ever prints a value; refused when standard output is a terminal unless --tty is given.
  • remove <key> (or rm) - removes a key.
  • list [<context>...] - the keys, one per line, never a value.
  • export <file> [<context>...] - writes the entries, or those of the contexts, to a new owner-only store file.
  • import <file> [<context>...] - merges the entries of another store file, or those of the contexts, into the store in one write; an imported key replaces the store's.
  • check <file> [--context <context>] - loads a configuration file and lists, one per line, the keys of its secret-marked members that the store lacks (through the contexts of CC-SECRETS-SK3-CONTEXTS); --context gives the context a .iiziPush file takes from its application at run time.

Standard output carries data only: the value of get, the keys of list, the missing keys of check. Everything else - confirmations, errors and the WARNING and SEVERE lines of the logger, which a plain JVM would print on standard output - goes to standard error. No value is ever written to standard error, a log line or an exception text, and none is read from the command line, so none can appear in a process list or a shell history.

Exit codes: 0 done; 1 a usage error; 2 the store or a file could not be opened, read or written; 3 a key that is not there (get, remove), or a check that found a missing key, a kind mismatch or a member without a context; 4 a value refused to a terminal.

Launched by iiziServer/bin/iizi-secrets.bat and iizi-secrets.sh, and by Get-IiziSecret of BuildUtil/mindus.psm1.

Author:
Christopher Mindus
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The exit code of a store or file that could not be opened, read or written: 2.
    static final int
    The exit code of a key that is not there, or of a check that found a problem: 3.
    static final int
    The exit code of a command that was done: 0.
    static final int
    The exit code of a value refused to a terminal: 4.
    static final int
    The exit code of a usage error: 1.
  • Constructor Summary

    Constructors
    Constructor
    Description
    SecretsTool(PropFactory factory, Path defaultStore, InputStream in, OutputStream out, PrintStream err, boolean stdinTerminal, boolean stdoutTerminal)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    main(String[] args)
    Runs the tool in its own process and exits with its exit code.
    int
    run(String... args)
    Runs one command.
  • Field Details

    • EXIT_OK

      public static final int EXIT_OK
      The exit code of a command that was done: 0.
      See Also:
    • EXIT_USAGE

      public static final int EXIT_USAGE
      The exit code of a usage error: 1.
      See Also:
    • EXIT_FAILED

      public static final int EXIT_FAILED
      The exit code of a store or file that could not be opened, read or written: 2.
      See Also:
    • EXIT_MISSING

      public static final int EXIT_MISSING
      The exit code of a key that is not there, or of a check that found a problem: 3.
      See Also:
    • EXIT_REFUSED

      public static final int EXIT_REFUSED
      The exit code of a value refused to a terminal: 4.
      See Also:
  • Constructor Details

    • SecretsTool

      public SecretsTool(PropFactory factory, Path defaultStore, InputStream in, OutputStream out, PrintStream err, boolean stdinTerminal, boolean stdoutTerminal)
      Constructor. main(String[]) builds one over the process's own streams; a test or another program may give its own.
      Parameters:
      factory - The SERVER property factory, its definitions loaded.
      defaultStore - The store file when --store is not given, normally SecretsStore.defaultFile().
      in - Standard input.
      out - Standard output, for data only.
      err - Standard error.
      stdinTerminal - true when standard input is a terminal: set then reads the value from the console without echo.
      stdoutTerminal - true when standard output is a terminal: get then refuses without --tty.
  • Method Details

    • main

      public static void main(String[] args)
      Runs the tool in its own process and exits with its exit code. Standard output and standard error are taken from the file descriptors before the logger replaces System.out and System.err; the logger's WARNING and SEVERE lines go to standard error, nothing below.
      Parameters:
      args - The command line.
    • run

      public int run(String... args)
      Runs one command. The store is opened for the command and disposed of afterwards.
      Parameters:
      args - The command line.
      Returns:
      The exit code.