Skip to content

Commit c1f9917

Browse files
modular-magicianrileykarsonslevenick
authored
Remove username and password from master_auth (#5372) (#10441)
* Remove `username` and `password` from `master_auth` * Add client_certificate_required note * Update mmv1/third_party/terraform/website/docs/guides/version_4_upgrade.html.markdown Co-authored-by: Riley Karson <[email protected]> * Remove bad merge Co-authored-by: Riley Karson <[email protected]> Co-authored-by: Sam Levenick <[email protected]> Signed-off-by: Modular Magician <[email protected]> Co-authored-by: Riley Karson <[email protected]> Co-authored-by: Sam Levenick <[email protected]>
1 parent 3cb6c91 commit c1f9917

7 files changed

+69
-101
lines changed

.changelog/5372.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
```release-note:breaking-change
2+
container: removed `master_auth.username` and `master_auth.password` from `google_container_cluster`
3+
```
4+
```release-note:breaking-change
5+
container: made `master_auth.client_certificate_config` required
6+
```

google/resource_container_cluster.go

+7-73
Original file line numberDiff line numberDiff line change
@@ -554,37 +554,15 @@ func resourceContainerCluster() *schema.Resource {
554554
Optional: true,
555555
MaxItems: 1,
556556
Computed: true,
557-
Deprecated: `Basic authentication was removed for GKE cluster versions >= 1.19.`,
558-
Description: `The authentication information for accessing the Kubernetes master. Some values in this block are only returned by the API if your service account has permission to get credentials for your GKE cluster. If you see an unexpected diff removing a username/password or unsetting your client cert, ensure you have the container.clusters.getCredentials permission.`,
557+
Description: `The authentication information for accessing the Kubernetes master. Some values in this block are only returned by the API if your service account has permission to get credentials for your GKE cluster. If you see an unexpected diff unsetting your client cert, ensure you have the container.clusters.getCredentials permission.`,
559558
Elem: &schema.Resource{
560559
Schema: map[string]*schema.Schema{
561-
"password": {
562-
Type: schema.TypeString,
563-
Optional: true,
564-
AtLeastOneOf: []string{"master_auth.0.password", "master_auth.0.username", "master_auth.0.client_certificate_config"},
565-
Sensitive: true,
566-
Description: `The password to use for HTTP basic authentication when accessing the Kubernetes master endpoint.`,
567-
},
568-
569-
"username": {
570-
Type: schema.TypeString,
571-
Optional: true,
572-
AtLeastOneOf: []string{"master_auth.0.password", "master_auth.0.username", "master_auth.0.client_certificate_config"},
573-
Description: `The username to use for HTTP basic authentication when accessing the Kubernetes master endpoint. If not present basic auth will be disabled.`,
574-
},
575-
576-
// Ideally, this would be Optional (and not Computed).
577-
// In past versions (incl. 2.X series) of the provider
578-
// though, being unset was considered identical to set
579-
// and the issue_client_certificate value being true.
580560
"client_certificate_config": {
581-
Type: schema.TypeList,
582-
MaxItems: 1,
583-
Optional: true,
584-
Computed: true,
585-
AtLeastOneOf: []string{"master_auth.0.password", "master_auth.0.username", "master_auth.0.client_certificate_config"},
586-
ForceNew: true,
587-
Description: `Whether client certificate authorization is enabled for this cluster.`,
561+
Type: schema.TypeList,
562+
MaxItems: 1,
563+
Required: true,
564+
ForceNew: true,
565+
Description: `Whether client certificate authorization is enabled for this cluster.`,
588566
Elem: &schema.Resource{
589567
Schema: map[string]*schema.Schema{
590568
"issue_client_certificate": {
@@ -2173,45 +2151,6 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
21732151
}
21742152
}
21752153

2176-
if d.HasChange("master_auth") {
2177-
var req *container.SetMasterAuthRequest
2178-
if ma, ok := d.GetOk("master_auth"); ok {
2179-
req = &container.SetMasterAuthRequest{
2180-
Action: "SET_USERNAME",
2181-
Update: expandMasterAuth(ma),
2182-
}
2183-
} else {
2184-
req = &container.SetMasterAuthRequest{
2185-
Action: "SET_USERNAME",
2186-
Update: &container.MasterAuth{
2187-
Username: "admin",
2188-
},
2189-
}
2190-
}
2191-
2192-
updateF := func() error {
2193-
name := containerClusterFullName(project, location, clusterName)
2194-
clusterSetMasterAuthCall := config.NewContainerClient(userAgent).Projects.Locations.Clusters.SetMasterAuth(name, req)
2195-
if config.UserProjectOverride {
2196-
clusterSetMasterAuthCall.Header().Add("X-Goog-User-Project", project)
2197-
}
2198-
op, err := clusterSetMasterAuthCall.Do()
2199-
if err != nil {
2200-
return err
2201-
}
2202-
2203-
// Wait until it's updated
2204-
return containerOperationWait(config, op, project, location, "updating master auth", userAgent, d.Timeout(schema.TimeoutUpdate))
2205-
}
2206-
2207-
// Call update serially.
2208-
if err := lockedCall(lockKey, updateF); err != nil {
2209-
return err
2210-
}
2211-
2212-
log.Printf("[INFO] GKE cluster %s: master auth has been updated", d.Id())
2213-
}
2214-
22152154
if d.HasChange("vertical_pod_autoscaling") {
22162155
if ac, ok := d.GetOk("vertical_pod_autoscaling"); ok {
22172156
req := &container.UpdateClusterRequest{
@@ -2817,10 +2756,7 @@ func expandMasterAuth(configured interface{}) *container.MasterAuth {
28172756
}
28182757

28192758
masterAuth := l[0].(map[string]interface{})
2820-
result := &container.MasterAuth{
2821-
Username: masterAuth["username"].(string),
2822-
Password: masterAuth["password"].(string),
2823-
}
2759+
result := &container.MasterAuth{}
28242760

28252761
if v, ok := masterAuth["client_certificate_config"]; ok {
28262762
if len(v.([]interface{})) > 0 {
@@ -3269,8 +3205,6 @@ func flattenMasterAuth(ma *container.MasterAuth) []map[string]interface{} {
32693205
}
32703206
masterAuth := []map[string]interface{}{
32713207
{
3272-
"username": ma.Username,
3273-
"password": ma.Password,
32743208
"client_certificate": ma.ClientCertificate,
32753209
"client_key": ma.ClientKey,
32763210
"cluster_ca_certificate": ma.ClusterCaCertificate,

google/resource_container_cluster_test.go

+40
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,31 @@ func TestAccContainerCluster_withAddons(t *testing.T) {
174174
})
175175
}
176176

177+
func TestAccContainerCluster_withMasterAuthConfig_NoCert(t *testing.T) {
178+
t.Parallel()
179+
180+
clusterName := fmt.Sprintf("tf-test-cluster-%s", randString(t, 10))
181+
182+
vcrTest(t, resource.TestCase{
183+
PreCheck: func() { testAccPreCheck(t) },
184+
Providers: testAccProviders,
185+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
186+
Steps: []resource.TestStep{
187+
{
188+
Config: testAccContainerCluster_withMasterAuthNoCert(clusterName),
189+
Check: resource.ComposeTestCheckFunc(
190+
resource.TestCheckResourceAttr("google_container_cluster.with_master_auth_no_cert", "master_auth.0.client_certificate", ""),
191+
),
192+
},
193+
{
194+
ResourceName: "google_container_cluster.with_master_auth_no_cert",
195+
ImportState: true,
196+
ImportStateVerify: true,
197+
},
198+
},
199+
})
200+
}
201+
177202
func TestAccContainerCluster_withAuthenticatorGroupsConfig(t *testing.T) {
178203
t.Parallel()
179204
clusterName := fmt.Sprintf("tf-test-cluster-%s", randString(t, 10))
@@ -2298,6 +2323,21 @@ resource "google_container_cluster" "with_version" {
22982323
`, clusterName)
22992324
}
23002325

2326+
func testAccContainerCluster_withMasterAuthNoCert(clusterName string) string {
2327+
return fmt.Sprintf(`
2328+
resource "google_container_cluster" "with_master_auth_no_cert" {
2329+
name = "%s"
2330+
location = "us-central1-a"
2331+
initial_node_count = 3
2332+
master_auth {
2333+
client_certificate_config {
2334+
issue_client_certificate = false
2335+
}
2336+
}
2337+
}
2338+
`, clusterName)
2339+
}
2340+
23012341
func testAccContainerCluster_updateVersion(clusterName string) string {
23022342
return fmt.Sprintf(`
23032343
data "google_container_engine_versions" "central1a" {

website/docs/d/container_cluster.html.markdown

-8
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@ data "google_container_cluster" "my_cluster" {
1919
location = "us-east1-a"
2020
}
2121
22-
output "cluster_username" {
23-
value = data.google_container_cluster.my_cluster.master_auth[0].username
24-
}
25-
26-
output "cluster_password" {
27-
value = data.google_container_cluster.my_cluster.master_auth[0].password
28-
}
29-
3022
output "endpoint" {
3123
value = data.google_container_cluster.my_cluster.endpoint
3224
}

website/docs/d/container_engine_versions.html.markdown

-5
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ resource "google_container_cluster" "foo" {
3131
location = "us-central1-b"
3232
node_version = data.google_container_engine_versions.central1b.latest_node_version
3333
initial_node_count = 1
34-
35-
master_auth {
36-
username = "mr.yoda"
37-
password = "adoy.rm"
38-
}
3934
}
4035
4136
output "stable_channel_version" {

website/docs/guides/version_4_upgrade.html.markdown

+12-5
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ description: |-
4949
- [Resource: `google_container_cluster`](#resource-google_container_cluster)
5050
- [`enable_shielded_nodes` now defaults to `true`](#enable_shielded_nodes-now-defaults-to-true)
5151
- [`instance_group_urls` is now removed](#instance_group_urls-is-now-removed)
52-
- [`master_auth` is now removed](#master_auth-is-now-removed)
52+
- [`master_auth.username` and `master_auth.password` are now removed](#master_authusername-and-master_authpassword-are-now-removed)
53+
- [`master_auth.client_certificate_config` is now required](#master_authclient_certificate_config-is-now-required)
5354
- [`node_config.workload_metadata_config.node_metadata` is now removed](#node_configworkload_metadata_confignode_metadata-is-now-removed)
5455
- [`workload_identity_config.0.identity_namespace` is now removed](#workload_identity_config0identity_namespace-is-now-removed)
5556
- [`pod_security_policy_config` is removed from the GA provider](#pod_security_policy_config-is-removed-from-the-ga-provider)
@@ -73,13 +74,13 @@ description: |-
7374
- [`bigquery-json.googleapis.com` is no longer a valid service name](#bigquery-jsongoogleapiscom-is-no-longer-a-valid-service-name)
7475
- [Resource: `google_spanner_instance`](#resource-google_spanner_instance)
7576
- [Exactly one of `num_nodes` or `processing_units` is required](#exactly-one-of-num_nodes-or-processing_units-is-required)
76-
- [Resource: `google_sql_database_instance`](#resource-google_sql_database_instance)
77+
- [Resource: `google_sql_database_instance`](#resource-google_sql_database_instance)
7778
- [First-generation fields have been removed](#first-generation-fields-have-been-removed)
7879
- [Drift detection and defaults enabled on fields](#drift-detection-and-defaults-enabled-on-fields)
7980
- [Resource: `google_storage_bucket`](#resource-google_storage_bucket)
8081
- [`bucket_policy_only` field is now removed](#bucket_policy_only-field-is-now-removed)
8182
- [`location` field is now required.](#location-field-is-now-required)
82-
- [Resource: `google_sql_database_instance`](#resource-google_sql_database_instance)
83+
- [Resource: `google_sql_database_instance`](#resource-google_sql_database_instance-1)
8384
- [`database_version` field is now required](#database_version-field-is-now-required)
8485
- [Resource: `google_pubsub_subscription`](#resource-google_pubsub_subscription)
8586
- [`path` is now removed](#path-is-now-removed)
@@ -375,11 +376,17 @@ Unless explicitly configured, users may see a diff changing `enable_shielded_nod
375376

376377
`instance_group_urls` has been removed in favor of `node_pool.instance_group_urls`
377378

378-
### `master_auth` is now removed
379+
### `master_auth.username` and `master_auth.password` are now removed
379380

380-
`master_auth` and its subfields have been removed.
381+
`master_auth.username` and `master_auth.password` have been removed.
381382
Basic authentication was removed for GKE cluster versions >= 1.19. The cluster cannot be created with basic authentication enabled. Instructions for choosing an alternative authentication method can be found at: cloud.google.com/kubernetes-engine/docs/how-to/api-server-authentication.
382383

384+
### `master_auth.client_certificate_config` is now required
385+
386+
With the removal of `master_auth.username` and `master_auth.password`, `master_auth.client_certificate_config` is now
387+
the only configurable field in `master_auth`. If you do not wish to configure `master_auth.client_certificate_config`,
388+
remove the `master_auth` block from your configuration entirely. You will still be able to reference the outputted fields under `master_auth` without the block defined.
389+
383390
### `node_config.workload_metadata_config.node_metadata` is now removed
384391

385392
Removed in favor of `node_config.workload_metadata_config.mode`.

website/docs/r/container_cluster.html.markdown

+4-10
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,9 @@ and requires the `ip_allocation_policy` block to be defined. By default when thi
197197
* `master_auth` - (Optional) The authentication information for accessing the
198198
Kubernetes master. Some values in this block are only returned by the API if
199199
your service account has permission to get credentials for your GKE cluster. If
200-
you see an unexpected diff removing a username/password or unsetting your client
201-
cert, ensure you have the `container.clusters.getCredentials` permission.
202-
Structure is [documented below](#nested_master_auth). This has been deprecated as of GKE 1.19.
200+
you see an unexpected diff unsetting your client cert, ensure you have the
201+
`container.clusters.getCredentials` permission.
202+
Structure is [documented below](#nested_master_auth).
203203

204204
* `master_authorized_networks_config` - (Optional) The desired
205205
configuration options for master authorized networks. Omit the
@@ -576,13 +576,7 @@ pick a specific range to use.
576576

577577
<a name="nested_master_auth"></a>The `master_auth` block supports:
578578

579-
* `password` - (Optional) The password to use for HTTP basic authentication when accessing
580-
the Kubernetes master endpoint. This has been deprecated as of GKE 1.19.
581-
582-
* `username` - (Optional) The username to use for HTTP basic authentication when accessing
583-
the Kubernetes master endpoint. If not present basic auth will be disabled. This has been deprecated as of GKE 1.19.
584-
585-
* `client_certificate_config` - (Optional) Whether client certificate authorization is enabled for this cluster. For example:
579+
* `client_certificate_config` - (Required) Whether client certificate authorization is enabled for this cluster. For example:
586580

587581
```hcl
588582
master_auth {

0 commit comments

Comments
 (0)