Key updating method and device, electronic equipment and storage medium

By building and updating the key dictionary of the private image warehouse in the Kubernetes cluster, security and compliance issues caused by key expiration are solved, automatic rotation and timeliness management of keys are realized, and management complexity is reduced.

CN118740375APending Publication Date: 2024-10-01CHONGQING SELIS PHOENIX INTELLIGENT INNOVATION TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202410891607.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-04
Publication Date
2024-10-01

AI Technical Summary

Technical Problem

When using Kubernetes cluster services to pull images from private image warehouses, key expiration may lead to security vulnerabilities, compliance issues and account risks, increasing management complexity.

Method used

By pre-building a dictionary in the kubernetes cluster, including the encoding of the historical user name and historical password of the private image warehouse, obtaining the encoding of the current user name and current password, querying and updating the key, and realizing automatic key rotation and expiration management.

Benefits of technology

Reduce the risk of key leakage, ensure key timeliness, meet compliance and audit requirements, and simplify the key management process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118740375A_ABST
    Figure CN118740375A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of computers, and provides a key updating method and device, electronic equipment and a storage medium. The method comprises the following steps: firstly, pre-constructing a first dictionary comprising second keys of private mirror image warehouses in a kubernetes cluster, then obtaining a target address of a target private mirror image warehouse and a first key of the target private mirror image warehouse, and querying in the first dictionary by using the target address to obtain the first key of the target private mirror image warehouse. And when it is determined that the first code in the first key is different from the second code in the second key, using the first key to update the second key in the first dictionary, and using the updated first dictionary to update the secure object of the kubernetes cluster so as to realize key update of the target private mirror image warehouse. According to the method, automatic credential rotation can be realized, and the key leakage risk is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a key updating method, device, electronic device and storage medium. Background Art

[0002] When using the kubernetes cluster service to pull images from a private image repository, you need to create a secret of the kubernetes.io / dockerconfigjson type as the credential for pulling images, which includes the key of the private image repository. If the key does not expire, there may be security vulnerabilities, compliance issues, account risks and other security risks, and it will increase management complexity. Summary of the invention

[0003] In view of this, the embodiments of the present application provide a key update method, device, electronic device and storage medium to solve the problem of low security of private image repositories in the prior art.

[0004] In a first aspect of an embodiment of the present application, a key update method is provided, the method being used to automatically update a private image repository key in a Kubernetes cluster, the method comprising:

[0005] Periodically obtain a target address of a target private image repository and a first key of the target private image repository, where the first key includes a current user name and a current password of the target private image repository and a first code obtained by encoding the current user name and the current password;

[0006] Use the target address to search in the constructed first dictionary;

[0007] In response to determining that the value of the first dictionary includes the target address, obtaining a second key corresponding to the target address, where the second key includes a historical user name, a historical password, and a second code obtained by encoding the historical user name and the historical password of the target private image repository;

[0008] In response to determining that the first code is different from the second code, updating the second key using the first key to obtain an updated first dictionary;

[0009] Use the updated first dictionary to update the secret object of the target private image repository in the Kubernetes cluster to update the key of the target private image repository.

[0010] A second aspect of an embodiment of the present application provides a key updating device, including:

[0011] An acquisition module is configured to periodically acquire a target address of a target private image repository and a first key of the target private image repository, where the first key includes a current user name and a current password of the target private image repository and a first code obtained by encoding the current user name and the current password;

[0012] A query module, configured to use the target address to query in the constructed first dictionary;

[0013] The acquisition module is further configured to, in response to determining that the value of the first dictionary includes the target address, acquire a second key corresponding to the target address, the second key including a historical user name, a historical password, and a second code obtained by encoding the historical user name and the historical password of the target private image repository;

[0014] an updating module, configured to, in response to determining that the first code is different from the second code, update the second key using the first key to obtain an updated first dictionary;

[0015] The update module is also configured to use the updated first dictionary to update the secret object of the target private image repository in the kubernetes cluster to achieve key update of the target private image repository.

[0016] According to a third aspect of an embodiment of the present application, an electronic device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above method when executing the computer program.

[0017] According to a fourth aspect of an embodiment of the present application, a computer-readable storage medium is provided, which stores a computer program, and when the computer program is executed by a processor, the steps of the above method are implemented.

[0018] Compared with the prior art, the embodiment of the present application has the following beneficial effects: the embodiment of the present application first pre-builds a first dictionary in the kubernetes cluster, the first dictionary includes the historical user name, historical password and the second key formed by the second code obtained by encoding the historical user name and the historical password of each private image repository, then obtains the target address of the target private image repository and the current user name, current password and the first key formed by the first code obtained by encoding the current user name and the current password of the target private image repository, and then uses the target address to query the first dictionary to obtain the first key of the target private image repository, and when it is determined that the first code is different from the second code, uses the first key to update the second key in the first dictionary, and uses the updated first dictionary to update the secret object of the kubernetes cluster to achieve the key update of the target private image repository. This method can realize automatic rotation of credentials and reduce the risk of key leakage.

[0019] Furthermore, you can also set expiration information for the current username and current password in the first key so that the credentials of each private image repository are automatically implemented after the corresponding expiration date. This ensures that even if the key is leaked, its timeliness is limited, and can prevent the security risks brought about by long-term reliance on a single key, meeting compliance and audit requirements. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0021] Figure 1 It is a scenario diagram of an application scenario of an embodiment of the present application.

[0022] Figure 2 It is a flowchart of a key updating method provided in an embodiment of the present application.

[0023] Figure 3 It is a flowchart diagram of a method for obtaining a second key corresponding to a target address in response to a value of a first dictionary including the target address, provided in an embodiment of the present application.

[0024] Figure 4 It is a flowchart of a method for obtaining a second key corresponding to a target address from a third dictionary provided in an embodiment of the present application.

[0025] Figure 5 It is a flowchart of a method for updating a secret object of a target private image repository in a Kubernetes cluster using an updated first dictionary provided in an embodiment of the present application.

[0026] Figure 6 It is a flowchart of a method for constructing a first dictionary provided in an embodiment of the present application.

[0027] Figure 7 It is a schematic diagram of a method for constructing variables in a key updating method provided in an embodiment of the present application.

[0028] Figure 8 It is a flowchart of another key updating method provided in an embodiment of the present application.

[0029] Fig. 9 It is a schematic diagram of a key updating device provided in an embodiment of the present application.

[0030] Fig.10 It is a schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0031] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.

[0032] A key updating method and device according to an embodiment of the present application will be described in detail below with reference to the accompanying drawings.

[0033] Figure 1 1 is a schematic diagram of an application scenario of an embodiment of the present application. The application scenario may include terminal devices 1, 2 and 3, a server 4 and a network 5.

[0034] The kubernetes cluster can be deployed on the server 4, and the terminal device 1, 2 or 3 can connect to the server 4 through a preset interface to obtain and update the key of each private image repository. On the other hand, the user can also directly operate in the server 4 to obtain and update the key of each private image repository.

[0035] The network 5 may be a wired network connected by coaxial cables, twisted pairs, and optical fibers, or a wireless network that can interconnect various communication devices without wiring, and the embodiments of the present application are not limited to this.

[0036] It should be noted that the specific types, quantities and combinations of the terminal devices 1, 2 and 3, the server 4 and the network 5 can be adjusted according to the actual needs of the application scenario, and the embodiments of the present application do not limit this.

[0037] As mentioned above, when using the kubernetes cluster service to pull images from a private image repository, you need to create a secret of the kubernetes.io / dockerconfigjson type as the credential for pulling images, which includes the key of the private image repository. If the key does not expire, there may be security vulnerabilities, compliance issues, account risks and other security risks, and it will increase management complexity.

[0038] Among them, security vulnerabilities mean that if the key is leaked, unauthorized users may access the private repository and pull or modify the image. Compliance issues mean that some organizations may have compliance requirements regarding key usage and lifecycles, and keys that do not expire for a long time may not meet these requirements. Account risk means that if the account permissions associated with the key are too high, once the key is leaked, it may pose a threat to the security of the entire repository. Management complexity means that if the key does not expire, it may be difficult to manage and track which keys are in use over time, increasing the complexity of management. Therefore, key update management is required.

[0039] In view of this, an embodiment of the present application provides a key update method, by first pre-building a first dictionary in the kubernetes cluster, the first dictionary including the historical user name, historical password and the second key formed by the second code obtained by encoding the historical user name and the historical password of each private image repository, and then obtaining the target address of the target private image repository and the current user name, current password and the first key formed by the first code obtained by encoding the current user name and the current password of the target private image repository, and then using the target address to query the first dictionary to obtain the first key of the target private image repository, and when it is determined that the first code is different from the second code, the first key is used to update the second key in the first dictionary, and the updated first dictionary is used to update the secret object of the kubernetes cluster to achieve the key update of the target private image repository. This method can realize automatic rotation of credentials and reduce the risk of key leakage.

