此内容没有您所选择的语言版本。
Chapter 3. API call authentication
Interaction with the Satellite API requires SSL authentication with Satellite Server CA certificate and authentication with valid Satellite user credentials. You can use the following authentication methods.
3.1. SSL authentication overview 复制链接链接已复制到粘贴板!
Red Hat Satellite uses HTTPS, which provides a degree of encryption and identity verification when communicating with Satellite Server. Satellite 6.18 does not support non-SSL communications.
By default, Satellite Server uses a self-signed certificate. This certificate acts as both the server certificate to verify the encryption key and the certificate authority (CA) to trust the identity of Satellite Server.
You can configure Satellite Server to use a custom SSL certificate. For more information, see Configuring Satellite Server with a custom SSL certificate in Installing Satellite Server in a connected network environment. For more information on disconnected Satellite Server, see Configuring Satellite Server with a custom SSL certificate in Installing Satellite Server in a disconnected network environment.
3.1.1. Configuring SSL authentication 复制链接链接已复制到粘贴板!
Configure an SSL authentication for the API requests to Satellite Server.
Procedure
Obtain a certificate from your Satellite Server by using one of the following options:
If you plan to call the API from a remote server, download the CA certificate:
curl \ --output /etc/pki/ca-trust/source/anchors/satellite.example.com-katello-server-ca.crt \ http://satellite.example.com/pub/katello-server-ca.crt
$ curl \ --output /etc/pki/ca-trust/source/anchors/satellite.example.com-katello-server-ca.crt \ http://satellite.example.com/pub/katello-server-ca.crtCopy to Clipboard Copied! Toggle word wrap Toggle overflow If you plan to call the API directly on your Satellite Server, copy the certificate to the
/etc/pki/ca-trust/source/anchorsdirectory:cp /var/www/html/pub/katello-server-ca.crt /etc/pki/ca-trust/source/anchors/satellite.example.com-katello-server-ca.crt
# cp /var/www/html/pub/katello-server-ca.crt /etc/pki/ca-trust/source/anchors/satellite.example.com-katello-server-ca.crtCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Add the certificate to the list of trusted CAs:
update-ca-trust extract
$ update-ca-trust extractCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Verify that your client trusts the Satellite SSL certificate by entering the API request without the
--cacertoption:curl \ --request GET \ --user My_User_Name:My_Password \ https://satellite.example.com/api/v2/hosts
$ curl \ --request GET \ --user My_User_Name:My_Password \ https://satellite.example.com/api/v2/hostsCopy to Clipboard Copied! Toggle word wrap Toggle overflow
3.2. HTTP authentication overview 复制链接链接已复制到粘贴板!
All requests to the Satellite API require a valid Satellite user name and password. The API uses Basic HTTP authentication to encode these credentials and add to the Authorization header. For more information about Basic authentication, see RFC 2617 HTTP Authentication: Basic and Digest Access Authentication. If a request does not include an appropriate Authorization header, the API returns a 401 Authorization Required error.
Basic authentication involves potentially sensitive information, for example, it sends passwords as plain text. The REST API requires HTTPS for transport-level encryption of plain text requests.
Some base64 libraries break encoded credentials into multiple lines and terminate each line with a newline character. This invalidates the header and causes a faulty request. The Authorization header requires the encoded credentials to be on a single line within the header.
3.3. Token authentication overview 复制链接链接已复制到粘贴板!
Red Hat Satellite supports Personal Access Tokens that you can use to authenticate API requests instead of using your password. You can set an expiration date for your Personal Access Token and you can revoke it if you decide it should expire before the expiration date.
3.3.1. Creating a Personal Access Token 复制链接链接已复制到粘贴板!
Use this procedure to create a Personal Access Token.
Procedure
- In the Satellite web UI, navigate to Administer > Users.
- Select a user for which you want to create a Personal Access Token.
- On the Personal Access Tokens tab, click Add Personal Access Token.
- Enter a Name for you Personal Access Token.
- Optional: Select the Expires date to set an expiration date. If you do not set an expiration date, your Personal Access Token will never expire unless revoked.
Click Submit. You now have the Personal Access Token available to you on the Personal Access Tokens tab.
ImportantEnsure to store your Personal Access Token as you will not be able to access it again after you leave the page or create a new Personal Access Token. You can click Copy to clipboard to copy your Personal Access Token.
Verification
Make an API request to your Satellite Server and authenticate with your Personal Access Token:
curl \ --user My_Username:My_Personal_Access_Token \ https://satellite.example.com/api/status
$ curl \ --user My_Username:My_Personal_Access_Token \ https://satellite.example.com/api/statusCopy to Clipboard Copied! Toggle word wrap Toggle overflow You should receive a response with status
200, for example:{"satellite_version":"6.18.0","result":"ok","status":200,"version":"3.5.1.10","api_version":2}{"satellite_version":"6.18.0","result":"ok","status":200,"version":"3.5.1.10","api_version":2}Copy to Clipboard Copied! Toggle word wrap Toggle overflow If you go back to Personal Access Tokens tab, you can see the updated Last Used time next to your Personal Access Token.
3.3.2. Revoking a Personal Access Token 复制链接链接已复制到粘贴板!
Use this procedure to revoke a Personal Access Token before its expiration date.
Procedure
- In the Satellite web UI, navigate to Administer > Users.
- Select a user for which you want to revoke the Personal Access Token.
- On the Personal Access Tokens tab, locate the Personal Access Token you want to revoke.
- Click Revoke in the Actions column next to the Personal Access Token you want to revoke.
Verification
Make an API request to your Satellite Server and try to authenticate with the revoked Personal Access Token:
curl \ --user My_Username:My_Personal_Access_Token \ https://satellite.example.com/api/status
$ curl \ --user My_Username:My_Personal_Access_Token \ https://satellite.example.com/api/statusCopy to Clipboard Copied! Toggle word wrap Toggle overflow You receive the following error message:
{ "error": {"message":"Unable to authenticate user My_Username"} }{ "error": {"message":"Unable to authenticate user My_Username"} }Copy to Clipboard Copied! Toggle word wrap Toggle overflow