-
Notifications
You must be signed in to change notification settings - Fork 605
[WIP] CNTRLPLANE-2711: add vault kms plug configuration api #2805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
flavianmissi
wants to merge
4
commits into
openshift:master
Choose a base branch
from
flavianmissi:CNTRLPLANE-2711-kms-api-2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 0 additions & 127 deletions
127
config/v1/tests/apiservers.config.openshift.io/KMSEncryptionProvider.yaml
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,55 +1,144 @@ | ||
| package v1 | ||
|
|
||
| // KMSConfig defines the configuration for the KMS instance | ||
| // that will be used with KMSEncryptionProvider encryption | ||
| // +kubebuilder:validation:XValidation:rule="has(self.type) && self.type == 'AWS' ? has(self.aws) : !has(self.aws)",message="aws config is required when kms provider type is AWS, and forbidden otherwise" | ||
| // that will be used with KMS encryption | ||
| // +openshift:validation:FeatureGateAwareXValidation:featureGate=KMSEncryption,rule="has(self.type) && self.type == 'Vault' ? (has(self.vault) && self.vault.vaultAddress != \"\") : !has(self.vault)",message="vault config is required when kms provider type is Vault, and forbidden otherwise" | ||
| // +union | ||
| type KMSConfig struct { | ||
| // type defines the kind of platform for the KMS provider. | ||
| // Available provider types are AWS only. | ||
| // Valid values are: | ||
| // - "Vault": HashiCorp Vault KMS (available when KMSEncryption feature gate is enabled) | ||
| // | ||
| // +unionDiscriminator | ||
| // +required | ||
| Type KMSProviderType `json:"type"` | ||
|
|
||
| // aws defines the key config for using an AWS KMS instance | ||
| // for the encryption. The AWS KMS instance is managed | ||
| // vault defines the configuration for the Vault KMS plugin. | ||
| // The plugin connects to a Vault Enterprise server that is managed | ||
| // by the user outside the purview of the control plane. | ||
| // This field must be set when type is Vault, and must be unset otherwise. | ||
| // | ||
| // +openshift:enable:FeatureGate=KMSEncryption | ||
| // +unionMember | ||
| // +optional | ||
| AWS *AWSKMSConfig `json:"aws,omitempty"` | ||
| Vault *VaultKMSConfig `json:"vault,omitempty,omitzero"` | ||
| } | ||
|
|
||
| // AWSKMSConfig defines the KMS config specific to AWS KMS provider | ||
| type AWSKMSConfig struct { | ||
| // keyARN specifies the Amazon Resource Name (ARN) of the AWS KMS key used for encryption. | ||
| // The value must adhere to the format `arn:aws:kms:<region>:<account_id>:key/<key_id>`, where: | ||
| // - `<region>` is the AWS region consisting of lowercase letters and hyphens followed by a number. | ||
| // - `<account_id>` is a 12-digit numeric identifier for the AWS account. | ||
| // - `<key_id>` is a unique identifier for the KMS key, consisting of lowercase hexadecimal characters and hyphens. | ||
| // KMSProviderType is a specific supported KMS provider | ||
| // +openshift:validation:FeatureGateAwareEnum:featureGate=KMSEncryption,enum=Vault | ||
| type KMSProviderType string | ||
|
|
||
| const ( | ||
| // VaultKMSProvider represents a supported KMS provider for use with HashiCorp Vault | ||
| VaultKMSProvider KMSProviderType = "Vault" | ||
| ) | ||
|
|
||
| // VaultKMSConfig defines the KMS plugin configuration specific to Vault KMS | ||
| type VaultKMSConfig struct { | ||
| // kmsPluginImage specifies the container image for the HashiCorp Vault KMS plugin. | ||
| // The image must be specified using a digest reference (not a tag). | ||
| // | ||
| // Consult the OpenShift documentation for compatible plugin versions with your cluster version, | ||
| // then obtain the image digest for that version from HashiCorp's container registry. | ||
| // | ||
| // For disconnected environments, mirror the plugin image to an accessible registry and | ||
| // reference the mirrored location with its digest. | ||
| // | ||
| // The minimum length is 75 characters (e.g., "r/i@sha256:" + 64 hex characters). | ||
| // The maximum length is 512 characters to accommodate long registry names and repository paths. | ||
| // | ||
| // +kubebuilder:validation:XValidation:rule="self.matches(r'^([a-zA-Z0-9.-]+)(:[0-9]+)?/[a-zA-Z0-9._/-]+@sha256:[a-f0-9]{64}$')",message="vaultKMSPluginImage must be a valid image reference with a SHA256 digest (e.g., 'registry.example.com/vault-plugin@sha256:0123...abcd'). Use '@sha256:<64-character-hex-digest>' instead of image tags like ':latest' or ':v1.0.0'." | ||
| // +kubebuilder:validation:MinLength=75 | ||
| // +kubebuilder:validation:MaxLength=512 | ||
| // +required | ||
| KMSPluginImage string `json:"kmsPluginImage,omitempty"` | ||
|
|
||
| // vaultAddress specifies the address of the HashiCorp Vault instance. | ||
| // The value must be a valid URL with scheme (https://) and can be up to 512 characters. | ||
| // Example: https://vault.example.com:8200 | ||
| // | ||
| // +kubebuilder:validation:MaxLength=128 | ||
| // +kubebuilder:validation:XValidation:rule="self.matches('^https://')",message="vaultAddress must be a valid URL starting with 'https://' (e.g., 'https://vault.example.com:8200')." | ||
| // +kubebuilder:validation:MaxLength=512 | ||
| // +kubebuilder:validation:MinLength=1 | ||
| // +kubebuilder:validation:XValidation:rule="self.matches('^arn:aws:kms:[a-z0-9-]+:[0-9]{12}:key/[a-f0-9-]+$')",message="keyARN must follow the format `arn:aws:kms:<region>:<account_id>:key/<key_id>`. The account ID must be a 12 digit number and the region and key ID should consist only of lowercase hexadecimal characters and hyphens (-)." | ||
| // +required | ||
| KeyARN string `json:"keyARN"` | ||
| // region specifies the AWS region where the KMS instance exists, and follows the format | ||
| // `<region-prefix>-<region-name>-<number>`, e.g.: `us-east-1`. | ||
| // Only lowercase letters and hyphens followed by numbers are allowed. | ||
| VaultAddress string `json:"vaultAddress,omitempty"` | ||
|
flavianmissi marked this conversation as resolved.
|
||
|
|
||
| // vaultNamespace specifies the Vault namespace where the Transit secrets engine is mounted. | ||
| // This is only applicable for Vault Enterprise installations. | ||
| // The value can be between 1 and 4096 characters. | ||
| // When this field is not set, no namespace is used. | ||
| // | ||
| // +kubebuilder:validation:MaxLength=64 | ||
| // +kubebuilder:validation:MinLength=1 | ||
| // +kubebuilder:validation:XValidation:rule="self.matches('^[a-z0-9]+(-[a-z0-9]+)*$')",message="region must be a valid AWS region, consisting of lowercase characters, digits and hyphens (-) only." | ||
| // +kubebuilder:validation:MaxLength=4096 | ||
| // +optional | ||
| VaultNamespace string `json:"vaultNamespace,omitempty"` | ||
|
|
||
| // tls contains the TLS configuration for connecting to the Vault server. | ||
| // When this field is not set, system default TLS settings are used. | ||
| // +optional | ||
| TLS *VaultTLSConfig `json:"tls,omitempty"` | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| // approleSecretRef references a secret in the openshift-config namespace containing | ||
| // the AppRole credentials used to authenticate with Vault. | ||
| // The secret must contain the following keys: | ||
| // - "roleID": The AppRole Role ID | ||
| // - "secretID": The AppRole Secret ID | ||
| // | ||
| // The namespace for the secret referenced by approleSecretRef is openshift-config. | ||
| // | ||
| // +required | ||
| Region string `json:"region"` | ||
| ApproleSecretRef SecretNameReference `json:"approleSecretRef,omitempty"` | ||
|
|
||
| // transitMount specifies the mount path of the Vault Transit engine. | ||
| // The value can be between 1 and 1024 characters. | ||
| // When this field is not set, it defaults to "transit". | ||
| // | ||
| // +kubebuilder:validation:MinLength=1 | ||
| // +kubebuilder:validation:MaxLength=1024 | ||
| // +kubebuilder:default="transit" | ||
| // +optional | ||
| TransitMount string `json:"transitMount,omitempty"` | ||
|
|
||
| // transitKey specifies the name of the encryption key in Vault's Transit engine. | ||
| // This key is used to encrypt and decrypt data. | ||
| // The value must be between 1 and 512 characters. | ||
| // | ||
| // +kubebuilder:validation:MinLength=1 | ||
| // +kubebuilder:validation:MaxLength=512 | ||
| // +required | ||
| TransitKey string `json:"transitKey,omitempty"` | ||
| } | ||
|
|
||
| // KMSProviderType is a specific supported KMS provider | ||
| // +kubebuilder:validation:Enum=AWS | ||
| type KMSProviderType string | ||
| // VaultTLSConfig contains TLS configuration for connecting to Vault. | ||
| type VaultTLSConfig struct { | ||
| // caBundle references a ConfigMap in the openshift-config namespace containing | ||
| // the CA certificate bundle used to verify the TLS connection to the Vault server. | ||
| // The ConfigMap must contain the CA bundle in the key "ca-bundle.crt". | ||
| // When this field is not set, the system's trusted CA certificates are used. | ||
| // | ||
| // The namespace for the ConfigMap is openshift-config. | ||
| // | ||
| // Example ConfigMap: | ||
| // apiVersion: v1 | ||
| // kind: ConfigMap | ||
| // metadata: | ||
| // name: vault-ca-bundle | ||
| // namespace: openshift-config | ||
| // data: | ||
| // ca-bundle.crt: | | ||
| // -----BEGIN CERTIFICATE----- | ||
| // ... | ||
| // -----END CERTIFICATE----- | ||
| // | ||
| // +optional | ||
| CABundle ConfigMapNameReference `json:"caBundle,omitempty"` | ||
|
|
||
| const ( | ||
| // AWSKMSProvider represents a supported KMS provider for use with AWS KMS | ||
| AWSKMSProvider KMSProviderType = "AWS" | ||
| ) | ||
| // serverName specifies the Server Name Indication (SNI) to use when connecting to Vault via TLS. | ||
| // This is useful when the Vault server's hostname doesn't match its TLS certificate. | ||
| // When this field is not set, the hostname from vaultAddress is used for SNI. | ||
| // | ||
| // +kubebuilder:validation:MaxLength=253 | ||
| // +kubebuilder:validation:MinLength=1 | ||
| // +optional | ||
| ServerName string `json:"serverName,omitempty"` | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.