[0040] Figure 2 It is a flowchart of a key updating method provided in an embodiment of the present application. Figure 2 The key update method can be Figure 1 The terminal device or server executes. Figure 2 As shown, the method comprises the following steps:

[0041] In step S201, a target address of a target private image repository and a first key of the target private image repository are periodically obtained.

[0042] The first key includes the current user name and password of the target private image repository and a first code obtained by encoding the current user name and the current password.

[0043] In step S202, the target address is used to search in the constructed first dictionary.

[0044] In step S203, in response to determining that the value of the first dictionary includes the target address, a second key corresponding to the target address is obtained.

[0045] The second key includes the historical user name, historical password, and a second code obtained by encoding the historical user name and historical password of the target private image repository.

[0046] In step S204, in response to determining that the first code is different from the second code, the second key is updated using the first key to obtain an updated first dictionary.

[0047] In step S205, the secret object of the target private image repository in the kubernetes cluster is updated using the updated first dictionary to implement the key update of the target private image repository.

[0048] In the embodiment of the present application, the method can be executed by a terminal device, or can be executed by a deployed kubernetes cluster.

[0049] In an embodiment of the present application, a terminal device or a server may periodically obtain the target address of a target private image repository and a first key of the target private image repository. The first key of the target private image repository includes the current username and current password of the target image private repository and a first code obtained by encoding the current username and current password. In one example, the target address of the target private image repository may be defined as a variable registry, the current username of the target image private repository may be recorded as new_username, the current password of the target image private repository may be recorded as new_password, the first code may be obtained by encoding new_username and new_password using base64, the first code is a string, and may be defined as a variable new_auth.

[0050] In the embodiment of the present application, the time period for periodically obtaining the target address and the first key of the target private image repository can be set as needed, and the time period can be a fixed time period or a variable time period. Different target private image repositories can be set with the same or different time periods.

[0051] In an embodiment of the present application, the target address of the target private image repository can be used to query the constructed first dictionary. If the query determines that the value of the first dictionary includes the target address, the second key corresponding to the target address can be obtained from the first dictionary. Among them, the second key includes the historical username, historical password and the second code obtained by encoding the historical username and historical password of the target private image repository. In one example, the historical username of the target image private repository can be recorded as old_username, and the historical password of the target image private repository can be recorded as old_password. The second code can be obtained by using base64 encoding on old_username and old_password. The second code is also a string and can be defined as a variable old_auth.

[0052] In the embodiment of the present application, the first key can be compared with the second key. If the two are the same, no operation is performed, the current round of key update is ended, and the next update cycle is waited. Otherwise, if the first code is different from the second code, the first key can be used to update the second key to obtain an updated first dictionary. In other words, the obtained first key can be compared with the second key obtained by the query. If the two are different, the new_username, new_password and new_auth in the first key are used to update the old_username, old_password and old_auth in the second key to obtain an updated first dictionary.

[0053] In an embodiment of the present application, after completing the update of the first dictionary, the updated first dictionary can be used to update the secret object of the target private image repository in the kubernetes cluster, thereby achieving the key update of the target private image repository.

[0054] According to the technical solution provided by the embodiment of the present application, a first dictionary is pre-built in the kubernetes cluster, the first dictionary includes the historical user name, historical password and the second key formed by the second code obtained by encoding the historical user name and the historical password of each private image repository, and then the target address of the target private image repository and the current user name, current password and the first key formed by the first code obtained by encoding the current user name and the current password of the target private image repository are obtained, and then the target address is used to query the first dictionary to obtain the first key of the target private image repository, and when it is determined that the first code is different from the second code, the first key is used to update the second key in the first dictionary, and the updated first dictionary is used to update the secret object of the kubernetes cluster to achieve the key update of the target private image repository. This method can realize automatic rotation of credentials and reduce the risk of key leakage.

[0055] In the embodiment of the present application, the key of the first dictionary may be a key key. For example, if the first dictionary is recorded as A, the key of A may be recorded as A.auths, and the value may be a second dictionary B. The key of the second dictionary B is the private image repository address, and the value is the third dictionary C. The private image repository address may include multiple addresses, that is, the key of the second dictionary B may include multiple keys, and each key corresponds to one value, that is, each private image repository address corresponds to one third dictionary C.

[0056] Figure 3 1 is a flow chart of a method for obtaining a second key corresponding to a target address in response to a value in a first dictionary including the target address provided by an embodiment of the present application. Figure 3 As shown, the method comprises the following steps:

[0057] In step S301, the target address is used to search in the keys of the second dictionary.

[0058] In step S302 , in response to determining that the target key of the second dictionary is the same as the target address, a second key corresponding to the target key is obtained from a third dictionary.

[0059] In the embodiment of the present application, the target address of the target private image repository can be used to query in the first dictionary, wherein, since the value of the first dictionary is the second dictionary, and the key of the second dictionary is the address of each private image repository, the target address can be used to query in the key of the second dictionary. If the target key that is the same as the target address is queried in the key of the second dictionary, the second key of the target private image repository is obtained from the value corresponding to the target key in the second dictionary.

[0060] In one example, the variable registry can be used to query the keys of the second dictionary B. When it is determined that the second dictionary B includes a key named registry, the second key of the target private image repository can be obtained from the value corresponding to the registry key.

[0061] In an embodiment of the present application, the keys of the third dictionary include a username key, a password key and a coding key. The value corresponding to the username key is the historical username of the first private image repository, the value corresponding to the password key is the historical password of the first private image repository, the value corresponding to the coding key is the second coding of the first private image repository, and the first private image repository is the private image repository corresponding to the key corresponding to the third dictionary in the second dictionary.

[0062] That is to say, for any first private image repository, the third dictionary C may include a username key username, a password key password and a coding key auth, wherein the value corresponding to the username key username is old_username, the value corresponding to the password key password is old_password, and the value corresponding to the coding key auth is old_auth.

[0063] Figure 4 1 is a flow chart of a method for obtaining a second key corresponding to a target address from a third dictionary provided in an embodiment of the present application. Figure 4 As shown, the method comprises the following steps:

[0064] In step S401, a target third dictionary corresponding to a key corresponding to a target address in the second dictionary is obtained.

[0065] In step S402, the user name value, password value and encoding value in the target third dictionary are obtained as the second key.

[0066] In an embodiment of the present application, the target third dictionary corresponding to the key corresponding to the target address in the second dictionary can be first obtained, and then the username value, password value and encoding value in the target third dictionary can be obtained as the second key.

[0067] That is to say, if it is determined that the second dictionary B includes a key named registry, the value corresponding to the registry key, that is, the target third dictionary C corresponding to the registry key, can be further obtained, and each value in the target third dictionary C can be taken out as the second key of the target private image repository.

[0068] In an embodiment of the present application, when using the first key to update the second key, the current user name in the first key can be used to update the historical user name in the second key, the current password in the first key can be used to update the historical password in the second key, and the first code in the first password can be used to update the second code in the second key.

[0069] That is, old_username, old_password, and old_auth in the target third dictionary C may be updated with new_username, new_password, and new_auth, thereby obtaining an updated first dictionary A.

[0070] Figure 5 1 is a flow chart of a method for updating a secret object of a target private image repository in a kubernetes cluster using an updated first dictionary provided by an embodiment of the present application. Figure 5 As shown, the method comprises the following steps:

[0071] In step S501 , the updated first dictionary is re-encoded.

[0072] In step S502, a command line tool is used to obtain a configuration file of a secret object of a target private image repository.

[0073] In step S503, the configuration file is updated using the re-encoded first dictionary to complete the secret object update of the target private image repository.

[0074] In an embodiment of the present application, after completing the update of the first dictionary A, the updated first dictionary A can be first re-encoded, and base64 encoding can be used for encoding. Then use the command line tool to obtain the configuration file of the secret object of the target private image repository. Among them, the command line tool can be kubectl, and the configuration file of the secret object of the target private image repository obtained can be a .dockerconfigjson file. Use the updated first dictionary A to update the configuration file, that is, the .dockerconfigjson file, to complete the update of the secret object of the target private image repository. Among them, using the updated first dictionary A to update the .dockerconfigjson file can be to replace the .dockerconfigjson file in the secret object with the updated first dictionary A.

