Skip to content

Commit

Permalink
oci: Add OCI key manager to the list of available key managers
Browse files Browse the repository at this point in the history
This enables the use of the OCI key manager.

Signed-off-by: Patrick Colp <[email protected]>
  • Loading branch information
pjcolp committed Oct 25, 2024
1 parent 0bed7c7 commit d327f1d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func DefaultConfig() *Configuration {
ServerPort: viper.GetString(VaultServerPort),
ClientToken: viper.GetString(VaultClientToken),
}
} else {
} else if strings.ToLower(cfg.KeyManager) == constant.KmipKeyManager {
cfg.Kmip = KmipConfig{
Version: viper.GetString(KmipVersion),
ServerIP: viper.GetString(KmipServerIP),
Expand All @@ -72,5 +72,6 @@ func DefaultConfig() *Configuration {
RootCertificateFilePath: viper.GetString(KmipRootCertPath),
}
}
// Currently we do nothing special for OCI config.
return cfg
}
1 change: 1 addition & 0 deletions constant/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const (

// kmipmanager constants
KmipKeyManager = "kmip"
OCIKeyManager = "oci"
VaultKeyManager = "vault"
DefaultVaultPort = 8200

Expand Down
8 changes: 8 additions & 0 deletions keymanager/key_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package keymanager

import (
"intel/kbs/v1/ociclient"
"intel/kbs/v1/vaultclient"
"strings"

Expand All @@ -27,6 +28,13 @@ func NewKeyManager(cfg *config.Configuration) (KeyManager, error) {
return nil, errors.Wrap(err, "Failed to initialize KmipManager")
}
return NewKmipManager(kmipClient), nil
} else if strings.ToLower(cfg.KeyManager) == constant.OCIKeyManager {
ociClient := ociclient.NewOCIClient()
err := ociClient.InitializeClient()
if err != nil {
return nil, errors.Wrap(err, "keymanager/key_manager:NewKeyManager() Failed to initialize OCI client")
}
return NewOCIManager(ociClient), nil
} else if strings.ToLower(cfg.KeyManager) == constant.VaultKeyManager {
vaultClient := vaultclient.NewVaultClient()
err := vaultClient.InitializeClient(cfg.Vault.ServerIP, cfg.Vault.ServerPort, cfg.Vault.ClientToken)
Expand Down
3 changes: 2 additions & 1 deletion service/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ func (svc service) CreateKey(_ context.Context, keyCreateReq model.KeyRequest) (

var err error
var createdKey *model.KeyResponse
if keyCreateReq.KeyInfo.KeyData == "" && keyCreateReq.KeyInfo.KmipKeyID == "" {
if keyCreateReq.KeyInfo.KeyData == "" &&
(keyCreateReq.KeyInfo.KmipKeyID == "" || keyCreateReq.KeyInfo.OciSecretId == "") {

log.Debug("Create key request received")
createdKey, err = svc.remoteManager.CreateKey(&keyCreateReq)
Expand Down

0 comments on commit d327f1d

Please sign in to comment.