Skip to content

Do not send data with DBUS Auth mechanisms#265

Merged
jsouthworth merged 1 commit intogodbus:masterfrom
R2Dtwo:godbus264_auth_external_container
Aug 5, 2021
Merged

Do not send data with DBUS Auth mechanisms#265
jsouthworth merged 1 commit intogodbus:masterfrom
R2Dtwo:godbus264_auth_external_container

Conversation

@R2Dtwo
Copy link
Contributor

@R2Dtwo R2Dtwo commented Aug 5, 2021

When running inside a container using systemd dynamic user to run as an
actual non-root user outside the container (i.e. UID 12345), the DBUS
refuses to allow the godbus code to connect. This is because the godbus
code sends the UID of the user.

The sdbus C library sends "AUTH EXTERNAL\r\n", whereas godbus sends
"AUTH EXTERNAL 30\r\n". Since godbus goes the extra step to tell DBUS
that the current UID is 0 (hex 0x30, getuid() == 0, i,e, root), DBUS
refuses to allow the process to connect because it sees the process is
actually running as UID 12345 (for example) outside of the container.

When the UID is not specified by just sending "AUTH EXTERNAL\r\n", DBUS
sends back a line of "DATA\r\n" and expects a reply of "DATA\r\n". The
godbus code specifically checks for "DATA" when waitingForOk in
tryAuth(), but sends a "CANCEL\r\n" to the DBUS and errors out.

Instead of erroring out, the tryAuth() code in godbus should reply with
"DATA\r\n" when the status is 'waitingForOk' and the line read back from
the DBUS begins with "DATA".

Fixes #264

When running inside a container using systemd dynamic user to run as an
actual non-root user outside the container (i.e. UID 12345), the DBUS
refuses to allow the godbus code to connect. This is because the godbus
code sends the UID of the user.

The sdbus C library sends "AUTH EXTERNAL\r\n", whereas godbus sends
"AUTH EXTERNAL 30\r\n". Since godbus goes the extra step to tell DBUS
that the current UID is 0 (hex 0x30, getuid() == 0, i,e, root), DBUS
refuses to allow the process to connect because it sees the process is
actually running as UID 12345 (for example) outside of the container.

When the UID is not specified by just sending "AUTH EXTERNAL\r\n", DBUS
sends back a line of "DATA\r\n" and expects a reply of "DATA\r\n". The
godbus code specifically checks for "DATA" when waitingForOk in
tryAuth(), but sends a "CANCEL\r\n" to the DBUS and errors out.

Instead of erroring out, the tryAuth() code in godbus should reply with
"DATA\r\n" when the status is 'waitingForOk' and the line read back from
the DBUS begins with "DATA".

Fixes godbus#264
@jsouthworth
Copy link
Member

Looks good, thanks.

@jsouthworth jsouthworth merged commit 31b5df7 into godbus:master Aug 5, 2021
Copy link

@joanbm joanbm left a comment

Choose a reason for hiding this comment

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

See below.

if name, _, status := m.FirstData(); bytes.Equal(v, name) {
var ok bool
err = authWriteLine(conn.transport, []byte("AUTH"), v, data)
err = authWriteLine(conn.transport, []byte("AUTH"), v)
Copy link

Choose a reason for hiding this comment

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

Doesn't this break DBUS_COOKIE_SHA1 / AuthCookieSha1 authentication? data is the authentication payload including the cookie here.

If so perhaps it's better to make the change only affect AuthExternal, as far as I can tell reverting those lines and calling AuthExternal("") instead of AuthExternal(uid) should be enough.

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.

authentication error when connecting from systemd-nspawn container using dynamic users

3 participants