[0075] In an embodiment of the present application, the current user name and current password in the first key may also include expiration information. Furthermore, the updated first dictionary also includes the expiration information, so that after the target private image repository implements the key update based on the updated first dictionary, the image is pulled after the correct credentials are obtained. The correct credentials include a key that matches the updated key of the target private repository, and the pulling time does not exceed the expiration date.

[0076] That is to say, the first key can carry expiration information, and the first dictionary updated with the first key also has the expiration information, so that the updated key of the target private image repository also contains the expiration information. In this way, when the target private image repository is pulled, the key in its secret object can be compared with the credentials provided when pulling the image. If the time in the credential exceeds the expiration in the key, and the username, password, and code are correct, the pull is allowed. Otherwise, the pull can be prohibited or an alarm can be prompted.

[0077] Figure 6 is a flow chart of a method for constructing a first dictionary provided in an embodiment of the present application. Figure 6 As shown, the method comprises the following steps:

[0078] In step S601, all namespaces of the kubernetes cluster are traversed to obtain secret objects of all target types.

[0079] The target type is kubernetes.io / dockerconfigjson.

[0080] In step S602, the third key of each private image repository is read from the obtained secret object.

[0081] The third key of each private image repository includes the current storage user name, the current storage password, and the third code obtained by encoding the current storage user name and the current storage password of the private image repository.

[0082] In step S603, a first dictionary is constructed, and the key of the first dictionary is set as the key key, and the value is set as the second dictionary.

[0083] In step S604, the key of the second dictionary is set to the address of each private image repository, and the value is set to the third dictionary.

[0084] In step S605, for the key of the second dictionary corresponding to the address of the second private image repository, the third dictionary corresponding to the value thereof is set, where the key is the user name key, password key and encoding key of the second private image repository.

[0085] In step S606, the currently stored user name, the currently stored password and the third code in the third key of the second private image repository are stored in the third dictionary as the value corresponding to the user name key, the value corresponding to the password key and the value corresponding to the code key in the third dictionary corresponding to the address of the second private image repository, respectively, to obtain the constructed first dictionary.

[0086] The second private image repository is any one of the private image repositories corresponding to the key of the second dictionary.

[0087] In an embodiment of the present application, when constructing the first dictionary A, all namespaces of the kubernetes cluster can be traversed first, all secret objects of type kubernetes.io / dockerconfigjson can be obtained, and the third key of each private image repository can be read from the configuration file .dockerconfigjson in the data of the obtained secret object. Among them, the key read from the .Dockerconfigjson file is a base64-encoded key, which needs to be decoded to obtain the third key. Furthermore, the third key of each private image repository includes the current storage user name, current storage password and the third code obtained by encoding the current storage user name and current storage password of the private image repository.

[0088] In the embodiment of the present application, a first dictionary A may be created, and the key of the first dictionary A is set to the key key auths, and the value is set to the second dictionary B. Further, the key of the second dictionary B is set to the address of each private image repository, and the value is set to the third dictionary C. Furthermore, for each key in the second dictionary B, that is, each private image repository address, for example, called the second private image repository address, the corresponding value, that is, the corresponding key of the third dictionary C is respectively set to the username key username, the password key password, and the encoding key auth of the second private image repository.

[0089] In an embodiment of the present application, the currently stored user name, the currently stored password and the third code in the third key of the second private image repository can be stored in the third dictionary as the value corresponding to the user name key, the value corresponding to the password key and the value corresponding to the code key in the third dictionary corresponding to the address of the second private image repository, respectively, to obtain the constructed first dictionary.

[0090] That is to say, in the third dictionary C corresponding to the address of the second private image repository, the value corresponding to the username key can be set to the currently stored username in the third key of the second private image repository, and it can be recorded as old_username, the value corresponding to the password key can be set to the currently stored password in the third key of the second private image repository, and it can be recorded as old_password, and the value corresponding to the code key can be set to the third code in the third key of the second private image repository, and it can be recorded as old_auth, thereby completing the construction of the first dictionary A.

[0091] An embodiment of the present application provides a method for automatically rotating private image repository credentials, creating a private image repository username and password with an expiration time, which is used to create secrets of the kubernetes.io / dockerconfigjson type as credentials for pulling images, creating a new username and password before the credentials expire, and updating the credentials within the cluster.

