In this recipe, we saw how to start a new replica set using key files. If you already have a replica set, you can still enable key-file-based authorization but you'll have to carefully sequence your steps, like so:
- First, add a superuser account as shown previously.
- Next, create the relevant client accounts that would be used by your applications.
- Ensure that the applications are using the newly created user accounts.
- Stop one of the secondaries and start with the parameter --transitionToAuth along with --keyFile.
- One by one, restart all secondary nodes with the parameter --transitionToAuth along with --keyFile.
- Bring down the primary using rs.stepDown(), and once a new primary node is elected, start this instance too, with ...