/
environments.go
155 lines (138 loc) · 5.84 KB
/
environments.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
package azureclient
// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.
import (
"fmt"
"strings"
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/go-autorest/autorest/azure"
utilgraph "github.com/Azure/ARO-RP/pkg/util/graph"
)
// AROEnvironment contains additional, cloud-specific information needed by ARO.
type AROEnvironment struct {
azure.Environment
ActualCloudName string
GenevaMonitoringEndpoint string
AppSuffix string
AppLensEndpoint string
AppLensScope string
AppLensTenantID string
PkiIssuerUrlTemplate string
PkiCaName string
AuthzRemotePDPEndPoint string
AzureRbacPDPEnvironment
Cloud cloud.Configuration
// Microsoft identity platform scopes used by ARO
// See https://learn.microsoft.com/EN-US/azure/active-directory/develop/scopes-oidc#the-default-scope
ResourceManagerScope string
KeyVaultScope string
MicrosoftGraphScope string
}
// AzureRbacPDPEnvironment contains cloud specific instance of Authz RBAC PDP Remote Server
type AzureRbacPDPEnvironment struct {
Endpoint string
OAuthScope string
}
var (
// PublicCloud contains additional ARO information for the public Azure cloud environment.
PublicCloud = AROEnvironment{
Environment: azure.PublicCloud,
ActualCloudName: "AzureCloud",
GenevaMonitoringEndpoint: "https://gcs.prod.monitoring.core.windows.net/",
AppSuffix: "aro.azure.com",
AppLensEndpoint: "https://diag-runtimehost-prod.trafficmanager.net/api/invoke",
AppLensScope: "0d7b6142-46a3-426a-ad6d-eed97c2a48ee",
AppLensTenantID: "33e01921-4d64-4f8c-a055-5bdaffd5e33d",
PkiIssuerUrlTemplate: "https://issuer.pki.azure.com/dsms/issuercertificates?getissuersv3&caName=%s",
PkiCaName: "ame",
Cloud: cloud.AzurePublic,
AzureRbacPDPEnvironment: AzureRbacPDPEnvironment{
Endpoint: "https://%s.authorization.azure.net/providers/Microsoft.Authorization/checkAccess?api-version=2021-06-01-preview",
OAuthScope: "https://authorization.azure.net/.default",
},
ResourceManagerScope: azure.PublicCloud.ResourceManagerEndpoint + "/.default",
KeyVaultScope: azure.PublicCloud.ResourceIdentifiers.KeyVault + "/.default",
MicrosoftGraphScope: azure.PublicCloud.MicrosoftGraphEndpoint + "/.default",
}
// USGovernmentCloud contains additional ARO information for the US Gov cloud environment.
USGovernmentCloud = AROEnvironment{
Environment: azure.USGovernmentCloud,
ActualCloudName: "AzureUSGovernment",
GenevaMonitoringEndpoint: "https://gcs.monitoring.core.usgovcloudapi.net/",
AppSuffix: "aro.azure.us",
AppLensEndpoint: "https://diag-runtimehost-prod-bn1-001.azurewebsites.us/api/invoke",
AppLensScope: "https://microsoft.onmicrosoft.com/runtimehost",
AppLensTenantID: "cab8a31a-1906-4287-a0d8-4eef66b95f6e",
Cloud: cloud.AzureGovernment,
// the .us tls cert is issued by DigiCerts, and no additional certs are needed from pki
PkiIssuerUrlTemplate: "",
PkiCaName: "",
AzureRbacPDPEnvironment: AzureRbacPDPEnvironment{
Endpoint: "https://%s.authorization.azure.us/providers/Microsoft.Authorization/checkAccess?api-version=2021-06-01-preview",
OAuthScope: "https://authorization.azure.us/.default",
},
ResourceManagerScope: azure.USGovernmentCloud.ResourceManagerEndpoint + "/.default",
KeyVaultScope: azure.USGovernmentCloud.ResourceIdentifiers.KeyVault + "/.default",
MicrosoftGraphScope: azure.USGovernmentCloud.MicrosoftGraphEndpoint + "/.default",
}
)
// EnvironmentFromName returns the AROEnvironment corresponding to the common name specified.
func EnvironmentFromName(name string) (AROEnvironment, error) {
switch strings.ToUpper(name) {
case "AZUREPUBLICCLOUD":
return PublicCloud, nil
case "AZUREUSGOVERNMENTCLOUD":
return USGovernmentCloud, nil
}
return AROEnvironment{}, fmt.Errorf("cloud environment %q is unsupported by ARO", name)
}
func (e *AROEnvironment) ClientCertificateCredentialOptions() *azidentity.ClientCertificateCredentialOptions {
return &azidentity.ClientCertificateCredentialOptions{
ClientOptions: azcore.ClientOptions{
Cloud: e.Cloud,
},
// Required for Subject Name/Issuer (SNI) authentication
SendCertificateChain: true,
}
}
func (e *AROEnvironment) ClientSecretCredentialOptions() *azidentity.ClientSecretCredentialOptions {
return &azidentity.ClientSecretCredentialOptions{
ClientOptions: azcore.ClientOptions{
Cloud: e.Cloud,
},
}
}
func (e *AROEnvironment) DefaultAzureCredentialOptions() *azidentity.DefaultAzureCredentialOptions {
return &azidentity.DefaultAzureCredentialOptions{
ClientOptions: azcore.ClientOptions{
Cloud: e.Cloud,
},
}
}
func (e *AROEnvironment) EnvironmentCredentialOptions() *azidentity.EnvironmentCredentialOptions {
return &azidentity.EnvironmentCredentialOptions{
ClientOptions: azcore.ClientOptions{
Cloud: e.Cloud,
},
}
}
func (e *AROEnvironment) ManagedIdentityCredentialOptions() *azidentity.ManagedIdentityCredentialOptions {
return &azidentity.ManagedIdentityCredentialOptions{
ClientOptions: azcore.ClientOptions{
Cloud: e.Cloud,
},
}
}
func (e *AROEnvironment) NewGraphServiceClient(tokenCredential azcore.TokenCredential) (*utilgraph.GraphServiceClient, error) {
scopes := []string{e.MicrosoftGraphScope}
client, err := utilgraph.NewGraphServiceClientWithCredentials(tokenCredential, scopes)
if err != nil {
return nil, err
}
// Watch this issue for a better way to configure the graph endpoint.
// https://github.com/microsoftgraph/msgraph-sdk-go/issues/235
client.GetAdapter().SetBaseUrl(e.MicrosoftGraphEndpoint + "v1.0")
return client, nil
}