[0092] Figure 7 Schematic diagram of a method for constructing variables in a key update method provided in an embodiment of the present application. Figure 7 As shown, the string obtained by combining the regularly updated username and new password and encoding them using base64 can be defined as a variable new_auth, and the address of the target private image repository is recorded as registry.

[0093] Figure 8 FIG. 1 is a flow chart of another key updating method provided in an embodiment of the present application. Figure 8 As shown, you can first traverse all namespaces in the current cluster and find the secret of type kubernetes.io / dockerconfigjson; then read the value of .dockerconfigjson in the data of the secret and use base64 decoding to save it as the first dictionary A, where the first dictionary A includes a key auths, whose value is the second dictionary B; the key of the second dictionary B is the private image repository address, and the value is the authentication information C corresponding to the private image repository; C is the third dictionary, which contains the keys username, password and auth, and the corresponding values ​​are the base64 encoded strings of the username, password, and username plus password, respectively.

[0094] Will Figure 7 The address of the target private image repository constructed in the embodiment shown is input into dictionary A, and A.auths is queried to see if it contains the value of registry. If so, the authentication information dictionary C corresponding to the registry is obtained; the value of the auth key is obtained from the dictionary C and recorded as old_auth. New_auth is compared with old_auth. If they are the same, it is skipped. If they are different, the values ​​of username, password, and auth in C are updated. Finally, base64 encoding is used again for A, and kubectl patch is used to update the secret to complete the key update of the target private image repository.

[0095] By adopting the technical solution of the embodiment of the present application, the risk of key leakage is reduced by automatically rotating credentials at a fixed time. By setting the expiration time, it can be ensured that even if the key is leaked, its effectiveness is limited; forced regular key updates: Regular key replacement is a good security practice that can prevent the security risks brought about by long-term reliance on a single key and meet compliance and audit requirements.

[0096] All the above optional technical solutions can be arbitrarily combined to form optional embodiments of the present application, which will not be described one by one here.

[0097] The following is an embodiment of the device of the present application, which can be used to execute the embodiment of the method of the present application. For details not disclosed in the embodiment of the device of the present application, please refer to the embodiment of the method of the present application.

[0098] Fig. 9 Schematic diagram of a key updating device provided in an embodiment of the present application. Fig. 9 As shown, the device comprises:

[0099] The acquisition module 901 is configured to periodically acquire the target address of the target private image repository and the first key of the target private image repository, where the first key includes the current user name, current password and a first code obtained by encoding the current user name and current password of the target private image repository.

[0100] The query module 902 is configured to use the target address to query in the constructed first dictionary.

[0101] The acquisition module 901 is also configured to acquire a second key corresponding to the target address in response to determining that the value of the first dictionary includes the target address, the second key including a historical user name, a historical password, and a second code obtained by encoding the historical user name and the historical password of the target private image repository.

[0102] The updating module 903 is configured to, in response to determining that the first code is different from the second code, use the first key to update the second key to obtain an updated first dictionary.

[0103] The updating module 903 is further configured to use the updated first dictionary to update the secret object of the target private image repository in the kubernetes cluster, thereby implementing a key update of the target private image repository.

[0104] According to the technical solution provided by the embodiment of the present application, a first dictionary is pre-built in the kubernetes cluster, the first dictionary includes the historical user name, historical password and the second key formed by the second code obtained by encoding the historical user name and the historical password of each private image repository, and then the target address of the target private image repository and the current user name, current password and the first key formed by the first code obtained by encoding the current user name and the current password of the target private image repository are obtained, and then the target address is used to query the first dictionary to obtain the first key of the target private image repository, and when it is determined that the first code is different from the second code, the first key is used to update the second key in the first dictionary, and the updated first dictionary is used to update the secret object of the kubernetes cluster to achieve the key update of the target private image repository. This method can realize automatic rotation of credentials and reduce the risk of key leakage.

[0105] In an embodiment of the present application, the key of the first dictionary is the key key, and the value is the second dictionary; the key of the second dictionary is the private image repository address, and the value is the third dictionary; in response to the value of the first dictionary including the target address, obtaining the second key corresponding to the target address includes: using the target address to query in the key of the second dictionary; in response to determining that the target key of the second dictionary is the same as the target address, obtaining the second key corresponding to the target key from the third dictionary.

