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

Enable filtering entry id's by prefix #325

Merged
merged 9 commits into from
Apr 2, 2024

Conversation

kfox1111
Copy link
Contributor

@kfox1111 kfox1111 commented Mar 13, 2024

This enables peaceful coexistence of multiple spire-controller-managers or other managers and manual entries in the same spire-server. Also provides a cleanup option for migration.

fixes: spiffe/spire#4898

This enables peaceful coexistence of multiple spire-controller-managers
or other managers and manual entries in the same spire-server. Also
provides a cleanup option for migration.

Signed-off-by: Kevin Fox <[email protected]>
Signed-off-by: Kevin Fox <[email protected]>
cmd/main.go Outdated Show resolved Hide resolved
cmd/main.go Outdated
if retval.ctrlConfig.EntryIDPrefix != "" && retval.ctrlConfig.EntryIDPrefix[len(retval.ctrlConfig.EntryIDPrefix)-1] != "."[0] {
retval.ctrlConfig.EntryIDPrefix += "."
}
if retval.ctrlConfig.EntryIDPrefixCleanup != nil && *retval.ctrlConfig.EntryIDPrefixCleanup != "" && (*retval.ctrlConfig.EntryIDPrefixCleanup)[len(*retval.ctrlConfig.EntryIDPrefixCleanup)-1] != "."[0] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty unwieldy. I'd add a addDotSuffix function or something that took in a string and appended a . if-and-only-if the string is non-empty and doesn't already have the suffix. Then this could be simplified to:

Suggested change
if retval.ctrlConfig.EntryIDPrefixCleanup != nil && *retval.ctrlConfig.EntryIDPrefixCleanup != "" && (*retval.ctrlConfig.EntryIDPrefixCleanup)[len(*retval.ctrlConfig.EntryIDPrefixCleanup)-1] != "."[0] {
if retval.ctrlConfig.EntryIDPrefixCleanup != nil {
*retval.ctrlConfig.EntryIDPrefixCleanup = addDotSuffix(*retval.ctrlConfig.EntryIDPrefixCleanup)
}

It could also be used unconditional above with EntryIDPrefix.

cmd/main.go Outdated
@@ -179,6 +179,21 @@ func parseConfig() (Config, error) {
retval.reconcile = *retval.ctrlConfig.Reconcile
}

if retval.ctrlConfig.EntryIDPrefix != "" && retval.ctrlConfig.EntryIDPrefixCleanup != nil && retval.ctrlConfig.EntryIDPrefix == *retval.ctrlConfig.EntryIDPrefixCleanup {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you want to do this equality comparison after you've normalized these values with the dot suffix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normalized and moved to reduce comparisons

}

printCleanup := "<unset>"
if retval.ctrlConfig.EntryIDPrefixCleanup != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would all be a little easier to read if there was if block that handled all of the code related to EntryIDPrefixCleanup being non-nil. Right now it's spread across four blocks and it's a little hard to track.

pkg/spireentry/reconciler.go Outdated Show resolved Hide resolved
Comment on lines 271 to 274
if strings.Contains(entry.ID, "/") {
return false, false
}
return false, true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dot is the separator between prefix, correct? Also this can be simplified.

Suggested change
if strings.Contains(entry.ID, "/") {
return false, false
}
return false, true
return false, strings.Contains(entry.ID, ".") {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Close... it needs to be negated though... Will rework it that way though to be this pattern.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, thanks for catching that.

pkg/spireentry/reconciler.go Outdated Show resolved Hide resolved
api/v1alpha1/controllermanagerconfig_types.go Outdated Show resolved Hide resolved
Copy link
Member

@azdagron azdagron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! thanks, @kfox1111 !

@azdagron azdagron merged commit 88c20a5 into spiffe:main Apr 2, 2024
6 checks passed
@kfox1111 kfox1111 deleted the endpoint-id-prefix branch April 3, 2024 01:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider adding metadata to the entry that allows a registrar to self-identify
2 participants