Support API versioning in broker API and authd#1446
Conversation
|
@denisonbarbosa do you want take over from here? |
I'll take a look at the current status and we can talk more about this (maybe in a HO?) |
sounds good |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1446 +/- ##
==========================================
- Coverage 87.03% 86.11% -0.93%
==========================================
Files 93 113 +20
Lines 6379 7489 +1110
Branches 111 111
==========================================
+ Hits 5552 6449 +897
- Misses 771 984 +213
Partials 56 56 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR introduces D-Bus API versioning support for brokers by adding a versioned interface (com.ubuntu.authd.Broker2) and updating both the daemon-side broker client and the OIDC broker D-Bus service to negotiate/use the appropriate interface version.
Changes:
- Add daemon-side broker interface discovery via D-Bus introspection and select the “latest” available broker interface when calling methods.
- Export multiple D-Bus interfaces (
BrokerandBroker2) from the OIDC broker service, and thread an API version into the broker implementation to gate behavior changes. - Update/adjust tests and golden outputs to reflect new behavior (e.g., brokers not available on D-Bus are ignored).
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/brokers/dbusbroker.go | Introspects broker object to detect supported interfaces and uses latest interface for calls. |
| internal/brokers/dbusbroker_test.go | Adds unit tests for interface detection/sorting and latest-interface selection. |
| internal/brokers/manager_test.go | Updates manager tests and sets up D-Bus broker mocks in TestMain. |
| internal/brokers/testdata/golden/TestNewManager/Ignores_brokers_not_available_on_dbus | New golden output for ignoring non-exported brokers. |
| internal/brokers/testdata/golden/TestNewManager/Creates_manager_even_if_broker_is_not_exported_on_dbus | Removes/updates prior golden output for behavior that changed. |
| authd-oidc-brokers/internal/dbusservice/dbusservice.go | Exports multiple broker interfaces and constructs per-interface broker instances. |
| authd-oidc-brokers/internal/dbusservice/methods.go | Moves exported D-Bus methods onto the per-interface exported object. |
| authd-oidc-brokers/internal/dbusservice/localbus.go | Adjusts local-bus implementation for the dbusservice package (with build tag). |
| authd-oidc-brokers/internal/broker/broker.go | Adds API version field and gates new response value behind version >= 2. |
| authd-oidc-brokers/internal/broker/helper_test.go | Updates test helper to pass latest API version into broker constructor. |
| authd-oidc-brokers/internal/broker/broker_test.go | Updates broker tests to pass latest API version into broker constructor. |
| authd-oidc-brokers/cmd/authd-oidc/daemon/daemon.go | Updates daemon to let dbusservice construct versioned broker instances from config. |
Comments suppressed due to low confidence (1)
authd-oidc-brokers/internal/dbusservice/localbus.go:31
- localbus.go now defines getBus on *Interface, but getBus is called on *Service (and the disconnect field also lives on Service). This won’t compile under the withlocalbus build tag, and the file also references context/log without importing them. The receiver should remain *Service (matching systembus.go), and the disconnect cleanup should be set on Service.
// getBus creates the local bus and returns a connection to the bus.
// It attaches a disconnect handler to stop the local bus subprocess.
func (s *Interface) getBus() (*dbus.Conn, error) {
cleanup, err := testutils.StartSystemBusMock()
if err != nil {
return nil, err
}
log.Infof(context.Background(), "Using local bus address: %s", os.Getenv("DBUS_SYSTEM_BUS_ADDRESS"))
conn, err := dbus.ConnectSystemBus()
if err != nil {
return nil, err
}
s.disconnect = func() {
conn.Close()
cleanup()
}
return conn, err
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
authd-oidc-brokers/internal/dbusservice/localbus.go:31
localbus.go(build tagwithlocalbus) no longer compiles:getBusis now a method on*Interface, but it assignss.disconnect(field exists onService, notInterface) anddbusservice.New()callsservice.getBus()(receiver mismatch). This file also usescontext.Background()andlog.Infofwithout importingcontext/log.getBusshould likely remain a*Servicemethod (matchingsystembus.go) and setservice.disconnect.
// getBus creates the local bus and returns a connection to the bus.
// It attaches a disconnect handler to stop the local bus subprocess.
func (s *Interface) getBus() (*dbus.Conn, error) {
cleanup, err := testutils.StartSystemBusMock()
if err != nil {
return nil, err
}
log.Infof(context.Background(), "Using local bus address: %s", os.Getenv("DBUS_SYSTEM_BUS_ADDRESS"))
conn, err := dbus.ConnectSystemBus()
if err != nil {
return nil, err
}
s.disconnect = func() {
conn.Close()
cleanup()
}
return conn, err
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
5f04457 to
e4872c6
Compare
e4872c6 to
beab51a
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
beab51a to
c393a64
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| slices.SortFunc(supportedInterfaces, func(a, b string) int { | ||
| versionA, err := strconv.Atoi(strings.TrimPrefix(a, DbusBaseInterface)) | ||
| if err != nil { | ||
| // If the interface doesn't match the expected format, we consider it as less than any valid versioned interface. | ||
| return -1 | ||
| } | ||
| versionB, err := strconv.Atoi(strings.TrimPrefix(b, DbusBaseInterface)) | ||
| if err != nil { | ||
| // If the interface doesn't match the expected format, we consider it as less than any valid versioned interface. | ||
| return 1 | ||
| } | ||
| if versionA < versionB { | ||
| return -1 | ||
| } else if versionA > versionB { | ||
| return 1 | ||
| } | ||
| return 0 | ||
| }) |
There was a problem hiding this comment.
The slices.SortFunc comparator violates strict weak ordering for interfaces that parse as non-numeric suffixes (including the unversioned base interface). For example, comparing base-vs-base returns -1 instead of 0, which can lead to undefined/unstable sorting and potentially selecting the wrong “latest” interface. Consider normalizing interface names to a numeric version first (treat com.ubuntu.authd.Broker as version 1) and ensure the comparator returns 0 when versions are equal/unknown in the same way for both sides.
There was a problem hiding this comment.
seems valid to me. what do you think, @denisonbarbosa?
There was a problem hiding this comment.
I'd like to see how copilot fixes it. @copilot, please push a fix.
There was a problem hiding this comment.
The last commit copilot pushed fixes it and it LGTM.
There was a problem hiding this comment.
Either the diff looks weird to me, or Copilot only reverted the change you did to the slice declaration and didn't touch the SortFunc at all?
There was a problem hiding this comment.
Nvm, I was looking at the wrong commit 😅
Adds a com.ubuntu.authd.Broker2 D-Bus interface in accordance with https://dbus.freedesktop.org/doc/dbus-api-design.html#api-versioning Also authd now properly considers the possibility of multiple interfaces and, for now, choose the latest one available.
c393a64 to
1130087
Compare
Agent-Logs-Url: https://github.com/canonical/authd/sessions/9ae9064a-3eaf-4982-a7bf-d0d1b95133a6 Co-authored-by: adombeck <18482300+adombeck@users.noreply.github.com>
|
LGTM now |
Agent-Logs-Url: https://github.com/canonical/authd/sessions/2156af1c-51fa-4e85-8e59-050702012524 Co-authored-by: adombeck <18482300+adombeck@users.noreply.github.com>
Adds a
com.ubuntu.authd.Broker2D-Bus interface in accordance with https://dbus.freedesktop.org/doc/dbus-api-design.html#api-versioningUDENG-9793