Support Questions

Find answers, ask questions, and share your expertise

How to Generate Certs to secure 3 node nifi cluster and configs

avatar
Explorer

How to Generate Certs to secure 3 node nifi cluster and configs

 

All, I am new to nifi and started to secure nifi 

can some share how to generate certs using toolkit standalone

 

Do I need to generate certs on all nodes

 

node1.xyz.com

node2.xyz.com

node3.xyz.com

 

I understand initial admin identity but what is  

Node Identity for 3 nodes i have to update in authorizers.xml file 

 

 

2 ACCEPTED SOLUTIONS

avatar
Explorer

Hi @MattWho one last question 

 

since i have generated certs as per hostnames with proper cn & san..

to configure truststore, do i need to merge the truststore.jks generated for both the hosts or can i use one truststore for both hosts? 

 

sh /opt/nifi-toolkit-1.9.2/bin/tls-toolkit.sh standalone -B  mypasswd -C 'CN=nifiadmin, OU=NIFI' -n 'ip-10-175-12x-xx.abc.com,ip-10-175-12x-xxx.abc.com' --nifiDnPrefix 'CN=' --nifiDnSuffix ', OU=NIFI' -o /tmp/certs_divya/ -K mypasswd -P mypasswd -S mypasswd

 

-rw-------. 1 root root 3437 Feb 3 04:46 CN=nifiadmin_OU=NIFI.p12
-rw-------. 1 root root 29 Feb 3 04:46 CN=nifiadmin_OU=NIFI.password
drwx------. 2 root root 71 Feb 3 04:46 ip-10-175-12x-xxx.abc.com
drwx------. 2 root root 71 Feb 3 04:46 ip-10-175-12x-xxx.abc.com
-rw-------. 1 root root 1200 Feb 3 04:46 nifi-cert.pem
-rw-------. 1 root root 1675 Feb 3 04:46 nifi-key.key

View solution in original post

avatar
Master Mentor

@DivyaKaki 

 

Since all your certificates have been signed by the same CA, the truststore used by all nodes only needs to contain the public cert for that one CA. 

 

Thanks,

Matt

View solution in original post

22 REPLIES 22

avatar
Master Mentor

@DivyaKaki 

 

Once you configure NiFi to operate securely over https, TLS based authentication is required fro all NiFi node communications.  This requires that each node in your NiFi cluster has its own keystore.jks that meets the following criteria:

1. NiFi keystore can only contain ONE PrivateKeyEntry.
2. The keystore password must match the PriavteKeyEntry (Key password) or have no password on the key.
3. The PrivateKeyEntry can not use wildcards.
4. The PrivateKeyEntry must support both clientAuth and serverAuth ExtendedKeyUsage (EKU).
5. The PrivateKeyEntry must contain at least one Subject Alternative Name (SAN) that matches the hostname of the server on which the keystore is being used.

The NiFi truststore will contain one or more TrustedCertEntries.  These are public keys used to verify trust of any presented client certificate during a TLS handshake.  You typically build one truststore which you then install on every NiFi server.  With self signed certificates, the public cert for every one of those must exist as an TrustedCertEntry in the common truststore.  Any self-signed user certificate must exist as a trustedCertEntry in the truststore as well.  If your PrivateKeyEntry was signed (issuer) by some certificate authority, then the complete certificate trust chain for that signed certificate should exist as TrustedCertEntries in your truststore.

 

NiFi nodes will use mutual TLS handshake when communicating with one another.  This means a NiFi nodes will be the clients at times and as servers at other times in the TLS handshake which is why the need for clientAuth and serverAuth EKUs.

When it comes to user authentication in to NiFi, the default method is also TLS, thus requiring that you have a user certificate which can be trusted by the NiFi servers truststores.  NiFi can also be configured to support other methods for user authentication to include things like kerberos, LDAP, and OpenID connect.

Details on how to use the NiFi TLS toolkit can be found here:
https://nifi.apache.org/docs/nifi-docs/html/toolkit-guide.html#tls_toolkit

Keep in mind that if you use this in standalone mode to create a keystore and trusttore for each node in your NiFi cluster, you will need to merge all the truststores created in to one truststore you will use on all hosts.  Plus you will need to import your user certificate public cert as well in to this truststore, so your user can authenticate.

Hope this helps,

Matt

avatar
Explorer

Hi @MattWho thanks for providing details.

I have question on generating cert, 

Do I need to generate certs as localhost on each node  or  do I need to generate based on hostname .

I have installed nifi on cloud with primary and secondary ipaddress on 3 nodes

avatar
Master Mentor

@DivyaKaki 

 

The hostname must exist as a SAN entry in your certificate.  You may also choose to add your servers IP as a SAN entry, FQDN, internal hostname (multi-homed network), etc as SAN entries.  Each SAN entry would correspond with a unique way of addressing the server.  Localhost should not be used anywhere in a certificate (good security practice).  When you access your NiFi via a web browser you should be using one of those SAN entries in the URL.

As far as the Distinguished Name (DN) goes for your certificate, NiFi does not support wildcards.  The CN within your DN can be whatever you like.  For example:

CN=NiFiNode1, OU=Specialists, O=MyCompany, L=Baltimore, ST=Maryland, C=US

 

My cert would require following EKUs:

