@@ -30,11 +30,14 @@ import (
30
30
"k8s.io/klog"
31
31
)
32
32
33
+ const (
34
+ // ADFSIdentitySystem is the override value for tenantID on Azure Stack clouds.
35
+ ADFSIdentitySystem = "adfs"
36
+ )
37
+
33
38
var (
34
39
// ErrorNoAuth indicates that no credentials are provided.
35
40
ErrorNoAuth = fmt .Errorf ("no credentials provided for Azure cloud provider" )
36
- // ADFSIdentitySystem indicates value of tenantId for ADFS on Azure Stack.
37
- ADFSIdentitySystem = "ADFS"
38
41
)
39
42
40
43
// AzureAuthConfig holds auth related part of cloud config
@@ -59,15 +62,19 @@ type AzureAuthConfig struct {
59
62
UserAssignedIdentityID string `json:"userAssignedIdentityID,omitempty" yaml:"userAssignedIdentityID,omitempty"`
60
63
// The ID of the Azure Subscription that the cluster is deployed in
61
64
SubscriptionID string `json:"subscriptionId,omitempty" yaml:"subscriptionId,omitempty"`
62
- // Identity system value for the deployment. This gets populate for Azure Stack case.
63
- IdentitySystem string `json:"identitySystem,omitempty" yaml:"identitySystem,omitempty"`
65
+ // IdentitySystem indicates the identity provider. Relevant only to hybrid clouds (Azure Stack).
66
+ // Allowed values are 'azure_ad' (default), 'adfs'.
67
+ IdentitySystem string `json:"identitySystem" yaml:"identitySystem"`
68
+ // CloudFQDN represents the hybrid cloud's fully qualified domain name: {location}.{domain}
69
+ // If set, cloud provider will generate its autorest.Environment instead of using one of the pre-defined ones.
70
+ CloudFQDN string `json:"cloudFQDN" yaml:"cloudFQDN"`
64
71
}
65
72
66
73
// GetServicePrincipalToken creates a new service principal token based on the configuration
67
74
func GetServicePrincipalToken (config * AzureAuthConfig , env * azure.Environment ) (* adal.ServicePrincipalToken , error ) {
68
75
var tenantID string
69
76
if strings .EqualFold (config .IdentitySystem , ADFSIdentitySystem ) {
70
- tenantID = "adfs"
77
+ tenantID = ADFSIdentitySystem
71
78
} else {
72
79
tenantID = config .TenantID
73
80
}
@@ -126,10 +133,18 @@ func GetServicePrincipalToken(config *AzureAuthConfig, env *azure.Environment) (
126
133
}
127
134
128
135
// ParseAzureEnvironment returns azure environment by name
129
- func ParseAzureEnvironment (cloudName string ) (* azure.Environment , error ) {
136
+ func ParseAzureEnvironment (cloudName , cloudFQDN , identitySystem string ) (* azure.Environment , error ) {
130
137
var env azure.Environment
131
138
var err error
132
- if cloudName == "" {
139
+ if cloudFQDN != "" {
140
+ resourceManagerEndpoint := fmt .Sprintf ("https://management.%s/" , cloudFQDN )
141
+ nameOverride := azure.OverrideProperty {Key : azure .EnvironmentName , Value : cloudName }
142
+ klog .V (4 ).Infof ("Loading environment from resource manager endpoint: %s" , resourceManagerEndpoint )
143
+ env , err = azure .EnvironmentFromURL (resourceManagerEndpoint , nameOverride )
144
+ if err == nil && strings .EqualFold (cloudName , "AzureStackCloud" ) {
145
+ azureStackOverrides (env , cloudFQDN , identitySystem )
146
+ }
147
+ } else if cloudName == "" {
133
148
env = azure .PublicCloud
134
149
} else {
135
150
env , err = azure .EnvironmentFromName (cloudName )
@@ -151,3 +166,22 @@ func decodePkcs12(pkcs []byte, password string) (*x509.Certificate, *rsa.Private
151
166
152
167
return certificate , rsaPrivateKey , nil
153
168
}
169
+
170
+ func azureStackOverrides (env azure.Environment , cloudFQDN , identitySystem string ) azure.Environment {
171
+ // if AzureStack, make sure the generated environment matches what AKSe currently generates
172
+ env .ManagementPortalURL = fmt .Sprintf ("https://portal.%s/" , cloudFQDN )
173
+ // TODO: figure out why AKSe does this
174
+ // why is autorest not setting ServiceManagementEndpoint?
175
+ env .ServiceManagementEndpoint = env .TokenAudience
176
+ // TODO: figure out why AKSe does this
177
+ // ResourceManagerVMDNSSuffix is not referenced in k/k
178
+ split := strings .Split (cloudFQDN , "." )
179
+ domain := strings .Join (split [1 :], "." )
180
+ env .ResourceManagerVMDNSSuffix = fmt .Sprintf ("cloudapp.%s" , domain )
181
+ // NOTE: autorest sets KeyVaultEndpoint while AKSe does not
182
+ if strings .EqualFold (identitySystem , ADFSIdentitySystem ) {
183
+ env .ActiveDirectoryEndpoint = strings .TrimSuffix (env .ActiveDirectoryEndpoint , "/" )
184
+ env .ActiveDirectoryEndpoint = strings .TrimSuffix (env .ActiveDirectoryEndpoint , "adfs" )
185
+ }
186
+ return env
187
+ }
0 commit comments