@@ -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.
65
+ // IdentitySystem indicates the identity provider. Relevant only to hybrid clouds (Azure Stack).
66
+ // Allowed values are 'azure_ad' (default), 'adfs'.
63
67
IdentitySystem string `json:"identitySystem,omitempty" yaml:"identitySystem,omitempty"`
68
+ // ResourceManagerEndpoint is the cloud's resource manager endpoint. If set, cloud provider queries this endpoint
69
+ // in order to generate an autorest.Environment instance instead of using one of the pre-defined Environments.
70
+ ResourceManagerEndpoint string `json:"resourceManagerEndpoint,omitempty" yaml:"resourceManagerEndpoint,omitempty"`
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
}
@@ -125,13 +132,24 @@ func GetServicePrincipalToken(config *AzureAuthConfig, env *azure.Environment) (
125
132
return nil , ErrorNoAuth
126
133
}
127
134
128
- // ParseAzureEnvironment returns azure environment by name
129
- func ParseAzureEnvironment (cloudName string ) (* azure.Environment , error ) {
135
+ // ParseAzureEnvironment returns the azure environment.
136
+ // If 'resourceManagerEndpoint' is set, the environment is computed by quering the cloud's resource manager endpoint.
137
+ // Otherwise, a pre-defined Environment is looked up by name.
138
+ func ParseAzureEnvironment (cloudName , resourceManagerEndpoint , identitySystem string ) (* azure.Environment , error ) {
130
139
var env azure.Environment
131
140
var err error
132
- if cloudName == "" {
141
+ if resourceManagerEndpoint != "" {
142
+ klog .V (4 ).Infof ("Loading environment from resource manager endpoint: %s" , resourceManagerEndpoint )
143
+ nameOverride := azure.OverrideProperty {Key : azure .EnvironmentName , Value : cloudName }
144
+ env , err = azure .EnvironmentFromURL (resourceManagerEndpoint , nameOverride )
145
+ if err == nil {
146
+ azureStackOverrides (& env , resourceManagerEndpoint , identitySystem )
147
+ }
148
+ } else if cloudName == "" {
149
+ klog .V (4 ).Info ("Using public cloud environment" )
133
150
env = azure .PublicCloud
134
151
} else {
152
+ klog .V (4 ).Infof ("Using %s environment" , cloudName )
135
153
env , err = azure .EnvironmentFromName (cloudName )
136
154
}
137
155
return & env , err
@@ -151,3 +169,15 @@ func decodePkcs12(pkcs []byte, password string) (*x509.Certificate, *rsa.Private
151
169
152
170
return certificate , rsaPrivateKey , nil
153
171
}
172
+
173
+ // azureStackOverrides ensures that the Environment matches what AKSe currently generates for Azure Stack
174
+ func azureStackOverrides (env * azure.Environment , resourceManagerEndpoint , identitySystem string ) {
175
+ env .ManagementPortalURL = strings .Replace (resourceManagerEndpoint , "https://management." , "https://portal." , - 1 )
176
+ env .ServiceManagementEndpoint = env .TokenAudience
177
+ env .ResourceManagerVMDNSSuffix = strings .Replace (resourceManagerEndpoint , "https://management." , "cloudapp." , - 1 )
178
+ env .ResourceManagerVMDNSSuffix = strings .TrimSuffix (env .ResourceManagerVMDNSSuffix , "/" )
179
+ if strings .EqualFold (identitySystem , ADFSIdentitySystem ) {
180
+ env .ActiveDirectoryEndpoint = strings .TrimSuffix (env .ActiveDirectoryEndpoint , "/" )
181
+ env .ActiveDirectoryEndpoint = strings .TrimSuffix (env .ActiveDirectoryEndpoint , "adfs" )
182
+ }
183
+ }
0 commit comments