This repository has been archived by the owner on Oct 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 525
/
defaults-apiserver.go
174 lines (153 loc) · 7.26 KB
/
defaults-apiserver.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
package api
import (
"fmt"
"strconv"
"github.com/Azure/go-autorest/autorest/to"
"github.com/Azure/aks-engine/pkg/api/common"
"github.com/Azure/aks-engine/pkg/helpers"
)
func (cs *ContainerService) setAPIServerConfig() {
o := cs.Properties.OrchestratorProfile
staticAPIServerConfig := map[string]string{
"--bind-address": "0.0.0.0",
"--advertise-address": "<advertiseAddr>",
"--allow-privileged": "true",
"--anonymous-auth": "false",
"--audit-log-path": "/var/log/kubeaudit/audit.log",
"--insecure-port": "8080",
"--secure-port": "443",
"--service-account-lookup": "true",
"--etcd-certfile": "/etc/kubernetes/certs/etcdclient.crt",
"--etcd-keyfile": "/etc/kubernetes/certs/etcdclient.key",
"--tls-cert-file": "/etc/kubernetes/certs/apiserver.crt",
"--tls-private-key-file": "/etc/kubernetes/certs/apiserver.key",
"--client-ca-file": "/etc/kubernetes/certs/ca.crt",
"--repair-malformed-updates": "false",
"--service-account-key-file": "/etc/kubernetes/certs/apiserver.key",
"--kubelet-client-certificate": "/etc/kubernetes/certs/client.crt",
"--kubelet-client-key": "/etc/kubernetes/certs/client.key",
"--service-cluster-ip-range": o.KubernetesConfig.ServiceCIDR,
"--storage-backend": o.GetAPIServerEtcdAPIVersion(),
"--enable-bootstrap-token-auth": "true",
"--v": "4",
}
if cs.Properties.MasterProfile != nil {
if cs.Properties.MasterProfile.HasCosmosEtcd() {
// Configuration for cosmos etcd
staticAPIServerConfig["--etcd-servers"] = fmt.Sprintf("https://%s:%s", cs.Properties.MasterProfile.GetCosmosEndPointURI(), strconv.Itoa(DefaultMasterEtcdClientPort))
} else {
// Configuration for local etcd
staticAPIServerConfig["--etcd-cafile"] = "/etc/kubernetes/certs/ca.crt"
staticAPIServerConfig["--etcd-servers"] = fmt.Sprintf("https://127.0.0.1:%s", strconv.Itoa(DefaultMasterEtcdClientPort))
}
}
// Default apiserver config
defaultAPIServerConfig := map[string]string{
"--audit-log-maxage": "30",
"--audit-log-maxbackup": "10",
"--audit-log-maxsize": "100",
"--profiling": DefaultKubernetesAPIServerEnableProfiling,
"--tls-cipher-suites": TLSStrongCipherSuitesAPIServer,
}
// Data Encryption at REST configuration conditions
if to.Bool(o.KubernetesConfig.EnableDataEncryptionAtRest) || to.Bool(o.KubernetesConfig.EnableEncryptionWithExternalKms) {
staticAPIServerConfig["--experimental-encryption-provider-config"] = "/etc/kubernetes/encryption-config.yaml"
}
// Aggregated API configuration
if o.KubernetesConfig.EnableAggregatedAPIs {
defaultAPIServerConfig["--requestheader-client-ca-file"] = "/etc/kubernetes/certs/proxy-ca.crt"
defaultAPIServerConfig["--proxy-client-cert-file"] = "/etc/kubernetes/certs/proxy.crt"
defaultAPIServerConfig["--proxy-client-key-file"] = "/etc/kubernetes/certs/proxy.key"
defaultAPIServerConfig["--requestheader-allowed-names"] = ""
defaultAPIServerConfig["--requestheader-extra-headers-prefix"] = "X-Remote-Extra-"
defaultAPIServerConfig["--requestheader-group-headers"] = "X-Remote-Group"
defaultAPIServerConfig["--requestheader-username-headers"] = "X-Remote-User"
}
// Enable cloudprovider if we're not using cloud controller manager
if !to.Bool(o.KubernetesConfig.UseCloudControllerManager) {
staticAPIServerConfig["--cloud-provider"] = "azure"
staticAPIServerConfig["--cloud-config"] = "/etc/kubernetes/azure.json"
}
// AAD configuration
if cs.Properties.HasAadProfile() {
defaultAPIServerConfig["--oidc-username-claim"] = "oid"
defaultAPIServerConfig["--oidc-groups-claim"] = "groups"
defaultAPIServerConfig["--oidc-client-id"] = "spn:" + cs.Properties.AADProfile.ServerAppID
issuerHost := "sts.windows.net"
if helpers.GetTargetEnv(cs.Location, cs.Properties.GetCustomCloudName()) == "AzureChinaCloud" {
issuerHost = "sts.chinacloudapi.cn"
}
defaultAPIServerConfig["--oidc-issuer-url"] = "https://" + issuerHost + "/" + cs.Properties.AADProfile.TenantID + "/"
}
// Audit Policy configuration
if common.IsKubernetesVersionGe(o.OrchestratorVersion, "1.8.0") {
defaultAPIServerConfig["--audit-policy-file"] = "/etc/kubernetes/addons/audit-policy.yaml"
}
// RBAC configuration
if to.Bool(o.KubernetesConfig.EnableRbac) {
if common.IsKubernetesVersionGe(o.OrchestratorVersion, "1.7.0") {
defaultAPIServerConfig["--authorization-mode"] = "Node,RBAC"
} else {
defaultAPIServerConfig["--authorization-mode"] = "RBAC"
}
}
// Set default admission controllers
admissionControlKey, admissionControlValues := getDefaultAdmissionControls(cs)
defaultAPIServerConfig[admissionControlKey] = admissionControlValues
// If no user-configurable apiserver config values exists, use the defaults
if o.KubernetesConfig.APIServerConfig == nil {
o.KubernetesConfig.APIServerConfig = defaultAPIServerConfig
} else {
for key, val := range defaultAPIServerConfig {
// If we don't have a user-configurable apiserver config for each option
if _, ok := o.KubernetesConfig.APIServerConfig[key]; !ok {
// then assign the default value
o.KubernetesConfig.APIServerConfig[key] = val
} else {
// Manual override of "--audit-policy-file" for back-compat
if key == "--audit-policy-file" {
if o.KubernetesConfig.APIServerConfig[key] == "/etc/kubernetes/manifests/audit-policy.yaml" {
o.KubernetesConfig.APIServerConfig[key] = val
}
}
}
}
}
// We don't support user-configurable values for the following,
// so any of the value assignments below will override user-provided values
for key, val := range staticAPIServerConfig {
o.KubernetesConfig.APIServerConfig[key] = val
}
// Remove flags for secure communication to kubelet, if configured
if !to.Bool(o.KubernetesConfig.EnableSecureKubelet) {
for _, key := range []string{"--kubelet-client-certificate", "--kubelet-client-key"} {
delete(o.KubernetesConfig.APIServerConfig, key)
}
}
// Enforce flags removal that don't work with specific versions, to accommodate upgrade
// Remove flags that are not compatible with 1.10
if common.IsKubernetesVersionGe(o.OrchestratorVersion, "1.10.0") {
for _, key := range []string{"--admission-control"} {
delete(o.KubernetesConfig.APIServerConfig, key)
}
}
// Enforce flags removal that don't work with specific versions, to accommodate upgrade
// Remove flags that are not compatible with 1.14
if common.IsKubernetesVersionGe(o.OrchestratorVersion, "1.14.0-alpha.1") {
for _, key := range []string{"--repair-malformed-updates"} {
delete(o.KubernetesConfig.APIServerConfig, key)
}
}
}
func getDefaultAdmissionControls(cs *ContainerService) (string, string) {
o := cs.Properties.OrchestratorProfile
admissionControlKey := "--enable-admission-plugins"
admissionControlValues := "NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,DefaultTolerationSeconds,ValidatingAdmissionWebhook,ResourceQuota,ExtendedResourceToleration"
// Pod Security Policy configuration
if to.Bool(o.KubernetesConfig.EnablePodSecurityPolicy) {
admissionControlValues += ",PodSecurityPolicy"
}
return admissionControlKey, admissionControlValues
}