Skip to content

Commit

Permalink
PAM: Build GDM support only on the library
Browse files Browse the repository at this point in the history
We don't really use all the gdm-related code in the PAM Exec child that
we use in normal PAM transactions, so no need to compile it at all by
default while we need it in the PAM library that GDM will consume.
  • Loading branch information
3v1n0 committed Oct 2, 2024
1 parent 6fd5788 commit 521bae5
Show file tree
Hide file tree
Showing 29 changed files with 106 additions and 46 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/qa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ jobs:
# Overriding the default coverage directory is not an exported flag of go test (yet), so
# we need to override it using the test.gocoverdir flag instead.
#TODO: Update when https://go-review.googlesource.com/c/go/+/456595 is merged.
go test -timeout ${GO_TESTS_TIMEOUT} -cover -covermode=set ./... -coverpkg=./... -shuffle=on -args -test.gocoverdir="${raw_cov_dir}"
go test -tags withgdmmodel -timeout ${GO_TESTS_TIMEOUT} -cover -covermode=set ./... -coverpkg=./... -shuffle=on -args -test.gocoverdir="${raw_cov_dir}"
# Convert the raw coverage data into textfmt so we can merge the Rust one into it
go tool covdata textfmt -i="${raw_cov_dir}" -o="${cov_dir}/coverage.out"
Expand All @@ -220,7 +220,7 @@ jobs:
env:
GO_TESTS_TIMEOUT: 35m
run: |
go test -timeout ${GO_TESTS_TIMEOUT} -race ./...
go test -tags withgdmmodel -timeout ${GO_TESTS_TIMEOUT} -race ./...
- name: Run PAM tests (with Address Sanitizer)
if: matrix.test == 'asan'
Expand All @@ -233,14 +233,14 @@ jobs:
# Use these flags to give ASAN a better time to unwind the stack trace
GO_GC_FLAGS: -N -l
run: |
go test -C ./pam/internal -asan -gcflags=all="${GO_GC_FLAGS}" -timeout ${GO_TESTS_TIMEOUT} ./... || exit_code=$?
go test -C ./pam/internal -tags withgdmmodel -asan -gcflags=all="${GO_GC_FLAGS}" -timeout ${GO_TESTS_TIMEOUT} ./... || exit_code=$?
if [ "${exit_code}" -ne 0 ]; then
cat "${AUTHD_TEST_ARTIFACTS_PATH}"/asan.log* || true
exit ${exit_code}
fi
pushd ./pam/integration-tests
go test -asan -gcflags=all="${GO_GC_FLAGS}" -c
go test -tags withgdmmodel -asan -gcflags=all="${GO_GC_FLAGS}" -c
# FIXME: Suppression may be removed with newer libpam, as the one we ship in ubuntu as some leaks
env LSAN_OPTIONS=suppressions=$(pwd)/lsan.supp \
./integration-tests.test \
Expand Down
2 changes: 1 addition & 1 deletion pam/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

//go:generate go generate -C internal/proto

//go:generate ./generate.sh -tags "!pam_binary_cli && !pam_debug"
//go:generate ./generate.sh -tags "!pam_binary_cli && !pam_debug" -build-tags withgdmmodel

package main
2 changes: 1 addition & 1 deletion pam/generate_debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

//go:generate go generate -C internal/proto

//go:generate env CFLAGS=-g3 CGO_CFLAGS=-g3 ./generate.sh -tags "!pam_binary_cli && pam_debug" -build-tags pam_gdm_debug -output pam_module_debug.go
//go:generate env CFLAGS=-g3 CGO_CFLAGS=-g3 ./generate.sh -tags "!pam_binary_cli && pam_debug" -build-tags "pam_gdm_debug,withgdmmodel" -output pam_module_debug.go

package main
2 changes: 2 additions & 0 deletions pam/integration-tests/gdm-module-handler_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build withgdmmodel

package main_test

