Skip to content

Commit

Permalink
ldap-import: Add additional logs
Browse files Browse the repository at this point in the history
These logs are being added to provide better debugging of LDAP
normalization on IAM import.
  • Loading branch information
donatello committed May 7, 2024
1 parent b9bdc17 commit 4878f20
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions cmd/iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -1672,6 +1672,11 @@ func (sys *IAMSys) NormalizeLDAPMappingImport(ctx context.Context, isGroup bool,
normKey, origKeys)
}

if len(origKeys[1:]) > 0 {
// Log that extra DN mappings will not be imported.
iamLogIf(ctx, fmt.Errorf("(import-info) extraneous DN mappings found for LDAP DN[%s]: %v will not be imported", origKeys[0], origKeys[1:]))
}

// Policies mapped to the DN's are the same, so we remove the extra
// ones from the map.
for i := 1; i < len(origKeys); i++ {
Expand All @@ -1680,7 +1685,11 @@ func (sys *IAMSys) NormalizeLDAPMappingImport(ctx context.Context, isGroup bool,
// Remove the mapping from storage by setting the policy to "".
if entityKeysInStorage.Contains(origKeys[i]) {
// Ignore any deletion error.
_, _ = sys.PolicyDBSet(ctx, origKeys[i], "", stsUser, isGroup)
_, delErr := sys.PolicyDBSet(ctx, origKeys[i], "", stsUser, isGroup)
if delErr != nil {
logErr := fmt.Errorf("(import-info) failed to delete extraneous LDAP DN mapping for `%s`: %w", origKeys[i], delErr)
iamLogIf(ctx, logErr)
}
}
}
}
Expand All @@ -1691,10 +1700,16 @@ func (sys *IAMSys) NormalizeLDAPMappingImport(ctx context.Context, isGroup bool,
mappingValue := policyMap[origKeys[0]]
delete(policyMap, origKeys[0])
policyMap[normKey] = mappingValue
iamLogIf(ctx, fmt.Errorf("(import-info) normalized LDAP DN mapping from `%s` to `%s`", origKeys[0], normKey))

// Remove the mapping from storage by setting the policy to "".
if entityKeysInStorage.Contains(origKeys[0]) {
// Ignore any deletion error.
_, _ = sys.PolicyDBSet(ctx, origKeys[0], "", stsUser, isGroup)
_, delErr := sys.PolicyDBSet(ctx, origKeys[0], "", stsUser, isGroup)
if delErr != nil {
logErr := fmt.Errorf("(import-info) failed to delete extraneous LDAP DN mapping for `%s`: %w", origKeys[0], delErr)
iamLogIf(ctx, logErr)
}
}
}
return nil
Expand Down

0 comments on commit 4878f20

Please sign in to comment.