Implementation method for safety certification of connection between Elasticsearch and Kerberos
By extending the NetworkPlugin interface of the Elasticsearch network plugin, a secure connection with Kerberos authentication is achieved, and a ticket caching mechanism is introduced. This solves the data security and authentication performance issues of Elasticsearch in insecure network environments, thereby improving the system's security and performance.
Patent Information
- Application Number
- CN202410952444.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-16
- Publication Date
- 2024-10-11
AI Technical Summary
Elasticsearch's open-source network security plugin does not support Kerberos security authentication, resulting in poor data security and low user authentication performance in insecure network environments.
By extending the NetworkPlugin interface of the Elasticsearch network plugin, a secure connection between Elasticsearch and Kerberos authentication is achieved. The Kerberos authentication mechanism is used for authentication, and a ticket caching mechanism is introduced to customize the ticket validity period to reduce duplicate authentication.
It improves the data security and user authentication performance of the Elasticsearch retrieval service, eliminates the risk of user information leakage, reduces the number of repeated authentications under high concurrency requests, and improves the overall performance of the system.
Smart Images

Figure CN118764276A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data communication, and in particular to a method for implementing Elasticsearch connection Kerberos security authentication. Background Art
[0002] Elasticsearch is an open source, Lucene-based search server that provides a distributed, multi-user, full-text search engine. In the e-commerce business domain, its distributed search function uses log search and analysis, spatiotemporal search, time series search, and report intelligent search to present, analyze, and predict customer-related information in multiple dimensions, thereby unleashing the value of data.
[0003] Due to the need for information security, Elasticsearch officially provides an open source x-pack plug-in after version 7.x. By enabling the security function of x-pack, you can use the basic authentication (Basic access authentication) method officially provided by it. However, this security authentication method has the following main disadvantages: First, the security is poor. The key or password transmitted in plain text during the access request process can be easily intercepted. As long as the request is intercepted, the user's account or password can be obtained. Similarly, there is no protection for the information returned by the server; second, the user authentication performance is low. Each access request requires the key or password to be identified. In high-concurrency usage scenarios, repeated authentication will generate a large amount of network io (Input / Output), reducing user authentication performance.
[0004] Kerberos authentication is a trusted third-party authentication system proposed by the Massachusetts Institute of Technology. The Kerberos authentication protocol has become a widely accepted standard protocol in the field of computer security. The big data field usually uses this protocol to implement mutual authentication operations between different services. Its characteristics are: first, high security performance. Kerberos encrypts the user's password as the user's private key, thereby avoiding the user's password from being displayed and transmitted on the network, making it difficult for eavesdroppers to obtain the corresponding password information on the network; second, more efficient identity authentication. After the client applies for a ticket from TGS (Ticket Granting Server) through AS (Authentication Server), it can use the ticket and TGS to request different access authorization tickets multiple times within the validity period, achieving the effect of one authentication and multiple uses. Its advantages just make up for the shortcomings of the basic authentication method.
[0005] However, the open source versions of Elasticsearch-related open source network security plug-ins (such as x-pack and search guard) do not support Kerberos security authentication and cannot meet the data security requirements of es search services in non-secure network environments. Therefore, implementing Elasticsearch to connect to Kerberos security authentication is of great significance to strengthening data security and improving user authentication performance. Summary of the invention
[0006] In order to solve the technical problem that none of the open source network security plug-ins related to Elasticsearch support Kerberos security authentication, and the data security of es retrieval services in non-secure network environments is insufficient, the present invention proposes an implementation method for connecting Elasticsearch to Kerberos security authentication.
[0007] In a first aspect, an embodiment of the present invention provides a method for implementing Elasticsearch connection Kerberos security authentication, which is applied to a client, and the method includes:
[0008] Send the access request containing user information to the server;
[0009] Receive authentication data sent by the server, and perform identity authentication based on the authentication data, wherein the authentication data is the authentication data obtained by parsing the request header of the user information of the access request by the server, and marking the authentication data if the request header has a corresponding Kerberos authentication method;
[0010] If the identity authentication is successful, the authentication subject information pre-created on the server is distributed to the key distribution center KDC, so that the client and server can authenticate their legal identity information through the key distribution center KDC;
[0011] Receive the authorization ticket voucher ticket returned by the key distribution center KDC, where the authorization ticket voucher ticket is the corresponding authorization ticket voucher ticket found by the ticket authorization service center from the database of the ticket authorization service center according to the Elasticsearch authentication subject information of the server; the authorization ticket voucher ticket is used as the permission voucher for the client to access the server;
[0012] The server is accessed according to the authorization ticket. If the access is successful, a connection is established with the server.
[0013] In some implementations, the method further includes: setting up an authorization ticket credential ticket caching mechanism, so that within a certain period of time, access to the server can be performed without verification by using the authorization ticket credential ticket. The certain period of time refers to the validity period of the ticket distributed by the customized TGS after the first successful authentication of the legal identity information.
[0014] In some implementations, if the request header begins with Negotiate, the request header corresponds to the Kerberos authentication method.
[0015] In some implementations, distributing the authentication subject information pre-created on the server to the key distribution center KDC, so as to authenticate the identity legal information of the client and the server through the key distribution center KDC, includes:
[0016] Instantiate a LoginContext authentication context instance by calling javax.security.auth.login.LoginContext;
[0017] By calling the login method of LoginContext, the server's Elasticsearch authentication subject information is distributed to the key distribution center KDC, and the key distribution center KDC is requested to authenticate the identity legality information of both the client and the server.
[0018] In some implementations, the method further includes:
[0019] By introducing the Subject.doAs method in GSSAPI, a Context is created to save the ticket data;
[0020] Get an authorization ticket through the initSecContext method and send it to the server;
[0021] A new authorization ticket voucher ticket fed back by the server is received, where the new authorization ticket voucher ticket is a new authorization ticket voucher ticket generated by the server for communication.
[0022] In some implementations, the method further includes: obtaining an authorization ticket voucher ticket directly based on the Context context within the validity period of the ticket distributed by the customized TGS, and accessing the server without verification by means of the authorization ticket voucher ticket.
[0023] In some implementations, the authorization ticket is the only way to access the server, and the authorization ticket includes Elasticsearch authentication subject information and a timestamp of when the authorization ticket is obtained.
[0024] In a second aspect, an embodiment of the present invention provides a method for implementing Elasticsearch connection Kerberos security authentication, which is applied to a server, and the method includes:
[0025] Receive access requests from clients that carry user information;
[0026] Read and parse the request header of the user information of the access request, and if the request header has a corresponding Kerberos authentication method, mark the authentication data, and send the marked authentication data to the client;
[0027] After receiving the authorization ticket from the client, the authorization ticket is decrypted to obtain the client information, and the client information is compared with the client authentication identifier obtained from the system table. If they are the same, the access is successful, otherwise the access fails.
[0028] In some implementations, receiving an access request carrying user information from a client includes:
[0029] Receive access requests by overriding the HttpChannelHandler method in the NetworkPlugin interface provided by the Elasticsearch network plug-in.
[0030] In some implementations, the method further includes: reading user information of the received access request by overriding a channelRead method in ChannelInboundHandlerAdapter.
[0031] In some implementations, the method further includes: after receiving the authorization ticket voucher ticket, verifying the received authorization ticket voucher ticket, generating a new authorization ticket voucher ticket for communication, and sending the new authorization ticket voucher ticket to the client.
[0032] In some implementations, the marked authentication data includes a request header of a Kerberos authentication mark set by an authentication subject of the server.
[0033] In some implementations, before authenticating the identity legality information, the method further includes:
[0034] Connect to the ticket authorization service and Kerberos authentication method components, and create Elasticsearch authentication subject information and user-password files;
[0035] Configure the relevant parameters of security authentication, including the https protocol related certificate files, Elasticsearch authentication subject information, and the path of the user-password file;
[0036] Store the user-password file in the specified path according to the path where the user-password file is located.
[0037] In a third aspect, a system for implementing Elasticsearch connected to Kerberos security authentication is provided, including:
[0038] A client, used to execute the above method;
[0039] The server is used to execute the above method.
[0040] One or more embodiments of the present invention bring at least the following beneficial effects:
[0041] The present invention realizes the kerberos security authentication of Elasticsearch connection by utilizing the NetworkPlugin interface provided by the Elasticsearch network plug-in, eliminates the risk of user information leakage when initiating Elasticsearch access requests, and customizes the effective duration of tickets based on the Kerberos security mechanism. When high-concurrency access requests are made, the server can be logged in without verification in a short period of time based on the ticket information obtained by the first verification, thereby reducing the number of repeated authentication times of access requests initiated by the client in a short period of time, thereby greatly improving the data security and performance issues in the process of using Elasticsearch retrieval services. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and should not be regarded as limiting the scope.
[0043] Figure 1 A schematic diagram of a method for implementing Elasticsearch connection Kerberos security authentication provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0044] The technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. The components of the embodiments of the present invention generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present invention provided in the drawings is not intended to limit the scope of the claimed invention, but merely represents the selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present invention.
[0045] This embodiment provides a method for implementing Kerberos security authentication for Elasticsearch, which is applied to a system, wherein the system includes a client and a server. The method mainly addresses the deficiencies of open source network plug-ins such as Elasticsearch, and implements Kerberos security authentication for Elasticsearch connection by extending the interface of the relevant network plug-in NetworkPlugin, thereby enhancing the data security and user authentication performance of Elasticsearch.
[0046] The methods applied to the client include:
[0047] Step S1, sending an access request carrying user information to the server;
[0048] Step S2, receiving authentication data sent by the server, and performing identity authentication based on the authentication data, wherein the authentication data is the authentication data obtained by the server parsing the request header of the user information of the access request, and marking the authentication data if the request header has a corresponding Kerberos authentication method. In some implementations, if the request header begins with Negotiate, the request header corresponds to the Kerberos authentication method.
[0049] Step S3, if the identity authentication is successful, the authentication subject information pre-created on the server is distributed to the key distribution center KDC, so that the key distribution center KDC can authenticate the identity of the client and the server. In some implementations, a LoginContext authentication context instance is instantiated by calling javax.security.auth.login.LoginContext; then the Elasticsearch authentication subject information of the server is distributed to the key distribution center KDC by calling the login method of LoginContext, and the key distribution center KDC is requested to authenticate the identity of both the client and the server.
[0050] Step S4, receiving the authorization ticket voucher ticket returned by the key distribution center KDC, the authorization ticket voucher ticket is the corresponding authorization ticket voucher ticket found by the ticket authorization service center from the database of the ticket authorization service center according to the Elasticsearch authentication subject information of the server; the authorization ticket voucher ticket is used as the permission voucher for the client to access the server. The authorization ticket voucher ticket is the only way to access the server, and the authorization ticket voucher ticket includes the Elasticsearch authentication subject information and the timestamp of the authorization ticket voucher ticket acquisition time.
[0051] Step S5, access the server according to the authorization ticket, and if the access is successful, establish a connection with the server.
[0052] In some implementations, for the client, step S5 in the method further includes:
[0053] Step S5.1, create a Context to save the ticket data by introducing the Subject.doAs method in GSSAPI;
[0054] Step S5.2, obtain an authorization ticket through the initSecContext method and send it to the server;
[0055] Step S5.3: Receive a new authorization ticket voucher ticket fed back by the server, where the new authorization ticket voucher ticket is a new authorization ticket voucher ticket generated by the server for communication.
[0056] In one embodiment, for the client, the method further includes:
[0057] Step S6, set up the authorization ticket voucher ticket cache mechanism, within a certain period of time, the authorization ticket voucher ticket can be used to access the server without verification, and the certain period of time refers to the validity period of the ticket distributed by the customized TGS after the first successful authentication of the legal identity information. Therefore, within the validity period of the ticket distributed by the customized TGS, the authorization ticket voucher ticket is directly obtained based on the Context context, and the authorization ticket voucher ticket is used to access the server without verification.
[0058] Methods applied to the server include:
[0059] Step S1, receiving an access request carrying user information from a client;
[0060] Step S2, read and parse the request header of the user information of the access request, and mark the authentication data if the request header has a corresponding Kerberos authentication method, and send the marked authentication data to the client. The marked authentication data includes the request header of the Kerberos authentication mark set by the authentication subject of the server. In some implementations, the access request is received by rewriting the HttpChannelHandler method in the NetworkPlugin interface provided by the Elasticsearch network plug-in; the user information of the received access request is read by rewriting the channelRead method in the ChannelInboundHandlerAdapter.
[0061] Step S3, after receiving the authorization ticket voucher ticket sent by the client, the authorization ticket voucher ticket is decrypted to obtain the client information, and the client information is compared with the client authentication identifier obtained from the system table. If they are the same, the access is successful, otherwise the access fails. In this embodiment, after receiving the authorization ticket voucher ticket, the received authorization ticket voucher ticket is also verified, and a new authorization ticket voucher ticket for communication is generated, and the new authorization ticket voucher ticket is sent to the client.
[0062] The method applied to the server also includes preparation steps before the identity legal information authentication, including:
[0063] Step S00, connect to the ticket authorization service, Kerberos authentication method component, and create Elasticsearch authentication subject information and user-password file;
[0064] Step S01, configure the relevant parameters of security authentication, which include the https protocol related certificate files, Elasticsearch authentication subject information, and the path of the user-password file;
[0065] Step S02: storing the user-password file in a designated path according to the path where the user-password file is located.
[0066] The specific application example of the implementation method of connecting Elasticsearch to Kerberos security authentication described in this embodiment is as follows: Figure 1 As shown, including:
[0067] S1. Preparation stage:
[0068] S1.1. The server connects to the ticket authorization service and Kerberos authentication method component.
[0069] S1.2. Create the Elasticsearch authentication principal and user-password file on the server.
[0070] S1.3. Configure the server with security authentication related parameters, including https protocol related certificate files, Elasticsearch authentication subject, user-password file path, etc.
[0071] S1.4. Store the user-password file on the server according to the path where the user-password file is located.
[0072] S2, authentication stage:
[0073] S2.1. The client sends an access request carrying user information to the server.
[0074] S2.2, the server reads the user information of the access request, parses the request header of the user information, and determines the authentication method corresponding to the request header according to the user-authentication method table pre-established in the system table, and marks the authentication data if the request header has a corresponding Kerberos authentication method, and sends the marked authentication data to the client. The marked authentication data includes the request header with the Kerberos authentication tag set by the authentication master of the server.
[0075] The specific implementation method of the server reading the user information of the access request is as follows: the server receives the access request by overriding the HttpChannelHandler method in the NetworkPlugin interface provided by the Elasticsearch network plug-in. The server reads the user information of the received access request by overriding the channelRead method in the ChannelInboundHandlerAdapter.
[0076] In this embodiment, if the request header begins with Negotiate, the request header corresponds to the Kerberos authentication method.
[0077] S2.3. The client receives the authentication data sent by the server and performs client verification.
[0078] S2.4. After the client identity authentication is passed, the client distributes the server's Elasticsearch authentication subject information to the key distribution center KDC. The key distribution center KDC authenticates the identity of both the client and the server.
[0079] The specific implementation method is: the client instantiates a LoginContext authentication context instance by calling javax.security.auth.login.LoginContext, and then distributes the server's Elasticsearch authentication subject information to the key distribution center KDC by calling the login method of LoginContext, requesting the key distribution center KDC to authenticate the identity of both the client and the server.
[0080] S2.5. The ticket authorization service center finds the corresponding client authentication identifier and authorization ticket voucher ticket from the database of the ticket authorization service center according to the authentication subject of the server; the authorization ticket voucher ticket is the permission voucher for the client to access the server. The authorization ticket voucher ticket is the only way to access the server, and the authorization ticket voucher ticket includes the client authentication subject and the timestamp of the time when the authorization ticket voucher ticket is obtained.
[0081] S2.6. After receiving the authorization ticket, the server obtains the client information through decryption and compares the client information with the client authentication identifier obtained from the system table. If they are the same, the access is successful, otherwise the access fails.
[0082] In this embodiment, step S2.6 specifically includes: the client creates a Context context to save the ticket data by introducing the Subject.doAs method in GSSAPI, obtains an authorization ticket voucher ticket through the initSecContext method and sends it to the server; after receiving the authorization ticket voucher ticket, the server verifies the received authorization ticket voucher ticket, that is, obtains the client information through decryption, compares the client information with the client authentication identifier obtained from the system table, if they are the same, the access is successful, otherwise the access fails. And the server generates a new authorization ticket voucher ticket for communication, and sends the new authorization ticket voucher ticket to the client. In this way, the two-way authentication between the client and the server can be completed without going through the authentication server.
[0083] S2.7, the client sets up an authorization ticket voucher ticket cache mechanism, and within a certain period of time, the server can be accessed without verification by using the authorization ticket voucher ticket. The certain period of time refers to the validity period of the ticket distributed by the customized TGS after the first successful authentication of the legal identity information. That is, within the validity period of the ticket distributed by the customized TGS, the client directly obtains the authorization ticket voucher ticket based on the Context context, and accesses the server without verification by using the authorization ticket voucher ticket, completing the two-way authentication between the client and the server.
[0084] The method provided in this embodiment implements the solution of connecting Elasticsearch to Kerberos security authentication by utilizing the NetworkPlugin interface provided by the Elasticsearch network plug-in, thereby eliminating the risk of user information leakage when initiating an Elasticsearch access request, and deeply combining and utilizing the Kerberos ticket cache mechanism. After the first authentication is successful, the effective duration of the ticket distributed by TGS is customized. When high-concurrency access requests are made, the ticket information obtained by the first authentication can be used to log in to the server without authentication in a short period of time, thereby avoiding repeated user authentication in a short period of time, and reducing the number of repeated authentications of access requests initiated by the client in a short period of time, thereby greatly improving the data security and performance issues in the process of using Elasticsearch retrieval services, making up for the deficiencies in data security of open source network security plug-ins related to Elasticsearch (such as: x-pack, search guard), and greatly improving data security and the performance of authentication requests when using Elasticsearch in massive data business scenarios, and having extremely high practical value.
[0085] Although the embodiments disclosed in the present invention are as above, the above contents are only embodiments adopted for facilitating the understanding of the present invention and are not intended to limit the present invention. Any technician in the technical field to which the present invention belongs can make any modifications and changes in the form and details of the implementation without departing from the spirit and scope disclosed in the present invention, but the patent protection scope of the present invention shall still be subject to the scope defined in the attached claims.
Claims
1. A method for implementing Elasticsearch connection Kerberos security authentication, characterized in that: Applied to a client, the method comprises: Send the access request containing user information to the server; Receive authentication data sent by the server, and perform identity authentication based on the authentication data, wherein the authentication data is the authentication data obtained by parsing the request header of the user information of the access request by the server, and marking the authentication data if the request header has a corresponding Kerberos authentication method; If the identity authentication is successful, the authentication subject information pre-created on the server is distributed to the key distribution center KDC, so that the client and server can authenticate their legal identity information through the key distribution center KDC; Receive the authorization ticket voucher ticket returned by the key distribution center KDC, where the authorization ticket voucher ticket is the corresponding authorization ticket voucher ticket found by the ticket authorization service center from the database of the ticket authorization service center according to the Elasticsearch authentication subject information of the server; the authorization ticket voucher ticket is used as the permission voucher for the client to access the server; The server is accessed according to the authorization ticket. If the access is successful, a connection is established with the server.
2. The method for implementing Elasticsearch connection Kerberos security authentication according to claim 1, characterized in that: Also includes: Set up an authorization ticket credential ticket cache mechanism. Within a certain period of time, access to the server with the authorization ticket credential ticket can be performed without verification. The certain period of time refers to the validity period of the ticket distributed by the custom TGS after the first successful authentication of the legal identity information.
3. The method for implementing Elasticsearch connection Kerberos security authentication according to claim 1, characterized in that: If the request header begins with Negotiate, the request header corresponds to the Kerberos authentication method.
4. The method for implementing Elasticsearch connection Kerberos security authentication according to claim 1, characterized in that: The method of distributing the authentication subject information pre-created on the server to the key distribution center KDC so as to authenticate the identity and legal information of the client and the server through the key distribution center KDC includes: Instantiate a LoginContext authentication context instance by calling javax.security.auth.login.LoginContext; By calling the login method of LoginContext, the server's Elasticsearch authentication subject information is distributed to the key distribution center KDC, and the key distribution center KDC is requested to authenticate the identity legality information of both the client and the server.
5. The method for implementing Elasticsearch connection Kerberos security authentication according to claim 1, characterized in that: Also includes: By introducing the Subject.doAs method in GSSAPI, a Context is created to save the ticket data; Get an authorization ticket through the initSecContext method and send it to the server; A new authorization ticket voucher ticket fed back by the server is received, where the new authorization ticket voucher ticket is a new authorization ticket voucher ticket generated by the server for communication.
6. The method for implementing Elasticsearch connection Kerberos security authentication according to claim 2, characterized in that: Also includes: Within the validity period of the ticket distributed by the custom TGS, the authorization ticket voucher ticket is directly obtained based on the Context context, and the server is accessed without verification with the authorization ticket voucher ticket.
7. The method for implementing Elasticsearch connection Kerberos security authentication according to claim 1, characterized in that: The authorization ticket is the only way to access the server. The authorization ticket includes Elasticsearch authentication subject information and a timestamp of when the authorization ticket is obtained.
8. A method for implementing Elasticsearch connection Kerberos security authentication, characterized in that: Applied to the server, the method includes: Receive access requests from clients that carry user information; Read and parse the request header of the user information of the access request, and if the request header has a corresponding Kerberos authentication method, mark the authentication data, and send the marked authentication data to the client; After receiving the authorization ticket from the client, the authorization ticket is decrypted to obtain the client information, and the client information is compared with the client authentication identifier obtained from the system table. If they are the same, the access is successful, otherwise the access fails.
9. The method for implementing Elasticsearch connection Kerberos security authentication according to claim 8, characterized in that: The receiving the access request carrying the user information sent by the client includes: Receive access requests by overriding the HttpChannelHandler method in the NetworkPlugin interface provided by the Elasticsearch network plug-in.
10. The method for implementing Elasticsearch connection Kerberos security authentication according to claim 8, characterized in that: Also includes: Rewrite the channelRead method in ChannelInboundHandlerAdapter to read the user information of the received access request.
11. The method for implementing Elasticsearch connection Kerberos security authentication according to claim 8, characterized in that: Also includes: After receiving the authorization ticket, the received authorization ticket is verified, and a new authorization ticket is generated for communication, and the new authorization ticket is sent to the client.
12. The method for implementing Elasticsearch connection Kerberos security authentication according to claim 8, characterized in that: The marked authentication data includes a request header of a Kerberos authentication mark set by an authentication subject at the server end.
13. The method for implementing Elasticsearch connection Kerberos security authentication according to claim 8, characterized in that: Before the legal identity information is authenticated, it also includes: Connect to the ticket authorization service and Kerberos authentication method components, and create Elasticsearch authentication subject information and user-password files; Configure the relevant parameters of security authentication, including the https protocol related certificate files, Elasticsearch authentication subject information, and the path of the user-password file; Store the user-password file in the specified path according to the path where the user-password file is located.
14. An implementation system for connecting Elasticsearch to Kerberos security authentication, characterized in that: include: A client, configured to execute the method according to any one of claims 1 to 7; The server is used to execute the method as described in any one of claims 8 to 13.
