travelaudience / kubernetes-nexus

Run Sonatype Nexus Repository Manager OSS on top of Kubernetes (GKE). Includes instructions for automated backups (GCS) and day-to-day usage.
Apache License 2.0
130 stars 61 forks source link

Keystore errors on GKE #47

Closed GMafra closed 5 years ago

GMafra commented 5 years ago

Hi,

I'm following the steps to deploy nexus with the proxy on GKE and it is failing due to issues with the Java Key store:

java.lang.RuntimeException: java.io.IOException: Keystore was tampered with, or password was incorrect at io.vertx.ext.auth.jwt.impl.JWTAuthProviderImpl.<init>(JWTAuthProviderImpl.java:78) at io.vertx.ext.auth.jwt.JWTAuth.create(JWTAuth.java:41) at com.travelaudience.nexus.proxy.JwtAuth.<init>(JwtAuth.java:29) at com.travelaudience.nexus.proxy.JwtAuth.create(JwtAuth.java:53) at com.travelaudience.nexus.proxy.CloudIamAuthNexusProxyVerticle.init(CloudIamAuthNexusProxyVerticle.java:106) at io.vertx.core.impl.DeploymentManager.lambda$doDeploy$8(DeploymentManager.java:432) at io.vertx.core.impl.ContextImpl.lambda$wrapTask$2(ContextImpl.java:337) at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163) at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:403) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:445) at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858) at java.lang.Thread.run(Thread.java:748) Caused by: java.io.IOException: Keystore was tampered with, or password was incorrect at com.sun.crypto.provider.JceKeyStore.engineLoad(JceKeyStore.java:879) at java.security.KeyStore.load(KeyStore.java:1445) at io.vertx.ext.auth.jwt.impl.JWTAuthProviderImpl.<init>(JWTAuthProviderImpl.java:66)

Expand all | Collapse all {
 insertId:  "ibljtdg4agry3a"  
 labels: {…}  
 logName:  "projects/kubernetes-dmafra/logs/nexus-proxy"  
 receiveTimestamp:  "2019-04-09T19:02:02.356485455Z"  
 resource: {…}  
 severity:  "INFO"  
 textPayload:  "java.lang.RuntimeException: java.io.IOException: Keystore was tampered with, or password was incorrect
    at io.vertx.ext.auth.jwt.impl.JWTAuthProviderImpl.<init>(JWTAuthProviderImpl.java:78)
    at io.vertx.ext.auth.jwt.JWTAuth.create(JWTAuth.java:41)
    at com.travelaudience.nexus.proxy.JwtAuth.<init>(JwtAuth.java:29)
    at com.travelaudience.nexus.proxy.JwtAuth.create(JwtAuth.java:53)
    at com.travelaudience.nexus.proxy.CloudIamAuthNexusProxyVerticle.init(CloudIamAuthNexusProxyVerticle.java:106)
    at io.vertx.core.impl.DeploymentManager.lambda$doDeploy$8(DeploymentManager.java:432)
    at io.vertx.core.impl.ContextImpl.lambda$wrapTask$2(ContextImpl.java:337)
    at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:403)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:445)
    at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.io.IOException: Keystore was tampered with, or password was incorrect
    at com.sun.crypto.provider.JceKeyStore.engineLoad(JceKeyStore.java:879)
    at java.security.KeyStore.load(KeyStore.java:1445)
    at io.vertx.ext.auth.jwt.impl.JWTAuthProviderImpl.<init>(JWTAuthProviderImpl.java:66)
"  
 timestamp:  "2019-04-09T19:01:15.668490300Z"  
}

and also some other errors such as "java.security.UnrecoverableKeyException: Password verification failed" or "Invalid keystore format at io.vertx.ext.auth.jwt.impl.JWTAuthProviderImpl."

I created the keystore as explained on the how to with the following code

keytool -genkey \
          -keystore keystore.jceks \
          -storetype jceks \
          -keyalg RSA \
          -keysize 2048 \
          -alias RS256 \
          -sigalg SHA256withRSA \
          -dname "CN=,OU=,O=,L=,ST=,C=" \
          -validity 3651 \

and was able to validate it with keytool -list -v -keystore keystore.jceks -storetype jceks

Not sure how to proceed here and get it working.

pires commented 5 years ago

Possibly the password is not properly defined or the file uploaded to the secret is not valid, as defined here.

Did you replace the corresponding values accordingly when running:

$ cat << EOF > nexus-proxy-ks-secret.yaml
apiVersion: v1
kind: Secret
metadata:
  name: nexus-proxy-ks
