2.3. Authenticating by using the roxctl CLI
For authentication, you can use an API token, your administrator password, or the roxctl central login command.
Follow these guidelines for the effective use of API tokens:
- Use an API token in a production environment with continuous integration (CI). Each token is assigned specific access permissions, providing control over the actions it can perform. In addition, API tokens do not require interactive processes, such as browser-based logins, making them ideal for automated processes. These tokens have a time-to-live (TTL) value of 1 year, providing a longer validity period for seamless integration and operational efficiency.
- Use your administrator password only for testing purposes. Do not use it in the production environment.
-
Use the
roxctl central logincommand only for interactive, local uses.
-
To prevent privilege escalation, when you create a new token, your role’s permissions limit the permission you can assign to that token. For example, if you only have
readpermission for the Integration resource, you cannot create a token withwritepermission. - If you want a custom role to create tokens for other users to use, you must assign the required permissions to that custom role.
-
Use short-lived tokens for machine-to-machine communication, such as CI/CD pipelines, scripts, and other automation. Also, use the
roxctl central logincommand for human-to-machine communication, such asroxctlCLI or API access. - The majority of cloud service providers support OIDC identity tokens, for example, Microsoft Entra ID, Google Cloud Identity Platform, and AWS Cognito. OIDC identity tokens issued by these services can be used for RHACS short-lived access.
- Third-party OIDC identity tokens can also be used directly to access the API endpoint, without an exchange, if a machine-to-machine configuration exists for the token issuer.
2.3.1. Creating an API token 링크 복사링크가 클립보드에 복사되었습니다!
Procedure
-
In the RHACS portal, go to Platform Configuration
Integrations. - Scroll to the Authentication Tokens category, and then click API Token.
- Click Generate Token.
- Enter a name for the token and select a role that provides the required level of access (for example, Continuous Integration or Sensor Creator).
Click Generate.
중요Copy the generated token and securely store it. You will not be able to view it again.
2.3.2. Exporting and saving the API token 링크 복사링크가 클립보드에 복사되었습니다!
Procedure
After you have generated the authentication token, export it as the
ROX_API_TOKENvariable by entering the following command:$ export ROX_API_TOKEN=<api_token>(Optional): You can also save the token in a file and use it with the
--token-fileoption by entering the following command:$ roxctl central debug dump --token-file <token_file>Note the following guidelines:
-
You cannot use both the
-password(-p) and the--token-fileoptions simultaneously. -
If you have already set the
ROX_API_TOKENvariable, and specify the--token-fileoption, theroxctlCLI uses the specified token file for authentication. -
If you have already set the
ROX_API_TOKENvariable, and specify the--passwordoption, theroxctlCLI uses the specified password for authentication.
-
You cannot use both the
2.3.3. Using an authentication provider to authenticate with roxctl 링크 복사링크가 클립보드에 복사되었습니다!
You can configure an authentication provider in Central and initiate the login process with the roxctl CLI. Set the ROX_ENDPOINT variable, initiate the login process with the roxctl central login command, select the authentication provider in a browser window, and retrieve the token information from the roxctl CLI as described in the following procedure.
Prerequisite
- You selected an authentication provider of your choice, such as OpenID Connect (OIDC) with fragment or query mode.
Procedure
Run the following command to set the
ROX_ENDPOINTvariable to Central hostname and port:export ROX_ENDPOINT=<central_hostname:port>Run the following command to initiate the login process to Central:
$ roxctl central login-
Within the
roxctlCLI, a URL is printed as output and you are redirected to a browser window where you can select the authentication provider you want to use. Log in with your authentication provider.
After you have successfully logged in, the browser window indicates that authentication was successful and you can close the browser window.
The
roxctlCLI displays your token information including details such as the access token, the expiration time of the access token, the refresh token if one has been issued, and notification that these values are stored locally.Example output
Please complete the authorization flow in the browser with an auth provider of your choice. If no browser window opens, please click on the following URL: http://127.0.0.1:xxxxx/login INFO: Received the following after the authorization flow from Central: INFO: Access token: <redacted> INFO: Access token expiration: 2023-04-19 13:58:43 +0000 UTC INFO: Refresh token: <redacted> INFO: Storing these values under $HOME/.roxctl/login…-
Access token: <redacted>is the access token. -
Access token expiration: 2023-04-19 13:58:43 +0000 UTCis the expiration time of the access token. -
Refresh token: <redacted>is the refresh token. $HOME/.roxctl/login…is the directory where values of the access token, the access token expiration time, and the refresh token are stored locally.중요Ensure that you set the environment to determine the directory where the configuration is stored. By default, the configuration is stored in the
$HOME/.roxctl/roxctl-configdirectory.-
If you set the
$ROX_CONFIG_DIRenvironment variable, the configuration is stored in the$ROX_CONFIG_DIR/roxctl-configdirectory. This option has the highest priority. -
If you set the
$XDG_RUNTIME_DIRenvironment variable and the$ROX_CONFIG_DIRvariable is not set, the configuration is stored in the$XDG_RUNTIME_DIR /roxctl-configdirectory. -
If you do not set the
$ROX_CONFIG_DIRor$XDG_RUNTIME_DIRenvironment variable, the configuration is stored in the$HOME/.roxctl/roxctl-configdirectory.
-
If you set the
-