[0106] In an embodiment of the present application, the keys of the third dictionary include a username key, a password key and a coding key, the value corresponding to the username key is a historical username of the first private image repository, the value corresponding to the password key is a historical password of the first private image repository, the value corresponding to the coding key is a second coding of the first private image repository, and the first private image repository is the private image repository corresponding to the key corresponding to the third dictionary in the second dictionary; obtaining the second key corresponding to the target address from the third dictionary includes: obtaining a target third dictionary corresponding to the key corresponding to the target address in the second dictionary; obtaining the username value, password value and coding value in the target third dictionary as the second key.

[0107] In an embodiment of the present application, the first key is used to update the second key to obtain an updated first dictionary, including: using the current user name in the first key to update the historical user name in the second key; and using the current password in the first key to update the historical password in the second key; and using the first code in the first password to update the second code in the second key.

[0108] In an embodiment of the present application, the secret object of the target private image repository in the kubernetes cluster is updated using the updated first dictionary, including: re-encoding the updated first dictionary; obtaining the configuration file of the secret object of the target private image repository using a command line tool; and updating the configuration file using the re-encoded first dictionary to complete the update of the secret object of the target private image repository.

[0109] In an embodiment of the present application, the current username and current password in the first key include expiration information; the updated first dictionary includes expiration information, so that after the target private image repository implements a key update based on the updated first dictionary, the image is pulled after the correct credentials are obtained; wherein the correct credentials include a key that matches the updated key of the target private repository, and the pulling time does not exceed the expiration date.

[0110] In an embodiment of the present application, the first dictionary is constructed in the following manner: traverse all namespaces of the kubernetes cluster to obtain secret objects of all target types, where the target type is the kubernetes.io / dockerconfigjson type; read the third key of each private image repository from the obtained secret object, where the third key of each private image repository includes the current storage user name, the current storage password, and the third code obtained by encoding the current storage user name and the current storage password of the private image repository; construct a first dictionary, set the key of the first dictionary to the key key, and the value to the second dictionary; set the key of the second dictionary to the address of each private image repository, and the value to the third dictionary; for the key of the second dictionary corresponding to the address of the second private image repository, set the key in the third dictionary corresponding to its value to the user name key, password key, and code key of the second private image repository; store the current storage user name, current storage password, and third code in the third key of the second private image repository as the value corresponding to the user name key, the value corresponding to the password key, and the value corresponding to the code key in the third dictionary corresponding to the address of the second private image repository in the third dictionary, respectively, to obtain the constructed first dictionary; wherein the second private image repository is any repository in each private image repository corresponding to the key of the second dictionary.

[0111] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.

[0112] Fig.10 Schematic diagram of an electronic device provided in an embodiment of the present application. Fig.10As shown, the electronic device 10 of this embodiment includes: a processor 1001, a memory 1002, and a computer program 1003 stored in the memory 1002 and executable on the processor 1001. When the processor 1001 executes the computer program 1003, the steps in the above-mentioned method embodiments are implemented. Alternatively, when the processor 1001 executes the computer program 1003, the functions of the modules / units in the above-mentioned device embodiments are implemented.

[0113] The electronic device 10 may be a desktop computer, a notebook, a PDA, a cloud server, or other electronic device. The electronic device 10 may include, but is not limited to, a processor 1001 and a memory 1002. Those skilled in the art will appreciate that Fig.10 The electronic device 10 is merely an example and does not limit the electronic device 10 . The electronic device 10 may include more or fewer components than shown in the figure, or different components.

[0114] Processor 1001 can be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.

[0115] The memory 1002 may be an internal storage unit of the electronic device 10, for example, a hard disk or memory of the electronic device 10. The memory 1002 may also be an external storage device of the electronic device 10, for example, a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card (FlashCard), etc. equipped on the electronic device 10. The memory 1002 may also include both an internal storage unit of the electronic device 10 and an external storage device. The memory 1002 is used to store computer programs and other programs and data required by the electronic device.

[0116] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units.

[0117] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. The computer program may include computer program code, which may be in source code form, object code form, executable file or some intermediate form. Computer-readable media may include: any entity or device capable of carrying computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium, etc.

[0118] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.

Claims

