|
| 1 | +# IAM Client |
| 2 | + |
| 3 | +Provides access to IAM services through gRPC communication with IAM server. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The `aos::cm::iamclient::IAMClient` class aggregates multiple gRPC service implementations to provide a unified |
| 8 | +IAM client interface. It indirectly implements the [IAMClientItf][iamclient-itf] by inheriting from specific gRPC |
| 9 | +service classes, each of which implements one of the required interfaces. |
| 10 | + |
| 11 | +## Indirect inheritance pattern |
| 12 | + |
| 13 | +`IAMClient` achieves interface compatibility with `IAMClientItf` through multiple inheritance from gRPC service |
| 14 | +implementations: |
| 15 | + |
| 16 | +### IAMClientItf requirements |
| 17 | + |
| 18 | +The `IAMClientItf` interface requires: |
| 19 | + |
| 20 | +* [aos::iamclient::CertHandlerItf][cert-handler-itf] - handles keys and certificates (renew, provisioning) |
| 21 | +* [aos::iamclient::CertProviderItf][cert-provider-itf] - provides info about current keys and certificates |
| 22 | +* [aos::iamclient::NodeHandlerItf][node-handler-itf] - handles node states (pause, resume) |
| 23 | +* [aos::iamclient::NodeInfoProviderItf][node-info-provider-itf] - provides nodes info |
| 24 | +* [aos::iamclient::ProvisioningItf][provisioning-itf] - performs node provisioning |
| 25 | + |
| 26 | +### Service implementation mapping |
| 27 | + |
| 28 | +`IAMClient` inherits from the following gRPC service classes, which implement the required interfaces: |
| 29 | + |
| 30 | +| gRPC Service Class | Implements Interface | Purpose | |
| 31 | +|-------------------|---------------------|---------| |
| 32 | +| [CertificateService][cert-service] | `CertHandlerItf` | Protected IAM Certificate Service client | |
| 33 | +| [PublicCertService][public-cert-service] | `CertProviderItf` | Public IAM Certificate Service client | |
| 34 | +| [NodesService][nodes-service] | `NodeHandlerItf` | Protected IAM Nodes Service client | |
| 35 | +| [PublicNodesService][public-nodes-service] | `NodeInfoProviderItf` | Public IAM Nodes Service client | |
| 36 | +| [ProvisioningService][provisioning-service] | `ProvisioningItf` | Protected IAM Provisioning Service client | |
| 37 | + |
| 38 | +### Additional interface |
| 39 | + |
| 40 | +`IAMClient` also directly implements: |
| 41 | + |
| 42 | +* [aos::iamclient::CertListenerItf][cert-listener-itf] - receives certificate change notifications |
| 43 | + |
| 44 | +## Class diagram |
| 45 | + |
| 46 | +```mermaid |
| 47 | +classDiagram |
| 48 | + class IAMClient ["aos::cm::iamclient::IAMClient"] { |
| 49 | + +Init() |
| 50 | + +OnCertChanged() |
| 51 | + } |
| 52 | +
|
| 53 | + class IAMClientItf ["aos::cm::iamclient::IAMClientItf"] { |
| 54 | + <<interface>> |
| 55 | + } |
| 56 | +
|
| 57 | + class CertHandlerItf ["aos::iamclient::CertHandlerItf"] { |
| 58 | + <<interface>> |
| 59 | + +CreateKey() |
| 60 | + +ApplyCert() |
| 61 | + } |
| 62 | +
|
| 63 | + class CertProviderItf ["aos::iamclient::CertProviderItf"] { |
| 64 | + <<interface>> |
| 65 | + +GetCert() |
| 66 | + +SubscribeListener() |
| 67 | + } |
| 68 | +
|
| 69 | + class NodeHandlerItf ["aos::iamclient::NodeHandlerItf"] { |
| 70 | + <<interface>> |
| 71 | + +PauseNode() |
| 72 | + +ResumeNode() |
| 73 | + } |
| 74 | +
|
| 75 | + class NodeInfoProviderItf ["aos::iamclient::NodeInfoProviderItf"] { |
| 76 | + <<interface>> |
| 77 | + +GetAllNodeIDs() |
| 78 | + +GetNodeInfo() |
| 79 | + } |
| 80 | +
|
| 81 | + class ProvisioningItf ["aos::iamclient::ProvisioningItf"] { |
| 82 | + <<interface>> |
| 83 | + +GetCertTypes() |
| 84 | + +StartProvisioning() |
| 85 | + +FinishProvisioning() |
| 86 | + +Deprovision() |
| 87 | + } |
| 88 | +
|
| 89 | + class CertListenerItf ["aos::iamclient::CertListenerItf"] { |
| 90 | + <<interface>> |
| 91 | + +OnCertChanged() |
| 92 | + } |
| 93 | +
|
| 94 | + class CertificateService ["aos::common::iamclient::CertificateService"] { |
| 95 | + } |
| 96 | +
|
| 97 | + class PublicCertService ["aos::common::iamclient::PublicCertService"] { |
| 98 | + } |
| 99 | +
|
| 100 | + class NodesService ["aos::common::iamclient::NodesService"] { |
| 101 | + } |
| 102 | +
|
| 103 | + class PublicNodesService ["aos::common::iamclient::PublicNodesService"] { |
| 104 | + } |
| 105 | +
|
| 106 | + class ProvisioningService ["aos::common::iamclient::ProvisioningService"] { |
| 107 | + } |
| 108 | +
|
| 109 | + %% IAMClientItf implements all required interfaces |
| 110 | + IAMClientItf ..|> CertHandlerItf |
| 111 | + IAMClientItf ..|> CertProviderItf |
| 112 | + IAMClientItf ..|> NodeHandlerItf |
| 113 | + IAMClientItf ..|> NodeInfoProviderItf |
| 114 | + IAMClientItf ..|> ProvisioningItf |
| 115 | +
|
| 116 | + %% Service classes implement specific interfaces |
| 117 | + CertificateService ..|> CertHandlerItf |
| 118 | + PublicCertService ..|> CertProviderItf |
| 119 | + NodesService ..|> NodeHandlerItf |
| 120 | + PublicNodesService ..|> NodeInfoProviderItf |
| 121 | + ProvisioningService ..|> ProvisioningItf |
| 122 | +
|
| 123 | + %% IAMClient inherits from all service classes |
| 124 | + IAMClient --|> CertificateService |
| 125 | + IAMClient --|> PublicCertService |
| 126 | + IAMClient --|> NodesService |
| 127 | + IAMClient --|> PublicNodesService |
| 128 | + IAMClient --|> ProvisioningService |
| 129 | + IAMClient ..|> CertListenerItf |
| 130 | +
|
| 131 | + %% IAMClient indirectly implements IAMClientItf |
| 132 | + IAMClient ..|> IAMClientItf : indirectly through services |
| 133 | +``` |
| 134 | + |
| 135 | +## Certificate change handling |
| 136 | + |
| 137 | +When a certificate changes, `IAMClient` receives notification via the `CertListenerItf::OnCertChanged()` callback |
| 138 | +and automatically reconnects all gRPC services to the IAM server using the updated credentials: |
| 139 | + |
| 140 | +1. Certificate change notification received |
| 141 | +2. Reconnect `CertificateService` to protected IAM server |
| 142 | +3. Reconnect `NodesService` to protected IAM server |
| 143 | +4. Reconnect `ProvisioningService` to protected IAM server |
| 144 | +5. Reconnect `PublicCertService` to public IAM server |
| 145 | +6. Reconnect `PublicNodesService` to public IAM server |
| 146 | + |
| 147 | +## Usage |
| 148 | + |
| 149 | +The `IAMClient` is initialized with both protected and public IAM server URLs: |
| 150 | + |
| 151 | +```cpp |
| 152 | +aos::cm::iamclient::IAMClient iamClient; |
| 153 | + |
| 154 | +auto err = iamClient.Init( |
| 155 | + "iam-protected.example.com:8089", // Protected IAM server |
| 156 | + "iam-public.example.com:8090", // Public IAM server |
| 157 | + "/var/aos/certs", // Certificate storage path |
| 158 | + tlsCredentials, // TLS credentials provider |
| 159 | + "client", // Certificate type to monitor |
| 160 | + false // Use secure connection |
| 161 | +); |
| 162 | +``` |
| 163 | + |
| 164 | +Once initialized, `IAMClient` can be used through any of the implemented interfaces, making it compatible with |
| 165 | +`IAMClientItf` without directly inheriting from it. |
| 166 | + |
| 167 | +[iamclient-itf]: https://github.com/aosedge/aos_core_lib_cpp/blob/main/src/core/cm/iamclient/itf/iamclient.hpp |
| 168 | +[cert-handler-itf]: https://github.com/aosedge/aos_core_lib_cpp/blob/main/src/core/common/iamclient/itf/certhandler.hpp |
| 169 | +[cert-provider-itf]: https://github.com/aosedge/aos_core_lib_cpp/blob/main/src/core/common/iamclient/itf/certprovider.hpp |
| 170 | +[node-handler-itf]: https://github.com/aosedge/aos_core_lib_cpp/blob/main/src/core/common/iamclient/itf/nodehandler.hpp |
| 171 | +[node-info-provider-itf]: https://github.com/aosedge/aos_core_lib_cpp/blob/main/src/core/common/iamclient/itf/nodeinfoprovider.hpp |
| 172 | +[provisioning-itf]: https://github.com/aosedge/aos_core_lib_cpp/blob/main/src/core/common/iamclient/itf/provisioning.hpp |
| 173 | +[cert-listener-itf]: https://github.com/aosedge/aos_core_lib_cpp/blob/main/src/core/common/iamclient/itf/certlistener.hpp |
| 174 | +[cert-service]: https://github.com/aosedge/aos_core_cpp/tree/feature_unification/src/common/iamclient/certificateservice.hpp |
| 175 | +[public-cert-service]: https://github.com/aosedge/aos_core_cpp/tree/feature_unification/src/common/iamclient/publiccertservice.hpp |
| 176 | +[nodes-service]: https://github.com/aosedge/aos_core_cpp/tree/feature_unification/src/common/iamclient/nodesservice.hpp |
| 177 | +[public-nodes-service]: https://github.com/aosedge/aos_core_cpp/tree/feature_unification/src/common/iamclient/publicnodeservice.hpp |
| 178 | +[provisioning-service]: https://github.com/aosedge/aos_core_cpp/tree/feature_unification/src/common/iamclient/provisioningservice.hpp |
0 commit comments