#5: ObjectId: 2.5.29.37 Criticality=false
ExtendedKeyUsages [
  serverAuth
  clientAuth


 I then would have SAN entries like following for example:

#8: ObjectId: 2.5.29.17 Criticality=false
SubjectAlternativeName [
  DNSName: nifi-node-01.com
  DNSName: nifi-node-01
  DNSName: nifi-node-internal-01

 

Hope this helps,

Matt

avatar
Explorer

Thanks, @MattWho for providing details.

i am little confused here on how to merge trust store on all nodes since I'm trying on standalone  mode . can you shared details, please 

 

 

 

 

avatar
Master Mentor

@DivyaKaki 


Sorry my responses were more genaralized requirements instead of the actual tls-toolkit command needed to accomplish this with the provided TLS toolkit.

 

When using "standalone" with NiFi TLS toolkit, all that means is that you are not using an already running  NiFi CA server.

To create certificates for all three of your nodes, your tsl-toolkit.sh standalone command would look something like the following:

 

./tls-toolkit.sh standalone -B <client cert password> -C 'CN=nifiadmin, OU=NIFI' -n 'node1.xyz.com,node2.xyz.com,node3.xyz.com' --nifiDnPrefix 'CN=' --nifiDnSuffix ', OU=NIFI' -o /tmp/certs/ -K <key password> -P <truststore password> -S <keystore password>

 

Above will create output in /tmp/certs directory (make sure directory exists before running above command).

 

What you end up with is the following:

1. A user certificate for nifiadmin which you can use in your browser by importing the p12 file to access your NiFi as the nifi-admin user (provided "CN=nifiadmin, OU=NIFI" was configured as your initial admin user). 

2. Three folders (one for each of your nodes) containing the keystore and truststore you need to use on each of those nodes.

Note: each node directory will contain a default nifi.properties file.  You should simply update your existing nifi.properties file on each node instead with the keystore and truststore required property values.

You Initial Admin Identity  gets configured with the authorizers.xml file.

Hope this helps,

Matt

avatar
Explorer

Hi @MattWho thanks for your help, really appreciate it. I'm kind of doing POC and thanks for helping me out 

 

here is where I stand currently: POC only

 

-> generated certs standalone, will reuse the syntax shared by you for standardaition 

sh tls-toolkit.sh standalone -n 'localhost(3)' -C 'CN=NifiAdmin, OU=ApacheNIfi' -o /opt/nifi-toolkit-1.9.2/certs/ssl

-> copied keystore, truststore to corresponding hosts

-> updated nifi.proprties on all hosts

-> updated authorizers on all hosts

<!-- <authorizer>
<identifier>file-provider</identifier>
<class>org.apache.nifi.authorization.FileAuthorizer</class>
<property name="Authorizations File">./conf/authorizations.xml</property>
<property name="Users File">./conf/users.xml</property>
<property name="Initial Admin Identity">CN=NifiAdmin, OU=ApacheNIfi</property>
<property name="Legacy Authorized Users File"></property>

<property name="Node Identity 1">CN=localhost, OU=NIFI</property>
</authorizer>

 

issue: while trying to access URL through cert, I'm getting an error 

 

Insufficient Permissions
  • home
No applicable policies could be found. Contact the system administrator.

 

-> users.xml or authorizations.xml is empty

-> i haven't merged the trust store as it generated by localhost 

Owner: CN=localhost, OU=NIFI
Issuer: CN=localhost, OU=NIFI

 

 

please help me what is missing here, why I'm seeing Insufficient Permissions, No applicable policies could be found. Contact the system administrator.

avatar
Explorer

@MattWho  for some reason I'm unable to execute the command below,

 

tls-toolkit.sh standalone -B password -C 'CN=nifiadmin, OU=NIFI' -n 'ldxxx001.xx.xx.com,ldxx002.xx.x.com’ --nifiDnPrefix 'CN=' --nifiDnSuffix ',OU=NIFI' -o /tmp/certs/ -K password -P password -S password

seems like  uncomplete

avatar
Master Mentor

@DivyaKaki 

 

Not really sure what to tell you about the command not working for you (maybe a copy paste issue with the single quotes?).   I ran the command locally just fine.

Never the less, you would not need to merge your truststore.jks files because every of your truststores already contains the same CA (localhost).

 

The response you are seeing in the UI indicates that your user authentication was successful; however, your authenticated user is not authorized to the requested resource (specifically /flow is needed to even see the NiFi UI canvas).

You will want to be looking at the output written to the nifi-user.log when you attempt to access the NiFi UI for details about user authentication and authorization.

Your users.xml and authorizations.xml files should not be empty.

NiFi's file-provider from the authorizers.xml file will only generate the users.xml and authorizations.xml files if they do NOT already exist at time of NiFi startup.  Try stopping your NiFi, removing these files from all three nodes, and then starting NiFi again.  Then inspect the new files to see if they are populated.

Hope this helps,

Matt

avatar
Explorer

Hi @MattWho 

thanks for the response 

I have stopped nifi on all nodes, removed user.xml & authorizations.xml on all nodes

started nifi back still the same message 

 

though I have configured below CN user as initial admin not sure why I am seeing this message, it should allow login using the cert right 

 

do I need to add any polices for the admin user initial admin 

 

<property name="Initial Admin Identity">CN=NifiAdmin, OU=ApacheNIfi</property>

 

2020-01-28 22:41:02,927 INFO [NiFi Web Server-38] o.a.n.w.s.NiFiAuthenticationFilter Attempting request for (CN=NifiAdmin, OU=ApacheNIfi) GET https://localhost:9696/nifi-api/flow/current-user (source ip: 10.175.124.142)

2020-01-28 22:41:02,927 INFO [NiFi Web Server-38] o.a.n.w.s.NiFiAuthenticationFilter Authentication success for CN=NifiAdmin, OU=ApacheNIfi

2020-01-28 22:41:02,929 INFO [NiFi Web Server-38] o.a.n.w.a.c.AccessDeniedExceptionMapper identity[CN=NifiAdmin, OU=ApacheNIfi, groups[] does not have permission to access the requested resource. No applicable policies could be found. Returning Forbidden response.