type: Opaque
data:
  keystore: $(cat /path/to/keystore.jceks | base64)
  password: $(echo -n "KEYSTORE_PASSWORD" | base64)
EOF

?

Do re-read the section above, because that's most probably where your problem is.

GMafra commented 5 years ago

Hi Pires,

Yes, the keystore I pointed to where it was located and the password I typed in there and it encoded successfully (I tried decoding it and got the correct value). Is password complexity a thing?

The file generated by the code you posted is:

apiVersion: v1
kind: Secret
metadata:
  name: nexus-proxy-ks
type: Opaque
data:
  keystore: zs7OzgAAAAIAAAABAAAAAQAFcnMyNTYAAAFqA2zfowAABO4wggTqMBwGCSsGAQQBKgITATAPBAhIX52BBrIm4wIDAw1ABIIEyAPIMsuRhF2if+Ukm+dWISvEo7u82r7vpM9w6tEBLQUrxjrPMKceuAlnL0EfabfuS0d0XKoIDU3+m4RQOcN1xeLGdP1diuSxeITSabeTAdZFLeNlPqmJmnfHIAPgbxgW3D1xbNR4m7nQAokvGFxMmnC5KO7pbggk7UjCrQQZONrx5rbjRzGEiM8XLEVbl6+ffK22pn+Flhr6F5FdLN8Bd2VEobRomcBTfsuVns6BDEm1aMQf6RVCYy8pjUaue0z6ZMbAEkBfMAnk9A+lnI9Ou5G6xH9MbLKonCpJK9WhlqvUQ0ls3oGzdrIxVnqf7r2listk8EXterh0INj0eitxV6/9Mv6HXbutIVJXFAH2hxyDRi1tW92uRXsTyiG/OqJXCnWIA3JCnn7lIm9SZNaPDfq+OjfNkCozxvMm0Un6imdTEgJj+GbCQOcW64YR6FmdXtFmQk8IYldgxioD/q4pd7bG0sRJ3p4F9cf8lzHX9FykgCCENwsg0K2D15T0bFtIST7ExXA7bcZlo7GbOAVDu9zpeVEyIIAYsLTUYsdrhZYkQkoQX1PRMg0rl97SB1DmKd2liDMp0JYPB80Go70xtdtbgmhxx7kany3tC6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. Also, this is the content of my Keystore:

Keystore type: JCEKS
Keystore provider: SunJCE

Your keystore contains 1 entry

Alias name: rs256
Creation date: Apr 9, 2019
Entry type: PrivateKeyEntry
Certificate chain length: 1
Certificate[1]:
Owner: CN=, OU=, O=, L=, ST=, C=
Issuer: CN=, OU=, O=, L=, ST=, C=
Serial number: 2eed0a1a
Valid from: Tue Apr 09 15:47:03 BRT 2019 until: Sat Apr 07 15:47:03 BRT 2029
Certificate fingerprints:
     MD5:  39:C9:0F:88:BF:BE:0F:8C:A5:09:4B:74:29:C7:BE:98
     SHA1: D3:EA:47:46:78:E3:96:A7:4E:E9:42:1B:3F:FA:E1:87:07:03:4C:E2
     SHA256: 65:12:D8:BE:F8:DC:F8:DC:B3:D8:43:9D:97:D6:65:5C:84:FC:59:80:FE:4E:38:44:72:5F:70:78:15:94:DC:CD
Signature algorithm name: SHA256withRSA
Subject Public Key Algorithm: 2048-bit RSA key
Version: 3

Extensions:

#1: ObjectId: 2.5.29.14 Criticality=false
SubjectKeyIdentifier [
KeyIdentifier [
0000: 04 9A 72 D8 E4 05 5D 08   6C D3 08 2C 0A 4B 8B 97  ..r...].l..,.K..
0010: 0C CD DB 9E                                        ....
]
]

*******************************************
*******************************************
pires commented 5 years ago

I'm out of ideas at this point :(

pires commented 5 years ago

Can you please start a debug pod with this secret mounted and run the validation manually?

GMafra commented 5 years ago

Sure, I will do that and let you know the results

GMafra commented 5 years ago

Hi Pires,

This is the result: image

Password looks good as well:

image

GMafra commented 5 years ago

Found the issue!

On the documentation it is said to replace KEYSTORE_PASSWORD with the password and encode it. The problem is that it is written between "" on the script, which makes it encode the value with "" as well!

So after doing this: password: $(echo -n Start123! | base64) Instead of this: password: $(echo -n "Start123!" | base64)

It worked!

pires commented 5 years ago

Ah! I'll fix it, thanks.