You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by pepov <gi...@git.apache.org> on 2018/05/29 07:38:51 UTC

[GitHub] nifi pull request #2746: NIFI-5247 NiFi toolkit signal handling changes, Doc...

GitHub user pepov opened a pull request:

    https://github.com/apache/nifi/pull/2746

    NIFI-5247 NiFi toolkit signal handling changes, Dockerfile enhancements

    nifi-toolkit bash entry points should leverage exec to replace bash with the current java process in order to handle signals properly in docker. Also add bash, openssl, jq to make certificate request operations easier
    
    Thank you for submitting a contribution to Apache NiFi.
    
    In order to streamline the review of the contribution we ask you
    to ensure the following steps have been taken:
    
    ### For all changes:
    - [x] Is there a JIRA ticket associated with this PR? Is it referenced 
         in the commit message?
    
    - [x] Does your PR title start with NIFI-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
    
    - [x] Has your PR been rebased against the latest commit within the target branch (typically master)?
    
    - [x] Is your initial contribution a single, squashed commit?
    
    ### For code changes:
    - [ ] Have you ensured that the full suite of tests is executed via mvn -Pcontrib-check clean install at the root nifi folder?
    - [ ] Have you written or updated unit tests to verify your changes?
    - [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)? 
    - [ ] If applicable, have you updated the LICENSE file, including the main LICENSE file under nifi-assembly?
    - [ ] If applicable, have you updated the NOTICE file, including the main NOTICE file found under nifi-assembly?
    - [ ] If adding new Properties, have you added .displayName in addition to .name (programmatic access) for each of the new properties?
    
    ### For documentation related changes:
    - [ ] Have you ensured that format looks appropriate for the output in which it is rendered?
    
    ### Note:
    Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/pepov/nifi NIFI-5247

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/nifi/pull/2746.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #2746
    
----
commit f20b05b8560426ee3c195d2480379771cee066f3
Author: pepov <pe...@...>
Date:   2018-05-24T14:15:55Z

    NIFI-5247 nifi-toolkit bash entry points should leverage exec to replace bash with the current java process in order to handle signals properly in docker. Also add bash, openssl, jq to make certificate request operations easier

----


---

[GitHub] nifi issue #2746: NIFI-5247 NiFi toolkit signal handling changes, Dockerfile...

Posted by pepov <gi...@git.apache.org>.
Github user pepov commented on the issue:

    https://github.com/apache/nifi/pull/2746
  
    added test files to rat exclude, also rebased and squashed commits


---

[GitHub] nifi pull request #2746: NIFI-5247 NiFi toolkit signal handling changes, Doc...

Posted by jtstorck <gi...@git.apache.org>.
Github user jtstorck commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/2746#discussion_r192240688
  
    --- Diff: nifi-toolkit/nifi-toolkit-assembly/docker/tests/tls-toolkit.sh ---
    @@ -0,0 +1,17 @@
    +#!/bin/bash
    --- End diff --
    
    This file needs to be added to the excludes for the apache-rat-plugin in nifi-toolkit-assembly.


---

[GitHub] nifi issue #2746: NIFI-5247 NiFi toolkit signal handling changes, Dockerfile...

Posted by pepov <gi...@git.apache.org>.
Github user pepov commented on the issue:

    https://github.com/apache/nifi/pull/2746
  
    Added some integration tests, to cover exit codes and some basic tls toolkit functionality through docker


---

[GitHub] nifi pull request #2746: NIFI-5247 NiFi toolkit signal handling changes, Doc...

