Chapter 3. Hammer authentication
A Satellite user must prove their identity to Red Hat Satellite when entering hammer commands. Hammer commands can be run manually or automatically. In either case, hammer requires Satellite credentials for authentication. There are three methods of hammer authentication:
- Hammer authentication session
- Storing credentials in the hammer configuration file
- Providing credentials with each hammer command
The hammer configuration file method is recommended when running commands automatically. For example, running Satellite maintenance commands from a cron job. When running commands manually, Red Hat recommends using the hammer authentication session and providing credentials with each command.
3.1. Authenticating Hammer using a configuration file Copy linkLink copied to clipboard!
If you ran the Satellite installation with --foreman-initial-admin-username and --foreman-initial-admin-password options, credentials you entered are stored in the ~/.hammer/cli.modules.d/foreman.yml configuration file on Satellite Server. Hammer does not prompt for your credentials when you run it on Satellite Server.
If you run a standalone Hammer, add your credentials to the Hammer configuration file.
If you change your credentials on Satellite Server, you must update the configuration file manually. The installer does not overwrite the configuration file.
Procedure
Add your credentials to the
~/.hammer/cli.modules.d/foreman.ymlconfiguration file::foreman: :username: 'username' :password: 'password'Use only spaces for indentation in Hammer configuration files, do not use tabs.
3.2. Authenticating Hammer using CLI options Copy linkLink copied to clipboard!
If you do not have your Satellite credentials saved in the ~/.hammer/cli.modules.d/foreman.yml configuration file, Hammer prompts you for them each time you enter a command.
Examples in this guide assume that you have saved credentials in the configuration file or are using a Hammer authentication session.
Procedure
Specify your credentials when executing a command as follows:
$ hammer -u username -p password subcommands
3.3. Authenticating Hammer using sessions Copy linkLink copied to clipboard!
The Hammer authentication session is a cache that stores your credentials, and you have to provide them only once, at the beginning of the session. This method is suited to running several Hammer commands in succession, for example a script containing Hammer commands. In this scenario, you enter your Satellite credentials once, and the script runs as expected. By using the Hammer authentication session, you avoid storing your credentials in the script itself and in the ~/.hammer/cli.modules.d/foreman.yml Hammer configuration file.
Prerequisites
You have enabled sessions by adding
:use_sessions: trueto the~/.hammer/cli.modules.d/foreman.ymlfile::foreman: :use_sessions: trueNote that if you enable sessions, credentials stored in the configuration file will be ignored.
Optional: You can change the length of a session, for example, to 30 minutes:
$ hammer settings set \ --name idle_timeout \ --value 30The default length is 60 minutes.
Procedure
Start a session:
$ hammer auth loginYou are prompted for your Satellite credentials, and logged in. You will not be prompted for the credentials again until your session expires.
Verification
View the current status of the session:
$ hammer auth status
Next steps
End the session:
$ hammer auth logout