import (
Expand Down
28 changes: 27 additions & 1 deletion pam/integration-tests/gdm_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build withgdmmodel

package main_test

import (
Expand All @@ -14,12 +16,15 @@ import (
"github.com/stretchr/testify/require"
"github.com/ubuntu/authd"
"github.com/ubuntu/authd/internal/brokers"
"github.com/ubuntu/authd/internal/services/errmessages"
"github.com/ubuntu/authd/internal/testutils"
localgroupstestutils "github.com/ubuntu/authd/internal/users/localgroups/testutils"
"github.com/ubuntu/authd/pam/internal/gdm"
"github.com/ubuntu/authd/pam/internal/gdm_test"
"github.com/ubuntu/authd/pam/internal/pam_test"
"github.com/ubuntu/authd/pam/internal/proto"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)

func enableGdmExtension() {
Expand Down Expand Up @@ -888,7 +893,7 @@ func buildPAMModule(t *testing.T) string {
libPath := filepath.Join(t.TempDir(), "libpam_authd.so")
t.Logf("Compiling PAM library at %s", libPath)

cmd.Args = append(cmd.Args, "-tags=pam_debug,pam_gdm_debug", "-o", libPath)
cmd.Args = append(cmd.Args, "-tags=withgdmmodel,pam_debug,pam_gdm_debug", "-o", libPath)
out, err := cmd.CombinedOutput()
require.NoError(t, err, "Setup: could not compile PAM module: %s", out)
if string(out) != "" {
Expand Down Expand Up @@ -924,3 +929,24 @@ func testQrcodeUILayoutData(reqN int) *authd.UILayout {
Entry: base.Entry,
}
}

func requirePreviousBrokerForUser(t *testing.T, socketPath string, brokerName string, user string) {
t.Helper()

conn, err := grpc.NewClient("unix://"+socketPath, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithUnaryInterceptor(errmessages.FormatErrorMessage))
require.NoError(t, err, "Can't connect to authd socket")

t.Cleanup(func() { conn.Close() })
pamClient := authd.NewPAMClient(conn)
brokers, err := pamClient.AvailableBrokers(context.TODO(), nil)
require.NoError(t, err, "Can't get available brokers")
prevBroker, err := pamClient.GetPreviousBroker(context.TODO(), &authd.GPBRequest{Username: user})
require.NoError(t, err, "Can't get previous broker")
var prevBrokerID string
for _, b := range brokers.BrokersInfos {
if b.Name == brokerName {
prevBrokerID = b.Id
}
}
require.Equal(t, prevBroker.PreviousBroker, prevBrokerID)
}
26 changes: 0 additions & 26 deletions pam/integration-tests/helpers_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main_test

import (
"context"
"errors"
"io/fs"
"math"
Expand All @@ -11,11 +10,7 @@ import (
"time"

"github.com/stretchr/testify/require"
"github.com/ubuntu/authd"
"github.com/ubuntu/authd/internal/services/errmessages"
"github.com/ubuntu/authd/internal/testutils"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)

func prepareFileLogging(t *testing.T, fileName string) string {
Expand All @@ -35,27 +30,6 @@ func prepareFileLogging(t *testing.T, fileName string) string {
return cliLog
}

func requirePreviousBrokerForUser(t *testing.T, socketPath string, brokerName string, user string) {
t.Helper()

conn, err := grpc.NewClient("unix://"+socketPath, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithUnaryInterceptor(errmessages.FormatErrorMessage))
require.NoError(t, err, "Can't connect to authd socket")

t.Cleanup(func() { conn.Close() })
pamClient := authd.NewPAMClient(conn)
brokers, err := pamClient.AvailableBrokers(context.TODO(), nil)
require.NoError(t, err, "Can't get available brokers")
prevBroker, err := pamClient.GetPreviousBroker(context.TODO(), &authd.GPBRequest{Username: user})
require.NoError(t, err, "Can't get previous broker")
var prevBrokerID string
for _, b := range brokers.BrokersInfos {
if b.Name == brokerName {
prevBrokerID = b.Id
}
}
require.Equal(t, prevBroker.PreviousBroker, prevBrokerID)
}

func saveArtifactsForDebugOnCleanup(t *testing.T, artifacts []string) {
t.Helper()
t.Cleanup(func() { saveArtifactsForDebug(t, artifacts) })
Expand Down
4 changes: 1 addition & 3 deletions pam/internal/adapter/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ type isAuthenticatedResultReceived struct {
}

// isAuthenticatedCancelled is the event to cancel the auth request.
type isAuthenticatedCancelled struct {
msg string
}
type isAuthenticatedCancelled struct{}

// reselectAuthMode signals to restart auth mode selection with the same id (to resend sms or
// reenable the broker).
Expand Down
3 changes: 2 additions & 1 deletion pam/internal/adapter/gdmmodel.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build withgdmmodel

package adapter

import (
Expand Down Expand Up @@ -286,7 +288,6 @@ func (m gdmModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, sendEvent(m.emitEventSync(&gdm.EventData_AuthEvent{
AuthEvent: &gdm.Events_AuthEvent{Response: &authd.IAResponse{
Access: brokers.AuthCancelled,
Msg: msg.msg,
}},
}))
}
Expand Down
2 changes: 2 additions & 0 deletions pam/internal/adapter/gdmmodel_convhandler_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build withgdmmodel

package adapter

import (
Expand Down
9 changes: 9 additions & 0 deletions pam/internal/adapter/gdmmodel_default.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build withgdmmodel

package adapter

import "github.com/msteinert/pam/v2"

func getGdmModel(pamMTx pam.ModuleTransaction) gdmModeler {
return gdmModel{pamMTx: pamMTx}
}
9 changes: 9 additions & 0 deletions pam/internal/adapter/gdmmodel_disabled.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build !withgdmmodel

package adapter

import "github.com/msteinert/pam/v2"

func getGdmModel(pamMTx pam.ModuleTransaction) gdmModeler {
return nil
}
2 changes: 2 additions & 0 deletions pam/internal/adapter/gdmmodel_helpers_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build withgdmmodel

package adapter

import (
Expand Down
2 changes: 2 additions & 0 deletions pam/internal/adapter/gdmmodel_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build withgdmmodel

package adapter

import (
Expand Down
2 changes: 2 additions & 0 deletions pam/internal/adapter/gdmmodel_uimodel_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build withgdmmodel

package adapter

import (
Expand Down
2 changes: 1 addition & 1 deletion pam/internal/adapter/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (m *UIModel) Init() tea.Cmd {

switch m.ClientType {
case Gdm:
m.gdmModel = gdmModel{pamMTx: m.PamMTx}
m.gdmModel = getGdmModel(m.PamMTx)
cmds = append(cmds, m.gdmModel.Init())
case Native:
m.nativeModel = nativeModel{pamMTx: m.PamMTx, nssClient: m.NssClient}
Expand Down
2 changes: 2 additions & 0 deletions pam/internal/gdm/conversation.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build withgdmmodel

package gdm

import "C"
Expand Down
2 changes: 2 additions & 0 deletions pam/internal/gdm/conversation_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build withgdmmodel

package gdm

import (
Expand Down
2 changes: 2 additions & 0 deletions pam/internal/gdm/export_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build withgdmmodel

package gdm

func init() {
Expand Down
2 changes: 2 additions & 0 deletions pam/internal/gdm/extension.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build withgdmmodel

package gdm

/*
Expand Down
2 changes: 2 additions & 0 deletions pam/internal/gdm/extension_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build withgdmmodel

package gdm

import (
Expand Down
12 changes: 12 additions & 0 deletions pam/internal/gdm/extension_unsupported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build !withgdmmodel

// Package gdm is the package for the GDM pam module handing.
package gdm

// PamExtensionCustomJSON is the gdm PAM extension for passing string values.
const PamExtensionCustomJSON = ""

// IsPamExtensionSupported returns if the provided extension is supported.
func IsPamExtensionSupported(extension string) bool {
return false
}
2 changes: 2 additions & 0 deletions pam/internal/gdm/gdm.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pam/internal/gdm/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build generate

package gdm

//go:generate ../../../tools/generate-proto.sh -I../../.. -I../proto --with-build-tag withgdmmodel gdm.proto
2 changes: 1 addition & 1 deletion pam/internal/gdm/protocol.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate ../../../tools/generate-proto.sh -I../../.. -I../proto gdm.proto
//go:build withgdmmodel

// Package gdm is the package for the GDM pam module handing.
package gdm
Expand Down
2 changes: 2 additions & 0 deletions pam/internal/gdm/protocol_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build withgdmmodel

package gdm_test

import (
Expand Down
2 changes: 2 additions & 0 deletions pam/internal/gdm_test/gdm_utils.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build withgdmmodel

package gdm_test

import (
Expand Down
6 changes: 3 additions & 3 deletions pam/internal/proto/pam.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pam/pam_module.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pam/pam_module_debug.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 521bae5

Please sign in to comment.