Posted by pepov <gi...@git.apache.org>.
Github user pepov commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/2746#discussion_r191668440
  
    --- Diff: nifi-toolkit/nifi-toolkit-assembly/src/main/resources/bin/cli.sh ---
    @@ -111,8 +111,7 @@ run() {
        export NIFI_TOOLKIT_HOME="$NIFI_TOOLKIT_HOME"
     
        umask 0077
    -   "${JAVA}" -cp "${CLASSPATH}" ${JAVA_OPTS:--Xms128m -Xmx256m} org.apache.nifi.toolkit.cli.CLIMain "$@"
    -   return $?
    +   exec "${JAVA}" -cp "${CLASSPATH}" ${JAVA_OPTS:--Xms128m -Xmx256m} org.apache.nifi.toolkit.cli.CLIMain "$@"
    --- End diff --
    
    exec is typically used for redirecting file descriptors for the current shell, the redirection errors should refer to that. Otherwise the return code of the program is not modified, since exec gets out of the way as soon as the program is started so that the return code is not manipulated in any way.
    
    ```sh
    # start a container 
    docker run --rm -ti debian bash
    
    # setup a file to exit with the input argument
    cat <<EOF > test.sh
    #!/bin/bash
    
    exit \$1
    EOF
    chmod +x test.sh
    
    # observe that exit codes are preserved
    for i in 0 1 2 3; do sh -c "exec ./test.sh $i"; echo $?; done
    ```


---

[GitHub] nifi pull request #2746: NIFI-5247 NiFi toolkit signal handling changes, Doc...

Posted by pepov <gi...@git.apache.org>.
Github user pepov commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/2746#discussion_r191681207
  
    --- Diff: nifi-toolkit/nifi-toolkit-assembly/src/main/resources/bin/cli.sh ---
    @@ -111,8 +111,7 @@ run() {
        export NIFI_TOOLKIT_HOME="$NIFI_TOOLKIT_HOME"
     
        umask 0077
    -   "${JAVA}" -cp "${CLASSPATH}" ${JAVA_OPTS:--Xms128m -Xmx256m} org.apache.nifi.toolkit.cli.CLIMain "$@"
    -   return $?
    +   exec "${JAVA}" -cp "${CLASSPATH}" ${JAVA_OPTS:--Xms128m -Xmx256m} org.apache.nifi.toolkit.cli.CLIMain "$@"
    --- End diff --
    
    I've also ran `mvn package -P docker` in the nifi-toolkit/nifi-toolkit-assembly folder and ran the following return code tests using the newly built dockerfile:
    
    Command not specified:
    ```
    docker run --rm apache/nifi-toolkit:1.7.0-SNAPSHOT tls-toolkit; echo $?
    Expected at least a service argument.
    
    Usage: tls-toolkit service [-h] [args]
    
    Services:
       standalone: Creates certificates and config files for nifi cluster.
       server: Acts as a Certificate Authority that can be used by clients to get Certificates
       client: Generates a private key and gets it signed by the certificate authority.
       status: Checks the status of an HTTPS endpoint by making a GET request using a supplied keystore and truststore.
    
    2
    ```
    
    Argument error:
    ```
    docker run --rm apache/nifi-toolkit:1.7.0-SNAPSHOT tls-toolkit client; echo $?
    token argument must not be empty unless useConfigJson or configJsonIn set
    
    usage: org.apache.nifi.toolkit.tls.TlsToolkitMain [-a <arg>] [-c <arg>] [-C <arg>] [--configJsonIn <arg>] [-D <arg>] [-f <arg>] [-F] [-g] [-h] [-k <arg>] [-p
           <arg>] [--subjectAlternativeNames <arg>] [-T <arg>] [-t <arg>]
    
    Generates a private key and gets it signed by the certificate authority.
    
     -a,--keyAlgorithm <arg>                   Algorithm to use for generated keys. (default: RSA)
     -c,--certificateAuthorityHostname <arg>   Hostname of NiFi Certificate Authority (default: localhost)
     -C,--certificateDirectory <arg>           The file to write the CA certificate to (default: .)
        --configJsonIn <arg>                   The place to read configuration info from (defaults to the value of configJson), implies useConfigJson if set.
                                               (default: configJson value)
     -D,--dn <arg>                             The dn to use for the client certificate (default: CN=0d2f3cfed775,OU=NIFI)
     -f,--configJson <arg>                     The place to write configuration info (default: config.json)
     -F,--useConfigJson                        Flag specifying that all configuration is read from configJson to facilitate automated use (otherwise configJson will
                                               only be written to.
     -g,--differentKeyAndKeystorePasswords     Use different generated password for the key and the keyStore.
     -h,--help                                 Print help and exit.
     -k,--keySize <arg>                        Number of bits for generated keys. (default: 2048)
     -p,--PORT <arg>                           The port to use to communicate with the Certificate Authority (default: 8443)
        --subjectAlternativeNames <arg>        Comma-separated list of domains to use as Subject Alternative Names in the certificate
     -T,--keyStoreType <arg>                   The type of keyStores to generate. (default: jks)
     -t,--token <arg>                          The token to use to prevent MITM (required and must be same as one used by CA)
    
    Java home: /usr/lib/jvm/java-1.8-openjdk/jre
    NiFi Toolkit home: /opt/nifi-toolkit/nifi-toolkit-1.7.0-SNAPSHOT
    8
    ```
    
    Service error:
    ```
    docker run --rm apache/nifi-toolkit:1.7.0-SNAPSHOT tls-toolkit client -t $(uuidgen); echo $?
    2018/05/30 08:23:44 INFO [main] org.apache.nifi.toolkit.tls.service.client.TlsCertificateAuthorityClient: Requesting new certificate from localhost:8443
    2018/05/30 08:23:45 INFO [main] org.apache.nifi.toolkit.tls.service.client.TlsCertificateSigningRequestPerformer: Requesting certificate with dn CN=24e8d8c4c0da,OU=NIFI from localhost:8443
    Service client error: Connect to localhost:8443 [localhost/127.0.0.1] failed: Connection refused (Connection refused)
    
    Usage: tls-toolkit service [-h] [args]
    
    Services:
       standalone: Creates certificates and config files for nifi cluster.
       server: Acts as a Certificate Authority that can be used by clients to get Certificates
       client: Generates a private key and gets it signed by the certificate authority.
       status: Checks the status of an HTTPS endpoint by making a GET request using a supplied keystore and truststore.
    
    3
    ```


---

[GitHub] nifi pull request #2746: NIFI-5247 NiFi toolkit signal handling changes, Doc...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/nifi/pull/2746


---

[GitHub] nifi issue #2746: NIFI-5247 NiFi toolkit signal handling changes, Dockerfile...

Posted by jtstorck <gi...@git.apache.org>.
Github user jtstorck commented on the issue:

    https://github.com/apache/nifi/pull/2746
  
    Contrib build passes, and was able to reproduce your example usages of invoking the toolkit and observing the exit codes.
    
    +1, merging to master.  Thanks for your contribution, @pepov!


---

[GitHub] nifi pull request #2746: NIFI-5247 NiFi toolkit signal handling changes, Doc...

Posted by bbende <gi...@git.apache.org>.
Github user bbende commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/2746#discussion_r191555681
  
    --- Diff: nifi-toolkit/nifi-toolkit-assembly/src/main/resources/bin/cli.sh ---
    @@ -111,8 +111,7 @@ run() {
        export NIFI_TOOLKIT_HOME="$NIFI_TOOLKIT_HOME"
     
        umask 0077
    -   "${JAVA}" -cp "${CLASSPATH}" ${JAVA_OPTS:--Xms128m -Xmx256m} org.apache.nifi.toolkit.cli.CLIMain "$@"
    -   return $?
    +   exec "${JAVA}" -cp "${CLASSPATH}" ${JAVA_OPTS:--Xms128m -Xmx256m} org.apache.nifi.toolkit.cli.CLIMain "$@"
    --- End diff --
    
    Does this have the same behavior in terms of the exit code that will be returned from calling cli.sh?
    
    I'm not familiar with exec, but it is import for the CLI that exit code from the Java process is returned from calling cli.sh. 
    
    The man page for exec says:
    "If there are no redirection errors, the return status is zero; otherwise the return status is non-zero."
    
    It is not clear to me if a redirection error is an error from the Java process, or an error replacing the current shell with the Java process.


---

[GitHub] nifi pull request #2746: NIFI-5247 NiFi toolkit signal handling changes, Doc...

Posted by jtstorck <gi...@git.apache.org>.
Github user jtstorck commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/2746#discussion_r192240524
  
    --- Diff: nifi-toolkit/nifi-toolkit-assembly/docker/tests/exit-codes.sh ---
    @@ -0,0 +1,35 @@
    +#!/bin/bash
    --- End diff --
    
    This file needs to be added to the excludes for the apache-rat-plugin in nifi-toolkit-assembly.


---