Skip to content
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

[CCE] Fix authenticating_proxy cluster auth mode #1418

Merged
merged 1 commit into from Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/resources/cce_cluster_v3.md
Expand Up @@ -124,6 +124,17 @@ The following arguments are supported:
Defaults to `rbac`. Changing this parameter will create a new cluster resource.

* `authenticating_proxy_ca` - (Optional) CA root certificate provided in the `authenticating_proxy` mode.
Deprecated, use `authenticating_proxy` instead.

* `authenticating_proxy` - (Optional) Authenticating proxy configuration. Required if `authentication_mode` is set to `authenticating_proxy`.
* `ca` - X509 CA certificate configured in `authenticating_proxy` mode. The maximum size of the certificate is 1 MB.
* `cert` - Client certificate issued by the X509 CA certificate configured in `authenticating_proxy` mode.
This certificate is used for authentication from kube-apiserver to the extended API server.
* `private_key` - Private key of the client certificate issued by the X509 CA certificate configured in `authenticating_proxy` mode.
This key is used for authentication from kube-apiserver to the extended API server.

~>
The private key used by the Kubernetes cluster does not support password encryption. Use an unencrypted private key.

* `multi_az` - (Optional) Enable multiple AZs for the cluster, only when using HA flavors. Changing this parameter will create a new cluster resource.

Expand Down
Expand Up @@ -281,31 +281,52 @@ resource "opentelekomcloud_cce_cluster_v3" "cluster_1" {
container_network_type = "overlay_l2"
kubernetes_svc_ip_range = "10.247.0.0/16"
authentication_mode = "authenticating_proxy"
authenticating_proxy_ca = <<EOT
authenticating_proxy {
ca = <<EOT
-----BEGIN CERTIFICATE-----
MIIDpTCCAo2gAwIBAgIJAKdmmOBYnFvoMA0GCSqGSIb3DQEBCwUAMGkxCzAJBgNV
BAYTAnh4MQswCQYDVQQIDAJ4eDELMAkGA1UEBwwCeHgxC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IVATE KEY-----
EOT
}
}
`, common.DataSourceSubnet, clusterName)

testAccCCEClusterV3InvalidSubnet = fmt.Sprintf(`
%s
Expand Down
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/hashicorp/go-multierror"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
Expand Down Expand Up @@ -49,7 +50,10 @@ func ResourceCCEClusterV3() *schema.Resource {
Delete: schema.DefaultTimeout(30 * time.Minute),
},

CustomizeDiff: validateCCEClusterNetwork,
CustomizeDiff: customdiff.All(
validateCCEClusterNetwork,
validateAuthProxy,
),

Schema: map[string]*schema.Schema{
"region": {
Expand Down Expand Up @@ -142,10 +146,36 @@ func ResourceCCEClusterV3() *schema.Resource {
ForceNew: true,
Default: "x509",
},
"authenticating_proxy_ca": {
Type: schema.TypeString,
"authenticating_proxy": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ca": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"cert": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"private_key": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
},
},
},
"authenticating_proxy_ca": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Deprecated: "Please use `authenticating_proxy` instead",
},
"kubernetes_svc_ip_range": {
Type: schema.TypeString,
Expand Down Expand Up @@ -291,9 +321,13 @@ func resourceCCEClusterV3Create(ctx context.Context, d *schema.ResourceData, met
}
}

authProxy := make(map[string]string)
authProxy := map[string]string{}
if ca, ok := d.GetOk("authenticating_proxy_ca"); ok {
authProxy["ca"] = common.Base64IfNot(ca.(string))
authProxy = map[string]string{
"ca": common.Base64IfNot(ca.(string)),
}
} else if _, ok := d.GetOk("authenticating_proxy"); ok {
authProxy = getAuthProxy(d)
}

createOpts := clusters.CreateOpts{
Expand Down Expand Up @@ -766,3 +800,25 @@ func isAuthRequired(err error) bool {
}
return false
}

func getAuthProxy(d *schema.ResourceData) map[string]string {
if d.Get("authenticating_proxy.#").(int) == 0 {
return nil
}
resMap := map[string]string{
"ca": common.Base64IfNot(d.Get("authenticating_proxy.0.ca").(string)),
"cert": common.Base64IfNot(d.Get("authenticating_proxy.0.cert").(string)),
"privateKey": common.Base64IfNot(d.Get("authenticating_proxy.0.private_key").(string)),
}
return resMap
}

func validateAuthProxy(_ context.Context, d *schema.ResourceDiff, _ interface{}) error {
if d.Get("authentication_mode") != "authenticating_proxy" {
return nil
}
if d.Get("authenticating_proxy.#").(int) == 0 {
return fmt.Errorf("`authenticating_proxy` fields needs to be set if auth mode is `authenticating_proxy`")
}
return nil
}
8 changes: 8 additions & 0 deletions releasenotes/notes/cce-auth-proxy-63baf6c8c7e08aae.yaml
@@ -0,0 +1,8 @@
---
enhancements:
- |
**[CCE]** Add ``authenticating_proxy`` argument to ``resource/opentelekomcloud_cce_cluster_v3`` (`#1418 <https://github.com/opentelekomcloud/terraform-provider-opentelekomcloud/pull/1418>`_)
deprecations:
- |
**[CCE]** Mark ``authenticating_proxy_ca`` argument of ``resource/opentelekomcloud_cce_cluster_v3`` as deprecated,
as passing only CA is not enough in current CCE version (`#1418 <https://github.com/opentelekomcloud/terraform-provider-opentelekomcloud/pull/1418>`_)