1. A key updating method, characterized in that: The method is used to automatically update a private image repository key in a kubernetes cluster, and the method includes: Periodically obtaining a target address of a target private image repository and a first key of the target private image repository, where the first key includes a current user name and a current password of the target private image repository and a first code obtained by encoding the current user name and the current password; Using the target address to search in the constructed first dictionary; In response to determining that the value of the first dictionary includes the target address, obtaining a second key corresponding to the target address, where the second key includes a historical user name and a historical password of the target private image repository, and a second code obtained by encoding the historical user name and the historical password; In response to determining that the first encoding is different from the second encoding, using the first key to update the second key to obtain an updated first dictionary; The secret object of the target private image repository in the Kubernetes cluster is updated using the updated first dictionary to implement a key update of the target private image repository.

2. The method according to claim 1, characterized in that The key of the first dictionary is the key key, and the value is the second dictionary; The key of the second dictionary is the private image repository address, and the value is the third dictionary; In response to the value of the first dictionary including the target address, obtaining a second key corresponding to the target address includes: Using the target address, query the key in the second dictionary; In response to determining that the target key of the second dictionary is the same as the target address, a second key corresponding to the target key is obtained from the third dictionary.

3. The method according to claim 2, characterized in that The keys of the third dictionary include a username key, a password key, and a coding key, the value corresponding to the username key is a historical username of the first private image repository, the value corresponding to the password key is a historical password of the first private image repository, the value corresponding to the coding key is the second coding of the first private image repository, and the first private image repository is the private image repository corresponding to the key corresponding to the third dictionary in the second dictionary; The obtaining the second key corresponding to the target address from the third dictionary includes: Obtain a target third dictionary corresponding to the key corresponding to the target address in the second dictionary; The user name value, password value and encoding value in the target third dictionary are obtained as the second key.

4. The method according to claim 3, characterized in that The using the first key to update the second key to obtain an updated first dictionary includes: Update the historical username in the second key using the current username in the first key; and Use the current password in the first key to update the historical password in the second key; and The second code in the second secret key is updated using the first code in the first password.

5. The method according to claim 1, characterized in that The updating of the secret object of the target private image repository in the kubernetes cluster using the updated first dictionary includes: re-encoding the updated first dictionary; Use the command line tool to obtain the configuration file of the secret object of the target private image repository; The configuration file is updated using the re-encoded first dictionary to complete the secret object update of the target private image repository.

6. The method according to claim 1, characterized in that The current user name and current password in the first key include expiration information; The updated first dictionary includes the expiration information, so that the target private image repository can pull the image after obtaining the correct credentials after the key is updated based on the updated first dictionary; The correct credentials include a key that matches the updated key of the target private repository, and the pull time does not exceed the deadline.

7. The method according to any one of claims 1 to 6, characterized in that The first dictionary is constructed in the following way: Traverse all namespaces of the kubernetes cluster and obtain secret objects of all target types, where the target type is kubernetes.io / dockerconfigjson type; Read the third key of each private image repository from the obtained secret object, where the third key of each private image repository includes the current storage user name and current storage password of the private image repository and a third code obtained by encoding the current storage user name and current storage password; Construct a first dictionary, set the key of the first dictionary to the key key, and the value to the second dictionary; Set the key of the second dictionary to the address of each private image repository, and the value to the third dictionary; For the key of the second dictionary corresponding to the address of the second private image repository, set the third dictionary corresponding to its value, where the key is the username key, password key and encoding key of the second private image repository; The currently stored user name, the currently stored password and the third code in the third key of the second private image repository are respectively stored in the third dictionary as the values ​​corresponding to the user name key, the password key and the code key in the third dictionary corresponding to the address of the second private image repository, to obtain the constructed first dictionary; The second private image repository is any one of the private image repositories corresponding to the key of the second dictionary.

8. A key updating device, characterized in that: include: an acquisition module configured to periodically acquire a target address of a target private image repository and a first key of the target private image repository, wherein the first key includes a current user name and a current password of the target private image repository and a first code obtained by encoding the current user name and the current password; A query module, configured to use the target address to query in the constructed first dictionary; The acquisition module is further configured to, in response to determining that the value of the first dictionary includes the target address, acquire a second key corresponding to the target address, where the second key includes a historical user name and a historical password of the target private image repository, and a second code obtained by encoding the historical user name and the historical password; an updating module, configured to, in response to determining that the first encoding is different from the second encoding, update the second key using the first key to obtain an updated first dictionary; The update module is also configured to use the updated first dictionary to update the secret object of the target private image repository in the kubernetes cluster to implement the key update of the target private image repository.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.

Citation Information

Cited By

  • Cloud service deployment

    WO2026103404A1