Skip to content

feat: add Alibaba Cloud (Aliyun) KMS provider#2148

Open
cnCloXie wants to merge 6 commits intogetsops:mainfrom
cnCloXie:feat/alibaba-cloud-kms-provider
Open

feat: add Alibaba Cloud (Aliyun) KMS provider#2148
cnCloXie wants to merge 6 commits intogetsops:mainfrom
cnCloXie:feat/alibaba-cloud-kms-provider

Conversation

@cnCloXie
Copy link
Copy Markdown

Summary

Thank you for building and maintaining sops — it has become an essential tool in our infrastructure for managing secrets safely alongside GitOps workflows.

Motivation

We use sops extensively to encrypt Kubernetes secrets and configuration files committed to Git. Our infrastructure runs on Alibaba Cloud (Aliyun), and we use Alibaba Cloud KMS to manage encryption keys. While sops already supports AWS KMS, GCP KMS, Azure Key Vault, and HuaweiCloud KMS, there is currently no native support for Alibaba Cloud KMS. This gap means teams on Alibaba Cloud either have to maintain a custom fork or fall back to less integrated solutions.

This PR adds a first-class acs_kms provider so that Alibaba Cloud users can use sops the same way as other cloud KMS users.

What this PR does

  • Adds a new acskms package implementing the keys.MasterKey interface for Alibaba Cloud KMS
  • Supports KMS key ARN format: acs:kms:{region}:{account-id}:key/{key-id} and alias/{name}
  • Credential resolution chain:
    1. Environment variables: ALIBABA_CLOUD_ACCESS_KEY_ID / ALIBABA_CLOUD_ACCESS_KEY_SECRET (with optional ALIBABA_CLOUD_ACCESS_KEY_STS_TOKEN)
    2. Alibaba Cloud CLI config file (~/.aliyun/config.json), supporting AK, StsToken, and CloudSSO profile types, selected via ALIBABA_CLOUD_PROFILE env var
  • Wires the provider into stores, config, and keyservice layers
  • Adds --acs-kms, --add-acs-kms, --rm-acs-kms CLI flags
  • Adds acs_kms support in .sops.yaml creation rules
  • Documents the new provider in README.rst
  • Includes unit tests covering ARN parsing, key construction, serialization, and credential loading

Notes for maintainers

  • Uses the official Alibaba Cloud SDK: github.com/alibabacloud-go/kms-20160120/v3
  • The keyservice integration avoids modifying keyservice.proto by defining AcsKmsKey and Key_AcsKmsKey as plain Go types in the same package implementing the unexported isKey_KeyType() interface (consistent with the approach used for other non-proto providers). If you prefer a proper proto change, happy to update.
  • The implementation has been validated end-to-end against a real Alibaba Cloud KMS key (both shared KMS gateway and Dedicated KMS-backed keys).

Related

This fills the same role as --gcp-kms, --azure-kv, and --hckms for Alibaba Cloud users.

Implements the keys.MasterKey interface for Alibaba Cloud (Aliyun) KMS,
following the same patterns as hckms and gcpkms.

Key features:
- MasterKey with Encrypt/Decrypt via alibabacloud-go/kms-20160120/v3 SDK
- ARN format: acs:kms:{region}:{account-id}:key/{key-id} or alias/{name}
- Region is extracted automatically from the ARN
- Credential chain: env vars (ALIBABA_CLOUD_ACCESS_KEY_ID / SECRET) with
  fallback to ~/.aliyun/config.json, supporting AK, StsToken and CloudSSO
  profile modes (profile selected via ALIBABA_CLOUD_PROFILE env var)
- Unit tests covering ARN parsing, key construction, rotation, and serialization

I need to use Alibaba Cloud KMS to encrypt secrets managed by sops in my
infrastructure. This adds first-class support for the Aliyun KMS service,
consistent with the existing AWS KMS, GCP KMS and Azure Key Vault providers.

Signed-off-by: Clovis Xie <clovis.xie@lego.com>
Add AcsKmsKey and Key_AcsKmsKey types for local keyservice dispatch,
implementing the isKey_KeyType() interface without modifying the
protobuf-generated file. The local client handles encrypt/decrypt for
*acskms.MasterKey directly, consistent with how other KMS providers work.

Also adds encryptWithAcsKms/decryptWithAcsKms helpers in server.go and
a case in KeyFromMasterKey for *acskms.MasterKey.

Signed-off-by: Clovis Xie <clovis.xie@lego.com>
stores/stores.go:
- Add acskmskey struct with arn/created_at/enc fields
- Add ACSKMSKeys field to Metadata and keygroup structs
- Add acskmsKeysFromGroup() and toInternal() serialization helpers
- Handle acs_kms keys in internalGroupFrom()

config/config.go:
- Add acs_kms creation rule field parsed from .sops.yaml
- Add GetACSKMSKeys() to return MasterKeys for a creationRule
- Wire into extractMasterKeys() and getKeyGroupsFromCreationRule()

Signed-off-by: Clovis Xie <clovis.xie@lego.com>
Add three new flags alongside the existing --hc-vault-transit / --gcp-kms
flags pattern:
  --acs-kms        comma-separated list of Alibaba Cloud KMS ARNs (encrypt/edit)
  --add-acs-kms    add KMS ARNs to an existing encrypted file
  --rm-acs-kms     remove KMS ARNs from an existing encrypted file

Wire into getMasterKeys() and keyGroups() to build the proper MasterKey slice.

Signed-off-by: Clovis Xie <clovis.xie@lego.com>
Required by the new acskms provider package.

Signed-off-by: Clovis Xie <clovis.xie@lego.com>
Document the new acs_kms provider including:
- Supported credential methods and resolution order
- KMS key ARN format
- Encrypt/decrypt usage examples
- .sops.yaml configuration example
- Updated 'Adding and removing keys' section to mention --acs-kms flag

Signed-off-by: Clovis Xie <clovis.xie@lego.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant