Skip to content

Commit

Permalink
clustermsi: log interaction with keyvault
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Kuznetsov <[email protected]>
  • Loading branch information
stevekuznetsov committed Feb 7, 2025
1 parent 78680a8 commit 51c1949
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
24 changes: 23 additions & 1 deletion pkg/cluster/clustermsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/Azure/azure-sdk-for-go/services/keyvault/v7.0/keyvault"
"github.com/Azure/go-autorest/autorest/date"
"github.com/Azure/msi-dataplane/pkg/dataplane"
"github.com/sirupsen/logrus"

"github.com/Azure/ARO-RP/pkg/api"
"github.com/Azure/ARO-RP/pkg/env"
Expand Down Expand Up @@ -120,6 +121,20 @@ func (m *manager) initializeClusterMsiClients(ctx context.Context) error {
return err
}

var censored dataplane.ManagedIdentityCredentials
if err := json.Unmarshal([]byte(*kvSecretResponse.Value), &censored); err != nil {
return err
}
env.CensorManagedIdentityCredentials(&censored)
censoredEncoded, err := json.Marshal(&censored)
if err != nil {
return err
}
m.env.Logger().WithFields(logrus.Fields{
"client": "msi-dataplane",
"body": string(censoredEncoded),
}).Info("fetched msi response from key vault")

cloud, err := m.env.Environment().CloudNameForMsiDataplane()
if err != nil {
return err
Expand All @@ -130,18 +145,25 @@ func (m *manager) initializeClusterMsiClients(ctx context.Context) error {
return err
}

var uamsiIds []string
var azureCred azcore.TokenCredential
for _, identity := range kvSecret.ExplicitIdentities {
if identity != nil && identity.ResourceID != nil {
uamsiIds = append(uamsiIds, *identity.ResourceID)
}
if identity != nil && identity.ResourceID != nil && *identity.ResourceID == msiResourceId.String() {
var err error
azureCred, err = dataplane.GetCredential(cloud, *identity)

Check failure on line 156 in pkg/cluster/clustermsi.go

View workflow job for this annotation

GitHub Actions / golangci-lint

SA4023(related information): the lhs of the comparison gets its value from here and has a concrete type (staticcheck)
if err != nil {
return fmt.Errorf("failed to get credential for msi identity %q: %v", msiResourceId, err)
}
if azureCred == nil {

Check failure on line 160 in pkg/cluster/clustermsi.go

View workflow job for this annotation

GitHub Actions / golangci-lint

SA4023: this comparison is never true (staticcheck)
return fmt.Errorf("credential for msi identity %q returned nil", msiResourceId)
}
}
}
if azureCred == nil {
return fmt.Errorf("managed identity credential missing user-assigned identity %q", msiResourceId)
return fmt.Errorf("managed identity credential had %d explicit identities (%s), but was missing user-assigned identity %q", len(kvSecret.ExplicitIdentities), strings.Join(uamsiIds, ","), msiResourceId)
}

// Note that we are assuming that all of the platform MIs are in the same subscription as the ARO resource.
Expand Down
4 changes: 2 additions & 2 deletions pkg/env/prod.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ func ClientDebugLoggerMiddleware(log *logrus.Entry) policy.Policy {
if err := json.Unmarshal(body, &response); err != nil {
log.WithError(err).Error("error unmarshalling response body")
} else {
censorCredentials(&response)
CensorManagedIdentityCredentials(&response)
censored, err := json.Marshal(response)
if err != nil {
log.WithError(err).Error("error marshalling response body after censoring")
Expand All @@ -469,7 +469,7 @@ func ClientDebugLoggerMiddleware(log *logrus.Entry) policy.Policy {
})
}

func censorCredentials(input *dataplane.ManagedIdentityCredentials) {
func CensorManagedIdentityCredentials(input *dataplane.ManagedIdentityCredentials) {
input.ClientSecret = nil
for i := 0; i < len(input.DelegatedResources); i++ {
if input.DelegatedResources[i] != nil && input.DelegatedResources[i].ImplicitIdentity != nil {
Expand Down

0 comments on commit 51c1949

Please sign in to comment.