API gateway parameter verification and service fuse system and method
Through the combination of CNN+LSTM+DNN hybrid model and decision tree regression model, the API gateway parameter verification and service circuit breaker are closely combined, which solves the problem of isolated processing of parameter verification and circuit breaker mechanism in the existing technology, and improves the security of the system. and stability, realizing intelligent control of the entire process.
Patent Information
- Application Number
- CN202410793069.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-19
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2044-06-19
AI Technical Summary
The existing API gateway lacks interaction and coordination in parameter verification and service circuit breaker, resulting in low efficiency and inability to fully utilize the potential capabilities of both, which may lead to potential service abuse or attack behavior, endangering system security and resource exhaustion.
A parameter verification model built with a mixture of CNN+LSTM+DNN, combined with the circuit breaker threshold and service grading model of the decision tree and regression model, forms a complete management and control chain, realizing intelligent control of the entire process from parameters to services to circuit breaker strategies, and closely Combined with parameter verification and service circuit breaker mechanism.
Through the automatic learning ability to identify abnormal parameters and strong response capabilities, the service circuit breaker mechanism can be triggered in advance to prevent potential service abuse or attacks, improve the security and stability of the system, and make the service more reliable, safe and efficient.
Smart Images

Figure CN118573453B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of information technology, and more specifically, to a parameter verification and service fuse system and method for an API gateway. Background Art
[0002] In modern software architecture, especially in the microservices environment, API gateways, as an important part of the system, undertake multiple functions such as traffic routing, service aggregation, authentication and authorization, and security protection. With the increase in services and users, the challenges faced by API gateways are also increasing, especially in parameter verification and service stability.
[0003] In a multi-service system, the API gateway is often the only entry point for external requests to access internal services. Although this architectural pattern simplifies the direct interaction between the client and each microservice and improves the overall security of the system, it also makes the API gateway a potential security risk point. Invalid or malicious request parameters may cause abnormalities in the backend service and even trigger security vulnerabilities. Therefore, strengthening the parameter verification mechanism of the API gateway can not only prevent illegal data from entering the system, but also identify and prevent potential attacks in advance. Service fuse is a common microservice protection mechanism designed to prevent the spread of service failures. In a microservice architecture, the dependencies between services are complex, and the failure of a single service may cause a chain reaction and affect the availability of the entire system. The service fuse mechanism provides the system with the ability to protect itself by temporarily interrupting services that may have problems. This not only helps to limit the scope of the problem, but also improves the recovery speed and stability of the system to a certain extent.
[0004] Although parameter validation and service circuit breaking each play a key role in the API gateway, traditional implementations usually handle the two separately, lacking sufficient interaction and collaboration.
[0005] The existing Chinese patent with publication number CN112187724A discloses an access control method, device, gateway, client and security token service. The client sends an API access request to the gateway. The API access request contains parameters for requesting signature verification and parameters for permission identification. Therefore, after the gateway receives the API access request, it can directly perform request signature verification according to the parameters for requesting signature verification carried in the API access request, and perform permission identification according to the parameters for permission identification. There is no need to access the database to obtain the required parameters, which reduces the network I / O and database query time. If the request signature verification passes and the permission identification passes, the gateway forwards the API access request to the corresponding business line interface, thereby improving the access efficiency of the API.
[0006] The existing Chinese patent with publication number CN114363153A discloses an adaptive fusing method for fuses and services, which relates to the field of information technology. The fuse of the upstream service predicts the service status of the downstream service according to the response time of the downstream service using the Markov chain model, and controls the communication between the upstream service and the downstream service according to the predicted service status of the downstream service, so that the fuse has autonomous capabilities, the fusing mechanism is activated more timely, the stability of the service system is improved, and the performance or availability of the system is avoided from being reduced due to unreasonable timeout setting.
[0007] The above patent implements the isolated processing of parameter verification and service circuit breaking, which may lead to inefficiency and fail to fully utilize the potential capabilities of both. For example, an effective parameter verification system can identify potential high-risk or malicious requests before the request enters the service. If it can be closely integrated with the circuit breaking mechanism, it will further enhance the security and stability of the service.
[0008] In view of the above background, it is particularly important to develop an API gateway system that integrates efficient parameter verification and intelligent service circuit breaking. If the system cannot trigger the service circuit breaking mechanism in advance when it identifies high-risk requests during the parameter verification stage, it may encounter potential service abuse or attack behaviors, which will quickly exhaust system resources and make normal users unable to access services. In serious cases, it may endanger system security and cause economic losses. Summary of the invention
[0009] In order to solve the problems existing in the above background technology, the present invention provides a parameter verification and service fuse system and method for an API gateway, the method comprising:
[0010] Collect parameter samples of API requests and service call parameters;
[0011] Input API request parameter samples to the annotation of pre-built parameter validation model output parameter samples;
[0012] Determine whether to grant permission to the API request based on the annotation of the parameter sample;
[0013] Input parameter sample annotations and service call parameters to the pre-built fuse threshold model to output safety thresholds;
[0014] Input the parameter samples of API requests into the pre-built service grading model to output the service rating;
[0015] Input the service rating and safety threshold into the pre-built circuit breaker activation model to output the activation code.
[0016] Furthermore, parameter samples include parameter type, parameter name, parameter value range, parameter format and parameter mandatory; annotations of parameter samples include normal, type mismatch, injection attack, value out of bounds, malformed data and missing mandatory fields; service call parameters include error rate and response time.
[0017] Furthermore, the structure of the parameter verification model is a hybrid construction of CNN+LSTM+DNN, and the parameter verification model structure of the hybrid construction of CNN+LSTM+DNN includes a CNN module, a LSTM module and a DNN module;
[0018] Among them, the CNN module includes the first input layer, two convolutional layers, two pooling layers and the first output layer; the input form of the first input layer is a one-dimensional sequence; the two convolutional layers include the first convolutional layer and the second convolutional layer, the convolution kernel size of the two convolutional layers is 1×3, the activation function is ReLU, the depth of the first convolutional layer is 32, and the depth of the second convolutional layer is 64; the two pooling layers include the first pooling layer and the second pooling layer, the window size of the two pooling layers is 2, and the step size is 2; the output of the first output layer is a one-dimensional vector sequence, and the number of channels of the one-dimensional vector sequence is 64;
[0019] The LSTM module includes the second input layer, the LSTM layer and the second output layer. The input of the second input layer is the one-dimensional vector sequence output by the CNN module. The hidden state dimension of the LSTM layer is set to 64. The LSTM includes LSTM units, which include input gates, candidate unit states, recurrent units, forget gates and output gates. The activation functions of the input gate, forget gate and output gate are all sigmoid, and the activation function of the candidate unit state is tanh. The hidden state dimension of the second output layer is 64, and the output is the hidden state vector of the last time sequence step.
[0020] The DNN module includes the third input layer, the first hidden layer, the second hidden layer and the third output layer; the third input layer concatenates the one-dimensional vector sequence output by the CNN module with the hidden state vector output by the LSTM module, that is, the number of input nodes of the third input layer is 128; the number of nodes in the first hidden layer is 256, and the activation function is ReLU; the number of nodes in the second hidden layer is 256, and the activation function is ReLU, and dropout is added, and the dropout rate is 0.5; the number of nodes in the third output layer is 6, and the activation function is Softmax.
[0021] Furthermore, the training method of the parameter verification model includes:
[0022] Select N groups of parameter samples and the annotations corresponding to the parameter samples from the background log to form a training set; initialize the weight of the parameter verification model, the weight of the parameter verification model is the preset value, forward propagation calculates the loss function loos, backward propagation calculates the gradient, set the optimizer Adam to update the network weight parameter verification model weight, repeat the training until the loss function converges, and the parameter verification model training is completed;
[0023] Among them, the calculation formula of the loss function loos includes:
[0024]
[0025] In the formula, y i is the true probability of the annotation corresponding to the parameter sample of the i-th group; p i is the predicted probability of the annotation corresponding to the i-th group of parameter samples; ε is the preset value; i≤N.
[0026] Furthermore, the method for determining whether to grant the API request permission based on the annotation of the parameter sample includes:
[0027] When the parameter sample is marked as normal, the API request is granted permission;
[0028] When the parameter sample is not labeled as normal, the API request is denied permission and an error report is sent to the backend.
[0029] Furthermore, the method for constructing the fuse threshold model includes:
[0030] Convert the annotations of each set of parameter samples and the service call parameters into the form of a first feature vector, where the elements of the first feature vector include normal, type mismatch, injection attack, value out of bounds, deformed data, missing required fields, error rate, and response time;
[0031] The set of all first feature vectors is used as the input of a fuse threshold model, wherein the fuse threshold model uses the safety threshold predicted for each group of first feature vectors as the output, uses the actual safety threshold corresponding to each group of first feature vectors as the prediction target, and uses minimizing the sum of the first prediction accuracies of all predicted safety thresholds as the training target;
[0032] Among them, the calculation formula for the first prediction accuracy is: K d =(Z d -Q d ) 2 , where K d is the first prediction accuracy, Z d is the predicted safety threshold corresponding to the annotation of the dth group of parameter samples and the service call parameters, Q dis the actual safety threshold corresponding to the annotation of the dth group of parameter samples and the service call parameter; the fuse threshold model is trained until the sum of the first prediction accuracy reaches convergence and the training is stopped; d is the group number of the first feature vector; the fuse threshold model is any one of a decision tree and a random forest;
[0033] Furthermore, service ratings include 11, 12, and 13; the activation code is 0 or 1, 0 means not activating the fuse mechanism, and 1 means activating the fuse mechanism; 13 is core service, 12 is general service, and 11 is non-core service.
[0034] Furthermore, the method for constructing the service classification model includes:
[0035] Convert the parameter samples of each group of API requests into the form of a second feature vector, where the elements of the second feature vector include parameter type, parameter name, parameter value range, parameter format, and parameter mandatory;
[0036] The set of all second feature vectors is used as the input of the service grading model, the service grading model takes the service rating predicted for each group of second feature vectors as the output, takes the actual service rating corresponding to each group of second feature vectors as the prediction target, and takes minimizing the sum of the second prediction accuracies of all predicted service ratings as the training target;
[0037] Among them, the calculation formula for the second prediction accuracy is: T r =(S r -V r ) 2 , where T r is the second prediction accuracy, S r is the predicted service rating corresponding to the parameter sample of the rth group of API requests, V r is the actual service rating corresponding to the parameter sample of the rth group of API requests; the service classification model is trained until the sum of the second prediction accuracy reaches convergence and the training is stopped; the service classification model is any one of a regression model and a decision tree.
[0038] Furthermore, the method for constructing the fuse initiation model includes:
[0039] Collect c groups of service ratings and start codes corresponding to security thresholds in advance, and convert the service ratings, security thresholds and corresponding start codes into a corresponding set of feature vectors;
[0040] Each set of feature vectors is used as the input of the fuse activation model. The fuse activation model uses a set of activation codes corresponding to each set of service ratings and safety thresholds as output, and uses the actual activation codes corresponding to each set of service ratings and safety thresholds as prediction targets. The actual activation codes are the activation codes corresponding to the service ratings and safety thresholds collected in advance. The training target is to minimize the sum of the prediction errors of all service ratings and safety thresholds. The calculation formula for the prediction error is df rh =(dr h -dx h ) 2 , where df rh is the prediction error, h is the group number of the feature vector corresponding to the service rating and the safety threshold, dr h is the start code corresponding to the service rating and safety threshold of the hth group, dx h The actual startup code corresponding to the service rating and safety threshold of the hth group is trained for the fuse startup model until the sum of the prediction errors reaches convergence and the training is stopped.
[0041] API Gateway parameter verification and service fuse system, the system includes:
[0042] Collection module: collects parameter samples of API requests and service call parameters;
[0043] Parameter verification module: inputs parameter samples of API requests to the pre-built parameter verification model and outputs annotations of parameter samples;
[0044] API request authorization module: determines whether to grant API request permission based on the annotation of parameter samples;
[0045] Fuse threshold generation module: input parameter sample annotations and service call parameters to the pre-built fuse threshold model to output the safety threshold;
[0046] Service grading module: inputs the parameter samples of API requests into the pre-built service grading model to output the service rating;
[0047] Execution module: Inputs the service rating and security threshold into the pre-built circuit breaker activation model and outputs the activation code.
[0048] The technical effects and advantages of the parameter verification and service fuse system and method of the API gateway optimized by deep reinforcement learning provided by the present invention are as follows:
[0049] Technical effect:
[0050] The parameter verification model constructed using CNN+LSTM+DNN can capture the timing and structural dependencies of parameters and effectively identify abnormal parameters; the service classification model and circuit breaker threshold model use algorithms such as regression and decision trees to learn implicit relationships and automatically complete classification and prediction tasks; the various models are connected to form a complete management and control chain to achieve full-process intelligent control from parameters to services to circuit breaker strategies; combining parameter verification and service circuit breaker can trigger the service circuit breaker mechanism in advance to prevent potential service abuse or attacks.
[0051] advantage:
[0052] It has strong automatic learning capabilities and does not require additional rules from humans. It can automatically extract dependencies from large amounts of data. It has strong recognition and response capabilities, and multi-model collaboration can cover multiple aspects from parameters to services. It has good scalability, and models can be added, deleted, and adjusted according to business needs, and the system is loosely coupled in design. It has low costs and is driven by existing tracking points and monitoring data without the need for additional investment. It has continuous optimization, and online model training can continuously learn new changes and optimization strategies. Parameter verification can be closely integrated with the circuit breaker mechanism to further enhance the security and stability of the service, making the service more reliable, safer, and more efficient. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] Figure 1 This is a flow chart of the parameter verification and service fuse method of the API gateway in Example 1;
[0054] Figure 2 This is a flow chart of the parameter verification and service fuse method of the API gateway in Example 2;
[0055] Figure 3 It is a schematic diagram of the structure principle of the parameter verification and service fuse system of the API gateway;
[0056] Figure 4 is a schematic diagram of an electronic device of the present invention;
[0057] Figure 5 Schematic diagram of the storage medium of the present invention. DETAILED DESCRIPTION
[0058] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0059] Example 1
[0060] See also Figure 1As shown, the parameter verification and service fuse method of the API gateway described in this embodiment includes:
[0061] Collect API request parameter samples and service call parameters.
[0062] Input the parameter samples requested by the API to the pre-built parameter verification model to output the annotation of the parameter samples.
[0063] Determine whether to grant permission to the API request based on the annotation of the parameter sample.
[0064] The annotations of the input parameter samples and the service call parameters are input to the pre-built fuse threshold model to output the safety threshold, and the fuse mechanism is determined based on the safety threshold.
[0065] Parameter samples include parameter type, parameter name, parameter value range, parameter format and parameter mandatory. Parameter samples can be collected through various collection methods such as interface collection, proxy reverse collection and interceptor collection. Parameter sample annotations include normal, type mismatch, injection attack, value out of range, deformed data and missing required fields. Through parameter type, illegal patterns of type mismatch can be identified, such as id parameter submitted as a string. According to the parameter name, it can be determined whether there are special parameters added by injection attacks, such as order Id injected in the middle of SQL statement. According to the parameter value range, illegal pattern parameters with value out of range can be identified, such as attack behavior where id is greater than the maximum range of 1000. According to the parameter format, deformed data that does not conform to the format can be detected, such as anomalies caused by date parameters not being in standard format. According to the mandatory parameter rules of parameter mandatory, data combination attacks with missing required fields can be identified, such as user information missing the username field.
[0066] Service call parameters include error rate and response time; service call parameters are obtained from the API gateway. If the error rate of requests received by a service exceeds the preset threshold within a time window, it can be judged that there is a problem with the service and a circuit breaker is required; if the interface response time of a service is higher than the response time threshold, a circuit breaker will be triggered; security thresholds include error rate thresholds, response time thresholds and time windows.
[0067] The structure of the parameter verification model is a hybrid of CNN+LSTM+DNN. Because the parameter sample contains the dependency between the specific attribute value of the parameter sample and the attribute of the parameter sample, CNN is required to learn the specific attribute value itself, and LSTM is required to learn the dependency between the attributes. For example, CNN can identify parameter samples whose types do not match the definition by learning the parameter type, and LSTM can discover the special parameters added by the injection attack by learning the order of the parameter names and the context of the parameter names. The parameter verification model structure of the hybrid of CNN+LSTM+DNN includes a CNN module, a LSTM module and a DNN module.
[0068] Among them, the CNN module includes the first input layer, two convolutional layers, two pooling layers and the first output layer; the input form of the first input layer is a one-dimensional sequence; the two convolutional layers include the first convolutional layer and the second convolutional layer, the convolution kernel size of the two convolutional layers is 1×3, the activation function is ReLU, the depth of the first convolutional layer is 32, and the depth of the second convolutional layer is 64; the two pooling layers include the first pooling layer and the second pooling layer, the window size of the two pooling layers is 2, and the step size is 2; the output of the first output layer is a one-dimensional vector sequence, and the number of channels of the one-dimensional vector sequence is 64.
[0069] It is specially noted that the initial input parameter samples have only attribute dimensions because they have not undergone convolution and pooling of CNN. The attribute dimensions represent the characteristic dimensions of the specific attribute values of each parameter sample. For example, if the parameter sample is a digital sequence, then the attribute dimension is 1. If the parameter sample is a categorical variable sequence, such as the parameter mandatory code is 0 or 1, then the attribute dimension is 2, that is, the number of categories. If the parameter sample is text, such as the parameter name, then the attribute dimension is the length of the word vector. After convolution and pooling of CNN, there is a vector dimension, and the parameter sample has a classification, that is, it becomes a one-dimensional vector sequence.
[0070] The LSTM module includes a second input layer, an LSTM layer and a second output layer. The input of the second input layer is a one-dimensional vector sequence output by the CNN module. The hidden state dimension of the LSTM layer is set to 64. The LSTM includes an LSTM unit, and the LSTM unit includes an input gate, a candidate unit state, a recurrent unit, a forget gate and an output gate. The activation functions of the input gate, the forget gate and the output gate are all sigmoid, and the activation function of the candidate unit state is tanh. The hidden state dimension of the second output layer is 64, and the output is the hidden state vector of the last sequential step.
[0071] It is particularly important to note that the number of LSTM units is not fixed. LSTM units are generated and updated autonomously by computers. The number of LSTM units depends on the sequence length of the one-dimensional vector sequence of the input layer.
[0072] The DNN module includes the third input layer, the first hidden layer, the second hidden layer and the third output layer; the third input layer concatenates the one-dimensional vector sequence output by the CNN module with the hidden state vector output by the LSTM module, that is, the number of input nodes of the third input layer is 128; the number of nodes in the first hidden layer is 256, and the activation function is ReLU; the number of nodes in the second hidden layer is 256, and the activation function is ReLU, and dropout is added, and the dropout rate is 0.5; the number of nodes in the third output layer is 6, and the activation function is Softmax.
[0073] The training method of the parameter verification model includes:
[0074] Select N groups of parameter samples and the corresponding annotations of the parameter samples from the background log to form a training set; initialize the weight of the parameter verification model, the weight of the parameter verification model is the preset value, forward propagation calculates the loss function loos, backward propagation calculates the gradient, set the optimizer Adam to update the network weight parameter verification model weight, repeat the training until the loss function converges, and the parameter verification model is completed.
[0075] Among them, the calculation formula of the loss function loos includes:
[0076]
[0077] In the formula, y i is the true probability of the annotation corresponding to the parameter sample of the i-th group; p i is the predicted probability of the annotation corresponding to the i-th group of parameter samples; ε is a preset value used to prevent underflow; i≤N.
[0078] The method for determining whether to grant the API request permission based on the annotation of the parameter sample includes:
[0079] When the parameter sample is marked as normal, the API request is granted permission.
[0080] When the parameter sample is not labeled as normal, the API request is denied permission and an error report is sent to the backend.
[0081] The method for constructing the fuse threshold model includes:
[0082] The annotations and service call parameters of each set of parameter samples are converted into the form of a first feature vector. The elements in the first feature vector include normal, type mismatch, injection attack, value out of bounds, deformed data, missing required fields, error rate and response time.
[0083] The set of all first feature vectors is used as the input of the fuse threshold model. The fuse threshold model takes the predicted safety threshold for each group of first feature vectors as output, takes the actual safety threshold corresponding to each group of first feature vectors as the prediction target, and takes minimizing the sum of the first prediction accuracies of all predicted safety thresholds as the training target.
[0084] Among them, the calculation formula for the first prediction accuracy is: K d =(Z d -Q d ) 2 , where K d is the first prediction accuracy, Z d is the predicted safety threshold corresponding to the annotation of the dth group of parameter samples and the service call parameters, Q d is the actual safety threshold corresponding to the annotation of the dth group of parameter samples and the service call parameters; the fuse threshold model is trained until the sum of the first prediction accuracy reaches convergence and the training is stopped; d is the group number of the first feature vector; the fuse threshold model is any one of a decision tree and a random forest.
[0085] Methods for determining whether to activate the fuse mechanism based on the safety threshold include:
[0086] When the request error rate received by a service exceeds the error rate threshold within a time window, the circuit breaker mechanism is activated.
[0087] When the interface response time of a service is higher than the response time threshold, the fuse mechanism is activated.
[0088] The formulas involved in the above are all dimensionless and numerical calculations. They are a formula closest to the actual situation obtained by collecting a large amount of data and performing software simulation. During the analysis process, each preset value is set by a technician in this field according to the actual situation or obtained by simulating a large amount of data.
[0089] Example 2
[0090] like Figure 2 As shown, this embodiment further improves the design on the basis of Embodiment 1. The difference is that the parameter verification and service fuse method of the API gateway provided in this embodiment is too direct in the actual application for judging the start of the fuse mechanism. Although the overall security is improved, the possibility of erroneous fuses is also increased. When the number of erroneous fuses increases, system delays will occur. The importance and fault tolerance of the service should be graded to form a multi-level fuse mechanism. Based on this, the parameter verification and service fuse method of the API gateway provided in this embodiment also includes:
[0091] Input the parameter samples of the API request into the pre-built service grading model to output the service rating.
[0092] Input the service rating and safety threshold into the pre-built circuit breaker activation model to output the activation code.
[0093] The parameter samples of API requests affect the service rating. For example, key business-related names, such as user ID, indicate that the service is of high importance and the higher the rating, while general names indicate that the service is of relatively low importance and the lower the rating. Service ratings include 11, 12, and 13. The startup code is 0 or 1, 0 means not starting the fuse mechanism, and 1 means starting the fuse mechanism. 13 is for core services, 12 is for general services, and 11 is for non-core services. The judgment conditions for starting the fuse for core services can be relaxed. For example, when the time window for core services can be twice that for non-core services, the error rate threshold within this twice-time window can be one time that for non-core services, but the total value of the error rate threshold does not exceed 1. The judgment conditions for general services are between the judgment conditions for starting the fuse for core services and the judgment conditions for starting the fuse for non-core services.
[0094] The method for constructing the service classification model includes:
[0095] The parameter samples of each group of API requests are converted into the form of a second feature vector, and the elements in the second feature vector include parameter type, parameter name, parameter value range, parameter format and parameter mandatory.
[0096] The set of all second feature vectors is used as the input of the service classification model, the service classification model takes the predicted service rating for each group of second feature vectors as output, takes the actual service rating corresponding to each group of second feature vectors as the prediction target, and takes minimizing the sum of the second prediction accuracies of all predicted service ratings as the training target.
[0097] Among them, the calculation formula for the second prediction accuracy is: T r =(S r -V r ) 2 , where T r is the second prediction accuracy, S r is the predicted service rating corresponding to the parameter sample of the rth group of API requests, V r is the actual service rating corresponding to the parameter sample of the rth group of API requests; the service grading model is trained until the sum of the second prediction accuracies reaches convergence and the training is stopped; r is the group number of the second feature vector; the service grading model is any one of a regression model and a decision tree.
[0098] The method for constructing the fuse initiation model includes:
[0099] C groups of service ratings and start codes corresponding to security thresholds are collected in advance, and the service ratings, security thresholds and corresponding start codes are converted into a corresponding set of feature vectors.
[0100] Each set of feature vectors is used as the input of the fuse activation model. The fuse activation model uses a set of activation codes corresponding to each set of service ratings and safety thresholds as output, and uses the actual activation codes corresponding to each set of service ratings and safety thresholds as prediction targets. The actual activation codes are the activation codes corresponding to the service ratings and safety thresholds collected in advance. The training target is to minimize the sum of the prediction errors of all service ratings and safety thresholds. The calculation formula for the prediction error is df rh =(dr h -dx h ) 2 , where df rh is the prediction error, h is the group number of the feature vector corresponding to the service rating and the safety threshold, dr h is the start code corresponding to the service rating and safety threshold of the hth group, dx h The actual startup code corresponding to the service rating and safety threshold of the hth group is trained for the fuse startup model until the sum of the prediction errors reaches convergence and the training is stopped.
[0101] Example 3
[0102] like Figure 3 As shown, the parameter verification and service fuse system of the API gateway includes:
[0103] Collection module: collects parameter samples of API requests and service call parameters.
[0104] Parameter validation module: Input the parameter sample of the API request to the pre-built parameter validation model and output the annotation of the parameter sample.
[0105] API request authorization module: determines whether to grant API request permission based on the annotation of parameter samples.
[0106] Circuit breaker threshold generation module: input parameter sample annotations and service call parameters to the pre-built circuit breaker threshold model to output the safety threshold.
[0107] Service grading module: Inputs parameter samples of API requests into the pre-built service grading model to output service ratings.
[0108] Execution module: Inputs the service rating and security threshold into the pre-built circuit breaker activation model and outputs the activation code.
[0109] Example 4
[0110] See also Figure 4As shown, the present application also provides an electronic device 500. The electronic device 500 may include one or more processors and one or more memories. The memories store computer readable codes, and when the computer readable codes are executed by one or more processors, the parameter verification and service fuse method of the API gateway as described above may be executed.
[0111] The system according to the embodiment of the present application can also be used by Figure 4 The electronic device architecture shown in FIG. Figure 4 As shown, the electronic device 500 may include a bus 501, one or more CPUs 502, ROM 503, RAM 504, a communication port 505 connected to a network, an input / output 506, a hard disk 507, etc. The storage device in the electronic device 500, such as ROM 503 or hard disk 507, may store the parameter verification and service fuse method of the API gateway provided in this application. Furthermore, the electronic device 500 may also include a user interface 508. Of course, Figure 4 The architecture shown is only exemplary and can be omitted according to actual needs when implementing different devices. Figure 4 One or more components of an electronic device are shown.
[0112] Example 5
[0113] See also Figure 5 As shown, it is a computer-readable storage medium according to an embodiment of the present application. Computer-readable instructions are stored on the computer-readable storage medium. When the computer-readable instructions are executed by the processor, the parameter verification and service fuse method of the API gateway according to the embodiment of the present application described with reference to the above figures can be executed. The storage medium includes, but is not limited to, for example, volatile memory and / or non-volatile memory. Volatile memory may include, for example, random access memory (RAM) and cache memory (cache), etc. Non-volatile memory may include, for example, read-only memory (ROM), hard disk, flash memory, etc.
[0114] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
[0115] Finally: The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. API gateway parameter verification and service fuse method, characterized in that: Methods include: Collect parameter samples of API requests and service call parameters; Input API request parameter samples to the annotation of pre-built parameter validation model output parameter samples; Determine whether to grant permission to the API request based on the annotation of the parameter sample; Input parameter sample annotations and service call parameters to the pre-built fuse threshold model to output safety thresholds; Input the parameter samples of API requests into the pre-built service grading model to output the service rating; Input the service rating and safety threshold into the pre-built circuit breaker activation model to output the activation code.
2. According to the parameter verification and service fuse method of the API gateway of claim 1, it is characterized in that: Parameter samples include parameter type, parameter name, parameter value range, parameter format and parameter mandatory field; parameter sample annotations include normal, type mismatch, injection attack, value out of bounds, malformed data and missing mandatory fields; service call parameters include error rate and response time.
3. The parameter verification and service fuse method of the API gateway according to claim 2 is characterized in that: The structure of the parameter verification model is a hybrid construction of CNN+LSTM+DNN, and the parameter verification model structure of the hybrid construction of CNN+LSTM+DNN includes a CNN module, a LSTM module and a DNN module; Among them, the CNN module includes the first input layer, two convolutional layers, two pooling layers and the first output layer; the input form of the first input layer is a one-dimensional sequence; the two convolutional layers include the first convolutional layer and the second convolutional layer, the convolution kernel size of the two convolutional layers is 1×3, the activation function is ReLU, the depth of the first convolutional layer is 32, and the depth of the second convolutional layer is 64; the two pooling layers include the first pooling layer and the second pooling layer, the window size of the two pooling layers is 2, and the step size is 2; the output of the first output layer is a one-dimensional vector sequence, and the number of channels of the one-dimensional vector sequence is 64; The LSTM module includes the second input layer, the LSTM layer and the second output layer. The input of the second input layer is the one-dimensional vector sequence output by the CNN module. The hidden state dimension of the LSTM layer is set to 64. The LSTM includes LSTM units, which include input gates, candidate unit states, recurrent units, forget gates and output gates. The activation functions of the input gate, forget gate and output gate are all sigmoid, and the activation function of the candidate unit state is tanh. The hidden state dimension of the second output layer is 64, and the output is the hidden state vector of the last time sequence step. The DNN module includes the third input layer, the first hidden layer, the second hidden layer and the third output layer; the third input layer concatenates the one-dimensional vector sequence output by the CNN module with the hidden state vector output by the LSTM module, that is, the number of input nodes of the third input layer is 128; the number of nodes in the first hidden layer is 256, and the activation function is ReLU; the number of nodes in the second hidden layer is 256, and the activation function is ReLU, and dropout is added, and the dropout rate is 0.5; the number of nodes in the third output layer is 6, and the activation function is Softmax.
4. The parameter verification and service fuse method of the API gateway according to claim 3 is characterized in that: The training method of the parameter verification model includes: Select N groups of parameter samples and the annotations corresponding to the parameter samples from the background log to form a training set; initialize the weight of the parameter verification model, the weight of the parameter verification model is the preset value, forward propagation calculates the loss function loos, backward propagation calculates the gradient, set the optimizer Adam to update the network weight parameter verification model weight, repeat the training until the loss function converges, and the parameter verification model training is completed; Among them, the calculation formula of the loss function loos includes: In the formula, y i is the true probability of the annotation corresponding to the parameter sample of the i-th group; p i is the predicted probability of the annotation corresponding to the i-th group of parameter samples; ε is the preset value; i≤N.
5. The parameter verification and service fuse method of the API gateway according to claim 1 is characterized in that: The method for determining whether to grant the API request permission based on the annotation of the parameter sample includes: When the parameter sample is marked as normal, the API request is granted permission; When the parameter sample is not labeled as normal, the API request is denied permission and an error report is sent to the backend.
6. The parameter verification and service fuse method of the API gateway according to claim 2 is characterized in that: The method for constructing the fuse threshold model includes: Convert the annotations of each set of parameter samples and the service call parameters into the form of a first feature vector, where the elements of the first feature vector include normal, type mismatch, injection attack, value out of bounds, deformed data, missing required fields, error rate, and response time; The set of all first feature vectors is used as the input of a fuse threshold model, wherein the fuse threshold model uses the safety threshold predicted for each group of first feature vectors as the output, uses the actual safety threshold corresponding to each group of first feature vectors as the prediction target, and uses minimizing the sum of the first prediction accuracies of all predicted safety thresholds as the training target; Among them, the calculation formula for the first prediction accuracy is: K d =(Z d -Q d ) 2 , where K d is the first prediction accuracy, Z d is the predicted safety threshold corresponding to the annotation of the dth group of parameter samples and the service call parameters, Q d is the actual safety threshold corresponding to the annotation of the dth group of parameter samples and the service call parameters; the fuse threshold model is trained until the sum of the first prediction accuracy reaches convergence and the training is stopped; d is the group number of the first feature vector; the fuse threshold model is any one of a decision tree and a random forest.
7. The parameter verification and service fuse method of the API gateway according to claim 1 is characterized in that: Service ratings include 11, 12, and 13; the activation code is 0 or 1, 0 means not activating the circuit breaker mechanism, and 1 means activating the circuit breaker mechanism; 13 is core service, 12 is general service, and 11 is non-core service.
8. The parameter verification and service fuse method of the API gateway according to claim 7 is characterized in that: The method for constructing the service classification model includes: Convert each set of API request parameter samples into the form of a second feature vector, where the elements of the second feature vector include parameter type, parameter name, parameter value range, parameter format, and parameter mandatory; The set of all second feature vectors is used as the input of the service grading model, the service grading model takes the service rating predicted for each group of second feature vectors as the output, takes the actual service rating corresponding to each group of second feature vectors as the prediction target, and takes minimizing the sum of the second prediction accuracies of all predicted service ratings as the training target; Among them, the calculation formula for the second prediction accuracy is: T r =(S r -V r ) 2 , where T r is the second prediction accuracy, S r is the predicted service rating corresponding to the parameter sample of the rth group of API requests, V r is the actual service rating corresponding to the parameter sample of the rth group of API requests; r is the group number of the second feature vector; the service grading model is trained until the sum of the second prediction accuracies reaches convergence and the training is stopped; the service grading model is any one of a regression model and a decision tree.
9. The parameter verification and service fuse method of the API gateway according to claim 1 is characterized in that: The method for constructing the fuse initiation model includes: Collect c groups of service ratings and start codes corresponding to security thresholds in advance, and convert the service ratings, security thresholds and corresponding start codes into a corresponding set of feature vectors; Each set of feature vectors is used as the input of the fuse activation model. The fuse activation model uses a set of activation codes corresponding to each set of service ratings and safety thresholds as output, and uses the actual activation codes corresponding to each set of service ratings and safety thresholds as prediction targets. The actual activation codes are the activation codes corresponding to the service ratings and safety thresholds collected in advance. The training target is to minimize the sum of the prediction errors of all service ratings and safety thresholds. The calculation formula for the prediction error is df rh =(dr h -dx h ) 2 , where df rh is the prediction error, h is the group number of the feature vector corresponding to the service rating and the safety threshold, dr h is the start code corresponding to the service rating and safety threshold of the hth group, dx h The actual startup code corresponding to the service rating and safety threshold of the hth group is trained for the fuse startup model until the sum of the prediction errors reaches convergence and the training is stopped.
10. A parameter verification and service fuse system for an API gateway, implementing the parameter verification and service fuse method for an API gateway as described in any one of claims 1 to 9, characterized in that: The system comprises: Collection module: collects parameter samples of API requests and service call parameters; Parameter verification module: inputs parameter samples of API requests to the pre-built parameter verification model and outputs annotations of parameter samples; API request authorization module: determines whether to grant API request permission based on the annotation of parameter samples; Fuse threshold generation module: input parameter sample annotations and service call parameters to the pre-built fuse threshold model to output the safety threshold; Service grading module: inputs the parameter samples of API requests into the pre-built service grading model to output the service rating; Execution module: Inputs the service rating and security threshold into the pre-built circuit breaker activation model and outputs the activation code.
