NeilMadden / apisecurityinaction

Source code that accompanies the book API Security in Action
MIT License
147 stars 97 forks source link

No reference to /etc/secrets/database/username format #6

Closed devops-ng closed 4 years ago

devops-ng commented 4 years ago

If we try to use the natter-api from this repository after running mvn clean compile exec:java we get the following error:

java.nio.file.FileSystemException: /etc/secrets/database/username: Not a directory

It clearly expects username to be a directory. There are 0 references to this in the whole book. The only reference found is to /etc/secrets/database where database is a file. Do you mind give an example of what's expected here to get this built?

NeilMadden commented 4 years ago

This is covered in section 11.5.1 on Kubernetes secrets: https://livebook.manning.com/book/api-security-in-action/chapter-11/v-8/249

The master branch tracks the latest completed chapter and is often ahead of what has been published in the early-access book. There are git branches for each chapter as discussed in the README which are generally easier to get running.

devops-ng commented 4 years ago

I saw that, and I even pointed it in my initial message. Having the file you linked to doesn't solve the issue. I still get that error above. The Java code is looking for 2 files (/etc/secrets/database/username, and /etc/secrets/database/password). And not the file presented in the book (/etc/secrets/database). Can you please double check?

NeilMadden commented 4 years ago

The Kubernetes secret is created with

kubectl create secret generic db-password -n natter-api \
    --from-literal=username=natter \
    --from-literal=password=password

which is then mounted into the image in listing 11.11:

        volumeMounts:
            - name: db-password
              mountPath: "/etc/secrets/database"
              readOnly: true

That will result in two files being created under /etc/secrets/database/username and /etc/secrets/database/password

devops-ng commented 4 years ago

Thank you. I got it now.