Skip to content

Commit 533474c

Browse files
Copilotdamcilva_microsofttobiasb_microsoft
authored
feat: Add SELinux detection and helpful error messages for image build failures (#431)
Co-authored-by: damcilva_microsoft <115752616+damcilva_microsoft@users.noreply.github.com> Co-authored-by: tobiasb_microsoft <115835401+tobiasb_microsoft@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent 5d27c1d commit 533474c

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

internal/utils/kiwi/kiwi.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/gim-home/azldev-preview/internal/global/opctx"
2020
"github.com/gim-home/azldev-preview/internal/utils/fileutils"
2121
"github.com/gim-home/azldev-preview/internal/utils/prereqs"
22+
"github.com/opencontainers/selinux/go-selinux"
2223
)
2324

2425
const (
@@ -277,12 +278,28 @@ func (r *Runner) Build(ctx context.Context) error {
277278

278279
err = cmd.Run(ctx)
279280
if err != nil {
280-
return fmt.Errorf("kiwi build failed:\n%w", err)
281+
return enhanceKiwiError(err)
281282
}
282283

283284
return nil
284285
}
285286

287+
// enhanceKiwiError checks if SELinux is enforcing and provides helpful guidance if so.
288+
func enhanceKiwiError(err error) error {
289+
// If SELinux is enforcing, provide helpful guidance
290+
if selinux.EnforceMode() == selinux.Enforcing {
291+
return fmt.Errorf("kiwi build failed:\n%w\n\n"+
292+
"SELinux is in enforcing mode, which may cause permission issues during image builds.\n"+
293+
"To work around this, temporarily disable SELinux:\n"+
294+
" sudo setenforce 0\n"+
295+
" azldev image build <image-name>\n"+
296+
" sudo setenforce 1", err)
297+
}
298+
299+
// For other cases, return the original error
300+
return fmt.Errorf("kiwi build failed:\n%w", err)
301+
}
302+
286303
// CheckPrerequisites verifies that required tools are available for running kiwi-ng.
287304
// This checks for sudo, kiwi, and sgdisk (used by kiwi for disk partitioning).
288305
func CheckPrerequisites(ctx opctx.Ctx) error {

0 commit comments

Comments
 (0)