Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use global credentials in low-level methods #1309

Merged
merged 26 commits into from
Nov 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
38ee403
Extract credentials fields into config.Credentials struct
babbageclunk Nov 3, 2020
7d586ba
Remove GlobalCredentials usage from pkg/resourcemanager/iam
babbageclunk Nov 4, 2020
be3fa93
Redefine config.Credentials as an interface for testing
babbageclunk Nov 4, 2020
b1a1c38
Remove GlobalCredentials usage from pkg/secrets/keyvault
babbageclunk Nov 4, 2020
3368137
Remove GlobalCredentials usage from pkg/resourcemanager/apim/*
babbageclunk Nov 4, 2020
7832c23
Remove GlobalCredentials usage from pkg/resourcemanager/appinsights
babbageclunk Nov 5, 2020
f808045
Remove GlobalCredentials usage from pkg/resourcemanager/azuresql/*
babbageclunk Nov 5, 2020
160b2cf
Remove GlobalCredentials usage from pkg/resourcemanager/cosmosdbs
babbageclunk Nov 5, 2020
80e6454
Remove GlobalCredentials usage from pkg/resourcemanager/eventhubs
babbageclunk Nov 8, 2020
fbeba71
Remove GlobalCredentials usage from pkg/resourcemanager/keyvaults
babbageclunk Nov 8, 2020
09eb668
Remove GlobalCredentials usage from pkg/resourcemanager/loadbalancer
babbageclunk Nov 8, 2020
404d3ce
Remove GlobalCredentials usage from pkg/resourcemanager/mysql/*
babbageclunk Nov 9, 2020
b9cb411
Remove GlobalCredentials usage from pkg/resourcemanager/nic
babbageclunk Nov 9, 2020
f581cd6
Remove GlobalCredentials usage from pkg/resourcemanager/pip
babbageclunk Nov 9, 2020
211a71d
Remove GlobalCredentials usage from pkg/resourcemanager/pollclient
babbageclunk Nov 9, 2020
3a6ff2e
Remove GlobalCredentials usage from pkg/resourcemanager/psql/*
babbageclunk Nov 9, 2020
5520078
Remove GlobalCredentials usage from pkg/resourcemanager/rediscaches
babbageclunk Nov 9, 2020
10d504c
Remove GlobalCredentials usage from pkg/resourcemanager/resourcegroups
babbageclunk Nov 9, 2020
294adc0
Remove GlobalCredentials usage from pkg/resourcemanager/storages/*
babbageclunk Nov 10, 2020
7797b89
Remove GlobalCredentials usage from pkg/resourcemanager/vm
babbageclunk Nov 10, 2020
a457486
Remove GlobalCredentials usage from pkg/resourcemanager/vmext
babbageclunk Nov 10, 2020
c66e30d
Remove GlobalCredentials usage from pkg/resourcemanager/vmss
babbageclunk Nov 10, 2020
750f3e8
Remove GlobalCredentials usage from pkg/resourcemanager/vnet
babbageclunk Nov 10, 2020
c194594
Merge branch 'master' into creds-refactor
babbageclunk Nov 13, 2020
59a2b45
Rename useMI to useManagedIdentity
babbageclunk Nov 13, 2020
9d24965
Incorporate code review comments
babbageclunk Nov 13, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion controllers/async_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/Azure/azure-service-operator/pkg/resourcemanager"
"github.com/Azure/azure-service-operator/pkg/resourcemanager/config"
"github.com/Azure/azure-service-operator/pkg/secrets"
keyvaultsecretlib "github.com/Azure/azure-service-operator/pkg/secrets/keyvault"
telemetry "github.com/Azure/azure-service-operator/pkg/telemetry"
Expand Down Expand Up @@ -75,7 +76,7 @@ func (r *AsyncReconciler) Reconcile(req ctrl.Request, obj runtime.Object) (resul

if len(KeyVaultName) != 0 {
// Instantiate the KeyVault Secret Client
keyvaultSecretClient = keyvaultsecretlib.New(KeyVaultName)
keyvaultSecretClient = keyvaultsecretlib.New(KeyVaultName, config.GlobalCredentials())

r.Telemetry.LogInfoByInstance("status", "ensuring vault", req.String())

Expand Down
9 changes: 5 additions & 4 deletions controllers/azuresql_combined_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/stretchr/testify/assert"

helpers "github.com/Azure/azure-service-operator/pkg/helpers"
"github.com/Azure/azure-service-operator/pkg/resourcemanager/config"
kvsecrets "github.com/Azure/azure-service-operator/pkg/secrets/keyvault"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -300,7 +301,7 @@ func TestAzureSqlServerCombinedHappyPath(t *testing.T) {
EnsureInstance(ctx, t, tc, kvSqlUser1)

// Check that the user's secret is in the keyvault
keyVaultSecretClient := kvsecrets.New(keyVaultName)
keyVaultSecretClient := kvsecrets.New(keyVaultName, config.GlobalCredentials())

assert.Eventually(func() bool {
keyNamespace := "azuresqluser-" + sqlServerName + "-" + sqlDatabaseName1
Expand Down Expand Up @@ -342,7 +343,7 @@ func TestAzureSqlServerCombinedHappyPath(t *testing.T) {
EnsureInstance(ctx, t, tc, kvSqlUser2)

// Check that the user's secret is in the keyvault
keyVaultSecretClient := kvsecrets.New(keyVaultName)
keyVaultSecretClient := kvsecrets.New(keyVaultName, config.GlobalCredentials())

assert.Eventually(func() bool {
keyNamespace := "azuresqluser-" + sqlServerName + "-" + sqlDatabaseName1
Expand All @@ -362,7 +363,7 @@ func TestAzureSqlServerCombinedHappyPath(t *testing.T) {
key := types.NamespacedName{Name: kvSqlUser1.ObjectMeta.Name, Namespace: keyNamespace}

keyVaultName := tc.keyvaultName
keyVaultSecretClient := kvsecrets.New(keyVaultName)
keyVaultSecretClient := kvsecrets.New(keyVaultName, config.GlobalCredentials())
var oldSecret, _ = keyVaultSecretClient.Get(ctx, key)

sqlActionName := GenerateTestResourceNameWithRandom("azuresqlaction-dev", 10)
Expand Down Expand Up @@ -409,7 +410,7 @@ func TestAzureSqlServerCombinedHappyPath(t *testing.T) {
EnsureDelete(ctx, t, tc, kvSqlUser2)

// Check that the user's secret is in the keyvault
keyVaultSecretClient := kvsecrets.New(tc.keyvaultName)
keyVaultSecretClient := kvsecrets.New(tc.keyvaultName, config.GlobalCredentials())

assert.Eventually(func() bool {
key := types.NamespacedName{Name: sqlUser.ObjectMeta.Name, Namespace: sqlUser.ObjectMeta.Namespace}
Expand Down
6 changes: 4 additions & 2 deletions controllers/eventhub_storageaccount_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/Azure/azure-service-operator/pkg/errhelp"

"github.com/Azure/azure-service-operator/pkg/resourcemanager/config"
kvhelper "github.com/Azure/azure-service-operator/pkg/resourcemanager/keyvaults"
kvsecrets "github.com/Azure/azure-service-operator/pkg/secrets/keyvault"

Expand Down Expand Up @@ -127,7 +128,8 @@ func TestEventHubControllerCreateAndDeleteCustomKeyVault(t *testing.T) {
keyVaultNameForSecrets := tc.keyvaultName

// Instantiate a KV client for the Keyvault that was created during test suite setup
_, err := kvhelper.AzureKeyVaultManager.GetVault(ctx, rgName, keyVaultNameForSecrets)
kvManager := kvhelper.NewAzureKeyVaultManager(config.GlobalCredentials(), nil)
_, err := kvManager.GetVault(ctx, rgName, keyVaultNameForSecrets)
assert.Equal(nil, err, "wait for keyvault to be available")

// Create EventhubNamespace instance as prereq
Expand Down Expand Up @@ -170,7 +172,7 @@ func TestEventHubControllerCreateAndDeleteCustomKeyVault(t *testing.T) {
EnsureInstance(ctx, t, tc, eventhubInstance)

// Check that the secret is added to KeyVault
keyvaultSecretClient := kvsecrets.New(keyVaultNameForSecrets)
keyvaultSecretClient := kvsecrets.New(keyVaultNameForSecrets, config.GlobalCredentials())

EnsureSecrets(ctx, t, tc, eventhubInstance, keyvaultSecretClient, eventhubName, eventhubInstance.Namespace)

Expand Down
2 changes: 1 addition & 1 deletion controllers/eventhubnamespace_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestEventHubNamespaceControllerNetworkRules(t *testing.T) {
EnsureInstance(ctx, t, tc, VNetInstance)

// Create EventhubNamespace network rule using the above VNET
subnetID := "/subscriptions/" + config.SubscriptionID() + "/resourceGroups/" + rgName + "/providers/Microsoft.Network/virtualNetworks/" + VNetName + "/subnets/" + subnetName
subnetID := "/subscriptions/" + config.GlobalCredentials().SubscriptionID() + "/resourceGroups/" + rgName + "/providers/Microsoft.Network/virtualNetworks/" + VNetName + "/subnets/" + subnetName
vnetRules := []azurev1alpha1.VirtualNetworkRules{
{
SubnetID: subnetID,
Expand Down
18 changes: 9 additions & 9 deletions controllers/keyvault_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ func TestKeyvaultControllerWithAccessPolicies(t *testing.T) {
keyVaultLocation := tc.resourceGroupLocation
accessPolicies := []azurev1alpha1.AccessPolicyEntry{
{
TenantID: config.TenantID(),
ClientID: config.ClientID(),
TenantID: config.GlobalCredentials().TenantID(),
ClientID: config.GlobalCredentials().ClientID(),

Permissions: &azurev1alpha1.Permissions{
Keys: &[]string{
Expand Down Expand Up @@ -122,7 +122,7 @@ func TestKeyvaultControllerWithAccessPolicies(t *testing.T) {

//Add code to set secret and get secret from this keyvault using secretclient

keyvaultSecretClient := kvsecrets.New(keyVaultName)
keyvaultSecretClient := kvsecrets.New(keyVaultName, config.GlobalCredentials())
secretName := "test-key"
key := types.NamespacedName{Name: secretName, Namespace: "default"}
datanew := map[string][]byte{
Expand Down Expand Up @@ -163,8 +163,8 @@ func TestKeyvaultControllerWithLimitedAccessPoliciesAndUpdate(t *testing.T) {
ResourceGroup: tc.resourceGroupName,
AccessPolicies: &[]azurev1alpha1.AccessPolicyEntry{
{
TenantID: config.TenantID(),
ClientID: config.ClientID(),
TenantID: config.GlobalCredentials().TenantID(),
ClientID: config.GlobalCredentials().ClientID(),
Permissions: &azurev1alpha1.Permissions{
Secrets: &[]string{"backup"},
},
Expand All @@ -182,7 +182,7 @@ func TestKeyvaultControllerWithLimitedAccessPoliciesAndUpdate(t *testing.T) {
}, tc.timeout, tc.retry, "wait for keyVaultInstance to be ready in azure")
//Add code to set secret and get secret from this keyvault using secretclient

keyvaultSecretClient := kvsecrets.New(keyVaultName)
keyvaultSecretClient := kvsecrets.New(keyVaultName, config.GlobalCredentials())
key := types.NamespacedName{Name: "test-key", Namespace: "default"}
datanew := map[string][]byte{
"test1": []byte("test2"),
Expand Down Expand Up @@ -296,8 +296,8 @@ func TestKeyvaultControllerWithVirtualNetworkRulesAndUpdate(t *testing.T) {
keyVaultLocation := tc.resourceGroupLocation
accessPolicies := []azurev1alpha1.AccessPolicyEntry{
{
TenantID: config.TenantID(),
ClientID: config.ClientID(),
TenantID: config.GlobalCredentials().TenantID(),
ClientID: config.GlobalCredentials().ClientID(),

Permissions: &azurev1alpha1.Permissions{
Secrets: &[]string{
Expand Down Expand Up @@ -329,7 +329,7 @@ func TestKeyvaultControllerWithVirtualNetworkRulesAndUpdate(t *testing.T) {
return result.Response.StatusCode == http.StatusOK
}, tc.timeout, tc.retry, "wait for keyVaultInstance to be ready in azure")

keyvaultSecretClient := kvsecrets.New(keyVaultName)
keyvaultSecretClient := kvsecrets.New(keyVaultName, config.GlobalCredentials())
secretName := "test-key"
key := types.NamespacedName{Name: secretName, Namespace: "default"}
datanew := map[string][]byte{
Expand Down
6 changes: 3 additions & 3 deletions controllers/keyvaultkey_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func TestKeyvaultKeyControllerHappyPath(t *testing.T) {
keyPermissions := []string{"get", "list", "update", "delete", "recover", "backup", "restore", "create", "import"}
accessPolicies := []azurev1alpha1.AccessPolicyEntry{
{
TenantID: config.TenantID(),
ClientID: config.ClientID(),
TenantID: config.GlobalCredentials().TenantID(),
ClientID: config.GlobalCredentials().ClientID(),
Permissions: &azurev1alpha1.Permissions{
Keys: &keyPermissions,
},
Expand Down Expand Up @@ -86,7 +86,7 @@ func TestKeyvaultKeyControllerHappyPath(t *testing.T) {
// create key
EnsureInstance(ctx, t, tc, keyVaultKey)

kvopsclient := resourcemanagerkeyvaults.NewOpsClient(keyVaultName)
kvopsclient := resourcemanagerkeyvaults.NewOpsClient(config.GlobalCredentials(), keyVaultName)

assert.Eventually(func() bool {
kvault, err := tc.keyVaultManager.GetVault(ctx, tc.resourceGroupName, keyVaultInstance.Name)
Expand Down
Loading